2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2009-2014 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-01-19 01:09:44 +00:00
|
|
|
* It may be used under the GNU Public License v2 or v3 licenses,
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2009-05-31 19:33:48 +00:00
|
|
|
* $Id$
|
2009-04-09 18:55:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cassert>
|
2013-08-24 17:53:45 +00:00
|
|
|
#include <climits> /* INT_MAX */
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
#include <QCheckBox>
|
2009-04-18 23:18:28 +00:00
|
|
|
#include <QComboBox>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QDateTime>
|
2013-09-08 19:03:25 +00:00
|
|
|
#include <QDesktopServices>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QDoubleSpinBox>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QEvent>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QFont>
|
|
|
|
#include <QFontMetrics>
|
|
|
|
#include <QHBoxLayout>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QHeaderView>
|
2014-12-14 15:34:31 +00:00
|
|
|
#include <QHostAddress>
|
2010-06-30 05:55:46 +00:00
|
|
|
#include <QInputDialog>
|
2010-07-27 19:43:32 +00:00
|
|
|
#include <QItemSelectionModel>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QLabel>
|
2010-07-27 19:43:32 +00:00
|
|
|
#include <QList>
|
|
|
|
#include <QMap>
|
2010-06-30 05:55:46 +00:00
|
|
|
#include <QMessageBox>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRadioButton>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QSpinBox>
|
2010-07-27 19:43:32 +00:00
|
|
|
#include <QStringList>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QStyle>
|
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QTextBrowser>
|
2009-10-06 00:27:26 +00:00
|
|
|
#include <QTreeView>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2009-04-13 18:21:22 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2013-01-26 01:19:54 +00:00
|
|
|
#include <libtransmission/utils.h> // tr_getRatio ()
|
2009-04-13 18:21:22 +00:00
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "details.h"
|
|
|
|
#include "file-tree.h"
|
2010-07-03 01:10:36 +00:00
|
|
|
#include "formatter.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "hig.h"
|
2010-04-03 14:23:29 +00:00
|
|
|
#include "prefs.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
#include "session.h"
|
|
|
|
#include "squeezelabel.h"
|
|
|
|
#include "torrent.h"
|
2009-04-18 23:18:28 +00:00
|
|
|
#include "torrent-model.h"
|
2010-07-27 19:43:32 +00:00
|
|
|
#include "tracker-delegate.h"
|
|
|
|
#include "tracker-model.h"
|
2010-07-28 14:43:47 +00:00
|
|
|
#include "tracker-model-filter.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
class Prefs;
|
|
|
|
class Session;
|
|
|
|
|
|
|
|
/****
|
|
|
|
*****
|
|
|
|
****/
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
const int REFRESH_INTERVAL_MSEC = 4000;
|
|
|
|
|
|
|
|
const char * PREF_KEY ("pref-key");
|
|
|
|
|
|
|
|
enum // peer columns
|
|
|
|
{
|
|
|
|
COL_LOCK,
|
|
|
|
COL_UP,
|
|
|
|
COL_DOWN,
|
|
|
|
COL_PERCENT,
|
|
|
|
COL_STATUS,
|
|
|
|
COL_ADDRESS,
|
|
|
|
COL_CLIENT,
|
|
|
|
N_COLUMNS
|
|
|
|
};
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
class PeerItem: public QTreeWidgetItem
|
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
Peer peer;
|
2014-12-14 15:34:31 +00:00
|
|
|
mutable QString collatedAddress;
|
2013-02-03 19:13:04 +00:00
|
|
|
QString status;
|
|
|
|
|
|
|
|
public:
|
2014-12-14 15:34:31 +00:00
|
|
|
PeerItem (const Peer& p): peer(p) {}
|
2013-02-03 19:13:04 +00:00
|
|
|
virtual ~PeerItem () {}
|
|
|
|
|
2014-12-14 15:34:31 +00:00
|
|
|
public:
|
|
|
|
void refresh (const Peer& p)
|
2013-02-03 19:13:04 +00:00
|
|
|
{
|
2014-12-14 15:34:31 +00:00
|
|
|
if (p.address != peer.address)
|
|
|
|
collatedAddress.clear ();
|
|
|
|
peer = p;
|
2013-02-03 19:13:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setStatus (const QString& s) { status = s; }
|
|
|
|
|
|
|
|
virtual bool operator< (const QTreeWidgetItem & other) const
|
|
|
|
{
|
|
|
|
const PeerItem * i = dynamic_cast<const PeerItem*> (&other);
|
|
|
|
QTreeWidget * tw (treeWidget ());
|
|
|
|
const int column = tw ? tw->sortColumn () : 0;
|
|
|
|
switch (column)
|
|
|
|
{
|
|
|
|
case COL_UP: return peer.rateToPeer < i->peer.rateToPeer;
|
|
|
|
case COL_DOWN: return peer.rateToClient < i->peer.rateToClient;
|
|
|
|
case COL_PERCENT: return peer.progress < i->peer.progress;
|
|
|
|
case COL_STATUS: return status < i->status;
|
|
|
|
case COL_CLIENT: return peer.clientName < i->peer.clientName;
|
|
|
|
case COL_LOCK: return peer.isEncrypted && !i->peer.isEncrypted;
|
2014-12-14 15:34:31 +00:00
|
|
|
default: return address () < i->address ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
}
|
2014-12-14 15:34:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const QString& address () const
|
|
|
|
{
|
|
|
|
if (collatedAddress.isEmpty ())
|
|
|
|
{
|
|
|
|
QHostAddress ipAddress;
|
|
|
|
if (ipAddress.setAddress (peer.address))
|
|
|
|
{
|
|
|
|
if (ipAddress.protocol () == QAbstractSocket::IPv4Protocol)
|
|
|
|
{
|
|
|
|
const quint32 ipv4Address = ipAddress.toIPv4Address ();
|
|
|
|
collatedAddress = QLatin1String ("1-") +
|
|
|
|
QString::fromLatin1 (QByteArray::number (ipv4Address, 16).rightJustified (8, '0'));
|
|
|
|
}
|
|
|
|
else if (ipAddress.protocol () == QAbstractSocket::IPv6Protocol)
|
|
|
|
{
|
|
|
|
const Q_IPV6ADDR ipv6Address = ipAddress.toIPv6Address ();
|
|
|
|
QByteArray tmp (16, '\0');
|
|
|
|
for (int i = 0; i < 16; ++i)
|
|
|
|
tmp[i] = ipv6Address[i];
|
|
|
|
collatedAddress = QLatin1String ("2-") + QString::fromLatin1 (tmp.toHex ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collatedAddress.isEmpty ())
|
|
|
|
collatedAddress = QLatin1String ("3-") + peer.address.toLower ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return collatedAddress;
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2010-06-30 05:55:46 +00:00
|
|
|
QIcon
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::getStockIcon (const QString& freedesktop_name, int fallback)
|
2010-06-30 05:55:46 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
QIcon icon = QIcon::fromTheme (freedesktop_name);
|
2010-06-30 05:55:46 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
if (icon.isNull ())
|
|
|
|
icon = style ()->standardIcon (QStyle::StandardPixmap (fallback), 0, this);
|
2010-06-30 05:55:46 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
return icon;
|
2010-06-30 05:55:46 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::Details (Session & session,
|
|
|
|
Prefs & prefs,
|
|
|
|
TorrentModel & model,
|
|
|
|
QWidget * parent):
|
2013-02-03 19:13:04 +00:00
|
|
|
QDialog (parent, Qt::Dialog),
|
|
|
|
mySession (session),
|
|
|
|
myPrefs (prefs),
|
|
|
|
myModel (model),
|
|
|
|
myChangedTorrents (false),
|
|
|
|
myHavePendingRefresh (false)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
QVBoxLayout * layout = new QVBoxLayout (this);
|
|
|
|
|
|
|
|
setWindowTitle (tr ("Torrent Properties"));
|
|
|
|
|
|
|
|
QTabWidget * t = new QTabWidget (this);
|
|
|
|
QWidget * w;
|
|
|
|
t->addTab (w = createInfoTab (), tr ("Information"));
|
|
|
|
myWidgets << w;
|
|
|
|
t->addTab (w = createPeersTab (), tr ("Peers"));
|
|
|
|
myWidgets << w;
|
|
|
|
t->addTab (w = createTrackerTab (), tr ("Tracker"));
|
|
|
|
myWidgets << w;
|
|
|
|
t->addTab (w = createFilesTab (), tr ("Files"));
|
|
|
|
myWidgets << w;
|
|
|
|
t->addTab (w = createOptionsTab (), tr ("Options"));
|
|
|
|
myWidgets << w;
|
|
|
|
layout->addWidget (t);
|
|
|
|
|
|
|
|
QDialogButtonBox * buttons = new QDialogButtonBox (QDialogButtonBox::Close, Qt::Horizontal, this);
|
|
|
|
connect (buttons, SIGNAL (rejected ()), this, SLOT (close ()));
|
|
|
|
layout->addWidget (buttons);
|
|
|
|
QWidget::setAttribute (Qt::WA_DeleteOnClose, true);
|
|
|
|
|
|
|
|
QList<int> initKeys;
|
2014-12-12 23:05:10 +00:00
|
|
|
initKeys << Prefs::SHOW_TRACKER_SCRAPES
|
|
|
|
<< Prefs::SHOW_BACKUP_TRACKERS;
|
2013-02-03 19:13:04 +00:00
|
|
|
foreach (int key, initKeys)
|
|
|
|
refreshPref (key);
|
|
|
|
|
|
|
|
connect (&myTimer, SIGNAL (timeout ()), this, SLOT (onTimer ()));
|
|
|
|
connect (&myPrefs, SIGNAL (changed (int)), this, SLOT (refreshPref (int)));
|
|
|
|
|
|
|
|
onTimer ();
|
|
|
|
myTimer.setSingleShot (false);
|
|
|
|
myTimer.start (REFRESH_INTERVAL_MSEC);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::~Details ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
myTrackerDelegate->deleteLater ();
|
|
|
|
myTrackerFilter->deleteLater ();
|
|
|
|
myTrackerModel->deleteLater ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2009-04-18 23:18:28 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::setIds (const QSet<int>& ids)
|
2009-04-18 23:18:28 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
if (ids == myIds)
|
|
|
|
return;
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
myChangedTorrents = true;
|
2010-05-05 09:41:14 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// stop listening to the old torrents
|
|
|
|
foreach (int id, myIds)
|
|
|
|
{
|
|
|
|
const Torrent * tor = myModel.getTorrentFromId (id);
|
|
|
|
if (tor)
|
|
|
|
disconnect (tor, SIGNAL (torrentChanged (int)), this, SLOT (onTorrentChanged ()));
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
myFileTreeView->clear ();
|
|
|
|
myIds = ids;
|
|
|
|
myTrackerModel->refresh (myModel, myIds);
|
|
|
|
|
|
|
|
// listen to the new torrents
|
|
|
|
foreach (int id, myIds)
|
|
|
|
{
|
|
|
|
const Torrent * tor = myModel.getTorrentFromId (id);
|
|
|
|
if (tor)
|
|
|
|
connect (tor, SIGNAL (torrentChanged (int)), this, SLOT (onTorrentChanged ()));
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
foreach (QWidget * w, myWidgets)
|
|
|
|
w->setEnabled (false);
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
onTimer ();
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
|
|
|
|
2010-07-27 19:43:32 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::refreshPref (int key)
|
2010-07-27 19:43:32 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
QString str;
|
2010-07-27 19:43:32 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
switch (key)
|
2010-07-27 19:43:32 +00:00
|
|
|
{
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::SHOW_TRACKER_SCRAPES:
|
2013-02-03 19:13:04 +00:00
|
|
|
{
|
|
|
|
QItemSelectionModel * selectionModel (myTrackerView->selectionModel ());
|
|
|
|
const QItemSelection selection (selectionModel->selection ());
|
|
|
|
const QModelIndex currentIndex (selectionModel->currentIndex ());
|
|
|
|
myTrackerDelegate->setShowMore (myPrefs.getBool (key));
|
|
|
|
selectionModel->clear ();
|
|
|
|
myTrackerView->reset ();
|
|
|
|
selectionModel->select (selection, QItemSelectionModel::Select);
|
|
|
|
selectionModel->setCurrentIndex (currentIndex, QItemSelectionModel::NoUpdate);
|
|
|
|
break;
|
2010-09-22 02:22:03 +00:00
|
|
|
}
|
2010-07-28 14:43:47 +00:00
|
|
|
|
2014-12-12 23:05:10 +00:00
|
|
|
case Prefs::SHOW_BACKUP_TRACKERS:
|
2013-02-03 19:13:04 +00:00
|
|
|
myTrackerFilter->setShowBackupTrackers (myPrefs.getBool (key));
|
|
|
|
break;
|
2010-07-27 19:43:32 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
default:
|
|
|
|
break;
|
2010-07-27 19:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2010-04-03 14:23:29 +00:00
|
|
|
QString
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::timeToStringRounded (int seconds)
|
2010-04-03 14:23:29 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
if (seconds > 60)
|
|
|
|
seconds -= (seconds % 60);
|
|
|
|
|
|
|
|
return Formatter::timeToString (seconds);
|
2010-04-03 14:23:29 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onTimer ()
|
2010-07-27 19:43:32 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
getNewData ();
|
2010-07-27 19:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::getNewData ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
if (!myIds.empty ())
|
2010-06-16 03:02:17 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
QSet<int> infos;
|
|
|
|
foreach (int id, myIds)
|
|
|
|
{
|
|
|
|
const Torrent * tor = myModel.getTorrentFromId (id);
|
|
|
|
if (tor->isMagnet ())
|
|
|
|
infos.insert (tor->id ());
|
2010-06-16 03:02:17 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
|
|
|
|
if (!infos.isEmpty ())
|
|
|
|
mySession.initTorrents (infos);
|
|
|
|
mySession.refreshExtraStats (myIds);
|
2010-06-16 03:02:17 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onTorrentChanged ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
if (!myHavePendingRefresh)
|
|
|
|
{
|
|
|
|
myHavePendingRefresh = true;
|
|
|
|
QTimer::singleShot (100, this, SLOT (refresh ()));
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-08 16:23:21 +00:00
|
|
|
namespace
|
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
void setIfIdle (QComboBox * box, int i)
|
|
|
|
{
|
|
|
|
if (!box->hasFocus ())
|
|
|
|
{
|
|
|
|
box->blockSignals (true);
|
|
|
|
box->setCurrentIndex (i);
|
|
|
|
box->blockSignals (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIfIdle (QDoubleSpinBox * spin, double value)
|
|
|
|
{
|
|
|
|
if (!spin->hasFocus ())
|
|
|
|
{
|
|
|
|
spin->blockSignals (true);
|
|
|
|
spin->setValue (value);
|
|
|
|
spin->blockSignals (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setIfIdle (QSpinBox * spin, int value)
|
|
|
|
{
|
|
|
|
if (!spin->hasFocus ())
|
|
|
|
{
|
|
|
|
spin->blockSignals (true);
|
|
|
|
spin->setValue (value);
|
|
|
|
spin->blockSignals (false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::refresh ()
|
2013-02-03 19:13:04 +00:00
|
|
|
{
|
|
|
|
const int n = myIds.size ();
|
|
|
|
const bool single = n == 1;
|
|
|
|
const QString blank;
|
|
|
|
const QFontMetrics fm (fontMetrics ());
|
|
|
|
QList<const Torrent*> torrents;
|
|
|
|
QString string;
|
|
|
|
const QString none = tr ("None");
|
|
|
|
const QString mixed = tr ("Mixed");
|
|
|
|
const QString unknown = tr ("Unknown");
|
|
|
|
|
|
|
|
// build a list of torrents
|
|
|
|
foreach (int id, myIds)
|
2010-12-08 16:23:21 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
const Torrent * tor = myModel.getTorrentFromId (id);
|
|
|
|
if (tor)
|
|
|
|
torrents << tor;
|
2010-12-08 16:23:21 +00:00
|
|
|
}
|
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
///
|
|
|
|
/// activity tab
|
|
|
|
///
|
|
|
|
|
|
|
|
// myStateLabel
|
|
|
|
if (torrents.empty ())
|
2010-12-08 16:23:21 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
string = none;
|
2010-12-08 16:23:21 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
else
|
2010-12-08 16:23:21 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
bool isMixed = false;
|
|
|
|
bool allPaused = true;
|
|
|
|
bool allFinished = true;
|
|
|
|
const tr_torrent_activity baseline = torrents[0]->getActivity ();
|
|
|
|
foreach (const Torrent * t, torrents)
|
2010-12-08 16:23:21 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
const tr_torrent_activity activity = t->getActivity ();
|
|
|
|
if (activity != baseline)
|
|
|
|
isMixed = true;
|
|
|
|
if (activity != TR_STATUS_STOPPED)
|
|
|
|
allPaused = allFinished = false;
|
|
|
|
if (!t->isFinished ())
|
|
|
|
allFinished = false;
|
2010-12-08 16:23:21 +00:00
|
|
|
}
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
if (isMixed)
|
|
|
|
string = mixed;
|
|
|
|
else if (allFinished)
|
|
|
|
string = tr ("Finished");
|
|
|
|
else if (allPaused)
|
|
|
|
string = tr ("Paused");
|
|
|
|
else
|
|
|
|
string = torrents[0]->activityString ();
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myStateLabel->setText (string);
|
|
|
|
const QString stateString = string;
|
|
|
|
|
|
|
|
// myHaveLabel
|
|
|
|
double sizeWhenDone = 0;
|
|
|
|
double available = 0;
|
|
|
|
if (torrents.empty ())
|
|
|
|
{
|
|
|
|
string = none;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-12 23:52:17 +00:00
|
|
|
double leftUntilDone = 0;
|
|
|
|
int64_t haveTotal = 0;
|
|
|
|
int64_t haveVerified = 0;
|
|
|
|
int64_t haveUnverified = 0;
|
|
|
|
int64_t verifiedPieces = 0;
|
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
if (t->hasMetadata ())
|
|
|
|
{
|
|
|
|
haveTotal += t->haveTotal ();
|
|
|
|
haveUnverified += t->haveUnverified ();
|
2013-08-29 00:37:37 +00:00
|
|
|
const uint64_t v = t->haveVerified ();
|
2013-02-03 19:13:04 +00:00
|
|
|
haveVerified += v;
|
|
|
|
if (t->pieceSize ())
|
|
|
|
verifiedPieces += v / t->pieceSize ();
|
|
|
|
sizeWhenDone += t->sizeWhenDone ();
|
|
|
|
leftUntilDone += t->leftUntilDone ();
|
|
|
|
available += t->sizeWhenDone () - t->leftUntilDone () + t->desiredAvailable ();
|
|
|
|
}
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
const double d = 100.0 * (sizeWhenDone ? (sizeWhenDone - leftUntilDone) / sizeWhenDone : 1);
|
|
|
|
QString pct = Formatter::percentToString (d);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
if (!haveUnverified && !leftUntilDone)
|
|
|
|
{
|
|
|
|
string = tr ("%1 (100%)")
|
|
|
|
.arg (Formatter::sizeToString (haveVerified));
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
else if (!haveUnverified)
|
|
|
|
{
|
|
|
|
string = tr ("%1 of %2 (%3%)")
|
|
|
|
.arg (Formatter::sizeToString (haveVerified))
|
|
|
|
.arg (Formatter::sizeToString (sizeWhenDone))
|
|
|
|
.arg (pct);
|
2010-06-03 23:39:31 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
else
|
2010-09-17 05:43:06 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
string = tr ("%1 of %2 (%3%), %4 Unverified")
|
|
|
|
.arg (Formatter::sizeToString (haveVerified + haveUnverified))
|
|
|
|
.arg (Formatter::sizeToString (sizeWhenDone))
|
|
|
|
.arg (pct)
|
|
|
|
.arg (Formatter::sizeToString (haveUnverified));
|
2010-06-03 23:39:31 +00:00
|
|
|
}
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myHaveLabel->setText (string);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// myAvailabilityLabel
|
|
|
|
if (torrents.empty ())
|
|
|
|
string = none;
|
|
|
|
else if (sizeWhenDone == 0)
|
|
|
|
string = none;
|
|
|
|
else
|
|
|
|
string = QString ("%1%").arg (Formatter::percentToString ( (100.0 * available) / sizeWhenDone));
|
|
|
|
myAvailabilityLabel->setText (string);
|
2010-02-02 05:34:26 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// myDownloadedLabel
|
|
|
|
if (torrents.empty ())
|
|
|
|
{
|
|
|
|
string = none;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-29 00:37:37 +00:00
|
|
|
uint64_t d = 0;
|
|
|
|
uint64_t f = 0;
|
2013-02-03 19:13:04 +00:00
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
d += t->downloadedEver ();
|
|
|
|
f += t->failedEver ();
|
2009-06-23 00:24:37 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
const QString dstr = Formatter::sizeToString (d);
|
|
|
|
const QString fstr = Formatter::sizeToString (f);
|
|
|
|
if (f)
|
|
|
|
string = tr ("%1 (%2 corrupt)").arg (dstr).arg (fstr);
|
|
|
|
else
|
|
|
|
string = dstr;
|
2009-06-23 00:24:37 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myDownloadedLabel->setText (string);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// myUploadedLabel
|
|
|
|
if (torrents.empty ())
|
|
|
|
{
|
|
|
|
string = none;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-29 00:37:37 +00:00
|
|
|
uint64_t u = 0;
|
|
|
|
uint64_t d = 0;
|
2013-02-03 19:13:04 +00:00
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
u += t->uploadedEver ();
|
|
|
|
d += t->downloadedEver ();
|
2010-06-03 23:39:31 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
string = tr ("%1 (Ratio: %2)")
|
|
|
|
.arg (Formatter::sizeToString (u))
|
|
|
|
.arg (Formatter::ratioToString (tr_getRatio (u, d)));
|
2010-06-03 23:39:31 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myUploadedLabel->setText (string);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
const QDateTime qdt_now = QDateTime::currentDateTime ();
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// myRunTimeLabel
|
|
|
|
if (torrents.empty ())
|
|
|
|
{
|
|
|
|
string = none;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bool allPaused = true;
|
|
|
|
QDateTime baseline = torrents[0]->lastStarted ();
|
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
if (baseline != t->lastStarted ())
|
|
|
|
baseline = QDateTime ();
|
|
|
|
if (!t->isPaused ())
|
|
|
|
allPaused = false;
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
|
|
|
|
if (allPaused)
|
|
|
|
string = stateString; // paused || finished
|
|
|
|
else if (baseline.isNull ())
|
|
|
|
string = mixed;
|
|
|
|
else
|
|
|
|
string = Formatter::timeToString (baseline.secsTo (qdt_now));
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myRunTimeLabel->setText (string);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2009-04-26 15:41:04 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// myETALabel
|
|
|
|
string.clear ();
|
|
|
|
if (torrents.empty ())
|
|
|
|
{
|
|
|
|
string = none;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int baseline = torrents[0]->getETA ();
|
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
if (baseline != t->getETA ())
|
|
|
|
{
|
|
|
|
string = mixed;
|
|
|
|
break;
|
2009-10-10 20:42:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
|
|
|
|
if (string.isEmpty ())
|
|
|
|
{
|
|
|
|
if (baseline < 0)
|
|
|
|
string = tr ("Unknown");
|
|
|
|
else
|
|
|
|
string = Formatter::timeToString (baseline);
|
2010-01-05 23:47:50 +00:00
|
|
|
}
|
2009-10-10 20:42:23 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myETALabel->setText (string);
|
2009-10-10 20:42:23 +00:00
|
|
|
|
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// myLastActivityLabel
|
|
|
|
if (torrents.empty ())
|
|
|
|
{
|
|
|
|
string = none;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QDateTime latest = torrents[0]->lastActivity ();
|
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
const QDateTime dt = t->lastActivity ();
|
|
|
|
if (latest < dt)
|
|
|
|
latest = dt;
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
|
|
|
|
const int seconds = latest.isValid () ? latest.secsTo (qdt_now) : -1;
|
|
|
|
if (seconds < 0)
|
|
|
|
string = none;
|
|
|
|
else if (seconds < 5)
|
|
|
|
string = tr ("Active now");
|
|
|
|
else
|
|
|
|
string = tr ("%1 ago").arg (Formatter::timeToString (seconds));
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myLastActivityLabel->setText (string);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2009-04-26 15:41:04 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
if (torrents.empty ())
|
|
|
|
{
|
|
|
|
string = none;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string = torrents[0]->getError ();
|
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
if (string != t->getError ())
|
|
|
|
{
|
|
|
|
string = mixed;
|
|
|
|
break;
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
if (string.isEmpty ())
|
|
|
|
string = none;
|
|
|
|
myErrorLabel->setText (string);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2009-04-26 15:41:04 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
///
|
|
|
|
/// information tab
|
|
|
|
///
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// mySizeLabel
|
|
|
|
if (torrents.empty ())
|
|
|
|
{
|
|
|
|
string = none;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
int pieces = 0;
|
2013-08-29 00:37:37 +00:00
|
|
|
uint64_t size = 0;
|
|
|
|
uint32_t pieceSize = torrents[0]->pieceSize ();
|
2013-02-03 19:13:04 +00:00
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
pieces += t->pieceCount ();
|
|
|
|
size += t->totalSize ();
|
|
|
|
if (pieceSize != t->pieceSize ())
|
|
|
|
pieceSize = 0;
|
|
|
|
}
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
if (!size)
|
2009-04-26 15:41:04 +00:00
|
|
|
string = none;
|
2013-02-03 19:13:04 +00:00
|
|
|
else if (pieceSize > 0)
|
|
|
|
string = tr ("%1 (%Ln pieces @ %2)", "", pieces)
|
|
|
|
.arg (Formatter::sizeToString (size))
|
|
|
|
.arg (Formatter::memToString (pieceSize));
|
|
|
|
else
|
|
|
|
string = tr ("%1 (%Ln pieces)", "", pieces)
|
|
|
|
.arg (Formatter::sizeToString (size));
|
|
|
|
}
|
|
|
|
mySizeLabel->setText (string);
|
|
|
|
|
|
|
|
// myHashLabel
|
|
|
|
string = none;
|
|
|
|
if (!torrents.empty ())
|
|
|
|
{
|
|
|
|
string = torrents[0]->hashString ();
|
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
if (string != t->hashString ())
|
|
|
|
{
|
|
|
|
string = mixed;
|
|
|
|
break;
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myHashLabel->setText (string);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// myPrivacyLabel
|
|
|
|
string = none;
|
|
|
|
if (!torrents.empty ())
|
|
|
|
{
|
|
|
|
bool b = torrents[0]->isPrivate ();
|
|
|
|
string = b ? tr ("Private to this tracker -- DHT and PEX disabled")
|
|
|
|
: tr ("Public torrent");
|
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
if (b != t->isPrivate ())
|
|
|
|
{
|
|
|
|
string = mixed;
|
|
|
|
break;
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myPrivacyLabel->setText (string);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// myCommentBrowser
|
|
|
|
string = none;
|
|
|
|
if (!torrents.empty ())
|
|
|
|
{
|
|
|
|
string = torrents[0]->comment ();
|
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
if (string != t->comment ())
|
|
|
|
{
|
|
|
|
string = mixed;
|
|
|
|
break;
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
if (myCommentBrowser->toPlainText() != string)
|
|
|
|
{
|
2013-02-03 18:36:10 +00:00
|
|
|
myCommentBrowser->setText (string);
|
|
|
|
myCommentBrowser->setMaximumHeight (QWIDGETSIZE_MAX);
|
|
|
|
}
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// myOriginLabel
|
|
|
|
string = none;
|
|
|
|
if (!torrents.empty ())
|
|
|
|
{
|
|
|
|
bool mixed_creator=false, mixed_date=false;
|
|
|
|
const QString creator = torrents[0]->creator ();
|
|
|
|
const QString date = torrents[0]->dateCreated ().toString ();
|
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
mixed_creator |= (creator != t->creator ());
|
|
|
|
mixed_date |= (date != t->dateCreated ().toString ());
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
|
|
|
|
if (mixed_creator && mixed_date)
|
|
|
|
string = mixed;
|
|
|
|
else if (mixed_date && !creator.isEmpty ())
|
|
|
|
string = tr ("Created by %1").arg (creator);
|
|
|
|
else if (mixed_creator && !date.isEmpty ())
|
|
|
|
string = tr ("Created on %1").arg (date);
|
|
|
|
else if (creator.isEmpty () && date.isEmpty ())
|
|
|
|
string = tr ("N/A");
|
|
|
|
else
|
|
|
|
string = tr ("Created by %1 on %2").arg (creator).arg (date);
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myOriginLabel->setText (string);
|
2010-01-05 23:47:50 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// myLocationLabel
|
|
|
|
string = none;
|
|
|
|
if (!torrents.empty ())
|
|
|
|
{
|
|
|
|
string = torrents[0]->getPath ();
|
|
|
|
foreach (const Torrent * t, torrents)
|
|
|
|
{
|
|
|
|
if (string != t->getPath ())
|
|
|
|
{
|
|
|
|
string = mixed;
|
|
|
|
break;
|
2009-04-26 15:41:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myLocationLabel->setText (string);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
///
|
|
|
|
/// Options Tab
|
|
|
|
///
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
if (myChangedTorrents && !torrents.empty ())
|
2009-04-18 23:18:28 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
int i;
|
|
|
|
bool uniform;
|
|
|
|
bool baselineFlag;
|
|
|
|
int baselineInt;
|
|
|
|
const Torrent * tor;
|
|
|
|
const Torrent * baseline = *torrents.begin ();
|
|
|
|
|
|
|
|
// mySessionLimitCheck
|
|
|
|
uniform = true;
|
|
|
|
baselineFlag = baseline->honorsSessionLimits ();
|
|
|
|
foreach (tor, torrents) if (baselineFlag != tor->honorsSessionLimits ()) { uniform = false; break; }
|
|
|
|
mySessionLimitCheck->setChecked (uniform && baselineFlag);
|
|
|
|
|
|
|
|
// mySingleDownCheck
|
|
|
|
uniform = true;
|
|
|
|
baselineFlag = baseline->downloadIsLimited ();
|
|
|
|
foreach (tor, torrents) if (baselineFlag != tor->downloadIsLimited ()) { uniform = false; break; }
|
|
|
|
mySingleDownCheck->setChecked (uniform && baselineFlag);
|
|
|
|
|
|
|
|
// mySingleUpCheck
|
|
|
|
uniform = true;
|
|
|
|
baselineFlag = baseline->uploadIsLimited ();
|
|
|
|
foreach (tor, torrents) if (baselineFlag != tor->uploadIsLimited ()) { uniform = false; break; }
|
|
|
|
mySingleUpCheck->setChecked (uniform && baselineFlag);
|
|
|
|
|
|
|
|
// myBandwidthPriorityCombo
|
|
|
|
uniform = true;
|
|
|
|
baselineInt = baseline->getBandwidthPriority ();
|
|
|
|
foreach (tor, torrents) if (baselineInt != tor->getBandwidthPriority ()) { uniform = false; break; }
|
|
|
|
if (uniform)
|
|
|
|
i = myBandwidthPriorityCombo->findData (baselineInt);
|
|
|
|
else
|
|
|
|
i = -1;
|
|
|
|
setIfIdle (myBandwidthPriorityCombo, i);
|
|
|
|
|
|
|
|
setIfIdle (mySingleDownSpin, int (tor->downloadLimit ().KBps ()));
|
|
|
|
setIfIdle (mySingleUpSpin, int (tor->uploadLimit ().KBps ()));
|
|
|
|
setIfIdle (myPeerLimitSpin, tor->peerLimit ());
|
2010-07-24 04:14:43 +00:00
|
|
|
}
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
if (!torrents.empty ())
|
2010-07-24 04:14:43 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
const Torrent * tor;
|
2010-07-24 04:14:43 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// ratio
|
|
|
|
bool uniform = true;
|
|
|
|
int baselineInt = torrents[0]->seedRatioMode ();
|
|
|
|
foreach (tor, torrents) if (baselineInt != tor->seedRatioMode ()) { uniform = false; break; }
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
setIfIdle (myRatioCombo, uniform ? myRatioCombo->findData (baselineInt) : -1);
|
|
|
|
myRatioSpin->setVisible (uniform && (baselineInt == TR_RATIOLIMIT_SINGLE));
|
2010-07-24 04:14:43 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
setIfIdle (myRatioSpin, tor->seedRatioLimit ());
|
2010-07-24 04:14:43 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// idle
|
|
|
|
uniform = true;
|
|
|
|
baselineInt = torrents[0]->seedIdleMode ();
|
|
|
|
foreach (tor, torrents) if (baselineInt != tor->seedIdleMode ()) { uniform = false; break; }
|
2010-07-24 04:14:43 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
setIfIdle (myIdleCombo, uniform ? myIdleCombo->findData (baselineInt) : -1);
|
|
|
|
myIdleSpin->setVisible (uniform && (baselineInt == TR_RATIOLIMIT_SINGLE));
|
2010-07-24 04:14:43 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
setIfIdle (myIdleSpin, tor->seedIdleLimit ());
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
///
|
|
|
|
/// Tracker tab
|
|
|
|
///
|
2010-06-30 05:55:46 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
myTrackerModel->refresh (myModel, myIds);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
///
|
|
|
|
/// Peers tab
|
|
|
|
///
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
QMap<QString,QTreeWidgetItem*> peers2;
|
|
|
|
QList<QTreeWidgetItem*> newItems;
|
|
|
|
foreach (const Torrent * t, torrents)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
const QString idStr (QString::number (t->id ()));
|
|
|
|
PeerList peers = t->peers ();
|
2009-05-04 02:58:05 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
foreach (const Peer& peer, peers)
|
2009-05-04 02:58:05 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
const QString key = idStr + ":" + peer.address;
|
2014-12-12 23:52:17 +00:00
|
|
|
PeerItem * item = static_cast<PeerItem*> (myPeers.value (key, 0));
|
2009-05-04 02:58:05 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
if (item == 0) // new peer has connected
|
2009-05-04 02:58:05 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
static const QIcon myEncryptionIcon (":/icons/encrypted.png");
|
|
|
|
static const QIcon myEmptyIcon;
|
|
|
|
item = new PeerItem (peer);
|
|
|
|
item->setTextAlignment (COL_UP, Qt::AlignRight|Qt::AlignVCenter);
|
|
|
|
item->setTextAlignment (COL_DOWN, Qt::AlignRight|Qt::AlignVCenter);
|
|
|
|
item->setTextAlignment (COL_PERCENT, Qt::AlignRight|Qt::AlignVCenter);
|
|
|
|
item->setIcon (COL_LOCK, peer.isEncrypted ? myEncryptionIcon : myEmptyIcon);
|
|
|
|
item->setToolTip (COL_LOCK, peer.isEncrypted ? tr ("Encrypted connection") : "");
|
|
|
|
item->setText (COL_ADDRESS, peer.address);
|
|
|
|
item->setText (COL_CLIENT, peer.clientName);
|
|
|
|
newItems << item;
|
2009-05-04 02:58:05 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
const QString code = peer.flagStr;
|
|
|
|
item->setStatus (code);
|
|
|
|
item->refresh (peer);
|
|
|
|
|
|
|
|
QString codeTip;
|
|
|
|
foreach (QChar ch, code)
|
|
|
|
{
|
|
|
|
QString txt;
|
2013-07-27 21:58:14 +00:00
|
|
|
switch (ch.unicode ())
|
2013-02-03 19:13:04 +00:00
|
|
|
{
|
|
|
|
case 'O': txt = tr ("Optimistic unchoke"); break;
|
|
|
|
case 'D': txt = tr ("Downloading from this peer"); break;
|
|
|
|
case 'd': txt = tr ("We would download from this peer if they would let us"); break;
|
|
|
|
case 'U': txt = tr ("Uploading to peer"); break;
|
|
|
|
case 'u': txt = tr ("We would upload to this peer if they asked"); break;
|
|
|
|
case 'K': txt = tr ("Peer has unchoked us, but we're not interested"); break;
|
|
|
|
case '?': txt = tr ("We unchoked this peer, but they're not interested"); break;
|
|
|
|
case 'E': txt = tr ("Encrypted connection"); break;
|
|
|
|
case 'H': txt = tr ("Peer was discovered through DHT"); break;
|
|
|
|
case 'X': txt = tr ("Peer was discovered through Peer Exchange (PEX)"); break;
|
|
|
|
case 'I': txt = tr ("Peer is an incoming connection"); break;
|
|
|
|
case 'T': txt = tr ("Peer is connected over uTP"); break;
|
2009-05-04 02:58:05 +00:00
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
|
|
|
|
if (!txt.isEmpty ())
|
|
|
|
codeTip += QString ("%1: %2\n").arg (ch).arg (txt);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2009-05-04 02:58:05 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
if (!codeTip.isEmpty ())
|
|
|
|
codeTip.resize (codeTip.size ()-1); // eat the trailing linefeed
|
2009-05-04 02:58:05 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
item->setText (COL_UP, peer.rateToPeer.isZero () ? "" : Formatter::speedToString (peer.rateToPeer));
|
|
|
|
item->setText (COL_DOWN, peer.rateToClient.isZero () ? "" : Formatter::speedToString (peer.rateToClient));
|
|
|
|
item->setText (COL_PERCENT, peer.progress > 0 ? QString ("%1%").arg ( (int) (peer.progress * 100.0)) : "");
|
|
|
|
item->setText (COL_STATUS, code);
|
|
|
|
item->setToolTip (COL_STATUS, codeTip);
|
2009-05-04 02:58:05 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
peers2.insert (key, item);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
|
|
|
|
myPeerTree->addTopLevelItems (newItems);
|
|
|
|
foreach (QString key, myPeers.keys ())
|
|
|
|
{
|
|
|
|
if (!peers2.contains (key)) // old peer has disconnected
|
|
|
|
{
|
|
|
|
QTreeWidgetItem * item = myPeers.value (key, 0);
|
|
|
|
myPeerTree->takeTopLevelItem (myPeerTree->indexOfTopLevelItem (item));
|
|
|
|
delete item;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-03 19:13:04 +00:00
|
|
|
myPeers = peers2;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
if (!single)
|
|
|
|
myFileTreeView->clear ();
|
|
|
|
if (single)
|
|
|
|
myFileTreeView->update (torrents[0]->files (), myChangedTorrents);
|
2009-04-18 23:18:28 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
myChangedTorrents = false;
|
|
|
|
myHavePendingRefresh = false;
|
|
|
|
foreach (QWidget * w, myWidgets)
|
|
|
|
w->setEnabled (true);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::enableWhenChecked (QCheckBox * box, QWidget * w)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
connect (box, SIGNAL (toggled (bool)), w, SLOT (setEnabled (bool)));
|
|
|
|
w->setEnabled (box->isChecked ());
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::createInfoTab ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
HIG * hig = new HIG (this);
|
|
|
|
|
|
|
|
hig->addSectionTitle (tr ("Activity"));
|
|
|
|
hig->addRow (tr ("Have:"), myHaveLabel = new SqueezeLabel);
|
|
|
|
hig->addRow (tr ("Availability:"), myAvailabilityLabel = new SqueezeLabel);
|
|
|
|
hig->addRow (tr ("Uploaded:"), myUploadedLabel = new SqueezeLabel);
|
2014-01-20 23:56:06 +00:00
|
|
|
hig->addRow (tr ("Downloaded:"), myDownloadedLabel = new SqueezeLabel);
|
2013-02-03 19:13:04 +00:00
|
|
|
hig->addRow (tr ("State:"), myStateLabel = new SqueezeLabel);
|
|
|
|
hig->addRow (tr ("Running time:"), myRunTimeLabel = new SqueezeLabel);
|
|
|
|
hig->addRow (tr ("Remaining time:"), myETALabel = new SqueezeLabel);
|
|
|
|
hig->addRow (tr ("Last activity:"), myLastActivityLabel = new SqueezeLabel);
|
|
|
|
hig->addRow (tr ("Error:"), myErrorLabel = new SqueezeLabel);
|
|
|
|
hig->addSectionDivider ();
|
|
|
|
|
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Details"));
|
|
|
|
hig->addRow (tr ("Size:"), mySizeLabel = new SqueezeLabel);
|
|
|
|
hig->addRow (tr ("Location:"), myLocationLabel = new SqueezeLabel);
|
|
|
|
hig->addRow (tr ("Hash:"), myHashLabel = new SqueezeLabel);
|
|
|
|
hig->addRow (tr ("Privacy:"), myPrivacyLabel = new SqueezeLabel);
|
|
|
|
hig->addRow (tr ("Origin:"), myOriginLabel = new SqueezeLabel);
|
|
|
|
myOriginLabel->setMinimumWidth (325); // stop long origin strings from resizing the widgit
|
|
|
|
hig->addRow (tr ("Comment:"), myCommentBrowser = new QTextBrowser);
|
|
|
|
const int h = QFontMetrics (myCommentBrowser->font ()).lineSpacing () * 4;
|
|
|
|
myCommentBrowser->setFixedHeight (h);
|
|
|
|
|
|
|
|
hig->finish ();
|
|
|
|
|
|
|
|
return hig;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2010-04-03 14:23:29 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onShowTrackerScrapesToggled (bool val)
|
2010-04-03 14:23:29 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
myPrefs.set (Prefs::SHOW_TRACKER_SCRAPES, val);
|
2010-04-03 14:23:29 +00:00
|
|
|
}
|
|
|
|
|
2010-07-28 14:43:47 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onShowBackupTrackersToggled (bool val)
|
2010-07-28 14:43:47 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
myPrefs.set (Prefs::SHOW_BACKUP_TRACKERS, val);
|
2010-07-28 14:43:47 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onHonorsSessionLimitsToggled (bool val)
|
2009-04-12 21:15:35 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
mySession.torrentSet (myIds, TR_KEY_honorsSessionLimits, val);
|
|
|
|
getNewData ();
|
2009-04-12 21:15:35 +00:00
|
|
|
}
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onDownloadLimitedToggled (bool val)
|
2009-04-12 21:15:35 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
mySession.torrentSet (myIds, TR_KEY_downloadLimited, val);
|
|
|
|
getNewData ();
|
2009-04-12 21:15:35 +00:00
|
|
|
}
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onSpinBoxEditingFinished ()
|
2009-04-12 21:15:35 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
const QObject * spin = sender ();
|
|
|
|
const tr_quark key = spin->property (PREF_KEY).toInt ();
|
|
|
|
const QDoubleSpinBox * d = qobject_cast<const QDoubleSpinBox*> (spin);
|
2012-12-22 20:35:19 +00:00
|
|
|
if (d)
|
2013-01-26 01:19:54 +00:00
|
|
|
mySession.torrentSet (myIds, key, d->value ());
|
2012-12-22 20:35:19 +00:00
|
|
|
else
|
2013-01-26 01:19:54 +00:00
|
|
|
mySession.torrentSet (myIds, key, qobject_cast<const QSpinBox*> (spin)->value ());
|
|
|
|
getNewData ();
|
2009-04-12 21:15:35 +00:00
|
|
|
}
|
2010-12-04 00:19:52 +00:00
|
|
|
|
2009-04-12 21:15:35 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onUploadLimitedToggled (bool val)
|
2009-04-12 21:15:35 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
mySession.torrentSet (myIds, TR_KEY_uploadLimited, val);
|
|
|
|
getNewData ();
|
2009-04-12 21:15:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onIdleModeChanged (int index)
|
2009-04-12 21:15:35 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
const int val = myIdleCombo->itemData (index).toInt ();
|
2012-12-22 20:35:19 +00:00
|
|
|
mySession.torrentSet (myIds, TR_KEY_seedIdleMode, val);
|
|
|
|
getNewData ();
|
2009-04-12 21:15:35 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 04:14:43 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onRatioModeChanged (int index)
|
2010-07-24 04:14:43 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
const int val = myRatioCombo->itemData (index).toInt ();
|
2012-12-22 20:35:19 +00:00
|
|
|
mySession.torrentSet (myIds, TR_KEY_seedRatioMode, val);
|
2010-07-24 04:14:43 +00:00
|
|
|
}
|
2009-04-19 02:48:55 +00:00
|
|
|
|
2009-04-18 23:18:28 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onBandwidthPriorityChanged (int index)
|
2009-04-18 23:18:28 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
if (index != -1)
|
2009-04-18 23:18:28 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
const int priority = myBandwidthPriorityCombo->itemData (index).toInt ();
|
|
|
|
mySession.torrentSet (myIds, TR_KEY_bandwidthPriority, priority);
|
|
|
|
getNewData ();
|
2009-04-18 23:18:28 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2010-06-30 05:55:46 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onTrackerSelectionChanged ()
|
2010-06-30 05:55:46 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
const int selectionCount = myTrackerView->selectionModel ()->selectedRows ().size ();
|
2012-12-22 20:35:19 +00:00
|
|
|
myEditTrackerButton->setEnabled (selectionCount == 1);
|
|
|
|
myRemoveTrackerButton->setEnabled (selectionCount > 0);
|
2010-06-30 05:55:46 +00:00
|
|
|
}
|
|
|
|
|
2010-07-27 19:43:32 +00:00
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onAddTrackerClicked ()
|
2010-06-30 05:55:46 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
bool ok = false;
|
|
|
|
const QString url = QInputDialog::getText (this,
|
2013-01-26 01:19:54 +00:00
|
|
|
tr ("Add URL "),
|
|
|
|
tr ("Add tracker announce URL:"),
|
|
|
|
QLineEdit::Normal, QString (), &ok);
|
|
|
|
if (!ok)
|
2010-06-30 05:55:46 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
// user pressed "cancel" -- noop
|
2010-06-30 05:55:46 +00:00
|
|
|
}
|
2013-01-26 01:19:54 +00:00
|
|
|
else if (!QUrl (url).isValid ())
|
2010-06-30 05:55:46 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
QMessageBox::warning (this, tr ("Error"), tr ("Invalid URL \"%1\"").arg (url));
|
2010-07-27 19:43:32 +00:00
|
|
|
}
|
2012-12-22 20:35:19 +00:00
|
|
|
else
|
2010-07-27 19:43:32 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
QSet<int> ids;
|
2010-06-30 05:55:46 +00:00
|
|
|
|
2012-12-22 20:35:19 +00:00
|
|
|
foreach (int id, myIds)
|
2013-01-26 01:19:54 +00:00
|
|
|
if (myTrackerModel->find (id,url) == -1)
|
2012-12-22 20:35:19 +00:00
|
|
|
ids.insert (id);
|
2010-06-30 05:55:46 +00:00
|
|
|
|
2013-01-26 01:19:54 +00:00
|
|
|
if (ids.empty ()) // all the torrents already have this tracker
|
2010-07-27 19:43:32 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
QMessageBox::warning (this, tr ("Error"), tr ("Tracker already exists."));
|
2010-06-30 05:55:46 +00:00
|
|
|
}
|
|
|
|
else
|
2010-07-27 19:43:32 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
QStringList urls;
|
|
|
|
urls << url;
|
|
|
|
mySession.torrentSet (ids, TR_KEY_trackerAdd, urls);
|
|
|
|
getNewData ();
|
2010-07-27 19:43:32 +00:00
|
|
|
}
|
2010-06-30 05:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onEditTrackerClicked ()
|
2010-06-30 05:55:46 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
QItemSelectionModel * selectionModel = myTrackerView->selectionModel ();
|
|
|
|
QModelIndexList selectedRows = selectionModel->selectedRows ();
|
|
|
|
assert (selectedRows.size () == 1);
|
|
|
|
QModelIndex i = selectionModel->currentIndex ();
|
|
|
|
const TrackerInfo trackerInfo = myTrackerView->model ()->data (i, TrackerModel::TrackerRole).value<TrackerInfo> ();
|
2012-12-22 20:35:19 +00:00
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
const QString newval = QInputDialog::getText (this,
|
2013-01-26 01:19:54 +00:00
|
|
|
tr ("Edit URL "),
|
|
|
|
tr ("Edit tracker announce URL:"),
|
2012-12-22 20:35:19 +00:00
|
|
|
QLineEdit::Normal,
|
|
|
|
trackerInfo.st.announce, &ok);
|
|
|
|
|
|
|
|
if (!ok)
|
2010-06-30 05:55:46 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
// user pressed "cancel" -- noop
|
2010-07-27 19:43:32 +00:00
|
|
|
}
|
2013-01-26 01:19:54 +00:00
|
|
|
else if (!QUrl (newval).isValid ())
|
2010-07-27 19:43:32 +00:00
|
|
|
{
|
2013-01-26 01:19:54 +00:00
|
|
|
QMessageBox::warning (this, tr ("Error"), tr ("Invalid URL \"%1\"").arg (newval));
|
2010-07-27 19:43:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
QSet<int> ids;
|
|
|
|
ids << trackerInfo.torrentId;
|
2010-06-30 05:55:46 +00:00
|
|
|
|
2012-12-22 20:35:19 +00:00
|
|
|
const QPair<int,QString> idUrl = qMakePair (trackerInfo.st.id, newval);
|
2010-06-30 05:55:46 +00:00
|
|
|
|
2012-12-22 20:35:19 +00:00
|
|
|
mySession.torrentSet (ids, TR_KEY_trackerReplace, idUrl);
|
|
|
|
getNewData ();
|
2010-06-30 05:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onRemoveTrackerClicked ()
|
2010-06-30 05:55:46 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
// make a map of torrentIds to announce URLs to remove
|
|
|
|
QItemSelectionModel * selectionModel = myTrackerView->selectionModel ();
|
|
|
|
QModelIndexList selectedRows = selectionModel->selectedRows ();
|
|
|
|
QMap<int,int> torrentId_to_trackerIds;
|
|
|
|
foreach (QModelIndex i, selectedRows)
|
2010-07-27 19:43:32 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
const TrackerInfo inf = myTrackerView->model ()->data (i, TrackerModel::TrackerRole).value<TrackerInfo> ();
|
|
|
|
torrentId_to_trackerIds.insertMulti (inf.torrentId, inf.st.id);
|
2010-07-27 19:43:32 +00:00
|
|
|
}
|
2010-06-30 05:55:46 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
// batch all of a tracker's torrents into one command
|
|
|
|
foreach (int id, torrentId_to_trackerIds.uniqueKeys ())
|
2010-07-27 19:43:32 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
QSet<int> ids;
|
|
|
|
ids << id;
|
|
|
|
mySession.torrentSet (ids, TR_KEY_trackerRemove, torrentId_to_trackerIds.values (id));
|
2010-06-30 05:55:46 +00:00
|
|
|
}
|
2010-09-14 06:23:48 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
selectionModel->clearSelection ();
|
|
|
|
getNewData ();
|
2010-06-30 05:55:46 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 18:55:47 +00:00
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::createOptionsTab ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
QSpinBox * s;
|
|
|
|
QCheckBox * c;
|
|
|
|
QComboBox * m;
|
|
|
|
QHBoxLayout * h;
|
|
|
|
QDoubleSpinBox * ds;
|
|
|
|
const QString speed_K_str = Formatter::unitStr (Formatter::SPEED, Formatter::KB);
|
|
|
|
|
|
|
|
HIG * hig = new HIG (this);
|
|
|
|
hig->addSectionTitle (tr ("Speed"));
|
|
|
|
|
|
|
|
c = new QCheckBox (tr ("Honor global &limits"));
|
|
|
|
mySessionLimitCheck = c;
|
|
|
|
hig->addWideControl (c);
|
|
|
|
connect (c, SIGNAL (clicked (bool)), this, SLOT (onHonorsSessionLimitsToggled (bool)));
|
|
|
|
|
|
|
|
c = new QCheckBox (tr ("Limit &download speed (%1):").arg (speed_K_str));
|
|
|
|
mySingleDownCheck = c;
|
|
|
|
s = new QSpinBox ();
|
|
|
|
s->setProperty (PREF_KEY, TR_KEY_downloadLimit);
|
|
|
|
s->setSingleStep (5);
|
|
|
|
s->setRange (0, INT_MAX);
|
|
|
|
mySingleDownSpin = s;
|
|
|
|
hig->addRow (c, s);
|
|
|
|
enableWhenChecked (c, s);
|
|
|
|
connect (c, SIGNAL (clicked (bool)), this, SLOT (onDownloadLimitedToggled (bool)));
|
|
|
|
connect (s, SIGNAL (editingFinished ()), this, SLOT (onSpinBoxEditingFinished ()));
|
|
|
|
|
|
|
|
c = new QCheckBox (tr ("Limit &upload speed (%1):").arg (speed_K_str));
|
|
|
|
mySingleUpCheck = c;
|
|
|
|
s = new QSpinBox ();
|
|
|
|
s->setSingleStep (5);
|
|
|
|
s->setRange (0, INT_MAX);
|
|
|
|
s->setProperty (PREF_KEY, TR_KEY_uploadLimit);
|
|
|
|
mySingleUpSpin = s;
|
|
|
|
hig->addRow (c, s);
|
|
|
|
enableWhenChecked (c, s);
|
|
|
|
connect (c, SIGNAL (clicked (bool)), this, SLOT (onUploadLimitedToggled (bool)));
|
|
|
|
connect (s, SIGNAL (editingFinished ()), this, SLOT (onSpinBoxEditingFinished ()));
|
|
|
|
|
|
|
|
m = new QComboBox;
|
|
|
|
m->addItem (tr ("High"), TR_PRI_HIGH);
|
|
|
|
m->addItem (tr ("Normal"), TR_PRI_NORMAL);
|
|
|
|
m->addItem (tr ("Low"), TR_PRI_LOW);
|
|
|
|
connect (m, SIGNAL (currentIndexChanged (int)), this, SLOT (onBandwidthPriorityChanged (int)));
|
|
|
|
hig->addRow (tr ("Torrent &priority:"), m);
|
|
|
|
myBandwidthPriorityCombo = m;
|
|
|
|
|
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Seeding Limits"));
|
|
|
|
|
|
|
|
h = new QHBoxLayout ();
|
2014-12-12 23:05:10 +00:00
|
|
|
h->setSpacing (HIG::PAD);
|
2013-02-03 19:13:04 +00:00
|
|
|
m = new QComboBox;
|
|
|
|
m->addItem (tr ("Use Global Settings"), TR_RATIOLIMIT_GLOBAL);
|
|
|
|
m->addItem (tr ("Seed regardless of ratio"), TR_RATIOLIMIT_UNLIMITED);
|
|
|
|
m->addItem (tr ("Stop seeding at ratio:"), TR_RATIOLIMIT_SINGLE);
|
|
|
|
connect (m, SIGNAL (currentIndexChanged (int)), this, SLOT (onRatioModeChanged (int)));
|
|
|
|
h->addWidget (myRatioCombo = m);
|
|
|
|
ds = new QDoubleSpinBox ();
|
|
|
|
ds->setRange (0.5, INT_MAX);
|
|
|
|
ds->setProperty (PREF_KEY, TR_KEY_seedRatioLimit);
|
|
|
|
connect (ds, SIGNAL (editingFinished ()), this, SLOT (onSpinBoxEditingFinished ()));
|
|
|
|
h->addWidget (myRatioSpin = ds);
|
|
|
|
hig->addRow (tr ("&Ratio:"), h, m);
|
|
|
|
|
|
|
|
h = new QHBoxLayout ();
|
2014-12-12 23:05:10 +00:00
|
|
|
h->setSpacing (HIG::PAD);
|
2013-02-03 19:13:04 +00:00
|
|
|
m = new QComboBox;
|
|
|
|
m->addItem (tr ("Use Global Settings"), TR_IDLELIMIT_GLOBAL);
|
|
|
|
m->addItem (tr ("Seed regardless of activity"), TR_IDLELIMIT_UNLIMITED);
|
|
|
|
m->addItem (tr ("Stop seeding if idle for N minutes:"), TR_IDLELIMIT_SINGLE);
|
|
|
|
connect (m, SIGNAL (currentIndexChanged (int)), this, SLOT (onIdleModeChanged (int)));
|
|
|
|
h->addWidget (myIdleCombo = m);
|
|
|
|
s = new QSpinBox ();
|
|
|
|
s->setSingleStep (5);
|
|
|
|
s->setRange (1, 9999);
|
|
|
|
s->setProperty (PREF_KEY, TR_KEY_seedIdleLimit);
|
|
|
|
connect (s, SIGNAL (editingFinished ()), this, SLOT (onSpinBoxEditingFinished ()));
|
|
|
|
h->addWidget (myIdleSpin = s);
|
|
|
|
hig->addRow (tr ("&Idle:"), h, m);
|
|
|
|
|
|
|
|
|
|
|
|
hig->addSectionDivider ();
|
|
|
|
hig->addSectionTitle (tr ("Peer Connections"));
|
|
|
|
|
|
|
|
s = new QSpinBox ();
|
|
|
|
s->setSingleStep (5);
|
|
|
|
s->setRange (1, 300);
|
|
|
|
s->setProperty (PREF_KEY, TR_KEY_peer_limit);
|
|
|
|
connect (s, SIGNAL (editingFinished ()), this, SLOT (onSpinBoxEditingFinished ()));
|
|
|
|
myPeerLimitSpin = s;
|
|
|
|
hig->addRow (tr ("&Maximum peers:"), s);
|
|
|
|
|
|
|
|
hig->finish ();
|
|
|
|
|
|
|
|
return hig;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::createTrackerTab ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
QCheckBox * c;
|
|
|
|
QPushButton * p;
|
|
|
|
QWidget * top = new QWidget;
|
|
|
|
QVBoxLayout * v = new QVBoxLayout (top);
|
|
|
|
QHBoxLayout * h = new QHBoxLayout ();
|
|
|
|
QVBoxLayout * v2 = new QVBoxLayout ();
|
|
|
|
|
|
|
|
v->setSpacing (HIG::PAD_BIG);
|
|
|
|
v->setContentsMargins (HIG::PAD_BIG, HIG::PAD_BIG, HIG::PAD_BIG, HIG::PAD_BIG);
|
|
|
|
|
|
|
|
h->setSpacing (HIG::PAD);
|
|
|
|
h->setContentsMargins (HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL, HIG::PAD_SMALL);
|
|
|
|
|
|
|
|
v2->setSpacing (HIG::PAD);
|
|
|
|
|
|
|
|
myTrackerModel = new TrackerModel;
|
|
|
|
myTrackerFilter = new TrackerModelFilter;
|
|
|
|
myTrackerFilter->setSourceModel (myTrackerModel);
|
|
|
|
myTrackerView = new QTreeView;
|
|
|
|
myTrackerView->setModel (myTrackerFilter);
|
|
|
|
myTrackerView->setHeaderHidden (true);
|
|
|
|
myTrackerView->setSelectionMode (QTreeWidget::ExtendedSelection);
|
|
|
|
myTrackerView->setRootIsDecorated (false);
|
|
|
|
myTrackerView->setIndentation (2);
|
|
|
|
myTrackerView->setItemsExpandable (false);
|
|
|
|
myTrackerView->setAlternatingRowColors (true);
|
|
|
|
myTrackerView->setItemDelegate (myTrackerDelegate = new TrackerDelegate ());
|
2014-12-13 09:04:10 +00:00
|
|
|
connect (myTrackerView->selectionModel (), SIGNAL (selectionChanged (QItemSelection, QItemSelection)), this, SLOT (onTrackerSelectionChanged ()));
|
2013-02-03 19:13:04 +00:00
|
|
|
h->addWidget (myTrackerView, 1);
|
|
|
|
|
|
|
|
p = new QPushButton ();
|
|
|
|
p->setIcon (getStockIcon ("list-add", QStyle::SP_DialogOpenButton));
|
|
|
|
p->setToolTip (tr ("Add Tracker"));
|
|
|
|
myAddTrackerButton = p;
|
|
|
|
v2->addWidget (p, 1);
|
|
|
|
connect (p, SIGNAL (clicked (bool)), this, SLOT (onAddTrackerClicked ()));
|
|
|
|
|
|
|
|
p = new QPushButton ();
|
|
|
|
p->setIcon (getStockIcon ("document-properties", QStyle::SP_DesktopIcon));
|
|
|
|
p->setToolTip (tr ("Edit Tracker"));
|
|
|
|
myAddTrackerButton = p;
|
|
|
|
p->setEnabled (false);
|
|
|
|
myEditTrackerButton = p;
|
|
|
|
v2->addWidget (p, 1);
|
|
|
|
connect (p, SIGNAL (clicked (bool)), this, SLOT (onEditTrackerClicked ()));
|
|
|
|
|
|
|
|
p = new QPushButton ();
|
|
|
|
p->setIcon (getStockIcon ("list-remove", QStyle::SP_TrashIcon));
|
|
|
|
p->setToolTip (tr ("Remove Trackers"));
|
|
|
|
p->setEnabled (false);
|
|
|
|
myRemoveTrackerButton = p;
|
|
|
|
v2->addWidget (p, 1);
|
|
|
|
connect (p, SIGNAL (clicked (bool)), this, SLOT (onRemoveTrackerClicked ()));
|
|
|
|
|
|
|
|
v2->addStretch (1);
|
|
|
|
|
|
|
|
h->addLayout (v2, 1);
|
|
|
|
h->setStretch (1, 0);
|
|
|
|
|
|
|
|
v->addLayout (h, 1);
|
|
|
|
|
|
|
|
c = new QCheckBox (tr ("Show &more details"));
|
|
|
|
c->setChecked (myPrefs.getBool (Prefs::SHOW_TRACKER_SCRAPES));
|
|
|
|
myShowTrackerScrapesCheck = c;
|
|
|
|
v->addWidget (c, 1);
|
|
|
|
connect (c, SIGNAL (clicked (bool)), this, SLOT (onShowTrackerScrapesToggled (bool)));
|
|
|
|
|
|
|
|
c = new QCheckBox (tr ("Show &backup trackers"));
|
|
|
|
c->setChecked (myPrefs.getBool (Prefs::SHOW_BACKUP_TRACKERS));
|
|
|
|
myShowBackupTrackersCheck = c;
|
|
|
|
v->addWidget (c, 1);
|
|
|
|
connect (c, SIGNAL (clicked (bool)), this, SLOT (onShowBackupTrackersToggled (bool)));
|
|
|
|
|
|
|
|
return top;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::createPeersTab ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
QWidget * top = new QWidget;
|
|
|
|
QVBoxLayout * v = new QVBoxLayout (top);
|
2014-12-12 23:05:10 +00:00
|
|
|
v->setSpacing (HIG::PAD_BIG);
|
2013-02-03 19:13:04 +00:00
|
|
|
v->setContentsMargins (HIG::PAD_BIG, HIG::PAD_BIG, HIG::PAD_BIG, HIG::PAD_BIG);
|
|
|
|
|
|
|
|
QStringList headers;
|
|
|
|
headers << QString () << tr ("Up") << tr ("Down") << tr ("%") << tr ("Status") << tr ("Address") << tr ("Client");
|
|
|
|
myPeerTree = new QTreeWidget;
|
|
|
|
myPeerTree->setUniformRowHeights (true);
|
|
|
|
myPeerTree->setHeaderLabels (headers);
|
|
|
|
myPeerTree->setColumnWidth (0, 20);
|
|
|
|
myPeerTree->setSortingEnabled (true);
|
|
|
|
myPeerTree->sortByColumn (COL_ADDRESS, Qt::AscendingOrder);
|
|
|
|
myPeerTree->setRootIsDecorated (false);
|
|
|
|
myPeerTree->setTextElideMode (Qt::ElideRight);
|
|
|
|
v->addWidget (myPeerTree, 1);
|
|
|
|
|
|
|
|
const QFontMetrics m (font ());
|
|
|
|
QSize size = m.size (0, "1024 MiB/s");
|
|
|
|
myPeerTree->setColumnWidth (COL_UP, size.width ());
|
|
|
|
myPeerTree->setColumnWidth (COL_DOWN, size.width ());
|
|
|
|
size = m.size (0, " 100% ");
|
|
|
|
myPeerTree->setColumnWidth (COL_PERCENT, size.width ());
|
|
|
|
size = m.size (0, "ODUK?EXI");
|
|
|
|
myPeerTree->setColumnWidth (COL_STATUS, size.width ());
|
|
|
|
size = m.size (0, "888.888.888.888");
|
|
|
|
myPeerTree->setColumnWidth (COL_ADDRESS, size.width ());
|
|
|
|
size = m.size (0, "Some BitTorrent Client");
|
|
|
|
myPeerTree->setColumnWidth (COL_CLIENT, size.width ());
|
|
|
|
myPeerTree->setAlternatingRowColors (true);
|
|
|
|
|
|
|
|
return top;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
QWidget *
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::createFilesTab ()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2013-02-03 19:13:04 +00:00
|
|
|
myFileTreeView = new FileTreeView ();
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2014-12-13 09:04:10 +00:00
|
|
|
connect (myFileTreeView, SIGNAL ( priorityChanged (QSet<int>, int)),
|
|
|
|
this, SLOT ( onFilePriorityChanged (QSet<int>, int)));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2014-12-13 09:04:10 +00:00
|
|
|
connect (myFileTreeView, SIGNAL ( wantedChanged (QSet<int>, bool)),
|
|
|
|
this, SLOT ( onFileWantedChanged (QSet<int>, bool)));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2014-12-13 09:04:10 +00:00
|
|
|
connect (myFileTreeView, SIGNAL (pathEdited (QString, QString)),
|
|
|
|
this, SLOT (onPathEdited (QString, QString)));
|
2013-01-20 01:31:58 +00:00
|
|
|
|
2014-12-13 09:04:10 +00:00
|
|
|
connect (myFileTreeView, SIGNAL (openRequested (QString)),
|
|
|
|
this, SLOT (onOpenRequested (QString)));
|
2013-09-08 19:03:25 +00:00
|
|
|
|
2013-02-03 19:13:04 +00:00
|
|
|
return myFileTreeView;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onFilePriorityChanged (const QSet<int>& indices, int priority)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
tr_quark key;
|
|
|
|
|
|
|
|
switch (priority)
|
|
|
|
{
|
|
|
|
case TR_PRI_LOW:
|
|
|
|
key = TR_KEY_priority_low;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_PRI_HIGH:
|
|
|
|
key = TR_KEY_priority_high;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
key = TR_KEY_priority_normal;
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2013-01-26 01:19:54 +00:00
|
|
|
mySession.torrentSet (myIds, key, indices.toList ());
|
2013-02-03 19:13:04 +00:00
|
|
|
getNewData ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onFileWantedChanged (const QSet<int>& indices, bool wanted)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
const tr_quark key = wanted ? TR_KEY_files_wanted : TR_KEY_files_unwanted;
|
2013-01-26 01:19:54 +00:00
|
|
|
mySession.torrentSet (myIds, key, indices.toList ());
|
2012-12-22 20:35:19 +00:00
|
|
|
getNewData ();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-01-20 01:31:58 +00:00
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onPathEdited (const QString& oldpath, const QString& newname)
|
2013-01-20 01:31:58 +00:00
|
|
|
{
|
|
|
|
mySession.torrentRenamePath (myIds, oldpath, newname);
|
|
|
|
}
|
2013-09-08 19:03:25 +00:00
|
|
|
|
|
|
|
void
|
2014-12-12 23:05:10 +00:00
|
|
|
Details::onOpenRequested (const QString& path)
|
2013-09-08 19:03:25 +00:00
|
|
|
{
|
|
|
|
if (!mySession.isLocal ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
foreach (const int id, myIds)
|
|
|
|
{
|
|
|
|
const Torrent * const tor = myModel.getTorrentFromId (id);
|
|
|
|
if (tor == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const QString localFilePath = tor->getPath () + "/" + path;
|
|
|
|
if (!QFile::exists (localFilePath))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (QDesktopServices::openUrl (QUrl::fromLocalFile (localFilePath)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|