From 21aabfdcb5acc5c6380ac821099f5939efb77931 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 5 Oct 2022 00:39:41 +0800 Subject: [PATCH 1/2] Clean up code --- src/gui/transferlistfilterswidget.cpp | 8 ++------ src/gui/transferlistfilterswidget.h | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/gui/transferlistfilterswidget.cpp b/src/gui/transferlistfilterswidget.cpp index b3c80a010..8bfefe9ed 100644 --- a/src/gui/transferlistfilterswidget.cpp +++ b/src/gui/transferlistfilterswidget.cpp @@ -66,11 +66,8 @@ namespace QString getScheme(const QString &tracker) { - const QUrl url {tracker}; - QString scheme = url.scheme(); - if (scheme.isEmpty()) - scheme = u"http"_qs; - return scheme; + const QString scheme = QUrl(tracker).scheme(); + return !scheme.isEmpty() ? scheme : u"http"_qs; } QString getHost(const QString &tracker) @@ -360,7 +357,6 @@ void StatusFilterWidget::torrentAboutToBeDeleted(BitTorrent::Torrent *const torr TrackerFiltersList::TrackerFiltersList(QWidget *parent, TransferListWidget *transferList, const bool downloadFavicon) : BaseFilterWidget(parent, transferList) - , m_totalTorrents(0) , m_downloadTrackerFavicon(downloadFavicon) { auto *allTrackers = new QListWidgetItem(this); diff --git a/src/gui/transferlistfilterswidget.h b/src/gui/transferlistfilterswidget.h index f911b2814..4745d6540 100644 --- a/src/gui/transferlistfilterswidget.h +++ b/src/gui/transferlistfilterswidget.h @@ -157,12 +157,12 @@ private: QListWidgetItem *item = nullptr; }; - QHash m_trackers; + QHash m_trackers; // QHash> m_errors; // QHash> m_warnings; // PathList m_iconPaths; - int m_totalTorrents; - bool m_downloadTrackerFavicon; + int m_totalTorrents = 0; + bool m_downloadTrackerFavicon = false; }; class TransferListFiltersWidget final : public QFrame From 6fa4305abafe6ab0564381d4dd15c9139a009b29 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 5 Oct 2022 00:59:18 +0800 Subject: [PATCH 2/2] Fix wrong 'tracker error' count This happens when a torrent contains some tracker URLs that share the same domain. Closes #17808. --- src/gui/transferlistfilterswidget.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gui/transferlistfilterswidget.cpp b/src/gui/transferlistfilterswidget.cpp index 8bfefe9ed..448217cfa 100644 --- a/src/gui/transferlistfilterswidget.cpp +++ b/src/gui/transferlistfilterswidget.cpp @@ -70,11 +70,14 @@ namespace return !scheme.isEmpty() ? scheme : u"http"_qs; } - QString getHost(const QString &tracker) + QString getHost(const QString &url) { // We want the domain + tld. Subdomains should be disregarded - const QUrl url {tracker}; - const QString host {url.host()}; + // If failed to parse the domain or IP address, original input should be returned + + const QString host = QUrl(url).host(); + if (host.isEmpty()) + return url; // host is in IP format if (!QHostAddress(host).isNull()) @@ -505,10 +508,8 @@ void TrackerFiltersList::addItems(const QString &trackerURL, const QVector torrentIDs = m_trackers.value(host).torrents; - if (torrentIDs.empty()) - return; + QSet torrentIDs = m_trackers.value(host).torrents; torrentIDs.remove(id); QListWidgetItem *trackerItem = nullptr;