Update trackersfilterwidget.cpp

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.
This commit is contained in:
AdKiller 2025-05-27 13:12:33 +02:00 committed by GitHub
commit dcde896d1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<BitTorrent::TorrentID> 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<BitTorrent::TrackerEntryStatus> &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;
}
}