mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-24 18:44:52 +08:00
- Update trackers edition code
- current tracker is now updated regularly when properties are displayed
This commit is contained in:
parent
f839d6fe41
commit
3e36cd3c46
1
TODO
1
TODO
@ -43,7 +43,6 @@
|
||||
- Translations update
|
||||
- Optimize and cleanup code
|
||||
- document url seeds
|
||||
- Improve trackers edition code
|
||||
- check painting problems in dl list
|
||||
- Wait for some bug fixes in libtorrent :
|
||||
- upload/download limit per torrent
|
||||
|
10
src/misc.h
10
src/misc.h
@ -31,6 +31,9 @@
|
||||
#include <QPair>
|
||||
#include <QThread>
|
||||
|
||||
#include <libtorrent/torrent_info.hpp>
|
||||
using namespace libtorrent;
|
||||
|
||||
#define MAX_CHAR_TMP 128
|
||||
|
||||
/* Miscellaneaous functions that can be useful */
|
||||
@ -144,6 +147,13 @@ class misc : public QObject{
|
||||
return QString();
|
||||
}
|
||||
|
||||
static void fixTrackersTiers(std::vector<announce_entry> trackers){
|
||||
unsigned int nbTrackers = trackers.size();
|
||||
for(unsigned int i=0; i<nbTrackers; ++i){
|
||||
trackers[i].tier = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Insertion sort, used instead of bubble sort because it is
|
||||
// approx. 5 times faster.
|
||||
template <class T> static void insertSort(QList<QPair<int, T> > &list, const QPair<int, T>& value, Qt::SortOrder sortOrder){
|
||||
|
@ -264,7 +264,8 @@ void properties::loadTrackers(){
|
||||
//Trackers
|
||||
std::vector<announce_entry> trackers = h.trackers();
|
||||
trackersURLS->clear();
|
||||
for(unsigned int i=0; i<trackers.size(); ++i){
|
||||
unsigned int nbTrackers = trackers.size();
|
||||
for(unsigned int i=0; i<nbTrackers; ++i){
|
||||
trackersURLS->addItem(QString(trackers[i].url.c_str()));
|
||||
}
|
||||
torrent_status torrentStatus = h.status();
|
||||
@ -311,8 +312,9 @@ void properties::askForTracker(){
|
||||
// Add the tracker to the list
|
||||
std::vector<announce_entry> trackers = h.trackers();
|
||||
announce_entry new_tracker(trackerUrl.toStdString());
|
||||
new_tracker.tier = trackersURLS->count();
|
||||
new_tracker.tier = 0; // Will be fixed a bit later
|
||||
trackers.push_back(new_tracker);
|
||||
misc::fixTrackersTiers(trackers);
|
||||
h.replace_trackers(trackers);
|
||||
h.force_reannounce();
|
||||
// Reload Trackers
|
||||
@ -379,12 +381,14 @@ void properties::riseSelectedTracker(){
|
||||
selectedItems = trackersURLS->selectedItems();
|
||||
QListWidgetItem *item;
|
||||
bool change = false;
|
||||
unsigned int nbTrackers = trackers.size();
|
||||
foreach(item, selectedItems){
|
||||
QString url = item->text();
|
||||
for(i=0; i<trackers.size(); ++i){
|
||||
for(i=0; i<nbTrackers; ++i){
|
||||
if(QString(trackers.at(i).url.c_str()) == url){
|
||||
if(trackers[i].tier>0 && i != 0){
|
||||
trackers[i].tier -= 1;
|
||||
qDebug("Asked to rise %s", trackers.at(i).url.c_str());
|
||||
qDebug("its tier was %d and will become %d", trackers[i].tier, trackers[i].tier-1);
|
||||
if(i > 0){
|
||||
announce_entry tmp = trackers[i];
|
||||
trackers[i] = trackers[i-1];
|
||||
trackers[i-1] = tmp;
|
||||
@ -395,6 +399,7 @@ void properties::riseSelectedTracker(){
|
||||
}
|
||||
}
|
||||
if(change){
|
||||
misc::fixTrackersTiers(trackers);
|
||||
h.replace_trackers(trackers);
|
||||
h.force_reannounce();
|
||||
// Reload Trackers
|
||||
@ -410,12 +415,14 @@ void properties::lowerSelectedTracker(){
|
||||
selectedItems = trackersURLS->selectedItems();
|
||||
QListWidgetItem *item;
|
||||
bool change = false;
|
||||
unsigned int nbTrackers = trackers.size();
|
||||
foreach(item, selectedItems){
|
||||
QString url = item->text();
|
||||
for(i=0; i<trackers.size(); ++i){
|
||||
for(i=0; i<nbTrackers; ++i){
|
||||
if(QString(trackers.at(i).url.c_str()) == url){
|
||||
if(i != trackers.size()-1){
|
||||
trackers[i].tier += 1;
|
||||
qDebug("Asked to lower %s", trackers.at(i).url.c_str());
|
||||
qDebug("its tier was %d and will become %d", trackers[i].tier, trackers[i].tier+1);
|
||||
if(i < nbTrackers-1){
|
||||
announce_entry tmp = trackers[i];
|
||||
trackers[i] = trackers[i+1];
|
||||
trackers[i+1] = tmp;
|
||||
@ -426,6 +433,7 @@ void properties::lowerSelectedTracker(){
|
||||
}
|
||||
}
|
||||
if(change){
|
||||
misc::fixTrackersTiers(trackers);
|
||||
h.replace_trackers(trackers);
|
||||
h.force_reannounce();
|
||||
// Reload Trackers
|
||||
@ -447,6 +455,14 @@ void properties::updateInfos(){
|
||||
close();
|
||||
}
|
||||
loadTrackersErrors();
|
||||
// Update current tracker
|
||||
torrent_status torrentStatus = h.status();
|
||||
QString tracker = QString(torrentStatus.current_tracker.c_str()).trimmed();
|
||||
if(!tracker.isEmpty()){
|
||||
trackerURL->setText(tracker);
|
||||
}else{
|
||||
trackerURL->setText(tr("None - Unreachable?"));
|
||||
}
|
||||
}
|
||||
|
||||
// Set the color of a row in data model
|
||||
|
Loading…
Reference in New Issue
Block a user