mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 13:18:06 -06:00
Replace QList by QVector for tracker related operations
This commit is contained in:
@@ -76,6 +76,7 @@ MagnetUri::MagnetUri(const QString &source)
|
||||
m_hash = m_addTorrentParams.info_hash;
|
||||
m_name = QString::fromStdString(m_addTorrentParams.name);
|
||||
|
||||
m_trackers.reserve(m_addTorrentParams.trackers.size());
|
||||
for (const std::string &tracker : m_addTorrentParams.trackers)
|
||||
m_trackers.append(lt::announce_entry {tracker});
|
||||
|
||||
@@ -98,7 +99,7 @@ QString MagnetUri::name() const
|
||||
return m_name;
|
||||
}
|
||||
|
||||
QList<TrackerEntry> MagnetUri::trackers() const
|
||||
QVector<TrackerEntry> MagnetUri::trackers() const
|
||||
{
|
||||
return m_trackers;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
#include "infohash.h"
|
||||
#include "trackerentry.h"
|
||||
@@ -49,7 +50,7 @@ namespace BitTorrent
|
||||
bool isValid() const;
|
||||
InfoHash hash() const;
|
||||
QString name() const;
|
||||
QList<TrackerEntry> trackers() const;
|
||||
QVector<TrackerEntry> trackers() const;
|
||||
QList<QUrl> urlSeeds() const;
|
||||
QString url() const;
|
||||
|
||||
@@ -60,7 +61,7 @@ namespace BitTorrent
|
||||
QString m_url;
|
||||
InfoHash m_hash;
|
||||
QString m_name;
|
||||
QList<TrackerEntry> m_trackers;
|
||||
QVector<TrackerEntry> m_trackers;
|
||||
QList<QUrl> m_urlSeeds;
|
||||
lt::add_torrent_params m_addTorrentParams;
|
||||
};
|
||||
|
||||
@@ -3336,7 +3336,7 @@ void Session::handleTorrentSavingModeChanged(TorrentHandle *const torrent)
|
||||
emit torrentSavingModeChanged(torrent);
|
||||
}
|
||||
|
||||
void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QList<TrackerEntry> &newTrackers)
|
||||
void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector<TrackerEntry> &newTrackers)
|
||||
{
|
||||
saveTorrentResumeData(torrent);
|
||||
|
||||
@@ -3348,7 +3348,7 @@ void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QLi
|
||||
emit trackersChanged(torrent);
|
||||
}
|
||||
|
||||
void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QList<TrackerEntry> &deletedTrackers)
|
||||
void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector<TrackerEntry> &deletedTrackers)
|
||||
{
|
||||
saveTorrentResumeData(torrent);
|
||||
|
||||
|
||||
@@ -436,8 +436,8 @@ namespace BitTorrent
|
||||
void handleTorrentResumed(TorrentHandle *const torrent);
|
||||
void handleTorrentChecked(TorrentHandle *const torrent);
|
||||
void handleTorrentFinished(TorrentHandle *const torrent);
|
||||
void handleTorrentTrackersAdded(TorrentHandle *const torrent, const QList<TrackerEntry> &newTrackers);
|
||||
void handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QList<TrackerEntry> &deletedTrackers);
|
||||
void handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector<TrackerEntry> &newTrackers);
|
||||
void handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector<TrackerEntry> &deletedTrackers);
|
||||
void handleTorrentTrackersChanged(TorrentHandle *const torrent);
|
||||
void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds);
|
||||
void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList<QUrl> &urlSeeds);
|
||||
@@ -474,8 +474,8 @@ namespace BitTorrent
|
||||
void recursiveTorrentDownloadPossible(BitTorrent::TorrentHandle *const torrent);
|
||||
void speedLimitModeChanged(bool alternative);
|
||||
void IPFilterParsed(bool error, int ruleCount);
|
||||
void trackersAdded(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers);
|
||||
void trackersRemoved(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers);
|
||||
void trackersAdded(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
|
||||
void trackersRemoved(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
|
||||
void trackersChanged(BitTorrent::TorrentHandle *const torrent);
|
||||
void trackerlessStateChanged(BitTorrent::TorrentHandle *const torrent, bool trackerless);
|
||||
void downloadFromUrlFailed(const QString &url, const QString &reason);
|
||||
@@ -669,7 +669,7 @@ namespace BitTorrent
|
||||
|
||||
int m_numResumeData;
|
||||
int m_extraLimit;
|
||||
QList<BitTorrent::TrackerEntry> m_additionalTrackerList;
|
||||
QVector<BitTorrent::TrackerEntry> m_additionalTrackerList;
|
||||
QString m_resumeFolderPath;
|
||||
QFile m_resumeFolderLock;
|
||||
bool m_useProxy;
|
||||
|
||||
@@ -386,14 +386,14 @@ void TorrentHandle::setAutoManaged(const bool enable)
|
||||
#endif
|
||||
}
|
||||
|
||||
QList<TrackerEntry> TorrentHandle::trackers() const
|
||||
QVector<TrackerEntry> TorrentHandle::trackers() const
|
||||
{
|
||||
QList<TrackerEntry> entries;
|
||||
const std::vector<lt::announce_entry> announces = m_nativeHandle.trackers();
|
||||
|
||||
QVector<TrackerEntry> entries;
|
||||
entries.reserve(announces.size());
|
||||
for (const lt::announce_entry &tracker : announces)
|
||||
entries << tracker;
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
@@ -402,53 +402,55 @@ QHash<QString, TrackerInfo> TorrentHandle::trackerInfos() const
|
||||
return m_trackerInfos;
|
||||
}
|
||||
|
||||
void TorrentHandle::addTrackers(const QList<TrackerEntry> &trackers)
|
||||
void TorrentHandle::addTrackers(const QVector<TrackerEntry> &trackers)
|
||||
{
|
||||
QList<TrackerEntry> addedTrackers;
|
||||
const QVector<TrackerEntry> currentTrackers = this->trackers();
|
||||
|
||||
QVector<TrackerEntry> newTrackers;
|
||||
newTrackers.reserve(trackers.size());
|
||||
|
||||
for (const TrackerEntry &tracker : trackers) {
|
||||
if (addTracker(tracker))
|
||||
addedTrackers << tracker;
|
||||
if (!currentTrackers.contains(tracker)) {
|
||||
m_nativeHandle.add_tracker(tracker.nativeEntry());
|
||||
newTrackers << tracker;
|
||||
}
|
||||
}
|
||||
|
||||
if (!addedTrackers.isEmpty())
|
||||
m_session->handleTorrentTrackersAdded(this, addedTrackers);
|
||||
if (!newTrackers.isEmpty())
|
||||
m_session->handleTorrentTrackersAdded(this, newTrackers);
|
||||
}
|
||||
|
||||
void TorrentHandle::replaceTrackers(const QList<TrackerEntry> &trackers)
|
||||
void TorrentHandle::replaceTrackers(const QVector<TrackerEntry> &trackers)
|
||||
{
|
||||
QList<TrackerEntry> existingTrackers = this->trackers();
|
||||
QList<TrackerEntry> addedTrackers;
|
||||
QVector<TrackerEntry> currentTrackers = this->trackers();
|
||||
|
||||
QVector<TrackerEntry> newTrackers;
|
||||
newTrackers.reserve(trackers.size());
|
||||
|
||||
std::vector<lt::announce_entry> announces;
|
||||
|
||||
for (const TrackerEntry &tracker : trackers) {
|
||||
announces.push_back(tracker.nativeEntry());
|
||||
if (!existingTrackers.contains(tracker))
|
||||
addedTrackers << tracker;
|
||||
else
|
||||
existingTrackers.removeOne(tracker);
|
||||
announces.emplace_back(tracker.nativeEntry());
|
||||
|
||||
if (!currentTrackers.removeOne(tracker))
|
||||
newTrackers << tracker;
|
||||
}
|
||||
|
||||
m_nativeHandle.replace_trackers(announces);
|
||||
if (addedTrackers.isEmpty() && existingTrackers.isEmpty()) {
|
||||
|
||||
if (newTrackers.isEmpty() && currentTrackers.isEmpty()) {
|
||||
// when existing tracker reorders
|
||||
m_session->handleTorrentTrackersChanged(this);
|
||||
}
|
||||
else {
|
||||
if (!existingTrackers.isEmpty())
|
||||
m_session->handleTorrentTrackersRemoved(this, existingTrackers);
|
||||
if (!addedTrackers.isEmpty())
|
||||
m_session->handleTorrentTrackersAdded(this, addedTrackers);
|
||||
if (!currentTrackers.isEmpty())
|
||||
m_session->handleTorrentTrackersRemoved(this, currentTrackers);
|
||||
|
||||
if (!newTrackers.isEmpty())
|
||||
m_session->handleTorrentTrackersAdded(this, newTrackers);
|
||||
}
|
||||
}
|
||||
|
||||
bool TorrentHandle::addTracker(const TrackerEntry &tracker)
|
||||
{
|
||||
if (trackers().contains(tracker))
|
||||
return false;
|
||||
|
||||
m_nativeHandle.add_tracker(tracker.nativeEntry());
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<QUrl> TorrentHandle::urlSeeds() const
|
||||
{
|
||||
QList<QUrl> urlSeeds;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <libtorrent/torrent_status.hpp>
|
||||
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
#include <QQueue>
|
||||
#include <QSet>
|
||||
@@ -260,7 +261,7 @@ namespace BitTorrent
|
||||
bool hasError() const;
|
||||
bool hasFilteredPieces() const;
|
||||
int queuePosition() const;
|
||||
QList<TrackerEntry> trackers() const;
|
||||
QVector<TrackerEntry> trackers() const;
|
||||
QHash<QString, TrackerInfo> trackerInfos() const;
|
||||
QList<QUrl> urlSeeds() const;
|
||||
QString error() const;
|
||||
@@ -323,8 +324,8 @@ namespace BitTorrent
|
||||
void setDownloadLimit(int limit);
|
||||
void setSuperSeeding(bool enable);
|
||||
void flushCache();
|
||||
void addTrackers(const QList<TrackerEntry> &trackers);
|
||||
void replaceTrackers(const QList<TrackerEntry> &trackers);
|
||||
void addTrackers(const QVector<TrackerEntry> &trackers);
|
||||
void replaceTrackers(const QVector<TrackerEntry> &trackers);
|
||||
void addUrlSeeds(const QList<QUrl> &urlSeeds);
|
||||
void removeUrlSeeds(const QList<QUrl> &urlSeeds);
|
||||
bool connectPeer(const PeerAddress &peerAddress);
|
||||
@@ -388,7 +389,6 @@ namespace BitTorrent
|
||||
void move_impl(QString path, bool overwrite);
|
||||
void moveStorage(const QString &newPath, bool overwrite);
|
||||
void manageIncompleteFiles();
|
||||
bool addTracker(const TrackerEntry &tracker);
|
||||
bool addUrlSeed(const QUrl &urlSeed);
|
||||
bool removeUrlSeed(const QUrl &urlSeed);
|
||||
void setFirstLastPiecePriorityImpl(bool enabled, const QVector<DownloadPriority> &updatedFilePrio = {});
|
||||
|
||||
@@ -264,15 +264,18 @@ qlonglong TorrentInfo::fileOffset(const int index) const
|
||||
return m_nativeInfo->files().file_offset(LTFileIndex {index});
|
||||
}
|
||||
|
||||
QList<TrackerEntry> TorrentInfo::trackers() const
|
||||
QVector<TrackerEntry> TorrentInfo::trackers() const
|
||||
{
|
||||
if (!isValid()) return {};
|
||||
|
||||
QList<TrackerEntry> trackers;
|
||||
for (const lt::announce_entry &tracker : m_nativeInfo->trackers())
|
||||
trackers.append(tracker);
|
||||
const std::vector<lt::announce_entry> trackers = m_nativeInfo->trackers();
|
||||
|
||||
return trackers;
|
||||
QVector<TrackerEntry> ret;
|
||||
ret.reserve(trackers.size());
|
||||
|
||||
for (const lt::announce_entry &tracker : trackers)
|
||||
ret.append(tracker);
|
||||
return ret;
|
||||
}
|
||||
|
||||
QList<QUrl> TorrentInfo::urlSeeds() const
|
||||
|
||||
@@ -88,7 +88,7 @@ namespace BitTorrent
|
||||
QString origFilePath(int index) const;
|
||||
qlonglong fileSize(int index) const;
|
||||
qlonglong fileOffset(int index) const;
|
||||
QList<TrackerEntry> trackers() const;
|
||||
QVector<TrackerEntry> trackers() const;
|
||||
QList<QUrl> urlSeeds() const;
|
||||
QByteArray metadata() const;
|
||||
QStringList filesForPiece(int pieceIndex) const;
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace BitTorrent
|
||||
NotWorking = 4
|
||||
};
|
||||
|
||||
TrackerEntry() = default;
|
||||
TrackerEntry(const QString &url);
|
||||
TrackerEntry(const lt::announce_entry &nativeEntry);
|
||||
TrackerEntry(const TrackerEntry &other) = default;
|
||||
|
||||
Reference in New Issue
Block a user