mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 08:48:07 -06:00
Merge pull request #14479 from glassez/trackerentry
Improve tracker entries handling
This commit is contained in:
@@ -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()
|
||||
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()
|
||||
|
||||
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()
|
||||
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()
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
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()
|
||||
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()
|
||||
// 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;
|
||||
|
||||
@@ -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
|
||||
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');
|
||||
|
||||
@@ -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
|
||||
continue;
|
||||
}
|
||||
|
||||
BitTorrent::TrackerEntry entry {line.toString()};
|
||||
entry.setTier(tier);
|
||||
entries.append(entry);
|
||||
entries.append({line.toString(), tier});
|
||||
}
|
||||
|
||||
return entries;
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
namespace BitTorrent
|
||||
{
|
||||
class TrackerEntry;
|
||||
struct TrackerEntry;
|
||||
}
|
||||
|
||||
namespace Ui
|
||||
|
||||
@@ -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
|
||||
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)
|
||||
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)
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace BitTorrent
|
||||
{
|
||||
class InfoHash;
|
||||
class Torrent;
|
||||
class TrackerEntry;
|
||||
struct TrackerEntry;
|
||||
}
|
||||
|
||||
namespace Net
|
||||
|
||||
Reference in New Issue
Block a user