Browse Source

- Finished trackers edition

adaptive-webui-19844
Christophe Dumez 18 years ago
parent
commit
d2d3968b8b
  1. 4
      Changelog
  2. 3
      TODO
  3. 15
      src/bittorrent.cpp
  4. 2
      src/bittorrent.h
  5. 67
      src/properties_imp.cpp
  6. 2
      src/properties_imp.h

4
Changelog

@ -1,7 +1,8 @@
* Unknown - Christophe Dumez <chris@qbittorrent.org> - v0.10.0 or v1.0.0? * Unknown - Christophe Dumez <chris@qbittorrent.org> - v0.10.0 or v1.0.0?
- FEATURE: Added UPnP port forwarding support - FEATURE: Added UPnP port forwarding support
- FEATURE: Display more infos about the torrent in its properties - 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 <chris@qbittorrent.org> - v0.9.0 * Unknown - Christophe Dumez <chris@qbittorrent.org> - v0.9.0
- FEATURE: Based on libtorrent v0.12 - FEATURE: Based on libtorrent v0.12
@ -31,6 +32,7 @@
- BUGFIX: Create Options object only when necessary (to save memory) - BUGFIX: Create Options object only when necessary (to save memory)
- BUGFIX: Let libtorrent store the torrent handles (save memory) - BUGFIX: Let libtorrent store the torrent handles (save memory)
- BUGFIX: Set DHT Port only when DHT is enabled - BUGFIX: Set DHT Port only when DHT is enabled
- I18N: Added Danish translation
- I18N: Better internationalization thanks to dynamic text support - I18N: Better internationalization thanks to dynamic text support
- COSMETIC: Replaced OSD messages by Qt4.2 systray messages - COSMETIC: Replaced OSD messages by Qt4.2 systray messages

3
TODO

@ -29,9 +29,8 @@
- Add a torrent scheduler - Add a torrent scheduler
// in v0.10 (partial) // 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 - 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) - Improve torrent creation dialog (look & features)
- Add IPv6 support (at least start working on it) - Add IPv6 support (at least start working on it)
- UPnP support (debug, sync with aMule CVS, option entry) - UPnP support (debug, sync with aMule CVS, option entry)

15
src/bittorrent.cpp

@ -252,8 +252,12 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, const QString
// Load filtered files // Load filtered files
loadFilteredFiles(h); loadFilteredFiles(h);
// Load trackers // Load trackers
bool loaded_trackers = loadTrackerFile(hash);
// Doing this to order trackers well
if(!loaded_trackers){
saveTrackerFile(hash);
loadTrackerFile(hash); loadTrackerFile(hash);
}
torrent_status torrentStatus = h.status(); torrent_status torrentStatus = h.status();
QString newFile = torrentBackup.path() + QDir::separator() + hash + ".torrent"; QString newFile = torrentBackup.path() + QDir::separator() + hash + ".torrent";
if(file != newFile){ 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"); QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QFile tracker_file(torrentBackup.path()+QDir::separator()+ hash + ".trackers"); 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); tracker_file.open(QIODevice::ReadOnly | QIODevice::Text);
QStringList lines = QString(tracker_file.readAll().data()).split("\n"); QStringList lines = QString(tracker_file.readAll().data()).split("\n");
std::vector<announce_entry> trackers; std::vector<announce_entry> trackers;
@ -566,6 +570,9 @@ void bittorrent::loadTrackerFile(const QString& hash){
if(trackers.size() != 0){ if(trackers.size() != 0){
torrent_handle h = getTorrentHandle(hash); torrent_handle h = getTorrentHandle(hash);
h.replace_trackers(trackers); h.replace_trackers(trackers);
return true;
}else{
return false;
} }
} }
@ -579,7 +586,7 @@ void bittorrent::saveTrackerFile(const QString& hash){
torrent_handle h = getTorrentHandle(hash); torrent_handle h = getTorrentHandle(hash);
std::vector<announce_entry> trackers = h.trackers(); std::vector<announce_entry> trackers = h.trackers();
for(unsigned int i=0; i<trackers.size(); ++i){ for(unsigned int i=0; i<trackers.size(); ++i){
tracker_file.write(QByteArray(trackers[i].url.c_str())+QByteArray("|")+QByteArray(misc::toString(trackers[i].tier).c_str())+QByteArray("\n")); tracker_file.write(QByteArray(trackers[i].url.c_str())+QByteArray("|")+QByteArray(misc::toString(i).c_str())+QByteArray("\n"));
} }
tracker_file.close(); tracker_file.close();
} }

2
src/bittorrent.h

@ -132,7 +132,7 @@ class bittorrent : public QObject{
void readAlerts(); void readAlerts();
void processDownloadedFile(const QString&, const QString&, int, const QString&); void processDownloadedFile(const QString&, const QString&, int, const QString&);
void resumeUnfinished(); void resumeUnfinished();
void loadTrackerFile(const QString& hash); bool loadTrackerFile(const QString& hash);
void saveTrackerFile(const QString& hash); void saveTrackerFile(const QString& hash);
signals: signals:

67
src/properties_imp.cpp

@ -47,6 +47,8 @@ properties::properties(QWidget *parent, torrent_handle &h, QStringList trackerEr
connect(filesList, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(toggleSelectedState(const QModelIndex&))); connect(filesList, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(toggleSelectedState(const QModelIndex&)));
connect(addTracker_button, SIGNAL(clicked()), this, SLOT(askForTracker())); connect(addTracker_button, SIGNAL(clicked()), this, SLOT(askForTracker()));
connect(removeTracker_button, SIGNAL(clicked()), this, SLOT(deleteSelectedTrackers())); connect(removeTracker_button, SIGNAL(clicked()), this, SLOT(deleteSelectedTrackers()));
connect(riseTracker_button, SIGNAL(clicked()), this, SLOT(riseSelectedTracker()));
connect(lowerTracker_button, SIGNAL(clicked()), this, SLOT(lowerSelectedTracker()));
// get Infos from torrent handle // get Infos from torrent handle
fileHash = QString(misc::toString(h.info_hash()).c_str()); fileHash = QString(misc::toString(h.info_hash()).c_str());
torrent_status torrentStatus = h.status(); torrent_status torrentStatus = h.status();
@ -192,15 +194,12 @@ void properties::deleteSelectedTrackers(){
QListWidgetItem *item; QListWidgetItem *item;
foreach(item, selectedItems){ foreach(item, selectedItems){
QString url = item->text(); QString url = item->text();
bool found = false;
for(unsigned int i=0; i<trackers.size(); ++i){ for(unsigned int i=0; i<trackers.size(); ++i){
if(QString(trackers.at(i).url.c_str()) == url){ if(QString(trackers.at(i).url.c_str()) == url){
trackers.erase(trackers.begin()+i); trackers.erase(trackers.begin()+i);
found = true;
break; break;
} }
} }
qDebug("Found: %d", found);
} }
h.replace_trackers(trackers); h.replace_trackers(trackers);
h.force_reannounce(); h.force_reannounce();
@ -208,6 +207,68 @@ void properties::deleteSelectedTrackers(){
loadTrackers(); loadTrackers();
} }
void properties::riseSelectedTracker(){
unsigned int i;
std::vector<announce_entry> trackers = h.trackers();
QList<QListWidgetItem *> selectedItems;
selectedItems = trackersURLS->selectedItems();
QListWidgetItem *item;
bool change = false;
foreach(item, selectedItems){
QString url = item->text();
for(i=0; i<trackers.size(); ++i){
if(QString(trackers.at(i).url.c_str()) == url){
if(trackers[i].tier>0 && 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<announce_entry> trackers = h.trackers();
QList<QListWidgetItem *> selectedItems;
selectedItems = trackersURLS->selectedItems();
QListWidgetItem *item;
bool change = false;
foreach(item, selectedItems){
QString url = item->text();
for(i=0; i<trackers.size(); ++i){
if(QString(trackers.at(i).url.c_str()) == url){
if(i != trackers.size()-1){
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::updateProgress(){ void properties::updateProgress(){
std::vector<float> fp; std::vector<float> fp;
try{ try{

2
src/properties_imp.h

@ -56,6 +56,8 @@ class properties : public QDialog, private Ui::properties{
void askForTracker(); void askForTracker();
void loadTrackers(); void loadTrackers();
void deleteSelectedTrackers(); void deleteSelectedTrackers();
void lowerSelectedTracker();
void riseSelectedTracker();
signals: signals:
void changedFilteredFiles(torrent_handle h, bool compact_mode); void changedFilteredFiles(torrent_handle h, bool compact_mode);

Loading…
Cancel
Save