Browse Source

Improve tracker entries handling

adaptive-webui-19844
Vladimir Golovnev (Glassez) 4 years ago
parent
commit
7a8c05dc7c
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 2
      src/base/bittorrent/magneturi.cpp
  2. 6
      src/base/bittorrent/session.cpp
  3. 2
      src/base/bittorrent/session.h
  4. 2
      src/base/bittorrent/torrent.h
  5. 128
      src/base/bittorrent/torrentimpl.cpp
  6. 2
      src/base/bittorrent/torrentinfo.cpp
  7. 2
      src/base/bittorrent/torrentinfo.h
  8. 132
      src/base/bittorrent/trackerentry.cpp
  9. 43
      src/base/bittorrent/trackerentry.h
  10. 40
      src/gui/properties/trackerlistwidget.cpp
  11. 4
      src/gui/properties/trackersadditiondialog.cpp
  12. 8
      src/gui/trackerentriesdialog.cpp
  13. 2
      src/gui/trackerentriesdialog.h
  14. 8
      src/gui/transferlistfilterswidget.cpp
  15. 2
      src/gui/transferlistfilterswidget.h
  16. 2
      src/webui/api/synccontroller.cpp
  17. 24
      src/webui/api/torrentscontroller.cpp

2
src/base/bittorrent/magneturi.cpp

@ -78,7 +78,7 @@ MagnetUri::MagnetUri(const QString &source) @@ -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)

6
src/base/bittorrent/session.cpp

@ -1604,7 +1604,7 @@ void Session::populateAdditionalTrackers() @@ -1604,7 +1604,7 @@ void Session::populateAdditionalTrackers()
{
tracker = tracker.trimmed();
if (!tracker.isEmpty())
m_additionalTrackerList << tracker.toString();
m_additionalTrackerList.append({tracker.toString()});
}
}
@ -3809,7 +3809,7 @@ void Session::handleTorrentTrackersAdded(TorrentImpl *const torrent, const QVect @@ -3809,7 +3809,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);
@ -3821,7 +3821,7 @@ void Session::handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QVe @@ -3821,7 +3821,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);

2
src/base/bittorrent/session.h

@ -99,8 +99,8 @@ namespace BitTorrent @@ -99,8 +99,8 @@ namespace BitTorrent
class Torrent;
class TorrentImpl;
class Tracker;
class TrackerEntry;
struct LoadTorrentParams;
struct TrackerEntry;
enum class MoveStorageMode;

2
src/base/bittorrent/torrent.h

@ -45,8 +45,8 @@ namespace BitTorrent @@ -45,8 +45,8 @@ namespace BitTorrent
class InfoHash;
class PeerInfo;
class TorrentInfo;
class TrackerEntry;
struct PeerAddress;
struct TrackerEntry;
enum class TorrentOperatingMode
{

128
src/base/bittorrent/torrentimpl.cpp

@ -47,6 +47,10 @@ @@ -47,6 +47,10 @@
#include <libtorrent/version.hpp>
#include <libtorrent/write_resume_data.hpp>
#if (LIBTORRENT_VERSION_NUM >= 20000)
#include <libtorrent/info_hash.hpp>
#endif
#include <QBitArray>
#include <QDebug>
#include <QDir>
@ -96,6 +100,114 @@ namespace @@ -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<TrackerEntry> TorrentImpl::trackers() const @@ -311,7 +423,11 @@ QVector<TrackerEntry> 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<TrackerEntry> &trackers) @@ -325,7 +441,7 @@ void TorrentImpl::addTrackers(const QVector<TrackerEntry> &trackers)
{
QSet<TrackerEntry> currentTrackers;
for (const lt::announce_entry &entry : m_nativeHandle.trackers())
currentTrackers << entry;
currentTrackers.insert({QString::fromStdString(entry.url), entry.tier});
QVector<TrackerEntry> newTrackers;
newTrackers.reserve(trackers.size());
@ -334,7 +450,7 @@ void TorrentImpl::addTrackers(const QVector<TrackerEntry> &trackers) @@ -334,7 +450,7 @@ void TorrentImpl::addTrackers(const QVector<TrackerEntry> &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<TrackerEntry> &trackers) @@ -355,7 +471,7 @@ void TorrentImpl::replaceTrackers(const QVector<TrackerEntry> &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) @@ -1496,9 +1612,9 @@ void TorrentImpl::handleTrackerErrorAlert(const lt::tracker_error_alert *p)
const QVector<TrackerEntry> 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);
}

2
src/base/bittorrent/torrentinfo.cpp

@ -302,7 +302,7 @@ QVector<TrackerEntry> TorrentInfo::trackers() const @@ -302,7 +302,7 @@ QVector<TrackerEntry> 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;
}

2
src/base/bittorrent/torrentinfo.h

@ -45,7 +45,7 @@ class QUrl; @@ -45,7 +45,7 @@ class QUrl;
namespace BitTorrent
{
class InfoHash;
class TrackerEntry;
struct TrackerEntry;
class TorrentInfo final : public AbstractFileStorage
{

132
src/base/bittorrent/trackerentry.cpp

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2015, 2021 Vladimir Golovnev <glassez@yandex.ru>
*
* 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 @@ @@ -28,139 +28,15 @@
#include "trackerentry.h"
#include <algorithm>
#include <libtorrent/version.hpp>
#include <QString>
#include <QUrl>
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));
}

43
src/base/bittorrent/trackerentry.h

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2015, 2021 Vladimir Golovnev <glassez@yandex.ru>
*
* 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 @@ @@ -28,17 +28,14 @@
#pragma once
#include <libtorrent/announce_entry.hpp>
#include <QtGlobal>
class QString;
#include <QString>
#include <QVector>
namespace BitTorrent
{
class TrackerEntry
struct TrackerEntry
{
public:
enum Status
{
NotContacted = 1,
@ -47,26 +44,26 @@ namespace BitTorrent @@ -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<EndpointStats> 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);

40
src/gui/properties/trackerlistwidget.cpp

@ -205,9 +205,7 @@ void TrackerListWidget::moveSelectionUp() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -443,7 +439,7 @@ void TrackerListWidget::askForTrackers()
QVector<BitTorrent::TrackerEntry> 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() @@ -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() @@ -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() @@ -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;

4
src/gui/properties/trackersadditiondialog.cpp

@ -96,7 +96,7 @@ void TrackersAdditionDialog::torrentListDownloadFinished(const Net::DownloadResu @@ -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 @@ -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');

8
src/gui/trackerentriesdialog.cpp

@ -66,8 +66,8 @@ void TrackerEntriesDialog::setTrackers(const QVector<BitTorrent::TrackerEntry> & @@ -66,8 +66,8 @@ void TrackerEntriesDialog::setTrackers(const QVector<BitTorrent::TrackerEntry> &
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<BitTorrent::TrackerEntry> TrackerEntriesDialog::trackers() const @@ -97,9 +97,7 @@ QVector<BitTorrent::TrackerEntry> TrackerEntriesDialog::trackers() const
continue;
}
BitTorrent::TrackerEntry entry {line.toString()};
entry.setTier(tier);
entries.append(entry);
entries.append({line.toString(), tier});
}
return entries;

2
src/gui/trackerentriesdialog.h

@ -35,7 +35,7 @@ @@ -35,7 +35,7 @@
namespace BitTorrent
{
class TrackerEntry;
struct TrackerEntry;
}
namespace Ui

8
src/gui/transferlistfilterswidget.cpp

@ -580,7 +580,7 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::Torrent *const torrent) @@ -580,7 +580,7 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::Torrent *const torrent)
const BitTorrent::InfoHash hash {torrent->hash()};
const QVector<BitTorrent::TrackerEntry> 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 @@ -594,7 +594,7 @@ void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::Torrent *const torr
const BitTorrent::InfoHash hash {torrent->hash()};
const QVector<BitTorrent::TrackerEntry> 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) @@ -743,13 +743,13 @@ void TransferListFiltersWidget::setDownloadTrackerFavicon(bool value)
void TransferListFiltersWidget::addTrackers(const BitTorrent::Torrent *torrent, const QVector<BitTorrent::TrackerEntry> &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<BitTorrent::TrackerEntry> &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)

2
src/gui/transferlistfilterswidget.h

@ -41,7 +41,7 @@ namespace BitTorrent @@ -41,7 +41,7 @@ namespace BitTorrent
{
class InfoHash;
class Torrent;
class TrackerEntry;
struct TrackerEntry;
}
namespace Net

2
src/webui/api/synccontroller.cpp

@ -488,7 +488,7 @@ void SyncController::maindataAction() @@ -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;
}

24
src/webui/api/torrentscontroller.cpp

@ -453,18 +453,18 @@ void TorrentsController::trackersAction() @@ -453,18 +453,18 @@ void TorrentsController::trackersAction()
QHash<QString, BitTorrent::TrackerInfo> 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<int>(tracker.status())},
{KEY_TRACKER_URL, tracker.url},
{KEY_TRACKER_TIER, tracker.tier},
{KEY_TRACKER_STATUS, static_cast<int>(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}
};
}
@ -694,7 +694,7 @@ void TorrentsController::addTrackersAction() @@ -694,7 +694,7 @@ void TorrentsController::addTrackersAction()
{
const QUrl url {urlStr.trimmed()};
if (url.isValid())
trackers << url.toString();
trackers.append({url.toString()});
}
torrent->addTrackers(trackers);
}
@ -722,15 +722,13 @@ void TorrentsController::editTrackerAction() @@ -722,15 +722,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)
@ -758,7 +756,7 @@ void TorrentsController::removeTrackersAction() @@ -758,7 +756,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);
}

Loading…
Cancel
Save