Revamp tracker list widget

Internally redesign tracker list widget using Qt Model/View architecture.
Make tracker list sortable by any column.

PR #19633.
Closes #261.
This commit is contained in:
Vladimir Golovnev 2023-10-03 08:42:05 +03:00 committed by GitHub
parent 70b438e6d9
commit c051ee9409
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 1786 additions and 1106 deletions

View file

@ -178,7 +178,7 @@ namespace
}
}
const int working = static_cast<int>(BitTorrent::TrackerEntry::Working);
const int working = static_cast<int>(BitTorrent::TrackerEntryStatus::Working);
const int disabled = 0;
const QString privateMsg {QCoreApplication::translate("TrackerListWidget", "This torrent is private")};
@ -483,57 +483,19 @@ void TorrentsController::trackersAction()
for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers()))
{
int numPeers = -1;
int numSeeds = -1;
int numLeeches = -1;
int numDownloaded = -1;
QDateTime nextAnnounceTime;
QDateTime minAnnounceTime;
QString message;
for (const auto &endpoint : tracker.stats)
{
for (const auto &protocolStat : endpoint)
{
numPeers = std::max(numPeers, protocolStat.numPeers);
numSeeds = std::max(numSeeds, protocolStat.numSeeds);
numLeeches = std::max(numLeeches, protocolStat.numLeeches);
numDownloaded = std::max(numDownloaded, protocolStat.numDownloaded);
if (protocolStat.status == tracker.status)
{
if (!nextAnnounceTime.isValid() || (nextAnnounceTime > protocolStat.nextAnnounceTime))
{
nextAnnounceTime = protocolStat.nextAnnounceTime;
minAnnounceTime = protocolStat.minAnnounceTime;
if ((protocolStat.status != BitTorrent::TrackerEntry::Status::Working)
|| !protocolStat.message.isEmpty())
{
message = protocolStat.message;
}
}
if (protocolStat.status == BitTorrent::TrackerEntry::Status::Working)
{
if (message.isEmpty())
message = protocolStat.message;
}
}
}
}
const bool isNotWorking = (tracker.status == BitTorrent::TrackerEntry::Status::NotWorking)
|| (tracker.status == BitTorrent::TrackerEntry::Status::TrackerError)
|| (tracker.status == BitTorrent::TrackerEntry::Status::Unreachable);
const bool isNotWorking = (tracker.status == BitTorrent::TrackerEntryStatus::NotWorking)
|| (tracker.status == BitTorrent::TrackerEntryStatus::TrackerError)
|| (tracker.status == BitTorrent::TrackerEntryStatus::Unreachable);
trackerList << QJsonObject
{
{KEY_TRACKER_URL, tracker.url},
{KEY_TRACKER_TIER, tracker.tier},
{KEY_TRACKER_STATUS, static_cast<int>((isNotWorking ? BitTorrent::TrackerEntry::Status::NotWorking : tracker.status))},
{KEY_TRACKER_MSG, message},
{KEY_TRACKER_PEERS_COUNT, numPeers},
{KEY_TRACKER_SEEDS_COUNT, numSeeds},
{KEY_TRACKER_LEECHES_COUNT, numLeeches},
{KEY_TRACKER_DOWNLOADED_COUNT, numDownloaded}
{KEY_TRACKER_STATUS, static_cast<int>((isNotWorking ? BitTorrent::TrackerEntryStatus::NotWorking : tracker.status))},
{KEY_TRACKER_MSG, tracker.message},
{KEY_TRACKER_PEERS_COUNT, tracker.numPeers},
{KEY_TRACKER_SEEDS_COUNT, tracker.numSeeds},
{KEY_TRACKER_LEECHES_COUNT, tracker.numLeeches},
{KEY_TRACKER_DOWNLOADED_COUNT, tracker.numDownloaded}
};
}