2010-11-14 22:32:29 +03:00
|
|
|
/*
|
2015-06-07 15:03:30 +03:00
|
|
|
* Bittorrent Client using Qt and libtorrent.
|
|
|
|
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
|
|
|
|
* Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
|
2010-11-14 22:32:29 +03:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2010-11-14 18:28:22 +03:00
|
|
|
#include <QDebug>
|
2015-04-12 16:23:06 +03:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QPalette>
|
2015-04-19 18:17:47 +03:00
|
|
|
#include <QIcon>
|
2010-11-14 18:28:22 +03:00
|
|
|
|
2015-04-19 18:17:47 +03:00
|
|
|
#include "core/bittorrent/session.h"
|
2015-06-07 15:03:30 +03:00
|
|
|
#include "core/bittorrent/torrenthandle.h"
|
2015-04-19 18:17:47 +03:00
|
|
|
#include "core/torrentfilter.h"
|
2015-05-06 14:53:27 +03:00
|
|
|
#include "core/utils/fs.h"
|
2015-04-19 18:17:47 +03:00
|
|
|
#include "torrentmodel.h"
|
2010-11-14 18:28:22 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon getIconByState(BitTorrent::TorrentState state);
|
|
|
|
static QColor getColorByState(BitTorrent::TorrentState state);
|
2014-05-11 15:29:06 +04:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon getPausedIcon();
|
|
|
|
static QIcon getQueuedIcon();
|
|
|
|
static QIcon getDownloadingIcon();
|
|
|
|
static QIcon getStalledDownloadingIcon();
|
|
|
|
static QIcon getUploadingIcon();
|
|
|
|
static QIcon getStalledUploadingIcon();
|
|
|
|
static QIcon getCompletedIcon();
|
|
|
|
static QIcon getCheckingIcon();
|
|
|
|
static QIcon getErrorIcon();
|
2014-05-11 15:29:06 +04:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
static bool isDarkTheme();
|
2014-05-11 15:29:06 +04:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
// TorrentModel
|
2014-05-11 15:29:06 +04:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
TorrentModel::TorrentModel(QObject *parent)
|
|
|
|
: QAbstractListModel(parent)
|
|
|
|
{
|
|
|
|
// Load the torrents
|
|
|
|
foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents())
|
|
|
|
addTorrent(torrent);
|
2014-05-11 15:29:06 +04:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
// Listen for torrent changes
|
|
|
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentAdded(BitTorrent::TorrentHandle *const)), SLOT(addTorrent(BitTorrent::TorrentHandle *const)));
|
|
|
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentAboutToBeRemoved(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const)));
|
|
|
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentStatusUpdated(BitTorrent::TorrentHandle *const)), this, SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
2015-04-12 16:23:06 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentFinished(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
|
|
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentMetadataLoaded(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
|
|
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentResumed(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
|
|
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentPaused(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
|
|
|
connect(BitTorrent::Session::instance(), SIGNAL(torrentFinishedChecking(BitTorrent::TorrentHandle *const)), SLOT(handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const)));
|
2014-05-11 15:29:06 +04:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
int TorrentModel::rowCount(const QModelIndex &index) const
|
2015-03-28 22:09:13 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
Q_UNUSED(index);
|
|
|
|
return m_torrents.size();
|
2015-03-28 22:09:13 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
int TorrentModel::columnCount(const QModelIndex &parent) const
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
Q_UNUSED(parent);
|
|
|
|
return NB_COLUMNS;
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QVariant TorrentModel::headerData(int section, Qt::Orientation orientation, int role) const
|
2015-04-19 18:17:47 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
if (orientation == Qt::Horizontal) {
|
|
|
|
if (role == Qt::DisplayRole) {
|
|
|
|
switch(section) {
|
|
|
|
case TR_PRIORITY: return "#";
|
|
|
|
case TR_NAME: return tr("Name", "i.e: torrent name");
|
|
|
|
case TR_SIZE: return tr("Size", "i.e: torrent size");
|
|
|
|
case TR_PROGRESS: return tr("Done", "% Done");
|
|
|
|
case TR_STATUS: return tr("Status", "Torrent status (e.g. downloading, seeding, paused)");
|
|
|
|
case TR_SEEDS: return tr("Seeds", "i.e. full sources (often untranslated)");
|
|
|
|
case TR_PEERS: return tr("Peers", "i.e. partial sources (often untranslated)");
|
|
|
|
case TR_DLSPEED: return tr("Down Speed", "i.e: Download speed");
|
|
|
|
case TR_UPSPEED: return tr("Up Speed", "i.e: Upload speed");
|
|
|
|
case TR_RATIO: return tr("Ratio", "Share ratio");
|
|
|
|
case TR_ETA: return tr("ETA", "i.e: Estimated Time of Arrival / Time left");
|
|
|
|
case TR_LABEL: return tr("Label");
|
|
|
|
case TR_ADD_DATE: return tr("Added On", "Torrent was added to transfer list on 01/01/2010 08:00");
|
|
|
|
case TR_SEED_DATE: return tr("Completed On", "Torrent was completed on 01/01/2010 08:00");
|
|
|
|
case TR_TRACKER: return tr("Tracker");
|
|
|
|
case TR_DLLIMIT: return tr("Down Limit", "i.e: Download limit");
|
|
|
|
case TR_UPLIMIT: return tr("Up Limit", "i.e: Upload limit");
|
|
|
|
case TR_AMOUNT_DOWNLOADED: return tr("Downloaded", "Amount of data downloaded (e.g. in MB)");
|
|
|
|
case TR_AMOUNT_UPLOADED: return tr("Uploaded", "Amount of data uploaded (e.g. in MB)");
|
|
|
|
case TR_AMOUNT_DOWNLOADED_SESSION: return tr("Session Download", "Amount of data downloaded since program open (e.g. in MB)");
|
|
|
|
case TR_AMOUNT_UPLOADED_SESSION: return tr("Session Upload", "Amount of data uploaded since program open (e.g. in MB)");
|
|
|
|
case TR_AMOUNT_LEFT: return tr("Remaining", "Amount of data left to download (e.g. in MB)");
|
|
|
|
case TR_TIME_ELAPSED: return tr("Time Active", "Time (duration) the torrent is active (not paused)");
|
|
|
|
case TR_SAVE_PATH: return tr("Save path", "Torrent save path");
|
|
|
|
case TR_COMPLETED: return tr("Completed", "Amount of data completed (e.g. in MB)");
|
|
|
|
case TR_RATIO_LIMIT: return tr("Ratio Limit", "Upload share ratio limit");
|
|
|
|
case TR_SEEN_COMPLETE_DATE: return tr("Last Seen Complete", "Indicates the time when the torrent was last seen complete/whole");
|
|
|
|
case TR_LAST_ACTIVITY: return tr("Last Activity", "Time passed since a chunk was downloaded/uploaded");
|
|
|
|
case TR_TOTAL_SIZE: return tr("Total Size", "i.e. Size including unwanted data");
|
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (role == Qt::TextAlignmentRole) {
|
|
|
|
switch(section) {
|
|
|
|
case TR_AMOUNT_DOWNLOADED:
|
|
|
|
case TR_AMOUNT_UPLOADED:
|
|
|
|
case TR_AMOUNT_DOWNLOADED_SESSION:
|
|
|
|
case TR_AMOUNT_UPLOADED_SESSION:
|
|
|
|
case TR_AMOUNT_LEFT:
|
|
|
|
case TR_COMPLETED:
|
|
|
|
case TR_SIZE:
|
|
|
|
case TR_TOTAL_SIZE:
|
|
|
|
case TR_ETA:
|
|
|
|
case TR_SEEDS:
|
|
|
|
case TR_PEERS:
|
|
|
|
case TR_UPSPEED:
|
|
|
|
case TR_DLSPEED:
|
|
|
|
case TR_UPLIMIT:
|
|
|
|
case TR_DLLIMIT:
|
|
|
|
case TR_RATIO_LIMIT:
|
|
|
|
case TR_RATIO:
|
|
|
|
case TR_PRIORITY:
|
|
|
|
case TR_LAST_ACTIVITY:
|
|
|
|
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
|
|
|
default:
|
|
|
|
return QAbstractListModel::headerData(section, orientation, role);
|
|
|
|
}
|
|
|
|
}
|
2015-02-25 12:48:40 +03:00
|
|
|
}
|
2014-10-25 14:12:05 +04:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
return QVariant();
|
2014-10-25 14:12:05 +04:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QVariant TorrentModel::data(const QModelIndex &index, int role) const
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
if (!index.isValid()) return QVariant();
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
BitTorrent::TorrentHandle *const torrent = m_torrents.value(index.row());
|
|
|
|
if (!torrent) return QVariant();
|
2010-11-14 18:28:22 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
if ((role == Qt::DecorationRole) && (index.column() == TR_NAME))
|
|
|
|
return getIconByState(torrent->state());
|
2015-04-19 18:17:47 +03:00
|
|
|
|
|
|
|
if (role == Qt::ForegroundRole)
|
2015-06-07 15:03:30 +03:00
|
|
|
return getColorByState(torrent->state());
|
2015-04-19 18:17:47 +03:00
|
|
|
|
|
|
|
if ((role != Qt::DisplayRole) && (role != Qt::UserRole))
|
|
|
|
return QVariant();
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
switch(index.column()) {
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_NAME:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->name();
|
2015-04-19 18:17:47 +03:00
|
|
|
case TR_PRIORITY:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->queuePosition();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_SIZE:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->wantedSize();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_PROGRESS:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->progress();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_STATUS:
|
2015-06-07 15:03:30 +03:00
|
|
|
return static_cast<int>(torrent->state());
|
2015-04-19 18:17:47 +03:00
|
|
|
case TR_SEEDS:
|
2015-06-07 15:03:30 +03:00
|
|
|
return (role == Qt::DisplayRole) ? torrent->seedsCount() : torrent->completeCount();
|
2015-04-19 18:17:47 +03:00
|
|
|
case TR_PEERS:
|
2015-06-07 15:03:30 +03:00
|
|
|
return (role == Qt::DisplayRole) ? (torrent->peersCount() - torrent->seedsCount()) : torrent->incompleteCount();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_DLSPEED:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->downloadPayloadRate();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_UPSPEED:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->uploadPayloadRate();
|
2015-04-19 18:17:47 +03:00
|
|
|
case TR_ETA:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->eta();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_RATIO:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->realRatio();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_LABEL:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->label();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_ADD_DATE:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->addedTime();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_SEED_DATE:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->completedTime();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_TRACKER:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->currentTracker();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_DLLIMIT:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->downloadLimit();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_UPLIMIT:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->uploadLimit();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_AMOUNT_DOWNLOADED:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->totalDownload();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_AMOUNT_UPLOADED:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->totalUpload();
|
2015-03-16 17:41:39 +03:00
|
|
|
case TR_AMOUNT_DOWNLOADED_SESSION:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->totalPayloadDownload();
|
2015-03-16 17:41:39 +03:00
|
|
|
case TR_AMOUNT_UPLOADED_SESSION:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->totalPayloadUpload();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_AMOUNT_LEFT:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->incompletedSize();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_TIME_ELAPSED:
|
2015-06-07 15:03:30 +03:00
|
|
|
return (role == Qt::DisplayRole) ? torrent->activeTime() : torrent->seedingTime();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_SAVE_PATH:
|
2015-07-19 13:07:36 +03:00
|
|
|
return torrent->rootPath();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_COMPLETED:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->completedSize();
|
2015-04-19 18:17:47 +03:00
|
|
|
case TR_RATIO_LIMIT:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->maxRatio();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_SEEN_COMPLETE_DATE:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->lastSeenComplete();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_LAST_ACTIVITY:
|
2015-06-07 15:03:30 +03:00
|
|
|
if (torrent->isPaused() || torrent->isChecking())
|
2015-02-25 12:48:40 +03:00
|
|
|
return -1;
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->timeSinceActivity();
|
2015-02-25 12:48:40 +03:00
|
|
|
case TR_TOTAL_SIZE:
|
2015-06-07 15:03:30 +03:00
|
|
|
return torrent->totalSize();
|
2015-02-25 12:48:40 +03:00
|
|
|
default:
|
|
|
|
return QVariant();
|
|
|
|
}
|
2010-11-14 18:28:22 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
return QVariant();
|
2015-03-22 02:18:21 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
bool TorrentModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
qDebug() << Q_FUNC_INFO << value;
|
|
|
|
if (!index.isValid() || (role != Qt::DisplayRole)) return false;
|
2010-11-14 18:28:22 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
qDebug("Index is valid and role is DisplayRole");
|
|
|
|
BitTorrent::TorrentHandle *const torrent = m_torrents.value(index.row());
|
|
|
|
if (!torrent) return false;
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
// Label, seed date and Name columns can be edited
|
|
|
|
switch(index.column()) {
|
|
|
|
case TR_NAME:
|
|
|
|
torrent->setName(value.toString());
|
|
|
|
break;
|
|
|
|
case TR_LABEL:
|
|
|
|
torrent->setLabel(value.toString());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
return true;
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
void TorrentModel::addTorrent(BitTorrent::TorrentHandle *const torrent)
|
|
|
|
{
|
|
|
|
if (m_torrents.indexOf(torrent) == -1) {
|
|
|
|
const int row = m_torrents.size();
|
|
|
|
beginInsertRows(QModelIndex(), row, row);
|
|
|
|
m_torrents << torrent;
|
|
|
|
endInsertRows();
|
|
|
|
}
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
Qt::ItemFlags TorrentModel::flags(const QModelIndex &index) const
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
if (!index.isValid()) return 0;
|
2010-11-14 18:28:22 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
// Explicitly mark as editable
|
|
|
|
return QAbstractListModel::flags(index) | Qt::ItemIsEditable;
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
BitTorrent::TorrentHandle *TorrentModel::torrentHandle(const QModelIndex &index) const
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
if (!index.isValid()) return 0;
|
2015-04-19 18:17:47 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
return m_torrents.value(index.row());
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
void TorrentModel::handleTorrentAboutToBeRemoved(BitTorrent::TorrentHandle *const torrent)
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
const int row = m_torrents.indexOf(torrent);
|
|
|
|
if (row >= 0) {
|
|
|
|
beginRemoveRows(QModelIndex(), row, row);
|
|
|
|
m_torrents.removeAt(row);
|
|
|
|
endRemoveRows();
|
2015-04-19 18:17:47 +03:00
|
|
|
}
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
void TorrentModel::handleTorrentStatusUpdated(BitTorrent::TorrentHandle *const torrent)
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
const int row = m_torrents.indexOf(torrent);
|
|
|
|
if (row >= 0)
|
|
|
|
emit dataChanged(index(row, 0), index(row, columnCount() - 1));
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
// Static functions
|
|
|
|
|
|
|
|
QIcon getIconByState(BitTorrent::TorrentState state)
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
switch (state) {
|
|
|
|
case BitTorrent::TorrentState::Downloading:
|
|
|
|
case BitTorrent::TorrentState::ForcedDownloading:
|
|
|
|
case BitTorrent::TorrentState::DownloadingMetadata:
|
|
|
|
return getDownloadingIcon();
|
|
|
|
case BitTorrent::TorrentState::Allocating:
|
|
|
|
case BitTorrent::TorrentState::StalledDownloading:
|
|
|
|
return getStalledDownloadingIcon();
|
|
|
|
case BitTorrent::TorrentState::StalledUploading:
|
|
|
|
return getStalledUploadingIcon();
|
|
|
|
case BitTorrent::TorrentState::Uploading:
|
|
|
|
case BitTorrent::TorrentState::ForcedUploading:
|
|
|
|
return getUploadingIcon();
|
|
|
|
case BitTorrent::TorrentState::PausedDownloading:
|
|
|
|
return getPausedIcon();
|
|
|
|
case BitTorrent::TorrentState::PausedUploading:
|
|
|
|
return getCompletedIcon();
|
|
|
|
case BitTorrent::TorrentState::QueuedDownloading:
|
|
|
|
case BitTorrent::TorrentState::QueuedUploading:
|
|
|
|
return getQueuedIcon();
|
|
|
|
case BitTorrent::TorrentState::CheckingDownloading:
|
|
|
|
case BitTorrent::TorrentState::CheckingUploading:
|
2015-06-30 11:03:46 +03:00
|
|
|
case BitTorrent::TorrentState::QueuedForChecking:
|
|
|
|
case BitTorrent::TorrentState::CheckingResumeData:
|
2015-06-07 15:03:30 +03:00
|
|
|
return getCheckingIcon();
|
|
|
|
case BitTorrent::TorrentState::Unknown:
|
|
|
|
case BitTorrent::TorrentState::Error:
|
|
|
|
return getErrorIcon();
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
|
|
|
return getErrorIcon();
|
2015-02-25 12:48:40 +03:00
|
|
|
}
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QColor getColorByState(BitTorrent::TorrentState state)
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
bool dark = isDarkTheme();
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case BitTorrent::TorrentState::Downloading:
|
|
|
|
case BitTorrent::TorrentState::ForcedDownloading:
|
|
|
|
case BitTorrent::TorrentState::DownloadingMetadata:
|
|
|
|
return QColor(34, 139, 34); // Forest Green
|
|
|
|
case BitTorrent::TorrentState::Allocating:
|
|
|
|
case BitTorrent::TorrentState::StalledDownloading:
|
|
|
|
case BitTorrent::TorrentState::StalledUploading:
|
|
|
|
if (!dark)
|
|
|
|
return QColor(0, 0, 0); // Black
|
|
|
|
else
|
|
|
|
return QColor(255, 255, 255); // White
|
|
|
|
case BitTorrent::TorrentState::Uploading:
|
|
|
|
case BitTorrent::TorrentState::ForcedUploading:
|
|
|
|
if (!dark)
|
|
|
|
return QColor(65, 105, 225); // Royal Blue
|
|
|
|
else
|
|
|
|
return QColor(100, 149, 237); // Cornflower Blue
|
|
|
|
case BitTorrent::TorrentState::PausedDownloading:
|
|
|
|
return QColor(250, 128, 114); // Salmon
|
|
|
|
case BitTorrent::TorrentState::PausedUploading:
|
|
|
|
if (!dark)
|
|
|
|
return QColor(0, 0, 139); // Dark Blue
|
|
|
|
else
|
|
|
|
return QColor(65, 105, 225); // Royal Blue
|
|
|
|
case BitTorrent::TorrentState::Error:
|
|
|
|
return QColor(255, 0, 0); // red
|
|
|
|
case BitTorrent::TorrentState::QueuedDownloading:
|
|
|
|
case BitTorrent::TorrentState::QueuedUploading:
|
|
|
|
case BitTorrent::TorrentState::CheckingDownloading:
|
|
|
|
case BitTorrent::TorrentState::CheckingUploading:
|
2015-06-30 11:03:46 +03:00
|
|
|
case BitTorrent::TorrentState::QueuedForChecking:
|
|
|
|
case BitTorrent::TorrentState::CheckingResumeData:
|
2015-06-07 15:03:30 +03:00
|
|
|
return QColor(0, 128, 128); // Teal
|
|
|
|
case BitTorrent::TorrentState::Unknown:
|
|
|
|
return QColor(255, 0, 0); // red
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
|
|
|
return QColor(255, 0, 0); // red
|
|
|
|
}
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QIcon getPausedIcon()
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon cached = QIcon(":/icons/skin/paused.png");
|
|
|
|
return cached;
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QIcon getQueuedIcon()
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon cached = QIcon(":/icons/skin/queued.png");
|
|
|
|
return cached;
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QIcon getDownloadingIcon()
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon cached = QIcon(":/icons/skin/downloading.png");
|
|
|
|
return cached;
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QIcon getStalledDownloadingIcon()
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon cached = QIcon(":/icons/skin/stalledDL.png");
|
|
|
|
return cached;
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QIcon getUploadingIcon()
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon cached = QIcon(":/icons/skin/uploading.png");
|
|
|
|
return cached;
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QIcon getStalledUploadingIcon()
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon cached = QIcon(":/icons/skin/stalledUP.png");
|
|
|
|
return cached;
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QIcon getCompletedIcon()
|
2010-11-14 18:28:22 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon cached = QIcon(":/icons/skin/completed.png");
|
|
|
|
return cached;
|
2010-11-14 18:28:22 +03:00
|
|
|
}
|
2010-11-14 21:46:16 +03:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QIcon getCheckingIcon()
|
2015-04-19 18:17:47 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon cached = QIcon(":/icons/skin/checking.png");
|
|
|
|
return cached;
|
2015-04-19 18:17:47 +03:00
|
|
|
}
|
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
QIcon getErrorIcon()
|
2010-11-14 21:46:16 +03:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
static QIcon cached = QIcon(":/icons/skin/error.png");
|
|
|
|
return cached;
|
2010-11-14 21:46:16 +03:00
|
|
|
}
|
2013-11-16 21:29:50 +04:00
|
|
|
|
2015-06-07 15:03:30 +03:00
|
|
|
bool isDarkTheme()
|
2013-11-16 21:29:50 +04:00
|
|
|
{
|
2015-06-07 15:03:30 +03:00
|
|
|
QPalette pal = QApplication::palette();
|
|
|
|
// QPalette::Base is used for the background of the Treeview
|
|
|
|
QColor color = pal.color(QPalette::Active, QPalette::Base);
|
|
|
|
return (color.lightness() < 127);
|
2013-11-16 21:29:50 +04:00
|
|
|
}
|