mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-27 08:19:30 +08:00
Cache tracker item in TrackerFilterList
This commit is contained in:
parent
30319e51e5
commit
da12daffee
@ -419,17 +419,18 @@ TrackerFiltersList::~TrackerFiltersList()
|
|||||||
void TrackerFiltersList::addItem(const QString &tracker, const BitTorrent::TorrentID &id)
|
void TrackerFiltersList::addItem(const QString &tracker, const BitTorrent::TorrentID &id)
|
||||||
{
|
{
|
||||||
const QString host {getHost(tracker)};
|
const QString host {getHost(tracker)};
|
||||||
const bool exists {m_trackers.contains(host)};
|
const auto existingDataItr = m_trackers.find(host);
|
||||||
|
const bool exists {existingDataItr != m_trackers.end()};
|
||||||
QListWidgetItem *trackerItem {nullptr};
|
QListWidgetItem *trackerItem {nullptr};
|
||||||
|
|
||||||
if (exists)
|
if (exists)
|
||||||
{
|
{
|
||||||
if (m_trackers.value(host).contains(id))
|
if (existingDataItr->torrents.contains(id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
trackerItem = item((host == NULL_HOST)
|
trackerItem = (host == NULL_HOST)
|
||||||
? TRACKERLESS_ROW
|
? item(TRACKERLESS_ROW)
|
||||||
: rowFromTracker(host));
|
: existingDataItr->item;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -441,7 +442,7 @@ void TrackerFiltersList::addItem(const QString &tracker, const BitTorrent::Torre
|
|||||||
}
|
}
|
||||||
if (!trackerItem) return;
|
if (!trackerItem) return;
|
||||||
|
|
||||||
QSet<BitTorrent::TorrentID> &torrentIDs {m_trackers[host]};
|
QSet<BitTorrent::TorrentID> &torrentIDs {m_trackers[host].torrents};
|
||||||
torrentIDs.insert(id);
|
torrentIDs.insert(id);
|
||||||
|
|
||||||
if (host == NULL_HOST)
|
if (host == NULL_HOST)
|
||||||
@ -478,13 +479,12 @@ void TrackerFiltersList::addItem(const QString &tracker, const BitTorrent::Torre
|
|||||||
void TrackerFiltersList::removeItem(const QString &trackerURL, const BitTorrent::TorrentID &id)
|
void TrackerFiltersList::removeItem(const QString &trackerURL, const BitTorrent::TorrentID &id)
|
||||||
{
|
{
|
||||||
const QString host = getHost(trackerURL);
|
const QString host = getHost(trackerURL);
|
||||||
QSet<BitTorrent::TorrentID> torrentIDs = m_trackers.value(host);
|
QSet<BitTorrent::TorrentID> torrentIDs = m_trackers.value(host).torrents;
|
||||||
if (torrentIDs.empty())
|
if (torrentIDs.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
torrentIDs.remove(id);
|
torrentIDs.remove(id);
|
||||||
|
|
||||||
int row = 0;
|
|
||||||
QListWidgetItem *trackerItem = nullptr;
|
QListWidgetItem *trackerItem = nullptr;
|
||||||
|
|
||||||
if (!host.isEmpty())
|
if (!host.isEmpty())
|
||||||
@ -518,12 +518,11 @@ void TrackerFiltersList::removeItem(const QString &trackerURL, const BitTorrent:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
row = rowFromTracker(host);
|
trackerItem = m_trackers.value(host).item;
|
||||||
trackerItem = item(row);
|
|
||||||
|
|
||||||
if (torrentIDs.empty())
|
if (torrentIDs.empty())
|
||||||
{
|
{
|
||||||
if (currentRow() == row)
|
if (currentItem() == trackerItem)
|
||||||
setCurrentRow(0, QItemSelectionModel::SelectCurrent);
|
setCurrentRow(0, QItemSelectionModel::SelectCurrent);
|
||||||
delete trackerItem;
|
delete trackerItem;
|
||||||
m_trackers.remove(host);
|
m_trackers.remove(host);
|
||||||
@ -536,15 +535,14 @@ void TrackerFiltersList::removeItem(const QString &trackerURL, const BitTorrent:
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
row = 1;
|
|
||||||
trackerItem = item(TRACKERLESS_ROW);
|
trackerItem = item(TRACKERLESS_ROW);
|
||||||
trackerItem->setText(tr("Trackerless (%1)").arg(torrentIDs.size()));
|
trackerItem->setText(tr("Trackerless (%1)").arg(torrentIDs.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_trackers.insert(host, torrentIDs);
|
m_trackers.insert(host, {torrentIDs, trackerItem});
|
||||||
|
|
||||||
if (currentRow() == row)
|
if (currentItem() == trackerItem)
|
||||||
applyFilter(row);
|
applyFilter(currentRow());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackerFiltersList::changeTrackerless(const bool trackerless, const BitTorrent::TorrentID &id)
|
void TrackerFiltersList::changeTrackerless(const bool trackerless, const BitTorrent::TorrentID &id)
|
||||||
@ -758,13 +756,13 @@ QSet<BitTorrent::TorrentID> TrackerFiltersList::getTorrentIDs(const int row) con
|
|||||||
switch (row)
|
switch (row)
|
||||||
{
|
{
|
||||||
case TRACKERLESS_ROW:
|
case TRACKERLESS_ROW:
|
||||||
return m_trackers.value(NULL_HOST);
|
return m_trackers.value(NULL_HOST).torrents;
|
||||||
case ERROR_ROW:
|
case ERROR_ROW:
|
||||||
return {m_errors.keyBegin(), m_errors.keyEnd()};
|
return {m_errors.keyBegin(), m_errors.keyEnd()};
|
||||||
case WARNING_ROW:
|
case WARNING_ROW:
|
||||||
return {m_warnings.keyBegin(), m_warnings.keyEnd()};
|
return {m_warnings.keyBegin(), m_warnings.keyEnd()};
|
||||||
default:
|
default:
|
||||||
return m_trackers.value(trackerFromRow(row));
|
return m_trackers.value(trackerFromRow(row)).torrents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,13 @@ private:
|
|||||||
QSet<BitTorrent::TorrentID> getTorrentIDs(int row) const;
|
QSet<BitTorrent::TorrentID> getTorrentIDs(int row) const;
|
||||||
void downloadFavicon(const QString &url);
|
void downloadFavicon(const QString &url);
|
||||||
|
|
||||||
QHash<QString, QSet<BitTorrent::TorrentID>> m_trackers; // <tracker host, torrent IDs>
|
struct TrackerData
|
||||||
|
{
|
||||||
|
QSet<BitTorrent::TorrentID> torrents;
|
||||||
|
QListWidgetItem *item = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
QHash<QString, TrackerData> m_trackers;
|
||||||
QHash<BitTorrent::TorrentID, QSet<QString>> m_errors; // <torrent ID, tracker hosts>
|
QHash<BitTorrent::TorrentID, QSet<QString>> m_errors; // <torrent ID, tracker hosts>
|
||||||
QHash<BitTorrent::TorrentID, QSet<QString>> m_warnings; // <torrent ID, tracker hosts>
|
QHash<BitTorrent::TorrentID, QSet<QString>> m_warnings; // <torrent ID, tracker hosts>
|
||||||
PathList m_iconPaths;
|
PathList m_iconPaths;
|
||||||
|
Loading…
Reference in New Issue
Block a user