2009-11-07 22:55:33 +03:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
|
|
|
* modified versions of it that use the same license as the "OpenSSL" library),
|
|
|
|
* and distribute the linked executables. You must obey the GNU General Public
|
|
|
|
* License in all respects for all of the code used other than "OpenSSL". If you
|
|
|
|
* modify file(s), you may extend this exception to your version of the file(s),
|
|
|
|
* but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
* exception statement from your version.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
|
|
|
*/
|
|
|
|
|
2009-11-20 10:48:44 +03:00
|
|
|
#include "transferlistwidget.h"
|
2010-10-09 18:06:35 +04:00
|
|
|
#include "qbtsession.h"
|
2009-11-20 10:48:44 +03:00
|
|
|
#include "torrentpersistentdata.h"
|
|
|
|
#include "transferlistdelegate.h"
|
|
|
|
#include "previewselect.h"
|
2009-11-17 16:11:32 +03:00
|
|
|
#include "speedlimitdlg.h"
|
2009-11-07 22:55:33 +03:00
|
|
|
#include "options_imp.h"
|
2010-11-14 00:15:52 +03:00
|
|
|
#include "mainwindow.h"
|
2009-12-30 19:18:50 +03:00
|
|
|
#include "preferences.h"
|
2009-11-18 15:11:15 +03:00
|
|
|
#include "deletionconfirmationdlg.h"
|
2010-08-18 12:46:04 +04:00
|
|
|
#include "propertieswidget.h"
|
2010-06-07 12:32:41 +04:00
|
|
|
#include <libtorrent/version.hpp>
|
2009-11-07 22:55:33 +03:00
|
|
|
#include <QStandardItemModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QDesktopServices>
|
2009-11-07 23:00:38 +03:00
|
|
|
#include <QTimer>
|
2009-11-07 22:55:33 +03:00
|
|
|
#include <QClipboard>
|
2009-12-15 22:52:43 +03:00
|
|
|
#include <QInputDialog>
|
2009-11-07 22:55:33 +03:00
|
|
|
#include <QColor>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QMenu>
|
2009-11-08 16:19:00 +03:00
|
|
|
#include <QRegExp>
|
2010-05-21 18:26:18 +04:00
|
|
|
#include <QFileDialog>
|
2009-11-07 22:55:33 +03:00
|
|
|
#include <vector>
|
|
|
|
|
2010-07-16 19:03:18 +04:00
|
|
|
#include "qinisettings.h"
|
|
|
|
|
2010-11-14 00:15:52 +03:00
|
|
|
TransferListWidget::TransferListWidget(QWidget *parent, MainWindow *main_window, QBtSession *_BTSession):
|
2010-10-19 20:45:23 +04:00
|
|
|
QTreeView(parent), BTSession(_BTSession), main_window(main_window) {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings("qBittorrent", "qBittorrent");
|
2009-11-07 22:55:33 +03:00
|
|
|
// Create and apply delegate
|
|
|
|
listDelegate = new TransferListDelegate(this);
|
|
|
|
setItemDelegate(listDelegate);
|
|
|
|
|
|
|
|
// Create transfer list model
|
2010-10-09 19:23:51 +04:00
|
|
|
listModel = new QStandardItemModel(0,18);
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setHeaderData(TR_NAME, Qt::Horizontal, tr("Name", "i.e: torrent name"));
|
|
|
|
listModel->setHeaderData(TR_PRIORITY, Qt::Horizontal, "#");
|
|
|
|
listModel->horizontalHeaderItem(TR_PRIORITY)->setTextAlignment(Qt::AlignRight);
|
|
|
|
listModel->setHeaderData(TR_SIZE, Qt::Horizontal, tr("Size", "i.e: torrent size"));
|
|
|
|
listModel->horizontalHeaderItem(TR_SIZE)->setTextAlignment(Qt::AlignRight);
|
|
|
|
listModel->setHeaderData(TR_PROGRESS, Qt::Horizontal, tr("Done", "% Done"));
|
|
|
|
listModel->horizontalHeaderItem(TR_PROGRESS)->setTextAlignment(Qt::AlignHCenter);
|
|
|
|
listModel->setHeaderData(TR_STATUS, Qt::Horizontal, tr("Status", "Torrent status (e.g. downloading, seeding, paused)"));
|
|
|
|
listModel->setHeaderData(TR_SEEDS, Qt::Horizontal, tr("Seeds", "i.e. full sources (often untranslated)"));
|
|
|
|
listModel->horizontalHeaderItem(TR_SEEDS)->setTextAlignment(Qt::AlignRight);
|
|
|
|
listModel->setHeaderData(TR_PEERS, Qt::Horizontal, tr("Peers", "i.e. partial sources (often untranslated)"));
|
|
|
|
listModel->horizontalHeaderItem(TR_PEERS)->setTextAlignment(Qt::AlignRight);
|
|
|
|
listModel->setHeaderData(TR_DLSPEED, Qt::Horizontal, tr("Down Speed", "i.e: Download speed"));
|
|
|
|
listModel->horizontalHeaderItem(TR_DLSPEED)->setTextAlignment(Qt::AlignRight);
|
|
|
|
listModel->setHeaderData(TR_UPSPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));;
|
|
|
|
listModel->horizontalHeaderItem(TR_UPSPEED)->setTextAlignment(Qt::AlignRight);
|
|
|
|
listModel->setHeaderData(TR_RATIO, Qt::Horizontal, tr("Ratio", "Share ratio"));
|
|
|
|
listModel->horizontalHeaderItem(TR_RATIO)->setTextAlignment(Qt::AlignRight);
|
|
|
|
listModel->setHeaderData(TR_ETA, Qt::Horizontal, tr("ETA", "i.e: Estimated Time of Arrival / Time left"));
|
2009-12-15 22:52:43 +03:00
|
|
|
listModel->setHeaderData(TR_LABEL, Qt::Horizontal, tr("Label"));
|
2010-01-30 20:47:01 +03:00
|
|
|
listModel->setHeaderData(TR_ADD_DATE, Qt::Horizontal, tr("Added On", "Torrent was added to transfer list on 01/01/2010 08:00"));
|
|
|
|
listModel->setHeaderData(TR_SEED_DATE, Qt::Horizontal, tr("Completed On", "Torrent was completed on 01/01/2010 08:00"));
|
2010-10-09 19:23:51 +04:00
|
|
|
listModel->setHeaderData(TR_TRACKER, Qt::Horizontal, tr("Tracker"));
|
2010-01-30 20:47:01 +03:00
|
|
|
listModel->setHeaderData(TR_DLLIMIT, Qt::Horizontal, tr("Down Limit", "i.e: Download limit"));
|
|
|
|
listModel->horizontalHeaderItem(TR_DLLIMIT)->setTextAlignment(Qt::AlignRight);
|
|
|
|
listModel->setHeaderData(TR_UPLIMIT, Qt::Horizontal, tr("Up Limit", "i.e: Upload limit"));;
|
|
|
|
listModel->horizontalHeaderItem(TR_UPLIMIT)->setTextAlignment(Qt::AlignRight);
|
2010-01-30 19:28:07 +03:00
|
|
|
|
2009-11-07 22:55:33 +03:00
|
|
|
|
|
|
|
// Set Sort/Filter proxy
|
2009-12-15 22:52:43 +03:00
|
|
|
labelFilterModel = new QSortFilterProxyModel();
|
|
|
|
labelFilterModel->setDynamicSortFilter(true);
|
|
|
|
labelFilterModel->setSourceModel(listModel);
|
|
|
|
labelFilterModel->setFilterKeyColumn(TR_LABEL);
|
|
|
|
labelFilterModel->setFilterRole(Qt::DisplayRole);
|
|
|
|
|
2010-08-20 16:27:20 +04:00
|
|
|
statusFilterModel = new QSortFilterProxyModel();
|
|
|
|
statusFilterModel->setDynamicSortFilter(true);
|
|
|
|
statusFilterModel->setSourceModel(labelFilterModel);
|
|
|
|
statusFilterModel->setFilterKeyColumn(TR_STATUS);
|
|
|
|
statusFilterModel->setFilterRole(Qt::DisplayRole);
|
|
|
|
|
|
|
|
nameFilterModel = new QSortFilterProxyModel();
|
|
|
|
nameFilterModel->setDynamicSortFilter(true);
|
|
|
|
nameFilterModel->setSourceModel(statusFilterModel);
|
|
|
|
nameFilterModel->setFilterKeyColumn(TR_NAME);
|
|
|
|
nameFilterModel->setFilterRole(Qt::DisplayRole);
|
|
|
|
setModel(nameFilterModel);
|
2009-11-07 22:55:33 +03:00
|
|
|
|
2009-12-15 22:52:43 +03:00
|
|
|
|
2009-11-07 22:55:33 +03:00
|
|
|
// Visual settings
|
|
|
|
setRootIsDecorated(false);
|
|
|
|
setAllColumnsShowFocus(true);
|
|
|
|
setSortingEnabled(true);
|
2009-11-08 22:54:22 +03:00
|
|
|
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
|
|
setItemsExpandable(false);
|
|
|
|
setAutoScroll(true);
|
2009-12-16 17:55:07 +03:00
|
|
|
setDragDropMode(QAbstractItemView::DragOnly);
|
2009-11-08 22:54:22 +03:00
|
|
|
|
2009-11-20 22:15:12 +03:00
|
|
|
hideColumn(TR_PRIORITY);
|
2009-12-15 22:52:43 +03:00
|
|
|
//hideColumn(TR_LABEL);
|
2009-11-20 22:15:12 +03:00
|
|
|
hideColumn(TR_HASH);
|
2009-11-07 22:55:33 +03:00
|
|
|
loadHiddenColumns();
|
2009-11-08 12:14:54 +03:00
|
|
|
// Load last columns width for transfer list
|
|
|
|
if(!loadColWidthList()) {
|
|
|
|
header()->resizeSection(0, 200);
|
|
|
|
}
|
|
|
|
loadLastSortedColumn();
|
2009-11-07 22:55:33 +03:00
|
|
|
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&)));
|
2009-11-08 12:28:34 +03:00
|
|
|
connect(BTSession, SIGNAL(metadataReceived(QTorrentHandle&)), this, SLOT(updateMetadata(QTorrentHandle&)));
|
2009-11-17 11:15:26 +03:00
|
|
|
connect(BTSession, SIGNAL(pausedTorrent(QTorrentHandle&)), this, SLOT(pauseTorrent(QTorrentHandle&)));
|
|
|
|
connect(BTSession, SIGNAL(resumedTorrent(QTorrentHandle&)), this, SLOT(resumeTorrent(QTorrentHandle&)));
|
2009-11-25 17:02:54 +03:00
|
|
|
connect(BTSession, SIGNAL(torrentFinishedChecking(QTorrentHandle&)), this, SLOT(updateMetadata(QTorrentHandle&)));
|
2010-10-30 17:55:36 +04:00
|
|
|
connect(BTSession, SIGNAL(deletedTorrent(QString)), SLOT(deleteTorrent(QString)));
|
2009-11-07 22:55:33 +03:00
|
|
|
|
|
|
|
// Listen for list events
|
|
|
|
connect(this, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(torrentDoubleClicked(QModelIndex)));
|
2009-11-08 00:04:56 +03:00
|
|
|
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayListMenu(const QPoint&)));
|
2009-11-17 12:07:37 +03:00
|
|
|
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
2009-11-07 22:55:33 +03:00
|
|
|
connect(header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&)));
|
|
|
|
|
|
|
|
// Refresh timer
|
2009-11-07 23:00:38 +03:00
|
|
|
refreshTimer = new QTimer();
|
|
|
|
refreshTimer->start(settings.value("Preferences/General/RefreshInterval", 1500).toInt());
|
|
|
|
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refreshList()));
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
TransferListWidget::~TransferListWidget() {
|
2009-11-08 12:14:54 +03:00
|
|
|
// Save settings
|
|
|
|
saveLastSortedColumn();
|
|
|
|
saveColWidthList();
|
2009-11-07 22:55:33 +03:00
|
|
|
saveHiddenColumns();
|
2009-11-08 12:14:54 +03:00
|
|
|
// Clean up
|
2009-11-07 22:55:33 +03:00
|
|
|
delete refreshTimer;
|
2009-12-15 22:52:43 +03:00
|
|
|
delete labelFilterModel;
|
2010-08-20 16:27:20 +04:00
|
|
|
delete statusFilterModel;
|
|
|
|
delete nameFilterModel;
|
2009-11-07 22:55:33 +03:00
|
|
|
delete listModel;
|
|
|
|
delete listDelegate;
|
|
|
|
}
|
|
|
|
|
2010-03-04 22:29:48 +03:00
|
|
|
void TransferListWidget::addTorrent(QTorrentHandle& h) {
|
2009-11-07 22:55:33 +03:00
|
|
|
if(!h.is_valid()) return;
|
2009-11-23 17:17:47 +03:00
|
|
|
// Check that the torrent is not already there
|
|
|
|
if(getRowFromHash(h.hash()) >= 0) return;
|
|
|
|
// Actuall add the torrent
|
2010-03-04 00:59:12 +03:00
|
|
|
const int row = listModel->rowCount();
|
2009-11-07 22:55:33 +03:00
|
|
|
try {
|
|
|
|
// Adding torrent to transfer list
|
|
|
|
listModel->insertRow(row);
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(h.name()));
|
|
|
|
listModel->setData(listModel->index(row, TR_SIZE), QVariant((qlonglong)h.actual_size()));
|
2010-05-21 15:46:12 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)MAX_ETA));
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_SEEDS), QVariant((double)0.0));
|
|
|
|
listModel->setData(listModel->index(row, TR_PEERS), QVariant((double)0.0));
|
2010-01-30 19:28:07 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_ADD_DATE), QVariant(TorrentPersistentData::getAddedDate(h.hash())));
|
|
|
|
listModel->setData(listModel->index(row, TR_SEED_DATE), QVariant(TorrentPersistentData::getSeedDate(h.hash())));
|
2010-01-30 20:47:01 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_UPLIMIT), QVariant(h.upload_limit()));
|
|
|
|
listModel->setData(listModel->index(row, TR_DLLIMIT), QVariant(h.download_limit()));
|
2010-04-06 00:07:56 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_RATIO), QVariant(BTSession->getRealRatio(h.hash())));
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString label = TorrentPersistentData::getLabel(h.hash());
|
2009-12-15 22:52:43 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_LABEL), QVariant(label));
|
2009-11-16 21:30:59 +03:00
|
|
|
if(BTSession->isQueueingEnabled())
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_PRIORITY), QVariant((int)h.queue_position()));
|
|
|
|
listModel->setData(listModel->index(row, TR_HASH), QVariant(h.hash()));
|
2009-11-07 22:55:33 +03:00
|
|
|
// Pause torrent if it is
|
|
|
|
if(h.is_paused()) {
|
2009-11-23 19:33:43 +03:00
|
|
|
if(h.is_seed()) {
|
2009-11-21 16:51:15 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED_UP);
|
2010-05-21 15:34:31 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)0));
|
2009-11-23 19:33:43 +03:00
|
|
|
} else {
|
2009-11-21 16:51:15 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED_DL);
|
2009-11-23 19:33:43 +03:00
|
|
|
}
|
2010-07-25 19:08:54 +04:00
|
|
|
if(TorrentPersistentData::hasError(h.hash()))
|
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/error.png"))), Qt::DecorationRole);
|
|
|
|
else
|
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/paused.png"))), Qt::DecorationRole);
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, QString::fromUtf8("red"));
|
2009-11-07 22:55:33 +03:00
|
|
|
}else{
|
2009-11-21 16:51:15 +03:00
|
|
|
if(h.is_seed()) {
|
2009-11-23 19:33:43 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalledUP.png"))), Qt::DecorationRole);
|
2009-11-21 16:51:15 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED_UP);
|
2010-05-21 15:34:31 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)0));
|
2009-11-21 16:51:15 +03:00
|
|
|
} else {
|
2009-11-23 19:33:43 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalledDL.png"))), Qt::DecorationRole);
|
2009-11-21 16:51:15 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED_DL);
|
|
|
|
}
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, QApplication::palette().color(QPalette::WindowText));
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
2009-11-08 22:54:22 +03:00
|
|
|
// Select first torrent to be added
|
|
|
|
if(listModel->rowCount() == 1)
|
2010-08-20 16:27:20 +04:00
|
|
|
selectionModel()->setCurrentIndex(nameFilterModel->index(row, TR_NAME), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows);
|
2009-12-16 16:09:30 +03:00
|
|
|
// Emit signal
|
2010-01-03 21:51:24 +03:00
|
|
|
emit torrentAdded(listModel->index(row, 0));
|
2009-12-16 16:09:30 +03:00
|
|
|
// Refresh the list
|
2010-05-21 18:56:56 +04:00
|
|
|
refreshList(true);
|
2009-11-07 22:55:33 +03:00
|
|
|
} catch(invalid_handle e) {
|
|
|
|
// Remove added torrent
|
|
|
|
listModel->removeRow(row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-03 21:51:24 +03:00
|
|
|
QStandardItemModel* TransferListWidget::getSourceModel() const {
|
|
|
|
return listModel;
|
|
|
|
}
|
|
|
|
|
2009-12-01 00:30:14 +03:00
|
|
|
void TransferListWidget::setRowColor(int row, QColor color) {
|
2010-03-04 00:59:12 +03:00
|
|
|
const unsigned int nbColumns = listModel->columnCount()-1;
|
2009-11-07 22:55:33 +03:00
|
|
|
for(unsigned int i=0; i<nbColumns; ++i) {
|
|
|
|
listModel->setData(listModel->index(row, i), QVariant(color), Qt::ForegroundRole);
|
|
|
|
}
|
2009-12-01 00:30:14 +03:00
|
|
|
}
|
2009-11-07 22:55:33 +03:00
|
|
|
|
2009-11-18 11:51:36 +03:00
|
|
|
void TransferListWidget::deleteTorrent(int row, bool refresh_list) {
|
2010-02-07 00:31:51 +03:00
|
|
|
Q_ASSERT(row >= 0);
|
2010-07-23 18:05:53 +04:00
|
|
|
const QModelIndex index = listModel->index(row, 0);
|
2010-02-07 00:31:51 +03:00
|
|
|
Q_ASSERT(index.isValid());
|
|
|
|
if(!index.isValid()) return;
|
|
|
|
emit torrentAboutToBeRemoved(index);
|
2009-11-07 22:55:33 +03:00
|
|
|
listModel->removeRow(row);
|
2009-11-18 11:51:36 +03:00
|
|
|
if(refresh_list)
|
2010-05-21 18:56:56 +04:00
|
|
|
refreshList(true);
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
2009-11-17 11:15:26 +03:00
|
|
|
// Wrapper slot for bittorrent signal
|
2010-03-04 22:29:48 +03:00
|
|
|
void TransferListWidget::pauseTorrent(QTorrentHandle &h) {
|
2009-11-17 11:15:26 +03:00
|
|
|
pauseTorrent(getRowFromHash(h.hash()));
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
2010-10-30 17:55:36 +04:00
|
|
|
void TransferListWidget::deleteTorrent(QString hash) {
|
|
|
|
const int row = getRowFromHash(hash);
|
|
|
|
if(row >= 0) {
|
|
|
|
deleteTorrent(row, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-18 11:51:36 +03:00
|
|
|
void TransferListWidget::pauseTorrent(int row, bool refresh_list) {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row));
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_DLSPEED), QVariant((double)0.0));
|
|
|
|
listModel->setData(listModel->index(row, TR_UPSPEED), QVariant((double)0.0));
|
2010-08-22 00:12:16 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_PROGRESS), h.progress());
|
2009-11-21 16:51:15 +03:00
|
|
|
if(h.is_seed()) {
|
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED_UP);
|
2010-07-25 19:08:54 +04:00
|
|
|
if(h.has_error() || TorrentPersistentData::hasError(h.hash())) {
|
2010-05-24 18:19:25 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), h.error(), Qt::ToolTipRole);
|
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QIcon(QString::fromUtf8(":/Icons/skin/error.png")), Qt::DecorationRole);
|
|
|
|
} else {
|
2010-05-24 18:43:31 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QIcon(QString::fromUtf8(":/Icons/skin/paused.png")), Qt::DecorationRole);
|
2010-05-24 18:19:25 +04:00
|
|
|
}
|
2009-11-21 16:51:15 +03:00
|
|
|
} else {
|
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED_DL);
|
2010-07-25 19:08:54 +04:00
|
|
|
if(h.has_error() || TorrentPersistentData::hasError(h.hash())) {
|
2010-05-24 18:19:25 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), h.error(), Qt::ToolTipRole);
|
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QIcon(QString::fromUtf8(":/Icons/skin/error.png")), Qt::DecorationRole);
|
|
|
|
} else {
|
2010-05-24 18:43:31 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QIcon(QString::fromUtf8(":/Icons/skin/paused.png")), Qt::DecorationRole);
|
2010-05-24 18:19:25 +04:00
|
|
|
}
|
2010-05-21 15:46:12 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)MAX_ETA));
|
2009-11-21 16:51:15 +03:00
|
|
|
}
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_SEEDS), QVariant(0.0));
|
|
|
|
listModel->setData(listModel->index(row, TR_PEERS), QVariant(0.0));
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, QString::fromUtf8("red"));
|
2009-11-18 11:51:36 +03:00
|
|
|
if(refresh_list)
|
|
|
|
refreshList();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
2009-12-16 16:09:30 +03:00
|
|
|
|
|
|
|
int TransferListWidget::getNbTorrents() const {
|
|
|
|
return listModel->rowCount();
|
|
|
|
}
|
|
|
|
|
2009-11-17 11:15:26 +03:00
|
|
|
// Wrapper slot for bittorrent signal
|
2010-03-04 22:29:48 +03:00
|
|
|
void TransferListWidget::resumeTorrent(QTorrentHandle &h) {
|
2009-11-17 11:15:26 +03:00
|
|
|
resumeTorrent(getRowFromHash(h.hash()));
|
|
|
|
}
|
|
|
|
|
2009-11-18 11:51:36 +03:00
|
|
|
void TransferListWidget::resumeTorrent(int row, bool refresh_list) {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QTorrentHandle h = BTSession->getTorrentHandle(getHashFromRow(row));
|
2009-11-07 22:55:33 +03:00
|
|
|
if(!h.is_valid()) return;
|
2009-11-08 16:19:00 +03:00
|
|
|
if(h.is_seed()) {
|
2009-11-23 19:33:43 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(":/Icons/skin/stalledUP.png")), Qt::DecorationRole);
|
2009-11-21 16:51:15 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED_UP);
|
2009-11-16 21:30:59 +03:00
|
|
|
} else {
|
2009-11-23 19:33:43 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(":/Icons/skin/stalledDL.png")), Qt::DecorationRole);
|
2009-11-21 16:51:15 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED_DL);
|
2009-11-08 16:19:00 +03:00
|
|
|
}
|
2010-05-24 18:19:25 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), "", Qt::ToolTipRole);
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, QApplication::palette().color(QPalette::WindowText));
|
2009-11-18 11:51:36 +03:00
|
|
|
if(refresh_list)
|
|
|
|
refreshList();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
2010-03-04 22:29:48 +03:00
|
|
|
void TransferListWidget::updateMetadata(QTorrentHandle &h) {
|
2010-08-22 20:55:57 +04:00
|
|
|
if(!h.is_valid()) return;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString hash = h.hash();
|
2010-03-04 00:59:12 +03:00
|
|
|
const int row = getRowFromHash(hash);
|
2009-11-08 12:28:34 +03:00
|
|
|
if(row != -1) {
|
|
|
|
qDebug("Updating torrent metadata in download list");
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(h.name()));
|
|
|
|
listModel->setData(listModel->index(row, TR_SIZE), QVariant((qlonglong)h.actual_size()));
|
2009-11-25 17:02:54 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_PROGRESS), QVariant((double)h.progress()));
|
2009-11-08 12:28:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-27 14:38:42 +03:00
|
|
|
void TransferListWidget::previewFile(QString filePath) {
|
2010-07-25 19:30:26 +04:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
QDesktopServices::openUrl(QUrl(QString("file:///")+filePath));
|
|
|
|
#else
|
2010-03-07 00:11:47 +03:00
|
|
|
QDesktopServices::openUrl(QUrl(QString("file://")+filePath));
|
2010-07-25 19:30:26 +04:00
|
|
|
#endif
|
2009-11-27 14:38:42 +03:00
|
|
|
}
|
|
|
|
|
2009-11-18 11:51:36 +03:00
|
|
|
int TransferListWidget::updateTorrent(int row) {
|
|
|
|
TorrentState s = STATE_INVALID;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString hash = getHashFromRow(row);
|
|
|
|
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-11-07 22:55:33 +03:00
|
|
|
if(!h.is_valid()) {
|
2010-02-07 00:31:51 +03:00
|
|
|
// Torrent will be deleted from list by caller
|
2009-11-18 11:51:36 +03:00
|
|
|
return s;
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
try {
|
2010-01-30 20:47:01 +03:00
|
|
|
if(!isColumnHidden(TR_SEEDS)) {
|
|
|
|
// Connected_seeds*100000+total_seeds*10 (if total_seeds is available)
|
|
|
|
// Connected_seeds*100000+1 (if total_seeds is unavailable)
|
|
|
|
qulonglong seeds = h.num_seeds()*1000000;
|
|
|
|
if(h.num_complete() >= h.num_seeds())
|
|
|
|
seeds += h.num_complete()*10;
|
|
|
|
else
|
|
|
|
seeds += 1;
|
|
|
|
listModel->setData(listModel->index(row, TR_SEEDS), QVariant(seeds));
|
|
|
|
}
|
|
|
|
if(!isColumnHidden(TR_PEERS)) {
|
|
|
|
qulonglong peers = (h.num_peers()-h.num_seeds())*1000000;
|
|
|
|
if(h.num_incomplete() >= (h.num_peers()-h.num_seeds()))
|
|
|
|
peers += h.num_incomplete()*10;
|
|
|
|
else
|
|
|
|
peers += 1;
|
|
|
|
listModel->setData(listModel->index(row, TR_PEERS), QVariant(peers));
|
|
|
|
}
|
2010-10-09 19:23:51 +04:00
|
|
|
if(!isColumnHidden(TR_TRACKER)) {
|
|
|
|
listModel->setData(listModel->index(row, TR_TRACKER), QVariant(h.current_tracker()));
|
|
|
|
}
|
2009-11-24 18:38:47 +03:00
|
|
|
// Update torrent size. It changes when files are filtered from torrent properties
|
|
|
|
// or Web UI
|
|
|
|
listModel->setData(listModel->index(row, TR_SIZE), QVariant((qlonglong)h.actual_size()));
|
2010-01-30 20:47:01 +03:00
|
|
|
// Update Up/Dl limits
|
|
|
|
if(!isColumnHidden(TR_UPLIMIT))
|
|
|
|
listModel->setData(listModel->index(row, TR_UPLIMIT), QVariant((qlonglong)h.upload_limit()));
|
|
|
|
if(!isColumnHidden(TR_DLLIMIT))
|
|
|
|
listModel->setData(listModel->index(row, TR_DLLIMIT), QVariant((qlonglong)h.download_limit()));
|
2009-11-18 20:32:54 +03:00
|
|
|
// Queueing code
|
2010-10-19 20:45:23 +04:00
|
|
|
if(BTSession->isQueueingEnabled()) {
|
|
|
|
if(h.is_seed())
|
|
|
|
listModel->setData(listModel->index(row, TR_PRIORITY), -1);
|
|
|
|
else
|
|
|
|
listModel->setData(listModel->index(row, TR_PRIORITY), QVariant((int)h.queue_position()));
|
2009-11-18 20:32:54 +03:00
|
|
|
if(h.is_queued()) {
|
|
|
|
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) {
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_PROGRESS), QVariant((double)h.progress()));
|
2009-11-23 19:33:43 +03:00
|
|
|
if(h.is_seed()) {
|
2009-11-21 16:51:15 +03:00
|
|
|
s = STATE_CHECKING_UP;
|
2009-11-23 19:33:43 +03:00
|
|
|
} else {
|
2009-11-21 16:51:15 +03:00
|
|
|
s = STATE_CHECKING_DL;
|
2009-11-23 19:33:43 +03:00
|
|
|
}
|
2010-05-24 18:43:31 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/checking.png"))), Qt::DecorationRole);
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), s);
|
2010-10-19 20:45:23 +04:00
|
|
|
} else {
|
2010-05-21 15:46:12 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)MAX_ETA));
|
2009-11-23 19:33:43 +03:00
|
|
|
if(h.is_seed()) {
|
2010-05-24 18:43:31 +04:00
|
|
|
s = STATE_QUEUED_UP;
|
2009-11-23 19:33:43 +03:00
|
|
|
} else {
|
2010-11-03 23:53:55 +03:00
|
|
|
s = STATE_QUEUED_DL;
|
2009-11-23 19:33:43 +03:00
|
|
|
}
|
2010-05-24 18:43:31 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/queued.png"))), Qt::DecorationRole);
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), s);
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
2009-11-18 20:32:54 +03:00
|
|
|
// Reset speeds and seeds/leech
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_DLSPEED), QVariant((double)0.));
|
|
|
|
listModel->setData(listModel->index(row, TR_UPSPEED), QVariant((double)0.));
|
2010-01-30 20:47:01 +03:00
|
|
|
if(!isColumnHidden(TR_SEEDS))
|
|
|
|
listModel->setData(listModel->index(row, TR_SEEDS), QVariant(0.0));
|
|
|
|
if(!isColumnHidden(TR_PEERS))
|
|
|
|
listModel->setData(listModel->index(row, TR_PEERS), QVariant(0.0));
|
2010-03-04 00:59:12 +03:00
|
|
|
setRowColor(row, "grey");
|
2009-11-18 20:32:54 +03:00
|
|
|
return s;
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
2009-11-18 20:32:54 +03:00
|
|
|
}
|
2009-11-24 18:38:47 +03:00
|
|
|
|
2009-11-21 16:51:15 +03:00
|
|
|
if(h.is_paused()) {
|
2010-08-22 20:55:57 +04:00
|
|
|
// XXX: Force progress update because of bug #621381
|
|
|
|
listModel->setData(listModel->index(row, TR_PROGRESS), QVariant((double)h.progress()));
|
2009-11-21 16:51:15 +03:00
|
|
|
if(h.is_seed())
|
|
|
|
return STATE_PAUSED_UP;
|
|
|
|
return STATE_PAUSED_DL;
|
|
|
|
}
|
2009-11-07 22:55:33 +03:00
|
|
|
|
2009-11-18 20:32:54 +03:00
|
|
|
// 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:
|
2009-11-23 19:33:43 +03:00
|
|
|
if(h.is_seed()) {
|
2009-11-21 16:51:15 +03:00
|
|
|
s = STATE_CHECKING_UP;
|
2009-11-23 19:33:43 +03:00
|
|
|
} else {
|
2009-11-21 16:51:15 +03:00
|
|
|
s = STATE_CHECKING_DL;
|
2009-11-23 19:33:43 +03:00
|
|
|
}
|
2010-05-24 18:43:31 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/checking.png"))), Qt::DecorationRole);
|
2009-11-21 17:42:58 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_PROGRESS), QVariant((double)h.progress()));
|
2010-01-30 20:47:01 +03:00
|
|
|
if(!isColumnHidden(TR_ETA))
|
2010-05-21 15:46:12 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)MAX_ETA));
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, QString::fromUtf8("grey"));
|
2009-11-18 20:32:54 +03:00
|
|
|
break;
|
|
|
|
case torrent_status::downloading:
|
|
|
|
case torrent_status::downloading_metadata:
|
|
|
|
if(h.download_payload_rate() > 0) {
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png"))), Qt::DecorationRole);
|
2010-01-30 20:47:01 +03:00
|
|
|
if(!isColumnHidden(TR_ETA))
|
|
|
|
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)BTSession->getETA(hash)));
|
2009-11-18 20:32:54 +03:00
|
|
|
s = STATE_DOWNLOADING;
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, QString::fromUtf8("green"));
|
2009-11-18 20:32:54 +03:00
|
|
|
}else{
|
2009-11-23 19:33:43 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalledDL.png"))), Qt::DecorationRole);
|
2010-01-30 20:47:01 +03:00
|
|
|
if(!isColumnHidden(TR_ETA))
|
2010-05-21 15:46:12 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)MAX_ETA));
|
2009-11-21 16:51:15 +03:00
|
|
|
s = STATE_STALLED_DL;
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, QApplication::palette().color(QPalette::WindowText));
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
2009-11-21 17:42:58 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_DLSPEED), QVariant((double)h.download_payload_rate()));
|
|
|
|
listModel->setData(listModel->index(row, TR_PROGRESS), QVariant((double)h.progress()));
|
2009-11-18 20:32:54 +03:00
|
|
|
break;
|
|
|
|
case torrent_status::finished:
|
|
|
|
case torrent_status::seeding:
|
2009-11-21 16:51:15 +03:00
|
|
|
if(h.upload_payload_rate() > 0) {
|
|
|
|
s = STATE_SEEDING;
|
2009-11-27 19:11:22 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/uploading.png"))), Qt::DecorationRole);
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, "orange");
|
2009-11-21 16:51:15 +03:00
|
|
|
} else {
|
|
|
|
s = STATE_STALLED_UP;
|
2009-11-27 19:11:22 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalledUP.png"))), Qt::DecorationRole);
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, QApplication::palette().color(QPalette::WindowText));
|
2009-11-21 16:51:15 +03:00
|
|
|
}
|
2010-02-04 23:18:58 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_PROGRESS), QVariant((double)1.));
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
// Common to both downloads and uploads
|
2009-11-21 17:42:58 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), s);
|
|
|
|
listModel->setData(listModel->index(row, TR_UPSPEED), QVariant((double)h.upload_payload_rate()));
|
2009-11-16 21:30:59 +03:00
|
|
|
// Share ratio
|
2010-01-30 20:47:01 +03:00
|
|
|
if(!isColumnHidden(TR_RATIO))
|
|
|
|
listModel->setData(listModel->index(row, TR_RATIO), QVariant(BTSession->getRealRatio(hash)));
|
2010-02-07 00:31:51 +03:00
|
|
|
}catch(invalid_handle) {
|
|
|
|
// Torrent will be deleted by caller
|
2009-11-18 11:51:36 +03:00
|
|
|
s = STATE_INVALID;
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
2009-11-18 11:51:36 +03:00
|
|
|
return s;
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
2010-03-04 22:29:48 +03:00
|
|
|
void TransferListWidget::setFinished(QTorrentHandle &h) {
|
2010-03-04 00:59:12 +03:00
|
|
|
const int row = getRowFromHash(h.hash());
|
2009-11-07 22:55:33 +03:00
|
|
|
try {
|
|
|
|
if(row >= 0) {
|
|
|
|
if(h.is_paused()) {
|
2010-05-24 18:43:31 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole);
|
2009-11-21 16:51:15 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), STATE_PAUSED_UP);
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, "red");
|
2009-11-07 22:55:33 +03:00
|
|
|
}else{
|
2009-11-23 19:33:43 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_NAME), QVariant(QIcon(":/Icons/skin/stalledUP.png")), Qt::DecorationRole);
|
2009-11-21 16:51:15 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_STATUS), STATE_STALLED_UP);
|
2009-12-01 00:30:14 +03:00
|
|
|
setRowColor(row, QApplication::palette().color(QPalette::WindowText));
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
2010-05-21 15:25:30 +04:00
|
|
|
listModel->setData(listModel->index(row, TR_ETA), QVariant((qlonglong)0));
|
2009-11-20 22:15:12 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_DLSPEED), QVariant((double)0.));
|
|
|
|
listModel->setData(listModel->index(row, TR_PROGRESS), QVariant((double)1.));
|
|
|
|
listModel->setData(listModel->index(row, TR_PRIORITY), QVariant((int)-1));
|
2010-01-30 19:28:07 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_SEED_DATE), QVariant(TorrentPersistentData::getSeedDate(h.hash())));
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
2010-03-04 00:59:12 +03:00
|
|
|
} catch(invalid_handle) {
|
2009-12-16 16:09:30 +03:00
|
|
|
if(row >= 0) {
|
|
|
|
deleteTorrent(row);
|
|
|
|
}
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::setRefreshInterval(int t) {
|
2009-11-22 21:08:05 +03:00
|
|
|
qDebug("Settings transfer list refresh interval to %dms", t);
|
2009-11-07 23:00:38 +03:00
|
|
|
refreshTimer->start(t);
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
2010-05-21 18:56:56 +04:00
|
|
|
void TransferListWidget::refreshList(bool force) {
|
2010-01-24 21:06:51 +03:00
|
|
|
// Stop updating the display
|
|
|
|
setUpdatesEnabled(false);
|
2009-11-21 17:16:54 +03:00
|
|
|
// Refresh only if displayed
|
2010-07-19 22:49:53 +04:00
|
|
|
if(!force && main_window->getCurrentTabWidget() != this) return;
|
2010-05-24 19:16:14 +04:00
|
|
|
unsigned int nb_downloading = 0, nb_seeding=0, nb_active=0, nb_inactive = 0, nb_paused = 0;
|
2010-01-23 22:01:10 +03:00
|
|
|
if(BTSession->getSession()->get_torrents().size() != (uint)listModel->rowCount()) {
|
2010-05-24 18:43:31 +04:00
|
|
|
// Oups, we have torrents that are not displayed, fix this
|
2010-01-23 22:01:10 +03:00
|
|
|
std::vector<torrent_handle> torrents = BTSession->getSession()->get_torrents();
|
2010-03-04 00:59:12 +03:00
|
|
|
std::vector<torrent_handle>::iterator itr;
|
|
|
|
for(itr = torrents.begin(); itr != torrents.end(); itr++) {
|
2010-03-04 22:29:48 +03:00
|
|
|
QTorrentHandle h(*itr);
|
2010-01-23 22:01:10 +03:00
|
|
|
if(h.is_valid() && getRowFromHash(h.hash()) < 0) {
|
|
|
|
addTorrent(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-01-23 22:15:00 +03:00
|
|
|
QStringList bad_hashes;
|
2009-11-07 22:55:33 +03:00
|
|
|
for(int i=0; i<listModel->rowCount(); ++i) {
|
2010-03-04 00:59:12 +03:00
|
|
|
const int s = updateTorrent(i);
|
2009-11-18 11:51:36 +03:00
|
|
|
switch(s) {
|
|
|
|
case STATE_DOWNLOADING:
|
2009-11-21 16:51:15 +03:00
|
|
|
++nb_active;
|
|
|
|
++nb_downloading;
|
|
|
|
break;
|
|
|
|
case STATE_STALLED_DL:
|
|
|
|
case STATE_CHECKING_DL:
|
|
|
|
case STATE_PAUSED_DL:
|
2010-05-24 19:16:14 +04:00
|
|
|
case STATE_QUEUED_DL: {
|
2010-10-19 20:45:23 +04:00
|
|
|
if(s == STATE_PAUSED_DL) {
|
|
|
|
++nb_paused;
|
2010-07-20 13:02:41 +04:00
|
|
|
}
|
2010-10-19 20:45:23 +04:00
|
|
|
++nb_inactive;
|
|
|
|
++nb_downloading;
|
|
|
|
break;
|
|
|
|
}
|
2009-11-18 11:51:36 +03:00
|
|
|
case STATE_SEEDING:
|
2009-11-21 16:51:15 +03:00
|
|
|
++nb_active;
|
2009-11-18 11:51:36 +03:00
|
|
|
++nb_seeding;
|
|
|
|
break;
|
2009-11-21 16:51:15 +03:00
|
|
|
case STATE_STALLED_UP:
|
|
|
|
case STATE_CHECKING_UP:
|
|
|
|
case STATE_PAUSED_UP:
|
2010-05-24 19:16:14 +04:00
|
|
|
case STATE_QUEUED_UP: {
|
2010-10-19 20:45:23 +04:00
|
|
|
if(s == STATE_PAUSED_UP) {
|
|
|
|
++nb_paused;
|
2010-07-20 13:02:41 +04:00
|
|
|
}
|
2010-10-19 20:45:23 +04:00
|
|
|
++nb_seeding;
|
|
|
|
++nb_inactive;
|
|
|
|
break;
|
|
|
|
}
|
2010-01-23 22:15:00 +03:00
|
|
|
case STATE_INVALID:
|
|
|
|
bad_hashes << getHashFromRow(i);
|
|
|
|
break;
|
2009-11-18 11:51:36 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
2010-01-23 22:15:00 +03:00
|
|
|
// Remove bad torrents from list
|
2010-03-04 00:59:12 +03:00
|
|
|
foreach(const QString &hash, bad_hashes) {
|
|
|
|
const int row = getRowFromHash(hash);
|
2010-02-07 00:31:51 +03:00
|
|
|
if(row >= 0)
|
|
|
|
deleteTorrent(row, false);
|
2010-01-23 22:15:00 +03:00
|
|
|
}
|
|
|
|
// Update status filters counters
|
2010-05-24 19:16:14 +04:00
|
|
|
emit torrentStatusUpdate(nb_downloading, nb_seeding, nb_active, nb_inactive, nb_paused);
|
2010-01-24 21:06:51 +03:00
|
|
|
// Start updating the display
|
|
|
|
setUpdatesEnabled(true);
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int TransferListWidget::getRowFromHash(QString hash) const{
|
2010-07-23 18:05:53 +04:00
|
|
|
const QList<QStandardItem *> items = listModel->findItems(hash, Qt::MatchExactly, TR_HASH);
|
2009-11-07 22:55:33 +03:00
|
|
|
if(items.empty()) return -1;
|
|
|
|
Q_ASSERT(items.size() == 1);
|
|
|
|
return items.first()->row();
|
|
|
|
}
|
|
|
|
|
2010-03-04 00:59:12 +03:00
|
|
|
inline QString TransferListWidget::getHashFromRow(int row) const {
|
2009-11-20 22:15:12 +03:00
|
|
|
return listModel->data(listModel->index(row, TR_HASH)).toString();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
2010-03-04 00:59:12 +03:00
|
|
|
inline QModelIndex TransferListWidget::mapToSource(const QModelIndex &index) const {
|
2010-09-28 20:53:58 +04:00
|
|
|
Q_ASSERT(index.isValid());
|
|
|
|
if(index.model() == nameFilterModel)
|
|
|
|
return labelFilterModel->mapToSource(statusFilterModel->mapToSource(nameFilterModel->mapToSource(index)));
|
|
|
|
if(index.model() == statusFilterModel)
|
|
|
|
return labelFilterModel->mapToSource(statusFilterModel->mapToSource(index));
|
|
|
|
return labelFilterModel->mapToSource(index);
|
2009-12-15 22:52:43 +03:00
|
|
|
}
|
|
|
|
|
2010-03-04 00:59:12 +03:00
|
|
|
inline QModelIndex TransferListWidget::mapFromSource(const QModelIndex &index) const {
|
2010-09-28 20:53:58 +04:00
|
|
|
Q_ASSERT(index.isValid());
|
|
|
|
Q_ASSERT(index.model() == labelFilterModel);
|
2010-08-20 16:27:20 +04:00
|
|
|
return nameFilterModel->mapFromSource(statusFilterModel->mapFromSource(labelFilterModel->mapFromSource(index)));
|
2010-01-03 17:38:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 22:52:43 +03:00
|
|
|
QStringList TransferListWidget::getCustomLabels() const {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
2010-03-04 00:59:12 +03:00
|
|
|
return settings.value("TransferListFilters/customLabels", QStringList()).toStringList();
|
2009-12-15 22:52:43 +03:00
|
|
|
}
|
|
|
|
|
2010-03-04 00:59:12 +03:00
|
|
|
void TransferListWidget::torrentDoubleClicked(const QModelIndex& index) {
|
|
|
|
const int row = mapToSource(index).row();
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString hash = getHashFromRow(row);
|
2009-11-07 22:55:33 +03:00
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
|
|
|
if(!h.is_valid()) return;
|
|
|
|
int action;
|
|
|
|
if(h.is_seed()) {
|
2010-05-21 16:30:57 +04:00
|
|
|
action = Preferences::getActionOnDblClOnTorrentFn();
|
2009-11-07 22:55:33 +03:00
|
|
|
} else {
|
2010-05-21 16:30:57 +04:00
|
|
|
action = Preferences::getActionOnDblClOnTorrentDl();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(action) {
|
|
|
|
case TOGGLE_PAUSE:
|
|
|
|
if(h.is_paused()) {
|
|
|
|
h.resume();
|
|
|
|
resumeTorrent(row);
|
|
|
|
} else {
|
|
|
|
h.pause();
|
|
|
|
pauseTorrent(row);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case OPEN_DEST:
|
2010-07-20 13:02:41 +04:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
QDesktopServices::openUrl(QUrl("file:///" + h.save_path()));
|
|
|
|
#else
|
|
|
|
QDesktopServices::openUrl(QUrl("file://" + h.save_path()));
|
|
|
|
#endif
|
2009-11-07 22:55:33 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-09 23:44:33 +03:00
|
|
|
QStringList TransferListWidget::getSelectedTorrentsHashes() const {
|
|
|
|
QStringList hashes;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
2009-11-07 22:55:33 +03:00
|
|
|
foreach(const QModelIndex &index, selectedIndexes) {
|
2010-02-09 23:44:33 +03:00
|
|
|
hashes << getHashFromRow(mapToSource(index).row());
|
|
|
|
}
|
|
|
|
return hashes;
|
|
|
|
}
|
|
|
|
|
2010-05-21 18:26:18 +04:00
|
|
|
void TransferListWidget::setSelectedTorrentsLocation() {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-05-21 18:26:18 +04:00
|
|
|
if(hashes.isEmpty()) return;
|
|
|
|
QString dir;
|
2010-08-18 12:46:04 +04:00
|
|
|
const QDir saveDir(TorrentPersistentData::getSavePath(hashes.first()));
|
2010-10-18 23:23:39 +04:00
|
|
|
qDebug("Old save path is %s", qPrintable(saveDir.absolutePath()));
|
|
|
|
QFileDialog dlg(this, tr("Choose save path"), saveDir.absolutePath());
|
|
|
|
dlg.setConfirmOverwrite(false);
|
|
|
|
dlg.setFileMode(QFileDialog::Directory);
|
|
|
|
dlg.setOption(QFileDialog::ShowDirsOnly, true);
|
|
|
|
dlg.setFilter(QDir::AllDirs);
|
|
|
|
dlg.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
|
dlg.setNameFilterDetailsVisible(false);
|
|
|
|
if(dlg.exec())
|
|
|
|
dir = dlg.selectedFiles().first();
|
|
|
|
if(!dir.isNull()) {
|
|
|
|
qDebug("New path is %s", qPrintable(dir));
|
2010-05-21 18:26:18 +04:00
|
|
|
// Check if savePath exists
|
|
|
|
QDir savePath(misc::expandPath(dir));
|
2010-10-18 23:23:39 +04:00
|
|
|
qDebug("New path after clean up is %s", qPrintable(savePath.absolutePath()));
|
2010-05-21 18:26:18 +04:00
|
|
|
foreach(const QString & hash, hashes) {
|
2010-07-20 13:02:41 +04:00
|
|
|
// Actually move storage
|
2010-05-21 18:26:18 +04:00
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2010-08-18 12:46:04 +04:00
|
|
|
if(!BTSession->useTemporaryFolder() || h.is_seed()) {
|
2010-10-18 23:23:39 +04:00
|
|
|
if(!savePath.exists()) savePath.mkpath(savePath.absolutePath());
|
2010-07-20 13:02:41 +04:00
|
|
|
h.move_storage(savePath.absolutePath());
|
2010-08-18 12:46:04 +04:00
|
|
|
} else {
|
|
|
|
TorrentPersistentData::saveSavePath(h.hash(), savePath.absolutePath());
|
|
|
|
main_window->getProperties()->updateSavePath(h);
|
|
|
|
}
|
2010-05-21 18:26:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-09 23:44:33 +03:00
|
|
|
void TransferListWidget::startSelectedTorrents() {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2009-11-07 22:55:33 +03:00
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
|
|
|
if(h.is_valid() && h.is_paused()) {
|
|
|
|
h.resume();
|
2010-02-09 23:44:33 +03:00
|
|
|
resumeTorrent(getRowFromHash(hash), false);
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
2010-02-09 23:44:33 +03:00
|
|
|
if(!hashes.empty())
|
2009-11-18 11:51:36 +03:00
|
|
|
refreshList();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2009-11-18 11:51:36 +03:00
|
|
|
resumeTorrent(i, false);
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
2009-11-18 11:51:36 +03:00
|
|
|
refreshList();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
2010-08-17 12:42:30 +04:00
|
|
|
void TransferListWidget::startVisibleTorrents() {
|
2010-08-18 12:07:17 +04:00
|
|
|
QStringList hashes;
|
2010-08-20 16:27:20 +04:00
|
|
|
for(int i=0; i<nameFilterModel->rowCount(); ++i) {
|
|
|
|
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
2010-08-18 12:07:17 +04:00
|
|
|
hashes << getHashFromRow(row);
|
|
|
|
}
|
|
|
|
foreach(const QString &hash, hashes) {
|
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2010-08-17 12:42:30 +04:00
|
|
|
if(h.is_valid() && h.is_paused()) {
|
|
|
|
h.resume();
|
2010-08-18 12:07:17 +04:00
|
|
|
resumeTorrent(getRowFromHash(hash), false);
|
2010-08-17 12:42:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
|
2009-11-07 22:55:33 +03:00
|
|
|
void TransferListWidget::pauseSelectedTorrents() {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2009-11-07 22:55:33 +03:00
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
|
|
|
if(h.is_valid() && !h.is_paused()) {
|
|
|
|
h.pause();
|
2010-02-09 23:44:33 +03:00
|
|
|
pauseTorrent(getRowFromHash(hash), false);
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
2010-02-09 23:44:33 +03:00
|
|
|
if(!hashes.empty())
|
2009-11-18 11:51:36 +03:00
|
|
|
refreshList();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2009-11-18 11:51:36 +03:00
|
|
|
pauseTorrent(i, false);
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
2009-11-18 11:51:36 +03:00
|
|
|
refreshList();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
2010-08-17 12:42:30 +04:00
|
|
|
void TransferListWidget::pauseVisibleTorrents() {
|
2010-08-18 12:07:17 +04:00
|
|
|
QStringList hashes;
|
2010-08-20 16:27:20 +04:00
|
|
|
for(int i=0; i<nameFilterModel->rowCount(); ++i) {
|
|
|
|
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
2010-08-18 12:07:17 +04:00
|
|
|
hashes << getHashFromRow(row);
|
|
|
|
}
|
|
|
|
foreach(const QString &hash, hashes) {
|
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2010-08-17 12:42:30 +04:00
|
|
|
if(h.is_valid() && !h.is_paused()) {
|
|
|
|
h.pause();
|
2010-08-18 12:07:17 +04:00
|
|
|
pauseTorrent(getRowFromHash(hash), false);
|
2010-08-17 12:42:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
|
2009-11-07 22:55:33 +03:00
|
|
|
void TransferListWidget::deleteSelectedTorrents() {
|
2010-07-19 22:49:53 +04:00
|
|
|
if(main_window->getCurrentTabWidget() != this) return;
|
2010-03-04 00:59:12 +03:00
|
|
|
const QStringList& hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
if(!hashes.empty()) {
|
2009-11-18 15:11:15 +03:00
|
|
|
bool delete_local_files = false;
|
|
|
|
if(DeletionConfirmationDlg::askForDeletionConfirmation(&delete_local_files)) {
|
|
|
|
foreach(const QString &hash, hashes) {
|
2010-03-04 00:59:12 +03:00
|
|
|
const int row = getRowFromHash(hash);
|
2009-12-16 16:09:30 +03:00
|
|
|
deleteTorrent(row, false);
|
2009-11-18 15:11:15 +03:00
|
|
|
BTSession->deleteTorrent(hash, delete_local_files);
|
|
|
|
}
|
|
|
|
refreshList();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-17 12:42:30 +04:00
|
|
|
void TransferListWidget::deleteVisibleTorrents() {
|
2010-08-20 16:27:20 +04:00
|
|
|
if(nameFilterModel->rowCount() <= 0) return;
|
2010-08-17 12:42:30 +04:00
|
|
|
bool delete_local_files = false;
|
|
|
|
if(DeletionConfirmationDlg::askForDeletionConfirmation(&delete_local_files)) {
|
|
|
|
QStringList hashes;
|
2010-08-20 16:27:20 +04:00
|
|
|
for(int i=0; i<nameFilterModel->rowCount(); ++i) {
|
|
|
|
const int row = mapToSource(nameFilterModel->index(i, 0)).row();
|
2010-08-17 12:42:30 +04:00
|
|
|
hashes << getHashFromRow(row);
|
|
|
|
}
|
|
|
|
foreach(const QString &hash, hashes) {
|
|
|
|
const int row = getRowFromHash(hash);
|
|
|
|
deleteTorrent(row, false);
|
|
|
|
BTSession->deleteTorrent(hash, delete_local_files);
|
|
|
|
}
|
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-07 22:55:33 +03:00
|
|
|
void TransferListWidget::increasePrioSelectedTorrents() {
|
2010-08-15 11:45:20 +04:00
|
|
|
if(main_window->getCurrentTabWidget() != this) return;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-11-07 22:55:33 +03:00
|
|
|
if(h.is_valid() && !h.is_seed()) {
|
2009-11-17 11:15:26 +03:00
|
|
|
h.queue_position_up();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
2009-11-08 12:50:29 +03:00
|
|
|
refreshList();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::decreasePrioSelectedTorrents() {
|
2010-08-15 11:45:20 +04:00
|
|
|
if(main_window->getCurrentTabWidget() != this) return;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-11-07 22:55:33 +03:00
|
|
|
if(h.is_valid() && !h.is_seed()) {
|
2009-11-17 11:15:26 +03:00
|
|
|
h.queue_position_down();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
2009-11-08 12:50:29 +03:00
|
|
|
refreshList();
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
2010-08-14 19:53:05 +04:00
|
|
|
void TransferListWidget::topPrioSelectedTorrents() {
|
2010-08-15 11:47:33 +04:00
|
|
|
if(main_window->getCurrentTabWidget() != this) return;
|
2010-08-14 19:53:05 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
|
|
|
foreach(const QString &hash, hashes) {
|
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
|
|
|
if(h.is_valid() && !h.is_seed()) {
|
|
|
|
h.queue_position_top();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::bottomPrioSelectedTorrents() {
|
2010-08-15 11:47:33 +04:00
|
|
|
if(main_window->getCurrentTabWidget() != this) return;
|
2010-08-14 19:53:05 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
|
|
|
foreach(const QString &hash, hashes) {
|
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
|
|
|
if(h.is_valid() && !h.is_seed()) {
|
|
|
|
h.queue_position_bottom();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
refreshList();
|
|
|
|
}
|
|
|
|
|
2009-11-07 22:55:33 +03:00
|
|
|
void TransferListWidget::buySelectedTorrents() const {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-11-07 22:55:33 +03:00
|
|
|
if(h.is_valid())
|
2010-03-07 00:11:47 +03:00
|
|
|
QDesktopServices::openUrl(QUrl("http://match.sharemonkey.com/?info_hash="+h.hash()+"&n="+h.name()+"&cid=33"));
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::copySelectedMagnetURIs() const {
|
|
|
|
QStringList magnet_uris;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-12-02 23:24:34 +03:00
|
|
|
if(h.is_valid() && h.has_metadata())
|
2009-11-07 22:55:33 +03:00
|
|
|
magnet_uris << misc::toQString(make_magnet_uri(h.get_torrent_info()));
|
|
|
|
}
|
|
|
|
qApp->clipboard()->setText(magnet_uris.join("\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::hidePriorityColumn(bool hide) {
|
2010-10-18 21:06:11 +04:00
|
|
|
qDebug("hidePriorityColumn(%d)", hide);
|
2009-11-20 22:15:12 +03:00
|
|
|
setColumnHidden(TR_PRIORITY, hide);
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::openSelectedTorrentsFolder() const {
|
|
|
|
QStringList pathsList;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-11-07 22:55:33 +03:00
|
|
|
if(h.is_valid()) {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString savePath = h.save_path();
|
2010-06-04 00:08:19 +04:00
|
|
|
qDebug("Opening path at %s", qPrintable(savePath));
|
2009-11-07 22:55:33 +03:00
|
|
|
if(!pathsList.contains(savePath)) {
|
|
|
|
pathsList.append(savePath);
|
2010-06-04 00:08:19 +04:00
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
QDesktopServices::openUrl(QUrl(QString("file:///")+savePath));
|
|
|
|
#else
|
2009-11-07 22:55:33 +03:00
|
|
|
QDesktopServices::openUrl(QUrl(QString("file://")+savePath));
|
2010-06-04 00:08:19 +04:00
|
|
|
#endif
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::previewSelectedTorrents() {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-12-02 23:24:34 +03:00
|
|
|
if(h.is_valid() && h.has_metadata()) {
|
2009-11-07 22:55:33 +03:00
|
|
|
new previewSelect(this, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-08 00:04:56 +03:00
|
|
|
void TransferListWidget::setDlLimitSelectedTorrents() {
|
2009-11-17 16:11:32 +03:00
|
|
|
QList<QTorrentHandle> selected_torrents;
|
|
|
|
bool first = true;
|
|
|
|
bool all_same_limit = true;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-11-17 16:11:32 +03:00
|
|
|
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();
|
2010-03-04 00:59:12 +03:00
|
|
|
const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Download Speed Limiting"), default_limit, Preferences::getGlobalDownloadLimit()*1024.);
|
2009-11-17 16:11:32 +03:00
|
|
|
if(ok) {
|
2010-03-04 00:59:12 +03:00
|
|
|
foreach(const QTorrentHandle &h, selected_torrents) {
|
2010-03-04 23:19:25 +03:00
|
|
|
qDebug("Applying download speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), qPrintable(h.hash()));
|
2009-11-17 16:16:25 +03:00
|
|
|
BTSession->setDownloadLimit(h.hash(), new_limit);
|
2009-11-17 16:11:32 +03:00
|
|
|
}
|
2009-11-08 00:04:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::setUpLimitSelectedTorrents() {
|
2009-11-17 16:11:32 +03:00
|
|
|
QList<QTorrentHandle> selected_torrents;
|
|
|
|
bool first = true;
|
|
|
|
bool all_same_limit = true;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-11-17 16:16:25 +03:00
|
|
|
if(h.is_valid()) {
|
2009-11-17 16:11:32 +03:00
|
|
|
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();
|
2010-03-04 00:59:12 +03:00
|
|
|
const long new_limit = SpeedLimitDialog::askSpeedLimit(&ok, tr("Torrent Upload Speed Limiting"), default_limit, Preferences::getGlobalUploadLimit()*1024.);
|
2009-11-17 16:11:32 +03:00
|
|
|
if(ok) {
|
2010-03-04 00:59:12 +03:00
|
|
|
foreach(const QTorrentHandle &h, selected_torrents) {
|
2010-03-04 23:19:25 +03:00
|
|
|
qDebug("Applying upload speed limit of %ld Kb/s to torrent %s", (long)(new_limit/1024.), qPrintable(h.hash()));
|
2009-11-17 16:16:25 +03:00
|
|
|
BTSession->setUploadLimit(h.hash(), new_limit);
|
2009-11-17 16:11:32 +03:00
|
|
|
}
|
2009-11-08 00:04:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::recheckSelectedTorrents() {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
|
|
|
BTSession->recheckTorrent(hash);
|
2009-11-08 00:04:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-07 22:55:33 +03:00
|
|
|
// save the hidden columns in settings
|
2010-03-04 00:59:12 +03:00
|
|
|
void TransferListWidget::saveHiddenColumns() const {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings("qBittorrent", "qBittorrent");
|
2009-11-07 22:55:33 +03:00
|
|
|
QStringList ishidden_list;
|
2010-03-04 00:59:12 +03:00
|
|
|
const short nbColumns = listModel->columnCount()-1;//hash column is hidden
|
2009-11-07 22:55:33 +03:00
|
|
|
|
|
|
|
for(short i=0; i<nbColumns; ++i){
|
|
|
|
if(isColumnHidden(i)) {
|
2010-03-04 00:59:12 +03:00
|
|
|
qDebug("Column named %s is hidden.", qPrintable(listModel->headerData(i, Qt::Horizontal).toString()));
|
2009-11-07 22:55:33 +03:00
|
|
|
ishidden_list << "0";
|
|
|
|
} else {
|
|
|
|
ishidden_list << "1";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settings.setValue("TransferListColsHoS", ishidden_list.join(" "));
|
|
|
|
}
|
|
|
|
|
|
|
|
// load the previous settings, and hide the columns
|
|
|
|
bool TransferListWidget::loadHiddenColumns() {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings("qBittorrent", "qBittorrent");
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString line = settings.value("TransferListColsHoS", "").toString();
|
2009-11-07 22:55:33 +03:00
|
|
|
bool loaded = false;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList ishidden_list = line.split(' ');
|
2010-03-04 00:59:12 +03:00
|
|
|
const unsigned int nbCol = ishidden_list.size();
|
2009-11-16 21:30:59 +03:00
|
|
|
if(nbCol == (unsigned int)listModel->columnCount()-1) {
|
2009-11-07 22:55:33 +03:00
|
|
|
for(unsigned int i=0; i<nbCol; ++i){
|
|
|
|
if(ishidden_list.at(i) == "0") {
|
|
|
|
setColumnHidden(i, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loaded = true;
|
|
|
|
}
|
2010-01-30 20:47:01 +03:00
|
|
|
// As a default, hide less useful columns
|
2010-01-30 19:28:07 +03:00
|
|
|
if(!loaded) {
|
|
|
|
setColumnHidden(TR_ADD_DATE, true);
|
|
|
|
setColumnHidden(TR_SEED_DATE, true);
|
2010-01-30 20:47:01 +03:00
|
|
|
setColumnHidden(TR_UPLIMIT, true);
|
|
|
|
setColumnHidden(TR_DLLIMIT, true);
|
2010-10-09 19:23:51 +04:00
|
|
|
setColumnHidden(TR_TRACKER, true);
|
2010-01-30 19:28:07 +03:00
|
|
|
}
|
2009-11-07 22:55:33 +03:00
|
|
|
return loaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hide/show columns menu
|
|
|
|
void TransferListWidget::displayDLHoSMenu(const QPoint&){
|
|
|
|
QMenu hideshowColumn(this);
|
|
|
|
hideshowColumn.setTitle(tr("Column visibility"));
|
|
|
|
QList<QAction*> actions;
|
2009-11-20 22:15:12 +03:00
|
|
|
for(int i=0; i < TR_HASH; ++i) {
|
2009-12-13 00:59:06 +03:00
|
|
|
if(!BTSession->isQueueingEnabled() && i == TR_PRIORITY) {
|
|
|
|
actions.append(0);
|
|
|
|
continue;
|
|
|
|
}
|
2010-06-22 02:07:36 +04:00
|
|
|
QAction *myAct = hideshowColumn.addAction(listModel->headerData(i, Qt::Horizontal).toString());
|
|
|
|
myAct->setCheckable(true);
|
|
|
|
myAct->setChecked(!isColumnHidden(i));
|
|
|
|
actions.append(myAct);
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
|
|
|
// Call menu
|
2010-06-22 02:07:36 +04:00
|
|
|
QAction *act = hideshowColumn.exec(QCursor::pos());
|
2009-12-13 00:59:06 +03:00
|
|
|
if(act) {
|
|
|
|
int col = actions.indexOf(act);
|
2010-06-02 17:08:26 +04:00
|
|
|
Q_ASSERT(col >= 0);
|
|
|
|
qDebug("Toggling column %d visibility", col);
|
2009-12-13 00:59:06 +03:00
|
|
|
setColumnHidden(col, !isColumnHidden(col));
|
2010-06-02 17:50:11 +04:00
|
|
|
if(!isColumnHidden(col) && columnWidth(col) <= 5)
|
2010-06-02 17:08:26 +04:00
|
|
|
setColumnWidth(col, 100);
|
2009-12-13 00:59:06 +03:00
|
|
|
}
|
2009-11-07 22:55:33 +03:00
|
|
|
}
|
2009-11-08 00:04:56 +03:00
|
|
|
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2010-03-04 00:59:12 +03:00
|
|
|
void TransferListWidget::toggleSelectedTorrentsSuperSeeding() const {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2009-11-18 14:04:19 +03:00
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-12-02 23:24:34 +03:00
|
|
|
if(h.is_valid() && h.has_metadata()) {
|
2009-11-18 14:04:19 +03:00
|
|
|
h.super_seeding(!h.super_seeding());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-03-04 00:59:12 +03:00
|
|
|
void TransferListWidget::toggleSelectedTorrentsSequentialDownload() const {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QStringList hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2009-11-19 15:45:11 +03:00
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-12-02 23:24:34 +03:00
|
|
|
if(h.is_valid() && h.has_metadata()) {
|
2009-11-19 15:45:11 +03:00
|
|
|
h.set_sequential_download(!h.is_sequential_download());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-04 00:59:12 +03:00
|
|
|
void TransferListWidget::toggleSelectedFirstLastPiecePrio() const {
|
2010-02-09 23:44:33 +03:00
|
|
|
QStringList hashes = getSelectedTorrentsHashes();
|
|
|
|
foreach(const QString &hash, hashes) {
|
2009-11-21 13:17:57 +03:00
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2009-12-02 23:24:34 +03:00
|
|
|
if(h.is_valid() && h.has_metadata()) {
|
2009-11-21 13:17:57 +03:00
|
|
|
h.prioritize_first_last_piece(!h.first_last_piece_first());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-15 22:52:43 +03:00
|
|
|
void TransferListWidget::askNewLabelForSelection() {
|
|
|
|
// Ask for label
|
|
|
|
bool ok;
|
2010-01-05 15:18:17 +03:00
|
|
|
bool invalid;
|
|
|
|
do {
|
|
|
|
invalid = false;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString label = QInputDialog::getText(this, tr("New Label"), tr("Label:"), QLineEdit::Normal, "", &ok);
|
2010-01-05 15:18:17 +03:00
|
|
|
if (ok && !label.isEmpty()) {
|
|
|
|
if(misc::isValidFileSystemName(label)) {
|
|
|
|
setSelectionLabel(label);
|
|
|
|
} else {
|
|
|
|
QMessageBox::warning(this, tr("Invalid label name"), tr("Please don't use any special characters in the label name."));
|
|
|
|
invalid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}while(invalid);
|
2009-12-15 22:52:43 +03:00
|
|
|
}
|
|
|
|
|
2010-01-01 16:25:59 +03:00
|
|
|
void TransferListWidget::renameSelectedTorrent() {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QModelIndexList selectedIndexes = selectionModel()->selectedRows();
|
2010-01-30 20:47:01 +03:00
|
|
|
if(selectedIndexes.size() != 1) return;
|
|
|
|
if(!selectedIndexes.first().isValid()) return;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString hash = getHashFromRow(mapToSource(selectedIndexes.first()).row());
|
|
|
|
const QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
2010-01-30 20:47:01 +03:00
|
|
|
if(!h.is_valid()) return;
|
|
|
|
// Ask for a new Name
|
|
|
|
bool ok;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString name = QInputDialog::getText(this, tr("Rename"), tr("New name:"), QLineEdit::Normal, h.name(), &ok);
|
2010-01-30 20:47:01 +03:00
|
|
|
if (ok && !name.isEmpty()) {
|
|
|
|
// Remember the name
|
|
|
|
TorrentPersistentData::saveName(hash, name);
|
|
|
|
// Visually change the name
|
2010-08-20 16:27:20 +04:00
|
|
|
nameFilterModel->setData(selectedIndexes.first(), name);
|
2010-01-30 20:47:01 +03:00
|
|
|
}
|
2010-01-01 16:25:59 +03:00
|
|
|
}
|
|
|
|
|
2009-12-15 22:52:43 +03:00
|
|
|
void TransferListWidget::setSelectionLabel(QString label) {
|
2010-03-04 00:59:12 +03:00
|
|
|
const QStringList& hashes = getSelectedTorrentsHashes();
|
2010-02-09 23:44:33 +03:00
|
|
|
foreach(const QString &hash, hashes) {
|
2010-02-07 00:31:51 +03:00
|
|
|
Q_ASSERT(!hash.isEmpty());
|
2010-03-04 00:59:12 +03:00
|
|
|
const int row = getRowFromHash(hash);
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString old_label = listModel->data(listModel->index(row, TR_LABEL)).toString();
|
2010-02-07 21:37:26 +03:00
|
|
|
listModel->setData(listModel->index(row, TR_LABEL), QVariant(label));
|
2009-12-15 22:52:43 +03:00
|
|
|
TorrentPersistentData::saveLabel(hash, label);
|
2009-12-16 16:09:30 +03:00
|
|
|
emit torrentChangedLabel(old_label, label);
|
2009-12-18 16:36:47 +03:00
|
|
|
// Update save path if necessary
|
2010-07-18 16:53:16 +04:00
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
|
|
|
BTSession->changeLabelInTorrentSavePath(h, old_label, label);
|
2009-12-15 22:52:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::removeLabelFromRows(QString label) {
|
|
|
|
for(int i=0; i<listModel->rowCount(); ++i) {
|
2010-01-03 01:53:27 +03:00
|
|
|
if(listModel->data(listModel->index(i, TR_LABEL)) == label) {
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString hash = getHashFromRow(i);
|
2009-12-15 22:52:43 +03:00
|
|
|
listModel->setData(listModel->index(i, TR_LABEL), "", Qt::DisplayRole);
|
2010-01-03 16:15:26 +03:00
|
|
|
TorrentPersistentData::saveLabel(hash, "");
|
2009-12-16 16:09:30 +03:00
|
|
|
emit torrentChangedLabel(label, "");
|
2010-01-05 21:11:52 +03:00
|
|
|
// Update save path if necessary
|
2010-07-18 16:53:16 +04:00
|
|
|
QTorrentHandle h = BTSession->getTorrentHandle(hash);
|
|
|
|
BTSession->changeLabelInTorrentSavePath(h, label, "");
|
2010-01-03 01:53:27 +03:00
|
|
|
}
|
2009-12-15 22:52:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-08 00:04:56 +03:00
|
|
|
void TransferListWidget::displayListMenu(const QPoint&) {
|
|
|
|
// Create actions
|
2010-08-19 23:37:29 +04:00
|
|
|
QAction actionStart(QIcon(QString::fromUtf8(":/Icons/skin/play.png")), tr("Resume", "Resume/start the torrent"), 0);
|
2009-11-08 00:04:56 +03:00
|
|
|
connect(&actionStart, SIGNAL(triggered()), this, SLOT(startSelectedTorrents()));
|
2010-08-19 23:37:29 +04:00
|
|
|
QAction actionPause(QIcon(QString::fromUtf8(":/Icons/skin/pause.png")), tr("Pause", "Pause the torrent"), 0);
|
2009-11-08 00:04:56 +03:00
|
|
|
connect(&actionPause, SIGNAL(triggered()), this, SLOT(pauseSelectedTorrents()));
|
2010-08-19 23:37:29 +04:00
|
|
|
QAction actionDelete(QIcon(QString::fromUtf8(":/Icons/skin/delete.png")), tr("Delete", "Delete the torrent"), 0);
|
2009-11-08 00:04:56 +03:00
|
|
|
connect(&actionDelete, SIGNAL(triggered()), this, SLOT(deleteSelectedTorrents()));
|
2010-06-21 22:32:01 +04:00
|
|
|
QAction actionPreview_file(QIcon(QString::fromUtf8(":/Icons/skin/preview.png")), tr("Preview file..."), 0);
|
2009-11-08 00:04:56 +03:00
|
|
|
connect(&actionPreview_file, SIGNAL(triggered()), this, SLOT(previewSelectedTorrents()));
|
2010-06-21 22:32:01 +04:00
|
|
|
QAction actionSet_upload_limit(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png")), tr("Limit upload rate..."), 0);
|
2009-11-08 00:04:56 +03:00
|
|
|
connect(&actionSet_upload_limit, SIGNAL(triggered()), this, SLOT(setUpLimitSelectedTorrents()));
|
2010-06-21 22:32:01 +04:00
|
|
|
QAction actionSet_download_limit(QIcon(QString::fromUtf8(":/Icons/skin/download.png")), tr("Limit download rate..."), 0);
|
2009-11-08 00:04:56 +03:00
|
|
|
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()));
|
2010-05-21 18:26:18 +04:00
|
|
|
//QAction actionBuy_it(QIcon(QString::fromUtf8(":/Icons/oxygen/wallet.png")), tr("Buy it"), 0);
|
|
|
|
//connect(&actionBuy_it, SIGNAL(triggered()), this, SLOT(buySelectedTorrents()));
|
2010-08-14 19:53:05 +04:00
|
|
|
QAction actionIncreasePriority(QIcon(QString::fromUtf8(":/Icons/oxygen/go-up.png")), tr("Move up", "i.e. move up in the queue"), 0);
|
2009-11-08 00:04:56 +03:00
|
|
|
connect(&actionIncreasePriority, SIGNAL(triggered()), this, SLOT(increasePrioSelectedTorrents()));
|
2010-08-14 19:53:05 +04:00
|
|
|
QAction actionDecreasePriority(QIcon(QString::fromUtf8(":/Icons/oxygen/go-down.png")), tr("Move down", "i.e. Move down in the queue"), 0);
|
2009-11-08 00:04:56 +03:00
|
|
|
connect(&actionDecreasePriority, SIGNAL(triggered()), this, SLOT(decreasePrioSelectedTorrents()));
|
2010-08-14 19:53:05 +04:00
|
|
|
QAction actionTopPriority(QIcon(QString::fromUtf8(":/Icons/oxygen/go-top.png")), tr("Move to top", "i.e. Move to top of the queue"), 0);
|
|
|
|
connect(&actionTopPriority, SIGNAL(triggered()), this, SLOT(topPrioSelectedTorrents()));
|
|
|
|
QAction actionBottomPriority(QIcon(QString::fromUtf8(":/Icons/oxygen/go-bottom.png")), tr("Move to bottom", "i.e. Move to bottom of the queue"), 0);
|
|
|
|
connect(&actionBottomPriority, SIGNAL(triggered()), this, SLOT(bottomPrioSelectedTorrents()));
|
|
|
|
QAction actionSetTorrentPath(QIcon(QString::fromUtf8(":/Icons/skin/folder.png")), tr("Set location..."), 0);
|
|
|
|
connect(&actionSetTorrentPath, SIGNAL(triggered()), this, SLOT(setSelectedTorrentsLocation()));
|
2009-11-08 00:04:56 +03:00
|
|
|
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()));
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2009-11-18 14:04:19 +03:00
|
|
|
QAction actionSuper_seeding_mode(tr("Super seeding mode"), 0);
|
2010-06-22 02:07:36 +04:00
|
|
|
actionSuper_seeding_mode.setCheckable(true);
|
2009-11-18 14:04:19 +03:00
|
|
|
connect(&actionSuper_seeding_mode, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSuperSeeding()));
|
2009-12-13 02:57:31 +03:00
|
|
|
#endif
|
2010-01-01 16:25:59 +03:00
|
|
|
QAction actionRename(QIcon(QString::fromUtf8(":/Icons/oxygen/edit_clear.png")), tr("Rename..."), 0);
|
|
|
|
connect(&actionRename, SIGNAL(triggered()), this, SLOT(renameSelectedTorrent()));
|
2009-11-19 15:45:11 +03:00
|
|
|
QAction actionSequential_download(tr("Download in sequential order"), 0);
|
2010-06-22 02:07:36 +04:00
|
|
|
actionSequential_download.setCheckable(true);
|
2009-11-19 15:45:11 +03:00
|
|
|
connect(&actionSequential_download, SIGNAL(triggered()), this, SLOT(toggleSelectedTorrentsSequentialDownload()));
|
2009-11-21 13:17:57 +03:00
|
|
|
QAction actionFirstLastPiece_prio(tr("Download first and last piece first"), 0);
|
2010-06-22 02:07:36 +04:00
|
|
|
actionFirstLastPiece_prio.setCheckable(true);
|
2009-11-21 13:17:57 +03:00
|
|
|
connect(&actionFirstLastPiece_prio, SIGNAL(triggered()), this, SLOT(toggleSelectedFirstLastPiecePrio()));
|
2009-11-08 00:04:56 +03:00
|
|
|
// 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;
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2009-11-22 14:16:30 +03:00
|
|
|
bool all_same_super_seeding = true;
|
|
|
|
bool super_seeding_mode = false;
|
|
|
|
#endif
|
|
|
|
bool all_same_sequential_download_mode = true, all_same_prio_firstlast = true;
|
|
|
|
bool sequential_download_mode = false, prioritize_first_last = false;
|
2009-11-21 15:35:26 +03:00
|
|
|
bool one_has_metadata = false, one_not_seed = false;
|
2009-11-18 14:04:19 +03:00
|
|
|
bool first = true;
|
2009-11-08 00:04:56 +03:00
|
|
|
QTorrentHandle h;
|
|
|
|
qDebug("Displaying menu");
|
|
|
|
foreach(const QModelIndex &index, selectedIndexes) {
|
|
|
|
// Get the file name
|
2009-12-15 22:52:43 +03:00
|
|
|
QString hash = getHashFromRow(mapToSource(index).row());
|
2009-11-08 00:04:56 +03:00
|
|
|
// Get handle and pause the torrent
|
|
|
|
h = BTSession->getTorrentHandle(hash);
|
|
|
|
if(!h.is_valid()) continue;
|
2009-11-08 11:56:20 +03:00
|
|
|
if(h.has_metadata())
|
2009-11-08 00:04:56 +03:00
|
|
|
one_has_metadata = true;
|
2009-11-18 14:04:19 +03:00
|
|
|
if(!h.is_seed()) {
|
2009-11-08 11:56:20 +03:00
|
|
|
one_not_seed = true;
|
2009-12-02 23:24:34 +03:00
|
|
|
if(h.has_metadata()) {
|
|
|
|
if(first) {
|
|
|
|
sequential_download_mode = h.is_sequential_download();
|
|
|
|
prioritize_first_last = h.first_last_piece_first();
|
|
|
|
} else {
|
|
|
|
if(sequential_download_mode != h.is_sequential_download()) {
|
|
|
|
all_same_sequential_download_mode = false;
|
|
|
|
}
|
|
|
|
if(prioritize_first_last != h.first_last_piece_first()) {
|
|
|
|
all_same_prio_firstlast = false;
|
|
|
|
}
|
2009-11-21 13:17:57 +03:00
|
|
|
}
|
2009-11-19 15:45:11 +03:00
|
|
|
}
|
2009-11-22 14:16:30 +03:00
|
|
|
}
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2009-11-22 14:16:30 +03:00
|
|
|
else {
|
2009-12-02 23:24:34 +03:00
|
|
|
if(!one_not_seed && all_same_super_seeding && h.has_metadata()) {
|
2009-11-18 14:04:19 +03:00
|
|
|
if(first) {
|
|
|
|
super_seeding_mode = h.super_seeding();
|
|
|
|
} else {
|
|
|
|
if(super_seeding_mode != h.super_seeding()) {
|
|
|
|
all_same_super_seeding = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-22 14:16:30 +03:00
|
|
|
#endif
|
2009-11-08 00:04:56 +03:00
|
|
|
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) {
|
|
|
|
has_preview = true;
|
|
|
|
}
|
2009-11-18 14:04:19 +03:00
|
|
|
first = false;
|
2009-11-08 11:56:20 +03:00
|
|
|
if(has_pause && has_start && has_preview && one_not_seed) break;
|
2009-11-08 00:04:56 +03:00
|
|
|
}
|
|
|
|
listMenu.addSeparator();
|
|
|
|
listMenu.addAction(&actionDelete);
|
|
|
|
listMenu.addSeparator();
|
2010-05-21 18:26:18 +04:00
|
|
|
listMenu.addAction(&actionSetTorrentPath);
|
2010-01-01 16:25:59 +03:00
|
|
|
if(selectedIndexes.size() == 1)
|
|
|
|
listMenu.addAction(&actionRename);
|
2009-12-15 22:52:43 +03:00
|
|
|
// Label Menu
|
2010-05-12 23:03:31 +04:00
|
|
|
QStringList customLabels = getCustomLabels();
|
|
|
|
customLabels.sort();
|
2009-12-15 22:52:43 +03:00
|
|
|
QList<QAction*> labelActions;
|
2009-12-17 13:01:01 +03:00
|
|
|
QMenu *labelMenu = listMenu.addMenu(QIcon(":/Icons/oxygen/feed-subscribe.png"), tr("Label"));
|
2009-12-19 22:14:39 +03:00
|
|
|
labelActions << labelMenu->addAction(QIcon(":/Icons/oxygen/list-add.png"), tr("New...", "New label..."));
|
|
|
|
labelActions << labelMenu->addAction(QIcon(":/Icons/oxygen/edit-clear.png"), tr("Reset", "Reset label"));
|
2009-12-15 22:52:43 +03:00
|
|
|
labelMenu->addSeparator();
|
|
|
|
foreach(const QString &label, customLabels) {
|
2009-12-17 12:59:43 +03:00
|
|
|
labelActions << labelMenu->addAction(QIcon(":/Icons/oxygen/folder.png"), label);
|
2009-12-15 22:52:43 +03:00
|
|
|
}
|
|
|
|
listMenu.addSeparator();
|
2009-11-08 11:56:20 +03:00
|
|
|
if(one_not_seed)
|
|
|
|
listMenu.addAction(&actionSet_download_limit);
|
2009-11-08 00:04:56 +03:00
|
|
|
listMenu.addAction(&actionSet_upload_limit);
|
2010-06-07 12:32:41 +04:00
|
|
|
#if LIBTORRENT_VERSION_MINOR > 14
|
2009-12-02 23:24:34 +03:00
|
|
|
if(!one_not_seed && all_same_super_seeding && one_has_metadata) {
|
2010-06-22 02:07:36 +04:00
|
|
|
actionSuper_seeding_mode.setChecked(super_seeding_mode);
|
2009-11-18 14:04:19 +03:00
|
|
|
listMenu.addAction(&actionSuper_seeding_mode);
|
|
|
|
}
|
2009-11-22 14:16:30 +03:00
|
|
|
#endif
|
2009-11-21 13:17:57 +03:00
|
|
|
listMenu.addSeparator();
|
|
|
|
bool added_preview_action = false;
|
|
|
|
if(has_preview) {
|
|
|
|
listMenu.addAction(&actionPreview_file);
|
|
|
|
added_preview_action = true;
|
|
|
|
}
|
2009-12-02 23:24:34 +03:00
|
|
|
if(one_not_seed && one_has_metadata) {
|
2009-11-21 13:17:57 +03:00
|
|
|
if(all_same_sequential_download_mode) {
|
2010-06-22 02:07:36 +04:00
|
|
|
actionSequential_download.setChecked(sequential_download_mode);
|
2009-11-21 13:17:57 +03:00
|
|
|
listMenu.addAction(&actionSequential_download);
|
|
|
|
added_preview_action = true;
|
|
|
|
}
|
2009-11-21 15:35:26 +03:00
|
|
|
if(all_same_prio_firstlast) {
|
2010-06-22 02:07:36 +04:00
|
|
|
actionFirstLastPiece_prio.setChecked(prioritize_first_last);
|
2009-11-21 13:17:57 +03:00
|
|
|
listMenu.addAction(&actionFirstLastPiece_prio);
|
|
|
|
added_preview_action = true;
|
2009-11-19 15:45:11 +03:00
|
|
|
}
|
|
|
|
}
|
2009-11-21 16:51:15 +03:00
|
|
|
if(added_preview_action)
|
|
|
|
listMenu.addSeparator();
|
2009-11-08 00:04:56 +03:00
|
|
|
if(one_has_metadata) {
|
|
|
|
listMenu.addAction(&actionForce_recheck);
|
|
|
|
listMenu.addSeparator();
|
|
|
|
}
|
|
|
|
listMenu.addAction(&actionOpen_destination_folder);
|
2009-11-08 11:56:20 +03:00
|
|
|
if(BTSession->isQueueingEnabled() && one_not_seed) {
|
2009-11-08 00:04:56 +03:00
|
|
|
listMenu.addSeparator();
|
2010-08-14 19:53:05 +04:00
|
|
|
QMenu *prioMenu = listMenu.addMenu(tr("Priority"));
|
|
|
|
prioMenu->addAction(&actionTopPriority);
|
|
|
|
prioMenu->addAction(&actionIncreasePriority);
|
|
|
|
prioMenu->addAction(&actionDecreasePriority);
|
|
|
|
prioMenu->addAction(&actionBottomPriority);
|
2009-11-08 00:04:56 +03:00
|
|
|
}
|
|
|
|
listMenu.addSeparator();
|
2009-12-02 23:24:34 +03:00
|
|
|
if(one_has_metadata)
|
|
|
|
listMenu.addAction(&actionCopy_magnet_link);
|
2010-05-21 18:26:18 +04:00
|
|
|
//listMenu.addAction(&actionBuy_it);
|
2009-11-08 00:04:56 +03:00
|
|
|
// Call menu
|
2009-12-15 22:52:43 +03:00
|
|
|
QAction *act = 0;
|
|
|
|
act = listMenu.exec(QCursor::pos());
|
|
|
|
if(act) {
|
|
|
|
// Parse label actions only (others have slots assigned)
|
|
|
|
int i = labelActions.indexOf(act);
|
|
|
|
if(i >= 0) {
|
|
|
|
// Label action
|
|
|
|
if(i == 0) {
|
|
|
|
// New Label
|
|
|
|
askNewLabelForSelection();
|
|
|
|
} else {
|
|
|
|
QString label = "";
|
|
|
|
if(i > 1)
|
|
|
|
label = customLabels.at(i-2);
|
|
|
|
// Update Label
|
|
|
|
setSelectionLabel(label);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-08 00:04:56 +03:00
|
|
|
}
|
2009-11-08 12:14:54 +03:00
|
|
|
|
|
|
|
// Save columns width in a file to remember them
|
|
|
|
void TransferListWidget::saveColWidthList() {
|
|
|
|
qDebug("Saving columns width in transfer list");
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
2009-11-08 12:14:54 +03:00
|
|
|
QStringList width_list;
|
|
|
|
QStringList new_width_list;
|
2010-03-04 00:59:12 +03:00
|
|
|
const short nbColumns = listModel->columnCount()-1; // HASH is hidden
|
2010-06-05 17:43:36 +04:00
|
|
|
if(nbColumns <= 0) return;
|
2010-07-23 18:05:53 +04:00
|
|
|
const QString line = settings.value("TransferListColsWidth", QString()).toString();
|
2009-11-08 12:14:54 +03:00
|
|
|
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
|
2010-03-03 20:27:25 +03:00
|
|
|
new_width_list << QString::number(columnWidth(i));
|
2009-11-08 12:14:54 +03:00
|
|
|
} else {
|
|
|
|
// default width
|
|
|
|
resizeColumnToContents(i);
|
2010-03-03 20:27:25 +03:00
|
|
|
new_width_list << QString::number(columnWidth(i));
|
2009-11-08 12:14:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
settings.setValue(QString::fromUtf8("TransferListColsWidth"), new_width_list.join(QString::fromUtf8(" ")));
|
2010-06-05 22:59:05 +04:00
|
|
|
QStringList visualIndexes;
|
2009-11-08 12:14:54 +03:00
|
|
|
for(int i=0; i<nbColumns; ++i) {
|
2010-06-05 22:59:05 +04:00
|
|
|
visualIndexes << QString::number(header()->visualIndex(i));
|
2009-11-08 12:14:54 +03:00
|
|
|
}
|
2010-06-05 22:59:05 +04:00
|
|
|
settings.setValue(QString::fromUtf8("TransferListVisualIndexes"), visualIndexes);
|
2009-11-08 12:14:54 +03:00
|
|
|
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");
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
2010-06-05 17:43:36 +04:00
|
|
|
QString line = settings.value(QString::fromUtf8("TransferListColsWidth"), QString()).toString();
|
2009-11-08 12:14:54 +03:00
|
|
|
if(line.isEmpty())
|
|
|
|
return false;
|
2010-06-05 17:43:36 +04:00
|
|
|
const QStringList width_list = line.split(" ");
|
2009-11-16 21:30:59 +03:00
|
|
|
if(width_list.size() != listModel->columnCount()-1) {
|
|
|
|
qDebug("Corrupted values for transfer list columns sizes");
|
2009-11-08 12:14:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
2010-03-04 00:59:12 +03:00
|
|
|
const unsigned int listSize = width_list.size();
|
2009-11-08 12:14:54 +03:00
|
|
|
for(unsigned int i=0; i<listSize; ++i) {
|
|
|
|
header()->resizeSection(i, width_list.at(i).toInt());
|
|
|
|
}
|
2010-06-05 22:59:05 +04:00
|
|
|
const QList<int> visualIndexes = misc::intListfromStringList(settings.value(QString::fromUtf8("TransferListVisualIndexes")).toStringList());
|
2009-11-16 21:30:59 +03:00
|
|
|
if(visualIndexes.size() != listModel->columnCount()-1) {
|
|
|
|
qDebug("Corrupted values for transfer list columns indexes");
|
2009-11-08 12:14:54 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool change = false;
|
|
|
|
do {
|
|
|
|
change = false;
|
|
|
|
for(int i=0;i<visualIndexes.size(); ++i) {
|
2010-06-05 17:43:36 +04:00
|
|
|
const int new_visual_index = visualIndexes.at(header()->logicalIndex(i));
|
2009-11-08 12:14:54 +03:00
|
|
|
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() {
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
2010-07-23 18:05:53 +04:00
|
|
|
const Qt::SortOrder sortOrder = header()->sortIndicatorOrder();
|
2009-11-08 12:14:54 +03:00
|
|
|
QString sortOrderLetter;
|
|
|
|
if(sortOrder == Qt::AscendingOrder)
|
|
|
|
sortOrderLetter = QString::fromUtf8("a");
|
|
|
|
else
|
|
|
|
sortOrderLetter = QString::fromUtf8("d");
|
2010-03-04 00:59:12 +03:00
|
|
|
const int index = header()->sortIndicatorSection();
|
2010-03-07 00:11:47 +03:00
|
|
|
settings.setValue(QString::fromUtf8("TransferListSortedCol"), QVariant(QString::number(index)+sortOrderLetter));
|
2009-11-08 12:14:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void TransferListWidget::loadLastSortedColumn() {
|
|
|
|
// Loading last sorted column
|
2010-07-16 19:03:18 +04:00
|
|
|
QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
2009-11-08 12:14:54 +03:00
|
|
|
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;
|
2009-11-22 21:20:47 +03:00
|
|
|
sortedCol.chop(1);
|
2010-03-04 00:59:12 +03:00
|
|
|
const int index = sortedCol.toInt();
|
2009-11-08 12:14:54 +03:00
|
|
|
sortByColumn(index, sortOrder);
|
|
|
|
}
|
|
|
|
}
|
2009-11-08 16:19:00 +03:00
|
|
|
|
2009-11-08 18:41:32 +03:00
|
|
|
void TransferListWidget::currentChanged(const QModelIndex& current, const QModelIndex&) {
|
2010-09-28 20:53:58 +04:00
|
|
|
qDebug("CURRENT CHANGED");
|
2009-11-08 22:54:22 +03:00
|
|
|
QTorrentHandle h;
|
|
|
|
if(current.isValid()) {
|
2010-03-04 00:59:12 +03:00
|
|
|
const int row = mapToSource(current).row();
|
2009-11-08 22:54:22 +03:00
|
|
|
h = BTSession->getTorrentHandle(getHashFromRow(row));
|
2009-11-25 21:20:42 +03:00
|
|
|
// Scroll Fix
|
|
|
|
scrollTo(current);
|
2009-11-08 22:54:22 +03:00
|
|
|
}
|
2009-11-08 18:41:32 +03:00
|
|
|
emit currentTorrentChanged(h);
|
|
|
|
}
|
|
|
|
|
2009-12-15 22:52:43 +03:00
|
|
|
void TransferListWidget::applyLabelFilter(QString label) {
|
|
|
|
if(label == "all") {
|
|
|
|
labelFilterModel->setFilterRegExp(QRegExp());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(label == "none") {
|
|
|
|
labelFilterModel->setFilterRegExp(QRegExp("^$"));
|
|
|
|
return;
|
|
|
|
}
|
2010-03-04 23:19:25 +03:00
|
|
|
qDebug("Applying Label filter: %s", qPrintable(label));
|
2009-12-15 22:52:43 +03:00
|
|
|
labelFilterModel->setFilterRegExp(QRegExp("^"+label+"$", Qt::CaseSensitive));
|
|
|
|
}
|
|
|
|
|
2010-08-20 16:27:20 +04:00
|
|
|
void TransferListWidget::applyNameFilter(QString name) {
|
|
|
|
nameFilterModel->setFilterRegExp(QRegExp(name, Qt::CaseInsensitive));
|
|
|
|
}
|
|
|
|
|
2009-12-15 22:52:43 +03:00
|
|
|
void TransferListWidget::applyStatusFilter(int f) {
|
2009-11-08 16:19:00 +03:00
|
|
|
switch(f) {
|
2009-11-16 21:30:59 +03:00
|
|
|
case FILTER_DOWNLOADING:
|
2010-08-20 16:27:20 +04:00
|
|
|
statusFilterModel->setFilterRegExp(QRegExp(QString::number(STATE_DOWNLOADING)+"|"+QString::number(STATE_STALLED_DL)+"|"+
|
2010-10-09 19:23:51 +04:00
|
|
|
QString::number(STATE_PAUSED_DL)+"|"+QString::number(STATE_CHECKING_DL)+"|"+
|
|
|
|
QString::number(STATE_QUEUED_DL), Qt::CaseSensitive));
|
2009-11-08 16:19:00 +03:00
|
|
|
break;
|
2009-11-16 21:30:59 +03:00
|
|
|
case FILTER_COMPLETED:
|
2010-08-20 16:27:20 +04:00
|
|
|
statusFilterModel->setFilterRegExp(QRegExp(QString::number(STATE_SEEDING)+"|"+QString::number(STATE_STALLED_UP)+"|"+
|
2010-10-09 19:23:51 +04:00
|
|
|
QString::number(STATE_PAUSED_UP)+"|"+QString::number(STATE_CHECKING_UP)+"|"+
|
|
|
|
QString::number(STATE_QUEUED_UP), Qt::CaseSensitive));
|
2009-11-08 16:19:00 +03:00
|
|
|
break;
|
2009-11-16 21:30:59 +03:00
|
|
|
case FILTER_ACTIVE:
|
2010-08-20 16:27:20 +04:00
|
|
|
statusFilterModel->setFilterRegExp(QRegExp(QString::number(STATE_DOWNLOADING)+"|"+QString::number(STATE_SEEDING), Qt::CaseSensitive));
|
2009-11-08 16:19:00 +03:00
|
|
|
break;
|
2009-11-16 21:30:59 +03:00
|
|
|
case FILTER_INACTIVE:
|
2010-08-20 16:27:20 +04:00
|
|
|
statusFilterModel->setFilterRegExp(QRegExp("[^"+QString::number(STATE_DOWNLOADING)+QString::number(STATE_SEEDING)+"]", Qt::CaseSensitive));
|
2009-11-08 16:19:00 +03:00
|
|
|
break;
|
2010-05-24 19:16:14 +04:00
|
|
|
case FILTER_PAUSED:
|
2010-08-20 16:27:20 +04:00
|
|
|
statusFilterModel->setFilterRegExp(QRegExp(QString::number(STATE_PAUSED_UP)+"|"+QString::number(STATE_PAUSED_DL)));
|
2010-05-24 19:16:14 +04:00
|
|
|
break;
|
2009-11-08 16:19:00 +03:00
|
|
|
default:
|
2010-08-20 16:27:20 +04:00
|
|
|
statusFilterModel->setFilterRegExp(QRegExp());
|
2009-11-08 16:19:00 +03:00
|
|
|
}
|
2009-11-09 10:05:06 +03:00
|
|
|
// Select first item if nothing is selected
|
2010-10-17 13:09:40 +04:00
|
|
|
if(selectionModel()->selectedRows(0).empty() && nameFilterModel->rowCount() > 0) {
|
|
|
|
qDebug("Nothing is selected, selecting first row: %s", qPrintable(nameFilterModel->index(0, TR_NAME).data().toString()));
|
|
|
|
selectionModel()->setCurrentIndex(nameFilterModel->index(0, TR_NAME), QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows);
|
|
|
|
}
|
2009-11-08 16:19:00 +03:00
|
|
|
}
|
2009-11-09 11:56:21 +03:00
|
|
|
|