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 .
*
2009-04-05 21:00:55 +04:00
* 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 .
*
2007-07-14 18:31:59 +04:00
* 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"
2009-08-16 07:09:20 +04:00
# include "torrentPersistentData.h"
2006-10-24 01:42:37 +04:00
using namespace libtorrent ;
class torrentAdditionDialog : public QDialog , private Ui_addTorrentDialog {
Q_OBJECT
2009-08-17 17:17:52 +04:00
private :
bittorrent * BTSession ;
QString fileName ;
QString hash ;
QString filePath ;
QString from_url ;
QStandardItemModel * PropListModel ;
PropListDelegate * PropDelegate ;
unsigned int nbFiles ;
boost : : intrusive_ptr < torrent_info > t ;
2006-10-24 01:42:37 +04:00
2009-08-17 17:17:52 +04:00
public :
torrentAdditionDialog ( QWidget * parent , bittorrent * _BTSession ) : QDialog ( parent ) {
setupUi ( this ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
BTSession = _BTSession ;
// Set Properties list model
PropListModel = new QStandardItemModel ( 0 , 5 ) ;
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 ) ;
torrentContentList - > hideColumn ( INDEX ) ;
PropDelegate = new PropListDelegate ( ) ;
torrentContentList - > setItemDelegate ( PropDelegate ) ;
connect ( torrentContentList , SIGNAL ( clicked ( const QModelIndex & ) ) , torrentContentList , SLOT ( edit ( const QModelIndex & ) ) ) ;
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 ( ) ) ) ;
connect ( collapseAllButton , SIGNAL ( clicked ( ) ) , torrentContentList , SLOT ( collapseAll ( ) ) ) ;
connect ( expandAllButton , SIGNAL ( clicked ( ) ) , torrentContentList , SLOT ( expandAll ( ) ) ) ;
2009-09-07 15:48:31 +04:00
2009-08-17 17:17:52 +04:00
torrentContentList - > header ( ) - > resizeSection ( 0 , 200 ) ;
//torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch);
QString home = QDir : : homePath ( ) ;
if ( home [ home . length ( ) - 1 ] ! = QDir : : separator ( ) ) {
home + = QDir : : separator ( ) ;
2006-10-29 12:32:28 +03:00
}
2009-08-17 17:17:52 +04:00
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
savePathTxt - > setText ( settings . value ( QString : : fromUtf8 ( " LastDirTorrentAdd " ) , home + QString : : fromUtf8 ( " qBT_dir " ) ) . toString ( ) ) ;
if ( settings . value ( " Preferences/Downloads/StartInPause " , false ) . toBool ( ) ) {
addInPause - > setChecked ( true ) ;
addInPause - > setEnabled ( false ) ;
2008-12-23 18:07:29 +03:00
}
2009-08-17 17:17:52 +04:00
}
2008-12-23 18:07:29 +03:00
2009-08-17 17:17:52 +04:00
~ torrentAdditionDialog ( ) {
delete PropDelegate ;
delete PropListModel ;
}
2006-10-24 01:42:37 +04:00
2009-08-17 17:17:52 +04:00
void showLoad ( QString filePath , QString from_url = QString : : null ) {
if ( ! QFile : : exists ( filePath ) ) {
close ( ) ;
return ;
}
this - > filePath = filePath ;
this - > from_url = from_url ;
// Getting torrent file informations
try {
t = new torrent_info ( filePath . toLocal8Bit ( ) . data ( ) ) ;
} catch ( std : : exception & ) {
qDebug ( " Caught error loading torrent " ) ;
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 " ) ) ;
2007-09-16 13:19:22 +04:00
}
2009-08-17 17:17:52 +04:00
close ( ) ;
return ;
2007-09-16 13:19:22 +04:00
}
2009-08-17 17:17:52 +04:00
nbFiles = t - > num_files ( ) ;
// Setting file name
fileName = misc : : toQString ( t - > name ( ) ) ;
hash = misc : : toQString ( t - > info_hash ( ) ) ;
// Use left() to remove .old extension
QString newFileName ;
if ( fileName . endsWith ( QString : : fromUtf8 ( " .old " ) ) ) {
newFileName = fileName . left ( fileName . size ( ) - 4 ) ;
} else {
newFileName = fileName ;
}
fileNameLbl - > setText ( QString : : fromUtf8 ( " <center><b> " ) + newFileName + QString : : fromUtf8 ( " </b></center> " ) ) ;
// List files in torrent
arborescence * arb = new arborescence ( t ) ;
addFilesToTree ( arb - > getRoot ( ) , PropListModel - > invisibleRootItem ( ) ) ;
delete arb ;
connect ( PropListModel , SIGNAL ( itemChanged ( QStandardItem * ) ) , this , SLOT ( updatePriorities ( QStandardItem * ) ) ) ;
//torrentContentList->expandAll();
2009-09-07 15:48:31 +04:00
connect ( savePathTxt , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( updateDiskSpaceLabels ( ) ) ) ;
2009-08-17 17:17:52 +04:00
updateDiskSpaceLabels ( ) ;
show ( ) ;
}
2007-09-16 13:19:22 +04:00
2009-08-17 17:17:52 +04:00
void addFilesToTree ( const torrent_file * root , QStandardItem * parent ) {
QList < QStandardItem * > child ;
// Name
QStandardItem * first ;
if ( root - > isDir ( ) ) {
first = new QStandardItem ( QIcon ( " :/Icons/oxygen/folder.png " ) , root - > name ( ) ) ;
} else {
first = new QStandardItem ( QIcon ( " :/Icons/oxygen/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 ( ) ) ) ;
2009-08-29 13:42:20 +04:00
2009-08-17 17:17:52 +04:00
// Add the child to the tree
parent - > appendRow ( child ) ;
2009-08-29 13:42:20 +04:00
// set row Color
setItemColor ( first - > index ( ) , " green " ) ;
2009-08-17 17:17:52 +04:00
// Add children
QList < const torrent_file * > children = root - > getChildren ( ) ;
foreach ( const torrent_file * child , children ) {
addFilesToTree ( child , first ) ;
2007-09-16 17:33:41 +04:00
}
2009-08-17 17:17:52 +04:00
}
2007-09-16 17:33:41 +04:00
2009-08-17 17:17:52 +04:00
public slots :
// priority is the new priority of given item
void updateParentsPriority ( QStandardItem * item , int priority ) {
QStandardItem * parent = item - > parent ( ) ;
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 ) {
QStandardItem * grandFather = parent - > parent ( ) ;
if ( ! grandFather ) {
grandFather = PropListModel - > invisibleRootItem ( ) ;
2007-09-16 13:19:22 +04:00
}
2009-08-17 17:17:52 +04:00
QStandardItem * parentPrio = grandFather - > child ( parent - > row ( ) , PRIORITY ) ;
if ( parentPrio - > text ( ) . toInt ( ) ! = NORMAL ) {
parentPrio - > setText ( misc : : toQString ( NORMAL ) ) ;
2009-08-29 13:42:20 +04:00
setItemColor ( parentPrio - > index ( ) , " green " ) ;
2009-08-17 17:17:52 +04:00
// Recursively update ancesters of this parent too
updateParentsPriority ( grandFather - > child ( parent - > row ( ) ) , priority ) ;
}
return ;
2007-09-16 13:19:22 +04:00
}
}
2009-08-17 17:17:52 +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 ) ) ;
2009-08-29 13:42:20 +04:00
if ( priority = = IGNORED )
setItemColor ( parentPrio - > index ( ) , " red " ) ;
else
setItemColor ( parentPrio - > index ( ) , " green " ) ;
2009-08-17 17:17:52 +04:00
// Recursively update ancesters of this parent too
updateParentsPriority ( grandFather - > child ( parent - > row ( ) ) , priority ) ;
}
}
2007-09-16 17:33:41 +04:00
2009-08-17 17:17:52 +04:00
void updateChildrenPriority ( QStandardItem * item , int priority ) {
QStandardItem * parent = item - > parent ( ) ;
if ( ! parent ) {
parent = PropListModel - > invisibleRootItem ( ) ;
2007-09-16 17:33:41 +04:00
}
2009-08-17 17:17:52 +04:00
parent = parent - > child ( item - > row ( ) ) ;
unsigned int rowCount = parent - > rowCount ( ) ;
for ( unsigned int i = 0 ; i < rowCount ; + + i ) {
QStandardItem * childPrio = parent - > child ( i , PRIORITY ) ;
if ( childPrio - > text ( ) . toInt ( ) ! = priority ) {
childPrio - > setText ( misc : : toQString ( priority ) ) ;
2009-08-29 13:42:20 +04:00
if ( priority = = IGNORED )
setItemColor ( childPrio - > index ( ) , " red " ) ;
else
setItemColor ( childPrio - > index ( ) , " green " ) ;
2009-08-17 17:17:52 +04:00
// recursively update children of this child too
updateChildrenPriority ( parent - > child ( i ) , priority ) ;
2006-10-24 01:42:37 +04:00
}
}
2009-08-17 17:17:52 +04:00
}
2006-10-24 01:42:37 +04:00
2009-08-17 17:17:52 +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 ( ) ;
2009-08-29 13:42:20 +04:00
if ( priority = = IGNORED )
setItemColor ( item - > index ( ) , " red " ) ;
else
setItemColor ( item - > index ( ) , " green " ) ;
2009-08-17 17:17:52 +04:00
// 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 ) ;
2006-10-24 01:42:37 +04:00
}
2009-08-17 17:17:52 +04:00
// Reconnect the signal/slot on item edition so that we
// get future updates
connect ( PropListModel , SIGNAL ( itemChanged ( QStandardItem * ) ) , this , SLOT ( updatePriorities ( QStandardItem * ) ) ) ;
// Update disk space labels
updateDiskSpaceLabels ( ) ;
}
2006-10-24 01:42:37 +04:00
2009-08-17 17:17:52 +04:00
void updateDiskSpaceLabels ( ) {
2009-09-07 15:48:31 +04:00
long long available = misc : : freeDiskSpaceOnPath ( savePathTxt - > text ( ) ) ;
2009-09-07 00:13:18 +04:00
lbl_disk_space - > setText ( misc : : friendlyUnit ( available ) ) ;
2009-08-17 17:17:52 +04:00
// Determine torrent size
unsigned long long torrent_size = 0 ;
int nbFiles = t - > num_files ( ) ;
int * priorities = new int [ nbFiles ] ;
getPriorities ( PropListModel - > invisibleRootItem ( ) , priorities ) ;
for ( int i = 0 ; i < nbFiles ; + + i ) {
if ( priorities [ i ] > 0 )
torrent_size + = t - > file_at ( i ) . size ;
}
lbl_torrent_size - > setText ( misc : : friendlyUnit ( torrent_size ) ) ;
// Check if free space is sufficient
if ( available > 0 ) {
2009-09-07 15:48:31 +04:00
if ( ( unsigned long long ) available > torrent_size ) {
2009-08-17 17:17:52 +04:00
// Space is sufficient
label_space_msg - > setText ( tr ( " (%1 left after torrent download) " , " e.g. (100MiB left after torrent download) " ) . arg ( misc : : friendlyUnit ( available - torrent_size ) ) ) ;
} else {
// Space is unsufficient
label_space_msg - > setText ( " <font color= \" red \" > " + tr ( " (%1 more are required to download) " , " e.g. (100MiB more are required to download) " ) . arg ( misc : : friendlyUnit ( torrent_size - available ) ) + " </font> " ) ;
2006-10-24 01:42:37 +04:00
}
2009-08-17 17:17:52 +04:00
} else {
// Available disk space is unknown
label_space_msg - > setText ( " " ) ;
2006-10-24 01:42:37 +04:00
}
2009-08-17 17:17:52 +04:00
}
2006-10-24 01:42:37 +04:00
2009-08-17 17:17:52 +04:00
void on_browseButton_clicked ( ) {
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 ( ) ) ;
2007-07-31 19:37:14 +04:00
}
2009-08-17 17:17:52 +04:00
if ( ! dir . isNull ( ) ) {
savePathTxt - > setText ( dir ) ;
}
}
void on_CancelButton_clicked ( ) {
close ( ) ;
}
2007-07-31 19:37:14 +04:00
2009-08-17 17:17:52 +04:00
// Set the color of a row in data model
2009-08-29 13:42:20 +04:00
void setItemColor ( QModelIndex index , QString color ) {
2009-08-17 17:17:52 +04:00
for ( int i = 0 ; i < PropListModel - > columnCount ( ) ; + + i ) {
2009-08-29 13:42:20 +04:00
PropListModel - > setData ( index . sibling ( index . row ( ) , i ) , QVariant ( QColor ( color ) ) , Qt : : ForegroundRole ) ;
2007-07-20 17:21:46 +04:00
}
2009-08-17 17:17:52 +04:00
}
2007-07-20 17:21:46 +04:00
2009-08-17 17:17:52 +04:00
bool allFiltered ( ) const {
unsigned int nbRows = PropListModel - > rowCount ( ) ;
for ( unsigned int i = 0 ; i < nbRows ; + + i ) {
if ( PropListModel - > data ( PropListModel - > index ( i , PRIORITY ) ) . toInt ( ) ! = IGNORED )
return false ;
2007-07-20 17:21:46 +04:00
}
2009-08-17 17:17:52 +04:00
return true ;
}
2007-07-20 17:21:46 +04:00
2009-08-17 17:17:52 +04:00
void displayFilesListMenu ( const QPoint & ) {
if ( nbFiles = = 1 ) return ;
QMenu myFilesLlistMenu ( this ) ;
QModelIndex index ;
// Enable/disable pause/start action given the DL state
QModelIndexList selectedIndexes = torrentContentList - > selectionModel ( ) - > selectedIndexes ( ) ;
myFilesLlistMenu . setTitle ( tr ( " Priority " ) ) ;
myFilesLlistMenu . addAction ( actionIgnored ) ;
myFilesLlistMenu . addAction ( actionNormal ) ;
myFilesLlistMenu . addAction ( actionHigh ) ;
myFilesLlistMenu . addAction ( actionMaximum ) ;
// Call menu
myFilesLlistMenu . exec ( QCursor : : pos ( ) ) ;
}
void ignoreSelection ( ) {
QModelIndexList selectedIndexes = torrentContentList - > selectionModel ( ) - > selectedIndexes ( ) ;
foreach ( const QModelIndex & index , selectedIndexes ) {
if ( index . column ( ) = = PRIORITY ) {
PropListModel - > setData ( index , QVariant ( IGNORED ) ) ;
2009-08-29 13:42:20 +04:00
setItemColor ( index , " red " ) ;
2007-07-20 17:21:46 +04:00
}
}
2009-08-17 17:17:52 +04:00
}
2007-07-20 17:21:46 +04:00
2009-08-17 17:17:52 +04:00
void normalSelection ( ) {
QModelIndexList selectedIndexes = torrentContentList - > selectionModel ( ) - > selectedIndexes ( ) ;
foreach ( const QModelIndex & index , selectedIndexes ) {
if ( index . column ( ) = = PRIORITY ) {
PropListModel - > setData ( index , QVariant ( NORMAL ) ) ;
2009-08-29 13:42:20 +04:00
setItemColor ( index , " green " ) ;
2007-07-20 17:21:46 +04:00
}
}
2009-08-17 17:17:52 +04:00
}
2007-07-20 17:21:46 +04:00
2009-08-17 17:17:52 +04:00
void highSelection ( ) {
QModelIndexList selectedIndexes = torrentContentList - > selectionModel ( ) - > selectedIndexes ( ) ;
foreach ( const QModelIndex & index , selectedIndexes ) {
if ( index . column ( ) = = PRIORITY ) {
PropListModel - > setData ( index , QVariant ( HIGH ) ) ;
2009-08-29 13:42:20 +04:00
setItemColor ( index , " green " ) ;
2007-07-20 17:21:46 +04:00
}
}
2009-08-17 17:17:52 +04:00
}
2007-07-20 17:21:46 +04:00
2009-08-17 17:17:52 +04:00
void maximumSelection ( ) {
QModelIndexList selectedIndexes = torrentContentList - > selectionModel ( ) - > selectedIndexes ( ) ;
foreach ( const QModelIndex & index , selectedIndexes ) {
if ( index . column ( ) = = PRIORITY ) {
PropListModel - > setData ( index , QVariant ( MAXIMUM ) ) ;
2009-08-29 13:42:20 +04:00
setItemColor ( index , " green " ) ;
2007-09-16 13:19:22 +04:00
}
}
2009-08-17 17:17:52 +04:00
}
2007-09-16 13:19:22 +04:00
2009-08-17 17:17:52 +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 ) {
qDebug ( " getPriorities(), found a folder, checking its children " ) ;
getPriorities ( parent - > child ( i ) , priorities ) ;
} else {
item = parent - > child ( i , PRIORITY ) ;
qDebug ( " getPriorities(), found priority %d for file at index %d " , item - > text ( ) . toInt ( ) , index ) ;
priorities [ index ] = item - > text ( ) . toInt ( ) ;
2006-10-24 01:42:37 +04:00
}
}
2009-08-17 17:17:52 +04:00
}
2006-10-24 01:42:37 +04:00
2009-08-17 17:17:52 +04:00
void savePiecesPriorities ( ) {
qDebug ( " Saving pieces priorities " ) ;
int * priorities = new int [ nbFiles ] ;
getPriorities ( PropListModel - > invisibleRootItem ( ) , priorities ) ;
std : : vector < int > vect_prio ;
for ( unsigned int i = 0 ; i < nbFiles ; + + i ) {
vect_prio . push_back ( priorities [ i ] ) ;
}
delete [ ] priorities ;
TorrentTempData : : setFilesPriority ( hash , vect_prio ) ;
}
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 " ) ) ;
2006-10-24 01:42:37 +04:00
return ;
}
}
2009-08-17 17:17:52 +04:00
// Save savepath
TorrentTempData : : setSavePath ( hash , savePath . path ( ) ) ;
// Save last dir to remember it
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
settings . setValue ( QString : : fromUtf8 ( " LastDirTorrentAdd " ) , savePathTxt - > text ( ) ) ;
// Create .incremental file if necessary
TorrentTempData : : setSequential ( hash , checkIncrementalDL - > isChecked ( ) ) ;
// Check if there is at least one selected file
if ( allFiltered ( ) ) {
QMessageBox : : warning ( 0 , tr ( " Invalid file selection " ) , tr ( " You must select at least one file in the torrent " ) ) ;
return ;
}
// save filtered files
savePiecesPriorities ( ) ;
// Add to download list
QTorrentHandle h = BTSession - > addTorrent ( filePath , false , from_url ) ;
if ( addInPause - > isChecked ( ) & & h . is_valid ( ) )
h . pause ( ) ;
close ( ) ;
}
2006-10-24 01:42:37 +04:00
} ;
# endif