Browse Source

Implement 'Error' and 'Warning' views in the tracker list. Closes #1077. Partially implements #33.

adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
8420559e05
  1. 21
      src/core/qtlibtorrent/qbtsession.cpp
  2. 4
      src/core/qtlibtorrent/qbtsession.h
  3. 3
      src/gui/mainwindow.cpp
  4. 77
      src/gui/transferlistfilterswidget.cpp
  5. 12
      src/gui/transferlistfilterswidget.h

21
src/core/qtlibtorrent/qbtsession.cpp

@ -2516,18 +2516,21 @@ void QBtSession::handleTrackerErrorAlert(libtorrent::tracker_error_alert* p) {
// Level: fatal // Level: fatal
QTorrentHandle h(p->handle); QTorrentHandle h(p->handle);
if (h.is_valid()) { if (h.is_valid()) {
const QString hash = h.hash();
// Authentication // Authentication
if (p->status_code != 401) { if (p->status_code != 401) {
qDebug("Received a tracker error for %s: %s", p->url.c_str(), p->msg.c_str()); qDebug("Received a tracker error for %s: %s", p->url.c_str(), p->msg.c_str());
const QString tracker_url = misc::toQString(p->url); const QString tracker_url = misc::toQString(p->url);
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>()); QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(hash, QHash<QString, TrackerInfos>());
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
data.last_message = misc::toQStringU(p->msg); data.last_message = misc::toQStringU(p->msg);
trackers_data.insert(tracker_url, data); trackers_data.insert(tracker_url, data);
trackersInfos[h.hash()] = trackers_data; trackersInfos[hash] = trackers_data;
} else { }
else {
emit trackerAuthenticationRequired(h); emit trackerAuthenticationRequired(h);
} }
emit trackerError(hash, misc::toQStringU(p->url));
} }
} }
@ -2536,13 +2539,15 @@ void QBtSession::handleTrackerReplyAlert(libtorrent::tracker_reply_alert* p) {
if (h.is_valid()) { if (h.is_valid()) {
qDebug("Received a tracker reply from %s (Num_peers=%d)", p->url.c_str(), p->num_peers); qDebug("Received a tracker reply from %s (Num_peers=%d)", p->url.c_str(), p->num_peers);
// Connection was successful now. Remove possible old errors // Connection was successful now. Remove possible old errors
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>()); const QString hash = h.hash();
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(hash, QHash<QString, TrackerInfos>());
const QString tracker_url = misc::toQString(p->url); const QString tracker_url = misc::toQString(p->url);
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
data.last_message = ""; // Reset error/warning message data.last_message = ""; // Reset error/warning message
data.num_peers = p->num_peers; data.num_peers = p->num_peers;
trackers_data.insert(tracker_url, data); trackers_data.insert(tracker_url, data);
trackersInfos[h.hash()] = trackers_data; trackersInfos[hash] = trackers_data;
emit trackerSuccess(hash, misc::toQStringU(p->url));
} }
} }
@ -2550,13 +2555,15 @@ void QBtSession::handleTrackerWarningAlert(libtorrent::tracker_warning_alert* p)
const QTorrentHandle h(p->handle); const QTorrentHandle h(p->handle);
if (h.is_valid()) { if (h.is_valid()) {
// Connection was successful now but there is a warning message // Connection was successful now but there is a warning message
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>()); const QString hash = h.hash();
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(hash, QHash<QString, TrackerInfos>());
const QString tracker_url = misc::toQString(p->url); const QString tracker_url = misc::toQString(p->url);
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
data.last_message = misc::toQStringU(p->msg); // Store warning message data.last_message = misc::toQStringU(p->msg); // Store warning message
trackers_data.insert(tracker_url, data); trackers_data.insert(tracker_url, data);
trackersInfos[h.hash()] = trackers_data; trackersInfos[hash] = trackers_data;
qDebug("Received a tracker warning from %s: %s", p->url.c_str(), p->msg.c_str()); qDebug("Received a tracker warning from %s: %s", p->url.c_str(), p->msg.c_str());
emit trackerWarning(hash, misc::toQStringU(p->url));
} }
} }

4
src/core/qtlibtorrent/qbtsession.h

@ -274,7 +274,9 @@ signals:
void resumedTorrent(const QTorrentHandle& h); void resumedTorrent(const QTorrentHandle& h);
void finishedTorrent(const QTorrentHandle& h); void finishedTorrent(const QTorrentHandle& h);
void fullDiskError(const QTorrentHandle& h, QString msg); void fullDiskError(const QTorrentHandle& h, QString msg);
void trackerError(const QString &hash, QString time, QString msg); void trackerSuccess(const QString &hash, const QString &tracker);
void trackerError(const QString &hash, const QString &tracker);
void trackerWarning(const QString &hash, const QString &tracker);
void trackerAuthenticationRequired(const QTorrentHandle& h); void trackerAuthenticationRequired(const QTorrentHandle& h);
void newDownloadedTorrent(QString path, QString url); void newDownloadedTorrent(QString path, QString url);
void newDownloadedTorrentFromRss(QString url); void newDownloadedTorrentFromRss(QString url);

3
src/gui/mainwindow.cpp

@ -220,6 +220,9 @@ MainWindow::MainWindow(QWidget *parent)
connect(QBtSession::instance(), SIGNAL(trackersAdded(const QStringList &, const QString &)), transferListFilters, SLOT(addTrackers(const QStringList &, const QString &))); connect(QBtSession::instance(), SIGNAL(trackersAdded(const QStringList &, const QString &)), transferListFilters, SLOT(addTrackers(const QStringList &, const QString &)));
connect(QBtSession::instance(), SIGNAL(trackerlessChange(bool, const QString &)), transferListFilters, SLOT(changeTrackerless(bool, const QString &))); connect(QBtSession::instance(), SIGNAL(trackerlessChange(bool, const QString &)), transferListFilters, SLOT(changeTrackerless(bool, const QString &)));
connect(QBtSession::instance(), SIGNAL(reloadTrackersAndUrlSeeds(const QTorrentHandle &)), properties, SLOT(loadTrackers(const QTorrentHandle &))); connect(QBtSession::instance(), SIGNAL(reloadTrackersAndUrlSeeds(const QTorrentHandle &)), properties, SLOT(loadTrackers(const QTorrentHandle &)));
connect(QBtSession::instance(), SIGNAL(trackerSuccess(const QString &, const QString &)), transferListFilters, SIGNAL(trackerSuccess(const QString &, const QString &)));
connect(QBtSession::instance(), SIGNAL(trackerError(const QString &, const QString &)), transferListFilters, SIGNAL(trackerError(const QString &, const QString &)));
connect(QBtSession::instance(), SIGNAL(trackerWarning(const QString &, const QString &)), transferListFilters, SIGNAL(trackerWarning(const QString &, const QString &)));
vboxLayout->addWidget(tabs); vboxLayout->addWidget(tabs);

77
src/gui/transferlistfilterswidget.cpp

@ -419,6 +419,12 @@ TrackerFiltersList::TrackerFiltersList(QWidget *parent, TransferListWidget *tran
QListWidgetItem *noTracker = new QListWidgetItem(this); QListWidgetItem *noTracker = new QListWidgetItem(this);
noTracker->setData(Qt::DisplayRole, QVariant(tr("Trackerless (0)"))); noTracker->setData(Qt::DisplayRole, QVariant(tr("Trackerless (0)")));
noTracker->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("network-server")); noTracker->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("network-server"));
QListWidgetItem *errorTracker = new QListWidgetItem(this);
errorTracker->setData(Qt::DisplayRole, QVariant(tr("Error (0)")));
errorTracker->setData(Qt::DecorationRole, style()->standardIcon(QStyle::SP_MessageBoxCritical));
QListWidgetItem *warningTracker = new QListWidgetItem(this);
warningTracker->setData(Qt::DisplayRole, QVariant(tr("Warning (0)")));
warningTracker->setData(Qt::DecorationRole, style()->standardIcon(QStyle::SP_MessageBoxWarning));
m_trackers.insert("", QStringList()); m_trackers.insert("", QStringList());
setCurrentRow(0, QItemSelectionModel::SelectCurrent); setCurrentRow(0, QItemSelectionModel::SelectCurrent);
@ -473,8 +479,8 @@ void TrackerFiltersList::addItem(const QString &tracker, const QString &hash)
return; return;
} }
Q_ASSERT(count() >= 2); Q_ASSERT(count() >= 4);
for (int i = 2; i<count(); ++i) { for (int i = 4; i<count(); ++i) {
bool less = false; bool less = false;
if (!(misc::naturalSort(host, item(i)->text(), less))) if (!(misc::naturalSort(host, item(i)->text(), less)))
less = (host.localeAwareCompare(item(i)->text()) < 0); less = (host.localeAwareCompare(item(i)->text()) < 0);
@ -500,6 +506,8 @@ void TrackerFiltersList::removeItem(const QString &tracker, const QString &hash)
tmp.removeAll(hash); tmp.removeAll(hash);
if (host != "") { if (host != "") {
// Remove from 'Error' and 'Warning' view
trackerSuccess(hash, tracker);
row = rowFromTracker(host); row = rowFromTracker(host);
trackerItem = item(row); trackerItem = item(row);
if (tmp.empty()) { if (tmp.empty()) {
@ -531,6 +539,62 @@ void TrackerFiltersList::changeTrackerless(bool trackerless, const QString &hash
removeItem("", hash); removeItem("", hash);
} }
void TrackerFiltersList::trackerSuccess(const QString &hash, const QString &tracker)
{
QStringList errored = m_errors.value(hash);
QStringList warned = m_warnings.value(hash);
if (errored.contains(tracker)) {
errored.removeAll(tracker);
if (errored.empty()) {
m_errors.remove(hash);
item(2)->setText(tr("Error (%1)").arg(m_errors.size()));
if (currentRow() == 2)
applyFilter(2);
}
}
if (warned.contains(tracker)) {
warned.removeAll(tracker);
if (warned.empty()) {
m_warnings.remove(hash);
item(3)->setText(tr("Warning (%1)").arg(m_warnings.size()));
if (currentRow() == 3)
applyFilter(3);
}
}
}
void TrackerFiltersList::trackerError(const QString &hash, const QString &tracker)
{
QStringList trackers = m_errors.value(hash);
if (trackers.contains(tracker))
return;
trackers.append(tracker);
m_errors.insert(hash, trackers);
item(2)->setText(tr("Error (%1)").arg(m_errors.size()));
if (currentRow() == 2)
applyFilter(2);
}
void TrackerFiltersList::trackerWarning(const QString &hash, const QString &tracker)
{
QStringList trackers = m_warnings.value(hash);
if (trackers.contains(tracker))
return;
trackers.append(tracker);
m_warnings.insert(hash, trackers);
item(3)->setText(tr("Warning (%1)").arg(m_warnings.size()));
if (currentRow() == 3)
applyFilter(3);
}
void TrackerFiltersList::handleFavicoDownload(const QString& url, const QString& filePath) void TrackerFiltersList::handleFavicoDownload(const QString& url, const QString& filePath)
{ {
QString host = getHost(url); QString host = getHost(url);
@ -637,7 +701,7 @@ QString TrackerFiltersList::trackerFromRow(int row) const
int TrackerFiltersList::rowFromTracker(const QString &tracker) const int TrackerFiltersList::rowFromTracker(const QString &tracker) const
{ {
Q_ASSERT(!tracker.isEmpty()); Q_ASSERT(!tracker.isEmpty());
for (int i = 2; i<count(); ++i) for (int i = 4; i<count(); ++i)
if (tracker == trackerFromRow(i)) return i; if (tracker == trackerFromRow(i)) return i;
return -1; return -1;
} }
@ -658,6 +722,10 @@ QStringList TrackerFiltersList::getHashes(int row)
{ {
if (row == 1) if (row == 1)
return m_trackers.value(""); return m_trackers.value("");
else if (row == 2)
return m_errors.keys();
else if (row == 3)
return m_warnings.keys();
else else
return m_trackers.value(trackerFromRow(row)); return m_trackers.value(trackerFromRow(row));
} }
@ -704,6 +772,9 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi
connect(labelLabel, SIGNAL(toggled(bool)), pref, SLOT(setLabelFilterState(const bool))); connect(labelLabel, SIGNAL(toggled(bool)), pref, SLOT(setLabelFilterState(const bool)));
connect(trackerLabel, SIGNAL(toggled(bool)), trackerFilters, SLOT(toggleFilter(bool))); connect(trackerLabel, SIGNAL(toggled(bool)), trackerFilters, SLOT(toggleFilter(bool)));
connect(trackerLabel, SIGNAL(toggled(bool)), pref, SLOT(setTrackerFilterState(const bool))); connect(trackerLabel, SIGNAL(toggled(bool)), pref, SLOT(setTrackerFilterState(const bool)));
connect(this, SIGNAL(trackerSuccess(const QString &, const QString &)), trackerFilters, SLOT(trackerSuccess(const QString &, const QString &)));
connect(this, SIGNAL(trackerError(const QString &, const QString &)), trackerFilters, SLOT(trackerError(const QString &, const QString &)));
connect(this, SIGNAL(trackerWarning(const QString &, const QString &)), trackerFilters, SLOT(trackerWarning(const QString &, const QString &)));
} }
void TransferListFiltersWidget::resizeEvent(QResizeEvent *event) void TransferListFiltersWidget::resizeEvent(QResizeEvent *event)

12
src/gui/transferlistfilterswidget.h

@ -133,6 +133,11 @@ public:
void removeItem(const QString &tracker, const QString &hash); void removeItem(const QString &tracker, const QString &hash);
void changeTrackerless(bool trackerless, const QString &hash); void changeTrackerless(bool trackerless, const QString &hash);
public slots:
void trackerSuccess(const QString &hash, const QString &tracker);
void trackerError(const QString &hash, const QString &tracker);
void trackerWarning(const QString &hash, const QString &tracker);
private slots: private slots:
void handleFavicoDownload(const QString &url, const QString &filePath); void handleFavicoDownload(const QString &url, const QString &filePath);
void handleFavicoFailure(const QString &url, const QString &reason); void handleFavicoFailure(const QString &url, const QString &reason);
@ -151,6 +156,8 @@ private:
private: private:
QHash<QString, QStringList> m_trackers; QHash<QString, QStringList> m_trackers;
QHash<QString, QStringList> m_errors;
QHash<QString, QStringList> m_warnings;
DownloadThread *m_downloader; DownloadThread *m_downloader;
QStringList m_iconPaths; QStringList m_iconPaths;
int m_totalTorrents; int m_totalTorrents;
@ -168,6 +175,11 @@ public slots:
void removeTrackers(const QStringList &trackers, const QString &hash); void removeTrackers(const QStringList &trackers, const QString &hash);
void changeTrackerless(bool trackerless, const QString &hash); void changeTrackerless(bool trackerless, const QString &hash);
signals:
void trackerSuccess(const QString &hash, const QString &tracker);
void trackerError(const QString &hash, const QString &tracker);
void trackerWarning(const QString &hash, const QString &tracker);
protected: protected:
virtual void resizeEvent(QResizeEvent *event); virtual void resizeEvent(QResizeEvent *event);

Loading…
Cancel
Save