diff --git a/src/base/bittorrent/magneturi.cpp b/src/base/bittorrent/magneturi.cpp index 7bc44a242..0d8461fff 100644 --- a/src/base/bittorrent/magneturi.cpp +++ b/src/base/bittorrent/magneturi.cpp @@ -78,7 +78,7 @@ MagnetUri::MagnetUri(const QString &source) m_trackers.reserve(m_addTorrentParams.trackers.size()); for (const std::string &tracker : m_addTorrentParams.trackers) - m_trackers.append(lt::announce_entry {tracker}); + m_trackers.append({QString::fromStdString(tracker)}); m_urlSeeds.reserve(m_addTorrentParams.url_seeds.size()); for (const std::string &urlSeed : m_addTorrentParams.url_seeds) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 670fd6c89..19e6f35a5 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -1606,7 +1606,7 @@ void Session::populateAdditionalTrackers() { tracker = tracker.trimmed(); if (!tracker.isEmpty()) - m_additionalTrackerList << tracker.toString(); + m_additionalTrackerList.append({tracker.toString()}); } } @@ -3825,7 +3825,7 @@ void Session::handleTorrentTrackersAdded(TorrentImpl *const torrent, const QVect torrent->saveResumeData(); for (const TrackerEntry &newTracker : newTrackers) - LogMsg(tr("Tracker '%1' was added to torrent '%2'").arg(newTracker.url(), torrent->name())); + LogMsg(tr("Tracker '%1' was added to torrent '%2'").arg(newTracker.url, torrent->name())); emit trackersAdded(torrent, newTrackers); if (torrent->trackers().size() == newTrackers.size()) emit trackerlessStateChanged(torrent, false); @@ -3837,7 +3837,7 @@ void Session::handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QVe torrent->saveResumeData(); for (const TrackerEntry &deletedTracker : deletedTrackers) - LogMsg(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url(), torrent->name())); + LogMsg(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url, torrent->name())); emit trackersRemoved(torrent, deletedTrackers); if (torrent->trackers().empty()) emit trackerlessStateChanged(torrent, true); diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 1b1f7ab34..db0209235 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -99,8 +99,8 @@ namespace BitTorrent class Torrent; class TorrentImpl; class Tracker; - class TrackerEntry; struct LoadTorrentParams; + struct TrackerEntry; enum class MoveStorageMode; diff --git a/src/base/bittorrent/torrent.h b/src/base/bittorrent/torrent.h index 5d5f1ca07..5396f34dc 100644 --- a/src/base/bittorrent/torrent.h +++ b/src/base/bittorrent/torrent.h @@ -45,8 +45,8 @@ namespace BitTorrent class InfoHash; class PeerInfo; class TorrentInfo; - class TrackerEntry; struct PeerAddress; + struct TrackerEntry; enum class TorrentOperatingMode { diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index ed29b1f05..eaf9cd415 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -47,6 +47,10 @@ #include #include +#if (LIBTORRENT_VERSION_NUM >= 20000) +#include +#endif + #include #include #include @@ -96,6 +100,114 @@ namespace entryList.emplace_back(setValue.toStdString()); return entryList; } + + lt::announce_entry makeNativeAnnouncerEntry(const QString &url, const int tier) + { + lt::announce_entry entry {url.toStdString()}; + entry.tier = tier; + return entry; + } + +#if (LIBTORRENT_VERSION_NUM >= 20000) + TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry, const lt::info_hash_t &hashes) +#else + TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry) +#endif + { + TrackerEntry trackerEntry {QString::fromStdString(nativeEntry.url), nativeEntry.tier}; + + int numUpdating = 0; + int numWorking = 0; + int numNotContacted = 0; +#if (LIBTORRENT_VERSION_NUM >= 20000) + const int numEndpoints = nativeEntry.endpoints.size() * ((hashes.has_v1() && hashes.has_v2()) ? 2 : 1); + trackerEntry.endpoints.reserve(numEndpoints); + for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints) + { + for (const auto protocolVersion : {lt::protocol_version::V1, lt::protocol_version::V2}) + { + if (hashes.has(protocolVersion)) + { + const lt::announce_infohash &infoHash = endpoint.info_hashes[protocolVersion]; + + TrackerEntry::EndpointStats trackerEndpoint; + trackerEndpoint.protocolVersion = (protocolVersion == lt::protocol_version::V1) ? 1 : 2; + trackerEndpoint.numSeeds = infoHash.scrape_complete; + trackerEndpoint.numLeeches = infoHash.scrape_incomplete; + trackerEndpoint.numDownloaded = infoHash.scrape_downloaded; + if (infoHash.updating) + { + trackerEndpoint.status = TrackerEntry::Updating; + ++numUpdating; + } + else if (infoHash.fails > 0) + { + trackerEndpoint.status = TrackerEntry::NotWorking; + } + else if (nativeEntry.verified) + { + trackerEndpoint.status = TrackerEntry::Working; + ++numWorking; + } + else + { + trackerEndpoint.status = TrackerEntry::NotContacted; + ++numNotContacted; + } + trackerEntry.endpoints.append(trackerEndpoint); + + trackerEntry.numSeeds = std::max(trackerEntry.numSeeds, infoHash.scrape_complete); + trackerEntry.numLeeches = std::max(trackerEntry.numLeeches, infoHash.scrape_incomplete); + trackerEntry.numDownloaded = std::max(trackerEntry.numDownloaded, infoHash.scrape_downloaded); + } + } + } +#else + trackerEntry.endpoints.reserve(nativeEntry.endpoints.size()); + for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints) + { + TrackerEntry::EndpointStats trackerEndpoint; + trackerEndpoint.numSeeds = endpoint.scrape_complete; + trackerEndpoint.numLeeches = endpoint.scrape_incomplete; + trackerEndpoint.numDownloaded = endpoint.scrape_downloaded; + if (endpoint.updating) + { + trackerEndpoint.status = TrackerEntry::Updating; + ++numUpdating; + } + else if (endpoint.fails > 0) + { + trackerEndpoint.status = TrackerEntry::NotWorking; + } + else if (nativeEntry.verified) + { + trackerEndpoint.status = TrackerEntry::Working; + ++numWorking; + } + else + { + trackerEndpoint.status = TrackerEntry::NotContacted; + ++numNotContacted; + } + trackerEntry.endpoints.append(trackerEndpoint); + + trackerEntry.numSeeds = std::max(trackerEntry.numSeeds, endpoint.scrape_complete); + trackerEntry.numLeeches = std::max(trackerEntry.numLeeches, endpoint.scrape_incomplete); + trackerEntry.numDownloaded = std::max(trackerEntry.numDownloaded, endpoint.scrape_downloaded); + } +#endif + + if (numUpdating > 0) + trackerEntry.status = TrackerEntry::Updating; + else if (numWorking > 0) + trackerEntry.status = TrackerEntry::Working; + else if (numNotContacted > 0) + trackerEntry.status = TrackerEntry::NotContacted; + else + trackerEntry.status = TrackerEntry::NotWorking; + + return trackerEntry; + } } // TorrentImpl @@ -311,7 +423,11 @@ QVector TorrentImpl::trackers() const entries.reserve(nativeTrackers.size()); for (const lt::announce_entry &tracker : nativeTrackers) - entries << tracker; +#if (LIBTORRENT_VERSION_NUM >= 20000) + entries << fromNativeAnnouncerEntry(tracker, m_nativeHandle.info_hashes()); +#else + entries << fromNativeAnnouncerEntry(tracker); +#endif return entries; } @@ -325,7 +441,7 @@ void TorrentImpl::addTrackers(const QVector &trackers) { QSet currentTrackers; for (const lt::announce_entry &entry : m_nativeHandle.trackers()) - currentTrackers << entry; + currentTrackers.insert({QString::fromStdString(entry.url), entry.tier}); QVector newTrackers; newTrackers.reserve(trackers.size()); @@ -334,7 +450,7 @@ void TorrentImpl::addTrackers(const QVector &trackers) { if (!currentTrackers.contains(tracker)) { - m_nativeHandle.add_tracker(tracker.nativeEntry()); + m_nativeHandle.add_tracker(makeNativeAnnouncerEntry(tracker.url, tracker.tier)); newTrackers << tracker; } } @@ -355,7 +471,7 @@ void TorrentImpl::replaceTrackers(const QVector &trackers) for (const TrackerEntry &tracker : trackers) { - nativeTrackers.emplace_back(tracker.nativeEntry()); + nativeTrackers.emplace_back(makeNativeAnnouncerEntry(tracker.url, tracker.tier)); if (!currentTrackers.removeOne(tracker)) newTrackers << tracker; @@ -1496,9 +1612,9 @@ void TorrentImpl::handleTrackerErrorAlert(const lt::tracker_error_alert *p) const QVector trackerList = trackers(); const auto iter = std::find_if(trackerList.cbegin(), trackerList.cend(), [&trackerUrl](const TrackerEntry &entry) { - return (entry.url() == trackerUrl); + return (entry.url == trackerUrl); }); - if ((iter != trackerList.cend()) && (iter->status() == TrackerEntry::NotWorking)) + if ((iter != trackerList.cend()) && (iter->status == TrackerEntry::NotWorking)) m_session->handleTorrentTrackerError(this, trackerUrl); } diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index 377373836..ffe228c3a 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -302,7 +302,7 @@ QVector TorrentInfo::trackers() const ret.reserve(trackers.size()); for (const lt::announce_entry &tracker : trackers) - ret.append(tracker); + ret.append({QString::fromStdString(tracker.url)}); return ret; } diff --git a/src/base/bittorrent/torrentinfo.h b/src/base/bittorrent/torrentinfo.h index dca6b59c7..7c842102d 100644 --- a/src/base/bittorrent/torrentinfo.h +++ b/src/base/bittorrent/torrentinfo.h @@ -45,7 +45,7 @@ class QUrl; namespace BitTorrent { class InfoHash; - class TrackerEntry; + struct TrackerEntry; class TorrentInfo final : public AbstractFileStorage { diff --git a/src/base/bittorrent/trackerentry.cpp b/src/base/bittorrent/trackerentry.cpp index 59b9d0a5a..622678022 100644 --- a/src/base/bittorrent/trackerentry.cpp +++ b/src/base/bittorrent/trackerentry.cpp @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2015 Vladimir Golovnev + * Copyright (C) 2015, 2021 Vladimir Golovnev * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,139 +28,15 @@ #include "trackerentry.h" -#include - -#include - -#include #include -using namespace BitTorrent; - -TrackerEntry::TrackerEntry(const QString &url) - : m_nativeEntry(url.toStdString()) -{ -} - -TrackerEntry::TrackerEntry(const lt::announce_entry &nativeEntry) - : m_nativeEntry(nativeEntry) -{ -} - -QString TrackerEntry::url() const -{ - return QString::fromStdString(nativeEntry().url); -} - -int TrackerEntry::tier() const -{ - return nativeEntry().tier; -} - -TrackerEntry::Status TrackerEntry::status() const -{ - const auto &endpoints = nativeEntry().endpoints; - - const bool allFailed = !endpoints.empty() && std::all_of(endpoints.begin(), endpoints.end() - , [](const lt::announce_endpoint &endpoint) - { -#if (LIBTORRENT_VERSION_NUM >= 20000) - return std::all_of(endpoint.info_hashes.begin(), endpoint.info_hashes.end() - , [](const lt::announce_infohash &infohash) - { - return (infohash.fails > 0); - }); -#else - return (endpoint.fails > 0); -#endif - }); - if (allFailed) - return NotWorking; - - const bool isUpdating = std::any_of(endpoints.begin(), endpoints.end() - , [](const lt::announce_endpoint &endpoint) - { -#if (LIBTORRENT_VERSION_NUM >= 20000) - return std::any_of(endpoint.info_hashes.begin(), endpoint.info_hashes.end() - , [](const lt::announce_infohash &infohash) - { - return infohash.updating; - }); -#else - return endpoint.updating; -#endif - }); - if (isUpdating) - return Updating; - - if (!nativeEntry().verified) - return NotContacted; - - return Working; -} - -void TrackerEntry::setTier(const int value) -{ - m_nativeEntry.tier = value; -} - -int TrackerEntry::numSeeds() const -{ - int value = -1; - for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) - { -#if (LIBTORRENT_VERSION_NUM >= 20000) - for (const lt::announce_infohash &infoHash : endpoint.info_hashes) - value = std::max(value, infoHash.scrape_complete); -#else - value = std::max(value, endpoint.scrape_complete); -#endif - } - return value; -} - -int TrackerEntry::numLeeches() const -{ - int value = -1; - for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) - { -#if (LIBTORRENT_VERSION_NUM >= 20000) - for (const lt::announce_infohash &infoHash : endpoint.info_hashes) - value = std::max(value, infoHash.scrape_incomplete); -#else - value = std::max(value, endpoint.scrape_incomplete); -#endif - } - return value; -} - -int TrackerEntry::numDownloaded() const -{ - int value = -1; - for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints) - { -#if (LIBTORRENT_VERSION_NUM >= 20000) - for (const lt::announce_infohash &infoHash : endpoint.info_hashes) - value = std::max(value, infoHash.scrape_downloaded); -#else - value = std::max(value, endpoint.scrape_downloaded); -#endif - } - return value; -} - -const lt::announce_entry &TrackerEntry::nativeEntry() const -{ - return m_nativeEntry; -} - bool BitTorrent::operator==(const TrackerEntry &left, const TrackerEntry &right) { - return ((left.tier() == right.tier()) - && QUrl(left.url()) == QUrl(right.url())); + return ((left.tier == right.tier) + && QUrl(left.url) == QUrl(right.url)); } uint BitTorrent::qHash(const TrackerEntry &key, const uint seed) { - return (::qHash(key.url(), seed) ^ ::qHash(key.tier())); + return (::qHash(key.url, seed) ^ ::qHash(key.tier)); } diff --git a/src/base/bittorrent/trackerentry.h b/src/base/bittorrent/trackerentry.h index 787c87d8a..e4bdd5538 100644 --- a/src/base/bittorrent/trackerentry.h +++ b/src/base/bittorrent/trackerentry.h @@ -1,6 +1,6 @@ /* * Bittorrent Client using Qt and libtorrent. - * Copyright (C) 2015 Vladimir Golovnev + * Copyright (C) 2015, 2021 Vladimir Golovnev * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -28,17 +28,14 @@ #pragma once -#include - #include - -class QString; +#include +#include namespace BitTorrent { - class TrackerEntry + struct TrackerEntry { - public: enum Status { NotContacted = 1, @@ -47,26 +44,26 @@ namespace BitTorrent NotWorking = 4 }; - TrackerEntry() = default; - TrackerEntry(const QString &url); - TrackerEntry(const lt::announce_entry &nativeEntry); - TrackerEntry(const TrackerEntry &other) = default; - TrackerEntry &operator=(const TrackerEntry &other) = default; - - QString url() const; - Status status() const; + struct EndpointStats + { + int protocolVersion = 1; - int tier() const; - void setTier(int value); + Status status = NotContacted; + int numSeeds = -1; + int numLeeches = -1; + int numDownloaded = -1; + }; - int numSeeds() const; - int numLeeches() const; - int numDownloaded() const; + QString url; + int tier = 0; - const lt::announce_entry &nativeEntry() const; + QVector endpoints {}; - private: - lt::announce_entry m_nativeEntry; + // Deprecated fields + Status status = NotContacted; + int numSeeds = -1; + int numLeeches = -1; + int numDownloaded = -1; }; bool operator==(const TrackerEntry &left, const TrackerEntry &right); diff --git a/src/gui/properties/trackerlistwidget.cpp b/src/gui/properties/trackerlistwidget.cpp index 53bed503d..fd3237612 100644 --- a/src/gui/properties/trackerlistwidget.cpp +++ b/src/gui/properties/trackerlistwidget.cpp @@ -205,9 +205,7 @@ void TrackerListWidget::moveSelectionUp() for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) { const QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString(); - BitTorrent::TrackerEntry e(trackerURL); - e.setTier(i - NB_STICKY_ITEM); - trackers.append(e); + trackers.append({trackerURL, (i - NB_STICKY_ITEM)}); } torrent->replaceTrackers(trackers); @@ -251,9 +249,7 @@ void TrackerListWidget::moveSelectionDown() for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) { const QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString(); - BitTorrent::TrackerEntry e(trackerURL); - e.setTier(i - NB_STICKY_ITEM); - trackers.append(e); + trackers.append({trackerURL, (i - NB_STICKY_ITEM)}); } torrent->replaceTrackers(trackers); @@ -372,7 +368,7 @@ void TrackerListWidget::loadTrackers() for (const BitTorrent::TrackerEntry &entry : asConst(torrent->trackers())) { - const QString trackerURL = entry.url(); + const QString trackerURL = entry.url; QTreeWidgetItem *item = m_trackerItems.value(trackerURL, nullptr); if (!item) @@ -387,11 +383,11 @@ void TrackerListWidget::loadTrackers() oldTrackerURLs.removeOne(trackerURL); } - item->setText(COL_TIER, QString::number(entry.tier())); + item->setText(COL_TIER, QString::number(entry.tier)); const BitTorrent::TrackerInfo data = trackerData.value(trackerURL); - switch (entry.status()) + switch (entry.status) { case BitTorrent::TrackerEntry::Working: item->setText(COL_STATUS, tr("Working")); @@ -412,14 +408,14 @@ void TrackerListWidget::loadTrackers() } item->setText(COL_PEERS, QString::number(data.numPeers)); - item->setText(COL_SEEDS, ((entry.numSeeds() > -1) - ? QString::number(entry.numSeeds()) + item->setText(COL_SEEDS, ((entry.numSeeds > -1) + ? QString::number(entry.numSeeds) : tr("N/A"))); - item->setText(COL_LEECHES, ((entry.numLeeches() > -1) - ? QString::number(entry.numLeeches()) + item->setText(COL_LEECHES, ((entry.numLeeches > -1) + ? QString::number(entry.numLeeches) : tr("N/A"))); - item->setText(COL_DOWNLOADED, ((entry.numDownloaded() > -1) - ? QString::number(entry.numDownloaded()) + item->setText(COL_DOWNLOADED, ((entry.numDownloaded > -1) + ? QString::number(entry.numDownloaded) : tr("N/A"))); const Qt::Alignment alignment = (Qt::AlignRight | Qt::AlignVCenter); @@ -443,7 +439,7 @@ void TrackerListWidget::askForTrackers() QVector trackers; for (const QString &tracker : asConst(TrackersAdditionDialog::askForTrackers(this, torrent))) - trackers << tracker; + trackers.append({tracker}); torrent->addTrackers(trackers); } @@ -492,7 +488,7 @@ void TrackerListWidget::deleteSelectedTrackers() for (const BitTorrent::TrackerEntry &entry : trackers) { - if (!urlsToRemove.contains(entry.url())) + if (!urlsToRemove.contains(entry.url)) remainingTrackers.push_back(entry); } @@ -529,18 +525,16 @@ void TrackerListWidget::editSelectedTracker() bool match = false; for (BitTorrent::TrackerEntry &entry : trackers) { - if (newTrackerURL == QUrl(entry.url())) + if (newTrackerURL == QUrl(entry.url)) { QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists.")); return; } - if (!match && (trackerURL == QUrl(entry.url()))) + if (!match && (trackerURL == QUrl(entry.url))) { match = true; - BitTorrent::TrackerEntry newEntry(newTrackerURL.toString()); - newEntry.setTier(entry.tier()); - entry = newEntry; + entry.url = newTrackerURL.toString(); } } @@ -572,7 +566,7 @@ void TrackerListWidget::reannounceSelected() // Trackers case for (int i = 0; i < trackers.size(); ++i) { - if (item->text(COL_URL) == trackers[i].url()) + if (item->text(COL_URL) == trackers[i].url) { torrent->forceReannounce(i); break; diff --git a/src/gui/properties/trackersadditiondialog.cpp b/src/gui/properties/trackersadditiondialog.cpp index e2f2f7197..f0f904e54 100644 --- a/src/gui/properties/trackersadditiondialog.cpp +++ b/src/gui/properties/trackersadditiondialog.cpp @@ -96,7 +96,7 @@ void TrackersAdditionDialog::torrentListDownloadFinished(const Net::DownloadResu existingTrackers.reserve(trackersFromUser.size()); for (const QString &userURL : trackersFromUser) { - const BitTorrent::TrackerEntry userTracker(userURL); + const BitTorrent::TrackerEntry userTracker {userURL}; if (!existingTrackers.contains(userTracker)) existingTrackers << userTracker; } @@ -113,7 +113,7 @@ void TrackersAdditionDialog::torrentListDownloadFinished(const Net::DownloadResu const QString line = buffer.readLine().trimmed(); if (line.isEmpty()) continue; - BitTorrent::TrackerEntry newTracker(line); + BitTorrent::TrackerEntry newTracker {line}; if (!existingTrackers.contains(newTracker)) { m_ui->textEditTrackersList->insertPlainText(line + '\n'); diff --git a/src/gui/trackerentriesdialog.cpp b/src/gui/trackerentriesdialog.cpp index e02f688db..46bb7fe37 100644 --- a/src/gui/trackerentriesdialog.cpp +++ b/src/gui/trackerentriesdialog.cpp @@ -66,8 +66,8 @@ void TrackerEntriesDialog::setTrackers(const QVector & for (const BitTorrent::TrackerEntry &entry : trackers) { - tiers[entry.tier()] += (entry.url() + '\n'); - maxTier = std::max(maxTier, entry.tier()); + tiers[entry.tier] += (entry.url + '\n'); + maxTier = std::max(maxTier, entry.tier); } QString text = tiers.value(0); @@ -97,9 +97,7 @@ QVector TrackerEntriesDialog::trackers() const continue; } - BitTorrent::TrackerEntry entry {line.toString()}; - entry.setTier(tier); - entries.append(entry); + entries.append({line.toString(), tier}); } return entries; diff --git a/src/gui/trackerentriesdialog.h b/src/gui/trackerentriesdialog.h index 4f67dd081..af1564ce4 100644 --- a/src/gui/trackerentriesdialog.h +++ b/src/gui/trackerentriesdialog.h @@ -35,7 +35,7 @@ namespace BitTorrent { - class TrackerEntry; + struct TrackerEntry; } namespace Ui diff --git a/src/gui/transferlistfilterswidget.cpp b/src/gui/transferlistfilterswidget.cpp index 68f95b46f..cb8d8489a 100644 --- a/src/gui/transferlistfilterswidget.cpp +++ b/src/gui/transferlistfilterswidget.cpp @@ -580,7 +580,7 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::Torrent *const torrent) const BitTorrent::InfoHash hash {torrent->hash()}; const QVector trackers {torrent->trackers()}; for (const BitTorrent::TrackerEntry &tracker : trackers) - addItem(tracker.url(), hash); + addItem(tracker.url, hash); // Check for trackerless torrent if (trackers.isEmpty()) @@ -594,7 +594,7 @@ void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::Torrent *const torr const BitTorrent::InfoHash hash {torrent->hash()}; const QVector trackers {torrent->trackers()}; for (const BitTorrent::TrackerEntry &tracker : trackers) - removeItem(tracker.url(), hash); + removeItem(tracker.url, hash); // Check for trackerless torrent if (trackers.isEmpty()) @@ -743,13 +743,13 @@ void TransferListFiltersWidget::setDownloadTrackerFavicon(bool value) void TransferListFiltersWidget::addTrackers(const BitTorrent::Torrent *torrent, const QVector &trackers) { for (const BitTorrent::TrackerEntry &tracker : trackers) - m_trackerFilters->addItem(tracker.url(), torrent->hash()); + m_trackerFilters->addItem(tracker.url, torrent->hash()); } void TransferListFiltersWidget::removeTrackers(const BitTorrent::Torrent *torrent, const QVector &trackers) { for (const BitTorrent::TrackerEntry &tracker : trackers) - m_trackerFilters->removeItem(tracker.url(), torrent->hash()); + m_trackerFilters->removeItem(tracker.url, torrent->hash()); } void TransferListFiltersWidget::changeTrackerless(const BitTorrent::Torrent *torrent, const bool trackerless) diff --git a/src/gui/transferlistfilterswidget.h b/src/gui/transferlistfilterswidget.h index 7e65cc947..0c29753e0 100644 --- a/src/gui/transferlistfilterswidget.h +++ b/src/gui/transferlistfilterswidget.h @@ -41,7 +41,7 @@ namespace BitTorrent { class InfoHash; class Torrent; - class TrackerEntry; + struct TrackerEntry; } namespace Net diff --git a/src/webui/api/synccontroller.cpp b/src/webui/api/synccontroller.cpp index 55df82a38..5ebe2881a 100644 --- a/src/webui/api/synccontroller.cpp +++ b/src/webui/api/synccontroller.cpp @@ -488,7 +488,7 @@ void SyncController::maindataAction() } for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers())) - trackers[tracker.url()] << torrentHash.toString(); + trackers[tracker.url] << torrentHash.toString(); torrents[torrentHash.toString()] = map; } diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 24568beba..30ca1358c 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -455,18 +455,18 @@ void TorrentsController::trackersAction() QHash trackersData = torrent->trackerInfos(); for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers())) { - const BitTorrent::TrackerInfo data = trackersData.value(tracker.url()); + const BitTorrent::TrackerInfo data = trackersData.value(tracker.url); trackerList << QJsonObject { - {KEY_TRACKER_URL, tracker.url()}, - {KEY_TRACKER_TIER, tracker.tier()}, - {KEY_TRACKER_STATUS, static_cast(tracker.status())}, + {KEY_TRACKER_URL, tracker.url}, + {KEY_TRACKER_TIER, tracker.tier}, + {KEY_TRACKER_STATUS, static_cast(tracker.status)}, {KEY_TRACKER_PEERS_COUNT, data.numPeers}, {KEY_TRACKER_MSG, data.lastMessage.trimmed()}, - {KEY_TRACKER_SEEDS_COUNT, tracker.numSeeds()}, - {KEY_TRACKER_LEECHES_COUNT, tracker.numLeeches()}, - {KEY_TRACKER_DOWNLOADED_COUNT, tracker.numDownloaded()} + {KEY_TRACKER_SEEDS_COUNT, tracker.numSeeds}, + {KEY_TRACKER_LEECHES_COUNT, tracker.numLeeches}, + {KEY_TRACKER_DOWNLOADED_COUNT, tracker.numDownloaded} }; } @@ -701,7 +701,7 @@ void TorrentsController::addTrackersAction() { const QUrl url {urlStr.trimmed()}; if (url.isValid()) - trackers << url.toString(); + trackers.append({url.toString()}); } torrent->addTrackers(trackers); } @@ -729,15 +729,13 @@ void TorrentsController::editTrackerAction() bool match = false; for (BitTorrent::TrackerEntry &tracker : trackers) { - const QUrl trackerUrl(tracker.url()); + const QUrl trackerUrl(tracker.url); if (trackerUrl == newTrackerUrl) throw APIError(APIErrorType::Conflict, "New tracker URL already exists"); if (trackerUrl == origTrackerUrl) { match = true; - BitTorrent::TrackerEntry newTracker(newTrackerUrl.toString()); - newTracker.setTier(tracker.tier()); - tracker = newTracker; + tracker.url = newTrackerUrl.toString(); } } if (!match) @@ -765,7 +763,7 @@ void TorrentsController::removeTrackersAction() remainingTrackers.reserve(trackers.size()); for (const BitTorrent::TrackerEntry &entry : trackers) { - if (!urls.contains(entry.url())) + if (!urls.contains(entry.url)) remainingTrackers.push_back(entry); }