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 @@ @@ -1,7 +1,8 @@
* Unknown - Christophe Dumez <chris@qbittorrent.org> - 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 <chris@qbittorrent.org> - v0.9.0
- FEATURE: Based on libtorrent v0.12
@ -31,6 +32,7 @@ @@ -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

3
TODO

@ -29,9 +29,8 @@ @@ -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)

15
src/bittorrent.cpp

@ -252,8 +252,12 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, const QString @@ -252,8 +252,12 @@ void bittorrent::addTorrent(const QString& path, bool fromScanDir, const QString
// Load filtered files
loadFilteredFiles(h);
// Load trackers
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){ @@ -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<announce_entry> trackers;
@ -566,6 +570,9 @@ void bittorrent::loadTrackerFile(const QString& hash){ @@ -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){ @@ -579,7 +586,7 @@ void bittorrent::saveTrackerFile(const QString& hash){
torrent_handle h = getTorrentHandle(hash);
std::vector<announce_entry> trackers = h.trackers();
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();
}

2
src/bittorrent.h

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

67
src/properties_imp.cpp

@ -47,6 +47,8 @@ properties::properties(QWidget *parent, torrent_handle &h, QStringList trackerEr @@ -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(addTracker_button, SIGNAL(clicked()), this, SLOT(askForTracker()));
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
fileHash = QString(misc::toString(h.info_hash()).c_str());
torrent_status torrentStatus = h.status();
@ -192,15 +194,12 @@ void properties::deleteSelectedTrackers(){ @@ -192,15 +194,12 @@ void properties::deleteSelectedTrackers(){
QListWidgetItem *item;
foreach(item, selectedItems){
QString url = item->text();
bool found = false;
for(unsigned int i=0; i<trackers.size(); ++i){
if(QString(trackers.at(i).url.c_str()) == url){
trackers.erase(trackers.begin()+i);
found = true;
break;
}
}
qDebug("Found: %d", found);
}
h.replace_trackers(trackers);
h.force_reannounce();
@ -208,6 +207,68 @@ void properties::deleteSelectedTrackers(){ @@ -208,6 +207,68 @@ void properties::deleteSelectedTrackers(){
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(){
std::vector<float> fp;
try{

2
src/properties_imp.h

@ -56,6 +56,8 @@ class properties : public QDialog, private Ui::properties{ @@ -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);

Loading…
Cancel
Save