From dcde896d1d25aae91e8c219e5c7d5e46a666e431 Mon Sep 17 00:00:00 2001 From: AdKiller Date: Tue, 27 May 2025 13:12:33 +0200 Subject: [PATCH] Update trackersfilterwidget.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces an "Only HTTP" special filter row in the Trackers sidebar of the Transfer List. The following changes were made: Added ONLY_HTTP_ROW to the TRACKER_FILTER_ROW enum This new row allows filtering torrents that use only HTTP (not HTTPS or other protocols) trackers. Displayed a dedicated sidebar entry labeled "Only HTTP" The sidebar now includes a "Only HTTP" row, grouped with the other special rows such as "All", "Trackerless", "Tracker error", "Other error", and "Warning". Provided a translation string for the new row Added an entry in getFormatStringForRow() to display the count of matching torrents in the "Only HTTP" row. Stubbed out the filtering logic in getTorrentIDs() Added a placeholder for returning the set of torrents that should appear in the "Only HTTP" row. Actual filtering logic to select torrents with only HTTP trackers will be implemented in a subsequent commit. Added a helper function (isOnlyHttpTrackers) Introduced a static method to determine if a given torrent’s tracker list consists solely of HTTP trackers, to be used by the filtering implementation. These changes lay the groundwork for supporting HTTP-only tracker filtering in the UI, with the actual selection logic to be completed in a follow-up commit. The code follows qBittorrent’s coding style and ensures clarity and future extensibility. --- .../trackersfilterwidget.cpp | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/gui/transferlistfilters/trackersfilterwidget.cpp b/src/gui/transferlistfilters/trackersfilterwidget.cpp index 60f8a08b8..835f8957a 100644 --- a/src/gui/transferlistfilters/trackersfilterwidget.cpp +++ b/src/gui/transferlistfilters/trackersfilterwidget.cpp @@ -57,7 +57,7 @@ namespace TRACKERERROR_ROW, OTHERERROR_ROW, WARNING_ROW, - + ONLY_HTTP_ROW, // Only HTTP special row NUM_SPECIAL_ROWS }; @@ -97,12 +97,15 @@ namespace return TrackersFilterWidget::tr("All (%1)", "this is for the tracker filter"); case TRACKERLESS_ROW: return TrackersFilterWidget::tr("Trackerless (%1)"); + case ONLY_HTTP_ROW: + return TrackersFilterWidget::tr("Only HTTP (%1)"); case TRACKERERROR_ROW: return TrackersFilterWidget::tr("Tracker error (%1)"); case OTHERERROR_ROW: return TrackersFilterWidget::tr("Other error (%1)"); case WARNING_ROW: return TrackersFilterWidget::tr("Warning (%1)"); + default: return {}; } @@ -141,6 +144,10 @@ TrackersFilterWidget::TrackersFilterWidget(QWidget *parent, TransferListWidget * warningItem->setData(Qt::DisplayRole, formatItemText(WARNING_ROW, 0)); warningItem->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(u"tracker-warning"_s, u"dialog-warning"_s)); + auto *onlyHttpItem = new QListWidgetItem(this); + onlyHttpItem->setData(Qt::DisplayRole, formatItemText(ONLY_HTTP_ROW, 0)); + onlyHttpItem->setData(Qt::DecorationRole, UIThemeManager::instance()->getIcon(u"trackers"_s, u"network-server"_s)); + m_trackers[NULL_HOST] = {{}, trackerlessItem}; handleTorrentsLoaded(BitTorrent::Session::instance()->torrents()); @@ -717,7 +724,27 @@ QSet TrackersFilterWidget::getTorrentIDs(const int row) c return {m_trackerErrors.keyBegin(), m_trackerErrors.keyEnd()}; case WARNING_ROW: return {m_warnings.keyBegin(), m_warnings.keyEnd()}; + case ONLY_HTTP_ROW: + // Placeholder: implement the "only HTTP" logic later + return {}; // TODO: Populate with IDs of torrents having only HTTP trackers default: return m_trackers.value(trackerFromRow(row)).torrents; } + + bool TrackersFilterWidget::isOnlyHttpTrackers(const QList &trackers) +{ + if (trackers.isEmpty()) + return false; + + bool anyHttps = false; + for (const auto &tracker : trackers) { + const QString scheme = QUrl(tracker.url).scheme(); + if (scheme.compare(u"https", Qt::CaseInsensitive) == 0) + anyHttps = true; + else if (!scheme.isEmpty() && scheme.compare(u"http", Qt::CaseInsensitive) != 0) + return false; + } + return !anyHttps; +} + }