From d2d3968b8bf11161470d41756f73a5cf23ee6c80 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 25 Mar 2007 18:39:27 +0000 Subject: [PATCH] - Finished trackers edition --- Changelog | 4 ++- TODO | 3 +- src/bittorrent.cpp | 17 +++++++---- src/bittorrent.h | 2 +- src/properties_imp.cpp | 67 ++++++++++++++++++++++++++++++++++++++++-- src/properties_imp.h | 2 ++ 6 files changed, 83 insertions(+), 12 deletions(-) diff --git a/Changelog b/Changelog index 6deede931..86b95fbb0 100644 --- a/Changelog +++ b/Changelog @@ -1,7 +1,8 @@ * Unknown - Christophe Dumez - v0.10.0 or v1.0.0? - FEATURE: Added UPnP port forwarding support - FEATURE: Display more infos about the torrent in its properties - - FEATURE: Allow the user to edit the torrent trackers list + - FEATURE: Allow the user to edit torrents' trackers + - COSMETIC: Redesigned torrent properties a little * Unknown - Christophe Dumez - v0.9.0 - FEATURE: Based on libtorrent v0.12 @@ -31,6 +32,7 @@ - BUGFIX: Create Options object only when necessary (to save memory) - BUGFIX: Let libtorrent store the torrent handles (save memory) - BUGFIX: Set DHT Port only when DHT is enabled + - I18N: Added Danish translation - I18N: Better internationalization thanks to dynamic text support - COSMETIC: Replaced OSD messages by Qt4.2 systray messages diff --git a/TODO b/TODO index 6fb641188..488a6d8d8 100644 --- a/TODO +++ b/TODO @@ -29,9 +29,8 @@ - Add a torrent scheduler // in v0.10 (partial) -- Download from RSS feeds (WIP by gtsoul) +- Download from RSS feeds (WIP by gtsoul in RSS_SUPPORT branch) - Move finished torrent to another tab and keep on seeding them even after restart -- Allow to edit the trackers for a torrent - Improve torrent creation dialog (look & features) - Add IPv6 support (at least start working on it) - UPnP support (debug, sync with aMule CVS, option entry) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index c608a8319..857da8021 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -252,8 +252,12 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, const QString // Load filtered files loadFilteredFiles(h); // Load trackers - loadTrackerFile(hash); - + bool loaded_trackers = loadTrackerFile(hash); + // Doing this to order trackers well + if(!loaded_trackers){ + saveTrackerFile(hash); + loadTrackerFile(hash); + } torrent_status torrentStatus = h.status(); QString newFile = torrentBackup.path() + QDir::separator() + hash + ".torrent"; if(file != newFile){ @@ -548,10 +552,10 @@ void bittorrent::setGlobalRatio(float ratio){ } } -void bittorrent::loadTrackerFile(const QString& hash){ +bool bittorrent::loadTrackerFile(const QString& hash){ QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QFile tracker_file(torrentBackup.path()+QDir::separator()+ hash + ".trackers"); - if(!tracker_file.exists()) return; + if(!tracker_file.exists()) return false; tracker_file.open(QIODevice::ReadOnly | QIODevice::Text); QStringList lines = QString(tracker_file.readAll().data()).split("\n"); std::vector trackers; @@ -566,6 +570,9 @@ void bittorrent::loadTrackerFile(const QString& hash){ if(trackers.size() != 0){ torrent_handle h = getTorrentHandle(hash); h.replace_trackers(trackers); + return true; + }else{ + return false; } } @@ -579,7 +586,7 @@ void bittorrent::saveTrackerFile(const QString& hash){ torrent_handle h = getTorrentHandle(hash); std::vector trackers = h.trackers(); for(unsigned int i=0; itext(); - bool found = false; for(unsigned int i=0; i trackers = h.trackers(); + QList selectedItems; + selectedItems = trackersURLS->selectedItems(); + QListWidgetItem *item; + bool change = false; + foreach(item, selectedItems){ + QString url = item->text(); + for(i=0; i0 && i != 0){ + trackers[i].tier -= 1; + announce_entry tmp = trackers[i]; + trackers[i] = trackers[i-1]; + trackers[i-1] = tmp; + change = true; + } + break; + } + } + } + if(change){ + h.replace_trackers(trackers); + h.force_reannounce(); + // Reload Trackers + loadTrackers(); + trackersURLS->item(i-1)->setSelected(true); + } +} + +void properties::lowerSelectedTracker(){ + unsigned int i; + std::vector trackers = h.trackers(); + QList selectedItems; + selectedItems = trackersURLS->selectedItems(); + QListWidgetItem *item; + bool change = false; + foreach(item, selectedItems){ + QString url = item->text(); + for(i=0; iitem(i+1)->setSelected(true); + } +} + void properties::updateProgress(){ std::vector fp; try{ diff --git a/src/properties_imp.h b/src/properties_imp.h index 362683672..fce325e32 100644 --- a/src/properties_imp.h +++ b/src/properties_imp.h @@ -56,6 +56,8 @@ class properties : public QDialog, private Ui::properties{ void askForTracker(); void loadTrackers(); void deleteSelectedTrackers(); + void lowerSelectedTracker(); + void riseSelectedTracker(); signals: void changedFilteredFiles(torrent_handle h, bool compact_mode);