mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
Replace QList by QVector for tracker related operations
This commit is contained in:
parent
f86c5442aa
commit
ed6bb0efdc
@ -76,6 +76,7 @@ MagnetUri::MagnetUri(const QString &source)
|
|||||||
m_hash = m_addTorrentParams.info_hash;
|
m_hash = m_addTorrentParams.info_hash;
|
||||||
m_name = QString::fromStdString(m_addTorrentParams.name);
|
m_name = QString::fromStdString(m_addTorrentParams.name);
|
||||||
|
|
||||||
|
m_trackers.reserve(m_addTorrentParams.trackers.size());
|
||||||
for (const std::string &tracker : m_addTorrentParams.trackers)
|
for (const std::string &tracker : m_addTorrentParams.trackers)
|
||||||
m_trackers.append(lt::announce_entry {tracker});
|
m_trackers.append(lt::announce_entry {tracker});
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ QString MagnetUri::name() const
|
|||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TrackerEntry> MagnetUri::trackers() const
|
QVector<TrackerEntry> MagnetUri::trackers() const
|
||||||
{
|
{
|
||||||
return m_trackers;
|
return m_trackers;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
#include "infohash.h"
|
#include "infohash.h"
|
||||||
#include "trackerentry.h"
|
#include "trackerentry.h"
|
||||||
@ -49,7 +50,7 @@ namespace BitTorrent
|
|||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
InfoHash hash() const;
|
InfoHash hash() const;
|
||||||
QString name() const;
|
QString name() const;
|
||||||
QList<TrackerEntry> trackers() const;
|
QVector<TrackerEntry> trackers() const;
|
||||||
QList<QUrl> urlSeeds() const;
|
QList<QUrl> urlSeeds() const;
|
||||||
QString url() const;
|
QString url() const;
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ namespace BitTorrent
|
|||||||
QString m_url;
|
QString m_url;
|
||||||
InfoHash m_hash;
|
InfoHash m_hash;
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QList<TrackerEntry> m_trackers;
|
QVector<TrackerEntry> m_trackers;
|
||||||
QList<QUrl> m_urlSeeds;
|
QList<QUrl> m_urlSeeds;
|
||||||
lt::add_torrent_params m_addTorrentParams;
|
lt::add_torrent_params m_addTorrentParams;
|
||||||
};
|
};
|
||||||
|
@ -3336,7 +3336,7 @@ void Session::handleTorrentSavingModeChanged(TorrentHandle *const torrent)
|
|||||||
emit torrentSavingModeChanged(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);
|
saveTorrentResumeData(torrent);
|
||||||
|
|
||||||
@ -3348,7 +3348,7 @@ void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QLi
|
|||||||
emit trackersChanged(torrent);
|
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);
|
saveTorrentResumeData(torrent);
|
||||||
|
|
||||||
|
@ -436,8 +436,8 @@ namespace BitTorrent
|
|||||||
void handleTorrentResumed(TorrentHandle *const torrent);
|
void handleTorrentResumed(TorrentHandle *const torrent);
|
||||||
void handleTorrentChecked(TorrentHandle *const torrent);
|
void handleTorrentChecked(TorrentHandle *const torrent);
|
||||||
void handleTorrentFinished(TorrentHandle *const torrent);
|
void handleTorrentFinished(TorrentHandle *const torrent);
|
||||||
void handleTorrentTrackersAdded(TorrentHandle *const torrent, const QList<TrackerEntry> &newTrackers);
|
void handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector<TrackerEntry> &newTrackers);
|
||||||
void handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QList<TrackerEntry> &deletedTrackers);
|
void handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector<TrackerEntry> &deletedTrackers);
|
||||||
void handleTorrentTrackersChanged(TorrentHandle *const torrent);
|
void handleTorrentTrackersChanged(TorrentHandle *const torrent);
|
||||||
void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds);
|
void handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds);
|
||||||
void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList<QUrl> &urlSeeds);
|
void handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList<QUrl> &urlSeeds);
|
||||||
@ -474,8 +474,8 @@ namespace BitTorrent
|
|||||||
void recursiveTorrentDownloadPossible(BitTorrent::TorrentHandle *const torrent);
|
void recursiveTorrentDownloadPossible(BitTorrent::TorrentHandle *const torrent);
|
||||||
void speedLimitModeChanged(bool alternative);
|
void speedLimitModeChanged(bool alternative);
|
||||||
void IPFilterParsed(bool error, int ruleCount);
|
void IPFilterParsed(bool error, int ruleCount);
|
||||||
void trackersAdded(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 QList<BitTorrent::TrackerEntry> &trackers);
|
void trackersRemoved(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
|
||||||
void trackersChanged(BitTorrent::TorrentHandle *const torrent);
|
void trackersChanged(BitTorrent::TorrentHandle *const torrent);
|
||||||
void trackerlessStateChanged(BitTorrent::TorrentHandle *const torrent, bool trackerless);
|
void trackerlessStateChanged(BitTorrent::TorrentHandle *const torrent, bool trackerless);
|
||||||
void downloadFromUrlFailed(const QString &url, const QString &reason);
|
void downloadFromUrlFailed(const QString &url, const QString &reason);
|
||||||
@ -669,7 +669,7 @@ namespace BitTorrent
|
|||||||
|
|
||||||
int m_numResumeData;
|
int m_numResumeData;
|
||||||
int m_extraLimit;
|
int m_extraLimit;
|
||||||
QList<BitTorrent::TrackerEntry> m_additionalTrackerList;
|
QVector<BitTorrent::TrackerEntry> m_additionalTrackerList;
|
||||||
QString m_resumeFolderPath;
|
QString m_resumeFolderPath;
|
||||||
QFile m_resumeFolderLock;
|
QFile m_resumeFolderLock;
|
||||||
bool m_useProxy;
|
bool m_useProxy;
|
||||||
|
@ -386,14 +386,14 @@ void TorrentHandle::setAutoManaged(const bool enable)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TrackerEntry> TorrentHandle::trackers() const
|
QVector<TrackerEntry> TorrentHandle::trackers() const
|
||||||
{
|
{
|
||||||
QList<TrackerEntry> entries;
|
|
||||||
const std::vector<lt::announce_entry> announces = m_nativeHandle.trackers();
|
const std::vector<lt::announce_entry> announces = m_nativeHandle.trackers();
|
||||||
|
|
||||||
|
QVector<TrackerEntry> entries;
|
||||||
|
entries.reserve(announces.size());
|
||||||
for (const lt::announce_entry &tracker : announces)
|
for (const lt::announce_entry &tracker : announces)
|
||||||
entries << tracker;
|
entries << tracker;
|
||||||
|
|
||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,53 +402,55 @@ QHash<QString, TrackerInfo> TorrentHandle::trackerInfos() const
|
|||||||
return m_trackerInfos;
|
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) {
|
for (const TrackerEntry &tracker : trackers) {
|
||||||
if (addTracker(tracker))
|
if (!currentTrackers.contains(tracker)) {
|
||||||
addedTrackers << tracker;
|
m_nativeHandle.add_tracker(tracker.nativeEntry());
|
||||||
|
newTrackers << tracker;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!addedTrackers.isEmpty())
|
if (!newTrackers.isEmpty())
|
||||||
m_session->handleTorrentTrackersAdded(this, addedTrackers);
|
m_session->handleTorrentTrackersAdded(this, newTrackers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TorrentHandle::replaceTrackers(const QList<TrackerEntry> &trackers)
|
void TorrentHandle::replaceTrackers(const QVector<TrackerEntry> &trackers)
|
||||||
{
|
{
|
||||||
QList<TrackerEntry> existingTrackers = this->trackers();
|
QVector<TrackerEntry> currentTrackers = this->trackers();
|
||||||
QList<TrackerEntry> addedTrackers;
|
|
||||||
|
QVector<TrackerEntry> newTrackers;
|
||||||
|
newTrackers.reserve(trackers.size());
|
||||||
|
|
||||||
std::vector<lt::announce_entry> announces;
|
std::vector<lt::announce_entry> announces;
|
||||||
|
|
||||||
for (const TrackerEntry &tracker : trackers) {
|
for (const TrackerEntry &tracker : trackers) {
|
||||||
announces.push_back(tracker.nativeEntry());
|
announces.emplace_back(tracker.nativeEntry());
|
||||||
if (!existingTrackers.contains(tracker))
|
|
||||||
addedTrackers << tracker;
|
if (!currentTrackers.removeOne(tracker))
|
||||||
else
|
newTrackers << tracker;
|
||||||
existingTrackers.removeOne(tracker);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_nativeHandle.replace_trackers(announces);
|
m_nativeHandle.replace_trackers(announces);
|
||||||
if (addedTrackers.isEmpty() && existingTrackers.isEmpty()) {
|
|
||||||
|
if (newTrackers.isEmpty() && currentTrackers.isEmpty()) {
|
||||||
|
// when existing tracker reorders
|
||||||
m_session->handleTorrentTrackersChanged(this);
|
m_session->handleTorrentTrackersChanged(this);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!existingTrackers.isEmpty())
|
if (!currentTrackers.isEmpty())
|
||||||
m_session->handleTorrentTrackersRemoved(this, existingTrackers);
|
m_session->handleTorrentTrackersRemoved(this, currentTrackers);
|
||||||
if (!addedTrackers.isEmpty())
|
|
||||||
m_session->handleTorrentTrackersAdded(this, addedTrackers);
|
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> TorrentHandle::urlSeeds() const
|
||||||
{
|
{
|
||||||
QList<QUrl> urlSeeds;
|
QList<QUrl> urlSeeds;
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include <libtorrent/torrent_status.hpp>
|
#include <libtorrent/torrent_status.hpp>
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
@ -260,7 +261,7 @@ namespace BitTorrent
|
|||||||
bool hasError() const;
|
bool hasError() const;
|
||||||
bool hasFilteredPieces() const;
|
bool hasFilteredPieces() const;
|
||||||
int queuePosition() const;
|
int queuePosition() const;
|
||||||
QList<TrackerEntry> trackers() const;
|
QVector<TrackerEntry> trackers() const;
|
||||||
QHash<QString, TrackerInfo> trackerInfos() const;
|
QHash<QString, TrackerInfo> trackerInfos() const;
|
||||||
QList<QUrl> urlSeeds() const;
|
QList<QUrl> urlSeeds() const;
|
||||||
QString error() const;
|
QString error() const;
|
||||||
@ -323,8 +324,8 @@ namespace BitTorrent
|
|||||||
void setDownloadLimit(int limit);
|
void setDownloadLimit(int limit);
|
||||||
void setSuperSeeding(bool enable);
|
void setSuperSeeding(bool enable);
|
||||||
void flushCache();
|
void flushCache();
|
||||||
void addTrackers(const QList<TrackerEntry> &trackers);
|
void addTrackers(const QVector<TrackerEntry> &trackers);
|
||||||
void replaceTrackers(const QList<TrackerEntry> &trackers);
|
void replaceTrackers(const QVector<TrackerEntry> &trackers);
|
||||||
void addUrlSeeds(const QList<QUrl> &urlSeeds);
|
void addUrlSeeds(const QList<QUrl> &urlSeeds);
|
||||||
void removeUrlSeeds(const QList<QUrl> &urlSeeds);
|
void removeUrlSeeds(const QList<QUrl> &urlSeeds);
|
||||||
bool connectPeer(const PeerAddress &peerAddress);
|
bool connectPeer(const PeerAddress &peerAddress);
|
||||||
@ -388,7 +389,6 @@ namespace BitTorrent
|
|||||||
void move_impl(QString path, bool overwrite);
|
void move_impl(QString path, bool overwrite);
|
||||||
void moveStorage(const QString &newPath, bool overwrite);
|
void moveStorage(const QString &newPath, bool overwrite);
|
||||||
void manageIncompleteFiles();
|
void manageIncompleteFiles();
|
||||||
bool addTracker(const TrackerEntry &tracker);
|
|
||||||
bool addUrlSeed(const QUrl &urlSeed);
|
bool addUrlSeed(const QUrl &urlSeed);
|
||||||
bool removeUrlSeed(const QUrl &urlSeed);
|
bool removeUrlSeed(const QUrl &urlSeed);
|
||||||
void setFirstLastPiecePriorityImpl(bool enabled, const QVector<DownloadPriority> &updatedFilePrio = {});
|
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});
|
return m_nativeInfo->files().file_offset(LTFileIndex {index});
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<TrackerEntry> TorrentInfo::trackers() const
|
QVector<TrackerEntry> TorrentInfo::trackers() const
|
||||||
{
|
{
|
||||||
if (!isValid()) return {};
|
if (!isValid()) return {};
|
||||||
|
|
||||||
QList<TrackerEntry> trackers;
|
const std::vector<lt::announce_entry> trackers = m_nativeInfo->trackers();
|
||||||
for (const lt::announce_entry &tracker : m_nativeInfo->trackers())
|
|
||||||
trackers.append(tracker);
|
|
||||||
|
|
||||||
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
|
QList<QUrl> TorrentInfo::urlSeeds() const
|
||||||
|
@ -88,7 +88,7 @@ namespace BitTorrent
|
|||||||
QString origFilePath(int index) const;
|
QString origFilePath(int index) const;
|
||||||
qlonglong fileSize(int index) const;
|
qlonglong fileSize(int index) const;
|
||||||
qlonglong fileOffset(int index) const;
|
qlonglong fileOffset(int index) const;
|
||||||
QList<TrackerEntry> trackers() const;
|
QVector<TrackerEntry> trackers() const;
|
||||||
QList<QUrl> urlSeeds() const;
|
QList<QUrl> urlSeeds() const;
|
||||||
QByteArray metadata() const;
|
QByteArray metadata() const;
|
||||||
QStringList filesForPiece(int pieceIndex) const;
|
QStringList filesForPiece(int pieceIndex) const;
|
||||||
|
@ -47,6 +47,7 @@ namespace BitTorrent
|
|||||||
NotWorking = 4
|
NotWorking = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TrackerEntry() = default;
|
||||||
TrackerEntry(const QString &url);
|
TrackerEntry(const QString &url);
|
||||||
TrackerEntry(const lt::announce_entry &nativeEntry);
|
TrackerEntry(const lt::announce_entry &nativeEntry);
|
||||||
TrackerEntry(const TrackerEntry &other) = default;
|
TrackerEntry(const TrackerEntry &other) = default;
|
||||||
|
@ -184,9 +184,10 @@ void TrackerListWidget::moveSelectionUp()
|
|||||||
|
|
||||||
setSelectionModel(selection);
|
setSelectionModel(selection);
|
||||||
// Update torrent trackers
|
// Update torrent trackers
|
||||||
QList<BitTorrent::TrackerEntry> trackers;
|
QVector<BitTorrent::TrackerEntry> trackers;
|
||||||
|
trackers.reserve(topLevelItemCount());
|
||||||
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) {
|
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) {
|
||||||
QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
|
const QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
|
||||||
BitTorrent::TrackerEntry e(trackerURL);
|
BitTorrent::TrackerEntry e(trackerURL);
|
||||||
e.setTier(i - NB_STICKY_ITEM);
|
e.setTier(i - NB_STICKY_ITEM);
|
||||||
trackers.append(e);
|
trackers.append(e);
|
||||||
@ -225,9 +226,10 @@ void TrackerListWidget::moveSelectionDown()
|
|||||||
|
|
||||||
setSelectionModel(selection);
|
setSelectionModel(selection);
|
||||||
// Update torrent trackers
|
// Update torrent trackers
|
||||||
QList<BitTorrent::TrackerEntry> trackers;
|
QVector<BitTorrent::TrackerEntry> trackers;
|
||||||
|
trackers.reserve(topLevelItemCount());
|
||||||
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) {
|
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) {
|
||||||
QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
|
const QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
|
||||||
BitTorrent::TrackerEntry e(trackerURL);
|
BitTorrent::TrackerEntry e(trackerURL);
|
||||||
e.setTier(i - NB_STICKY_ITEM);
|
e.setTier(i - NB_STICKY_ITEM);
|
||||||
trackers.append(e);
|
trackers.append(e);
|
||||||
@ -388,7 +390,7 @@ void TrackerListWidget::askForTrackers()
|
|||||||
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
||||||
if (!torrent) return;
|
if (!torrent) return;
|
||||||
|
|
||||||
QList<BitTorrent::TrackerEntry> trackers;
|
QVector<BitTorrent::TrackerEntry> trackers;
|
||||||
for (const QString &tracker : asConst(TrackersAdditionDialog::askForTrackers(this, torrent)))
|
for (const QString &tracker : asConst(TrackersAdditionDialog::askForTrackers(this, torrent)))
|
||||||
trackers << tracker;
|
trackers << tracker;
|
||||||
|
|
||||||
@ -430,14 +432,17 @@ void TrackerListWidget::deleteSelectedTrackers()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterate over the trackers and remove the selected ones
|
// Iterate over the trackers and remove the selected ones
|
||||||
QList<BitTorrent::TrackerEntry> remainingTrackers;
|
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||||
const QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
QVector<BitTorrent::TrackerEntry> remainingTrackers;
|
||||||
|
remainingTrackers.reserve(trackers.size());
|
||||||
|
|
||||||
for (const BitTorrent::TrackerEntry &entry : trackers) {
|
for (const BitTorrent::TrackerEntry &entry : trackers) {
|
||||||
if (!urlsToRemove.contains(entry.url()))
|
if (!urlsToRemove.contains(entry.url()))
|
||||||
remainingTrackers.push_back(entry);
|
remainingTrackers.push_back(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent->replaceTrackers(remainingTrackers);
|
torrent->replaceTrackers(remainingTrackers);
|
||||||
|
|
||||||
if (!torrent->isPaused())
|
if (!torrent->isPaused())
|
||||||
torrent->forceReannounce();
|
torrent->forceReannounce();
|
||||||
}
|
}
|
||||||
@ -451,10 +456,10 @@ void TrackerListWidget::editSelectedTracker()
|
|||||||
if (selectedTrackerItems.isEmpty()) return;
|
if (selectedTrackerItems.isEmpty()) return;
|
||||||
|
|
||||||
// During multi-select only process item selected last
|
// During multi-select only process item selected last
|
||||||
QUrl trackerURL = selectedTrackerItems.last()->text(COL_URL);
|
const QUrl trackerURL = selectedTrackerItems.last()->text(COL_URL);
|
||||||
|
|
||||||
bool ok;
|
bool ok;
|
||||||
QUrl newTrackerURL = AutoExpandableDialog::getText(this, tr("Tracker editing"), tr("Tracker URL:"),
|
const QUrl newTrackerURL = AutoExpandableDialog::getText(this, tr("Tracker editing"), tr("Tracker URL:"),
|
||||||
QLineEdit::Normal, trackerURL.toString(), &ok).trimmed();
|
QLineEdit::Normal, trackerURL.toString(), &ok).trimmed();
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
|
||||||
@ -464,23 +469,24 @@ void TrackerListWidget::editSelectedTracker()
|
|||||||
}
|
}
|
||||||
if (newTrackerURL == trackerURL) return;
|
if (newTrackerURL == trackerURL) return;
|
||||||
|
|
||||||
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||||
bool match = false;
|
bool match = false;
|
||||||
for (auto &entry : trackers) {
|
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."));
|
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trackerURL == QUrl(entry.url()) && !match) {
|
if (!match && (trackerURL == QUrl(entry.url()))) {
|
||||||
|
match = true;
|
||||||
BitTorrent::TrackerEntry newEntry(newTrackerURL.toString());
|
BitTorrent::TrackerEntry newEntry(newTrackerURL.toString());
|
||||||
newEntry.setTier(entry.tier());
|
newEntry.setTier(entry.tier());
|
||||||
match = true;
|
|
||||||
entry = newEntry;
|
entry = newEntry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
torrent->replaceTrackers(trackers);
|
torrent->replaceTrackers(trackers);
|
||||||
|
|
||||||
if (!torrent->isPaused())
|
if (!torrent->isPaused())
|
||||||
torrent->forceReannounce();
|
torrent->forceReannounce();
|
||||||
}
|
}
|
||||||
@ -493,7 +499,7 @@ void TrackerListWidget::reannounceSelected()
|
|||||||
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
||||||
if (!torrent) return;
|
if (!torrent) return;
|
||||||
|
|
||||||
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||||
|
|
||||||
for (const QTreeWidgetItem *item : selItems) {
|
for (const QTreeWidgetItem *item : selItems) {
|
||||||
// DHT case
|
// DHT case
|
||||||
|
@ -89,12 +89,11 @@ void TrackersAdditionDialog::torrentListDownloadFinished(const Net::DownloadResu
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load from torrent handle
|
const QStringList trackersFromUser = m_ui->textEditTrackersList->toPlainText().split('\n');
|
||||||
QList<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers();
|
QVector<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers();
|
||||||
// Load from current user list
|
existingTrackers.reserve(trackersFromUser.size());
|
||||||
const QStringList tmp = m_ui->textEditTrackersList->toPlainText().split('\n');
|
for (const QString &userURL : trackersFromUser) {
|
||||||
for (const QString &userURL : tmp) {
|
const BitTorrent::TrackerEntry userTracker(userURL);
|
||||||
BitTorrent::TrackerEntry userTracker(userURL);
|
|
||||||
if (!existingTrackers.contains(userTracker))
|
if (!existingTrackers.contains(userTracker))
|
||||||
existingTrackers << userTracker;
|
existingTrackers << userTracker;
|
||||||
}
|
}
|
||||||
|
@ -474,7 +474,7 @@ void TrackerFiltersList::applyFilter(int row)
|
|||||||
void TrackerFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torrent)
|
void TrackerFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
QString hash = torrent->hash();
|
QString hash = torrent->hash();
|
||||||
const QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||||
for (const BitTorrent::TrackerEntry &tracker : trackers)
|
for (const BitTorrent::TrackerEntry &tracker : trackers)
|
||||||
addItem(tracker.url(), hash);
|
addItem(tracker.url(), hash);
|
||||||
|
|
||||||
@ -488,7 +488,7 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torre
|
|||||||
void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const torrent)
|
void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
QString hash = torrent->hash();
|
QString hash = torrent->hash();
|
||||||
const QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||||
for (const BitTorrent::TrackerEntry &tracker : trackers)
|
for (const BitTorrent::TrackerEntry &tracker : trackers)
|
||||||
removeItem(tracker.url(), hash);
|
removeItem(tracker.url(), hash);
|
||||||
|
|
||||||
@ -647,13 +647,13 @@ void TransferListFiltersWidget::setDownloadTrackerFavicon(bool value)
|
|||||||
m_trackerFilters->setDownloadTrackerFavicon(value);
|
m_trackerFilters->setDownloadTrackerFavicon(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListFiltersWidget::addTrackers(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers)
|
void TransferListFiltersWidget::addTrackers(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers)
|
||||||
{
|
{
|
||||||
for (const BitTorrent::TrackerEntry &tracker : trackers)
|
for (const BitTorrent::TrackerEntry &tracker : trackers)
|
||||||
m_trackerFilters->addItem(tracker.url(), torrent->hash());
|
m_trackerFilters->addItem(tracker.url(), torrent->hash());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransferListFiltersWidget::removeTrackers(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers)
|
void TransferListFiltersWidget::removeTrackers(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers)
|
||||||
{
|
{
|
||||||
for (const BitTorrent::TrackerEntry &tracker : trackers)
|
for (const BitTorrent::TrackerEntry &tracker : trackers)
|
||||||
m_trackerFilters->removeItem(tracker.url(), torrent->hash());
|
m_trackerFilters->removeItem(tracker.url(), torrent->hash());
|
||||||
|
@ -148,8 +148,8 @@ public:
|
|||||||
void setDownloadTrackerFavicon(bool value);
|
void setDownloadTrackerFavicon(bool value);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addTrackers(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers);
|
void addTrackers(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
|
||||||
void removeTrackers(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers);
|
void removeTrackers(BitTorrent::TorrentHandle *const torrent, const QVector<BitTorrent::TrackerEntry> &trackers);
|
||||||
void changeTrackerless(BitTorrent::TorrentHandle *const torrent, bool trackerless);
|
void changeTrackerless(BitTorrent::TorrentHandle *const torrent, bool trackerless);
|
||||||
void trackerSuccess(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
void trackerSuccess(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
||||||
void trackerWarning(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
void trackerWarning(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
||||||
|
@ -604,7 +604,7 @@ void TorrentsController::addTrackersAction()
|
|||||||
if (!torrent)
|
if (!torrent)
|
||||||
throw APIError(APIErrorType::NotFound);
|
throw APIError(APIErrorType::NotFound);
|
||||||
|
|
||||||
QList<BitTorrent::TrackerEntry> trackers;
|
QVector<BitTorrent::TrackerEntry> trackers;
|
||||||
for (const QString &urlStr : asConst(params()["urls"].split('\n'))) {
|
for (const QString &urlStr : asConst(params()["urls"].split('\n'))) {
|
||||||
const QUrl url {urlStr.trimmed()};
|
const QUrl url {urlStr.trimmed()};
|
||||||
if (url.isValid())
|
if (url.isValid())
|
||||||
@ -632,7 +632,7 @@ void TorrentsController::editTrackerAction()
|
|||||||
if (!newTrackerUrl.isValid())
|
if (!newTrackerUrl.isValid())
|
||||||
throw APIError(APIErrorType::BadParams, "New tracker URL is invalid");
|
throw APIError(APIErrorType::BadParams, "New tracker URL is invalid");
|
||||||
|
|
||||||
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||||
bool match = false;
|
bool match = false;
|
||||||
for (BitTorrent::TrackerEntry &tracker : trackers) {
|
for (BitTorrent::TrackerEntry &tracker : trackers) {
|
||||||
const QUrl trackerUrl(tracker.url());
|
const QUrl trackerUrl(tracker.url());
|
||||||
@ -649,6 +649,7 @@ void TorrentsController::editTrackerAction()
|
|||||||
throw APIError(APIErrorType::Conflict, "Tracker not found");
|
throw APIError(APIErrorType::Conflict, "Tracker not found");
|
||||||
|
|
||||||
torrent->replaceTrackers(trackers);
|
torrent->replaceTrackers(trackers);
|
||||||
|
|
||||||
if (!torrent->isPaused())
|
if (!torrent->isPaused())
|
||||||
torrent->forceReannounce();
|
torrent->forceReannounce();
|
||||||
}
|
}
|
||||||
@ -664,8 +665,9 @@ void TorrentsController::removeTrackersAction()
|
|||||||
if (!torrent)
|
if (!torrent)
|
||||||
throw APIError(APIErrorType::NotFound);
|
throw APIError(APIErrorType::NotFound);
|
||||||
|
|
||||||
QList<BitTorrent::TrackerEntry> remainingTrackers;
|
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||||
const QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
QVector<BitTorrent::TrackerEntry> remainingTrackers;
|
||||||
|
remainingTrackers.reserve(trackers.size());
|
||||||
for (const BitTorrent::TrackerEntry &entry : trackers) {
|
for (const BitTorrent::TrackerEntry &entry : trackers) {
|
||||||
if (!urls.contains(entry.url()))
|
if (!urls.contains(entry.url()))
|
||||||
remainingTrackers.push_back(entry);
|
remainingTrackers.push_back(entry);
|
||||||
@ -675,6 +677,7 @@ void TorrentsController::removeTrackersAction()
|
|||||||
throw APIError(APIErrorType::Conflict, "No trackers were removed");
|
throw APIError(APIErrorType::Conflict, "No trackers were removed");
|
||||||
|
|
||||||
torrent->replaceTrackers(remainingTrackers);
|
torrent->replaceTrackers(remainingTrackers);
|
||||||
|
|
||||||
if (!torrent->isPaused())
|
if (!torrent->isPaused())
|
||||||
torrent->forceReannounce();
|
torrent->forceReannounce();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user