Christophe Dumez
15 years ago
13 changed files with 8 additions and 2104 deletions
@ -1,116 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef DLLISTDELEGATE_H |
|
||||||
#define DLLISTDELEGATE_H |
|
||||||
|
|
||||||
#include <QItemDelegate> |
|
||||||
#include <QModelIndex> |
|
||||||
#include <QPainter> |
|
||||||
#include <QStyleOptionProgressBarV2> |
|
||||||
#include <QStyleOptionViewItemV2> |
|
||||||
#include <QProgressBar> |
|
||||||
#include <QApplication> |
|
||||||
#include "misc.h" |
|
||||||
|
|
||||||
// Defines for download list list columns
|
|
||||||
#define NAME 0 |
|
||||||
#define SIZE 1 |
|
||||||
#define PROGRESS 2 |
|
||||||
#define DLSPEED 3 |
|
||||||
#define UPSPEED 4 |
|
||||||
#define SEEDSLEECH 5 |
|
||||||
#define RATIO 6 |
|
||||||
#define ETA 7 |
|
||||||
#define PRIORITY 8 |
|
||||||
#define HASH 9 |
|
||||||
|
|
||||||
class DLListDelegate: public QItemDelegate { |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
DLListDelegate(QObject *parent) : QItemDelegate(parent){} |
|
||||||
|
|
||||||
~DLListDelegate(){} |
|
||||||
|
|
||||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{ |
|
||||||
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option); |
|
||||||
switch(index.column()){ |
|
||||||
case SIZE: |
|
||||||
QItemDelegate::drawBackground(painter, opt, index); |
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong())); |
|
||||||
break; |
|
||||||
case ETA: |
|
||||||
QItemDelegate::drawBackground(painter, opt, index); |
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::userFriendlyDuration(index.data().toLongLong())); |
|
||||||
break; |
|
||||||
case UPSPEED: |
|
||||||
case DLSPEED:{ |
|
||||||
QItemDelegate::drawBackground(painter, opt, index); |
|
||||||
double speed = index.data().toDouble(); |
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(speed/1024., 'f', 1))+QString::fromUtf8(" ")+tr("KiB/s")); |
|
||||||
break; |
|
||||||
} |
|
||||||
case RATIO:{ |
|
||||||
QItemDelegate::drawBackground(painter, opt, index); |
|
||||||
double ratio = index.data().toDouble(); |
|
||||||
if(ratio > 100.) |
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("∞")); |
|
||||||
else |
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(ratio, 'f', 1))); |
|
||||||
break; |
|
||||||
} |
|
||||||
case PROGRESS:{ |
|
||||||
QStyleOptionProgressBarV2 newopt; |
|
||||||
double progress = index.data().toDouble()*100.; |
|
||||||
newopt.rect = opt.rect; |
|
||||||
newopt.text = QString(QByteArray::number(progress, 'f', 1))+QString::fromUtf8("%"); |
|
||||||
newopt.progress = (int)progress; |
|
||||||
newopt.maximum = 100; |
|
||||||
newopt.minimum = 0; |
|
||||||
newopt.state |= QStyle::State_Enabled; |
|
||||||
newopt.textVisible = true; |
|
||||||
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, |
|
||||||
painter); |
|
||||||
break; |
|
||||||
} |
|
||||||
default: |
|
||||||
QItemDelegate::paint(painter, option, index); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const { |
|
||||||
// No editor here
|
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
|
||||||
}; |
|
||||||
|
|
||||||
#endif |
|
@ -1,98 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef FINISHEDLISTDELEGATE_H |
|
||||||
#define FINISHEDLISTDELEGATE_H |
|
||||||
|
|
||||||
#include <QItemDelegate> |
|
||||||
#include <QModelIndex> |
|
||||||
#include <QPainter> |
|
||||||
#include <QStyleOptionProgressBarV2> |
|
||||||
#include <QStyleOptionViewItemV2> |
|
||||||
#include <QProgressBar> |
|
||||||
#include <QApplication> |
|
||||||
#include "misc.h" |
|
||||||
|
|
||||||
// Defines for download list list columns
|
|
||||||
#define F_NAME 0 |
|
||||||
#define F_SIZE 1 |
|
||||||
#define F_UPSPEED 2 |
|
||||||
#define F_SWARM 3 |
|
||||||
#define F_PEERS 4 |
|
||||||
#define F_UPLOAD 5 |
|
||||||
#define F_RATIO 6 |
|
||||||
#define F_HASH 7 |
|
||||||
|
|
||||||
#define MAX_RATIO 100. |
|
||||||
|
|
||||||
class FinishedListDelegate: public QItemDelegate { |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
FinishedListDelegate(QObject *parent) : QItemDelegate(parent){} |
|
||||||
|
|
||||||
~FinishedListDelegate(){} |
|
||||||
|
|
||||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const{ |
|
||||||
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option); |
|
||||||
switch(index.column()){ |
|
||||||
case F_SIZE: |
|
||||||
case F_UPLOAD: |
|
||||||
QItemDelegate::drawBackground(painter, opt, index); |
|
||||||
QItemDelegate::drawDisplay(painter, opt, option.rect, misc::friendlyUnit(index.data().toLongLong())); |
|
||||||
break; |
|
||||||
case F_UPSPEED:{ |
|
||||||
QItemDelegate::drawBackground(painter, opt, index); |
|
||||||
double speed = index.data().toDouble(); |
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(speed/1024., 'f', 1))+QString::fromUtf8(" ")+tr("KiB/s")); |
|
||||||
break; |
|
||||||
} |
|
||||||
case F_RATIO:{ |
|
||||||
QItemDelegate::drawBackground(painter, opt, index); |
|
||||||
double ratio = index.data().toDouble(); |
|
||||||
if(ratio > MAX_RATIO) |
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString::fromUtf8("∞")); |
|
||||||
else |
|
||||||
QItemDelegate::drawDisplay(painter, opt, opt.rect, QString(QByteArray::number(ratio, 'f', 1))); |
|
||||||
break; |
|
||||||
} |
|
||||||
default: |
|
||||||
QItemDelegate::paint(painter, option, index); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const { |
|
||||||
// No editor here
|
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
|
||||||
}; |
|
||||||
|
|
||||||
#endif |
|
@ -1,699 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 |
|
||||||
*/ |
|
||||||
#include "FinishedTorrents.h" |
|
||||||
#include "misc.h" |
|
||||||
#include "properties_imp.h" |
|
||||||
#include "bittorrent.h" |
|
||||||
#include "allocationDlg.h" |
|
||||||
#include "FinishedListDelegate.h" |
|
||||||
#include "GUI.h" |
|
||||||
|
|
||||||
#include <QFile> |
|
||||||
#include <QSettings> |
|
||||||
#include <QStandardItemModel> |
|
||||||
#include <QSortFilterProxyModel> |
|
||||||
#include <QHeaderView> |
|
||||||
#include <QMenu> |
|
||||||
#include <QMessageBox> |
|
||||||
|
|
||||||
FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession) : parent(parent), BTSession(BTSession), nbFinished(0){ |
|
||||||
setupUi(this); |
|
||||||
actionStart->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/play.png"))); |
|
||||||
actionPause->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/pause.png"))); |
|
||||||
finishedListModel = new QStandardItemModel(0,8); |
|
||||||
finishedListModel->setHeaderData(F_NAME, Qt::Horizontal, tr("Name", "i.e: file name")); |
|
||||||
finishedListModel->setHeaderData(F_SIZE, Qt::Horizontal, tr("Size", "i.e: file size")); |
|
||||||
finishedListModel->setHeaderData(F_UPSPEED, Qt::Horizontal, tr("UP Speed", "i.e: Upload speed")); |
|
||||||
finishedListModel->setHeaderData(F_SWARM, Qt::Horizontal, tr("Seeds / Leechers")); |
|
||||||
finishedListModel->setHeaderData(F_PEERS, Qt::Horizontal, tr("Connected peers")); |
|
||||||
finishedListModel->setHeaderData(F_UPLOAD, Qt::Horizontal, tr("Total uploaded", "i.e: Total amount of uploaded data")); |
|
||||||
finishedListModel->setHeaderData(F_RATIO, Qt::Horizontal, tr("Ratio")); |
|
||||||
|
|
||||||
proxyModel = new QSortFilterProxyModel(); |
|
||||||
proxyModel->setDynamicSortFilter(true); |
|
||||||
proxyModel->setSourceModel(finishedListModel); |
|
||||||
finishedList->setModel(proxyModel); |
|
||||||
|
|
||||||
finishedList->setRootIsDecorated(false); |
|
||||||
finishedList->setAllColumnsShowFocus(true); |
|
||||||
finishedList->setSortingEnabled(true); |
|
||||||
|
|
||||||
loadHiddenColumns(); |
|
||||||
// Hide hash column
|
|
||||||
finishedList->hideColumn(F_HASH); |
|
||||||
// Load last columns width for download list
|
|
||||||
if(!loadColWidthFinishedList()){ |
|
||||||
finishedList->header()->resizeSection(0, 200); |
|
||||||
} |
|
||||||
// Connect BTSession signals
|
|
||||||
connect(BTSession, SIGNAL(metadataReceived(QTorrentHandle&)), this, SLOT(updateMetadata(QTorrentHandle&))); |
|
||||||
// Make download list header clickable for sorting
|
|
||||||
finishedList->header()->setClickable(true); |
|
||||||
finishedList->header()->setSortIndicatorShown(true); |
|
||||||
finishedListDelegate = new FinishedListDelegate(finishedList); |
|
||||||
finishedList->setItemDelegate(finishedListDelegate); |
|
||||||
connect(finishedList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFinishedListMenu(const QPoint&))); |
|
||||||
finishedList->header()->setContextMenuPolicy(Qt::CustomContextMenu); |
|
||||||
connect(finishedList->header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFinishedHoSMenu(const QPoint&))); |
|
||||||
connect(finishedList, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(notifyTorrentDoubleClicked(const QModelIndex&))); |
|
||||||
actionDelete->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/delete.png"))); |
|
||||||
actionPreview_file->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/preview.png"))); |
|
||||||
actionDelete_Permanently->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/delete_perm.png"))); |
|
||||||
actionTorrent_Properties->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/properties.png"))); |
|
||||||
actionSet_upload_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png"))); |
|
||||||
actionCopy_magnet_link->setIcon(QIcon(QString::fromUtf8(":/Icons/magnet.png"))); |
|
||||||
|
|
||||||
connect(actionPause, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionPause_triggered())); |
|
||||||
connect(actionStart, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionStart_triggered())); |
|
||||||
connect(actionDelete, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionDelete_triggered())); |
|
||||||
connect(actionPreview_file, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionPreview_file_triggered())); |
|
||||||
connect(actionDelete_Permanently, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionDelete_Permanently_triggered())); |
|
||||||
connect(actionOpen_destination_folder, SIGNAL(triggered()), (GUI*)parent, SLOT(openDestinationFolder())); |
|
||||||
connect(actionBuy_it, SIGNAL(triggered()), (GUI*)parent, SLOT(goBuyPage())); |
|
||||||
connect(actionTorrent_Properties, SIGNAL(triggered()), this, SLOT(propertiesSelection())); |
|
||||||
connect(actionForce_recheck, SIGNAL(triggered()), this, SLOT(forceRecheck())); |
|
||||||
connect(actionCopy_magnet_link, SIGNAL(triggered()), (GUI*)parent, SLOT(copyMagnetURI())); |
|
||||||
|
|
||||||
connect(actionHOSColName, SIGNAL(triggered()), this, SLOT(hideOrShowColumnName())); |
|
||||||
connect(actionHOSColSize, SIGNAL(triggered()), this, SLOT(hideOrShowColumnSize())); |
|
||||||
connect(actionHOSColUpSpeed, SIGNAL(triggered()), this, SLOT(hideOrShowColumnUpSpeed())); |
|
||||||
connect(actionHOSColSwarm, SIGNAL(triggered()), this, SLOT(hideOrShowColumnSwarm())); |
|
||||||
connect(actionHOSColPeers, SIGNAL(triggered()), this, SLOT(hideOrShowColumnPeers())); |
|
||||||
connect(actionHOSColUpload, SIGNAL(triggered()), this, SLOT(hideOrShowColumnUpload())); |
|
||||||
connect(actionHOSColRatio, SIGNAL(triggered()), this, SLOT(hideOrShowColumnRatio())); |
|
||||||
} |
|
||||||
|
|
||||||
FinishedTorrents::~FinishedTorrents(){ |
|
||||||
saveLastSortedColumn(); |
|
||||||
saveColWidthFinishedList(); |
|
||||||
saveHiddenColumns(); |
|
||||||
delete finishedListDelegate; |
|
||||||
delete proxyModel; |
|
||||||
delete finishedListModel; |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::notifyTorrentDoubleClicked(const QModelIndex& index) { |
|
||||||
unsigned int row = index.row(); |
|
||||||
QString hash = getHashFromRow(row); |
|
||||||
emit torrentDoubleClicked(hash, true); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::addTorrent(QString hash){ |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
if(row != -1) return; |
|
||||||
row = finishedListModel->rowCount(); |
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
// Adding torrent to download list
|
|
||||||
finishedListModel->insertRow(row); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(h.name())); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_SIZE), QVariant((qlonglong)h.actual_size())); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_UPSPEED), QVariant((double)0.)); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_SWARM), QVariant("-1/-1")); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_PEERS), QVariant("0")); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_UPLOAD), QVariant((qlonglong)h.all_time_upload())); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_RATIO), QVariant(QString::fromUtf8(misc::toString(BTSession->getRealRatio(hash)).c_str()))); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_HASH), QVariant(hash)); |
|
||||||
if(h.is_paused()) { |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_NAME), QIcon(":/Icons/skin/paused.png"), Qt::DecorationRole); |
|
||||||
setRowColor(row, "red"); |
|
||||||
}else{ |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(QIcon(":/Icons/skin/seeding.png")), Qt::DecorationRole); |
|
||||||
setRowColor(row, "orange"); |
|
||||||
} |
|
||||||
// Update the number of finished torrents
|
|
||||||
++nbFinished; |
|
||||||
emit finishedTorrentsNumberChanged(nbFinished); |
|
||||||
|
|
||||||
loadLastSortedColumn(); |
|
||||||
} |
|
||||||
|
|
||||||
// Set the color of a row in data model
|
|
||||||
void FinishedTorrents::setRowColor(int row, QString color){ |
|
||||||
unsigned int nbColumns = finishedListModel->columnCount()-1; |
|
||||||
for(unsigned int i=0; i<nbColumns; ++i){ |
|
||||||
finishedListModel->setData(finishedListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
QStringList FinishedTorrents::getSelectedTorrents(bool only_one) const{ |
|
||||||
QStringList res; |
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); |
|
||||||
foreach(const QModelIndex &index, selectedIndexes) { |
|
||||||
if(index.column() == F_NAME) { |
|
||||||
// Get the file hash
|
|
||||||
QString hash = getHashFromRow(index.row()); |
|
||||||
res << hash; |
|
||||||
if(only_one) break; |
|
||||||
} |
|
||||||
} |
|
||||||
return res; |
|
||||||
} |
|
||||||
|
|
||||||
unsigned int FinishedTorrents::getNbTorrentsInList() const { |
|
||||||
return nbFinished; |
|
||||||
} |
|
||||||
|
|
||||||
// Load columns width in a file that were saved previously
|
|
||||||
// (finished list)
|
|
||||||
bool FinishedTorrents::loadColWidthFinishedList(){ |
|
||||||
qDebug("Loading columns width for finished list"); |
|
||||||
QSettings settings("qBittorrent", "qBittorrent"); |
|
||||||
QString line = settings.value("FinishedListColsWidth", QString()).toString(); |
|
||||||
if(line.isEmpty()) |
|
||||||
return false; |
|
||||||
QStringList width_list = line.split(' '); |
|
||||||
if(width_list.size() < finishedListModel->columnCount()-1) |
|
||||||
return false; |
|
||||||
unsigned int listSize = width_list.size(); |
|
||||||
for(unsigned int i=0; i<listSize; ++i){ |
|
||||||
finishedList->header()->resizeSection(i, width_list.at(i).toInt()); |
|
||||||
} |
|
||||||
loadLastSortedColumn(); |
|
||||||
QVariantList visualIndexes = settings.value(QString::fromUtf8("FinishedListVisualIndexes"), QVariantList()).toList(); |
|
||||||
if(visualIndexes.size() != finishedListModel->columnCount()-1) { |
|
||||||
qDebug("Corrupted values for download list columns sizes"); |
|
||||||
return false; |
|
||||||
} |
|
||||||
bool change = false; |
|
||||||
do { |
|
||||||
change = false; |
|
||||||
for(int i=0;i<visualIndexes.size(); ++i) { |
|
||||||
int new_visual_index = visualIndexes.at(finishedList->header()->logicalIndex(i)).toInt(); |
|
||||||
if(i != new_visual_index) { |
|
||||||
qDebug("Moving column from %d to %d", finishedList->header()->logicalIndex(i), new_visual_index); |
|
||||||
finishedList->header()->moveSection(i, new_visual_index); |
|
||||||
change = true; |
|
||||||
} |
|
||||||
} |
|
||||||
}while(change); |
|
||||||
qDebug("Finished list columns width loaded"); |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::saveLastSortedColumn() { |
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); |
|
||||||
Qt::SortOrder sortOrder = finishedList->header()->sortIndicatorOrder(); |
|
||||||
QString sortOrderLetter; |
|
||||||
if(sortOrder == Qt::AscendingOrder) |
|
||||||
sortOrderLetter = QString::fromUtf8("a"); |
|
||||||
else |
|
||||||
sortOrderLetter = QString::fromUtf8("d"); |
|
||||||
int index = finishedList->header()->sortIndicatorSection(); |
|
||||||
settings.setValue(QString::fromUtf8("FinishedListSortedCol"), misc::toQString(index)+sortOrderLetter); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::loadLastSortedColumn() { |
|
||||||
// Loading last sorted column
|
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); |
|
||||||
QString sortedCol = settings.value(QString::fromUtf8("FinishedListSortedCol"), 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(); |
|
||||||
finishedList->sortByColumn(index, sortOrder); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Save columns width in a file to remember them
|
|
||||||
// (finished list)
|
|
||||||
void FinishedTorrents::saveColWidthFinishedList() const{ |
|
||||||
qDebug("Saving columns width in finished list"); |
|
||||||
QSettings settings("qBittorrent", "qBittorrent"); |
|
||||||
QStringList width_list; |
|
||||||
QStringList new_width_list; |
|
||||||
short nbColumns = finishedListModel->columnCount()-1; |
|
||||||
|
|
||||||
QString line = settings.value("FinishedListColsWidth", QString()).toString(); |
|
||||||
if(!line.isEmpty()) { |
|
||||||
width_list = line.split(' '); |
|
||||||
} |
|
||||||
for(short i=0; i<nbColumns; ++i){ |
|
||||||
if(finishedList->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(finishedList->columnWidth(i)>=1) { |
|
||||||
// usual case, save the current width
|
|
||||||
new_width_list << QString::fromUtf8(misc::toString(finishedList->columnWidth(i)).c_str()); |
|
||||||
} else { |
|
||||||
// default width
|
|
||||||
finishedList->resizeColumnToContents(i); |
|
||||||
new_width_list << QString::fromUtf8(misc::toString(finishedList->columnWidth(i)).c_str()); |
|
||||||
} |
|
||||||
} |
|
||||||
settings.setValue("FinishedListColsWidth", new_width_list.join(" ")); |
|
||||||
QVariantList visualIndexes; |
|
||||||
for(int i=0; i<nbColumns; ++i) { |
|
||||||
visualIndexes.append(finishedList->header()->visualIndex(i)); |
|
||||||
} |
|
||||||
settings.setValue(QString::fromUtf8("FinishedListVisualIndexes"), visualIndexes); |
|
||||||
qDebug("Finished list columns width saved"); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::on_actionSet_upload_limit_triggered(){ |
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); |
|
||||||
QStringList hashes; |
|
||||||
foreach(const QModelIndex &index, selectedIndexes){ |
|
||||||
if(index.column() == F_NAME){ |
|
||||||
// Get the file hash
|
|
||||||
hashes << getHashFromRow(index.row()); |
|
||||||
} |
|
||||||
} |
|
||||||
new BandwidthAllocationDialog(this, true, BTSession, hashes); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::updateMetadata(QTorrentHandle &h) { |
|
||||||
QString hash = h.hash(); |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
if(row != -1) { |
|
||||||
qDebug("Updating torrent metadata in download list"); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(h.name())); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_SIZE), QVariant((qlonglong)h.actual_size())); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::updateTorrent(QTorrentHandle h) { |
|
||||||
if(!h.is_valid()) return; |
|
||||||
QString hash = h.hash(); |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
if(row == -1){ |
|
||||||
qDebug("Cannot find torrent in finished list, adding it"); |
|
||||||
addTorrent(hash); |
|
||||||
row = getRowFromHash(hash); |
|
||||||
} |
|
||||||
Q_ASSERT(row != -1); |
|
||||||
if(!finishedList->isColumnHidden(F_SWARM)) { |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_SWARM), misc::toQString(h.num_complete())+QString("/")+misc::toQString(h.num_incomplete())); |
|
||||||
} |
|
||||||
if(h.is_paused()) return; |
|
||||||
// Update queued torrent
|
|
||||||
if(BTSession->isQueueingEnabled() && h.is_queued()) { |
|
||||||
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking){ |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/time.png"))), Qt::DecorationRole); |
|
||||||
} else { |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/queued.png"))), Qt::DecorationRole); |
|
||||||
} |
|
||||||
// Reset upload speed and seeds/leech
|
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_UPSPEED), 0.); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_PEERS), "0"); |
|
||||||
setRowColor(row, QString::fromUtf8("grey")); |
|
||||||
return; |
|
||||||
} |
|
||||||
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking){ |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/time.png"))), Qt::DecorationRole); |
|
||||||
setRowColor(row, QString::fromUtf8("grey")); |
|
||||||
return; |
|
||||||
} |
|
||||||
setRowColor(row, QString::fromUtf8("orange")); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png"))), Qt::DecorationRole); |
|
||||||
if(!finishedList->isColumnHidden(F_UPSPEED)) { |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_UPSPEED), QVariant((double)h.upload_payload_rate())); |
|
||||||
} |
|
||||||
if(!finishedList->isColumnHidden(F_PEERS)) { |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_PEERS), misc::toQString(h.num_peers() - h.num_seeds(), true)); |
|
||||||
} |
|
||||||
if(!finishedList->isColumnHidden(F_UPLOAD)) { |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_UPLOAD), QVariant((double)h.all_time_upload())); |
|
||||||
} |
|
||||||
if(!finishedList->isColumnHidden(F_RATIO)) { |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_RATIO), QVariant(misc::toQString(BTSession->getRealRatio(hash)))); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
int FinishedTorrents::getRowFromHash(QString hash) const{ |
|
||||||
unsigned int nbRows = finishedListModel->rowCount(); |
|
||||||
for(unsigned int i=0; i<nbRows; ++i){ |
|
||||||
if(finishedListModel->data(finishedListModel->index(i, F_HASH)) == hash){ |
|
||||||
return i; |
|
||||||
} |
|
||||||
} |
|
||||||
return -1; |
|
||||||
} |
|
||||||
|
|
||||||
// Note: does not actually pause the torrent in BT Session
|
|
||||||
void FinishedTorrents::pauseTorrent(QString hash) { |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
if(row == -1) |
|
||||||
return; |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_UPSPEED), QVariant((double)0.0)); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_NAME), QIcon(QString::fromUtf8(":/Icons/skin/paused.png")), Qt::DecorationRole); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_PEERS), QVariant(QString::fromUtf8("0"))); |
|
||||||
setRowColor(row, QString::fromUtf8("red")); |
|
||||||
} |
|
||||||
|
|
||||||
QString FinishedTorrents::getHashFromRow(unsigned int row) const { |
|
||||||
Q_ASSERT(row < (unsigned int)proxyModel->rowCount()); |
|
||||||
return proxyModel->data(proxyModel->index(row, F_HASH)).toString(); |
|
||||||
} |
|
||||||
|
|
||||||
// Will move it to download tab
|
|
||||||
void FinishedTorrents::deleteTorrent(QString hash){ |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
if(row == -1){ |
|
||||||
qDebug("Torrent is not in finished list, nothing to delete"); |
|
||||||
return; |
|
||||||
} |
|
||||||
// Select item just under (or above nothing under) the one that was deleted
|
|
||||||
QModelIndex current_prox_index = proxyModel->mapFromSource(finishedListModel->index(row, 0, finishedList->rootIndex())); |
|
||||||
bool was_selected = finishedList->selectionModel()->isSelected(current_prox_index); |
|
||||||
if(finishedListModel->rowCount() > 1 && was_selected) { |
|
||||||
QModelIndex under_prox_index; |
|
||||||
if(current_prox_index.row() == finishedListModel->rowCount()-1) |
|
||||||
under_prox_index = proxyModel->index(current_prox_index.row()-1, 0); |
|
||||||
else |
|
||||||
under_prox_index = proxyModel->index(current_prox_index.row()+1, 0); |
|
||||||
//downloadList->selectionModel()->select(under_prox_index, QItemSelectionModel::Current|QItemSelectionModel::Columns|QItemSelectionModel::Select);
|
|
||||||
finishedList->setCurrentIndex(under_prox_index); |
|
||||||
finishedList->update(); |
|
||||||
} |
|
||||||
// Actually delete the row
|
|
||||||
finishedListModel->removeRow(row); |
|
||||||
--nbFinished; |
|
||||||
emit finishedTorrentsNumberChanged(nbFinished); |
|
||||||
} |
|
||||||
|
|
||||||
// Show torrent properties dialog
|
|
||||||
void FinishedTorrents::showProperties(const QModelIndex &index){ |
|
||||||
showPropertiesFromHash(getHashFromRow(index.row())); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::showPropertiesFromHash(QString hash){ |
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
properties *prop = new properties(this, BTSession, h); |
|
||||||
connect(prop, SIGNAL(filteredFilesChanged(QString)), this, SLOT(updateFileSize(QString))); |
|
||||||
connect(prop, SIGNAL(trackersChanged(QString)), BTSession, SLOT(saveTrackerFile(QString))); |
|
||||||
prop->show(); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::updateFileSize(QString hash){ |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
finishedListModel->setData(finishedListModel->index(row, F_SIZE), QVariant((qlonglong)h.actual_size())); |
|
||||||
} |
|
||||||
|
|
||||||
// display properties of selected items
|
|
||||||
void FinishedTorrents::propertiesSelection(){ |
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); |
|
||||||
foreach(const QModelIndex &index, selectedIndexes){ |
|
||||||
if(index.column() == F_NAME){ |
|
||||||
showProperties(index); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::forceRecheck(){ |
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); |
|
||||||
foreach(const QModelIndex &index, selectedIndexes){ |
|
||||||
if(index.column() == F_NAME){ |
|
||||||
QString hash = getHashFromRow(index.row()); |
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
qDebug("Forcing recheck for torrent %s", hash.toLocal8Bit().data()); |
|
||||||
h.force_recheck(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::displayFinishedListMenu(const QPoint&){ |
|
||||||
QMenu myFinishedListMenu(this); |
|
||||||
// Enable/disable pause/start action given the DL state
|
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); |
|
||||||
bool has_pause = false, has_start = false, has_preview = false, hide_uper_seeding = false, super_seeding_enabled = false; |
|
||||||
bool first_torrent = true; |
|
||||||
foreach(const QModelIndex &index, selectedIndexes) { |
|
||||||
if(index.column() == F_NAME) { |
|
||||||
// Get the file name
|
|
||||||
QString hash = getHashFromRow(index.row()); |
|
||||||
// Get handle and pause the torrent
|
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
if(!h.is_valid()) continue; |
|
||||||
if(h.is_paused()) { |
|
||||||
if(!has_start) { |
|
||||||
myFinishedListMenu.addAction(actionStart); |
|
||||||
has_start = true; |
|
||||||
} |
|
||||||
}else{ |
|
||||||
if(!has_pause) { |
|
||||||
myFinishedListMenu.addAction(actionPause); |
|
||||||
has_pause = true; |
|
||||||
} |
|
||||||
} |
|
||||||
if(BTSession->isFilePreviewPossible(hash) && !has_preview) { |
|
||||||
myFinishedListMenu.addAction(actionPreview_file); |
|
||||||
has_preview = true; |
|
||||||
} |
|
||||||
if(h.super_seeding()) { |
|
||||||
if(first_torrent) { |
|
||||||
super_seeding_enabled = true; |
|
||||||
} else { |
|
||||||
if(!super_seeding_enabled) hide_uper_seeding = true; |
|
||||||
} |
|
||||||
} else { |
|
||||||
if(!first_torrent) { |
|
||||||
if(super_seeding_enabled) hide_uper_seeding = true; |
|
||||||
} |
|
||||||
} |
|
||||||
first_torrent = false; |
|
||||||
if(has_pause && has_start && has_preview && hide_uper_seeding) break; |
|
||||||
} |
|
||||||
} |
|
||||||
myFinishedListMenu.addSeparator(); |
|
||||||
myFinishedListMenu.addAction(actionDelete); |
|
||||||
myFinishedListMenu.addAction(actionDelete_Permanently); |
|
||||||
myFinishedListMenu.addSeparator(); |
|
||||||
if(!hide_uper_seeding) { |
|
||||||
QAction *act; |
|
||||||
if(super_seeding_enabled) |
|
||||||
act = myFinishedListMenu.addAction(QIcon(":/Icons/oxygen/button_ok.png"), tr("Super seeding mode")); |
|
||||||
else |
|
||||||
act = myFinishedListMenu.addAction(QIcon(":/Icons/oxygen/button_cancel.png"), tr("Super seeding mode")); |
|
||||||
// Bind signal / slot
|
|
||||||
connect(act, SIGNAL(triggered()), this, SLOT(toggleSuperSeedingMode())); |
|
||||||
} |
|
||||||
myFinishedListMenu.addAction(actionSet_upload_limit); |
|
||||||
myFinishedListMenu.addSeparator(); |
|
||||||
myFinishedListMenu.addAction(actionForce_recheck); |
|
||||||
myFinishedListMenu.addSeparator(); |
|
||||||
myFinishedListMenu.addAction(actionOpen_destination_folder); |
|
||||||
myFinishedListMenu.addAction(actionTorrent_Properties); |
|
||||||
myFinishedListMenu.addSeparator(); |
|
||||||
myFinishedListMenu.addAction(actionCopy_magnet_link); |
|
||||||
myFinishedListMenu.addAction(actionBuy_it); |
|
||||||
|
|
||||||
// Call menu
|
|
||||||
myFinishedListMenu.exec(QCursor::pos()); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hiding Columns functions |
|
||||||
*/ |
|
||||||
|
|
||||||
// hide/show columns menu
|
|
||||||
void FinishedTorrents::displayFinishedHoSMenu(const QPoint&){ |
|
||||||
QMenu hideshowColumn(this); |
|
||||||
hideshowColumn.setTitle(tr("Hide or Show Column")); |
|
||||||
int lastCol = F_RATIO; |
|
||||||
for(int i=0; i<=lastCol; i++) { |
|
||||||
hideshowColumn.addAction(getActionHoSCol(i)); |
|
||||||
} |
|
||||||
// Call menu
|
|
||||||
hideshowColumn.exec(QCursor::pos()); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::toggleSuperSeedingMode() { |
|
||||||
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes(); |
|
||||||
bool super_seeding_enabled = false, first_torrent=true; |
|
||||||
// Check whether we should disable or enable super seeding mode
|
|
||||||
foreach(const QModelIndex &index, selectedIndexes) { |
|
||||||
if(index.column() == F_NAME) { |
|
||||||
// Get the file name
|
|
||||||
QString hash = getHashFromRow(index.row()); |
|
||||||
// Get handle and pause the torrent
|
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
if(!h.is_valid()) continue; |
|
||||||
if(h.super_seeding()) { |
|
||||||
if(first_torrent) { |
|
||||||
super_seeding_enabled = true; |
|
||||||
} |
|
||||||
} else { |
|
||||||
if(!first_torrent) { |
|
||||||
if(super_seeding_enabled) super_seeding_enabled = false; |
|
||||||
} |
|
||||||
} |
|
||||||
first_torrent = false; |
|
||||||
} |
|
||||||
} |
|
||||||
// Toggling super seeding mode
|
|
||||||
foreach(const QModelIndex &index, selectedIndexes) { |
|
||||||
if(index.column() == F_NAME) { |
|
||||||
// Get the file name
|
|
||||||
QString hash = getHashFromRow(index.row()); |
|
||||||
// Get handle and pause the torrent
|
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
if(!h.is_valid()) continue; |
|
||||||
qDebug("Seeding mode=%d for torrent %s",!super_seeding_enabled, h.name().toLocal8Bit().data()); |
|
||||||
h.super_seeding(!super_seeding_enabled); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// toggle hide/show a column
|
|
||||||
void FinishedTorrents::hideOrShowColumn(int index) { |
|
||||||
unsigned int nbVisibleColumns = 0; |
|
||||||
unsigned int nbCols = finishedListModel->columnCount(); |
|
||||||
// Count visible columns
|
|
||||||
for(unsigned int i=0; i<nbCols; ++i) { |
|
||||||
if(!finishedList->isColumnHidden(i)) |
|
||||||
++nbVisibleColumns; |
|
||||||
} |
|
||||||
if(!finishedList->isColumnHidden(index)) { |
|
||||||
// User wants to hide the column
|
|
||||||
// Is there at least one other visible column?
|
|
||||||
if(nbVisibleColumns <= 1) return; |
|
||||||
// User can hide the column, do it.
|
|
||||||
finishedList->setColumnHidden(index, true); |
|
||||||
getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/oxygen/button_cancel.png"))); |
|
||||||
--nbVisibleColumns; |
|
||||||
} else { |
|
||||||
// User want to display the column
|
|
||||||
finishedList->setColumnHidden(index, false); |
|
||||||
getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/oxygen/button_ok.png"))); |
|
||||||
++nbVisibleColumns; |
|
||||||
} |
|
||||||
//resize all others non-hidden columns
|
|
||||||
for(unsigned int i=0; i<nbCols; ++i) { |
|
||||||
if(!finishedList->isColumnHidden(i)) { |
|
||||||
finishedList->setColumnWidth(i, (int)ceil(finishedList->columnWidth(i)+(finishedList->columnWidth(index)/nbVisibleColumns))); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::hideOrShowColumnName() { |
|
||||||
hideOrShowColumn(F_NAME); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::hideOrShowColumnSize() { |
|
||||||
hideOrShowColumn(F_SIZE); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::hideOrShowColumnUpSpeed() { |
|
||||||
hideOrShowColumn(F_UPSPEED); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::hideOrShowColumnSwarm() { |
|
||||||
hideOrShowColumn(F_SWARM); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::hideOrShowColumnPeers() { |
|
||||||
hideOrShowColumn(F_PEERS); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::hideOrShowColumnUpload() { |
|
||||||
hideOrShowColumn(F_UPLOAD); |
|
||||||
} |
|
||||||
|
|
||||||
void FinishedTorrents::hideOrShowColumnRatio() { |
|
||||||
hideOrShowColumn(F_RATIO); |
|
||||||
} |
|
||||||
|
|
||||||
// load the previous settings, and hide the columns
|
|
||||||
bool FinishedTorrents::loadHiddenColumns() { |
|
||||||
bool loaded = false; |
|
||||||
QSettings settings("qBittorrent", "qBittorrent"); |
|
||||||
QString line = settings.value("FinishedListColsHoS", QString()).toString(); |
|
||||||
QStringList ishidden_list; |
|
||||||
if(!line.isEmpty()) { |
|
||||||
ishidden_list = line.split(' '); |
|
||||||
if(ishidden_list.size() == finishedListModel->columnCount()-1) { |
|
||||||
unsigned int listSize = ishidden_list.size(); |
|
||||||
for(unsigned int i=0; i<listSize; ++i){ |
|
||||||
finishedList->header()->resizeSection(i, ishidden_list.at(i).toInt()); |
|
||||||
} |
|
||||||
loaded = true; |
|
||||||
} |
|
||||||
} |
|
||||||
for(int i=0; i<finishedListModel->columnCount()-1; i++) { |
|
||||||
if(loaded && ishidden_list.at(i) == "0") { |
|
||||||
finishedList->setColumnHidden(i, true); |
|
||||||
getActionHoSCol(i)->setIcon(QIcon(QString::fromUtf8(":/Icons/oxygen/button_cancel.png"))); |
|
||||||
} else { |
|
||||||
getActionHoSCol(i)->setIcon(QIcon(QString::fromUtf8(":/Icons/oxygen/button_ok.png"))); |
|
||||||
} |
|
||||||
} |
|
||||||
return loaded; |
|
||||||
} |
|
||||||
|
|
||||||
// save the hidden columns in settings
|
|
||||||
void FinishedTorrents::saveHiddenColumns() { |
|
||||||
QSettings settings("qBittorrent", "qBittorrent"); |
|
||||||
QStringList ishidden_list; |
|
||||||
short nbColumns = finishedListModel->columnCount()-1; |
|
||||||
|
|
||||||
for(short i=0; i<nbColumns; ++i){ |
|
||||||
if(finishedList->isColumnHidden(i)) { |
|
||||||
ishidden_list << QString::fromUtf8(misc::toString(0).c_str()); |
|
||||||
} else { |
|
||||||
ishidden_list << QString::fromUtf8(misc::toString(1).c_str()); |
|
||||||
} |
|
||||||
} |
|
||||||
settings.setValue("FinishedListColsHoS", ishidden_list.join(" ")); |
|
||||||
} |
|
||||||
|
|
||||||
// getter, return the action hide or show whose id is index
|
|
||||||
QAction* FinishedTorrents::getActionHoSCol(int index) { |
|
||||||
switch(index) { |
|
||||||
case F_NAME : |
|
||||||
return actionHOSColName; |
|
||||||
break; |
|
||||||
case F_SIZE : |
|
||||||
return actionHOSColSize; |
|
||||||
break; |
|
||||||
case F_UPSPEED : |
|
||||||
return actionHOSColUpSpeed; |
|
||||||
break; |
|
||||||
case F_SWARM : |
|
||||||
return actionHOSColSwarm; |
|
||||||
break; |
|
||||||
case F_PEERS : |
|
||||||
return actionHOSColPeers; |
|
||||||
break; |
|
||||||
case F_UPLOAD : |
|
||||||
return actionHOSColUpload; |
|
||||||
break; |
|
||||||
case F_RATIO : |
|
||||||
return actionHOSColRatio; |
|
||||||
break; |
|
||||||
default : |
|
||||||
return NULL; |
|
||||||
} |
|
||||||
} |
|
@ -1,105 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef SEEDING_H |
|
||||||
#define SEEDING_H |
|
||||||
|
|
||||||
#include "ui_seeding.h" |
|
||||||
#include "qtorrenthandle.h" |
|
||||||
|
|
||||||
class QStandardItemModel; |
|
||||||
class QSortFilterProxyModel; |
|
||||||
class bittorrent; |
|
||||||
class FinishedListDelegate; |
|
||||||
|
|
||||||
using namespace libtorrent; |
|
||||||
|
|
||||||
class FinishedTorrents : public QWidget, public Ui::seeding { |
|
||||||
Q_OBJECT |
|
||||||
private: |
|
||||||
QObject *parent; |
|
||||||
bittorrent *BTSession; |
|
||||||
FinishedListDelegate *finishedListDelegate; |
|
||||||
QStandardItemModel *finishedListModel; |
|
||||||
QSortFilterProxyModel *proxyModel; |
|
||||||
unsigned int nbFinished; |
|
||||||
void hideOrShowColumn(int index); |
|
||||||
bool loadHiddenColumns(); |
|
||||||
void saveHiddenColumns(); |
|
||||||
QAction* getActionHoSCol(int index); |
|
||||||
|
|
||||||
public: |
|
||||||
FinishedTorrents(QObject *parent, bittorrent *BTSession); |
|
||||||
~FinishedTorrents(); |
|
||||||
// Methods
|
|
||||||
bool loadColWidthFinishedList(); |
|
||||||
int getRowFromHash(QString hash) const; |
|
||||||
QStringList getSelectedTorrents(bool only_one=false) const; |
|
||||||
unsigned int getNbTorrentsInList() const; |
|
||||||
QString getHashFromRow(unsigned int row) const; |
|
||||||
|
|
||||||
protected slots: |
|
||||||
void showProperties(const QModelIndex &index); |
|
||||||
void displayFinishedListMenu(const QPoint&); |
|
||||||
void displayFinishedHoSMenu(const QPoint&); |
|
||||||
void setRowColor(int row, QString color); |
|
||||||
void saveColWidthFinishedList() const; |
|
||||||
void updateFileSize(QString hash); |
|
||||||
void on_actionSet_upload_limit_triggered(); |
|
||||||
void notifyTorrentDoubleClicked(const QModelIndex& index); |
|
||||||
void hideOrShowColumnName(); |
|
||||||
void hideOrShowColumnSize(); |
|
||||||
void hideOrShowColumnUpSpeed(); |
|
||||||
void hideOrShowColumnSwarm(); |
|
||||||
void hideOrShowColumnPeers(); |
|
||||||
void hideOrShowColumnUpload(); |
|
||||||
void hideOrShowColumnRatio(); |
|
||||||
void forceRecheck(); |
|
||||||
void toggleSuperSeedingMode(); |
|
||||||
|
|
||||||
public slots: |
|
||||||
void addTorrent(QString hash); |
|
||||||
void updateTorrent(QTorrentHandle h); |
|
||||||
void pauseTorrent(QString hash); |
|
||||||
void propertiesSelection(); |
|
||||||
void deleteTorrent(QString hash); |
|
||||||
void showPropertiesFromHash(QString hash); |
|
||||||
void loadLastSortedColumn(); |
|
||||||
void saveLastSortedColumn(); |
|
||||||
void updateMetadata(QTorrentHandle &h); |
|
||||||
|
|
||||||
signals: |
|
||||||
void torrentMovedFromFinishedList(QString); |
|
||||||
void torrentDoubleClicked(QString hash, bool finished); |
|
||||||
void finishedTorrentsNumberChanged(unsigned int); |
|
||||||
|
|
||||||
}; |
|
||||||
|
|
||||||
#endif |
|
Before Width: | Height: | Size: 856 B |
Before Width: | Height: | Size: 493 B |
@ -0,0 +1,4 @@ |
|||||||
|
#ifndef TRANSFERLISTFILTERSWIDGET_H |
||||||
|
#define TRANSFERLISTFILTERSWIDGET_H |
||||||
|
|
||||||
|
#endif // TRANSFERLISTFILTERSWIDGET_H
|
@ -1,193 +0,0 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<ui version="4.0"> |
|
||||||
<class>downloading</class> |
|
||||||
<widget class="QWidget" name="downloading"> |
|
||||||
<property name="geometry"> |
|
||||||
<rect> |
|
||||||
<x>0</x> |
|
||||||
<y>0</y> |
|
||||||
<width>811</width> |
|
||||||
<height>453</height> |
|
||||||
</rect> |
|
||||||
</property> |
|
||||||
<property name="windowTitle"> |
|
||||||
<string>Search</string> |
|
||||||
</property> |
|
||||||
<layout class="QVBoxLayout"> |
|
||||||
<item> |
|
||||||
<layout class="QVBoxLayout"> |
|
||||||
<property name="spacing"> |
|
||||||
<number>6</number> |
|
||||||
</property> |
|
||||||
<property name="margin"> |
|
||||||
<number>0</number> |
|
||||||
</property> |
|
||||||
<item> |
|
||||||
<widget class="QTreeView" name="downloadList"> |
|
||||||
<property name="minimumSize"> |
|
||||||
<size> |
|
||||||
<width>0</width> |
|
||||||
<height>0</height> |
|
||||||
</size> |
|
||||||
</property> |
|
||||||
<property name="contextMenuPolicy"> |
|
||||||
<enum>Qt::CustomContextMenu</enum> |
|
||||||
</property> |
|
||||||
<property name="autoScroll"> |
|
||||||
<bool>true</bool> |
|
||||||
</property> |
|
||||||
<property name="selectionMode"> |
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum> |
|
||||||
</property> |
|
||||||
<property name="indentation"> |
|
||||||
<number>1</number> |
|
||||||
</property> |
|
||||||
<property name="itemsExpandable"> |
|
||||||
<bool>false</bool> |
|
||||||
</property> |
|
||||||
</widget> |
|
||||||
</item> |
|
||||||
</layout> |
|
||||||
</item> |
|
||||||
</layout> |
|
||||||
<action name="actionStart"> |
|
||||||
<property name="text"> |
|
||||||
<string>Start</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionPause"> |
|
||||||
<property name="text"> |
|
||||||
<string>Pause</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionDelete"> |
|
||||||
<property name="text"> |
|
||||||
<string>Delete</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionPreview_file"> |
|
||||||
<property name="text"> |
|
||||||
<string>Preview file</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionSet_upload_limit"> |
|
||||||
<property name="text"> |
|
||||||
<string>Set upload limit</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionSet_download_limit"> |
|
||||||
<property name="text"> |
|
||||||
<string>Set download limit</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionDelete_Permanently"> |
|
||||||
<property name="text"> |
|
||||||
<string>Delete Permanently</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionTorrent_Properties"> |
|
||||||
<property name="text"> |
|
||||||
<string>Torrent Properties</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionOpen_destination_folder"> |
|
||||||
<property name="icon"> |
|
||||||
<iconset resource="icons.qrc"> |
|
||||||
<normaloff>:/Icons/oxygen/folder.png</normaloff>:/Icons/oxygen/folder.png</iconset> |
|
||||||
</property> |
|
||||||
<property name="text"> |
|
||||||
<string>Open destination folder</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionHOSColName"> |
|
||||||
<property name="text"> |
|
||||||
<string>Name</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionHOSColSize"> |
|
||||||
<property name="text"> |
|
||||||
<string>Size</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionHOSColProgress"> |
|
||||||
<property name="text"> |
|
||||||
<string>Progress</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionHOSColDownSpeed"> |
|
||||||
<property name="text"> |
|
||||||
<string>DLSpeed</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionHOSColUpSpeed"> |
|
||||||
<property name="text"> |
|
||||||
<string>UpSpeed</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionHOSColSeedersLeechers"> |
|
||||||
<property name="text"> |
|
||||||
<string>Seeds/Leechs</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionHOSColRatio"> |
|
||||||
<property name="text"> |
|
||||||
<string>Ratio</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionHOSColEta"> |
|
||||||
<property name="text"> |
|
||||||
<string>ETA</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionBuy_it"> |
|
||||||
<property name="icon"> |
|
||||||
<iconset resource="icons.qrc"> |
|
||||||
<normaloff>:/Icons/oxygen/wallet.png</normaloff>:/Icons/oxygen/wallet.png</iconset> |
|
||||||
</property> |
|
||||||
<property name="text"> |
|
||||||
<string>Buy it</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionHOSColPriority"> |
|
||||||
<property name="text"> |
|
||||||
<string>Priority</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionIncreasePriority"> |
|
||||||
<property name="icon"> |
|
||||||
<iconset resource="icons.qrc"> |
|
||||||
<normaloff>:/Icons/skin/increase.png</normaloff>:/Icons/skin/increase.png</iconset> |
|
||||||
</property> |
|
||||||
<property name="text"> |
|
||||||
<string>Increase priority</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionDecreasePriority"> |
|
||||||
<property name="icon"> |
|
||||||
<iconset resource="icons.qrc"> |
|
||||||
<normaloff>:/Icons/skin/decrease.png</normaloff>:/Icons/skin/decrease.png</iconset> |
|
||||||
</property> |
|
||||||
<property name="text"> |
|
||||||
<string>Decrease priority</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionForce_recheck"> |
|
||||||
<property name="icon"> |
|
||||||
<iconset resource="icons.qrc"> |
|
||||||
<normaloff>:/Icons/oxygen/gear.png</normaloff>:/Icons/oxygen/gear.png</iconset> |
|
||||||
</property> |
|
||||||
<property name="text"> |
|
||||||
<string>Force recheck</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
<action name="actionCopy_magnet_link"> |
|
||||||
<property name="text"> |
|
||||||
<string>Copy magnet link</string> |
|
||||||
</property> |
|
||||||
</action> |
|
||||||
</widget> |
|
||||||
<resources> |
|
||||||
<include location="icons.qrc"/> |
|
||||||
</resources> |
|
||||||
<connections/> |
|
||||||
</ui> |
|
@ -1,774 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 |
|
||||||
*/ |
|
||||||
#include "downloadingTorrents.h" |
|
||||||
#include "misc.h" |
|
||||||
#include "properties_imp.h" |
|
||||||
#include "bittorrent.h" |
|
||||||
#include "allocationDlg.h" |
|
||||||
#include "DLListDelegate.h" |
|
||||||
#include "GUI.h" |
|
||||||
|
|
||||||
#include <QFile> |
|
||||||
#include <QSettings> |
|
||||||
#include <QStandardItemModel> |
|
||||||
#include <QSortFilterProxyModel> |
|
||||||
#include <QHeaderView> |
|
||||||
#include <QTime> |
|
||||||
#include <QMenu> |
|
||||||
|
|
||||||
DownloadingTorrents::DownloadingTorrents(QObject *parent, bittorrent *BTSession) : parent(parent), BTSession(BTSession), nbTorrents(0) { |
|
||||||
setupUi(this); |
|
||||||
// Setting icons
|
|
||||||
actionStart->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/play.png"))); |
|
||||||
actionPause->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/pause.png"))); |
|
||||||
actionDelete->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/delete.png"))); |
|
||||||
actionPreview_file->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/preview.png"))); |
|
||||||
actionSet_upload_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png"))); |
|
||||||
actionSet_download_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png"))); |
|
||||||
actionDelete_Permanently->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/delete_perm.png"))); |
|
||||||
actionTorrent_Properties->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/properties.png"))); |
|
||||||
actionCopy_magnet_link->setIcon(QIcon(QString::fromUtf8(":/Icons/magnet.png"))); |
|
||||||
// tabBottom->setTabIcon(0, QIcon(QString::fromUtf8(":/Icons/oxygen/log.png")));
|
|
||||||
// tabBottom->setTabIcon(1, QIcon(QString::fromUtf8(":/Icons/oxygen/filter.png")));
|
|
||||||
|
|
||||||
// Set Download list model
|
|
||||||
DLListModel = new QStandardItemModel(0,10); |
|
||||||
DLListModel->setHeaderData(NAME, Qt::Horizontal, tr("Name", "i.e: file name")); |
|
||||||
DLListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size", "i.e: file size")); |
|
||||||
DLListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded")); |
|
||||||
DLListModel->setHeaderData(DLSPEED, Qt::Horizontal, tr("DL Speed", "i.e: Download speed")); |
|
||||||
DLListModel->setHeaderData(UPSPEED, Qt::Horizontal, tr("UP Speed", "i.e: Upload speed")); |
|
||||||
DLListModel->setHeaderData(SEEDSLEECH, Qt::Horizontal, tr("Seeds/Leechers", "i.e: full/partial sources")); |
|
||||||
DLListModel->setHeaderData(RATIO, Qt::Horizontal, tr("Ratio")); |
|
||||||
DLListModel->setHeaderData(ETA, Qt::Horizontal, tr("ETA", "i.e: Estimated Time of Arrival / Time left")); |
|
||||||
DLListModel->setHeaderData(PRIORITY, Qt::Horizontal, "#"); |
|
||||||
downloadList->setRootIsDecorated(false); |
|
||||||
downloadList->setAllColumnsShowFocus(true); |
|
||||||
DLDelegate = new DLListDelegate(downloadList); |
|
||||||
downloadList->setItemDelegate(DLDelegate); |
|
||||||
proxyModel = new QSortFilterProxyModel(); |
|
||||||
proxyModel->setDynamicSortFilter(true); |
|
||||||
proxyModel->setSourceModel(DLListModel); |
|
||||||
downloadList->setModel(proxyModel); |
|
||||||
downloadList->setSortingEnabled(true); |
|
||||||
// Hide priority column
|
|
||||||
downloadList->hideColumn(PRIORITY); |
|
||||||
// Hide hash column
|
|
||||||
downloadList->hideColumn(HASH); |
|
||||||
loadHiddenColumns(); |
|
||||||
|
|
||||||
connect(BTSession, SIGNAL(metadataReceived(QTorrentHandle&)), this, SLOT(updateMetadata(QTorrentHandle&))); |
|
||||||
|
|
||||||
// Load last columns width for download list
|
|
||||||
if(!loadColWidthDLList()) { |
|
||||||
downloadList->header()->resizeSection(0, 200); |
|
||||||
} |
|
||||||
// Make download list header clickable for sorting
|
|
||||||
downloadList->header()->setClickable(true); |
|
||||||
downloadList->header()->setSortIndicatorShown(true); |
|
||||||
// Connecting Actions to slots
|
|
||||||
connect(downloadList, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(notifyTorrentDoubleClicked(const QModelIndex&))); |
|
||||||
connect(downloadList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLListMenu(const QPoint&))); |
|
||||||
downloadList->header()->setContextMenuPolicy(Qt::CustomContextMenu); |
|
||||||
connect(downloadList->header(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayDLHoSMenu(const QPoint&))); |
|
||||||
// Actions
|
|
||||||
connect(actionPause, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionPause_triggered())); |
|
||||||
connect(actionStart, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionStart_triggered())); |
|
||||||
connect(actionDelete, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionDelete_triggered())); |
|
||||||
connect(actionIncreasePriority, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionIncreasePriority_triggered())); |
|
||||||
connect(actionDecreasePriority, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionDecreasePriority_triggered())); |
|
||||||
connect(actionPreview_file, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionPreview_file_triggered())); |
|
||||||
connect(actionDelete_Permanently, SIGNAL(triggered()), (GUI*)parent, SLOT(on_actionDelete_Permanently_triggered())); |
|
||||||
connect(actionOpen_destination_folder, SIGNAL(triggered()), (GUI*)parent, SLOT(openDestinationFolder())); |
|
||||||
connect(actionTorrent_Properties, SIGNAL(triggered()), this, SLOT(propertiesSelection())); |
|
||||||
connect(actionForce_recheck, SIGNAL(triggered()), this, SLOT(forceRecheck())); |
|
||||||
connect(actionBuy_it, SIGNAL(triggered()), (GUI*)parent, SLOT(goBuyPage())); |
|
||||||
connect(actionCopy_magnet_link, SIGNAL(triggered()), (GUI*)parent, SLOT(copyMagnetURI())); |
|
||||||
|
|
||||||
connect(actionHOSColName, SIGNAL(triggered()), this, SLOT(hideOrShowColumnName())); |
|
||||||
connect(actionHOSColSize, SIGNAL(triggered()), this, SLOT(hideOrShowColumnSize())); |
|
||||||
connect(actionHOSColProgress, SIGNAL(triggered()), this, SLOT(hideOrShowColumnProgress())); |
|
||||||
connect(actionHOSColDownSpeed, SIGNAL(triggered()), this, SLOT(hideOrShowColumnDownSpeed())); |
|
||||||
connect(actionHOSColUpSpeed, SIGNAL(triggered()), this, SLOT(hideOrShowColumnUpSpeed())); |
|
||||||
connect(actionHOSColSeedersLeechers, SIGNAL(triggered()), this, SLOT(hideOrShowColumnSeedersLeechers())); |
|
||||||
connect(actionHOSColRatio, SIGNAL(triggered()), this, SLOT(hideOrShowColumnRatio())); |
|
||||||
connect(actionHOSColEta, SIGNAL(triggered()), this, SLOT(hideOrShowColumnEta())); |
|
||||||
connect(actionHOSColPriority, SIGNAL(triggered()), this, SLOT(hideOrShowColumnPriority())); |
|
||||||
|
|
||||||
// Load last sorted column
|
|
||||||
loadLastSortedColumn(); |
|
||||||
// Set info Bar infos
|
|
||||||
BTSession->addConsoleMessage(tr("qBittorrent %1 started.", "e.g: qBittorrent v0.x started.").arg(QString::fromUtf8(""VERSION))); |
|
||||||
qDebug("Download tab built"); |
|
||||||
} |
|
||||||
|
|
||||||
DownloadingTorrents::~DownloadingTorrents() { |
|
||||||
saveLastSortedColumn(); |
|
||||||
saveColWidthDLList(); |
|
||||||
saveHiddenColumns(); |
|
||||||
delete DLDelegate; |
|
||||||
delete proxyModel; |
|
||||||
delete DLListModel; |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::enablePriorityColumn(bool enable) { |
|
||||||
if(enable) { |
|
||||||
downloadList->showColumn(PRIORITY); |
|
||||||
} else { |
|
||||||
downloadList->hideColumn(PRIORITY); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::notifyTorrentDoubleClicked(const QModelIndex& index) { |
|
||||||
unsigned int row = index.row(); |
|
||||||
QString hash = getHashFromRow(row); |
|
||||||
emit torrentDoubleClicked(hash, false); |
|
||||||
} |
|
||||||
|
|
||||||
unsigned int DownloadingTorrents::getNbTorrentsInList() const { |
|
||||||
return nbTorrents; |
|
||||||
} |
|
||||||
|
|
||||||
// Note: do not actually pause the torrent in BT session
|
|
||||||
void DownloadingTorrents::pauseTorrent(QString hash) { |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
if(row == -1) |
|
||||||
return; |
|
||||||
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.0)); |
|
||||||
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.0)); |
|
||||||
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1)); |
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QIcon(QString::fromUtf8(":/Icons/skin/paused.png")), Qt::DecorationRole); |
|
||||||
DLListModel->setData(DLListModel->index(row, SEEDSLEECH), QVariant(QString::fromUtf8("0/0"))); |
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
//DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)h.progress()));
|
|
||||||
setRowColor(row, QString::fromUtf8("red")); |
|
||||||
} |
|
||||||
|
|
||||||
QString DownloadingTorrents::getHashFromRow(unsigned int row) const { |
|
||||||
Q_ASSERT(row < (unsigned int)proxyModel->rowCount()); |
|
||||||
return proxyModel->data(proxyModel->index(row, HASH)).toString(); |
|
||||||
} |
|
||||||
|
|
||||||
// Show torrent properties dialog
|
|
||||||
void DownloadingTorrents::showProperties(const QModelIndex &index) { |
|
||||||
showPropertiesFromHash(getHashFromRow(index.row())); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::showPropertiesFromHash(QString hash) { |
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
if(h.is_valid() && h.has_metadata()) { |
|
||||||
properties *prop = new properties(this, BTSession, h); |
|
||||||
connect(prop, SIGNAL(filteredFilesChanged(QString)), this, SLOT(updateFileSizeAndProgress(QString))); |
|
||||||
connect(prop, SIGNAL(trackersChanged(QString)), BTSession, SLOT(saveTrackerFile(QString))); |
|
||||||
prop->show(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Remove a torrent from the download list but NOT from the BT Session
|
|
||||||
void DownloadingTorrents::deleteTorrent(QString hash) { |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
if(row == -1){ |
|
||||||
qDebug("torrent is not in download list, nothing to delete"); |
|
||||||
return; |
|
||||||
} |
|
||||||
// Select item just under (or above nothing under) the one that was deleted
|
|
||||||
QModelIndex current_prox_index = proxyModel->mapFromSource(DLListModel->index(row, 0, downloadList->rootIndex())); |
|
||||||
bool was_selected = downloadList->selectionModel()->isSelected(current_prox_index); |
|
||||||
if(DLListModel->rowCount() > 1 && was_selected) { |
|
||||||
QModelIndex under_prox_index; |
|
||||||
if(current_prox_index.row() == DLListModel->rowCount()-1) |
|
||||||
under_prox_index = proxyModel->index(current_prox_index.row()-1, 0); |
|
||||||
else |
|
||||||
under_prox_index = proxyModel->index(current_prox_index.row()+1, 0); |
|
||||||
//downloadList->selectionModel()->select(under_prox_index, QItemSelectionModel::Current|QItemSelectionModel::Columns|QItemSelectionModel::Select);
|
|
||||||
downloadList->setCurrentIndex(under_prox_index); |
|
||||||
downloadList->update(); |
|
||||||
} |
|
||||||
// Actually delete the row
|
|
||||||
DLListModel->removeRow(row); |
|
||||||
--nbTorrents; |
|
||||||
emit unfinishedTorrentsNumberChanged(nbTorrents); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::on_actionSet_download_limit_triggered() { |
|
||||||
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); |
|
||||||
QStringList hashes; |
|
||||||
foreach(const QModelIndex &index, selectedIndexes) { |
|
||||||
if(index.column() == NAME) { |
|
||||||
// Get the file hash
|
|
||||||
hashes << getHashFromRow(index.row()); |
|
||||||
} |
|
||||||
} |
|
||||||
Q_ASSERT(hashes.size() > 0); |
|
||||||
new BandwidthAllocationDialog(this, false, BTSession, hashes); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::on_actionSet_upload_limit_triggered() { |
|
||||||
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); |
|
||||||
QStringList hashes; |
|
||||||
foreach(const QModelIndex &index, selectedIndexes) { |
|
||||||
if(index.column() == NAME) { |
|
||||||
// Get the file hash
|
|
||||||
hashes << getHashFromRow(index.row()); |
|
||||||
} |
|
||||||
} |
|
||||||
Q_ASSERT(hashes.size() > 0); |
|
||||||
new BandwidthAllocationDialog(this, true, BTSession, hashes); |
|
||||||
} |
|
||||||
|
|
||||||
// display properties of selected items
|
|
||||||
void DownloadingTorrents::propertiesSelection(){ |
|
||||||
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); |
|
||||||
foreach(const QModelIndex &index, selectedIndexes){ |
|
||||||
if(index.column() == NAME){ |
|
||||||
showProperties(index); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::forceRecheck() { |
|
||||||
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); |
|
||||||
foreach(const QModelIndex &index, selectedIndexes){ |
|
||||||
if(index.column() == NAME){ |
|
||||||
QString hash = getHashFromRow(index.row()); |
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
if(h.is_valid() && h.has_metadata()) |
|
||||||
h.force_recheck(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::displayDLListMenu(const QPoint&) { |
|
||||||
QMenu myDLLlistMenu(this); |
|
||||||
// Enable/disable pause/start action given the DL state
|
|
||||||
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); |
|
||||||
bool has_pause = false, has_start = false, has_preview = false; |
|
||||||
bool one_has_metadata = false; |
|
||||||
QTorrentHandle h; |
|
||||||
qDebug("Displaying menu"); |
|
||||||
foreach(const QModelIndex &index, selectedIndexes) { |
|
||||||
if(index.column() == NAME) { |
|
||||||
// Get the file name
|
|
||||||
QString hash = getHashFromRow(index.row()); |
|
||||||
// Get handle and pause the torrent
|
|
||||||
h = BTSession->getTorrentHandle(hash); |
|
||||||
if(!h.is_valid()) continue; |
|
||||||
if(h.has_metadata()) { |
|
||||||
one_has_metadata = true; |
|
||||||
} |
|
||||||
if(h.is_paused()) { |
|
||||||
if(!has_start) { |
|
||||||
myDLLlistMenu.addAction(actionStart); |
|
||||||
has_start = true; |
|
||||||
} |
|
||||||
}else{ |
|
||||||
if(!has_pause) { |
|
||||||
myDLLlistMenu.addAction(actionPause); |
|
||||||
has_pause = true; |
|
||||||
} |
|
||||||
} |
|
||||||
if(h.has_metadata() && BTSession->isFilePreviewPossible(hash) && !has_preview) { |
|
||||||
myDLLlistMenu.addAction(actionPreview_file); |
|
||||||
has_preview = true; |
|
||||||
} |
|
||||||
if(has_pause && has_start && has_preview) break; |
|
||||||
} |
|
||||||
} |
|
||||||
myDLLlistMenu.addSeparator(); |
|
||||||
myDLLlistMenu.addAction(actionDelete); |
|
||||||
myDLLlistMenu.addAction(actionDelete_Permanently); |
|
||||||
myDLLlistMenu.addSeparator(); |
|
||||||
myDLLlistMenu.addAction(actionSet_download_limit); |
|
||||||
myDLLlistMenu.addAction(actionSet_upload_limit); |
|
||||||
myDLLlistMenu.addSeparator(); |
|
||||||
if(one_has_metadata) { |
|
||||||
myDLLlistMenu.addAction(actionForce_recheck); |
|
||||||
myDLLlistMenu.addSeparator(); |
|
||||||
} |
|
||||||
myDLLlistMenu.addAction(actionOpen_destination_folder); |
|
||||||
if(one_has_metadata) |
|
||||||
myDLLlistMenu.addAction(actionTorrent_Properties); |
|
||||||
if(BTSession->isQueueingEnabled()) { |
|
||||||
myDLLlistMenu.addSeparator(); |
|
||||||
myDLLlistMenu.addAction(actionIncreasePriority); |
|
||||||
myDLLlistMenu.addAction(actionDecreasePriority); |
|
||||||
} |
|
||||||
myDLLlistMenu.addSeparator(); |
|
||||||
myDLLlistMenu.addAction(actionCopy_magnet_link); |
|
||||||
myDLLlistMenu.addAction(actionBuy_it); |
|
||||||
// Call menu
|
|
||||||
myDLLlistMenu.exec(QCursor::pos()); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Hiding Columns functions |
|
||||||
*/ |
|
||||||
|
|
||||||
// hide/show columns menu
|
|
||||||
void DownloadingTorrents::displayDLHoSMenu(const QPoint&){ |
|
||||||
QMenu hideshowColumn(this); |
|
||||||
hideshowColumn.setTitle(tr("Hide or Show Column")); |
|
||||||
int lastCol; |
|
||||||
if(BTSession->isQueueingEnabled()) { |
|
||||||
lastCol = PRIORITY; |
|
||||||
} else { |
|
||||||
lastCol = ETA; |
|
||||||
} |
|
||||||
for(int i=0; i <= lastCol; ++i) { |
|
||||||
hideshowColumn.addAction(getActionHoSCol(i)); |
|
||||||
} |
|
||||||
// Call menu
|
|
||||||
hideshowColumn.exec(QCursor::pos()); |
|
||||||
} |
|
||||||
|
|
||||||
// toggle hide/show a column
|
|
||||||
void DownloadingTorrents::hideOrShowColumn(int index) { |
|
||||||
unsigned int nbVisibleColumns = 0; |
|
||||||
unsigned int nbCols = DLListModel->columnCount(); |
|
||||||
// Count visible columns
|
|
||||||
for(unsigned int i=0; i<nbCols; ++i) { |
|
||||||
if(!downloadList->isColumnHidden(i)) |
|
||||||
++nbVisibleColumns; |
|
||||||
} |
|
||||||
if(!downloadList->isColumnHidden(index)) { |
|
||||||
// User wants to hide the column
|
|
||||||
// Is there at least one other visible column?
|
|
||||||
if(nbVisibleColumns <= 1) return; |
|
||||||
// User can hide the column, do it.
|
|
||||||
downloadList->setColumnHidden(index, true); |
|
||||||
getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/oxygen/button_cancel.png"))); |
|
||||||
--nbVisibleColumns; |
|
||||||
} else { |
|
||||||
// User want to display the column
|
|
||||||
downloadList->setColumnHidden(index, false); |
|
||||||
getActionHoSCol(index)->setIcon(QIcon(QString::fromUtf8(":/Icons/oxygen/button_ok.png"))); |
|
||||||
++nbVisibleColumns; |
|
||||||
} |
|
||||||
//resize all others non-hidden columns
|
|
||||||
for(unsigned int i=0; i<nbCols; ++i) { |
|
||||||
if(!downloadList->isColumnHidden(i)) { |
|
||||||
downloadList->setColumnWidth(i, (int)ceil(downloadList->columnWidth(i)+(downloadList->columnWidth(index)/nbVisibleColumns))); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// save the hidden columns in settings
|
|
||||||
void DownloadingTorrents::saveHiddenColumns() { |
|
||||||
QSettings settings("qBittorrent", "qBittorrent"); |
|
||||||
QStringList ishidden_list; |
|
||||||
short nbColumns = DLListModel->columnCount()-1; |
|
||||||
|
|
||||||
for(short i=0; i<nbColumns; ++i){ |
|
||||||
if(downloadList->isColumnHidden(i)) { |
|
||||||
ishidden_list << QString::fromUtf8(misc::toString(0).c_str()); |
|
||||||
} else { |
|
||||||
ishidden_list << QString::fromUtf8(misc::toString(1).c_str()); |
|
||||||
} |
|
||||||
} |
|
||||||
settings.setValue("DownloadListColsHoS", ishidden_list.join(" ")); |
|
||||||
} |
|
||||||
|
|
||||||
// load the previous settings, and hide the columns
|
|
||||||
bool DownloadingTorrents::loadHiddenColumns() { |
|
||||||
bool loaded = false; |
|
||||||
QSettings settings("qBittorrent", "qBittorrent"); |
|
||||||
QString line = settings.value("DownloadListColsHoS", QString()).toString(); |
|
||||||
QStringList ishidden_list; |
|
||||||
if(!line.isEmpty()) { |
|
||||||
ishidden_list = line.split(' '); |
|
||||||
if(ishidden_list.size() == DLListModel->columnCount()-1) { |
|
||||||
unsigned int listSize = ishidden_list.size(); |
|
||||||
for(unsigned int i=0; i<listSize; ++i){ |
|
||||||
downloadList->header()->resizeSection(i, ishidden_list.at(i).toInt()); |
|
||||||
} |
|
||||||
loaded = true; |
|
||||||
} |
|
||||||
} |
|
||||||
for(int i=0; i<DLListModel->columnCount()-1; i++) { |
|
||||||
if(loaded && ishidden_list.at(i) == "0") { |
|
||||||
downloadList->setColumnHidden(i, true); |
|
||||||
getActionHoSCol(i)->setIcon(QIcon(QString::fromUtf8(":/Icons/oxygen/button_cancel.png"))); |
|
||||||
} else { |
|
||||||
getActionHoSCol(i)->setIcon(QIcon(QString::fromUtf8(":/Icons/oxygen/button_ok.png"))); |
|
||||||
} |
|
||||||
} |
|
||||||
return loaded; |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::hideOrShowColumnName() { |
|
||||||
hideOrShowColumn(NAME); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::hideOrShowColumnSize() { |
|
||||||
hideOrShowColumn(SIZE); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::hideOrShowColumnProgress() { |
|
||||||
hideOrShowColumn(PROGRESS); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::hideOrShowColumnDownSpeed() { |
|
||||||
hideOrShowColumn(DLSPEED); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::hideOrShowColumnUpSpeed() { |
|
||||||
hideOrShowColumn(UPSPEED); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::hideOrShowColumnSeedersLeechers() { |
|
||||||
hideOrShowColumn(SEEDSLEECH); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::hideOrShowColumnRatio() { |
|
||||||
hideOrShowColumn(RATIO); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::hideOrShowColumnEta() { |
|
||||||
hideOrShowColumn(ETA); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::hideOrShowColumnPriority() { |
|
||||||
hideOrShowColumn(PRIORITY); |
|
||||||
} |
|
||||||
|
|
||||||
// getter, return the action hide or show whose id is index
|
|
||||||
QAction* DownloadingTorrents::getActionHoSCol(int index) { |
|
||||||
switch(index) { |
|
||||||
case NAME : |
|
||||||
return actionHOSColName; |
|
||||||
break; |
|
||||||
case SIZE : |
|
||||||
return actionHOSColSize; |
|
||||||
break; |
|
||||||
case PROGRESS : |
|
||||||
return actionHOSColProgress; |
|
||||||
break; |
|
||||||
case DLSPEED : |
|
||||||
return actionHOSColDownSpeed; |
|
||||||
break; |
|
||||||
case UPSPEED : |
|
||||||
return actionHOSColUpSpeed; |
|
||||||
break; |
|
||||||
case SEEDSLEECH : |
|
||||||
return actionHOSColSeedersLeechers; |
|
||||||
break; |
|
||||||
case RATIO : |
|
||||||
return actionHOSColRatio; |
|
||||||
break; |
|
||||||
case ETA : |
|
||||||
return actionHOSColEta; |
|
||||||
break; |
|
||||||
case PRIORITY : |
|
||||||
return actionHOSColPriority; |
|
||||||
break; |
|
||||||
default : |
|
||||||
return NULL; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
QStringList DownloadingTorrents::getSelectedTorrents(bool only_one) const{ |
|
||||||
QStringList res; |
|
||||||
QModelIndexList selectedIndexes = downloadList->selectionModel()->selectedIndexes(); |
|
||||||
foreach(const QModelIndex &index, selectedIndexes) { |
|
||||||
if(index.column() == NAME) { |
|
||||||
// Get the file hash
|
|
||||||
QString hash = getHashFromRow(index.row()); |
|
||||||
res << hash; |
|
||||||
if(only_one) break; |
|
||||||
} |
|
||||||
} |
|
||||||
return res; |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::updateMetadata(QTorrentHandle &h) { |
|
||||||
QString hash = h.hash(); |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
if(row != -1) { |
|
||||||
qDebug("Updating torrent metadata in download list"); |
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(h.name())); |
|
||||||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)h.actual_size())); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// get information from torrent handles and
|
|
||||||
// update download list accordingly
|
|
||||||
bool DownloadingTorrents::updateTorrent(QTorrentHandle h) { |
|
||||||
if(!h.is_valid()) return false; |
|
||||||
bool added = false; |
|
||||||
try{ |
|
||||||
QString hash = h.hash(); |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
if(row == -1) { |
|
||||||
qDebug("Info: Could not find filename in download list, adding it..."); |
|
||||||
addTorrent(hash); |
|
||||||
row = getRowFromHash(hash); |
|
||||||
added = true; |
|
||||||
} |
|
||||||
Q_ASSERT(row != -1); |
|
||||||
// Update Priority
|
|
||||||
if(BTSession->isQueueingEnabled()) { |
|
||||||
DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((int)BTSession->getDlTorrentPriority(hash))); |
|
||||||
if(h.is_queued()) { |
|
||||||
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) { |
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/time.png"))), Qt::DecorationRole); |
|
||||||
if(!downloadList->isColumnHidden(PROGRESS)) { |
|
||||||
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)h.progress())); |
|
||||||
} |
|
||||||
}else { |
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/queued.png"))), Qt::DecorationRole); |
|
||||||
if(!downloadList->isColumnHidden(ETA)) { |
|
||||||
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1)); |
|
||||||
} |
|
||||||
} |
|
||||||
// Reset speeds and seeds/leech
|
|
||||||
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.)); |
|
||||||
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.)); |
|
||||||
DLListModel->setData(DLListModel->index(row, SEEDSLEECH), QVariant("0/0")); |
|
||||||
setRowColor(row, QString::fromUtf8("grey")); |
|
||||||
return added; |
|
||||||
} |
|
||||||
} |
|
||||||
if(!downloadList->isColumnHidden(PROGRESS)) |
|
||||||
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)h.progress())); |
|
||||||
// No need to update a paused torrent
|
|
||||||
if(h.is_paused()) return added; |
|
||||||
// Parse download state
|
|
||||||
// Setting download state
|
|
||||||
switch(h.state()) { |
|
||||||
case torrent_status::checking_files: |
|
||||||
case torrent_status::queued_for_checking: |
|
||||||
case torrent_status::checking_resume_data: |
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/oxygen/time.png"))), Qt::DecorationRole); |
|
||||||
setRowColor(row, QString::fromUtf8("grey")); |
|
||||||
break; |
|
||||||
case torrent_status::downloading: |
|
||||||
case torrent_status::downloading_metadata: |
|
||||||
if(h.download_payload_rate() > 0) { |
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/downloading.png"))), Qt::DecorationRole); |
|
||||||
if(!downloadList->isColumnHidden(ETA)) { |
|
||||||
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)BTSession->getETA(hash))); |
|
||||||
} |
|
||||||
setRowColor(row, QString::fromUtf8("green")); |
|
||||||
}else{ |
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalled.png"))), Qt::DecorationRole); |
|
||||||
if(!downloadList->isColumnHidden(ETA)) { |
|
||||||
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1)); |
|
||||||
} |
|
||||||
setRowColor(row, QApplication::palette().color(QPalette::WindowText)); |
|
||||||
} |
|
||||||
if(!downloadList->isColumnHidden(DLSPEED)) { |
|
||||||
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)h.download_payload_rate())); |
|
||||||
} |
|
||||||
if(!downloadList->isColumnHidden(UPSPEED)) { |
|
||||||
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)h.upload_payload_rate())); |
|
||||||
} |
|
||||||
break; |
|
||||||
default: |
|
||||||
if(!downloadList->isColumnHidden(ETA)) { |
|
||||||
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1)); |
|
||||||
} |
|
||||||
} |
|
||||||
if(!downloadList->isColumnHidden(SEEDSLEECH)) { |
|
||||||
QString tmp = misc::toQString(h.num_seeds(), true); |
|
||||||
if(h.num_complete() >= 0) |
|
||||||
tmp.append(QString("(")+misc::toQString(h.num_complete())+QString(")")); |
|
||||||
tmp.append(QString("/")+misc::toQString(h.num_peers() - h.num_seeds(), true)); |
|
||||||
if(h.num_incomplete() >= 0) |
|
||||||
tmp.append(QString("(")+misc::toQString(h.num_incomplete())+QString(")")); |
|
||||||
DLListModel->setData(DLListModel->index(row, SEEDSLEECH), QVariant(tmp)); |
|
||||||
} |
|
||||||
if(!downloadList->isColumnHidden(RATIO)) { |
|
||||||
DLListModel->setData(DLListModel->index(row, RATIO), QVariant(misc::toQString(BTSession->getRealRatio(hash)))); |
|
||||||
} |
|
||||||
}catch(invalid_handle e) {} |
|
||||||
return added; |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::addTorrent(QString hash) { |
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
qDebug("DL: addTorrent(): %s, row: %d", (const char*)hash.toLocal8Bit(), row); |
|
||||||
if(row != -1) return; |
|
||||||
row = DLListModel->rowCount(); |
|
||||||
// Adding torrent to download list
|
|
||||||
DLListModel->insertRow(row); |
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(h.name())); |
|
||||||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)h.actual_size())); |
|
||||||
DLListModel->setData(DLListModel->index(row, DLSPEED), QVariant((double)0.)); |
|
||||||
DLListModel->setData(DLListModel->index(row, UPSPEED), QVariant((double)0.)); |
|
||||||
DLListModel->setData(DLListModel->index(row, SEEDSLEECH), QVariant(QString::fromUtf8("0/0"))); |
|
||||||
DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)h.progress())); |
|
||||||
DLListModel->setData(DLListModel->index(row, RATIO), QVariant((double)0.)); |
|
||||||
DLListModel->setData(DLListModel->index(row, ETA), QVariant((qlonglong)-1)); |
|
||||||
if(BTSession->isQueueingEnabled()) |
|
||||||
DLListModel->setData(DLListModel->index(row, PRIORITY), QVariant((int)BTSession->getDlTorrentPriority(hash))); |
|
||||||
DLListModel->setData(DLListModel->index(row, HASH), QVariant(hash)); |
|
||||||
// Pause torrent if it is
|
|
||||||
if(h.is_paused()) { |
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/paused.png"))), Qt::DecorationRole); |
|
||||||
setRowColor(row, QString::fromUtf8("red")); |
|
||||||
}else{ |
|
||||||
DLListModel->setData(DLListModel->index(row, NAME), QVariant(QIcon(QString::fromUtf8(":/Icons/skin/stalled.png"))), Qt::DecorationRole); |
|
||||||
setRowColor(row, QString::fromUtf8("grey")); |
|
||||||
} |
|
||||||
++nbTorrents; |
|
||||||
emit unfinishedTorrentsNumberChanged(nbTorrents); |
|
||||||
} |
|
||||||
|
|
||||||
// Save columns width in a file to remember them
|
|
||||||
// (download list)
|
|
||||||
void DownloadingTorrents::saveColWidthDLList() const{ |
|
||||||
qDebug("Saving columns width in download list"); |
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); |
|
||||||
QStringList width_list; |
|
||||||
QStringList new_width_list; |
|
||||||
short nbColumns = DLListModel->columnCount()-1; |
|
||||||
QString line = settings.value("DownloadListColsWidth", QString()).toString(); |
|
||||||
if(!line.isEmpty()) { |
|
||||||
width_list = line.split(' '); |
|
||||||
} |
|
||||||
for(short i=0; i<nbColumns; ++i){ |
|
||||||
if(downloadList->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(downloadList->columnWidth(i)>=1) { |
|
||||||
// usual case, save the current width
|
|
||||||
new_width_list << QString::fromUtf8(misc::toString(downloadList->columnWidth(i)).c_str()); |
|
||||||
} else { |
|
||||||
// default width
|
|
||||||
downloadList->resizeColumnToContents(i); |
|
||||||
new_width_list << QString::fromUtf8(misc::toString(downloadList->columnWidth(i)).c_str()); |
|
||||||
} |
|
||||||
} |
|
||||||
settings.setValue(QString::fromUtf8("DownloadListColsWidth"), new_width_list.join(QString::fromUtf8(" "))); |
|
||||||
QVariantList visualIndexes; |
|
||||||
for(int i=0; i<nbColumns; ++i) { |
|
||||||
visualIndexes.append(downloadList->header()->visualIndex(i)); |
|
||||||
} |
|
||||||
settings.setValue(QString::fromUtf8("DownloadListVisualIndexes"), visualIndexes); |
|
||||||
qDebug("Download list columns width saved"); |
|
||||||
} |
|
||||||
|
|
||||||
// Load columns width in a file that were saved previously
|
|
||||||
// (download list)
|
|
||||||
bool DownloadingTorrents::loadColWidthDLList() { |
|
||||||
qDebug("Loading columns width for download list"); |
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); |
|
||||||
QString line = settings.value(QString::fromUtf8("DownloadListColsWidth"), QString()).toString(); |
|
||||||
if(line.isEmpty()) |
|
||||||
return false; |
|
||||||
QStringList width_list = line.split(QString::fromUtf8(" ")); |
|
||||||
if(width_list.size() != DLListModel->columnCount()-1) { |
|
||||||
qDebug("Corrupted values for download list columns sizes"); |
|
||||||
return false; |
|
||||||
} |
|
||||||
unsigned int listSize = width_list.size(); |
|
||||||
for(unsigned int i=0; i<listSize; ++i) { |
|
||||||
downloadList->header()->resizeSection(i, width_list.at(i).toInt()); |
|
||||||
} |
|
||||||
QVariantList visualIndexes = settings.value(QString::fromUtf8("DownloadListVisualIndexes"), QVariantList()).toList(); |
|
||||||
if(visualIndexes.size() != DLListModel->columnCount()-1) { |
|
||||||
qDebug("Corrupted values for download list columns sizes"); |
|
||||||
return false; |
|
||||||
} |
|
||||||
bool change = false; |
|
||||||
do { |
|
||||||
change = false; |
|
||||||
for(int i=0;i<visualIndexes.size(); ++i) { |
|
||||||
int new_visual_index = visualIndexes.at(downloadList->header()->logicalIndex(i)).toInt(); |
|
||||||
if(i != new_visual_index) { |
|
||||||
qDebug("Moving column from %d to %d", downloadList->header()->logicalIndex(i), new_visual_index); |
|
||||||
downloadList->header()->moveSection(i, new_visual_index); |
|
||||||
change = true; |
|
||||||
} |
|
||||||
} |
|
||||||
}while(change); |
|
||||||
qDebug("Download list columns width loaded"); |
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::saveLastSortedColumn() { |
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); |
|
||||||
Qt::SortOrder sortOrder = downloadList->header()->sortIndicatorOrder(); |
|
||||||
QString sortOrderLetter; |
|
||||||
if(sortOrder == Qt::AscendingOrder) |
|
||||||
sortOrderLetter = QString::fromUtf8("a"); |
|
||||||
else |
|
||||||
sortOrderLetter = QString::fromUtf8("d"); |
|
||||||
int index = downloadList->header()->sortIndicatorSection(); |
|
||||||
settings.setValue(QString::fromUtf8("DownloadListSortedCol"), misc::toQString(index)+sortOrderLetter); |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::loadLastSortedColumn() { |
|
||||||
// Loading last sorted column
|
|
||||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); |
|
||||||
QString sortedCol = settings.value(QString::fromUtf8("DownloadListSortedCol"), 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(); |
|
||||||
downloadList->sortByColumn(index, sortOrder); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void DownloadingTorrents::updateFileSizeAndProgress(QString hash) { |
|
||||||
int row = getRowFromHash(hash); |
|
||||||
Q_ASSERT(row != -1); |
|
||||||
QTorrentHandle h = BTSession->getTorrentHandle(hash); |
|
||||||
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)h.actual_size())); |
|
||||||
//DLListModel->setData(DLListModel->index(row, PROGRESS), QVariant((double)h.progress()));
|
|
||||||
} |
|
||||||
|
|
||||||
// Set the color of a row in data model
|
|
||||||
void DownloadingTorrents::setRowColor(int row, QColor color) { |
|
||||||
unsigned int nbColumns = DLListModel->columnCount()-1; |
|
||||||
for(unsigned int i=0; i<nbColumns; ++i) { |
|
||||||
DLListModel->setData(DLListModel->index(row, i), QVariant(color), Qt::ForegroundRole); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// return the row of in data model
|
|
||||||
// corresponding to the given the hash
|
|
||||||
int DownloadingTorrents::getRowFromHash(QString hash) const{ |
|
||||||
unsigned int nbRows = DLListModel->rowCount(); |
|
||||||
for(unsigned int i=0; i<nbRows; ++i) { |
|
||||||
if(DLListModel->data(DLListModel->index(i, HASH)) == hash) { |
|
||||||
return i; |
|
||||||
} |
|
||||||
} |
|
||||||
return -1; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
@ -1,107 +0,0 @@ |
|||||||
/*
|
|
||||||
* 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 |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef DOWNLOADINGTORRENTS_H |
|
||||||
#define DOWNLOADINGTORRENTS_H |
|
||||||
|
|
||||||
#include "ui_download.h" |
|
||||||
#include "qtorrenthandle.h" |
|
||||||
|
|
||||||
class QStandardItemModel; |
|
||||||
class bittorrent; |
|
||||||
class DLListDelegate; |
|
||||||
class QSortFilterProxyModel; |
|
||||||
|
|
||||||
using namespace libtorrent; |
|
||||||
|
|
||||||
class DownloadingTorrents : public QWidget, public Ui::downloading{ |
|
||||||
Q_OBJECT |
|
||||||
private: |
|
||||||
QObject *parent; |
|
||||||
bittorrent *BTSession; |
|
||||||
DLListDelegate *DLDelegate; |
|
||||||
QStandardItemModel *DLListModel; |
|
||||||
QSortFilterProxyModel *proxyModel; |
|
||||||
unsigned int nbTorrents; |
|
||||||
void hideOrShowColumn(int index); |
|
||||||
bool loadHiddenColumns(); |
|
||||||
void saveHiddenColumns(); |
|
||||||
QAction* getActionHoSCol(int index); |
|
||||||
|
|
||||||
public: |
|
||||||
DownloadingTorrents(QObject *parent, bittorrent *BTSession); |
|
||||||
~DownloadingTorrents(); |
|
||||||
// Methods
|
|
||||||
bool loadColWidthDLList(); |
|
||||||
int getRowFromHash(QString hash) const; |
|
||||||
QString getHashFromRow(unsigned int row) const; |
|
||||||
QStringList getSelectedTorrents(bool only_one=false) const; |
|
||||||
unsigned int getNbTorrentsInList() const; |
|
||||||
void enablePriorityColumn(bool enable); |
|
||||||
|
|
||||||
signals: |
|
||||||
void unfinishedTorrentsNumberChanged(unsigned int); |
|
||||||
void torrentDoubleClicked(QString hash, bool finished); |
|
||||||
|
|
||||||
protected slots: |
|
||||||
void on_actionSet_download_limit_triggered(); |
|
||||||
void notifyTorrentDoubleClicked(const QModelIndex& index); |
|
||||||
void on_actionSet_upload_limit_triggered(); |
|
||||||
void displayDLListMenu(const QPoint& pos); |
|
||||||
void displayDLHoSMenu(const QPoint&); |
|
||||||
void saveColWidthDLList() const; |
|
||||||
void setRowColor(int row, QColor color); |
|
||||||
void showProperties(const QModelIndex &index); |
|
||||||
void hideOrShowColumnName(); |
|
||||||
void hideOrShowColumnSize(); |
|
||||||
void hideOrShowColumnProgress(); |
|
||||||
void hideOrShowColumnDownSpeed(); |
|
||||||
void hideOrShowColumnUpSpeed(); |
|
||||||
void hideOrShowColumnSeedersLeechers(); |
|
||||||
void hideOrShowColumnRatio(); |
|
||||||
void hideOrShowColumnEta(); |
|
||||||
void hideOrShowColumnPriority(); |
|
||||||
void forceRecheck(); |
|
||||||
|
|
||||||
public slots: |
|
||||||
bool updateTorrent(QTorrentHandle h); |
|
||||||
void pauseTorrent(QString hash); |
|
||||||
void deleteTorrent(QString hash); |
|
||||||
void propertiesSelection(); |
|
||||||
void updateFileSizeAndProgress(QString hash); |
|
||||||
void showPropertiesFromHash(QString hash); |
|
||||||
void saveLastSortedColumn(); |
|
||||||
void loadLastSortedColumn(); |
|
||||||
void addTorrent(QString hash); |
|
||||||
void updateMetadata(QTorrentHandle &h); |
|
||||||
|
|
||||||
}; |
|
||||||
|
|
||||||
#endif |
|
Loading…
Reference in new issue