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
|
|
|
|
*/
|
|
|
|
|
2017-04-11 15:35:10 +03:00
|
|
|
#include "trackerlist.h"
|
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
#include <QAction>
|
2017-03-09 19:25:41 +03:00
|
|
|
#include <QApplication>
|
2010-10-09 18:06:35 +04:00
|
|
|
#include <QColor>
|
2013-02-09 21:18:52 +04:00
|
|
|
#include <QDebug>
|
2017-03-09 19:25:41 +03:00
|
|
|
#include <QHash>
|
|
|
|
#include <QHeaderView>
|
|
|
|
#include <QMenu>
|
2015-06-02 12:09:15 +03:00
|
|
|
#include <QMessageBox>
|
2017-03-09 19:25:41 +03:00
|
|
|
#include <QStringList>
|
2015-11-18 19:13:25 +03:00
|
|
|
#include <QTableView>
|
2017-03-09 19:25:41 +03:00
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
#include <QUrl>
|
2015-06-02 12:09:15 +03:00
|
|
|
|
2017-03-09 19:25:41 +03:00
|
|
|
#include "base/bittorrent/peerinfo.h"
|
2015-09-25 11:10:05 +03:00
|
|
|
#include "base/bittorrent/session.h"
|
|
|
|
#include "base/bittorrent/torrenthandle.h"
|
|
|
|
#include "base/bittorrent/trackerentry.h"
|
|
|
|
#include "base/preferences.h"
|
|
|
|
#include "base/utils/misc.h"
|
2017-03-09 19:25:41 +03:00
|
|
|
#include "autoexpandabledialog.h"
|
|
|
|
#include "guiiconprovider.h"
|
2015-06-02 12:09:15 +03:00
|
|
|
#include "propertieswidget.h"
|
|
|
|
#include "trackersadditiondlg.h"
|
2010-10-09 18:06:35 +04:00
|
|
|
|
2017-03-09 19:25:41 +03:00
|
|
|
TrackerList::TrackerList(PropertiesWidget *properties)
|
|
|
|
: QTreeWidget()
|
2017-05-11 18:58:50 +03:00
|
|
|
, m_properties(properties)
|
2017-03-09 19:25:41 +03:00
|
|
|
{
|
2017-03-10 12:43:59 +03:00
|
|
|
// Set header
|
|
|
|
// Must be set before calling loadSettings() otherwise the header is reset on restart
|
|
|
|
setHeaderLabels(headerLabels());
|
|
|
|
// Load settings
|
|
|
|
loadSettings();
|
2010-10-09 18:06:35 +04:00
|
|
|
// Graphical settings
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
setAllColumnsShowFocus(true);
|
|
|
|
setItemsExpandable(false);
|
|
|
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
2017-03-10 12:43:59 +03:00
|
|
|
header()->setStretchLastSection(false); // Must be set after loadSettings() in order to work
|
|
|
|
// Ensure that at least one column is visible at all times
|
|
|
|
if (visibleColumnsCount() == 0)
|
|
|
|
setColumnHidden(COL_URL, false);
|
|
|
|
// To also mitigate the above issue, we have to resize each column when
|
|
|
|
// its size is 0, because explicitly 'showing' the column isn't enough
|
|
|
|
// in the above scenario.
|
|
|
|
for (unsigned int i = 0; i < COL_COUNT; ++i)
|
|
|
|
if ((columnWidth(i) <= 0) && !isColumnHidden(i))
|
|
|
|
resizeColumnToContents(i);
|
2010-10-09 18:06:35 +04:00
|
|
|
// Context menu
|
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showTrackerListMenu(QPoint)));
|
2017-03-10 12:43:59 +03:00
|
|
|
// Header context menu
|
|
|
|
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayToggleColumnsMenu(const QPoint&)));
|
|
|
|
// Set DHT, PeX, LSD items
|
2017-05-11 18:58:50 +03:00
|
|
|
m_DHTItem = new QTreeWidgetItem({ "", "** [DHT] **", "", "0", "", "", "0" });
|
|
|
|
insertTopLevelItem(0, m_DHTItem);
|
2010-10-09 18:06:35 +04:00
|
|
|
setRowColor(0, QColor("grey"));
|
2017-05-11 18:58:50 +03:00
|
|
|
m_PEXItem = new QTreeWidgetItem({ "", "** [PeX] **", "", "0", "", "", "0" });
|
|
|
|
insertTopLevelItem(1, m_PEXItem);
|
2010-10-09 18:06:35 +04:00
|
|
|
setRowColor(1, QColor("grey"));
|
2017-05-11 18:58:50 +03:00
|
|
|
m_LSDItem = new QTreeWidgetItem({ "", "** [LSD] **", "", "0", "", "", "0" });
|
|
|
|
insertTopLevelItem(2, m_LSDItem);
|
2010-10-09 18:06:35 +04:00
|
|
|
setRowColor(2, QColor("grey"));
|
2017-03-10 21:23:11 +03:00
|
|
|
// Set static items alignment
|
2017-05-11 18:58:50 +03:00
|
|
|
m_DHTItem->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_PEXItem->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_LSDItem->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_DHTItem->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_PEXItem->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_LSDItem->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_DHTItem->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_PEXItem->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_LSDItem->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_DHTItem->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_PEXItem->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
m_LSDItem->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
|
2017-03-10 21:23:11 +03:00
|
|
|
// Set header alignment
|
|
|
|
headerItem()->setTextAlignment(COL_TIER, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
headerItem()->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
headerItem()->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
headerItem()->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
headerItem()->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
// Set hotkeys
|
2017-05-11 18:58:50 +03:00
|
|
|
m_editHotkey = new QShortcut(Qt::Key_F2, this, SLOT(editSelectedTracker()), 0, Qt::WidgetShortcut);
|
2013-07-22 18:39:48 +04:00
|
|
|
connect(this, SIGNAL(doubleClicked(QModelIndex)), SLOT(editSelectedTracker()));
|
2017-05-11 18:58:50 +03:00
|
|
|
m_deleteHotkey = new QShortcut(QKeySequence::Delete, this, SLOT(deleteSelectedTrackers()), 0, Qt::WidgetShortcut);
|
|
|
|
m_copyHotkey = new QShortcut(QKeySequence::Copy, this, SLOT(copyTrackerUrl()), 0, Qt::WidgetShortcut);
|
2011-06-12 17:55:19 +04:00
|
|
|
|
2015-11-18 19:13:25 +03:00
|
|
|
// This hack fixes reordering of first column with Qt5.
|
|
|
|
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
|
|
|
|
QTableView unused;
|
2017-03-10 12:43:59 +03:00
|
|
|
unused.setVerticalHeader(header());
|
|
|
|
header()->setParent(this);
|
2015-11-18 19:13:25 +03:00
|
|
|
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
2017-03-09 19:25:41 +03:00
|
|
|
TrackerList::~TrackerList()
|
|
|
|
{
|
|
|
|
saveSettings();
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2017-05-11 18:58:50 +03:00
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent) {
|
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
|
2015-04-19 18:17:47 +03:00
|
|
|
QList<BitTorrent::TrackerEntry> trackers;
|
|
|
|
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();
|
2015-04-19 18:17:47 +03:00
|
|
|
BitTorrent::TrackerEntry e(tracker_url);
|
|
|
|
e.setTier(i - NB_STICKY_ITEM);
|
|
|
|
trackers.append(e);
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
2015-04-19 18:17:47 +03:00
|
|
|
|
|
|
|
torrent->replaceTrackers(trackers);
|
2010-10-09 18:06:35 +04:00
|
|
|
// Reannounce
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent->isPaused())
|
|
|
|
torrent->forceReannounce();
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::moveSelectionDown() {
|
2017-05-11 18:58:50 +03:00
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent) {
|
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
|
2015-04-19 18:17:47 +03:00
|
|
|
QList<BitTorrent::TrackerEntry> trackers;
|
|
|
|
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();
|
2015-04-19 18:17:47 +03:00
|
|
|
BitTorrent::TrackerEntry e(tracker_url);
|
|
|
|
e.setTier(i - NB_STICKY_ITEM);
|
|
|
|
trackers.append(e);
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
2015-04-19 18:17:47 +03:00
|
|
|
|
|
|
|
torrent->replaceTrackers(trackers);
|
2010-10-09 18:06:35 +04:00
|
|
|
// Reannounce
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent->isPaused())
|
|
|
|
torrent->forceReannounce();
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
2017-02-05 19:21:25 +03:00
|
|
|
void TrackerList::clear()
|
|
|
|
{
|
2017-05-11 18:58:50 +03:00
|
|
|
qDeleteAll(m_trackerItems.values());
|
|
|
|
m_trackerItems.clear();
|
|
|
|
m_DHTItem->setText(COL_STATUS, "");
|
|
|
|
m_DHTItem->setText(COL_SEEDS, "");
|
|
|
|
m_DHTItem->setText(COL_PEERS, "");
|
|
|
|
m_DHTItem->setText(COL_MSG, "");
|
|
|
|
m_PEXItem->setText(COL_STATUS, "");
|
|
|
|
m_PEXItem->setText(COL_SEEDS, "");
|
|
|
|
m_PEXItem->setText(COL_PEERS, "");
|
|
|
|
m_PEXItem->setText(COL_MSG, "");
|
|
|
|
m_LSDItem->setText(COL_STATUS, "");
|
|
|
|
m_LSDItem->setText(COL_SEEDS, "");
|
|
|
|
m_LSDItem->setText(COL_PEERS, "");
|
|
|
|
m_LSDItem->setText(COL_MSG, "");
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
void TrackerList::loadStickyItems(BitTorrent::TorrentHandle *const torrent) {
|
2014-06-04 01:35:23 +04:00
|
|
|
QString working = tr("Working");
|
|
|
|
QString disabled = tr("Disabled");
|
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
// load DHT information
|
2015-04-19 18:17:47 +03:00
|
|
|
if (BitTorrent::Session::instance()->isDHTEnabled() && !torrent->isPrivate())
|
2017-05-11 18:58:50 +03:00
|
|
|
m_DHTItem->setText(COL_STATUS, working);
|
2014-06-04 01:35:23 +04:00
|
|
|
else
|
2017-05-11 18:58:50 +03:00
|
|
|
m_DHTItem->setText(COL_STATUS, disabled);
|
2012-08-10 12:18:37 +04:00
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
// Load PeX Information
|
2016-05-01 11:05:52 +03:00
|
|
|
if (BitTorrent::Session::instance()->isPeXEnabled() && !torrent->isPrivate())
|
2017-05-11 18:58:50 +03:00
|
|
|
m_PEXItem->setText(COL_STATUS, working);
|
2010-10-09 18:06:35 +04:00
|
|
|
else
|
2017-05-11 18:58:50 +03:00
|
|
|
m_PEXItem->setText(COL_STATUS, disabled);
|
2012-08-10 12:18:37 +04:00
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
// Load LSD Information
|
2015-04-19 18:17:47 +03:00
|
|
|
if (BitTorrent::Session::instance()->isLSDEnabled() && !torrent->isPrivate())
|
2017-05-11 18:58:50 +03:00
|
|
|
m_LSDItem->setText(COL_STATUS, working);
|
2010-10-09 18:06:35 +04:00
|
|
|
else
|
2017-05-11 18:58:50 +03:00
|
|
|
m_LSDItem->setText(COL_STATUS, disabled);
|
2014-06-04 01:35:23 +04:00
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
if (torrent->isPrivate()) {
|
2014-06-04 01:35:23 +04:00
|
|
|
QString privateMsg = tr("This torrent is private");
|
2017-05-11 18:58:50 +03:00
|
|
|
m_DHTItem->setText(COL_MSG, privateMsg);
|
|
|
|
m_PEXItem->setText(COL_MSG, privateMsg);
|
|
|
|
m_LSDItem->setText(COL_MSG, privateMsg);
|
2014-06-04 01:35:23 +04:00
|
|
|
}
|
2012-08-10 12:18:37 +04:00
|
|
|
|
2017-02-05 19:21:25 +03:00
|
|
|
// XXX: libtorrent should provide this info...
|
|
|
|
// Count peers from DHT, PeX, LSD
|
|
|
|
uint seedsDHT = 0, seedsPeX = 0, seedsLSD = 0, peersDHT = 0, peersPeX = 0, peersLSD = 0;
|
|
|
|
foreach (const BitTorrent::PeerInfo &peer, torrent->peers()) {
|
|
|
|
if (peer.isConnecting()) continue;
|
|
|
|
|
|
|
|
if (peer.fromDHT()) {
|
|
|
|
if (peer.isSeed())
|
|
|
|
++seedsDHT;
|
|
|
|
else
|
|
|
|
++peersDHT;
|
|
|
|
}
|
|
|
|
if (peer.fromPeX()) {
|
|
|
|
if (peer.isSeed())
|
|
|
|
++seedsPeX;
|
|
|
|
else
|
|
|
|
++peersPeX;
|
|
|
|
}
|
|
|
|
if (peer.fromLSD()) {
|
|
|
|
if (peer.isSeed())
|
|
|
|
++seedsLSD;
|
|
|
|
else
|
|
|
|
++peersLSD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-11 18:58:50 +03:00
|
|
|
m_DHTItem->setText(COL_SEEDS, QString::number(seedsDHT));
|
|
|
|
m_DHTItem->setText(COL_PEERS, QString::number(peersDHT));
|
|
|
|
m_PEXItem->setText(COL_SEEDS, QString::number(seedsPeX));
|
|
|
|
m_PEXItem->setText(COL_PEERS, QString::number(peersPeX));
|
|
|
|
m_LSDItem->setText(COL_SEEDS, QString::number(seedsLSD));
|
|
|
|
m_LSDItem->setText(COL_PEERS, QString::number(peersLSD));
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::loadTrackers() {
|
|
|
|
// Load trackers from torrent handle
|
2017-05-11 18:58:50 +03:00
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent) return;
|
|
|
|
|
|
|
|
loadStickyItems(torrent);
|
2010-10-09 18:06:35 +04:00
|
|
|
// Load actual trackers information
|
2015-04-19 18:17:47 +03:00
|
|
|
QHash<QString, BitTorrent::TrackerInfo> trackers_data = torrent->trackerInfos();
|
2017-05-11 18:58:50 +03:00
|
|
|
QStringList old_trackers_urls = m_trackerItems.keys();
|
2015-04-19 18:17:47 +03:00
|
|
|
foreach (const BitTorrent::TrackerEntry &entry, torrent->trackers()) {
|
|
|
|
QString trackerUrl = entry.url();
|
2017-05-11 18:58:50 +03:00
|
|
|
QTreeWidgetItem *item = m_trackerItems.value(trackerUrl, 0);
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!item) {
|
2010-10-09 18:06:35 +04:00
|
|
|
item = new QTreeWidgetItem();
|
2015-04-19 18:17:47 +03:00
|
|
|
item->setText(COL_URL, trackerUrl);
|
2010-10-09 18:06:35 +04:00
|
|
|
addTopLevelItem(item);
|
2017-05-11 18:58:50 +03:00
|
|
|
m_trackerItems[trackerUrl] = item;
|
2010-10-09 18:06:35 +04:00
|
|
|
} else {
|
2015-04-19 18:17:47 +03:00
|
|
|
old_trackers_urls.removeOne(trackerUrl);
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
2015-04-19 18:17:47 +03:00
|
|
|
item->setText(COL_TIER, QString::number(entry.tier()));
|
|
|
|
BitTorrent::TrackerInfo data = trackers_data.value(trackerUrl);
|
|
|
|
QString error_message = data.lastMessage.trimmed();
|
|
|
|
switch (entry.status()) {
|
|
|
|
case BitTorrent::TrackerEntry::Working:
|
|
|
|
item->setText(COL_STATUS, tr("Working"));
|
|
|
|
item->setText(COL_MSG, "");
|
|
|
|
break;
|
|
|
|
case BitTorrent::TrackerEntry::Updating:
|
2010-10-09 18:06:35 +04:00
|
|
|
item->setText(COL_STATUS, tr("Updating..."));
|
|
|
|
item->setText(COL_MSG, "");
|
2015-04-19 18:17:47 +03:00
|
|
|
break;
|
|
|
|
case BitTorrent::TrackerEntry::NotWorking:
|
|
|
|
item->setText(COL_STATUS, tr("Not working"));
|
|
|
|
item->setText(COL_MSG, error_message);
|
|
|
|
break;
|
|
|
|
case BitTorrent::TrackerEntry::NotContacted:
|
|
|
|
item->setText(COL_STATUS, tr("Not contacted yet"));
|
|
|
|
item->setText(COL_MSG, "");
|
|
|
|
break;
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
2015-06-09 01:50:35 +03:00
|
|
|
item->setText(COL_RECEIVED, QString::number(data.numPeers));
|
|
|
|
|
|
|
|
#if LIBTORRENT_VERSION_NUM >= 10000
|
|
|
|
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_DOWNLOADED, QString::number(entry.nativeEntry().scrape_downloaded > 0 ? entry.nativeEntry().scrape_downloaded : 0));
|
|
|
|
#else
|
|
|
|
item->setText(COL_SEEDS, "0");
|
|
|
|
item->setText(COL_PEERS, "0");
|
|
|
|
item->setText(COL_DOWNLOADED, "0");
|
|
|
|
#endif
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2017-03-10 21:23:11 +03:00
|
|
|
item->setTextAlignment(COL_TIER, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
item->setTextAlignment(COL_RECEIVED, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
item->setTextAlignment(COL_SEEDS, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
item->setTextAlignment(COL_PEERS, (Qt::AlignRight | Qt::AlignVCenter));
|
|
|
|
item->setTextAlignment(COL_DOWNLOADED, (Qt::AlignRight | Qt::AlignVCenter));
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
// Remove old trackers
|
2012-02-20 21:30:53 +04:00
|
|
|
foreach (const QString &tracker, old_trackers_urls) {
|
2017-05-11 18:58:50 +03:00
|
|
|
delete m_trackerItems.take(tracker);
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ask the user for new trackers and add them to the torrent
|
2012-02-20 21:56:07 +04:00
|
|
|
void TrackerList::askForTrackers() {
|
2017-05-11 18:58:50 +03:00
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent) return;
|
|
|
|
|
|
|
|
QList<BitTorrent::TrackerEntry> trackers;
|
2016-02-09 10:27:08 +03:00
|
|
|
foreach (const QString &tracker, TrackersAdditionDlg::askForTrackers(this, torrent))
|
2015-04-19 18:17:47 +03:00
|
|
|
trackers << tracker;
|
|
|
|
torrent->addTrackers(trackers);
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
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() {
|
2017-05-11 18:58:50 +03:00
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent) {
|
2010-10-09 18:06:35 +04:00
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
2012-02-20 21:30:53 +04:00
|
|
|
if (selected_items.isEmpty()) return;
|
2015-04-19 18:17:47 +03:00
|
|
|
|
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;
|
2017-05-11 18:58:50 +03:00
|
|
|
m_trackerItems.remove(tracker_url);
|
2010-10-09 18:06:35 +04:00
|
|
|
delete item;
|
|
|
|
}
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
// Iterate of trackers and remove selected ones
|
2015-04-19 18:17:47 +03:00
|
|
|
QList<BitTorrent::TrackerEntry> remaining_trackers;
|
|
|
|
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
|
|
|
foreach (const BitTorrent::TrackerEntry &entry, trackers) {
|
|
|
|
if (!urls_to_remove.contains(entry.url())) {
|
|
|
|
remaining_trackers.push_back(entry);
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
}
|
2015-04-19 18:17:47 +03:00
|
|
|
|
|
|
|
torrent->replaceTrackers(remaining_trackers);
|
|
|
|
if (!torrent->isPaused())
|
|
|
|
torrent->forceReannounce();
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
2013-01-11 22:58:38 +04:00
|
|
|
void TrackerList::editSelectedTracker() {
|
2017-05-11 18:58:50 +03:00
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent) return;
|
|
|
|
|
|
|
|
QString hash = torrent->hash();
|
2013-01-11 22:58:38 +04:00
|
|
|
|
2013-02-10 22:04:48 +04:00
|
|
|
QList<QTreeWidgetItem *> selected_items = getSelectedTrackerItems();
|
|
|
|
if (selected_items.isEmpty())
|
|
|
|
return;
|
|
|
|
// During multi-select only process item selected last
|
|
|
|
QUrl tracker_url = selected_items.last()->text(COL_URL);
|
|
|
|
|
2013-07-22 15:46:10 +04:00
|
|
|
bool ok;
|
|
|
|
QUrl new_tracker_url = AutoExpandableDialog::getText(this, tr("Tracker editing"), tr("Tracker URL:"),
|
|
|
|
QLineEdit::Normal, tracker_url.toString(), &ok).trimmed();
|
|
|
|
if (!ok)
|
2013-02-10 22:04:48 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!new_tracker_url.isValid()) {
|
|
|
|
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL entered is invalid."));
|
|
|
|
return;
|
|
|
|
}
|
2013-02-10 22:39:15 +04:00
|
|
|
if (new_tracker_url == tracker_url)
|
2013-02-10 22:04:48 +04:00
|
|
|
return;
|
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
2013-02-10 22:04:48 +04:00
|
|
|
bool match = false;
|
2015-04-19 18:17:47 +03:00
|
|
|
for (int i = 0; i < trackers.size(); ++i) {
|
|
|
|
BitTorrent::TrackerEntry &entry = trackers[i];
|
|
|
|
if (new_tracker_url == QUrl(entry.url())) {
|
2013-02-10 22:04:48 +04:00
|
|
|
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists."));
|
|
|
|
return;
|
|
|
|
}
|
2013-02-10 20:15:36 +04:00
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
if (tracker_url == QUrl(entry.url()) && !match) {
|
|
|
|
BitTorrent::TrackerEntry new_entry(new_tracker_url.toString());
|
|
|
|
new_entry.setTier(entry.tier());
|
2013-02-10 22:04:48 +04:00
|
|
|
match = true;
|
2015-04-19 18:17:47 +03:00
|
|
|
entry = new_entry;
|
2013-02-10 22:04:48 +04:00
|
|
|
}
|
|
|
|
}
|
2013-02-10 20:15:36 +04:00
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
torrent->replaceTrackers(trackers);
|
|
|
|
if (!torrent->isPaused()) {
|
|
|
|
torrent->forceReannounce();
|
2014-01-26 18:29:53 +04:00
|
|
|
}
|
2013-01-11 22:58:38 +04:00
|
|
|
}
|
|
|
|
|
2014-01-07 23:48:38 +04:00
|
|
|
void TrackerList::reannounceSelected() {
|
2015-07-14 10:59:15 +03:00
|
|
|
QList<QTreeWidgetItem *> selected_items = selectedItems();
|
|
|
|
if (selected_items.isEmpty()) return;
|
|
|
|
|
2017-05-11 18:58:50 +03:00
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent) return;
|
2015-07-14 10:59:15 +03:00
|
|
|
QList<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
2014-01-07 23:48:38 +04:00
|
|
|
|
2015-07-14 10:59:15 +03:00
|
|
|
foreach (QTreeWidgetItem* item, selected_items) {
|
|
|
|
// DHT case
|
2017-05-11 18:58:50 +03:00
|
|
|
if (item == m_DHTItem) {
|
2015-07-14 10:59:15 +03:00
|
|
|
torrent->forceDHTAnnounce();
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-07 23:48:38 +04:00
|
|
|
|
2015-07-14 10:59:15 +03:00
|
|
|
// Trackers case
|
|
|
|
for (int i = 0; i < trackers.size(); ++i) {
|
|
|
|
if (item->text(COL_URL) == trackers[i].url()) {
|
2015-04-19 18:17:47 +03:00
|
|
|
torrent->forceReannounce(i);
|
2014-01-07 23:48:38 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
loadTrackers();
|
2014-01-07 23:48:38 +04:00
|
|
|
}
|
|
|
|
|
2010-10-09 18:06:35 +04:00
|
|
|
void TrackerList::showTrackerListMenu(QPoint) {
|
2017-05-11 18:58:50 +03:00
|
|
|
BitTorrent::TorrentHandle *const torrent = m_properties->getCurrentTorrent();
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent) return;
|
2010-10-09 18:06:35 +04:00
|
|
|
//QList<QTreeWidgetItem*> selected_items = getSelectedTrackerItems();
|
|
|
|
QMenu menu;
|
|
|
|
// Add actions
|
2015-04-19 18:17:47 +03:00
|
|
|
QAction *addAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-add"), tr("Add a new tracker..."));
|
2017-03-09 19:45:34 +03:00
|
|
|
QAction *copyAct = nullptr;
|
|
|
|
QAction *delAct = nullptr;
|
|
|
|
QAction *editAct = nullptr;
|
2012-02-20 21:30:53 +04:00
|
|
|
if (!getSelectedTrackerItems().isEmpty()) {
|
2015-04-19 18:17:47 +03:00
|
|
|
delAct = menu.addAction(GuiIconProvider::instance()->getIcon("list-remove"), tr("Remove tracker"));
|
2015-03-30 14:15:48 +03:00
|
|
|
copyAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-copy"), tr("Copy tracker URL"));
|
2015-04-19 18:17:47 +03:00
|
|
|
editAct = menu.addAction(GuiIconProvider::instance()->getIcon("edit-rename"),tr("Edit selected tracker URL"));
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
2017-03-09 19:45:34 +03:00
|
|
|
QAction *reannounceSelAct = nullptr;
|
|
|
|
QAction *reannounceAct = nullptr;
|
2015-04-19 18:17:47 +03:00
|
|
|
if (!torrent->isPaused()) {
|
|
|
|
reannounceSelAct = menu.addAction(GuiIconProvider::instance()->getIcon("view-refresh"), tr("Force reannounce to selected trackers"));
|
2014-01-26 18:29:53 +04:00
|
|
|
menu.addSeparator();
|
2015-04-19 18:17:47 +03:00
|
|
|
reannounceAct = menu.addAction(GuiIconProvider::instance()->getIcon("view-refresh"), tr("Force reannounce to all trackers"));
|
2014-01-26 18:29:53 +04:00
|
|
|
}
|
2010-10-09 18:06:35 +04:00
|
|
|
QAction *act = menu.exec(QCursor::pos());
|
2017-03-09 19:45:34 +03:00
|
|
|
if (act == nullptr) return;
|
2012-02-20 21:30:53 +04:00
|
|
|
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;
|
|
|
|
}
|
2014-01-07 23:48:38 +04:00
|
|
|
if (act == reannounceSelAct) {
|
|
|
|
reannounceSelected();
|
|
|
|
return;
|
|
|
|
}
|
2013-10-24 00:30:12 +04:00
|
|
|
if (act == reannounceAct) {
|
2017-05-11 18:58:50 +03:00
|
|
|
BitTorrent::TorrentHandle *h = m_properties->getCurrentTorrent();
|
2015-07-14 11:14:17 +03:00
|
|
|
h->forceReannounce();
|
|
|
|
h->forceDHTAnnounce();
|
2013-10-24 00:30:12 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-01-11 22:58:38 +04:00
|
|
|
if (act == editAct) {
|
|
|
|
editSelectedTracker();
|
|
|
|
return;
|
|
|
|
}
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
2017-03-09 19:25:41 +03:00
|
|
|
void TrackerList::loadSettings()
|
|
|
|
{
|
2017-03-10 12:43:59 +03:00
|
|
|
header()->restoreState(Preferences::instance()->getPropTrackerListState());
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
|
|
|
|
2017-03-09 19:25:41 +03:00
|
|
|
void TrackerList::saveSettings() const
|
|
|
|
{
|
|
|
|
Preferences::instance()->setPropTrackerListState(header()->saveState());
|
2010-10-09 18:06:35 +04:00
|
|
|
}
|
2017-03-10 12:43:59 +03:00
|
|
|
|
|
|
|
QStringList TrackerList::headerLabels()
|
|
|
|
{
|
|
|
|
static const QStringList header {
|
|
|
|
"#"
|
|
|
|
, tr("URL")
|
|
|
|
, tr("Status")
|
|
|
|
, tr("Received")
|
|
|
|
, tr("Seeds")
|
|
|
|
, tr("Peers")
|
|
|
|
, tr("Downloaded")
|
|
|
|
, tr("Message")
|
|
|
|
};
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TrackerList::visibleColumnsCount() const
|
|
|
|
{
|
|
|
|
int visibleCols = 0;
|
|
|
|
for (unsigned int i = 0; i < COL_COUNT; ++i) {
|
|
|
|
if (!isColumnHidden(i))
|
|
|
|
++visibleCols;
|
|
|
|
}
|
|
|
|
|
|
|
|
return visibleCols;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TrackerList::displayToggleColumnsMenu(const QPoint &)
|
|
|
|
{
|
|
|
|
QMenu hideshowColumn(this);
|
|
|
|
hideshowColumn.setTitle(tr("Column visibility"));
|
|
|
|
for (int i = 0; i < COL_COUNT; ++i) {
|
|
|
|
QAction *myAct = hideshowColumn.addAction(headerLabels().at(i));
|
|
|
|
myAct->setCheckable(true);
|
|
|
|
myAct->setChecked(!isColumnHidden(i));
|
|
|
|
myAct->setData(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call menu
|
|
|
|
QAction *act = hideshowColumn.exec(QCursor::pos());
|
|
|
|
if (!act) return;
|
|
|
|
|
|
|
|
int col = act->data().toInt();
|
|
|
|
Q_ASSERT(visibleColumnsCount() > 0);
|
|
|
|
if (!isColumnHidden(col) && (visibleColumnsCount() == 1))
|
|
|
|
return;
|
|
|
|
qDebug("Toggling column %d visibility", col);
|
|
|
|
setColumnHidden(col, !isColumnHidden(col));
|
|
|
|
if (!isColumnHidden(col) && (columnWidth(col) <= 5))
|
|
|
|
setColumnWidth(col, 100);
|
|
|
|
saveSettings();
|
|
|
|
}
|