mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-22 16:37:21 -06:00
Replace QList by QVector for tracker related operations
This commit is contained in:
@@ -184,9 +184,10 @@ void TrackerListWidget::moveSelectionUp()
|
||||
|
||||
setSelectionModel(selection);
|
||||
// Update torrent trackers
|
||||
QList<BitTorrent::TrackerEntry> trackers;
|
||||
QVector<BitTorrent::TrackerEntry> trackers;
|
||||
trackers.reserve(topLevelItemCount());
|
||||
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);
|
||||
e.setTier(i - NB_STICKY_ITEM);
|
||||
trackers.append(e);
|
||||
@@ -225,9 +226,10 @@ void TrackerListWidget::moveSelectionDown()
|
||||
|
||||
setSelectionModel(selection);
|
||||
// Update torrent trackers
|
||||
QList<BitTorrent::TrackerEntry> trackers;
|
||||
QVector<BitTorrent::TrackerEntry> trackers;
|
||||
trackers.reserve(topLevelItemCount());
|
||||
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);
|
||||
e.setTier(i - NB_STICKY_ITEM);
|
||||
trackers.append(e);
|
||||
@@ -388,7 +390,7 @@ void TrackerListWidget::askForTrackers()
|
||||
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
||||
if (!torrent) return;
|
||||
|
||||
QList<BitTorrent::TrackerEntry> trackers;
|
||||
QVector<BitTorrent::TrackerEntry> trackers;
|
||||
for (const QString &tracker : asConst(TrackersAdditionDialog::askForTrackers(this, torrent)))
|
||||
trackers << tracker;
|
||||
|
||||
@@ -430,14 +432,17 @@ void TrackerListWidget::deleteSelectedTrackers()
|
||||
}
|
||||
|
||||
// Iterate over the trackers and remove the selected ones
|
||||
QList<BitTorrent::TrackerEntry> remainingTrackers;
|
||||
const QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
QVector<BitTorrent::TrackerEntry> remainingTrackers;
|
||||
remainingTrackers.reserve(trackers.size());
|
||||
|
||||
for (const BitTorrent::TrackerEntry &entry : trackers) {
|
||||
if (!urlsToRemove.contains(entry.url()))
|
||||
remainingTrackers.push_back(entry);
|
||||
}
|
||||
|
||||
torrent->replaceTrackers(remainingTrackers);
|
||||
|
||||
if (!torrent->isPaused())
|
||||
torrent->forceReannounce();
|
||||
}
|
||||
@@ -451,10 +456,10 @@ void TrackerListWidget::editSelectedTracker()
|
||||
if (selectedTrackerItems.isEmpty()) return;
|
||||
|
||||
// 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;
|
||||
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();
|
||||
if (!ok) return;
|
||||
|
||||
@@ -464,23 +469,24 @@ void TrackerListWidget::editSelectedTracker()
|
||||
}
|
||||
if (newTrackerURL == trackerURL) return;
|
||||
|
||||
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
bool match = false;
|
||||
for (auto &entry : trackers) {
|
||||
for (BitTorrent::TrackerEntry &entry : trackers) {
|
||||
if (newTrackerURL == QUrl(entry.url())) {
|
||||
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (trackerURL == QUrl(entry.url()) && !match) {
|
||||
if (!match && (trackerURL == QUrl(entry.url()))) {
|
||||
match = true;
|
||||
BitTorrent::TrackerEntry newEntry(newTrackerURL.toString());
|
||||
newEntry.setTier(entry.tier());
|
||||
match = true;
|
||||
entry = newEntry;
|
||||
}
|
||||
}
|
||||
|
||||
torrent->replaceTrackers(trackers);
|
||||
|
||||
if (!torrent->isPaused())
|
||||
torrent->forceReannounce();
|
||||
}
|
||||
@@ -493,7 +499,7 @@ void TrackerListWidget::reannounceSelected()
|
||||
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
||||
if (!torrent) return;
|
||||
|
||||
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
|
||||
for (const QTreeWidgetItem *item : selItems) {
|
||||
// DHT case
|
||||
|
||||
@@ -89,12 +89,11 @@ void TrackersAdditionDialog::torrentListDownloadFinished(const Net::DownloadResu
|
||||
return;
|
||||
}
|
||||
|
||||
// Load from torrent handle
|
||||
QList<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers();
|
||||
// Load from current user list
|
||||
const QStringList tmp = m_ui->textEditTrackersList->toPlainText().split('\n');
|
||||
for (const QString &userURL : tmp) {
|
||||
BitTorrent::TrackerEntry userTracker(userURL);
|
||||
const QStringList trackersFromUser = m_ui->textEditTrackersList->toPlainText().split('\n');
|
||||
QVector<BitTorrent::TrackerEntry> existingTrackers = m_torrent->trackers();
|
||||
existingTrackers.reserve(trackersFromUser.size());
|
||||
for (const QString &userURL : trackersFromUser) {
|
||||
const BitTorrent::TrackerEntry userTracker(userURL);
|
||||
if (!existingTrackers.contains(userTracker))
|
||||
existingTrackers << userTracker;
|
||||
}
|
||||
|
||||
@@ -474,7 +474,7 @@ void TrackerFiltersList::applyFilter(int row)
|
||||
void TrackerFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torrent)
|
||||
{
|
||||
QString hash = torrent->hash();
|
||||
const QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
for (const BitTorrent::TrackerEntry &tracker : trackers)
|
||||
addItem(tracker.url(), hash);
|
||||
|
||||
@@ -488,7 +488,7 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::TorrentHandle *const torre
|
||||
void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::TorrentHandle *const torrent)
|
||||
{
|
||||
QString hash = torrent->hash();
|
||||
const QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
const QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
for (const BitTorrent::TrackerEntry &tracker : trackers)
|
||||
removeItem(tracker.url(), hash);
|
||||
|
||||
@@ -647,13 +647,13 @@ void TransferListFiltersWidget::setDownloadTrackerFavicon(bool 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)
|
||||
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)
|
||||
m_trackerFilters->removeItem(tracker.url(), torrent->hash());
|
||||
|
||||
@@ -148,8 +148,8 @@ public:
|
||||
void setDownloadTrackerFavicon(bool value);
|
||||
|
||||
public slots:
|
||||
void addTrackers(BitTorrent::TorrentHandle *const torrent, const QList<BitTorrent::TrackerEntry> &trackers);
|
||||
void removeTrackers(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 QVector<BitTorrent::TrackerEntry> &trackers);
|
||||
void changeTrackerless(BitTorrent::TorrentHandle *const torrent, bool trackerless);
|
||||
void trackerSuccess(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
||||
void trackerWarning(BitTorrent::TorrentHandle *const torrent, const QString &tracker);
|
||||
|
||||
Reference in New Issue
Block a user