2006-10-24 01:42:37 +04:00
|
|
|
/*
|
|
|
|
* Bittorrent Client using Qt4 and libtorrent.
|
2007-07-14 18:31:59 +04:00
|
|
|
* Copyright (C) 2006 Christophe Dumez
|
2006-10-24 01:42:37 +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.
|
2006-10-24 01:42:37 +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
|
2006-10-24 01:42:37 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TORRENTADDITION_H
|
|
|
|
#define TORRENTADDITION_H
|
|
|
|
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFile>
|
|
|
|
#include <fstream>
|
|
|
|
#include <QMessageBox>
|
2006-10-24 02:18:06 +04:00
|
|
|
#include <QMenu>
|
2006-11-15 00:17:51 +03:00
|
|
|
#include <QSettings>
|
2007-04-13 00:22:42 +04:00
|
|
|
#include <QStandardItemModel>
|
2007-04-13 00:28:10 +04:00
|
|
|
#include <QHeaderView>
|
2006-10-24 01:42:37 +04:00
|
|
|
|
|
|
|
#include <libtorrent/session.hpp>
|
|
|
|
#include <libtorrent/bencode.hpp>
|
2008-09-07 15:31:29 +04:00
|
|
|
#include "bittorrent.h"
|
2006-10-24 01:42:37 +04:00
|
|
|
#include "misc.h"
|
2007-04-13 00:22:42 +04:00
|
|
|
#include "PropListDelegate.h"
|
2006-10-24 01:42:37 +04:00
|
|
|
#include "ui_addTorrentDialog.h"
|
2007-09-16 13:19:22 +04:00
|
|
|
#include "arborescence.h"
|
2006-10-24 01:42:37 +04:00
|
|
|
|
|
|
|
using namespace libtorrent;
|
|
|
|
|
|
|
|
class torrentAdditionDialog : public QDialog, private Ui_addTorrentDialog{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
2008-09-07 15:31:29 +04:00
|
|
|
bittorrent *BTSession;
|
2006-10-24 01:42:37 +04:00
|
|
|
QString fileName;
|
2007-08-20 10:29:18 +04:00
|
|
|
QString hash;
|
2006-10-24 01:42:37 +04:00
|
|
|
QString filePath;
|
|
|
|
bool fromScanDir;
|
|
|
|
QString from_url;
|
2007-04-13 00:22:42 +04:00
|
|
|
QStandardItemModel *PropListModel;
|
|
|
|
PropListDelegate *PropDelegate;
|
2007-09-16 13:19:22 +04:00
|
|
|
unsigned int nbFiles;
|
2006-10-24 01:42:37 +04:00
|
|
|
|
|
|
|
public:
|
2008-09-07 15:31:29 +04:00
|
|
|
torrentAdditionDialog(QWidget *parent, bittorrent* _BTSession) : QDialog(parent) {
|
2006-10-24 01:42:37 +04:00
|
|
|
setupUi(this);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2008-09-07 15:31:29 +04:00
|
|
|
BTSession = _BTSession;
|
2007-04-13 00:22:42 +04:00
|
|
|
// Set Properties list model
|
2007-09-16 13:19:22 +04:00
|
|
|
PropListModel = new QStandardItemModel(0,5);
|
2007-04-13 00:22:42 +04:00
|
|
|
PropListModel->setHeaderData(NAME, Qt::Horizontal, tr("File name"));
|
|
|
|
PropListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size"));
|
|
|
|
PropListModel->setHeaderData(PROGRESS, Qt::Horizontal, tr("Progress"));
|
|
|
|
PropListModel->setHeaderData(PRIORITY, Qt::Horizontal, tr("Priority"));
|
|
|
|
torrentContentList->setModel(PropListModel);
|
|
|
|
torrentContentList->hideColumn(PROGRESS);
|
2007-09-16 13:19:22 +04:00
|
|
|
torrentContentList->hideColumn(INDEX);
|
2007-04-13 00:22:42 +04:00
|
|
|
PropDelegate = new PropListDelegate();
|
|
|
|
torrentContentList->setItemDelegate(PropDelegate);
|
|
|
|
connect(torrentContentList, SIGNAL(clicked(const QModelIndex&)), torrentContentList, SLOT(edit(const QModelIndex&)));
|
2007-07-20 17:21:46 +04:00
|
|
|
connect(torrentContentList, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayFilesListMenu(const QPoint&)));
|
|
|
|
connect(actionIgnored, SIGNAL(triggered()), this, SLOT(ignoreSelection()));
|
|
|
|
connect(actionNormal, SIGNAL(triggered()), this, SLOT(normalSelection()));
|
|
|
|
connect(actionHigh, SIGNAL(triggered()), this, SLOT(highSelection()));
|
|
|
|
connect(actionMaximum, SIGNAL(triggered()), this, SLOT(maximumSelection()));
|
2008-09-21 12:13:23 +04:00
|
|
|
connect(collapseAllButton, SIGNAL(clicked()), torrentContentList, SLOT(collapseAll()));
|
|
|
|
connect(expandAllButton, SIGNAL(clicked()), torrentContentList, SLOT(expandAll()));
|
2007-04-13 00:28:10 +04:00
|
|
|
torrentContentList->header()->resizeSection(0, 200);
|
2008-07-27 22:07:35 +04:00
|
|
|
//torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch);
|
2006-10-24 01:42:37 +04:00
|
|
|
QString home = QDir::homePath();
|
|
|
|
if(home[home.length()-1] != QDir::separator()){
|
|
|
|
home += QDir::separator();
|
|
|
|
}
|
2007-08-20 10:29:18 +04:00
|
|
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
|
|
|
savePathTxt->setText(settings.value(QString::fromUtf8("LastDirTorrentAdd"), home+QString::fromUtf8("qBT_dir")).toString());
|
2007-09-08 21:07:29 +04:00
|
|
|
if(settings.value("Preferences/Downloads/StartInPause", false).toBool()) {
|
|
|
|
addInPause->setChecked(true);
|
|
|
|
addInPause->setEnabled(false);
|
|
|
|
}
|
2006-10-29 12:32:28 +03:00
|
|
|
}
|
|
|
|
|
2008-12-23 18:07:29 +03:00
|
|
|
~torrentAdditionDialog() {
|
|
|
|
delete PropDelegate;
|
2008-12-23 18:51:32 +03:00
|
|
|
delete PropListModel;
|
2008-12-23 18:07:29 +03:00
|
|
|
}
|
|
|
|
|
2006-10-29 12:32:28 +03:00
|
|
|
void showLoad(QString filePath, bool fromScanDir=false, QString from_url=QString::null){
|
2008-11-02 00:42:56 +03:00
|
|
|
this->filePath = filePath;
|
|
|
|
this->fromScanDir = fromScanDir;
|
|
|
|
this->from_url = from_url;
|
2006-10-24 01:42:37 +04:00
|
|
|
// Getting torrent file informations
|
2008-11-02 00:42:56 +03:00
|
|
|
boost::intrusive_ptr<torrent_info> t;
|
|
|
|
try {
|
|
|
|
t = new torrent_info(filePath.toUtf8().data());
|
|
|
|
} catch(std::exception&) {
|
|
|
|
if(!from_url.isNull()){
|
|
|
|
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+from_url+QString::fromUtf8("'"), QString::fromUtf8("red"));
|
|
|
|
QFile::remove(filePath);
|
|
|
|
}else{
|
|
|
|
BTSession->addConsoleMessage(tr("Unable to decode torrent file:")+QString::fromUtf8(" '")+filePath+QString::fromUtf8("'"), QString::fromUtf8("red"));
|
|
|
|
}
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
nbFiles = t->num_files();
|
2006-10-24 01:42:37 +04:00
|
|
|
// Setting file name
|
2008-11-02 00:42:56 +03:00
|
|
|
fileName = misc::toQString(t->name());
|
|
|
|
hash = misc::toQString(t->info_hash());
|
2007-03-08 01:36:01 +03:00
|
|
|
// Use left() to remove .old extension
|
|
|
|
QString newFileName;
|
2007-08-20 10:29:18 +04:00
|
|
|
if(fileName.endsWith(QString::fromUtf8(".old"))){
|
2008-11-02 00:42:56 +03:00
|
|
|
newFileName = fileName.left(fileName.size()-4);
|
2007-03-08 01:36:01 +03:00
|
|
|
}else{
|
2008-11-02 00:42:56 +03:00
|
|
|
newFileName = fileName;
|
2007-03-08 01:36:01 +03:00
|
|
|
}
|
2007-08-20 10:29:18 +04:00
|
|
|
fileNameLbl->setText(QString::fromUtf8("<center><b>")+newFileName+QString::fromUtf8("</b></center>"));
|
2006-10-24 01:42:37 +04:00
|
|
|
// List files in torrent
|
2007-09-16 13:19:22 +04:00
|
|
|
arborescence *arb = new arborescence(t);
|
|
|
|
addFilesToTree(arb->getRoot(), PropListModel->invisibleRootItem());
|
|
|
|
delete arb;
|
2007-09-16 17:33:41 +04:00
|
|
|
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
|
2007-09-16 13:19:22 +04:00
|
|
|
torrentContentList->expandAll();
|
2008-11-02 00:42:56 +03:00
|
|
|
show();
|
2006-10-24 01:42:37 +04:00
|
|
|
}
|
|
|
|
|
2008-02-03 13:43:12 +03:00
|
|
|
void addFilesToTree(torrent_file *root, QStandardItem *parent) {
|
2007-09-16 13:19:22 +04:00
|
|
|
QList<QStandardItem*> child;
|
|
|
|
// Name
|
|
|
|
QStandardItem *first;
|
|
|
|
if(root->isDir()) {
|
|
|
|
first = new QStandardItem(QIcon(":/Icons/folder.png"), root->name());
|
|
|
|
} else {
|
|
|
|
first = new QStandardItem(QIcon(":/Icons/file.png"), root->name());
|
|
|
|
}
|
|
|
|
child << first;
|
|
|
|
// Size
|
|
|
|
child << new QStandardItem(misc::toQString(root->getSize()));
|
|
|
|
// Hidden progress
|
|
|
|
child << new QStandardItem("");
|
|
|
|
// Prio
|
|
|
|
child << new QStandardItem(misc::toQString(NORMAL));
|
|
|
|
// INDEX
|
|
|
|
child << new QStandardItem(misc::toQString(root->getIndex()));
|
|
|
|
// TODO: row Color?
|
|
|
|
// Add the child to the tree
|
|
|
|
parent->appendRow(child);
|
2008-12-23 18:51:32 +03:00
|
|
|
// Add children
|
|
|
|
QList<torrent_file*> children = root->getChildren();
|
|
|
|
unsigned int nbChildren = children.size();
|
|
|
|
for(unsigned int i=0; i < nbChildren; ++i) {
|
|
|
|
addFilesToTree(children.at(i), first);
|
2007-09-16 13:19:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-24 01:42:37 +04:00
|
|
|
public slots:
|
2007-09-16 13:19:22 +04:00
|
|
|
|
2007-09-16 17:33:41 +04:00
|
|
|
// priority is the new priority of given item
|
|
|
|
void updateParentsPriority(QStandardItem *item, int priority) {
|
2007-09-16 13:19:22 +04:00
|
|
|
QStandardItem *parent = item->parent();
|
2007-09-16 17:33:41 +04:00
|
|
|
if(!parent) return;
|
|
|
|
// Check if children have different priorities
|
|
|
|
// then folder must have NORMAL priority
|
|
|
|
unsigned int rowCount = parent->rowCount();
|
|
|
|
for(unsigned int i=0; i<rowCount; ++i) {
|
|
|
|
if(parent->child(i, PRIORITY)->text().toInt() != priority) {
|
2007-09-16 13:19:22 +04:00
|
|
|
QStandardItem *grandFather = parent->parent();
|
|
|
|
if(!grandFather) {
|
|
|
|
grandFather = PropListModel->invisibleRootItem();
|
|
|
|
}
|
|
|
|
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
|
2007-09-16 17:33:41 +04:00
|
|
|
if(parentPrio->text().toInt() != NORMAL) {
|
|
|
|
parentPrio->setText(misc::toQString(NORMAL));
|
|
|
|
// Recursively update ancesters of this parent too
|
|
|
|
updateParentsPriority(grandFather->child(parent->row()), priority);
|
|
|
|
}
|
|
|
|
return;
|
2007-09-16 13:19:22 +04:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 17:33:41 +04:00
|
|
|
// All the children have the same priority
|
|
|
|
// Parent folder should have the same priority too
|
|
|
|
QStandardItem *grandFather = parent->parent();
|
|
|
|
if(!grandFather) {
|
|
|
|
grandFather = PropListModel->invisibleRootItem();
|
|
|
|
}
|
|
|
|
QStandardItem *parentPrio = grandFather->child(parent->row(), PRIORITY);
|
|
|
|
if(parentPrio->text().toInt() != priority) {
|
|
|
|
parentPrio->setText(misc::toQString(priority));
|
|
|
|
// Recursively update ancesters of this parent too
|
|
|
|
updateParentsPriority(grandFather->child(parent->row()), priority);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateChildrenPriority(QStandardItem *item, int priority) {
|
|
|
|
QStandardItem *parent = item->parent();
|
|
|
|
if(!parent) {
|
|
|
|
parent = PropListModel->invisibleRootItem();
|
|
|
|
}
|
|
|
|
parent = parent->child(item->row());
|
2007-09-16 13:19:22 +04:00
|
|
|
unsigned int rowCount = parent->rowCount();
|
|
|
|
for(unsigned int i=0; i<rowCount; ++i) {
|
2007-09-16 17:33:41 +04:00
|
|
|
QStandardItem * childPrio = parent->child(i, PRIORITY);
|
|
|
|
if(childPrio->text().toInt() != priority) {
|
|
|
|
childPrio->setText(misc::toQString(priority));
|
|
|
|
// recursively update children of this child too
|
|
|
|
updateChildrenPriority(parent->child(i), priority);
|
2007-09-16 13:19:22 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-16 17:33:41 +04:00
|
|
|
|
|
|
|
void updatePriorities(QStandardItem *item) {
|
|
|
|
qDebug("Priority changed");
|
|
|
|
// First we disable the signal/slot on item edition
|
|
|
|
// temporarily so that it doesn't mess with our manual updates
|
|
|
|
disconnect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
|
|
|
|
QStandardItem *parent = item->parent();
|
|
|
|
if(!parent) {
|
|
|
|
parent = PropListModel->invisibleRootItem();
|
|
|
|
}
|
|
|
|
int priority = parent->child(item->row(), PRIORITY)->text().toInt();
|
|
|
|
// Update parents priorities
|
|
|
|
updateParentsPriority(item, priority);
|
|
|
|
// If this is not a directory, then there are
|
|
|
|
// no children to update
|
|
|
|
if(parent->child(item->row(), INDEX)->text().toInt() == -1) {
|
|
|
|
// Updating children
|
|
|
|
qDebug("Priority changed for a folder to %d", priority);
|
|
|
|
updateChildrenPriority(item, priority);
|
|
|
|
}
|
|
|
|
// Reconnect the signal/slot on item edition so that we
|
|
|
|
// get future updates
|
|
|
|
connect(PropListModel, SIGNAL(itemChanged(QStandardItem*)), this, SLOT(updatePriorities(QStandardItem*)));
|
|
|
|
}
|
2007-09-16 13:19:22 +04:00
|
|
|
|
2006-10-24 01:42:37 +04:00
|
|
|
void on_browseButton_clicked(){
|
2006-10-29 12:46:38 +03:00
|
|
|
QString dir;
|
|
|
|
QDir saveDir(savePathTxt->text());
|
|
|
|
if(saveDir.exists()){
|
|
|
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), savePathTxt->text());
|
|
|
|
}else{
|
|
|
|
dir = QFileDialog::getExistingDirectory(this, tr("Choose save path"), QDir::homePath());
|
|
|
|
}
|
2006-10-24 01:42:37 +04:00
|
|
|
if(!dir.isNull()){
|
|
|
|
savePathTxt->setText(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_CancelButton_clicked(){
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2007-04-13 00:22:42 +04:00
|
|
|
// Set the color of a row in data model
|
|
|
|
void setRowColor(int row, QString color){
|
|
|
|
for(int i=0; i<PropListModel->columnCount(); ++i){
|
2007-07-31 14:39:03 +04:00
|
|
|
PropListModel->setData(PropListModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
|
2006-10-24 01:42:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-04 02:52:58 +04:00
|
|
|
bool allFiltered() const {
|
2007-07-31 19:37:14 +04:00
|
|
|
unsigned int nbRows = PropListModel->rowCount();
|
|
|
|
for(unsigned int i=0; i<nbRows; ++i){
|
2007-09-04 02:52:58 +04:00
|
|
|
if(PropListModel->data(PropListModel->index(i, PRIORITY)).toInt() != IGNORED)
|
|
|
|
return false;
|
2007-07-31 19:37:14 +04:00
|
|
|
}
|
2007-09-04 02:52:58 +04:00
|
|
|
return true;
|
2007-07-31 19:37:14 +04:00
|
|
|
}
|
|
|
|
|
2007-07-20 17:21:46 +04:00
|
|
|
void displayFilesListMenu(const QPoint& pos){
|
2007-09-16 13:19:22 +04:00
|
|
|
if(nbFiles == 1) return;
|
2007-07-20 17:21:46 +04:00
|
|
|
QMenu myFilesLlistMenu(this);
|
|
|
|
QModelIndex index;
|
2007-07-31 19:37:14 +04:00
|
|
|
// Enable/disable pause/start action given the DL state
|
2007-07-20 17:21:46 +04:00
|
|
|
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
|
|
|
myFilesLlistMenu.setTitle(tr("Priority"));
|
2007-09-04 02:52:58 +04:00
|
|
|
myFilesLlistMenu.addAction(actionIgnored);
|
2007-07-20 17:21:46 +04:00
|
|
|
myFilesLlistMenu.addAction(actionNormal);
|
|
|
|
myFilesLlistMenu.addAction(actionHigh);
|
|
|
|
myFilesLlistMenu.addAction(actionMaximum);
|
2007-07-31 19:37:14 +04:00
|
|
|
// Call menu
|
|
|
|
// XXX: why mapToGlobal() is not enough?
|
2007-07-20 17:30:30 +04:00
|
|
|
myFilesLlistMenu.exec(mapToGlobal(pos)+QPoint(10,145));
|
2007-07-20 17:21:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ignoreSelection(){
|
|
|
|
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
|
|
|
QModelIndex index;
|
|
|
|
foreach(index, selectedIndexes){
|
|
|
|
if(index.column() == PRIORITY){
|
|
|
|
PropListModel->setData(index, QVariant(IGNORED));
|
|
|
|
}
|
2007-07-31 17:59:03 +04:00
|
|
|
for(int i=0; i<PropListModel->columnCount(); ++i){
|
2007-08-20 10:29:18 +04:00
|
|
|
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor(QString::fromUtf8("red"))), Qt::ForegroundRole);
|
2007-07-31 17:59:03 +04:00
|
|
|
}
|
2007-07-20 17:21:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void normalSelection(){
|
|
|
|
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
|
|
|
QModelIndex index;
|
|
|
|
foreach(index, selectedIndexes){
|
|
|
|
if(index.column() == PRIORITY){
|
|
|
|
PropListModel->setData(index, QVariant(NORMAL));
|
|
|
|
}
|
2007-07-31 17:59:03 +04:00
|
|
|
for(int i=0; i<PropListModel->columnCount(); ++i){
|
2007-08-20 10:29:18 +04:00
|
|
|
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor(QString::fromUtf8("green"))), Qt::ForegroundRole);
|
2007-07-31 17:59:03 +04:00
|
|
|
}
|
2007-07-20 17:21:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void highSelection(){
|
|
|
|
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
|
|
|
QModelIndex index;
|
|
|
|
foreach(index, selectedIndexes){
|
|
|
|
if(index.column() == PRIORITY){
|
|
|
|
PropListModel->setData(index, QVariant(HIGH));
|
|
|
|
}
|
2007-07-31 17:59:03 +04:00
|
|
|
for(int i=0; i<PropListModel->columnCount(); ++i){
|
|
|
|
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor("green")), Qt::ForegroundRole);
|
|
|
|
}
|
2007-07-20 17:21:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void maximumSelection(){
|
|
|
|
QModelIndexList selectedIndexes = torrentContentList->selectionModel()->selectedIndexes();
|
|
|
|
QModelIndex index;
|
|
|
|
foreach(index, selectedIndexes){
|
|
|
|
if(index.column() == PRIORITY){
|
|
|
|
PropListModel->setData(index, QVariant(MAXIMUM));
|
|
|
|
}
|
2007-07-31 17:59:03 +04:00
|
|
|
for(int i=0; i<PropListModel->columnCount(); ++i){
|
2007-08-20 10:29:18 +04:00
|
|
|
PropListModel->setData(PropListModel->index(index.row(), i), QVariant(QColor(QString::fromUtf8("green"))), Qt::ForegroundRole);
|
2007-07-31 17:59:03 +04:00
|
|
|
}
|
2007-07-20 17:21:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 13:19:22 +04:00
|
|
|
void getPriorities(QStandardItem *parent, int *priorities) {
|
|
|
|
unsigned int nbRows = parent->rowCount();
|
|
|
|
for(unsigned int i=0; i<nbRows; ++i){
|
|
|
|
QStandardItem *item = parent->child(i, INDEX);
|
|
|
|
int index = item->text().toInt();
|
|
|
|
if(index < 0) {
|
2007-09-16 13:41:05 +04:00
|
|
|
qDebug("getPriorities(), found a folder, checking its children");
|
|
|
|
getPriorities(parent->child(i), priorities);
|
2007-09-16 13:19:22 +04:00
|
|
|
} else {
|
|
|
|
item = parent->child(i, PRIORITY);
|
2007-09-16 13:41:05 +04:00
|
|
|
qDebug("getPriorities(), found priority %d for file at index %d", item->text().toInt(), index);
|
2007-09-16 13:19:22 +04:00
|
|
|
priorities[index] = item->text().toInt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-13 00:22:42 +04:00
|
|
|
void savePiecesPriorities(){
|
|
|
|
qDebug("Saving pieces priorities");
|
2007-08-20 10:29:18 +04:00
|
|
|
QFile pieces_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".priorities"));
|
2006-10-24 01:42:37 +04:00
|
|
|
// First, remove old file
|
|
|
|
pieces_file.remove();
|
2007-09-16 13:19:22 +04:00
|
|
|
int *priorities = new int[nbFiles];
|
|
|
|
getPriorities(PropListModel->invisibleRootItem(), priorities);
|
|
|
|
// Ok, we have priorities, save them
|
2006-10-24 01:42:37 +04:00
|
|
|
if(!pieces_file.open(QIODevice::WriteOnly | QIODevice::Text)){
|
2007-04-13 00:22:42 +04:00
|
|
|
std::cerr << "Error: Could not save pieces priorities\n";
|
2006-10-24 01:42:37 +04:00
|
|
|
return;
|
|
|
|
}
|
2007-09-16 13:19:22 +04:00
|
|
|
for(unsigned int i=0; i<nbFiles; ++i) {
|
2007-09-16 13:41:05 +04:00
|
|
|
qDebug("%d ", priorities[i]);
|
2007-09-16 13:19:22 +04:00
|
|
|
pieces_file.write(misc::toQByteArray(priorities[i])+misc::toQByteArray("\n"));
|
2006-10-24 01:42:37 +04:00
|
|
|
}
|
|
|
|
pieces_file.close();
|
2007-09-16 13:19:22 +04:00
|
|
|
delete[] priorities;
|
2006-10-24 01:42:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_OkButton_clicked(){
|
|
|
|
QDir savePath(savePathTxt->text());
|
|
|
|
if(savePathTxt->text().trimmed().isEmpty()){
|
|
|
|
QMessageBox::critical(0, tr("Empty save path"), tr("Please enter a save path"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Check if savePath exists
|
|
|
|
if(!savePath.exists()){
|
|
|
|
if(!savePath.mkpath(savePath.path())){
|
|
|
|
QMessageBox::critical(0, tr("Save path creation error"), tr("Could not create the save path"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Save savepath
|
2007-08-20 10:29:18 +04:00
|
|
|
QFile savepath_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".savepath"));
|
2006-10-24 01:42:37 +04:00
|
|
|
savepath_file.open(QIODevice::WriteOnly | QIODevice::Text);
|
2006-10-26 00:35:41 +04:00
|
|
|
savepath_file.write(savePath.path().toUtf8());
|
2006-10-24 01:42:37 +04:00
|
|
|
savepath_file.close();
|
2006-10-29 12:46:38 +03:00
|
|
|
// Save last dir to remember it
|
2007-08-20 10:29:18 +04:00
|
|
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
|
|
|
|
settings.setValue(QString::fromUtf8("LastDirTorrentAdd"), savePathTxt->text());
|
2006-10-24 01:42:37 +04:00
|
|
|
// Create .incremental file if necessary
|
|
|
|
if(checkIncrementalDL->isChecked()){
|
2007-08-20 10:29:18 +04:00
|
|
|
QFile incremental_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".incremental"));
|
2006-10-24 01:42:37 +04:00
|
|
|
incremental_file.open(QIODevice::WriteOnly | QIODevice::Text);
|
|
|
|
incremental_file.close();
|
|
|
|
}else{
|
2007-08-20 10:29:18 +04:00
|
|
|
QFile::remove(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".incremental"));
|
2006-10-24 01:42:37 +04:00
|
|
|
}
|
|
|
|
// Create .paused file if necessary
|
|
|
|
if(addInPause->isChecked()){
|
2007-08-20 10:29:18 +04:00
|
|
|
QFile paused_file(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".paused"));
|
2006-10-24 01:42:37 +04:00
|
|
|
paused_file.open(QIODevice::WriteOnly | QIODevice::Text);
|
|
|
|
paused_file.close();
|
|
|
|
}else{
|
2007-08-20 10:29:18 +04:00
|
|
|
QFile::remove(misc::qBittorrentPath()+QString::fromUtf8("BT_backup")+QDir::separator()+hash+QString::fromUtf8(".paused"));
|
2006-10-24 01:42:37 +04:00
|
|
|
}
|
|
|
|
// Check if there is at least one selected file
|
2007-09-04 02:52:58 +04:00
|
|
|
if(allFiltered()){
|
|
|
|
QMessageBox::warning(0, tr("Invalid file selection"), tr("You must select at least one file in the torrent"));
|
2006-10-24 01:42:37 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// save filtered files
|
2007-04-13 00:22:42 +04:00
|
|
|
savePiecesPriorities();
|
2006-10-24 01:42:37 +04:00
|
|
|
// Add to download list
|
2008-09-07 15:31:29 +04:00
|
|
|
BTSession->addTorrent(filePath, fromScanDir, from_url);
|
2006-10-24 01:42:37 +04:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|