BUGFIX: Fix actions on selected torrents (non-selected torrents could be affected)

This commit is contained in:
Christophe Dumez
2010-02-09 20:48:48 +00:00
parent 461cca2f52
commit cf0c359abf
3 changed files with 53 additions and 73 deletions

View File

@@ -1,4 +1,5 @@
* Unreleased - Christophe Dumez <chris@qbittorrent.org> - v2.1.5
- BUGFIX: Fix actions on selected torrents (non-selected torrents could be affected)
- BUGFIX: Link against boost and ssl to fix issues with gold linker
* Mon Feb 8 2010 - Christophe Dumez <chris@qbittorrent.org> - v2.1.4

View File

@@ -567,19 +567,25 @@ void TransferListWidget::torrentDoubleClicked(QModelIndex index) {
}
}
void TransferListWidget::startSelectedTorrents() {
QStringList TransferListWidget::getSelectedTorrentsHashes() const {
QStringList hashes;
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) {
// Get the file hash
int row = mapToSource(index).row();
QString hash = getHashFromRow(row);
hashes << getHashFromRow(mapToSource(index).row());
}
return hashes;
}
void TransferListWidget::startSelectedTorrents() {
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && h.is_paused()) {
h.resume();
resumeTorrent(row, false);
resumeTorrent(getRowFromHash(hash), false);
}
}
if(!selectedIndexes.empty())
if(!hashes.empty())
refreshList();
}
@@ -595,18 +601,15 @@ void TransferListWidget::startAllTorrents() {
}
void TransferListWidget::pauseSelectedTorrents() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) {
// Get the file hash
int row = mapToSource(index).row();
QString hash = getHashFromRow(row);
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && !h.is_paused()) {
h.pause();
pauseTorrent(row, false);
pauseTorrent(getRowFromHash(hash), false);
}
}
if(!selectedIndexes.empty())
if(!hashes.empty())
refreshList();
}
@@ -623,15 +626,10 @@ void TransferListWidget::pauseAllTorrents() {
void TransferListWidget::deleteSelectedTorrents() {
if(main_window->getCurrentTabIndex() != TAB_TRANSFER) return;
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
if(!selectedIndexes.empty()) {
QStringList hashes = getSelectedTorrentsHashes();
if(!hashes.empty()) {
bool delete_local_files = false;
if(DeletionConfirmationDlg::askForDeletionConfirmation(&delete_local_files)) {
QStringList hashes;
foreach(const QModelIndex &index, selectedIndexes) {
// Get the file hash
hashes << getHashFromRow(mapToSource(index).row());
}
foreach(const QString &hash, hashes) {
int row = getRowFromHash(hash);
deleteTorrent(row, false);
@@ -644,9 +642,9 @@ void TransferListWidget::deleteSelectedTorrents() {
// FIXME: Should work only if the tab is displayed
void TransferListWidget::increasePrioSelectedTorrents() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(mapToSource(index).row()));
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && !h.is_seed()) {
h.queue_position_up();
}
@@ -656,9 +654,9 @@ void TransferListWidget::increasePrioSelectedTorrents() {
// FIXME: Should work only if the tab is displayed
void TransferListWidget::decreasePrioSelectedTorrents() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(mapToSource(index).row()));
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && !h.is_seed()) {
h.queue_position_down();
}
@@ -667,19 +665,19 @@ void TransferListWidget::decreasePrioSelectedTorrents() {
}
void TransferListWidget::buySelectedTorrents() const {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(mapToSource(index).row()));
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid())
QDesktopServices::openUrl("http://match.sharemonkey.com/?info_hash="+h.hash()+"&n="+h.name()+"&cid=33");
}
}
void TransferListWidget::copySelectedMagnetURIs() const {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList magnet_uris;
foreach(const QModelIndex &index, selectedIndexes) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(mapToSource(index).row()));
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && h.has_metadata())
magnet_uris << misc::toQString(make_magnet_uri(h.get_torrent_info()));
}
@@ -691,10 +689,10 @@ void TransferListWidget::hidePriorityColumn(bool hide) {
}
void TransferListWidget::openSelectedTorrentsFolder() const {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList pathsList;
foreach(const QModelIndex &index, selectedIndexes) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(mapToSource(index).row()));
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid()) {
QString savePath = h.root_path();
if(!pathsList.contains(savePath)) {
@@ -706,10 +704,10 @@ void TransferListWidget::openSelectedTorrentsFolder() const {
}
void TransferListWidget::previewSelectedTorrents() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList pathsList;
foreach(const QModelIndex &index, selectedIndexes) {
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(mapToSource(index).row()));
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && h.has_metadata()) {
new previewSelect(this, h);
}
@@ -717,14 +715,11 @@ void TransferListWidget::previewSelectedTorrents() {
}
void TransferListWidget::setDlLimitSelectedTorrents() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList hashes;
QList<QTorrentHandle> selected_torrents;
bool first = true;
bool all_same_limit = true;
foreach(const QModelIndex &index, selectedIndexes) {
// Get the file hash
QString hash = getHashFromRow(mapToSource(index).row());
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && !h.is_seed()) {
selected_torrents << h;
@@ -753,14 +748,11 @@ void TransferListWidget::setDlLimitSelectedTorrents() {
}
void TransferListWidget::setUpLimitSelectedTorrents() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList hashes;
QList<QTorrentHandle> selected_torrents;
bool first = true;
bool all_same_limit = true;
foreach(const QModelIndex &index, selectedIndexes) {
// Get the file hash
QString hash = getHashFromRow(mapToSource(index).row());
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid()) {
selected_torrents << h;
@@ -789,13 +781,9 @@ void TransferListWidget::setUpLimitSelectedTorrents() {
}
void TransferListWidget::recheckSelectedTorrents() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes){
QString hash = getHashFromRow(mapToSource(index).row());
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid()) {
BTSession->recheckTorrent(h.hash());
}
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
BTSession->recheckTorrent(hash);
}
}
@@ -863,10 +851,8 @@ void TransferListWidget::displayDLHoSMenu(const QPoint&){
#ifdef LIBTORRENT_0_15
void TransferListWidget::toggleSelectedTorrentsSuperSeeding() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) {
// Get the file hash
QString hash = getHashFromRow(mapToSource(index).row());
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && h.has_metadata()) {
h.super_seeding(!h.super_seeding());
@@ -876,10 +862,8 @@ void TransferListWidget::toggleSelectedTorrentsSuperSeeding() {
#endif
void TransferListWidget::toggleSelectedTorrentsSequentialDownload() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) {
// Get the file hash
QString hash = getHashFromRow(mapToSource(index).row());
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && h.has_metadata()) {
h.set_sequential_download(!h.is_sequential_download());
@@ -888,10 +872,8 @@ void TransferListWidget::toggleSelectedTorrentsSequentialDownload() {
}
void TransferListWidget::toggleSelectedFirstLastPiecePrio() {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) {
// Get the file hash
QString hash = getHashFromRow(mapToSource(index).row());
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(h.is_valid() && h.has_metadata()) {
h.prioritize_first_last_piece(!h.first_last_piece_first());
@@ -937,12 +919,8 @@ void TransferListWidget::renameSelectedTorrent() {
}
void TransferListWidget::setSelectionLabel(QString label) {
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
QStringList hashes;
foreach(const QModelIndex &index, selectedIndexes) {
hashes << getHashFromRow(mapToSource(index).row());
}
foreach(const QString& hash, hashes) {
QStringList hashes = getSelectedTorrentsHashes();
foreach(const QString &hash, hashes) {
Q_ASSERT(!hash.isEmpty());
int row = getRowFromHash(hash);
QString old_label = listModel->data(listModel->index(row, TR_LABEL)).toString();

View File

@@ -71,6 +71,7 @@ protected:
bool loadColWidthList();
void saveLastSortedColumn();
void loadLastSortedColumn();
QStringList getSelectedTorrentsHashes() const;
protected slots:
int updateTorrent(int row);