Browse Source

Improve torrent event handling in TrackerFiltersList

adaptive-webui-19844
Prince Gupta 3 years ago
parent
commit
cd9ed1706d
  1. 1
      src/base/bittorrent/torrent.h
  2. 16
      src/base/bittorrent/torrentimpl.cpp
  3. 1
      src/base/bittorrent/torrentimpl.h
  4. 16
      src/gui/transferlistfilterswidget.cpp

1
src/base/bittorrent/torrent.h

@ -217,6 +217,7 @@ namespace BitTorrent @@ -217,6 +217,7 @@ namespace BitTorrent
virtual bool hasMissingFiles() const = 0;
virtual bool hasError() const = 0;
virtual int queuePosition() const = 0;
virtual QVector<QString> trackerURLs() const = 0;
virtual QVector<TrackerEntry> trackers() const = 0;
virtual QVector<QUrl> urlSeeds() const = 0;
virtual QString error() const = 0;

16
src/base/bittorrent/torrentimpl.cpp

@ -517,6 +517,22 @@ void TorrentImpl::setAutoManaged(const bool enable) @@ -517,6 +517,22 @@ void TorrentImpl::setAutoManaged(const bool enable)
m_nativeHandle.unset_flags(lt::torrent_flags::auto_managed);
}
QVector<QString> TorrentImpl::trackerURLs() const
{
const std::vector<lt::announce_entry> nativeTrackers = m_nativeHandle.trackers();
QVector<QString> urls;
urls.reserve(static_cast<decltype(urls)::size_type>(nativeTrackers.size()));
for (const lt::announce_entry &tracker : nativeTrackers)
{
const QString trackerURL = QString::fromStdString(tracker.url);
urls.push_back(trackerURL);
}
return urls;
}
QVector<TrackerEntry> TorrentImpl::trackers() const
{
const std::vector<lt::announce_entry> nativeTrackers = m_nativeHandle.trackers();

1
src/base/bittorrent/torrentimpl.h

@ -153,6 +153,7 @@ namespace BitTorrent @@ -153,6 +153,7 @@ namespace BitTorrent
bool hasMissingFiles() const override;
bool hasError() const override;
int queuePosition() const override;
QVector<QString> trackerURLs() const override;
QVector<TrackerEntry> trackers() const override;
QVector<QUrl> urlSeeds() const override;
QString error() const override;

16
src/gui/transferlistfilterswidget.cpp

@ -630,12 +630,12 @@ void TrackerFiltersList::applyFilter(const int row) @@ -630,12 +630,12 @@ void TrackerFiltersList::applyFilter(const int row)
void TrackerFiltersList::handleNewTorrent(BitTorrent::Torrent *const torrent)
{
const BitTorrent::TorrentID torrentID {torrent->id()};
const QVector<BitTorrent::TrackerEntry> trackers {torrent->trackers()};
for (const BitTorrent::TrackerEntry &tracker : trackers)
addItem(tracker.url, torrentID);
const QVector<QString> trackerURLs {torrent->trackerURLs()};
for (const QString &trackerURL : trackerURLs)
addItem(trackerURL, torrentID);
// Check for trackerless torrent
if (trackers.isEmpty())
if (trackerURLs.isEmpty())
addItem(NULL_HOST, torrentID);
item(ALL_ROW)->setText(tr("All (%1)", "this is for the tracker filter").arg(++m_totalTorrents));
@ -644,12 +644,12 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::Torrent *const torrent) @@ -644,12 +644,12 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::Torrent *const torrent)
void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::Torrent *const torrent)
{
const BitTorrent::TorrentID torrentID {torrent->id()};
const QVector<BitTorrent::TrackerEntry> trackers {torrent->trackers()};
for (const BitTorrent::TrackerEntry &tracker : trackers)
removeItem(tracker.url, torrentID);
const QVector<QString> trackerURLs {torrent->trackerURLs()};
for (const QString &trackerURL : trackerURLs)
removeItem(trackerURL, torrentID);
// Check for trackerless torrent
if (trackers.isEmpty())
if (trackerURLs.isEmpty())
removeItem(NULL_HOST, torrentID);
item(ALL_ROW)->setText(tr("All (%1)", "this is for the tracker filter").arg(--m_totalTorrents));

Loading…
Cancel
Save