From 0dd84c37a1d68d55e3c75cbb5a3b46ff85faa623 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 15 May 2008 19:48:15 +0000 Subject: [PATCH] - Commit some tracker changes. Work is not completed and this is probably buggy. I will complete this later. --- src/bittorrent.cpp | 30 +- src/bittorrent.h | 4 +- src/properties.ui | 714 ++++++++++++++++++----------------------- src/properties_imp.cpp | 28 +- src/properties_imp.h | 1 - 5 files changed, 348 insertions(+), 429 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 37be3cb16..0e2c35bd0 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1163,18 +1163,30 @@ void bittorrent::readAlerts() { // Level: fatal QTorrentHandle h(p->handle); if(h.is_valid()){ - QString hash = h.hash(); - QList > errors = trackersErrors.value(hash, QList >()); - if(errors.size() > MAX_TRACKER_ERRORS) - errors.removeAt(0); - errors << QPair(QTime::currentTime().toString("hh:mm:ss"), QString::fromUtf8(a->msg().c_str())); - trackersErrors[hash] = errors; // Authentication - if(p->status_code == 401) { + if(p->status_code != 401) { + QString hash = h.hash(); + qDebug("Received a tracker error for %s", (const char*)h.current_tracker().toUtf8()); + QHash errors = trackersErrors.value(hash, QHash()); + // p->url requires at least libtorrent v0.13.1 + errors[misc::toQString(p->url)] = QString::fromUtf8(a->msg().c_str()); + trackersErrors[hash] = errors; + } else { emit trackerAuthenticationRequired(h); } } } + else if (tracker_reply_alert* p = dynamic_cast(a.get())) { + QTorrentHandle h(p->handle); + if(h.is_valid()){ + qDebug("Received a tracker reply from %s", (const char*)h.current_tracker().toUtf8()); + QString hash = h.hash(); + QHash errors = trackersErrors.value(hash, QHash()); + // p->url requires at least libtorrent v0.13.1 + errors.remove(h.current_tracker()); + trackersErrors[hash] = errors; + } + } else if (portmap_error_alert* p = dynamic_cast(a.get())) { emit UPnPError(QString(p->msg().c_str())); } @@ -1218,8 +1230,8 @@ void bittorrent::readAlerts() { } } -QList > bittorrent::getTrackersErrors(QString hash) const{ - return trackersErrors.value(hash, QList >()); +QHash bittorrent::getTrackersErrors(QString hash) const{ + return trackersErrors.value(hash, QHash()); } QStringList bittorrent::getTorrentsToPauseAfterChecking() const{ diff --git a/src/bittorrent.h b/src/bittorrent.h index 54333c112..3a10560b5 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -54,7 +54,7 @@ class bittorrent : public QObject{ QHash TorrentsStartTime; QHash TorrentsStartData; QHash > ratioData; - QHash > > trackersErrors; + QHash > trackersErrors; deleteThread *deleter; QStringList finishedTorrents; QStringList unfinishedTorrents; @@ -86,7 +86,7 @@ class bittorrent : public QObject{ qlonglong getETA(QString hash) const; float getRealRatio(QString hash) const; session* getSession() const; - QList > getTrackersErrors(QString hash) const; + QHash getTrackersErrors(QString hash) const; QStringList getFinishedTorrents() const; QStringList getUnfinishedTorrents() const; bool isFinished(QString hash) const; diff --git a/src/properties.ui b/src/properties.ui index 159d3e63b..0f16405d3 100644 --- a/src/properties.ui +++ b/src/properties.ui @@ -31,7 +31,7 @@ - 0 + 1 @@ -573,412 +573,322 @@ Trackers - - 6 - - - 9 - - - 9 - - - 9 - - - 9 - - - - - 0 - 0 - + + + 6 - - - 0 - 170 - + + 0 - - - Sans Serif - 9 - 75 - false - true - false - false - + + 0 - - Tracker + + 0 - - - 6 - - - 9 - - - 9 - - - 9 - - - 9 - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - Sans Serif - 9 - 50 - false - false - false - false - - - - Trackers: - - - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - - - - - - - - - 24 - 24 - - - - - 24 - 24 - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - Sans Serif - 9 - 50 - false - false - false - false - - - - Errors: - - - - - - - QTextEdit::NoWrap - - - - - - - - - 6 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 16777215 - 16 - - - - - Sans Serif - 9 - 50 - false - false - false - false - - - - Current tracker: - - - - - - - - 16777215 - 16 - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - + + 0 + + + + + + Sans Serif + 9 + 50 + false + false + false + false + + + + Trackers: + + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + + + + + + + + + 24 + 24 + + + + + 24 + 24 + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 16777215 + 16 + + + + + Sans Serif + 9 + 50 + false + false + false + false + + + + Current tracker: + + + + + + + + 16777215 + 16 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Minimum + + + + 20 + 40 + + + diff --git a/src/properties_imp.cpp b/src/properties_imp.cpp index 98e90347e..38418026f 100644 --- a/src/properties_imp.cpp +++ b/src/properties_imp.cpp @@ -99,7 +99,6 @@ properties::properties(QWidget *parent, bittorrent *BTSession, QTorrentHandle &h } } shareRatio->setText(QString(QByteArray::number(ratio, 'f', 1))); - loadTrackersErrors(); std::vector fp; h.file_progress(fp); int *prioritiesTab = loadPiecesPriorities(); @@ -277,19 +276,6 @@ void properties::updatePriorities(QStandardItem *item) { // get future updates connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*))); } - -void properties::loadTrackersErrors(){ - // Tracker Errors - QList > errors = BTSession->getTrackersErrors(hash); - unsigned int nbTrackerErrors = errors.size(); - trackerErrors->clear(); - for(unsigned int i=0; i < nbTrackerErrors; ++i){ - QPair pair = errors.at(i); - trackerErrors->append(QString::fromUtf8("")+pair.first+QString::fromUtf8(" - ")+pair.second+QString::fromUtf8("")); - } - if(!nbTrackerErrors) - trackerErrors->append(tr("None", "i.e: No error message")); -} void properties::loadWebSeeds(){ QString url_seed; @@ -449,9 +435,19 @@ void properties::loadTrackers(){ //Trackers std::vector trackers = h.trackers(); trackersURLS->clear(); + QHash errors = BTSession->getTrackersErrors(h.hash()); unsigned int nbTrackers = trackers.size(); for(unsigned int i=0; iaddItem(misc::toQString(trackers[i].url)); + QString current_tracker = misc::toQString(trackers[i].url); + QListWidgetItem *item = new QListWidgetItem(current_tracker, trackersURLS); + // IsThere any errors ? + if(errors.contains(current_tracker)) { + item->setForeground(QBrush(QColor("red"))); + // Set tooltip + item->setToolTip(errors[current_tracker]); + } else { + item->setForeground(QBrush(QColor("green"))); + } } QString tracker = h.current_tracker().trimmed(); if(!tracker.isEmpty()){ @@ -633,6 +629,8 @@ void properties::updateInfos(){ }else{ trackerURL->setText(tr("None - Unreachable?")); } + // XXX: This causes selection problems + //loadTrackers(); }catch(invalid_handle e){ // torrent was removed, closing properties close(); diff --git a/src/properties_imp.h b/src/properties_imp.h index e6cd309d0..ed80c7212 100644 --- a/src/properties_imp.h +++ b/src/properties_imp.h @@ -72,7 +72,6 @@ class properties : public QDialog, private Ui::properties{ void saveWebSeeds(); void loadWebSeedsFromFile(); void deleteSelectedUrlSeeds(); - void loadTrackersErrors(); void addFilesToTree(torrent_file *root, QStandardItem *parent); void updateChildrenPriority(QStandardItem *item, int priority); void updateParentsPriority(QStandardItem *item, int priority);