2010-10-09 18:06:35 +04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* 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
|
|
|
|
* exception statement from your version.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QHash>
|
|
|
|
#include <QAction>
|
|
|
|
#include <QColor>
|
2013-02-09 21:18:52 +04:00
|
|
|
#include <QDebug>
|
2010-10-09 18:06:35 +04:00
|
|
|
#include <libtorrent/version.hpp>
|
2010-11-28 13:29:59 +03:00
|
|
|
#include <libtorrent/peer_info.hpp>
|
2010-10-09 18:06:35 +04:00
|
|
|
#include "trackerlist.h"
|
|
|
|
#include "propertieswidget.h"
|
|
|
|
#include "trackersadditiondlg.h"
|
2013-01-11 22:58:38 +04:00
|
|
|
#include "trackereditdlg.h"
|
2011-01-01 16:05:28 +03:00
|
|
|
#include "iconprovider.h"
|
2010-10-09 18:06:35 +04:00
|
|
|
#include "qbtsession.h"
|
|
|
|
#include "qinisettings.h"
|
2011-01-01 16:05:28 +03:00
|
|
|
#include "misc.h"
|
2010-10-09 18:06:35 +04:00
|
|
|
|
2010-11-23 00:55:32 +03:00
|
|
|
using namespace libtorrent;
|
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
TrackerList::TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) {
|
|
|
|
// Graphical settings
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
setAllColumnsShowFocus(true);
|
|
|
|
setItemsExpandable(false);
|
|
|
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
// Context menu
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showTrackerListMenu(QPoint)));
|
|
|
|
// Set header
|
|
|
|
QStringList header;
|
2011-06-12 17:55:19 +04:00
|
|
|
header << "#";
|
2010-10-09 18:06:35 +04:00
|
|
|
header << tr("URL");
|
|
|
|
header << tr("Status");
|
|
|
|
header << tr("Peers");
|
|
|
|
header << tr("Message");
|
|
|
|
setHeaderItem(new QTreeWidgetItem(header));
|
2011-06-12 17:55:19 +04:00
|
|
|
dht_item = new QTreeWidgetItem(QStringList() << "" << "** "+tr("[DHT]")+" **");
|
2010-10-09 18:06:35 +04:00
|
|
|
insertTopLevelItem(0, dht_item);
|
|
|
|
setRowColor(0, QColor("grey"));
|
2011-06-12 17:55:19 +04:00
|
|
|
pex_item = new QTreeWidgetItem(QStringList() << "" << "** "+tr("[PeX]")+" **");
|
2010-10-09 18:06:35 +04:00
|
|
|
insertTopLevelItem(1, pex_item);
|
|
|
|
setRowColor(1, QColor("grey"));
|
2011-06-12 17:55:19 +04:00
|
|
|
lsd_item = new QTreeWidgetItem(QStringList() << "" << "** "+tr("[LSD]")+" **");
|
2010-10-09 18:06:35 +04:00
|
|
|
insertTopLevelItem(2, lsd_item);
|
|
|
|
setRowColor(2, QColor("grey"));
|
2011-06-12 17:55:19 +04:00
|
|
|
|
|
|
|
loadSettings();
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TrackerList::~TrackerList() {
|
|
|
|
saveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem*> TrackerList::getSelectedTrackerItems() const {
|
2012-06-27 20:27:49 +04:00
|
|
|
const QList<QTreeWidgetItem*> selected_items = selectedItems();
|
2010-10-09 18:06:35 +04:00
|
|
|
QList<QTreeWidgetItem*> selected_trackers;
|
2012-06-28 19:06:05 +04:00
|
|
|
foreach (QTreeWidgetItem *item, selected_items) {
|
2012-02-20 21:30:53 +04:00
|
|
|
if (indexOfTopLevelItem(item) >= NB_STICKY_ITEM) { // Ignore STICKY ITEMS
|
2010-10-09 18:06:35 +04:00
|
|
|
selected_trackers << item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return selected_trackers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::setRowColor(int row, QColor color) {
|
|
|
|
unsigned int nbColumns = columnCount();
|
|
|
|
QTreeWidgetItem *item = topLevelItem(row);
|
2012-02-20 21:30:53 +04:00
|
|
|
for (unsigned int i=0; i<nbColumns; ++i) {
|
2010-10-09 18:06:35 +04:00
|
|
|
item->setData(i, Qt::ForegroundRole, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::moveSelectionUp() {
|
|
|
|
QTorrentHandle h = properties->getCurrentTorrent();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!h.is_valid()) {
|
2010-10-09 18:06:35 +04:00
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (selected_items.isEmpty()) return;
|
2010-10-09 18:06:35 +04:00
|
|
|
bool change = false;
|
2012-02-20 21:56:07 +04:00
|
|
|
foreach (QTreeWidgetItem *item, selected_items) {
|
2010-10-09 18:06:35 +04:00
|
|
|
int index = indexOfTopLevelItem(item);
|
2012-02-20 21:30:53 +04:00
|
|
|
if (index > NB_STICKY_ITEM) {
|
2010-10-09 18:06:35 +04:00
|
|
|
insertTopLevelItem(index-1, takeTopLevelItem(index));
|
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!change) return;
|
2010-10-09 18:06:35 +04:00
|
|
|
// Restore selection
|
|
|
|
QItemSelectionModel *selection = selectionModel();
|
2012-02-20 21:30:53 +04:00
|
|
|
foreach (QTreeWidgetItem *item, selected_items) {
|
2010-10-09 18:06:35 +04:00
|
|
|
selection->select(indexFromItem(item), QItemSelectionModel::Rows|QItemSelectionModel::Select);
|
|
|
|
}
|
|
|
|
setSelectionModel(selection);
|
|
|
|
// Update torrent trackers
|
|
|
|
std::vector<announce_entry> trackers;
|
2012-02-20 21:30:53 +04:00
|
|
|
for (int i=NB_STICKY_ITEM; i<topLevelItemCount(); ++i) {
|
2010-10-09 18:06:35 +04:00
|
|
|
QString tracker_url = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
|
|
|
|
announce_entry e(tracker_url.toStdString());
|
|
|
|
e.tier = i-NB_STICKY_ITEM;
|
|
|
|
trackers.push_back(e);
|
|
|
|
}
|
|
|
|
h.replace_trackers(trackers);
|
|
|
|
// Reannounce
|
|
|
|
h.force_reannounce();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::moveSelectionDown() {
|
|
|
|
QTorrentHandle h = properties->getCurrentTorrent();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!h.is_valid()) {
|
2010-10-09 18:06:35 +04:00
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (selected_items.isEmpty()) return;
|
2010-10-09 18:06:35 +04:00
|
|
|
bool change = false;
|
2012-02-20 21:30:53 +04:00
|
|
|
for (int i=selectedItems().size()-1; i>= 0; --i) {
|
2010-10-09 18:06:35 +04:00
|
|
|
int index = indexOfTopLevelItem(selected_items.at(i));
|
2012-02-20 21:30:53 +04:00
|
|
|
if (index < topLevelItemCount()-1) {
|
2010-10-09 18:06:35 +04:00
|
|
|
insertTopLevelItem(index+1, takeTopLevelItem(index));
|
|
|
|
change = true;
|
|
|
|
}
|
|
|
|
}
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!change) return;
|
2010-10-09 18:06:35 +04:00
|
|
|
// Restore selection
|
|
|
|
QItemSelectionModel *selection = selectionModel();
|
2012-02-20 21:30:53 +04:00
|
|
|
foreach (QTreeWidgetItem *item, selected_items) {
|
2010-10-09 18:06:35 +04:00
|
|
|
selection->select(indexFromItem(item), QItemSelectionModel::Rows|QItemSelectionModel::Select);
|
|
|
|
}
|
|
|
|
setSelectionModel(selection);
|
|
|
|
// Update torrent trackers
|
|
|
|
std::vector<announce_entry> trackers;
|
2012-02-20 21:30:53 +04:00
|
|
|
for (int i=NB_STICKY_ITEM; i<topLevelItemCount(); ++i) {
|
2010-10-09 18:06:35 +04:00
|
|
|
QString tracker_url = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
|
|
|
|
announce_entry e(tracker_url.toStdString());
|
|
|
|
e.tier = i-NB_STICKY_ITEM;
|
|
|
|
trackers.push_back(e);
|
|
|
|
}
|
|
|
|
h.replace_trackers(trackers);
|
|
|
|
// Reannounce
|
|
|
|
h.force_reannounce();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::clear() {
|
|
|
|
qDeleteAll(tracker_items.values());
|
|
|
|
tracker_items.clear();
|
|
|
|
dht_item->setText(COL_PEERS, "");
|
|
|
|
dht_item->setText(COL_STATUS, "");
|
|
|
|
dht_item->setText(COL_MSG, "");
|
|
|
|
pex_item->setText(COL_PEERS, "");
|
|
|
|
pex_item->setText(COL_STATUS, "");
|
|
|
|
pex_item->setText(COL_MSG, "");
|
|
|
|
lsd_item->setText(COL_PEERS, "");
|
|
|
|
lsd_item->setText(COL_STATUS, "");
|
|
|
|
lsd_item->setText(COL_MSG, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::loadStickyItems(const QTorrentHandle &h) {
|
|
|
|
// load DHT information
|
2012-08-10 12:18:37 +04:00
|
|
|
if (QBtSession::instance()->isDHTEnabled() && (!h.has_metadata() || !h.priv())) {
|
2010-10-09 18:06:35 +04:00
|
|
|
dht_item->setText(COL_STATUS, tr("Working"));
|
|
|
|
} else {
|
|
|
|
dht_item->setText(COL_STATUS, tr("Disabled"));
|
|
|
|
}
|
2012-02-20 21:30:53 +04:00
|
|
|
if (h.has_metadata() && h.priv()) {
|
2010-10-09 18:06:35 +04:00
|
|
|
dht_item->setText(COL_MSG, tr("This torrent is private"));
|
|
|
|
}
|
2012-08-10 12:18:37 +04:00
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
// Load PeX Information
|
2012-02-20 21:30:53 +04:00
|
|
|
if (QBtSession::instance()->isPexEnabled())
|
2010-10-09 18:06:35 +04:00
|
|
|
pex_item->setText(COL_STATUS, tr("Working"));
|
|
|
|
else
|
|
|
|
pex_item->setText(COL_STATUS, tr("Disabled"));
|
2012-08-10 12:18:37 +04:00
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
// Load LSD Information
|
2012-02-20 21:30:53 +04:00
|
|
|
if (QBtSession::instance()->isLSDEnabled())
|
2010-10-09 18:06:35 +04:00
|
|
|
lsd_item->setText(COL_STATUS, tr("Working"));
|
|
|
|
else
|
|
|
|
lsd_item->setText(COL_STATUS, tr("Disabled"));
|
2012-08-10 12:18:37 +04:00
|
|
|
|
|
|
|
// XXX: libtorrent should provide this info...
|
|
|
|
// Count peers from DHT, LSD, PeX
|
|
|
|
uint nb_dht = 0, nb_lsd = 0, nb_pex = 0;
|
|
|
|
std::vector<peer_info> peers;
|
|
|
|
h.get_peer_info(peers);
|
|
|
|
std::vector<peer_info>::iterator it = peers.begin();
|
|
|
|
std::vector<peer_info>::iterator end = peers.end();
|
|
|
|
for ( ; it != end; ++it) {
|
|
|
|
if (it->source & peer_info::dht)
|
|
|
|
++nb_dht;
|
|
|
|
if (it->source & peer_info::lsd)
|
|
|
|
++nb_lsd;
|
|
|
|
if (it->source & peer_info::pex)
|
|
|
|
++nb_pex;
|
|
|
|
}
|
|
|
|
dht_item->setText(COL_PEERS, QString::number(nb_dht));
|
|
|
|
pex_item->setText(COL_PEERS, QString::number(nb_pex));
|
2010-10-09 18:06:35 +04:00
|
|
|
lsd_item->setText(COL_PEERS, QString::number(nb_lsd));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::loadTrackers() {
|
|
|
|
// Load trackers from torrent handle
|
|
|
|
QTorrentHandle h = properties->getCurrentTorrent();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!h.is_valid()) return;
|
2010-10-09 18:06:35 +04:00
|
|
|
loadStickyItems(h);
|
|
|
|
// Load actual trackers information
|
2010-11-14 00:15:52 +03:00
|
|
|
QHash<QString, TrackerInfos> trackers_data = QBtSession::instance()->getTrackersInfo(h.hash());
|
2010-10-09 18:06:35 +04:00
|
|
|
QStringList old_trackers_urls = tracker_items.keys();
|
|
|
|
const std::vector<announce_entry> trackers = h.trackers();
|
2012-06-27 20:27:49 +04:00
|
|
|
std::vector<announce_entry>::const_iterator it = trackers.begin();
|
|
|
|
std::vector<announce_entry>::const_iterator end = trackers.end();
|
|
|
|
for ( ; it != end; ++it) {
|
2010-10-09 18:06:35 +04:00
|
|
|
QString tracker_url = misc::toQString(it->url);
|
|
|
|
QTreeWidgetItem *item = tracker_items.value(tracker_url, 0);
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!item) {
|
2010-10-09 18:06:35 +04:00
|
|
|
item = new QTreeWidgetItem();
|
2011-06-12 17:55:19 +04:00
|
|
|
item->setText(COL_TIER, QString::number(it->tier));
|
2010-10-09 18:06:35 +04:00
|
|
|
item->setText(COL_URL, tracker_url);
|
|
|
|
addTopLevelItem(item);
|
|
|
|
tracker_items[tracker_url] = item;
|
|
|
|
} else {
|
|
|
|
old_trackers_urls.removeOne(tracker_url);
|
|
|
|
}
|
|
|
|
TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url));
|
|
|
|
QString error_message = data.last_message.trimmed();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (it->verified) {
|
2010-10-09 18:06:35 +04:00
|
|
|
item->setText(COL_STATUS, tr("Working"));
|
|
|
|
item->setText(COL_MSG, "");
|
|
|
|
} else {
|
2012-02-20 21:30:53 +04:00
|
|
|
if (it->updating && it->fails == 0) {
|
2010-10-09 18:06:35 +04:00
|
|
|
item->setText(COL_STATUS, tr("Updating..."));
|
|
|
|
item->setText(COL_MSG, "");
|
|
|
|
} else {
|
2012-02-20 21:30:53 +04:00
|
|
|
if (it->fails > 0) {
|
2010-10-09 18:06:35 +04:00
|
|
|
item->setText(COL_STATUS, tr("Not working"));
|
|
|
|
item->setText(COL_MSG, error_message);
|
|
|
|
} else {
|
|
|
|
item->setText(COL_STATUS, tr("Not contacted yet"));
|
|
|
|
item->setText(COL_MSG, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
item->setText(COL_PEERS, QString::number(trackers_data.value(tracker_url, TrackerInfos(tracker_url)).num_peers));
|
|
|
|
}
|
|
|
|
// Remove old trackers
|
2012-02-20 21:30:53 +04:00
|
|
|
foreach (const QString &tracker, old_trackers_urls) {
|
2010-10-09 18:06:35 +04:00
|
|
|
delete tracker_items.take(tracker);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ask the user for new trackers and add them to the torrent
|
2012-02-20 21:56:07 +04:00
|
|
|
void TrackerList::askForTrackers() {
|
2010-10-09 18:06:35 +04:00
|
|
|
QTorrentHandle h = properties->getCurrentTorrent();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!h.is_valid()) return;
|
2010-10-09 18:06:35 +04:00
|
|
|
QStringList trackers = TrackersAdditionDlg::askForTrackers(h);
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!trackers.empty()) {
|
|
|
|
foreach (const QString& tracker, trackers) {
|
|
|
|
if (tracker.trimmed().isEmpty()) continue;
|
2010-10-09 18:06:35 +04:00
|
|
|
announce_entry url(tracker.toStdString());
|
|
|
|
url.tier = 0;
|
|
|
|
h.add_tracker(url);
|
|
|
|
}
|
|
|
|
// Reannounce to new trackers
|
|
|
|
h.force_reannounce();
|
|
|
|
// Reload tracker list
|
|
|
|
loadTrackers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-06 23:03:19 +04:00
|
|
|
void TrackerList::copyTrackerUrl() {
|
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
|
|
|
if (selected_items.isEmpty()) return;
|
2012-11-15 22:04:26 +04:00
|
|
|
QStringList urls_to_copy;
|
2012-11-06 23:03:19 +04:00
|
|
|
foreach (QTreeWidgetItem *item, selected_items) {
|
|
|
|
QString tracker_url = item->data(COL_URL, Qt::DisplayRole).toString();
|
2012-11-15 22:04:26 +04:00
|
|
|
qDebug() << QString("Copy: ") + tracker_url;
|
|
|
|
urls_to_copy << tracker_url;
|
2012-11-06 23:03:19 +04:00
|
|
|
}
|
2012-11-15 22:04:26 +04:00
|
|
|
QApplication::clipboard()->setText(urls_to_copy.join("\n"));
|
2012-11-06 23:03:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-20 21:56:07 +04:00
|
|
|
void TrackerList::deleteSelectedTrackers() {
|
2010-10-09 18:06:35 +04:00
|
|
|
QTorrentHandle h = properties->getCurrentTorrent();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!h.is_valid()) {
|
2010-10-09 18:06:35 +04:00
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (selected_items.isEmpty()) return;
|
2010-10-09 18:06:35 +04:00
|
|
|
QStringList urls_to_remove;
|
2012-02-20 21:56:07 +04:00
|
|
|
foreach (QTreeWidgetItem *item, selected_items) {
|
2010-10-09 18:06:35 +04:00
|
|
|
QString tracker_url = item->data(COL_URL, Qt::DisplayRole).toString();
|
|
|
|
urls_to_remove << tracker_url;
|
|
|
|
tracker_items.remove(tracker_url);
|
|
|
|
delete item;
|
|
|
|
}
|
|
|
|
// Iterate of trackers and remove selected ones
|
2010-12-16 23:34:37 +03:00
|
|
|
std::vector<announce_entry> remaining_trackers;
|
2010-10-09 18:06:35 +04:00
|
|
|
std::vector<announce_entry> trackers = h.trackers();
|
2012-07-14 02:28:23 +04:00
|
|
|
|
|
|
|
std::vector<announce_entry>::iterator it = trackers.begin();
|
|
|
|
std::vector<announce_entry>::iterator itend = trackers.end();
|
|
|
|
for ( ; it != itend; ++it) {
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!urls_to_remove.contains(misc::toQString((*it).url))) {
|
2010-12-16 23:34:37 +03:00
|
|
|
remaining_trackers.push_back(*it);
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
}
|
2010-12-16 23:34:37 +03:00
|
|
|
h.replace_trackers(remaining_trackers);
|
2010-10-09 18:06:35 +04:00
|
|
|
h.force_reannounce();
|
|
|
|
// Reload Trackers
|
|
|
|
loadTrackers();
|
|
|
|
}
|
|
|
|
|
2013-01-11 22:58:38 +04:00
|
|
|
void TrackerList::editSelectedTracker() {
|
|
|
|
QTorrentHandle h = properties->getCurrentTorrent();
|
|
|
|
if (!h.is_valid()) return;
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
|
|
|
if (selected_items.isEmpty()) return;
|
|
|
|
// During multi-select only process item selected last
|
|
|
|
QString tracker_URI = selected_items.last()->data(COL_URL, Qt::DisplayRole).toString();
|
|
|
|
if (!TrackerEditDlg::editSelectedTracker(h,tracker_URI))
|
|
|
|
return;
|
|
|
|
|
|
|
|
h.force_reannounce();
|
|
|
|
loadTrackers();
|
|
|
|
}
|
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
void TrackerList::showTrackerListMenu(QPoint) {
|
|
|
|
QTorrentHandle h = properties->getCurrentTorrent();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!h.is_valid()) return;
|
2010-10-09 18:06:35 +04:00
|
|
|
//QList<QTreeWidgetItem*> selected_items = getSelectedTrackerItems();
|
|
|
|
QMenu menu;
|
|
|
|
// Add actions
|
2011-01-01 16:05:28 +03:00
|
|
|
QAction *addAct = menu.addAction(IconProvider::instance()->getIcon("list-add"), tr("Add a new tracker..."));
|
2012-11-15 22:16:06 +04:00
|
|
|
QAction *copyAct = menu.addAction(IconProvider::instance()->getIcon("edit-copy"), tr("Copy tracker url"));
|
2010-10-09 18:06:35 +04:00
|
|
|
QAction *delAct = 0;
|
2013-01-11 22:58:38 +04:00
|
|
|
QAction *editAct = 0;
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!getSelectedTrackerItems().isEmpty()) {
|
2011-01-01 16:05:28 +03:00
|
|
|
delAct = menu.addAction(IconProvider::instance()->getIcon("list-remove"), tr("Remove tracker"));
|
2013-01-11 22:58:38 +04:00
|
|
|
editAct = menu.addAction(IconProvider::instance()->getIcon("edit-rename"),tr("Edit selected tracker URI"));
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
QAction *act = menu.exec(QCursor::pos());
|
2012-02-20 21:30:53 +04:00
|
|
|
if (act == 0) return;
|
|
|
|
if (act == addAct) {
|
2010-10-09 18:06:35 +04:00
|
|
|
askForTrackers();
|
|
|
|
return;
|
|
|
|
}
|
2012-11-06 23:03:19 +04:00
|
|
|
if (act == copyAct) {
|
|
|
|
copyTrackerUrl();
|
|
|
|
return;
|
|
|
|
}
|
2012-02-20 21:30:53 +04:00
|
|
|
if (act == delAct) {
|
2010-10-09 18:06:35 +04:00
|
|
|
deleteSelectedTrackers();
|
|
|
|
return;
|
|
|
|
}
|
2013-01-11 22:58:38 +04:00
|
|
|
if (act == editAct) {
|
|
|
|
editSelectedTracker();
|
|
|
|
return;
|
|
|
|
}
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::loadSettings() {
|
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!header()->restoreState(settings.value("TorrentProperties/Trackers/TrackerListState").toByteArray())) {
|
2011-06-12 17:55:19 +04:00
|
|
|
setColumnWidth(0, 30);
|
|
|
|
setColumnWidth(1, 300);
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::saveSettings() const {
|
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
2011-03-13 13:09:31 +03:00
|
|
|
settings.setValue("TorrentProperties/Trackers/TrackerListState", header()->saveState());
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|