2007-04-04 16:01:32 +04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
2007-07-14 18:31:59 +04:00
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
2007-04-04 16:01:32 +04:00
|
|
|
*
|
2007-07-14 18:31:59 +04:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-04-04 16:01:32 +04:00
|
|
|
*
|
|
|
|
* 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
|
2007-07-14 18:31:59 +04:00
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contact : chris@qbittorrent.org
|
2007-04-04 16:01:32 +04:00
|
|
|
*/
|
|
|
|
#include "FinishedTorrents.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "GUI.h"
|
2007-04-04 16:52:50 +04:00
|
|
|
#include "properties_imp.h"
|
2007-07-23 16:12:55 +04:00
|
|
|
#include "bittorrent.h"
|
2007-04-10 14:50:34 +04:00
|
|
|
#include "allocationDlg.h"
|
2007-07-23 16:12:55 +04:00
|
|
|
|
2007-04-04 16:01:32 +04:00
|
|
|
#include <QFile>
|
2007-04-04 17:12:11 +04:00
|
|
|
#include <QSettings>
|
2007-07-23 16:12:55 +04:00
|
|
|
#include <QStandardItemModel>
|
2007-07-23 16:46:36 +04:00
|
|
|
#include <QHeaderView>
|
2007-04-04 16:01:32 +04:00
|
|
|
|
|
|
|
FinishedTorrents::FinishedTorrents(QObject *parent, bittorrent *BTSession){
|
|
|
|
setupUi(this);
|
|
|
|
nbFinished = 0;
|
|
|
|
this->parent = parent;
|
|
|
|
this->BTSession = BTSession;
|
2007-07-23 11:44:58 +04:00
|
|
|
finishedListModel = new QStandardItemModel(0,7);
|
|
|
|
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_PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded"));
|
|
|
|
finishedListModel->setHeaderData(F_UPSPEED, Qt::Horizontal, tr("UP Speed", "i.e: Upload speed"));
|
|
|
|
finishedListModel->setHeaderData(F_SEEDSLEECH, Qt::Horizontal, tr("Seeds/Leechs", "i.e: full/partial sources"));
|
|
|
|
finishedListModel->setHeaderData(F_RATIO, Qt::Horizontal, tr("Ratio"));
|
2007-04-04 16:01:32 +04:00
|
|
|
finishedList->setModel(finishedListModel);
|
2007-04-11 22:31:21 +04:00
|
|
|
// Hide ETA & hash column
|
2007-07-23 11:44:58 +04:00
|
|
|
finishedList->hideColumn(F_HASH);
|
2007-04-11 17:10:13 +04:00
|
|
|
// Load last columns width for download list
|
|
|
|
if(!loadColWidthFinishedList()){
|
|
|
|
finishedList->header()->resizeSection(0, 200);
|
|
|
|
}
|
2007-04-11 17:19:58 +04:00
|
|
|
// Make download list header clickable for sorting
|
|
|
|
finishedList->header()->setClickable(true);
|
|
|
|
finishedList->header()->setSortIndicatorShown(true);
|
|
|
|
connect(finishedList->header(), SIGNAL(sectionPressed(int)), this, SLOT(sortFinishedList(int)));
|
2007-07-23 11:44:58 +04:00
|
|
|
finishedListDelegate = new FinishedListDelegate(finishedList);
|
2007-04-04 16:01:32 +04:00
|
|
|
finishedList->setItemDelegate(finishedListDelegate);
|
2007-04-04 17:12:11 +04:00
|
|
|
connect(finishedList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFinishedListMenu(const QPoint&)));
|
2007-08-01 12:43:00 +04:00
|
|
|
connect(finishedList, SIGNAL(doubleClicked(const QModelIndex&)), parent, SLOT(togglePausedState(const QModelIndex&)));
|
2007-04-04 17:12:11 +04:00
|
|
|
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")));
|
2007-04-10 14:50:34 +04:00
|
|
|
actionSet_upload_limit->setIcon(QIcon(QString::fromUtf8(":/Icons/skin/seeding.png")));
|
2007-04-13 01:10:44 +04:00
|
|
|
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()));
|
2007-04-04 18:29:59 +04:00
|
|
|
connect(actionTorrent_Properties, SIGNAL(triggered()), this, SLOT(propertiesSelection()));
|
2007-04-04 16:01:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
FinishedTorrents::~FinishedTorrents(){
|
2007-04-11 17:10:13 +04:00
|
|
|
saveColWidthFinishedList();
|
2007-04-04 16:01:32 +04:00
|
|
|
delete finishedListDelegate;
|
|
|
|
delete finishedListModel;
|
|
|
|
}
|
|
|
|
|
2007-08-19 18:20:54 +04:00
|
|
|
void FinishedTorrents::addFinishedTorrent(QString hash){
|
|
|
|
int row = finishedListModel->rowCount();
|
|
|
|
torrent_handle h = BTSession->getTorrentHandle(hash);
|
|
|
|
// Adding torrent to download list
|
|
|
|
finishedListModel->insertRow(row);
|
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_NAME), QVariant(h.name().c_str()));
|
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_SIZE), QVariant((qlonglong)h.get_torrent_info().total_size()));
|
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_UPSPEED), QVariant((double)0.));
|
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_SEEDSLEECH), QVariant("0/0"));
|
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_RATIO), QVariant(QString(misc::toString(BTSession->getRealRatio(hash)).c_str())));
|
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_HASH), QVariant(hash));
|
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_PROGRESS), QVariant((double)1.));
|
|
|
|
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");
|
2007-04-04 16:01:32 +04:00
|
|
|
}
|
2007-08-19 18:20:54 +04:00
|
|
|
// Create .finished file
|
|
|
|
QFile finished_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished");
|
|
|
|
finished_file.open(QIODevice::WriteOnly | QIODevice::Text);
|
|
|
|
finished_file.close();
|
|
|
|
// Update the number of finished torrents
|
|
|
|
++nbFinished;
|
|
|
|
((GUI*)parent)->setTabText(1, tr("Finished") +" ("+QString(misc::toString(nbFinished).c_str())+")");
|
2007-04-04 16:01:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the color of a row in data model
|
2007-07-22 13:47:27 +04:00
|
|
|
void FinishedTorrents::setRowColor(int row, QString color){
|
2007-04-04 16:01:32 +04:00
|
|
|
for(int i=0; i<finishedListModel->columnCount(); ++i){
|
2007-07-31 14:39:03 +04:00
|
|
|
finishedListModel->setData(finishedListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
|
2007-04-04 16:01:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-11 17:10:13 +04:00
|
|
|
// 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(' ');
|
2007-08-02 18:12:22 +04:00
|
|
|
if(width_list.size() != finishedListModel->columnCount()-1)
|
2007-04-11 17:10:13 +04:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
qDebug("Finished list columns width loaded");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
2007-08-02 18:12:22 +04:00
|
|
|
unsigned int nbColumns = finishedListModel->columnCount()-1;
|
2007-04-11 17:10:13 +04:00
|
|
|
for(unsigned int i=0; i<nbColumns; ++i){
|
|
|
|
width_list << QString(misc::toString(finishedList->columnWidth(i)).c_str());
|
|
|
|
}
|
|
|
|
settings.setValue("FinishedListColsWidth", width_list.join(" "));
|
|
|
|
qDebug("Finished list columns width saved");
|
|
|
|
}
|
|
|
|
|
2007-04-10 14:11:36 +04:00
|
|
|
void FinishedTorrents::on_actionSet_upload_limit_triggered(){
|
2007-04-10 14:50:34 +04:00
|
|
|
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
2007-04-10 14:11:36 +04:00
|
|
|
QModelIndex index;
|
|
|
|
QStringList hashes;
|
|
|
|
foreach(index, selectedIndexes){
|
2007-07-23 11:44:58 +04:00
|
|
|
if(index.column() == F_NAME){
|
2007-04-10 14:11:36 +04:00
|
|
|
// Get the file hash
|
2007-07-23 11:44:58 +04:00
|
|
|
hashes << finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString();
|
2007-04-10 14:11:36 +04:00
|
|
|
}
|
|
|
|
}
|
2007-04-10 14:50:34 +04:00
|
|
|
new BandwidthAllocationDialog(this, true, BTSession, hashes);
|
2007-04-10 14:11:36 +04:00
|
|
|
}
|
|
|
|
|
2007-04-04 16:01:32 +04:00
|
|
|
void FinishedTorrents::updateFinishedList(){
|
2007-07-29 19:20:05 +04:00
|
|
|
Q_ASSERT(((GUI*)parent)->getCurrentTabIndex() == 1);
|
2007-04-04 16:01:32 +04:00
|
|
|
QString hash;
|
2007-08-19 18:20:54 +04:00
|
|
|
QStringList finishedSHAs = BTSession->getFinishedTorrents();
|
2007-04-04 16:01:32 +04:00
|
|
|
foreach(hash, finishedSHAs){
|
|
|
|
torrent_handle h = BTSession->getTorrentHandle(hash);
|
|
|
|
if(!h.is_valid()){
|
|
|
|
qDebug("Problem: This torrent is not valid in finished list");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
torrent_status torrentStatus = h.status();
|
2007-08-01 12:43:00 +04:00
|
|
|
int row = getRowFromHash(hash);
|
|
|
|
if(row == -1){
|
2007-08-19 18:20:54 +04:00
|
|
|
qDebug("Cannot find torrent in finished list, adding it");
|
|
|
|
addFinishedTorrent(hash);
|
2007-08-01 12:43:00 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(h.is_paused()) continue;
|
2007-08-19 20:33:37 +04:00
|
|
|
Q_ASSERT(torrentStatus.progress <= 1. && torrentStatus.progress >= 0.);
|
2007-08-19 18:48:16 +04:00
|
|
|
if(torrentStatus.state == torrent_status::downloading || (torrentStatus.state != torrent_status::checking_files && torrentStatus.state != torrent_status::queued_for_checking && torrentStatus.progress < 1.)) {
|
2007-07-23 12:32:06 +04:00
|
|
|
// What are you doing here? go back to download tab!
|
2007-04-04 16:01:32 +04:00
|
|
|
qDebug("Info: a torrent was moved from finished to download tab");
|
|
|
|
deleteFromFinishedList(hash);
|
2007-08-19 18:20:54 +04:00
|
|
|
BTSession->setFinishedTorrent(hash);
|
2007-04-15 22:15:22 +04:00
|
|
|
emit torrentMovedFromFinishedList(h);
|
2007-04-04 16:01:32 +04:00
|
|
|
continue;
|
|
|
|
}
|
2007-07-23 11:44:58 +04:00
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_UPSPEED), QVariant((double)torrentStatus.upload_payload_rate));
|
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_SEEDSLEECH), QVariant(QString(misc::toString(torrentStatus.num_seeds, true).c_str())+"/"+QString(misc::toString(torrentStatus.num_peers - torrentStatus.num_seeds, true).c_str())));
|
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_RATIO), QVariant(QString(misc::toString(BTSession->getRealRatio(hash)).c_str())));
|
2007-04-04 16:01:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-22 13:47:27 +04:00
|
|
|
int FinishedTorrents::getRowFromHash(QString hash) const{
|
2007-04-15 22:15:22 +04:00
|
|
|
unsigned int nbRows = finishedListModel->rowCount();
|
|
|
|
for(unsigned int i=0; i<nbRows; ++i){
|
2007-07-23 11:44:58 +04:00
|
|
|
if(finishedListModel->data(finishedListModel->index(i, F_HASH)) == hash){
|
2007-04-15 22:15:22 +04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-04-04 16:01:32 +04:00
|
|
|
// Will move it to download tab
|
|
|
|
void FinishedTorrents::deleteFromFinishedList(QString hash){
|
2007-06-17 16:15:04 +04:00
|
|
|
int row = getRowFromHash(hash);
|
2007-08-19 18:20:54 +04:00
|
|
|
Q_ASSERT(row != -1);
|
2007-06-17 16:15:04 +04:00
|
|
|
finishedListModel->removeRow(row);
|
2007-04-04 16:01:32 +04:00
|
|
|
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished");
|
|
|
|
--nbFinished;
|
|
|
|
((GUI*)parent)->setTabText(1, tr("Finished") +" ("+QString(misc::toString(nbFinished).c_str())+")");
|
2007-08-19 18:20:54 +04:00
|
|
|
BTSession->setUnfinishedTorrent(hash);
|
2007-04-04 16:01:32 +04:00
|
|
|
}
|
2007-04-04 16:33:53 +04:00
|
|
|
|
|
|
|
QTreeView* FinishedTorrents::getFinishedList(){
|
|
|
|
return finishedList;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStandardItemModel* FinishedTorrents::getFinishedListModel(){
|
|
|
|
return finishedListModel;
|
|
|
|
}
|
2007-04-04 16:52:50 +04:00
|
|
|
|
|
|
|
// Show torrent properties dialog
|
|
|
|
void FinishedTorrents::showProperties(const QModelIndex &index){
|
|
|
|
int row = index.row();
|
2007-07-23 11:44:58 +04:00
|
|
|
QString fileHash = finishedListModel->data(finishedListModel->index(row, F_HASH)).toString();
|
2007-04-04 16:52:50 +04:00
|
|
|
torrent_handle h = BTSession->getTorrentHandle(fileHash);
|
2007-07-27 17:58:12 +04:00
|
|
|
properties *prop = new properties(this, BTSession, h);
|
2007-07-23 11:44:58 +04:00
|
|
|
connect(prop, SIGNAL(mustHaveFullAllocationMode(torrent_handle)), BTSession, SLOT(reloadTorrent(torrent_handle)));
|
|
|
|
connect(prop, SIGNAL(filteredFilesChanged(QString)), this, SLOT(updateFileSize(QString)));
|
2007-04-04 16:52:50 +04:00
|
|
|
prop->show();
|
|
|
|
}
|
|
|
|
|
2007-07-23 11:44:58 +04:00
|
|
|
void FinishedTorrents::updateFileSize(QString hash){
|
|
|
|
int row = getRowFromHash(hash);
|
|
|
|
finishedListModel->setData(finishedListModel->index(row, F_SIZE), QVariant((qlonglong)BTSession->torrentEffectiveSize(hash)));
|
|
|
|
}
|
|
|
|
|
2007-04-04 16:52:50 +04:00
|
|
|
// display properties of selected items
|
|
|
|
void FinishedTorrents::propertiesSelection(){
|
|
|
|
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
|
|
|
QModelIndex index;
|
|
|
|
foreach(index, selectedIndexes){
|
2007-07-23 11:44:58 +04:00
|
|
|
if(index.column() == F_NAME){
|
2007-04-04 16:52:50 +04:00
|
|
|
showProperties(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-04 17:12:11 +04:00
|
|
|
|
|
|
|
void FinishedTorrents::displayFinishedListMenu(const QPoint& pos){
|
|
|
|
QMenu myFinishedListMenu(this);
|
|
|
|
QModelIndex index;
|
|
|
|
// Enable/disable pause/start action given the DL state
|
|
|
|
QModelIndexList selectedIndexes = finishedList->selectionModel()->selectedIndexes();
|
|
|
|
QSettings settings("qBittorrent", "qBittorrent");
|
|
|
|
QString previewProgram = settings.value("Options/Misc/PreviewProgram", QString()).toString();
|
|
|
|
foreach(index, selectedIndexes){
|
2007-07-23 11:44:58 +04:00
|
|
|
if(index.column() == F_NAME){
|
2007-04-04 17:12:11 +04:00
|
|
|
// Get the file name
|
2007-07-23 11:44:58 +04:00
|
|
|
QString fileHash = finishedListModel->data(finishedListModel->index(index.row(), F_HASH)).toString();
|
2007-04-04 17:12:11 +04:00
|
|
|
torrent_handle h = BTSession->getTorrentHandle(fileHash);
|
|
|
|
myFinishedListMenu.addAction(actionDelete);
|
|
|
|
myFinishedListMenu.addAction(actionDelete_Permanently);
|
2007-04-10 14:11:36 +04:00
|
|
|
myFinishedListMenu.addAction(actionSet_upload_limit);
|
2007-04-04 17:12:11 +04:00
|
|
|
myFinishedListMenu.addAction(actionTorrent_Properties);
|
|
|
|
if(!previewProgram.isEmpty() && BTSession->isFilePreviewPossible(fileHash) && selectedIndexes.size()<=finishedListModel->columnCount()){
|
|
|
|
myFinishedListMenu.addAction(actionPreview_file);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Call menu
|
|
|
|
// XXX: why mapToGlobal() is not enough?
|
|
|
|
myFinishedListMenu.exec(mapToGlobal(pos)+QPoint(10,55));
|
|
|
|
}
|
2007-07-23 16:12:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sorting functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
void FinishedTorrents::sortFinishedList(int index){
|
|
|
|
static Qt::SortOrder sortOrder = Qt::AscendingOrder;
|
|
|
|
if(finishedList->header()->sortIndicatorSection() == index){
|
|
|
|
if(sortOrder == Qt::AscendingOrder){
|
|
|
|
sortOrder = Qt::DescendingOrder;
|
|
|
|
}else{
|
|
|
|
sortOrder = Qt::AscendingOrder;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finishedList->header()->setSortIndicator(index, sortOrder);
|
|
|
|
switch(index){
|
|
|
|
case F_SIZE:
|
|
|
|
case F_UPSPEED:
|
|
|
|
case F_PROGRESS:
|
|
|
|
sortFinishedListFloat(index, sortOrder);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sortFinishedListString(index, sortOrder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FinishedTorrents::sortFinishedListFloat(int index, Qt::SortOrder sortOrder){
|
|
|
|
QList<QPair<int, double> > lines;
|
|
|
|
// insertion sorting
|
|
|
|
unsigned int nbRows = finishedListModel->rowCount();
|
|
|
|
for(unsigned int i=0; i<nbRows; ++i){
|
|
|
|
misc::insertSort(lines, QPair<int,double>(i, finishedListModel->data(finishedListModel->index(i, index)).toDouble()), sortOrder);
|
|
|
|
}
|
|
|
|
// Insert items in new model, in correct order
|
|
|
|
unsigned int nbRows_old = lines.size();
|
|
|
|
for(unsigned int row=0; row<nbRows_old; ++row){
|
|
|
|
finishedListModel->insertRow(finishedListModel->rowCount());
|
|
|
|
unsigned int sourceRow = lines[row].first;
|
|
|
|
unsigned int nbColumns = finishedListModel->columnCount();
|
|
|
|
for(unsigned int col=0; col<nbColumns; ++col){
|
|
|
|
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col)));
|
|
|
|
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::DecorationRole), Qt::DecorationRole);
|
2007-07-31 14:39:03 +04:00
|
|
|
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::ForegroundRole), Qt::ForegroundRole);
|
2007-07-23 16:12:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Remove old rows
|
|
|
|
finishedListModel->removeRows(0, nbRows_old);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FinishedTorrents::sortFinishedListString(int index, Qt::SortOrder sortOrder){
|
|
|
|
QList<QPair<int, QString> > lines;
|
|
|
|
// Insertion sorting
|
|
|
|
unsigned int nbRows = finishedListModel->rowCount();
|
|
|
|
for(unsigned int i=0; i<nbRows; ++i){
|
|
|
|
misc::insertSortString(lines, QPair<int, QString>(i, finishedListModel->data(finishedListModel->index(i, index)).toString()), sortOrder);
|
|
|
|
}
|
|
|
|
// Insert items in new model, in correct order
|
|
|
|
unsigned int nbRows_old = lines.size();
|
|
|
|
for(unsigned int row=0; row<nbRows_old; ++row){
|
|
|
|
finishedListModel->insertRow(finishedListModel->rowCount());
|
|
|
|
unsigned int sourceRow = lines[row].first;
|
|
|
|
unsigned int nbColumns = finishedListModel->columnCount();
|
|
|
|
for(unsigned int col=0; col<nbColumns; ++col){
|
|
|
|
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col)));
|
|
|
|
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::DecorationRole), Qt::DecorationRole);
|
2007-07-31 14:39:03 +04:00
|
|
|
finishedListModel->setData(finishedListModel->index(nbRows_old+row, col), finishedListModel->data(finishedListModel->index(sourceRow, col), Qt::ForegroundRole), Qt::ForegroundRole);
|
2007-07-23 16:12:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Remove old rows
|
|
|
|
finishedListModel->removeRows(0, nbRows_old);
|
|
|
|
}
|