|
|
@ -1,6 +1,6 @@ |
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent. |
|
|
|
* Bittorrent Client using Qt and libtorrent. |
|
|
|
* Copyright (C) 2006 Christophe Dumez |
|
|
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org> |
|
|
|
* |
|
|
|
* |
|
|
|
* This program is free software; you can redistribute it and/or |
|
|
|
* This program is free software; you can redistribute it and/or |
|
|
|
* modify it under the terms of the GNU General Public License |
|
|
|
* modify it under the terms of the GNU General Public License |
|
|
@ -24,8 +24,6 @@ |
|
|
|
* modify file(s), you may extend this exception to your version of the file(s), |
|
|
|
* modify file(s), you may extend this exception to your version of the file(s), |
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this |
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this |
|
|
|
* exception statement from your version. |
|
|
|
* exception statement from your version. |
|
|
|
* |
|
|
|
|
|
|
|
* Contact : chris@qbittorrent.org |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include "trackerlist.h" |
|
|
|
#include "trackerlist.h" |
|
|
@ -132,53 +130,57 @@ TrackerList::~TrackerList() |
|
|
|
saveSettings(); |
|
|
|
saveSettings(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem*> TrackerList::getSelectedTrackerItems() const { |
|
|
|
QList<QTreeWidgetItem*> TrackerList::getSelectedTrackerItems() const |
|
|
|
const QList<QTreeWidgetItem*> selected_items = selectedItems(); |
|
|
|
{ |
|
|
|
QList<QTreeWidgetItem*> selected_trackers; |
|
|
|
const QList<QTreeWidgetItem *> selectedTrackerItems = selectedItems(); |
|
|
|
foreach (QTreeWidgetItem *item, selected_items) { |
|
|
|
QList<QTreeWidgetItem *> selectedTrackers; |
|
|
|
if (indexOfTopLevelItem(item) >= NB_STICKY_ITEM) { // Ignore STICKY ITEMS
|
|
|
|
foreach (QTreeWidgetItem *item, selectedTrackerItems) { |
|
|
|
selected_trackers << item; |
|
|
|
if (indexOfTopLevelItem(item) >= NB_STICKY_ITEM) // Ignore STICKY ITEMS
|
|
|
|
} |
|
|
|
selectedTrackers << item; |
|
|
|
} |
|
|
|
} |
|
|
|
return selected_trackers; |
|
|
|
|
|
|
|
|
|
|
|
return selectedTrackers; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerList::setRowColor(int row, QColor color) { |
|
|
|
void TrackerList::setRowColor(int row, QColor color) |
|
|
|
|
|
|
|
{ |
|
|
|
unsigned int nbColumns = columnCount(); |
|
|
|
unsigned int nbColumns = columnCount(); |
|
|
|
QTreeWidgetItem *item = topLevelItem(row); |
|
|
|
QTreeWidgetItem *item = topLevelItem(row); |
|
|
|
for (unsigned int i=0; i<nbColumns; ++i) { |
|
|
|
for (unsigned int i = 0; i < nbColumns; ++i) |
|
|
|
item->setData(i, Qt::ForegroundRole, color); |
|
|
|
item->setData(i, Qt::ForegroundRole, color); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerList::moveSelectionUp() { |
|
|
|
void TrackerList::moveSelectionUp() |
|
|
|
|
|
|
|
{ |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
if (!torrent) { |
|
|
|
if (!torrent) { |
|
|
|
clear(); |
|
|
|
clear(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems(); |
|
|
|
QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems(); |
|
|
|
if (selected_items.isEmpty()) return; |
|
|
|
if (selectedTrackerItems.isEmpty()) return; |
|
|
|
|
|
|
|
|
|
|
|
bool change = false; |
|
|
|
bool change = false; |
|
|
|
foreach (QTreeWidgetItem *item, selected_items) { |
|
|
|
foreach (QTreeWidgetItem *item, selectedTrackerItems) { |
|
|
|
int index = indexOfTopLevelItem(item); |
|
|
|
int index = indexOfTopLevelItem(item); |
|
|
|
if (index > NB_STICKY_ITEM) { |
|
|
|
if (index > NB_STICKY_ITEM) { |
|
|
|
insertTopLevelItem(index-1, takeTopLevelItem(index)); |
|
|
|
insertTopLevelItem(index - 1, takeTopLevelItem(index)); |
|
|
|
change = true; |
|
|
|
change = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!change) return; |
|
|
|
if (!change) return; |
|
|
|
|
|
|
|
|
|
|
|
// Restore selection
|
|
|
|
// Restore selection
|
|
|
|
QItemSelectionModel *selection = selectionModel(); |
|
|
|
QItemSelectionModel *selection = selectionModel(); |
|
|
|
foreach (QTreeWidgetItem *item, selected_items) { |
|
|
|
foreach (QTreeWidgetItem *item, selectedTrackerItems) |
|
|
|
selection->select(indexFromItem(item), QItemSelectionModel::Rows|QItemSelectionModel::Select); |
|
|
|
selection->select(indexFromItem(item), (QItemSelectionModel::Rows | QItemSelectionModel::Select)); |
|
|
|
} |
|
|
|
|
|
|
|
setSelectionModel(selection); |
|
|
|
setSelectionModel(selection); |
|
|
|
// Update torrent trackers
|
|
|
|
// Update torrent trackers
|
|
|
|
QList<BitTorrent::TrackerEntry> trackers; |
|
|
|
QList<BitTorrent::TrackerEntry> trackers; |
|
|
|
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) { |
|
|
|
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) { |
|
|
|
QString tracker_url = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString(); |
|
|
|
QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString(); |
|
|
|
BitTorrent::TrackerEntry e(tracker_url); |
|
|
|
BitTorrent::TrackerEntry e(trackerURL); |
|
|
|
e.setTier(i - NB_STICKY_ITEM); |
|
|
|
e.setTier(i - NB_STICKY_ITEM); |
|
|
|
trackers.append(e); |
|
|
|
trackers.append(e); |
|
|
|
} |
|
|
|
} |
|
|
@ -189,34 +191,37 @@ void TrackerList::moveSelectionUp() { |
|
|
|
torrent->forceReannounce(); |
|
|
|
torrent->forceReannounce(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerList::moveSelectionDown() { |
|
|
|
void TrackerList::moveSelectionDown() |
|
|
|
|
|
|
|
{ |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
if (!torrent) { |
|
|
|
if (!torrent) { |
|
|
|
clear(); |
|
|
|
clear(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems(); |
|
|
|
QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems(); |
|
|
|
if (selected_items.isEmpty()) return; |
|
|
|
if (selectedTrackerItems.isEmpty()) return; |
|
|
|
|
|
|
|
|
|
|
|
bool change = false; |
|
|
|
bool change = false; |
|
|
|
for (int i=selectedItems().size()-1; i>= 0; --i) { |
|
|
|
for (int i = selectedItems().size() - 1; i >= 0; --i) { |
|
|
|
int index = indexOfTopLevelItem(selected_items.at(i)); |
|
|
|
int index = indexOfTopLevelItem(selectedTrackerItems.at(i)); |
|
|
|
if (index < topLevelItemCount()-1) { |
|
|
|
if (index < (topLevelItemCount() - 1)) { |
|
|
|
insertTopLevelItem(index+1, takeTopLevelItem(index)); |
|
|
|
insertTopLevelItem(index + 1, takeTopLevelItem(index)); |
|
|
|
change = true; |
|
|
|
change = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!change) return; |
|
|
|
if (!change) return; |
|
|
|
|
|
|
|
|
|
|
|
// Restore selection
|
|
|
|
// Restore selection
|
|
|
|
QItemSelectionModel *selection = selectionModel(); |
|
|
|
QItemSelectionModel *selection = selectionModel(); |
|
|
|
foreach (QTreeWidgetItem *item, selected_items) { |
|
|
|
foreach (QTreeWidgetItem *item, selectedTrackerItems) |
|
|
|
selection->select(indexFromItem(item), QItemSelectionModel::Rows|QItemSelectionModel::Select); |
|
|
|
selection->select(indexFromItem(item), (QItemSelectionModel::Rows | QItemSelectionModel::Select)); |
|
|
|
} |
|
|
|
|
|
|
|
setSelectionModel(selection); |
|
|
|
setSelectionModel(selection); |
|
|
|
// Update torrent trackers
|
|
|
|
// Update torrent trackers
|
|
|
|
QList<BitTorrent::TrackerEntry> trackers; |
|
|
|
QList<BitTorrent::TrackerEntry> trackers; |
|
|
|
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) { |
|
|
|
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) { |
|
|
|
QString tracker_url = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString(); |
|
|
|
QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString(); |
|
|
|
BitTorrent::TrackerEntry e(tracker_url); |
|
|
|
BitTorrent::TrackerEntry e(trackerURL); |
|
|
|
e.setTier(i - NB_STICKY_ITEM); |
|
|
|
e.setTier(i - NB_STICKY_ITEM); |
|
|
|
trackers.append(e); |
|
|
|
trackers.append(e); |
|
|
|
} |
|
|
|
} |
|
|
@ -245,7 +250,8 @@ void TrackerList::clear() |
|
|
|
m_LSDItem->setText(COL_MSG, ""); |
|
|
|
m_LSDItem->setText(COL_MSG, ""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerList::loadStickyItems(BitTorrent::TorrentHandle *const torrent) { |
|
|
|
void TrackerList::loadStickyItems(BitTorrent::TorrentHandle *const torrent) |
|
|
|
|
|
|
|
{ |
|
|
|
QString working = tr("Working"); |
|
|
|
QString working = tr("Working"); |
|
|
|
QString disabled = tr("Disabled"); |
|
|
|
QString disabled = tr("Disabled"); |
|
|
|
|
|
|
|
|
|
|
@ -308,29 +314,32 @@ void TrackerList::loadStickyItems(BitTorrent::TorrentHandle *const torrent) { |
|
|
|
m_LSDItem->setText(COL_PEERS, QString::number(peersLSD)); |
|
|
|
m_LSDItem->setText(COL_PEERS, QString::number(peersLSD)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerList::loadTrackers() { |
|
|
|
void TrackerList::loadTrackers() |
|
|
|
|
|
|
|
{ |
|
|
|
// Load trackers from torrent handle
|
|
|
|
// Load trackers from torrent handle
|
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
if (!torrent) return; |
|
|
|
if (!torrent) return; |
|
|
|
|
|
|
|
|
|
|
|
loadStickyItems(torrent); |
|
|
|
loadStickyItems(torrent); |
|
|
|
|
|
|
|
|
|
|
|
// Load actual trackers information
|
|
|
|
// Load actual trackers information
|
|
|
|
QHash<QString, BitTorrent::TrackerInfo> trackers_data = torrent->trackerInfos(); |
|
|
|
QHash<QString, BitTorrent::TrackerInfo> trackerData = torrent->trackerInfos(); |
|
|
|
QStringList old_trackers_urls = m_trackerItems.keys(); |
|
|
|
QStringList oldTrackerURLs = m_trackerItems.keys(); |
|
|
|
foreach (const BitTorrent::TrackerEntry &entry, torrent->trackers()) { |
|
|
|
foreach (const BitTorrent::TrackerEntry &entry, torrent->trackers()) { |
|
|
|
QString trackerUrl = entry.url(); |
|
|
|
QString trackerURL = entry.url(); |
|
|
|
QTreeWidgetItem *item = m_trackerItems.value(trackerUrl, 0); |
|
|
|
QTreeWidgetItem *item = m_trackerItems.value(trackerURL, 0); |
|
|
|
if (!item) { |
|
|
|
if (!item) { |
|
|
|
item = new QTreeWidgetItem(); |
|
|
|
item = new QTreeWidgetItem(); |
|
|
|
item->setText(COL_URL, trackerUrl); |
|
|
|
item->setText(COL_URL, trackerURL); |
|
|
|
addTopLevelItem(item); |
|
|
|
addTopLevelItem(item); |
|
|
|
m_trackerItems[trackerUrl] = item; |
|
|
|
m_trackerItems[trackerURL] = item; |
|
|
|
} else { |
|
|
|
} |
|
|
|
old_trackers_urls.removeOne(trackerUrl); |
|
|
|
else { |
|
|
|
|
|
|
|
oldTrackerURLs.removeOne(trackerURL); |
|
|
|
} |
|
|
|
} |
|
|
|
item->setText(COL_TIER, QString::number(entry.tier())); |
|
|
|
item->setText(COL_TIER, QString::number(entry.tier())); |
|
|
|
BitTorrent::TrackerInfo data = trackers_data.value(trackerUrl); |
|
|
|
BitTorrent::TrackerInfo data = trackerData.value(trackerURL); |
|
|
|
QString error_message = data.lastMessage.trimmed(); |
|
|
|
QString errorMessage = data.lastMessage.trimmed(); |
|
|
|
switch (entry.status()) { |
|
|
|
switch (entry.status()) { |
|
|
|
case BitTorrent::TrackerEntry::Working: |
|
|
|
case BitTorrent::TrackerEntry::Working: |
|
|
|
item->setText(COL_STATUS, tr("Working")); |
|
|
|
item->setText(COL_STATUS, tr("Working")); |
|
|
@ -342,15 +351,15 @@ void TrackerList::loadTrackers() { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BitTorrent::TrackerEntry::NotWorking: |
|
|
|
case BitTorrent::TrackerEntry::NotWorking: |
|
|
|
item->setText(COL_STATUS, tr("Not working")); |
|
|
|
item->setText(COL_STATUS, tr("Not working")); |
|
|
|
item->setText(COL_MSG, error_message); |
|
|
|
item->setText(COL_MSG, errorMessage); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case BitTorrent::TrackerEntry::NotContacted: |
|
|
|
case BitTorrent::TrackerEntry::NotContacted: |
|
|
|
item->setText(COL_STATUS, tr("Not contacted yet")); |
|
|
|
item->setText(COL_STATUS, tr("Not contacted yet")); |
|
|
|
item->setText(COL_MSG, ""); |
|
|
|
item->setText(COL_MSG, ""); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
item->setText(COL_RECEIVED, QString::number(data.numPeers)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
item->setText(COL_RECEIVED, QString::number(data.numPeers)); |
|
|
|
#if LIBTORRENT_VERSION_NUM >= 10000 |
|
|
|
#if LIBTORRENT_VERSION_NUM >= 10000 |
|
|
|
item->setText(COL_SEEDS, QString::number(entry.nativeEntry().scrape_complete > 0 ? entry.nativeEntry().scrape_complete : 0)); |
|
|
|
item->setText(COL_SEEDS, QString::number(entry.nativeEntry().scrape_complete > 0 ? entry.nativeEntry().scrape_complete : 0)); |
|
|
|
item->setText(COL_PEERS, QString::number(entry.nativeEntry().scrape_incomplete > 0 ? entry.nativeEntry().scrape_incomplete : 0)); |
|
|
|
item->setText(COL_PEERS, QString::number(entry.nativeEntry().scrape_incomplete > 0 ? entry.nativeEntry().scrape_incomplete : 0)); |
|
|
@ -368,124 +377,127 @@ void TrackerList::loadTrackers() { |
|
|
|
item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); |
|
|
|
item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter)); |
|
|
|
} |
|
|
|
} |
|
|
|
// Remove old trackers
|
|
|
|
// Remove old trackers
|
|
|
|
foreach (const QString &tracker, old_trackers_urls) { |
|
|
|
foreach (const QString &tracker, oldTrackerURLs) |
|
|
|
delete m_trackerItems.take(tracker); |
|
|
|
delete m_trackerItems.take(tracker); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Ask the user for new trackers and add them to the torrent
|
|
|
|
// Ask the user for new trackers and add them to the torrent
|
|
|
|
void TrackerList::askForTrackers() { |
|
|
|
void TrackerList::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; |
|
|
|
QList<BitTorrent::TrackerEntry> trackers; |
|
|
|
foreach (const QString &tracker, TrackersAdditionDlg::askForTrackers(this, torrent)) |
|
|
|
foreach (const QString &tracker, TrackersAdditionDlg::askForTrackers(this, torrent)) |
|
|
|
trackers << tracker; |
|
|
|
trackers << tracker; |
|
|
|
|
|
|
|
|
|
|
|
torrent->addTrackers(trackers); |
|
|
|
torrent->addTrackers(trackers); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerList::copyTrackerUrl() { |
|
|
|
void TrackerList::copyTrackerUrl() |
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems(); |
|
|
|
{ |
|
|
|
if (selected_items.isEmpty()) return; |
|
|
|
QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems(); |
|
|
|
QStringList urls_to_copy; |
|
|
|
if (selectedTrackerItems.isEmpty()) return; |
|
|
|
foreach (QTreeWidgetItem *item, selected_items) { |
|
|
|
|
|
|
|
QString tracker_url = item->data(COL_URL, Qt::DisplayRole).toString(); |
|
|
|
QStringList URLsToCopy; |
|
|
|
qDebug() << QString("Copy: ") + tracker_url; |
|
|
|
foreach (QTreeWidgetItem *item, selectedTrackerItems) { |
|
|
|
urls_to_copy << tracker_url; |
|
|
|
QString trackerURL = item->data(COL_URL, Qt::DisplayRole).toString(); |
|
|
|
|
|
|
|
qDebug() << QString("Copy: ") + trackerURL; |
|
|
|
|
|
|
|
URLsToCopy << trackerURL; |
|
|
|
} |
|
|
|
} |
|
|
|
QApplication::clipboard()->setText(urls_to_copy.join("\n")); |
|
|
|
QApplication::clipboard()->setText(URLsToCopy.join("\n")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void TrackerList::deleteSelectedTrackers() { |
|
|
|
void TrackerList::deleteSelectedTrackers() |
|
|
|
|
|
|
|
{ |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
if (!torrent) { |
|
|
|
if (!torrent) { |
|
|
|
clear(); |
|
|
|
clear(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems(); |
|
|
|
QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems(); |
|
|
|
if (selected_items.isEmpty()) return; |
|
|
|
if (selectedTrackerItems.isEmpty()) return; |
|
|
|
|
|
|
|
|
|
|
|
QStringList urls_to_remove; |
|
|
|
QStringList URLsToRemove; |
|
|
|
foreach (QTreeWidgetItem *item, selected_items) { |
|
|
|
foreach (QTreeWidgetItem *item, selectedTrackerItems) { |
|
|
|
QString tracker_url = item->data(COL_URL, Qt::DisplayRole).toString(); |
|
|
|
QString trackerURL = item->data(COL_URL, Qt::DisplayRole).toString(); |
|
|
|
urls_to_remove << tracker_url; |
|
|
|
URLsToRemove << trackerURL; |
|
|
|
m_trackerItems.remove(tracker_url); |
|
|
|
m_trackerItems.remove(trackerURL); |
|
|
|
delete item; |
|
|
|
delete item; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Iterate of trackers and remove selected ones
|
|
|
|
// Iterate over the trackers and remove the selected ones
|
|
|
|
QList<BitTorrent::TrackerEntry> remaining_trackers; |
|
|
|
QList<BitTorrent::TrackerEntry> remainingTrackers; |
|
|
|
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers(); |
|
|
|
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers(); |
|
|
|
foreach (const BitTorrent::TrackerEntry &entry, trackers) { |
|
|
|
foreach (const BitTorrent::TrackerEntry &entry, trackers) { |
|
|
|
if (!urls_to_remove.contains(entry.url())) { |
|
|
|
if (!URLsToRemove.contains(entry.url())) |
|
|
|
remaining_trackers.push_back(entry); |
|
|
|
remainingTrackers.push_back(entry); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
torrent->replaceTrackers(remaining_trackers); |
|
|
|
torrent->replaceTrackers(remainingTrackers); |
|
|
|
if (!torrent->isPaused()) |
|
|
|
if (!torrent->isPaused()) |
|
|
|
torrent->forceReannounce(); |
|
|
|
torrent->forceReannounce(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerList::editSelectedTracker() { |
|
|
|
void TrackerList::editSelectedTracker() |
|
|
|
|
|
|
|
{ |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
if (!torrent) return; |
|
|
|
if (!torrent) return; |
|
|
|
|
|
|
|
|
|
|
|
QString hash = torrent->hash(); |
|
|
|
QString hash = torrent->hash(); |
|
|
|
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems(); |
|
|
|
QList<QTreeWidgetItem *> selectedTrackerItems = getSelectedTrackerItems(); |
|
|
|
if (selected_items.isEmpty()) |
|
|
|
if (selectedTrackerItems.isEmpty()) return; |
|
|
|
return; |
|
|
|
|
|
|
|
// During multi-select only process item selected last
|
|
|
|
// During multi-select only process item selected last
|
|
|
|
QUrl tracker_url = selected_items.last()->text(COL_URL); |
|
|
|
QUrl trackerURL = selectedTrackerItems.last()->text(COL_URL); |
|
|
|
|
|
|
|
|
|
|
|
bool ok; |
|
|
|
bool ok; |
|
|
|
QUrl new_tracker_url = AutoExpandableDialog::getText(this, tr("Tracker editing"), tr("Tracker URL:"), |
|
|
|
QUrl newTrackerURL = AutoExpandableDialog::getText(this, tr("Tracker editing"), tr("Tracker URL:"), |
|
|
|
QLineEdit::Normal, tracker_url.toString(), &ok).trimmed(); |
|
|
|
QLineEdit::Normal, trackerURL.toString(), &ok).trimmed(); |
|
|
|
if (!ok) |
|
|
|
if (!ok) return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!new_tracker_url.isValid()) { |
|
|
|
if (!newTrackerURL.isValid()) { |
|
|
|
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL entered is invalid.")); |
|
|
|
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL entered is invalid.")); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (new_tracker_url == tracker_url) |
|
|
|
if (newTrackerURL == trackerURL) return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers(); |
|
|
|
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers(); |
|
|
|
bool match = false; |
|
|
|
bool match = false; |
|
|
|
for (int i = 0; i < trackers.size(); ++i) { |
|
|
|
for (int i = 0; i < trackers.size(); ++i) { |
|
|
|
BitTorrent::TrackerEntry &entry = trackers[i]; |
|
|
|
BitTorrent::TrackerEntry &entry = trackers[i]; |
|
|
|
if (new_tracker_url == 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 (tracker_url == QUrl(entry.url()) && !match) { |
|
|
|
if (trackerURL == QUrl(entry.url()) && !match) { |
|
|
|
BitTorrent::TrackerEntry new_entry(new_tracker_url.toString()); |
|
|
|
BitTorrent::TrackerEntry newEntry(newTrackerURL.toString()); |
|
|
|
new_entry.setTier(entry.tier()); |
|
|
|
newEntry.setTier(entry.tier()); |
|
|
|
match = true; |
|
|
|
match = true; |
|
|
|
entry = new_entry; |
|
|
|
entry = newEntry; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
torrent->replaceTrackers(trackers); |
|
|
|
torrent->replaceTrackers(trackers); |
|
|
|
if (!torrent->isPaused()) { |
|
|
|
if (!torrent->isPaused()) |
|
|
|
torrent->forceReannounce(); |
|
|
|
torrent->forceReannounce(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerList::reannounceSelected() { |
|
|
|
void TrackerList::reannounceSelected() |
|
|
|
QList<QTreeWidgetItem *> selected_items = selectedItems(); |
|
|
|
{ |
|
|
|
if (selected_items.isEmpty()) return; |
|
|
|
QList<QTreeWidgetItem *> selItems = selectedItems(); |
|
|
|
|
|
|
|
if (selItems.isEmpty()) return; |
|
|
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers(); |
|
|
|
|
|
|
|
|
|
|
|
foreach (QTreeWidgetItem* item, selected_items) { |
|
|
|
foreach (QTreeWidgetItem* item, selItems) { |
|
|
|
// DHT case
|
|
|
|
// DHT case
|
|
|
|
if (item == m_DHTItem) { |
|
|
|
if (item == m_DHTItem) { |
|
|
|
torrent->forceDHTAnnounce(); |
|
|
|
torrent->forceDHTAnnounce(); |
|
|
@ -504,9 +516,11 @@ void TrackerList::reannounceSelected() { |
|
|
|
loadTrackers(); |
|
|
|
loadTrackers(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void TrackerList::showTrackerListMenu(QPoint) { |
|
|
|
void TrackerList::showTrackerListMenu(QPoint) |
|
|
|
|
|
|
|
{ |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent(); |
|
|
|
if (!torrent) return; |
|
|
|
if (!torrent) return; |
|
|
|
|
|
|
|
|
|
|
|
//QList<QTreeWidgetItem*> selected_items = getSelectedTrackerItems();
|
|
|
|
//QList<QTreeWidgetItem*> selected_items = getSelectedTrackerItems();
|
|
|
|
QMenu menu; |
|
|
|
QMenu menu; |
|
|
|
// Add actions
|
|
|
|
// Add actions
|
|
|
@ -520,14 +534,15 @@ void TrackerList::showTrackerListMenu(QPoint) { |
|
|
|
editAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"),tr("Edit selected tracker URL")); |
|
|
|
editAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"),tr("Edit selected tracker URL")); |
|
|
|
} |
|
|
|
} |
|
|
|
QAction *reannounceSelAct = nullptr; |
|
|
|
QAction *reannounceSelAct = nullptr; |
|
|
|
QAction *reannounceAct = nullptr; |
|
|
|
QAction *reannounceAllAct = nullptr; |
|
|
|
if (!torrent->isPaused()) { |
|
|
|
if (!torrent->isPaused()) { |
|
|
|
reannounceSelAct = menu.addAction(GuiIconProvider::instance()->getIcon("view-refresh"), tr("Force reannounce to selected trackers")); |
|
|
|
reannounceSelAct = menu.addAction(GuiIconProvider::instance()->getIcon("view-refresh"), tr("Force reannounce to selected trackers")); |
|
|
|
menu.addSeparator(); |
|
|
|
menu.addSeparator(); |
|
|
|
reannounceAct = menu.addAction(GuiIconProvider::instance()->getIcon("view-refresh"), tr("Force reannounce to all trackers")); |
|
|
|
reannounceAllAct = menu.addAction(GuiIconProvider::instance()->getIcon("view-refresh"), tr("Force reannounce to all trackers")); |
|
|
|
} |
|
|
|
} |
|
|
|
QAction *act = menu.exec(QCursor::pos()); |
|
|
|
QAction *act = menu.exec(QCursor::pos()); |
|
|
|
if (act == nullptr) return; |
|
|
|
if (act == nullptr) return; |
|
|
|
|
|
|
|
|
|
|
|
if (act == addAct) { |
|
|
|
if (act == addAct) { |
|
|
|
askForTrackers(); |
|
|
|
askForTrackers(); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -544,7 +559,7 @@ void TrackerList::showTrackerListMenu(QPoint) { |
|
|
|
reannounceSelected(); |
|
|
|
reannounceSelected(); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (act == reannounceAct) { |
|
|
|
if (act == reannounceAllAct) { |
|
|
|
BitTorrent::TorrentHandle *h = m_properties->getCurrentTorrent(); |
|
|
|
BitTorrent::TorrentHandle *h = m_properties->getCurrentTorrent(); |
|
|
|
h->forceReannounce(); |
|
|
|
h->forceReannounce(); |
|
|
|
h->forceDHTAnnounce(); |
|
|
|
h->forceDHTAnnounce(); |
|
|
|