From 55538934e0c583eb7094bc40b406c35f49e6a2e1 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 28 Jun 2007 22:58:43 +0000 Subject: [PATCH] A better fix for progress column sorting on restart (still untested, gtsoul please check) --- src/FinishedTorrents.cpp | 3 +++ src/GUI.cpp | 18 +++++++++++++++--- src/GUI.h | 1 + src/bittorrent.cpp | 24 ++++++++++++++++++++++-- src/bittorrent.h | 6 +++++- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/FinishedTorrents.cpp b/src/FinishedTorrents.cpp index efe81d8b7..f415df1da 100644 --- a/src/FinishedTorrents.cpp +++ b/src/FinishedTorrents.cpp @@ -75,6 +75,9 @@ FinishedTorrents::~FinishedTorrents(){ } void FinishedTorrents::addFinishedSHA(QString hash){ + if(BTSession->getUncheckedTorrentsList().indexOf(hash) != -1){ + BTSession->setTorrentFinishedChecking(hash); + } if(finishedSHAs.indexOf(hash) == -1) { finishedSHAs << hash; int row = finishedListModel->rowCount(); diff --git a/src/GUI.cpp b/src/GUI.cpp index 9bfe7d82f..78cc333f9 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -140,6 +140,7 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent){ connect(&BTSession, SIGNAL(fullDiskError(torrent_handle&)), this, SLOT(fullDiskError(torrent_handle&))); connect(&BTSession, SIGNAL(portListeningFailure()), this, SLOT(portListeningFailure())); connect(&BTSession, SIGNAL(trackerError(const QString&, const QString&, const QString&)), this, SLOT(trackerError(const QString&, const QString&, const QString&))); + connect(&BTSession,SIGNAL(allTorrentsFinishedChecking()), this, SLOT(sortProgressColumnDelayed())); connect(&BTSession, SIGNAL(trackerAuthenticationRequired(torrent_handle&)), this, SLOT(trackerAuthenticationRequired(torrent_handle&))); connect(&BTSession, SIGNAL(scanDirFoundTorrents(const QStringList&)), this, SLOT(processScannedFiles(const QStringList&))); connect(&BTSession, SIGNAL(newDownloadedTorrent(const QString&, const QString&)), this, SLOT(processDownloadedFiles(const QString&, const QString&))); @@ -448,6 +449,14 @@ void GUI::displayInfoBarMenu(const QPoint& pos){ myLogMenu.exec(mapToGlobal(pos)+QPoint(22,383)); } +void GUI::sortProgressColumnDelayed() { + if(delayedSorting){ + sortDownloadListFloat(PROGRESS, delayedSortingOrder); + qDebug("Delayed sorting of progress column"); + delayedSorting = false; + } +} + // get information from torrent handles and // update download list accordingly void GUI::updateDlList(bool force){ @@ -480,6 +489,11 @@ void GUI::updateDlList(bool force){ torrent_status torrentStatus = h.status(); QString fileHash = QString(misc::toString(h.info_hash()).c_str()); int row = getRowFromHash(fileHash); + if(delayedSorting && BTSession.getUncheckedTorrentsList().indexOf(fileHash) != -1){ + if(torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking){ + BTSession.setTorrentFinishedChecking(fileHash); + } + } if(BTSession.getTorrentsToPauseAfterChecking().indexOf(fileHash) != -1){ // Pause torrent if it finished checking and it is was supposed to be paused. // This is a trick to see the progress of the pause torrents on startup @@ -487,8 +501,6 @@ void GUI::updateDlList(bool force){ qDebug("Paused torrent finished checking with state: %d", torrentStatus.state); DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)torrentStatus.progress)); BTSession.pauseTorrent(fileHash); - if(delayedSorting) - sortDownloadListFloat(PROGRESS, delayedSortingOrder); continue; } } @@ -1133,7 +1145,7 @@ void GUI::processDownloadedFiles(const QString& path, const QString& url){ connect(dialog, SIGNAL(setInfoBarGUI(const QString&, const QString&)), this, SLOT(setInfoBar(const QString&, const QString&))); dialog->showLoad(path, false, url); }else{ - BTSession.addTorrent(path, false, url); + BTSession.addTorrent(path, false, false, url); } } diff --git a/src/GUI.h b/src/GUI.h index b3534c03f..ec7305985 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -170,6 +170,7 @@ class GUI : public QMainWindow, private Ui::MainWindow{ void trackerAuthenticationRequired(torrent_handle& h); void setTabText(int index, QString text); void updateFileSize(QString hash); + void sortProgressColumnDelayed(); protected: void closeEvent(QCloseEvent *); diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index af965a7f7..fa225b04b 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -144,7 +144,7 @@ void bittorrent::resumeTorrent(const QString& hash){ } // Add a torrent to the bittorrent session -void bittorrent::addTorrent(const QString& path, bool fromScanDir, const QString& from_url){ +void bittorrent::addTorrent(const QString& path, bool fromScanDir, bool onStartup, const QString& from_url){ torrent_handle h; entry resume_data; bool fastResume=false; @@ -173,6 +173,10 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, const QString // Getting torrent file informations torrent_info t(e); QString hash = QString(misc::toString(t.info_hash()).c_str()); + if(onStartup){ + qDebug("Added a hash to the unchecked torrents list"); + torrentsUnchecked << hash; + } if(s->find_torrent(t.info_hash()).is_valid()){ // Update info Bar if(!fromScanDir){ @@ -831,6 +835,22 @@ QList bittorrent::getFinishedTorrentHandles() const{ return finished; } +QStringList bittorrent::getUncheckedTorrentsList() const{ + return torrentsUnchecked; +} + +void bittorrent::setTorrentFinishedChecking(QString hash){ + int index = torrentsUnchecked.indexOf(hash); + if(index != -1){ + qDebug("torrent %s finished checking", (const char*)hash.toUtf8()); + torrentsUnchecked.removeAt(index); + qDebug("Still %d unchecked torrents", torrentsUnchecked.size()); + if(torrentsUnchecked.size() == 0){ + emit allTorrentsFinishedChecking(); + } + } +} + // Save DHT entry to hard drive void bittorrent::saveDHTEntry(){ // Save DHT entry @@ -867,7 +887,7 @@ void bittorrent::resumeUnfinished(){ } // Resume downloads foreach(fileName, filePaths){ - addTorrent(fileName); + addTorrent(fileName, false, true); } qDebug("Unfinished torrents resumed"); } diff --git a/src/bittorrent.h b/src/bittorrent.h index a83660111..dee7a480e 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -58,6 +58,7 @@ class bittorrent : public QObject{ QStringList supported_preview_extensions; QString defaultSavePath; QStringList torrentsToPauseAfterChecking; + QStringList torrentsUnchecked; protected: QString getSavePath(const QString& hash); @@ -78,9 +79,10 @@ class bittorrent : public QObject{ session_status getSessionStatus() const; int getListenPort() const; QStringList getTorrentsToPauseAfterChecking() const; + QStringList getUncheckedTorrentsList() const; public slots: - void addTorrent(const QString& path, bool fromScanDir = false, const QString& from_url = QString()); + void addTorrent(const QString& path, bool fromScanDir = false, bool onStartup = false, const QString& from_url = QString()); void downloadFromUrl(const QString& url); void downloadFromURLList(const QStringList& url_list); void deleteTorrent(const QString& hash, bool permanent = false); @@ -98,6 +100,7 @@ class bittorrent : public QObject{ void enableIPFilter(ip_filter filter); void disableIPFilter(); void reloadTorrent(const torrent_handle &h, bool compact_mode = true); + void setTorrentFinishedChecking(QString hash); void resumeUnfinishedTorrents(); // Session configuration - Setters void setListeningPortsRange(std::pair ports); @@ -135,6 +138,7 @@ class bittorrent : public QObject{ void newDownloadedTorrent(const QString& path, const QString& url); void aboutToDownloadFromUrl(const QString& url); void updateFileSize(QString hash); + void allTorrentsFinishedChecking(); };