From c8b944508ba6fbfdbc9a23c9faba574e0c3d66ee Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 19 Nov 2007 21:10:57 +0000 Subject: [PATCH] - Saving trackers file only when necessary - Avoid code duplication for showProperties() --- src/FinishedTorrents.cpp | 8 ++------ src/bittorrent.cpp | 3 +-- src/downloadingTorrents.cpp | 8 ++------ src/properties_imp.cpp | 4 ++++ src/properties_imp.h | 2 ++ 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/FinishedTorrents.cpp b/src/FinishedTorrents.cpp index 319861115..4400e10fa 100644 --- a/src/FinishedTorrents.cpp +++ b/src/FinishedTorrents.cpp @@ -310,18 +310,14 @@ void FinishedTorrents::deleteTorrent(QString hash){ // Show torrent properties dialog void FinishedTorrents::showProperties(const QModelIndex &index){ - int row = index.row(); - QString hash = finishedListModel->data(finishedListModel->index(row, F_HASH)).toString(); - QTorrentHandle h = BTSession->getTorrentHandle(hash); - properties *prop = new properties(this, BTSession, h); - connect(prop, SIGNAL(filteredFilesChanged(QString)), this, SLOT(updateFileSize(QString))); - prop->show(); + showPropertiesFromHash(finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString()); } void FinishedTorrents::showPropertiesFromHash(QString hash){ QTorrentHandle h = BTSession->getTorrentHandle(hash); properties *prop = new properties(this, BTSession, h); connect(prop, SIGNAL(filteredFilesChanged(QString)), this, SLOT(updateFileSize(QString))); + connect(prop, SIGNAL(trackersChanged(QString)), BTSession, SLOT(saveTrackerFile(QString))); prop->show(); } diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index fe713ab01..7180c0d0b 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -858,8 +858,6 @@ void bittorrent::saveFastResumeAndRatioData() { } // Save ratio data saveDownloadUploadForTorrent(hash); - // Save trackers - saveTrackerFile(hash); } } qDebug("Fast resume and ratio data saved"); @@ -1005,6 +1003,7 @@ bool bittorrent::loadTrackerFile(QString hash) { } void bittorrent::saveTrackerFile(QString hash) { + qDebug("Saving tracker file for %s", hash.toUtf8().data()); QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QFile tracker_file(torrentBackup.path()+QDir::separator()+ hash + ".trackers"); if(tracker_file.exists()) { diff --git a/src/downloadingTorrents.cpp b/src/downloadingTorrents.cpp index 1dcef85fc..a4902dfd1 100644 --- a/src/downloadingTorrents.cpp +++ b/src/downloadingTorrents.cpp @@ -168,18 +168,14 @@ void DownloadingTorrents::setBottomTabEnabled(unsigned int index, bool b){ // Show torrent properties dialog void DownloadingTorrents::showProperties(const QModelIndex &index) { - int row = index.row(); - QString hash = DLListModel->data(DLListModel->index(row, HASH)).toString(); - QTorrentHandle h = BTSession->getTorrentHandle(hash); - properties *prop = new properties(this, BTSession, h); - connect(prop, SIGNAL(filteredFilesChanged(QString)), this, SLOT(updateFileSizeAndProgress(QString))); - prop->show(); + showPropertiesFromHash(DLListModel->data(DLListModel->index(index.row(), HASH)).toString()); } void DownloadingTorrents::showPropertiesFromHash(QString hash) { QTorrentHandle h = BTSession->getTorrentHandle(hash); properties *prop = new properties(this, BTSession, h); connect(prop, SIGNAL(filteredFilesChanged(QString)), this, SLOT(updateFileSizeAndProgress(QString))); + connect(prop, SIGNAL(trackersChanged(QString)), BTSession, SLOT(saveTrackerFile(QString))); prop->show(); } diff --git a/src/properties_imp.cpp b/src/properties_imp.cpp index 1136a7eef..9139c721c 100644 --- a/src/properties_imp.cpp +++ b/src/properties_imp.cpp @@ -502,6 +502,7 @@ void properties::askForTracker(){ h.force_reannounce(); // Reload Trackers loadTrackers(); + emit trackersChanged(h.hash()); } void properties::deleteSelectedUrlSeeds(){ @@ -550,6 +551,7 @@ void properties::deleteSelectedTrackers(){ h.force_reannounce(); // Reload Trackers loadTrackers(); + emit trackersChanged(h.hash()); } void properties::riseSelectedTracker(){ @@ -583,6 +585,7 @@ void properties::riseSelectedTracker(){ // Reload Trackers loadTrackers(); trackersURLS->item(i-1)->setSelected(true); + emit trackersChanged(h.hash()); } } @@ -617,6 +620,7 @@ void properties::lowerSelectedTracker(){ // Reload Trackers loadTrackers(); trackersURLS->item(i+1)->setSelected(true); + emit trackersChanged(h.hash()); } } diff --git a/src/properties_imp.h b/src/properties_imp.h index 4d7cd115c..a794ea428 100644 --- a/src/properties_imp.h +++ b/src/properties_imp.h @@ -42,6 +42,7 @@ class properties : public QDialog, private Ui::properties{ QTorrentHandle h; bittorrent *BTSession; bool changedFilteredfiles; + bool changedTrackers; QString hash; PropListDelegate *PropDelegate; QStandardItemModel *PropListModel; @@ -84,6 +85,7 @@ class properties : public QDialog, private Ui::properties{ signals: void filteredFilesChanged(QString hash); void fileSizeChanged(QString hash); + void trackersChanged(QString hash); public: // Constructor