From 6802e22f7e7e3d7e2cb9dfbb877655f124b9a2a6 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 15 Apr 2007 18:15:22 +0000 Subject: [PATCH] - Improved a lot switching between tabs --- TODO | 3 +-- src/FinishedTorrents.cpp | 23 ++++++++++++++++------- src/FinishedTorrents.h | 4 ++++ src/GUI.cpp | 3 ++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 2d27f0798..f1fc4f05e 100644 --- a/TODO +++ b/TODO @@ -45,5 +45,4 @@ - Use its piece prioritization support (debug) - Improve ratio display / calculation / saving / per torrent... - Sorting in Download Status column should be smarter than just an alphabetical sort -- Windows port : http://www.peerweb.nl/qbittorrent/experimentalbuild/testing.zip -- MUST Improve torrent switching between download & finished list (and vice-versa) (USE SIGNALs/SLOTS) \ No newline at end of file +- Windows port : http://www.peerweb.nl/qbittorrent/experimentalbuild/testing.zip \ No newline at end of file diff --git a/src/FinishedTorrents.cpp b/src/FinishedTorrents.cpp index bf9a2b3d7..38bca0b03 100644 --- a/src/FinishedTorrents.cpp +++ b/src/FinishedTorrents.cpp @@ -243,22 +243,21 @@ void FinishedTorrents::updateFinishedList(){ continue; } if(h.is_paused()){ - h.resume(); - continue; + h.resume(); // No paused torrents in finished list } torrent_status torrentStatus = h.status(); - if(torrentStatus.state == torrent_status::downloading) { + if(torrentStatus.state == torrent_status::downloading || (torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking && torrentStatus.progress != 1.)) { // What are you doing here, go back to download tab! qDebug("Info: a torrent was moved from finished to download tab"); deleteFromFinishedList(hash); + emit torrentMovedFromFinishedList(h); continue; } - QList items = finishedListModel->findItems(hash, Qt::MatchExactly, HASH ); - if(items.size() != 1){ - qDebug("Problem: Can't find torrent in finished list"); + int row = getRowFromHash(hash); + if(row == -1){ + std::cerr << "ERROR: Can't find torrent in finished list\n"; continue; } - int row = items.at(0)->row(); finishedListModel->setData(finishedListModel->index(row, UPSPEED), QVariant((double)torrentStatus.upload_payload_rate)); finishedListModel->setData(finishedListModel->index(row, SEEDSLEECH), QVariant(QString(misc::toString(torrentStatus.num_seeds, true).c_str())+"/"+QString(misc::toString(torrentStatus.num_peers - torrentStatus.num_seeds, true).c_str()))); } @@ -268,6 +267,16 @@ QStringList FinishedTorrents::getFinishedSHAs(){ return finishedSHAs; } +int FinishedTorrents::getRowFromHash(const QString& hash) const{ + unsigned int nbRows = finishedListModel->rowCount(); + for(unsigned int i=0; idata(finishedListModel->index(i, HASH)) == hash){ + return i; + } + } + return -1; +} + // Will move it to download tab void FinishedTorrents::deleteFromFinishedList(QString hash){ finishedSHAs.removeAll(hash); diff --git a/src/FinishedTorrents.h b/src/FinishedTorrents.h index 93bbccf7c..ff24a0ca5 100644 --- a/src/FinishedTorrents.h +++ b/src/FinishedTorrents.h @@ -45,6 +45,7 @@ class FinishedTorrents : public QWidget, public Ui::seeding{ QTreeView* getFinishedList(); QStandardItemModel* getFinishedListModel(); bool loadColWidthFinishedList(); + int getRowFromHash(const QString& hash) const; public slots: void addFinishedSHA(QString sha); @@ -62,6 +63,9 @@ class FinishedTorrents : public QWidget, public Ui::seeding{ protected slots: void on_actionSet_upload_limit_triggered(); + signals: + void torrentMovedFromFinishedList(torrent_handle); + }; #endif diff --git a/src/GUI.cpp b/src/GUI.cpp index 4a8270866..0b1213f46 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -69,6 +69,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ finishedTorrentTab = new FinishedTorrents(this, &BTSession); tabs->addTab(finishedTorrentTab, tr("Finished")); tabs->setTabIcon(1, QIcon(QString::fromUtf8(":/Icons/skin/seeding.png"))); + connect(finishedTorrentTab, SIGNAL(torrentMovedFromFinishedList(torrent_handle)), this, SLOT(restoreInDownloadList(torrent_handle))); // Search engine tab searchEngine = new SearchEngine(&BTSession, myTrayIcon, systrayIntegration); tabs->addTab(searchEngine, tr("Search")); @@ -490,7 +491,7 @@ void GUI::updateDlList(bool force){ if(finishedSHAs.indexOf(fileHash) != -1) continue; int row = getRowFromHash(fileHash); if(row == -1){ - qDebug("Could not find filename in download list, adding it..."); + qDebug("Info: Could not find filename in download list, adding it..."); restoreInDownloadList(h); row = getRowFromHash(fileHash); }