Some work about adaptive color scheme for Web UI (PR #19901)
http://[316:c51a:62a3:8b9::4]/d4708/qBittorrent/src/branch/adaptive-webui
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1004 lines
40 KiB
1004 lines
40 KiB
15 years ago
|
/*
|
||
|
* 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
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include "transferlistwidget.h"
|
||
15 years ago
|
#include "bittorrent.h"
|
||
15 years ago
|
#include "torrentpersistentdata.h"
|
||
|
#include "transferlistdelegate.h"
|
||
|
#include "previewselect.h"
|
||
15 years ago
|
#include "speedlimitdlg.h"
|
||
15 years ago
|
#include "options_imp.h"
|
||
15 years ago
|
#include "deletionconfirmationdlg.h"
|
||
15 years ago
|
#include <QStandardItemModel>
|
||
|
#include <QSortFilterProxyModel>
|
||
|
#include <QDesktopServices>
|
||
15 years ago
|
#include <QTimer>
|
||
15 years ago
|
#include <QSettings>
|
||
|
#include <QClipboard>
|
||
|
#include <QColor>
|
||
|
#include <QUrl>
|
||
|
#include <QMenu>
|
||
15 years ago
|
#include <QRegExp>
|
||
15 years ago
|
#include <vector>
|
||
|
|
||
|
TransferListWidget::TransferListWidget(QWidget *parent, bittorrent *_BTSession): QTreeView(parent) {
|
||
|
QSettings settings("qBittorrent", "qBittorrent");
|
||
|
BTSession = _BTSession;
|
||
|
|
||
|
// Create and apply delegate
|
||
|
listDelegate = new TransferListDelegate(this);
|
||
|
setItemDelegate(listDelegate);
|
||
|
|
||
|
// Create transfer list model
|
||
15 years ago
|
listModel = new QStandardItemModel(0,12);
|
||
|
listModel->setHeaderData(NAME, Qt::Horizontal, tr("Name", "i.e: torrent name"));
|
||
|
listModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size", "i.e: torrent size"));
|
||
15 years ago
|
listModel->horizontalHeaderItem(SIZE)->setTextAlignment(Qt::AlignRight);
|
||
15 years ago
|
listModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Done", "% Done"));
|
||
15 years ago
|
listModel->horizontalHeaderItem(PROGRESS)->setTextAlignment(Qt::AlignHCenter);
|
||
15 years ago
|
listModel->setHeaderData(STATUS, Qt::Horizontal, tr("Status", "Torrent status (e.g. downloading, seeding, paused)"));
|
||
|
listModel->setHeaderData(SEEDS, Qt::Horizontal, tr("Seeds", "i.e. full sources (often untranslated)"));
|
||
15 years ago
|
listModel->horizontalHeaderItem(SEEDS)->setTextAlignment(Qt::AlignRight);
|
||
15 years ago
|
listModel->setHeaderData(PEERS, Qt::Horizontal, tr("Peers", "i.e. partial sources (often untranslated)"));
|
||
15 years ago
|
listModel->horizontalHeaderItem(PEERS)->setTextAlignment(Qt::AlignRight);
|
||
15 years ago
|
listModel->setHeaderData(DLSPEED, Qt::Horizontal, tr("Down Speed", "i.e: Download speed"));
|
||
15 years ago
|
listModel->horizontalHeaderItem(DLSPEED)->setTextAlignment(Qt::AlignRight);
|
||
15 years ago
|
listModel->setHeaderData(UPSPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));;
|
||
15 years ago
|
listModel->horizontalHeaderItem(UPSPEED)->setTextAlignment(Qt::AlignRight);
|
||
15 years ago
|
listModel->setHeaderData(RATIO, Qt::Horizontal, tr("Ratio", "Share ratio"));
|
||
15 years ago
|
listModel->horizontalHeaderItem(RATIO)->setTextAlignment(Qt::AlignRight);
|
||
15 years ago
|
listModel->setHeaderData(ETA, Qt::Horizontal, tr("ETA", "i.e: Estimated Time of Arrival / Time left"));
|
||
|
listModel->setHeaderData(PRIORITY, Qt::Horizontal, "#");
|
||
15 years ago
|
listModel->horizontalHeaderItem(PRIORITY)->setTextAlignment(Qt::AlignRight);
|
||
15 years ago
|
|
||
|
// Set Sort/Filter proxy
|
||
|
proxyModel = new QSortFilterProxyModel();
|
||
|
proxyModel->setDynamicSortFilter(true);
|
||
|
proxyModel->setSourceModel(listModel);
|
||
15 years ago
|
proxyModel->setFilterKeyColumn(STATUS);
|
||
|
proxyModel->setFilterRole(Qt::DisplayRole);
|
||
15 years ago
|
setModel(proxyModel);
|
||
|
|
||
|
// Visual settings
|
||
|
setRootIsDecorated(false);
|
||
|
setAllColumnsShowFocus(true);
|
||
|
setSortingEnabled(true);
|
||
15 years ago
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||
|
setItemsExpandable(false);
|
||
|
setAutoScroll(true);
|
||
|
|
||
15 years ago
|
hideColumn(PRIORITY);
|
||
|
hideColumn(HASH);
|
||
|
loadHiddenColumns();
|
||
15 years ago
|
// Load last columns width for transfer list
|
||
|
if(!loadColWidthList()) {
|
||
|
header()->resizeSection(0, 200);
|
||
|
}
|
||
|
loadLastSortedColumn();
|
||
15 years ago
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
||
|
|
||
|
// Listen for BTSession events
|
||
|
connect(BTSession, SIGNAL(addedTorrent(QTorrentHandle&)), this, SLOT(addTorrent(QTorrentHandle&)));
|
||
|
connect(BTSession, SIGNAL(finishedTorrent(QTorrentHandle&)), this, SLOT(setFinished(QTorrentHandle&)));
|
||
15 years ago
|
connect(BTSession, SIGNAL(metadataReceived(QTorrentHandle&)), this, SLOT(updateMetadata(QTorrentHandle&)));
|
||
15 years ago
|
connect(BTSession, SIGNAL(pausedTorrent(QTorrentHandle&)), this, SLOT(pauseTorrent(QTorrentHandle&)));
|
||
|
connect(BTSession, SIGNAL(resumedTorrent(QTorrentHandle&)), this, SLOT(resumeTorrent(QTorrentHandle&)));
|
||
15 years ago
|
|
||
|
// Listen for list events
|
||
|
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(torrentDoubleClicked(QModelIndex)));
|
||
15 years ago
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayListMenu(const QPoint&)));
|
||
15 years ago
|
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||
15 years ago
|
connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&)));
|
||
|
|
||
|
// Refresh timer
|
||
15 years ago
|
refreshTimer = new QTimer();
|
||
|
refreshTimer->start(settings.value("Preferences/General/RefreshInterval", 1500).toInt());
|
||
|
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refreshList()));
|
||
15 years ago
|
}
|
||
|
|
||
|
TransferListWidget::~TransferListWidget() {
|
||
15 years ago
|
// Save settings
|
||
|
saveLastSortedColumn();
|
||
|
saveColWidthList();
|
||
15 years ago
|
saveHiddenColumns();
|
||
15 years ago
|
// Clean up
|
||
15 years ago
|
delete refreshTimer;
|
||
|
delete proxyModel;
|
||
|
delete listModel;
|
||
|
delete listDelegate;
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::addTorrent(QTorrentHandle& h) {
|
||
|
if(!h.is_valid()) return;
|
||
|
int row = listModel->rowCount();
|
||
|
try {
|
||
|
// Adding torrent to transfer list
|
||
|
listModel->insertRow(row);
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(h.name()));
|
||
|
listModel->setData(listModel->index(row, SIZE), QVariant((qlonglong)h.actual_size()));
|
||
15 years ago
|
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
|
||
15 years ago
|
listModel->setData(listModel->index(row, SEEDS), QVariant((double)0.0));
|
||
|
listModel->setData(listModel->index(row, PEERS), QVariant((double)0.0));
|
||
|
if(BTSession->isQueueingEnabled())
|
||
15 years ago
|
listModel->setData(listModel->index(row, PRIORITY), QVariant((int)h.queue_position()));
|
||
15 years ago
|
listModel->setData(listModel->index(row, HASH), QVariant(h.hash()));
|
||
|
// Pause torrent if it is
|
||
|
if(h.is_paused()) {
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/paused.png"))), Qt::DecorationRole);
|
||
15 years ago
|
listModel->setData(listModel->index(row, STATUS), STATE_PAUSED);
|
||
15 years ago
|
//setRowColor(row, QString::fromUtf8("red"));
|
||
|
}else{
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalled.png"))), Qt::DecorationRole);
|
||
15 years ago
|
listModel->setData(listModel->index(row, STATUS), STATE_STALLED);
|
||
15 years ago
|
//setRowColor(row, QString::fromUtf8("grey"));
|
||
|
}
|
||
15 years ago
|
// Select first torrent to be added
|
||
|
if(listModel->rowCount() == 1)
|
||
|
selectionModel()->setCurrentIndex(proxyModel->index(row, NAME), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows);
|
||
15 years ago
|
refreshList();
|
||
15 years ago
|
} catch(invalid_handle e) {
|
||
|
// Remove added torrent
|
||
|
listModel->removeRow(row);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*void TransferListWidget::setRowColor(int row, QColor color) {
|
||
15 years ago
|
unsigned int nbColumns = listModel->columnCount()-1;
|
||
15 years ago
|
for(unsigned int i=0; i<nbColumns; ++i) {
|
||
|
listModel->setData(listModel->index(row, i), QVariant(color), Qt::ForegroundRole);
|
||
|
}
|
||
|
}*/
|
||
|
|
||
15 years ago
|
void TransferListWidget::deleteTorrent(int row, bool refresh_list) {
|
||
15 years ago
|
listModel->removeRow(row);
|
||
15 years ago
|
if(refresh_list)
|
||
|
refreshList();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
// Wrapper slot for bittorrent signal
|
||
|
void TransferListWidget::pauseTorrent(QTorrentHandle &h) {
|
||
|
pauseTorrent(getRowFromHash(h.hash()));
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void TransferListWidget::pauseTorrent(int row, bool refresh_list) {
|
||
15 years ago
|
listModel->setData(listModel->index(row, DLSPEED), QVariant((double)0.0));
|
||
|
listModel->setData(listModel->index(row, UPSPEED), QVariant((double)0.0));
|
||
|
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
|
||
|
listModel->setData(listModel->index(row, NAME), QIcon(QString::fromUtf8(":/Icons/skin/paused.png")), Qt::DecorationRole);
|
||
15 years ago
|
listModel->setData(listModel->index(row, STATUS), STATE_PAUSED);
|
||
|
listModel->setData(listModel->index(row, SEEDS), QVariant(0.0));
|
||
|
listModel->setData(listModel->index(row, PEERS), QVariant(0.0));
|
||
15 years ago
|
//setRowColor(row, QString::fromUtf8("red"));
|
||
15 years ago
|
if(refresh_list)
|
||
|
refreshList();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
// Wrapper slot for bittorrent signal
|
||
|
void TransferListWidget::resumeTorrent(QTorrentHandle &h) {
|
||
|
resumeTorrent(getRowFromHash(h.hash()));
|
||
|
}
|
||
|
|
||
15 years ago
|
void TransferListWidget::resumeTorrent(int row, bool refresh_list) {
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row));
|
||
|
if(!h.is_valid()) return;
|
||
15 years ago
|
if(h.is_seed()) {
|
||
15 years ago
|
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole);
|
||
15 years ago
|
listModel->setData(listModel->index(row, STATUS), STATE_SEEDING);
|
||
|
} else {
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/stalled.png")), Qt::DecorationRole);
|
||
|
listModel->setData(listModel->index(row, STATUS), STATE_STALLED);
|
||
15 years ago
|
}
|
||
15 years ago
|
if(refresh_list)
|
||
|
refreshList();
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void TransferListWidget::updateMetadata(QTorrentHandle &h) {
|
||
|
QString hash = h.hash();
|
||
|
int row = getRowFromHash(hash);
|
||
|
if(row != -1) {
|
||
|
qDebug("Updating torrent metadata in download list");
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(h.name()));
|
||
|
listModel->setData(listModel->index(row, SIZE), QVariant((qlonglong)h.actual_size()));
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
int TransferListWidget::updateTorrent(int row) {
|
||
|
TorrentState s = STATE_INVALID;
|
||
15 years ago
|
QString hash = getHashFromRow(row);
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(!h.is_valid()) {
|
||
|
// Delete torrent
|
||
15 years ago
|
deleteTorrent(row, false);
|
||
|
return s;
|
||
15 years ago
|
}
|
||
|
try {
|
||
15 years ago
|
// Queueing code
|
||
|
if(!h.is_seed() && BTSession->isQueueingEnabled()) {
|
||
|
listModel->setData(listModel->index(row, PRIORITY), QVariant((int)h.queue_position()));
|
||
|
if(h.is_queued()) {
|
||
|
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) {
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/run-build.png"))), Qt::DecorationRole);
|
||
|
listModel->setData(listModel->index(row, PROGRESS), QVariant((double)h.progress()));
|
||
|
}else {
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/mail-queue.png"))), Qt::DecorationRole);
|
||
|
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
|
||
15 years ago
|
}
|
||
15 years ago
|
s = STATE_QUEUED;
|
||
|
listModel->setData(listModel->index(row, STATUS), STATE_QUEUED);
|
||
|
// Reset speeds and seeds/leech
|
||
|
listModel->setData(listModel->index(row, DLSPEED), QVariant((double)0.));
|
||
|
listModel->setData(listModel->index(row, UPSPEED), QVariant((double)0.));
|
||
|
listModel->setData(listModel->index(row, SEEDS), QVariant(0.0));
|
||
|
listModel->setData(listModel->index(row, PEERS), QVariant(0.0));
|
||
|
//setRowColor(row, QString::fromUtf8("grey"));
|
||
|
return s;
|
||
15 years ago
|
}
|
||
15 years ago
|
}
|
||
|
if(h.is_paused()) return STATE_PAUSED;
|
||
15 years ago
|
|
||
15 years ago
|
// Parse download state
|
||
|
switch(h.state()) {
|
||
|
case torrent_status::allocating:
|
||
|
case torrent_status::checking_files:
|
||
|
case torrent_status::queued_for_checking:
|
||
|
case torrent_status::checking_resume_data:
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/run-build.png"))), Qt::DecorationRole);
|
||
|
listModel->setData(listModel->index(row, STATUS), STATE_CHECKING);
|
||
|
s = STATE_CHECKING;
|
||
|
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
|
||
|
//setRowColor(row, QString::fromUtf8("grey"));
|
||
|
break;
|
||
|
case torrent_status::downloading:
|
||
|
case torrent_status::downloading_metadata:
|
||
|
if(h.download_payload_rate() > 0) {
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png"))), Qt::DecorationRole);
|
||
|
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)BTSession->getETA(hash)));
|
||
|
listModel->setData(listModel->index(row, STATUS), STATE_DOWNLOADING);
|
||
|
s = STATE_DOWNLOADING;
|
||
|
//setRowColor(row, QString::fromUtf8("green"));
|
||
|
}else{
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalled.png"))), Qt::DecorationRole);
|
||
15 years ago
|
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
|
||
15 years ago
|
listModel->setData(listModel->index(row, STATUS), STATE_STALLED);
|
||
|
s = STATE_STALLED;
|
||
|
//setRowColor(row, QApplication::palette().color(QPalette::WindowText));
|
||
15 years ago
|
}
|
||
15 years ago
|
listModel->setData(listModel->index(row, UPSPEED), QVariant((double)h.upload_payload_rate()));
|
||
|
break;
|
||
|
case torrent_status::finished:
|
||
|
case torrent_status::seeding:
|
||
|
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
|
||
|
listModel->setData(listModel->index(row, UPSPEED), QVariant((double)h.upload_payload_rate()));
|
||
|
listModel->setData(listModel->index(row, STATUS), STATE_SEEDING);
|
||
|
s = STATE_SEEDING;
|
||
15 years ago
|
}
|
||
|
// Common to both downloads and uploads
|
||
15 years ago
|
listModel->setData(listModel->index(row, PROGRESS), QVariant((double)h.progress()));
|
||
|
listModel->setData(listModel->index(row, DLSPEED), QVariant((double)h.download_payload_rate()));
|
||
15 years ago
|
// Connected_seeds*100000+total_seeds*10 (if total_seeds is available)
|
||
|
// Connected_seeds*100000+1 (if total_seeds is unavailable)
|
||
15 years ago
|
qulonglong seeds = h.num_seeds()*1000000;
|
||
15 years ago
|
if(h.num_complete() >= h.num_seeds())
|
||
|
seeds += h.num_complete()*10;
|
||
|
else
|
||
|
seeds += 1;
|
||
|
listModel->setData(listModel->index(row, SEEDS), QVariant(seeds));
|
||
15 years ago
|
qulonglong peers = (h.num_peers()-h.num_seeds())*1000000;
|
||
15 years ago
|
if(h.num_incomplete() >= (h.num_peers()-h.num_seeds()))
|
||
|
peers += h.num_incomplete()*10;
|
||
|
else
|
||
|
peers += 1;
|
||
|
listModel->setData(listModel->index(row, PEERS), QVariant(peers));
|
||
|
// Share ratio
|
||
|
listModel->setData(listModel->index(row, RATIO), QVariant(BTSession->getRealRatio(hash)));
|
||
15 years ago
|
}catch(invalid_handle e) {
|
||
15 years ago
|
deleteTorrent(row, false);
|
||
|
s = STATE_INVALID;
|
||
15 years ago
|
qDebug("Caught Invalid handle exception, lucky us.");
|
||
|
}
|
||
15 years ago
|
return s;
|
||
15 years ago
|
}
|
||
|
|
||
|
void TransferListWidget::setFinished(QTorrentHandle &h) {
|
||
|
int row = -1;
|
||
|
try {
|
||
|
row = getRowFromHash(h.hash());
|
||
|
if(row >= 0) {
|
||
|
if(h.is_paused()) {
|
||
|
listModel->setData(listModel->index(row, NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole);
|
||
15 years ago
|
listModel->setData(listModel->index(row, STATUS), STATE_PAUSED);
|
||
15 years ago
|
//setRowColor(row, "red");
|
||
|
}else{
|
||
|
listModel->setData(listModel->index(row, NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole);
|
||
15 years ago
|
listModel->setData(listModel->index(row, STATUS), STATE_SEEDING);
|
||
15 years ago
|
//setRowColor(row, "orange");
|
||
|
}
|
||
|
listModel->setData(listModel->index(row, ETA), QVariant((qlonglong)-1));
|
||
|
listModel->setData(listModel->index(row, DLSPEED), QVariant((double)0.));
|
||
|
listModel->setData(listModel->index(row, PROGRESS), QVariant((double)1.));
|
||
|
listModel->setData(listModel->index(row, PRIORITY), QVariant((int)-1));
|
||
|
}
|
||
|
} catch(invalid_handle e) {
|
||
|
if(row >= 0) deleteTorrent(row);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::setRefreshInterval(int t) {
|
||
15 years ago
|
refreshTimer->start(t);
|
||
15 years ago
|
}
|
||
|
|
||
|
void TransferListWidget::refreshList() {
|
||
15 years ago
|
unsigned int nb_downloading = 0, nb_seeding=0, nb_inactive = 0;
|
||
15 years ago
|
for(int i=0; i<listModel->rowCount(); ++i) {
|
||
15 years ago
|
int s = updateTorrent(i);
|
||
|
switch(s) {
|
||
|
case STATE_DOWNLOADING:
|
||
|
case STATE_STALLED:
|
||
|
++nb_downloading;
|
||
|
break;
|
||
|
case STATE_SEEDING:
|
||
|
++nb_seeding;
|
||
|
break;
|
||
|
case STATE_CHECKING:
|
||
|
case STATE_PAUSED:
|
||
|
case STATE_QUEUED:
|
||
|
++nb_inactive;
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
15 years ago
|
}
|
||
15 years ago
|
emit torrentStatusUpdate(nb_downloading, nb_seeding, nb_inactive);
|
||
15 years ago
|
}
|
||
|
|
||
|
int TransferListWidget::getRowFromHash(QString hash) const{
|
||
|
QList<QStandardItem *> items = listModel->findItems(hash, Qt::MatchExactly, HASH);
|
||
|
if(items.empty()) return -1;
|
||
|
Q_ASSERT(items.size() == 1);
|
||
|
return items.first()->row();
|
||
|
}
|
||
|
|
||
|
QString TransferListWidget::getHashFromRow(int row) const {
|
||
|
return listModel->data(listModel->index(row, HASH)).toString();
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::torrentDoubleClicked(QModelIndex index) {
|
||
|
int row = proxyModel->mapToSource(index).row();
|
||
|
QString hash = getHashFromRow(row);
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(!h.is_valid()) return;
|
||
|
int action;
|
||
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||
|
if(h.is_seed()) {
|
||
|
action = settings.value(QString::fromUtf8("Preferences/Downloads/DblClOnTorFN"), 0).toInt();
|
||
|
} else {
|
||
|
action = settings.value(QString::fromUtf8("Preferences/Downloads/DblClOnTorDl"), 0).toInt();
|
||
|
}
|
||
|
|
||
|
switch(action) {
|
||
|
case TOGGLE_PAUSE:
|
||
|
if(h.is_paused()) {
|
||
|
h.resume();
|
||
|
resumeTorrent(row);
|
||
|
} else {
|
||
|
h.pause();
|
||
|
pauseTorrent(row);
|
||
|
}
|
||
|
break;
|
||
|
case OPEN_DEST:
|
||
|
QDesktopServices::openUrl(QUrl(h.save_path()));
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::startSelectedTorrents() {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
|
// Get the file hash
|
||
15 years ago
|
int row = proxyModel->mapToSource(index).row();
|
||
|
QString hash = getHashFromRow(row);
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(h.is_valid() && h.is_paused()) {
|
||
|
h.resume();
|
||
15 years ago
|
resumeTorrent(row, false);
|
||
15 years ago
|
}
|
||
|
}
|
||
15 years ago
|
if(!selectedIndexes.empty())
|
||
|
refreshList();
|
||
15 years ago
|
}
|
||
|
|
||
|
void TransferListWidget::startAllTorrents() {
|
||
|
for(int i=0; i<listModel->rowCount(); ++i) {
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(i));
|
||
|
if(h.is_valid() && h.is_paused()) {
|
||
|
h.resume();
|
||
15 years ago
|
resumeTorrent(i, false);
|
||
15 years ago
|
}
|
||
|
}
|
||
15 years ago
|
refreshList();
|
||
15 years ago
|
}
|
||
|
|
||
|
void TransferListWidget::pauseSelectedTorrents() {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
|
// Get the file hash
|
||
15 years ago
|
int row = proxyModel->mapToSource(index).row();
|
||
|
QString hash = getHashFromRow(row);
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(h.is_valid() && !h.is_paused()) {
|
||
|
h.pause();
|
||
15 years ago
|
pauseTorrent(row, false);
|
||
15 years ago
|
}
|
||
|
}
|
||
15 years ago
|
if(!selectedIndexes.empty())
|
||
|
refreshList();
|
||
15 years ago
|
}
|
||
|
|
||
|
void TransferListWidget::pauseAllTorrents() {
|
||
|
for(int i=0; i<listModel->rowCount(); ++i) {
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(i));
|
||
|
if(h.is_valid() && !h.is_paused()) {
|
||
|
h.pause();
|
||
15 years ago
|
pauseTorrent(i, false);
|
||
15 years ago
|
}
|
||
|
}
|
||
15 years ago
|
refreshList();
|
||
15 years ago
|
}
|
||
|
|
||
|
void TransferListWidget::deleteSelectedTorrents() {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
if(!selectedIndexes.empty()) {
|
||
15 years ago
|
bool delete_local_files = false;
|
||
|
if(DeletionConfirmationDlg::askForDeletionConfirmation(&delete_local_files)) {
|
||
|
QStringList hashes;
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
|
// Get the file hash
|
||
|
hashes << getHashFromRow(proxyModel->mapToSource(index).row());
|
||
|
}
|
||
|
foreach(const QString &hash, hashes) {
|
||
|
deleteTorrent(getRowFromHash(hash), false);
|
||
|
BTSession->deleteTorrent(hash, delete_local_files);
|
||
|
}
|
||
|
refreshList();
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// FIXME: Should work only if the tab is displayed
|
||
|
void TransferListWidget::increasePrioSelectedTorrents() {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row()));
|
||
15 years ago
|
if(h.is_valid() && !h.is_seed()) {
|
||
15 years ago
|
h.queue_position_up();
|
||
15 years ago
|
}
|
||
|
}
|
||
15 years ago
|
refreshList();
|
||
15 years ago
|
}
|
||
|
|
||
|
// FIXME: Should work only if the tab is displayed
|
||
|
void TransferListWidget::decreasePrioSelectedTorrents() {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row()));
|
||
15 years ago
|
if(h.is_valid() && !h.is_seed()) {
|
||
15 years ago
|
h.queue_position_down();
|
||
15 years ago
|
}
|
||
|
}
|
||
15 years ago
|
refreshList();
|
||
15 years ago
|
}
|
||
|
|
||
|
void TransferListWidget::buySelectedTorrents() const {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row()));
|
||
15 years ago
|
if(h.is_valid())
|
||
|
QDesktopServices::openUrl("http://match.sharemonkey.com/?info_hash="+h.hash()+"&n="+h.name()+"&cid=33");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::copySelectedMagnetURIs() const {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
QStringList magnet_uris;
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row()));
|
||
15 years ago
|
if(h.is_valid())
|
||
|
magnet_uris << misc::toQString(make_magnet_uri(h.get_torrent_info()));
|
||
|
}
|
||
|
qApp->clipboard()->setText(magnet_uris.join("\n"));
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::hidePriorityColumn(bool hide) {
|
||
|
setColumnHidden(PRIORITY, hide);
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::openSelectedTorrentsFolder() const {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
QStringList pathsList;
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row()));
|
||
15 years ago
|
if(h.is_valid()) {
|
||
|
QString savePath = h.save_path();
|
||
|
if(!pathsList.contains(savePath)) {
|
||
|
pathsList.append(savePath);
|
||
|
QDesktopServices::openUrl(QUrl(QString("file://")+savePath));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::previewSelectedTorrents() {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
QStringList pathsList;
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(proxyModel->mapToSource(index).row()));
|
||
15 years ago
|
if(h.is_valid()) {
|
||
|
new previewSelect(this, h);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void TransferListWidget::setDlLimitSelectedTorrents() {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
QStringList hashes;
|
||
15 years ago
|
QList<QTorrentHandle> selected_torrents;
|
||
|
bool first = true;
|
||
|
bool all_same_limit = true;
|
||
15 years ago
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
|
// Get the file hash
|
||
15 years ago
|
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
15 years ago
|
if(h.is_valid() && !h.is_seed()) {
|
||
|
selected_torrents << h;
|
||
|
// Determine current limit for selected torrents
|
||
|
if(first) {
|
||
|
first = false;
|
||
|
} else {
|
||
|
if(all_same_limit && h.download_limit() != selected_torrents.first().download_limit())
|
||
|
all_same_limit = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if(selected_torrents.empty()) return;
|
||
|
|
||
|
bool ok=false;
|
||
|
int default_limit = -1;
|
||
|
if(all_same_limit)
|
||
|
default_limit = selected_torrents.first().download_limit();
|
||
|
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit);
|
||
|
if(ok) {
|
||
|
foreach(QTorrentHandle h, selected_torrents) {
|
||
|
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), h.hash().toLocal8Bit().data());
|
||
15 years ago
|
BTSession->setDownloadLimit(h.hash(), new_limit);
|
||
15 years ago
|
}
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::setUpLimitSelectedTorrents() {
|
||
15 years ago
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
15 years ago
|
QStringList hashes;
|
||
15 years ago
|
QList<QTorrentHandle> selected_torrents;
|
||
|
bool first = true;
|
||
|
bool all_same_limit = true;
|
||
15 years ago
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
|
// Get the file hash
|
||
15 years ago
|
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
15 years ago
|
if(h.is_valid()) {
|
||
15 years ago
|
selected_torrents << h;
|
||
|
// Determine current limit for selected torrents
|
||
|
if(first) {
|
||
|
first = false;
|
||
|
} else {
|
||
|
if(all_same_limit && h.upload_limit() != selected_torrents.first().upload_limit())
|
||
|
all_same_limit = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if(selected_torrents.empty()) return;
|
||
|
|
||
|
bool ok=false;
|
||
|
int default_limit = -1;
|
||
|
if(all_same_limit)
|
||
|
default_limit = selected_torrents.first().upload_limit();
|
||
|
long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit);
|
||
|
if(ok) {
|
||
|
foreach(QTorrentHandle h, selected_torrents) {
|
||
|
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), h.hash().toLocal8Bit().data());
|
||
15 years ago
|
BTSession->setUploadLimit(h.hash(), new_limit);
|
||
15 years ago
|
}
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::recheckSelectedTorrents() {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
foreach(const QModelIndex &index, selectedIndexes){
|
||
15 years ago
|
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
|
||
15 years ago
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(h.is_valid() && h.has_metadata())
|
||
|
h.force_recheck();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
// save the hidden columns in settings
|
||
|
void TransferListWidget::saveHiddenColumns() {
|
||
|
QSettings settings("qBittorrent", "qBittorrent");
|
||
|
QStringList ishidden_list;
|
||
15 years ago
|
short nbColumns = listModel->columnCount()-1;//hash column is hidden
|
||
15 years ago
|
|
||
|
for(short i=0; i<nbColumns; ++i){
|
||
|
if(isColumnHidden(i)) {
|
||
|
ishidden_list << "0";
|
||
|
} else {
|
||
|
ishidden_list << "1";
|
||
|
}
|
||
|
}
|
||
|
settings.setValue("TransferListColsHoS", ishidden_list.join(" "));
|
||
|
}
|
||
|
|
||
|
// load the previous settings, and hide the columns
|
||
|
bool TransferListWidget::loadHiddenColumns() {
|
||
|
QSettings settings("qBittorrent", "qBittorrent");
|
||
|
QString line = settings.value("TransferListColsHoS", QString()).toString();
|
||
|
if(line.isEmpty()) return false;
|
||
|
bool loaded = false;
|
||
|
QStringList ishidden_list;
|
||
|
ishidden_list = line.split(' ');
|
||
|
unsigned int nbCol = ishidden_list.size();
|
||
15 years ago
|
if(nbCol == (unsigned int)listModel->columnCount()-1) {
|
||
15 years ago
|
for(unsigned int i=0; i<nbCol; ++i){
|
||
|
if(ishidden_list.at(i) == "0") {
|
||
|
setColumnHidden(i, true);
|
||
|
}
|
||
|
}
|
||
|
loaded = true;
|
||
|
}
|
||
|
return loaded;
|
||
|
}
|
||
|
|
||
|
// hide/show columns menu
|
||
|
void TransferListWidget::displayDLHoSMenu(const QPoint&){
|
||
|
QMenu hideshowColumn(this);
|
||
|
hideshowColumn.setTitle(tr("Column visibility"));
|
||
|
int lastCol;
|
||
|
if(BTSession->isQueueingEnabled()) {
|
||
|
lastCol = PRIORITY;
|
||
|
} else {
|
||
|
lastCol = ETA;
|
||
|
}
|
||
|
QList<QAction*> actions;
|
||
|
for(int i=0; i <= lastCol; ++i) {
|
||
|
QIcon icon;
|
||
|
if(isColumnHidden(i))
|
||
|
icon = QIcon(QString::fromUtf8(":/Icons/oxygen/button_cancel.png"));
|
||
|
else
|
||
|
icon = QIcon(QString::fromUtf8(":/Icons/oxygen/button_ok.png"));
|
||
|
actions.append(hideshowColumn.addAction(icon, listModel->headerData(i, Qt::Horizontal).toString()));
|
||
|
}
|
||
|
// Call menu
|
||
|
QAction *act = hideshowColumn.exec(QCursor::pos());
|
||
|
int col = actions.indexOf(act);
|
||
|
setColumnHidden(col, !isColumnHidden(col));
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
#ifdef LIBTORRENT_0_15
|
||
|
void TransferListWidget::toggleSelectedTorrentsSuperSeeding() {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
|
// Get the file hash
|
||
|
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(h.is_valid()) {
|
||
|
h.super_seeding(!h.super_seeding());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
|
||
15 years ago
|
void TransferListWidget::toggleSelectedTorrentsSequentialDownload() {
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
|
// Get the file hash
|
||
|
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
if(h.is_valid()) {
|
||
|
h.set_sequential_download(!h.is_sequential_download());
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void TransferListWidget::displayListMenu(const QPoint&) {
|
||
|
// Create actions
|
||
|
QAction actionStart(QIcon(QString::fromUtf8(":/Icons/skin/play.png")), tr("Start"), 0);
|
||
|
connect(&actionStart, SIGNAL(triggered()), this, SLOT(startSelectedTorrents()));
|
||
|
QAction actionPause(QIcon(QString::fromUtf8(":/Icons/skin/pause.png")), tr("Pause"), 0);
|
||
|
connect(&actionPause, SIGNAL(triggered()), this, SLOT(pauseSelectedTorrents()));
|
||
|
QAction actionDelete(QIcon(QString::fromUtf8(":/Icons/skin/delete.png")), tr("Delete"), 0);
|
||
|
connect(&actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedTorrents()));
|
||
|
QAction actionPreview_file(QIcon(QString::fromUtf8(":/Icons/skin/preview.png")), tr("Preview file"), 0);
|
||
|
connect(&actionPreview_file, SIGNAL(triggered()), this, SLOT(previewSelectedTorrents()));
|
||
15 years ago
|
QAction actionSet_upload_limit(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png")), tr("Limit upload rate"), 0);
|
||
15 years ago
|
connect(&actionSet_upload_limit, SIGNAL(triggered()), this, SLOT(setUpLimitSelectedTorrents()));
|
||
15 years ago
|
QAction actionSet_download_limit(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png")), tr("Limit download rate"), 0);
|
||
15 years ago
|
connect(&actionSet_download_limit, SIGNAL(triggered()), this, SLOT(setDlLimitSelectedTorrents()));
|
||
|
QAction actionOpen_destination_folder(QIcon(QString::fromUtf8(":/Icons/oxygen/folder.png")), tr("Open destination folder"), 0);
|
||
|
connect(&actionOpen_destination_folder, SIGNAL(triggered()), this, SLOT(openSelectedTorrentsFolder()));
|
||
|
QAction actionBuy_it(QIcon(QString::fromUtf8(":/Icons/oxygen/wallet.png")), tr("Buy it"), 0);
|
||
|
connect(&actionBuy_it, SIGNAL(triggered()), this, SLOT(buySelectedTorrents()));
|
||
|
QAction actionIncreasePriority(QIcon(QString::fromUtf8(":/Icons/skin/increase.png")), tr("Increase priority"), 0);
|
||
|
connect(&actionIncreasePriority, SIGNAL(triggered()), this, SLOT(increasePrioSelectedTorrents()));
|
||
|
QAction actionDecreasePriority(QIcon(QString::fromUtf8(":/Icons/skin/decrease.png")), tr("Decrease priority"), 0);
|
||
|
connect(&actionDecreasePriority, SIGNAL(triggered()), this, SLOT(decreasePrioSelectedTorrents()));
|
||
|
QAction actionForce_recheck(QIcon(QString::fromUtf8(":/Icons/oxygen/gear.png")), tr("Force recheck"), 0);
|
||
|
connect(&actionForce_recheck, SIGNAL(triggered()), this, SLOT(recheckSelectedTorrents()));
|
||
|
QAction actionCopy_magnet_link(QIcon(QString::fromUtf8(":/Icons/magnet.png")), tr("Copy magnet link"), 0);
|
||
|
connect(&actionCopy_magnet_link, SIGNAL(triggered()), this, SLOT(copySelectedMagnetURIs()));
|
||
15 years ago
|
QAction actionSuper_seeding_mode(tr("Super seeding mode"), 0);
|
||
|
connect(&actionSuper_seeding_mode, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSuperSeeding()));
|
||
15 years ago
|
QAction actionSequential_download(tr("Download in sequential order"), 0);
|
||
|
connect(&actionSequential_download, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSequentialDownload()));
|
||
15 years ago
|
// End of actions
|
||
|
QMenu listMenu(this);
|
||
|
// Enable/disable pause/start action given the DL state
|
||
|
QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
||
|
bool has_pause = false, has_start = false, has_preview = false;
|
||
15 years ago
|
bool all_same_super_seeding = true, all_same_sequential_download_mode = true;
|
||
|
bool super_seeding_mode = false, sequential_download_mode = false;
|
||
15 years ago
|
bool one_has_metadata = false, one_not_seed = false;
|
||
15 years ago
|
bool first = true;
|
||
15 years ago
|
QTorrentHandle h;
|
||
|
qDebug("Displaying menu");
|
||
|
foreach(const QModelIndex &index, selectedIndexes) {
|
||
|
// Get the file name
|
||
15 years ago
|
QString hash = getHashFromRow(proxyModel->mapToSource(index).row());
|
||
15 years ago
|
// Get handle and pause the torrent
|
||
|
h = BTSession->getTorrentHandle(hash);
|
||
|
if(!h.is_valid()) continue;
|
||
15 years ago
|
if(h.has_metadata())
|
||
15 years ago
|
one_has_metadata = true;
|
||
15 years ago
|
if(!h.is_seed()) {
|
||
15 years ago
|
one_not_seed = true;
|
||
15 years ago
|
if(first) {
|
||
|
sequential_download_mode = h.is_sequential_download();
|
||
|
} else {
|
||
|
if(sequential_download_mode != h.is_sequential_download()) {
|
||
|
all_same_sequential_download_mode = false;
|
||
|
}
|
||
|
}
|
||
15 years ago
|
} else {
|
||
|
if(!one_not_seed && all_same_super_seeding) {
|
||
|
if(first) {
|
||
|
super_seeding_mode = h.super_seeding();
|
||
|
} else {
|
||
|
if(super_seeding_mode != h.super_seeding()) {
|
||
|
all_same_super_seeding = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
15 years ago
|
if(h.is_paused()) {
|
||
|
if(!has_start) {
|
||
|
listMenu.addAction(&actionStart);
|
||
|
has_start = true;
|
||
|
}
|
||
|
}else{
|
||
|
if(!has_pause) {
|
||
|
listMenu.addAction(&actionPause);
|
||
|
has_pause = true;
|
||
|
}
|
||
|
}
|
||
|
if(h.has_metadata() && BTSession->isFilePreviewPossible(hash) && !has_preview) {
|
||
|
listMenu.addAction(&actionPreview_file);
|
||
|
has_preview = true;
|
||
|
}
|
||
15 years ago
|
first = false;
|
||
15 years ago
|
if(has_pause && has_start && has_preview && one_not_seed) break;
|
||
15 years ago
|
}
|
||
|
listMenu.addSeparator();
|
||
|
listMenu.addAction(&actionDelete);
|
||
|
listMenu.addSeparator();
|
||
15 years ago
|
if(one_not_seed)
|
||
|
listMenu.addAction(&actionSet_download_limit);
|
||
15 years ago
|
listMenu.addAction(&actionSet_upload_limit);
|
||
15 years ago
|
if(!one_not_seed && all_same_super_seeding) {
|
||
|
QIcon ico;
|
||
|
if(super_seeding_mode) {
|
||
|
ico = QIcon(":/Icons/oxygen/button_ok.png");
|
||
|
} else {
|
||
|
ico = QIcon(":/Icons/oxygen/button_cancel.png");
|
||
|
}
|
||
|
actionSuper_seeding_mode.setIcon(ico);
|
||
|
listMenu.addAction(&actionSuper_seeding_mode);
|
||
|
}
|
||
15 years ago
|
if(one_not_seed && all_same_sequential_download_mode) {
|
||
|
QIcon ico;
|
||
|
if(sequential_download_mode) {
|
||
|
ico = QIcon(":/Icons/oxygen/button_ok.png");
|
||
|
} else {
|
||
|
ico = QIcon(":/Icons/oxygen/button_cancel.png");
|
||
|
}
|
||
|
actionSequential_download.setIcon(ico);
|
||
|
listMenu.addAction(&actionSequential_download);
|
||
|
}
|
||
15 years ago
|
listMenu.addSeparator();
|
||
|
if(one_has_metadata) {
|
||
|
listMenu.addAction(&actionForce_recheck);
|
||
|
listMenu.addSeparator();
|
||
|
}
|
||
|
listMenu.addAction(&actionOpen_destination_folder);
|
||
15 years ago
|
if(BTSession->isQueueingEnabled() && one_not_seed) {
|
||
15 years ago
|
listMenu.addSeparator();
|
||
|
listMenu.addAction(&actionIncreasePriority);
|
||
|
listMenu.addAction(&actionDecreasePriority);
|
||
|
}
|
||
|
listMenu.addSeparator();
|
||
|
listMenu.addAction(&actionCopy_magnet_link);
|
||
|
listMenu.addAction(&actionBuy_it);
|
||
|
// Call menu
|
||
|
listMenu.exec(QCursor::pos());
|
||
|
}
|
||
15 years ago
|
|
||
|
// Save columns width in a file to remember them
|
||
|
void TransferListWidget::saveColWidthList() {
|
||
|
qDebug("Saving columns width in transfer list");
|
||
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||
|
QStringList width_list;
|
||
|
QStringList new_width_list;
|
||
15 years ago
|
short nbColumns = listModel->columnCount()-1; // HASH is hidden
|
||
15 years ago
|
QString line = settings.value("TransferListColsWidth", QString()).toString();
|
||
|
if(!line.isEmpty()) {
|
||
|
width_list = line.split(' ');
|
||
|
}
|
||
|
for(short i=0; i<nbColumns; ++i){
|
||
|
if(columnWidth(i)<1 && width_list.size() == nbColumns && width_list.at(i).toInt()>=1) {
|
||
|
// load the former width
|
||
|
new_width_list << width_list.at(i);
|
||
|
} else if(columnWidth(i)>=1) {
|
||
|
// usual case, save the current width
|
||
|
new_width_list << misc::toQString(columnWidth(i));
|
||
|
} else {
|
||
|
// default width
|
||
|
resizeColumnToContents(i);
|
||
|
new_width_list << misc::toQString(columnWidth(i));
|
||
|
}
|
||
|
}
|
||
|
settings.setValue(QString::fromUtf8("TransferListColsWidth"), new_width_list.join(QString::fromUtf8(" ")));
|
||
|
QVariantList visualIndexes;
|
||
|
for(int i=0; i<nbColumns; ++i) {
|
||
|
visualIndexes.append(header()->visualIndex(i));
|
||
|
}
|
||
|
settings.setValue(QString::fromUtf8("TransferListVisualIndexes"), visualIndexes);
|
||
|
qDebug("Download list columns width saved");
|
||
|
}
|
||
|
|
||
|
// Load columns width in a file that were saved previously
|
||
|
bool TransferListWidget::loadColWidthList() {
|
||
|
qDebug("Loading columns width for download list");
|
||
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||
|
QString line = settings.value(QString::fromUtf8("TransferListColsWidth"), QString()).toString();
|
||
|
if(line.isEmpty())
|
||
|
return false;
|
||
|
QStringList width_list = line.split(QString::fromUtf8(" "));
|
||
15 years ago
|
if(width_list.size() != listModel->columnCount()-1) {
|
||
|
qDebug("Corrupted values for transfer list columns sizes");
|
||
15 years ago
|
return false;
|
||
|
}
|
||
|
unsigned int listSize = width_list.size();
|
||
|
for(unsigned int i=0; i<listSize; ++i) {
|
||
|
header()->resizeSection(i, width_list.at(i).toInt());
|
||
|
}
|
||
|
QVariantList visualIndexes = settings.value(QString::fromUtf8("TransferListVisualIndexes"), QVariantList()).toList();
|
||
15 years ago
|
if(visualIndexes.size() != listModel->columnCount()-1) {
|
||
|
qDebug("Corrupted values for transfer list columns indexes");
|
||
15 years ago
|
return false;
|
||
|
}
|
||
|
bool change = false;
|
||
|
do {
|
||
|
change = false;
|
||
|
for(int i=0;i<visualIndexes.size(); ++i) {
|
||
|
int new_visual_index = visualIndexes.at(header()->logicalIndex(i)).toInt();
|
||
|
if(i != new_visual_index) {
|
||
|
qDebug("Moving column from %d to %d", header()->logicalIndex(i), new_visual_index);
|
||
|
header()->moveSection(i, new_visual_index);
|
||
|
change = true;
|
||
|
}
|
||
|
}
|
||
|
}while(change);
|
||
|
qDebug("Transfer list columns width loaded");
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::saveLastSortedColumn() {
|
||
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||
|
Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
|
||
|
QString sortOrderLetter;
|
||
|
if(sortOrder == Qt::AscendingOrder)
|
||
|
sortOrderLetter = QString::fromUtf8("a");
|
||
|
else
|
||
|
sortOrderLetter = QString::fromUtf8("d");
|
||
|
int index = header()->sortIndicatorSection();
|
||
|
settings.setValue(QString::fromUtf8("TransferListSortedCol"), misc::toQString(index)+sortOrderLetter);
|
||
|
}
|
||
|
|
||
|
void TransferListWidget::loadLastSortedColumn() {
|
||
|
// Loading last sorted column
|
||
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
||
|
QString sortedCol = settings.value(QString::fromUtf8("TransferListSortedCol"), QString()).toString();
|
||
|
if(!sortedCol.isEmpty()) {
|
||
|
Qt::SortOrder sortOrder;
|
||
|
if(sortedCol.endsWith(QString::fromUtf8("d")))
|
||
|
sortOrder = Qt::DescendingOrder;
|
||
|
else
|
||
|
sortOrder = Qt::AscendingOrder;
|
||
|
sortedCol = sortedCol.left(sortedCol.size()-1);
|
||
|
int index = sortedCol.toInt();
|
||
|
sortByColumn(index, sortOrder);
|
||
|
}
|
||
|
}
|
||
15 years ago
|
|
||
15 years ago
|
void TransferListWidget::currentChanged(const QModelIndex& current, const QModelIndex&) {
|
||
15 years ago
|
QTorrentHandle h;
|
||
|
if(current.isValid()) {
|
||
|
int row = proxyModel->mapToSource(current).row();
|
||
|
h = BTSession->getTorrentHandle(getHashFromRow(row));
|
||
|
}
|
||
15 years ago
|
emit currentTorrentChanged(h);
|
||
|
}
|
||
|
|
||
15 years ago
|
void TransferListWidget::applyFilter(int f) {
|
||
|
switch(f) {
|
||
15 years ago
|
case FILTER_DOWNLOADING:
|
||
|
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_DOWNLOADING)+"|"+QString::number(STATE_STALLED), Qt::CaseSensitive));
|
||
15 years ago
|
break;
|
||
15 years ago
|
case FILTER_COMPLETED:
|
||
|
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_SEEDING), Qt::CaseSensitive, QRegExp::FixedString));
|
||
15 years ago
|
break;
|
||
15 years ago
|
case FILTER_ACTIVE:
|
||
|
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_DOWNLOADING)+"|"+QString::number(STATE_SEEDING)+"|"+QString::number(STATE_STALLED), Qt::CaseSensitive));
|
||
15 years ago
|
break;
|
||
15 years ago
|
case FILTER_INACTIVE:
|
||
|
proxyModel->setFilterRegExp(QRegExp(QString::number(STATE_CHECKING)+"|"+QString::number(STATE_PAUSED)+"|"+QString::number(STATE_QUEUED), Qt::CaseSensitive));
|
||
15 years ago
|
break;
|
||
|
default:
|
||
|
proxyModel->setFilterRegExp(QRegExp());
|
||
|
}
|
||
15 years ago
|
// Select first item if nothing is selected
|
||
|
if(selectionModel()->selectedRows(0).empty() && proxyModel->rowCount() > 0)
|
||
|
selectionModel()->setCurrentIndex(proxyModel->index(0, NAME), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows);
|
||
15 years ago
|
}
|
||
15 years ago
|
|
||
|
void TransferListWidget::updateTorrentSizeAndProgress(QString hash) {
|
||
|
int row = getRowFromHash(hash);
|
||
|
Q_ASSERT(row != -1);
|
||
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
||
|
listModel->setData(listModel->index(row, SIZE), QVariant((qlonglong)h.actual_size()));
|
||
|
listModel->setData(listModel->index(row, PROGRESS), QVariant((double)h.progress()));
|
||
|
}
|