@ -60,7 +60,7 @@
@@ -60,7 +60,7 @@
using namespace libtorrent ;
torrentAdditionDialog : : torrentAdditionDialog ( QWidget * parent ) :
QDialog ( parent ) , old_l abel( " " ) , hidden_h eight( 0 ) , m_showContentList ( true ) {
QDialog ( parent ) , m_oldL abel( " " ) , m_hiddenH eight( 0 ) , m_showContentList ( true ) {
Preferences pref ;
setupUi ( this ) ;
setAttribute ( Qt : : WA_DeleteOnClose ) ;
@ -68,33 +68,33 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) :
@@ -68,33 +68,33 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) :
CancelButton - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " dialog-cancel " ) ) ;
OkButton - > setIcon ( IconProvider : : instance ( ) - > getIcon ( " list-add " ) ) ;
// Set Properties list model
P ropListModel = new TorrentContentFilterModel ( this ) ;
connect ( P ropListModel, SIGNAL ( filteredFilesChanged ( ) ) , SLOT ( updateDiskSpaceLabels ( ) ) ) ;
torrentContentList - > setModel ( P ropListModel) ;
m_p ropListModel = new TorrentContentFilterModel ( this ) ;
connect ( m_p ropListModel, SIGNAL ( filteredFilesChanged ( ) ) , SLOT ( updateDiskSpaceLabels ( ) ) ) ;
torrentContentList - > setModel ( m_p ropListModel) ;
torrentContentList - > hideColumn ( PROGRESS ) ;
Prop Delegate = new PropListDelegate ( ) ;
torrentContentList - > setItemDelegate ( Prop Delegate) ;
m_propList Delegate = new PropListDelegate ( ) ;
torrentContentList - > setItemDelegate ( m_propList Delegate) ;
connect ( torrentContentList , SIGNAL ( clicked ( const QModelIndex & ) ) , torrentContentList , SLOT ( edit ( const QModelIndex & ) ) ) ;
connect ( torrentContentList , SIGNAL ( customContextMenuRequested ( const QPoint & ) ) , this , SLOT ( displayContentListMenu ( const QPoint & ) ) ) ;
connect ( selectAllButton , SIGNAL ( clicked ( ) ) , P ropListModel, SLOT ( selectAll ( ) ) ) ;
connect ( selectNoneButton , SIGNAL ( clicked ( ) ) , P ropListModel, SLOT ( selectNone ( ) ) ) ;
connect ( selectAllButton , SIGNAL ( clicked ( ) ) , m_p ropListModel, SLOT ( selectAll ( ) ) ) ;
connect ( selectNoneButton , SIGNAL ( clicked ( ) ) , m_p ropListModel, SLOT ( selectNone ( ) ) ) ;
connect ( comboLabel , SIGNAL ( editTextChanged ( QString ) ) , this , SLOT ( resetComboLabelIndex ( QString ) ) ) ;
connect ( comboLabel , SIGNAL ( editTextChanged ( QString ) ) , this , SLOT ( updateLabelInSavePath ( QString ) ) ) ;
connect ( comboLabel , SIGNAL ( currentIndexChanged ( QString ) ) , this , SLOT ( updateLabelInSavePath ( QString ) ) ) ;
LineEdit * contentFilterLine = new LineEdit ( this ) ;
connect ( contentFilterLine , SIGNAL ( textChanged ( QString ) ) , P ropListModel, SLOT ( setFilterFixedString ( QString ) ) ) ;
connect ( contentFilterLine , SIGNAL ( textChanged ( QString ) ) , m_p ropListModel, SLOT ( setFilterFixedString ( QString ) ) ) ;
contentFilterLayout - > insertWidget ( 1 , contentFilterLine ) ;
// Important: as a default, it inserts at the bottom which is not desirable
savePathTxt - > setInsertPolicy ( QComboBox : : InsertAtCurrent ) ;
//torrentContentList->header()->setResizeMode(0, QHeaderView::Stretch);
defaultSavePath = pref . getSavePath ( ) ;
m_ defaultSavePath = pref . getSavePath ( ) ;
//In case of the LastLocationPath doesn't exist anymore, empty the string
appendLabelToSavePath = pref . appendTorrentLabel ( ) ;
QString display_path = defaultSavePath . replace ( " \\ " , " / " ) ;
m_ appendLabelToSavePath = pref . appendTorrentLabel ( ) ;
QString display_path = m_ defaultSavePath. replace ( " \\ " , " / " ) ;
if ( ! display_path . endsWith ( " / " ) )
display_path + = " / " ;
path_h istory < < display_path ;
m_pathH istory < < display_path ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
display_path . replace ( " / " , " \\ " ) ;
# endif
@ -118,8 +118,8 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) :
@@ -118,8 +118,8 @@ torrentAdditionDialog::torrentAdditionDialog(QWidget *parent) :
}
torrentAdditionDialog : : ~ torrentAdditionDialog ( ) {
delete Prop Delegate;
delete P ropListModel;
delete m_propList Delegate;
delete m_p ropListModel;
}
void torrentAdditionDialog : : closeEvent ( QCloseEvent * event )
@ -193,28 +193,23 @@ void torrentAdditionDialog::hideTorrentContent() {
@@ -193,28 +193,23 @@ void torrentAdditionDialog::hideTorrentContent() {
m_showContentList = false ;
}
void torrentAdditionDialog : : showLoadMagnetURI ( QString magnet_uri ) {
is_m agnet = true ;
this - > from_u rl = magnet_uri ;
void torrentAdditionDialog : : showLoadMagnetURI ( const QString & magnet_uri ) {
m_isM agnet = true ;
this - > m_fromU rl = magnet_uri ;
checkLastFolder - > setEnabled ( false ) ;
// Disable Save path combox and browse button
// Save path should be default for magnet links
savePathTxt - > setEnabled ( true ) ;
browseButton - > setEnabled ( true ) ;
// Get torrent hash
hash = misc : : magnetUriToHash ( magnet_uri ) ;
if ( hash . isEmpty ( ) ) {
QBtSession : : instance ( ) - > addConsoleMessage ( tr ( " Unable to decode magnet link: " ) + QString : : fromUtf8 ( " ' " ) + from_u rl+ QString : : fromUtf8 ( " ' " ) , QString : : fromUtf8 ( " red " ) ) ;
m_hash = misc : : magnetUriToHash ( magnet_uri ) ;
if ( m_hash . isEmpty ( ) ) {
QBtSession : : instance ( ) - > addConsoleMessage ( tr ( " Unable to decode magnet link: " ) + QString : : fromUtf8 ( " ' " ) + m_fromUrl + QString : : fromUtf8 ( " ' " ) , QString : : fromUtf8 ( " red " ) ) ;
return ;
}
// Set torrent name
fileName = misc : : magnetUriToName ( magnet_uri ) ;
if ( fileName . isEmpty ( ) ) {
fileName = tr ( " Magnet Link " ) ;
m_ fileName = misc : : magnetUriToName ( magnet_uri ) ;
if ( m_ fileName. isEmpty ( ) ) {
m_ fileName = tr ( " Magnet Link " ) ;
}
fileNameLbl - > setText ( QString : : fromUtf8 ( " <center><b> " ) + fileName + QString : : fromUtf8 ( " </b></center> " ) ) ;
fileNameLbl - > setText ( QString : : fromUtf8 ( " <center><b> " ) + m_ fileName+ QString : : fromUtf8 ( " </b></center> " ) ) ;
// Update display
updateDiskSpaceLabels ( ) ;
@ -231,73 +226,73 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
@@ -231,73 +226,73 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
show ( ) ;
}
void torrentAdditionDialog : : showLoad ( QString filePath , QString from_url ) {
is_m agnet = false ;
void torrentAdditionDialog : : showLoad ( const QString & filePath , const QString & from_url ) {
m_isM agnet = false ;
// This is an URL to a local file, switch to local path
if ( filePath . startsWith ( " file: " , Qt : : CaseInsensitive ) )
filePath = QUrl : : fromEncoded ( filePath . toLocal8Bit ( ) ) . toLocalFile ( ) ;
m_filePath = QUrl : : fromEncoded ( filePath . toLocal8Bit ( ) ) . toLocalFile ( ) ;
else
m_filePath = filePath ;
if ( ! QFile : : exists ( filePath ) ) {
if ( ! QFile : : exists ( m_ filePath) ) {
close ( ) ;
return ;
}
qDebug ( ) < < Q_FUNC_INFO < < filePath ;
this - > filePath = filePath ;
this - > from_url = from_url ;
this - > m_fromUrl = from_url ;
// Getting torrent file informations
try {
t = new torrent_info ( filePath . toUtf8 ( ) . data ( ) ) ;
if ( ! t - > is_valid ( ) )
m_ torrentInfo = new torrent_info ( m_ filePath. toUtf8 ( ) . data ( ) ) ;
if ( ! m_ torrentInfo - > is_valid ( ) )
throw std : : exception ( ) ;
} catch ( std : : exception & ) {
qDebug ( " Caught error loading torrent " ) ;
if ( ! from_url . isNull ( ) ) {
QBtSession : : instance ( ) - > addConsoleMessage ( tr ( " Unable to decode torrent file: " ) + QString : : fromUtf8 ( " ' " ) + from_url + QString : : fromUtf8 ( " ' " ) , QString : : fromUtf8 ( " red " ) ) ;
QFile : : remove ( filePath ) ;
QFile : : remove ( m_ filePath) ;
} else {
QBtSession : : instance ( ) - > addConsoleMessage ( tr ( " Unable to decode torrent file: " ) + QString : : fromUtf8 ( " ' " ) + filePath + QString : : fromUtf8 ( " ' " ) , QString : : fromUtf8 ( " red " ) ) ;
QBtSession : : instance ( ) - > addConsoleMessage ( tr ( " Unable to decode torrent file: " ) + QString : : fromUtf8 ( " ' " ) + m_ filePath+ QString : : fromUtf8 ( " ' " ) , QString : : fromUtf8 ( " red " ) ) ;
}
close ( ) ;
return ;
}
nbFiles = t - > num_files ( ) ;
if ( nbFiles = = 0 ) {
m_ nbFiles = m_ torrentInfo - > num_files ( ) ;
if ( m_ nbFiles = = 0 ) {
// Empty torrent file!?
close ( ) ;
return ;
}
# if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t - > files ( ) ;
file_storage fs = m_ torrentInfo - > files ( ) ;
# endif
// Truncate root folder
QString root_folder = misc : : truncateRootFolder ( t ) ;
QString root_folder = misc : : truncateRootFolder ( m_ torrentInfo ) ;
// Setting file name
fileName = misc : : toQStringU ( t - > name ( ) ) ;
hash = misc : : toQString ( t - > info_hash ( ) ) ;
m_ fileName = misc : : toQStringU ( m_ torrentInfo - > name ( ) ) ;
m_ hash = misc : : toQString ( m_ torrentInfo - > info_hash ( ) ) ;
// Use left() to remove .old extension
QString newFileName ;
if ( fileName . endsWith ( QString : : fromUtf8 ( " .old " ) ) ) {
newFileName = fileName . left ( fileName . size ( ) - 4 ) ;
if ( m_ fileName. endsWith ( QString : : fromUtf8 ( " .old " ) ) ) {
newFileName = m_ fileName. left ( m_ fileName. size ( ) - 4 ) ;
} else {
newFileName = fileName ;
newFileName = m_ fileName;
}
fileNameLbl - > setText ( QString : : fromUtf8 ( " <center><b> " ) + newFileName + QString : : fromUtf8 ( " </b></center> " ) ) ;
if ( t - > num_files ( ) > 1 ) {
if ( m_ torrentInfo - > num_files ( ) > 1 ) {
// List files in torrent
P ropListModel- > model ( ) - > setupModelData ( * t ) ;
connect ( Prop Delegate, SIGNAL ( filteredFilesChanged ( ) ) , this , SLOT ( updateDiskSpaceLabels ( ) ) ) ;
m_p ropListModel- > model ( ) - > setupModelData ( * m_ torrentInfo ) ;
connect ( m_propList Delegate, SIGNAL ( filteredFilesChanged ( ) ) , this , SLOT ( updateDiskSpaceLabels ( ) ) ) ;
// Loads files path in the torrent
for ( uint i = 0 ; i < nbFiles ; + + i ) {
for ( uint i = 0 ; i < m_ nbFiles; + + i ) {
# if LIBTORRENT_VERSION_MINOR >= 16
files_p ath < < misc : : toQStringU ( fs . file_path ( t - > file_at ( i ) ) ) ;
m_filesP ath < < misc : : toQStringU ( fs . file_path ( m_ torrentInfo - > file_at ( i ) ) ) ;
# else
files_p ath < < misc : : toQStringU ( t - > file_at ( i ) . path . string ( ) ) ;
m_filesP ath < < misc : : toQStringU ( m_ torrentInfo - > file_at ( i ) . path . string ( ) ) ;
# endif
}
}
// Load save path history
@ -317,12 +312,12 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -317,12 +312,12 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
if ( ! root_folder . isEmpty ( ) ) {
save_path + = root_folder ;
}
if ( nbFiles = = 1 ) {
if ( m_ nbFiles = = 1 ) {
// single file torrent
# if LIBTORRENT_VERSION_MINOR >= 16
QString single_file_relpath = misc : : toQStringU ( fs . file_path ( t - > file_at ( 0 ) ) ) ;
QString single_file_relpath = misc : : toQStringU ( fs . file_path ( m_ torrentInfo - > file_at ( 0 ) ) ) ;
# else
QString single_file_relpath = misc : : toQStringU ( t - > file_at ( 0 ) . path . string ( ) ) ;
QString single_file_relpath = misc : : toQStringU ( m_ torrentInfo - > file_at ( 0 ) . path . string ( ) ) ;
# endif
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
single_file_relpath . replace ( " / " , " \\ " ) ;
@ -335,7 +330,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -335,7 +330,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
updateDiskSpaceLabels ( ) ;
// Hide useless widgets
if ( t - > num_files ( ) < = 1 )
if ( m_ torrentInfo - > num_files ( ) < = 1 )
hideTorrentContent ( ) ;
// Remember dialog geometry
@ -349,11 +344,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -349,11 +344,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
}
void torrentAdditionDialog : : displayContentListMenu ( const QPoint & ) {
Q_ASSERT ( ! is_m agnet & & t - > num_files ( ) > 1 ) ;
Q_ASSERT ( ! m_isM agnet & & m_ torrentInfo - > num_files ( ) > 1 ) ;
QMenu myFilesLlistMenu ;
const QModelIndexList selectedRows = torrentContentList - > selectionModel ( ) - > selectedRows ( 0 ) ;
QAction * actRename = 0 ;
if ( selectedRows . size ( ) = = 1 & & t - > num_files ( ) > 1 ) {
if ( selectedRows . size ( ) = = 1 & & m_ torrentInfo - > num_files ( ) > 1 ) {
actRename = myFilesLlistMenu . addAction ( IconProvider : : instance ( ) - > getIcon ( " edit-rename " ) , tr ( " Rename... " ) ) ;
myFilesLlistMenu . addSeparator ( ) ;
}
@ -385,14 +380,14 @@ void torrentAdditionDialog::displayContentListMenu(const QPoint&) {
@@ -385,14 +380,14 @@ void torrentAdditionDialog::displayContentListMenu(const QPoint&) {
qDebug ( " Setting files priority " ) ;
foreach ( const QModelIndex & index , selectedRows ) {
qDebug ( " Setting priority(%d) for file at row %d " , prio , index . row ( ) ) ;
P ropListModel- > setData ( P ropListModel- > index ( index . row ( ) , PRIORITY , index . parent ( ) ) , prio ) ;
m_p ropListModel- > setData ( m_p ropListModel- > index ( index . row ( ) , PRIORITY , index . parent ( ) ) , prio ) ;
}
}
}
}
void torrentAdditionDialog : : renameSelectedFile ( ) {
Q_ASSERT ( ! is_m agnet & & t - > num_files ( ) > 1 ) ;
Q_ASSERT ( ! m_isM agnet & & m_ torrentInfo - > num_files ( ) > 1 ) ;
const QModelIndexList selectedIndexes = torrentContentList - > selectionModel ( ) - > selectedRows ( 0 ) ;
Q_ASSERT ( selectedIndexes . size ( ) = = 1 ) ;
const QModelIndex & index = selectedIndexes . first ( ) ;
@ -408,10 +403,10 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -408,10 +403,10 @@ void torrentAdditionDialog::renameSelectedFile() {
QMessageBox : : Ok ) ;
return ;
}
if ( P ropListModel- > getType ( index ) = = TorrentContentModelItem : : TFILE ) {
if ( m_p ropListModel- > getType ( index ) = = TorrentContentModelItem : : TFILE ) {
// File renaming
const uint file_index = P ropListModel- > getFileIndex ( index ) ;
QString old_name = files_p ath. at ( file_index ) ;
const uint file_index = m_p ropListModel- > getFileIndex ( index ) ;
QString old_name = m_filesP ath. at ( file_index ) ;
old_name . replace ( " \\ " , " / " ) ;
qDebug ( " Old name: %s " , qPrintable ( old_name ) ) ;
QStringList path_items = old_name . split ( " / " ) ;
@ -425,12 +420,12 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -425,12 +420,12 @@ void torrentAdditionDialog::renameSelectedFile() {
new_name = QDir : : cleanPath ( new_name ) ;
qDebug ( " New name: %s " , qPrintable ( new_name ) ) ;
// Check if that name is already used
for ( uint i = 0 ; i < nbFiles ; + + i ) {
for ( uint i = 0 ; i < m_ nbFiles; + + i ) {
if ( i = = file_index ) continue ;
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if ( files_p ath. at ( i ) . compare ( new_name , Qt : : CaseSensitive ) = = 0 ) {
if ( m_filesP ath. at ( i ) . compare ( new_name , Qt : : CaseSensitive ) = = 0 ) {
# else
if ( files_p ath. at ( i ) . compare ( new_name , Qt : : CaseInsensitive ) = = 0 ) {
if ( m_filesP ath. at ( i ) . compare ( new_name , Qt : : CaseInsensitive ) = = 0 ) {
# endif
// Display error message
QMessageBox : : warning ( this , tr ( " The file could not be renamed " ) ,
@ -442,17 +437,17 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -442,17 +437,17 @@ void torrentAdditionDialog::renameSelectedFile() {
new_name = QDir : : cleanPath ( new_name ) ;
qDebug ( " Renaming %s to %s " , qPrintable ( old_name ) , qPrintable ( new_name ) ) ;
// Rename file in files_path
files_p ath. replace ( file_index , new_name ) ;
m_filesP ath. replace ( file_index , new_name ) ;
// Rename in torrent files model too
P ropListModel- > setData ( index , new_name_last ) ;
m_p ropListModel- > setData ( index , new_name_last ) ;
} else {
// Folder renaming
QStringList path_items ;
path_items < < index . data ( ) . toString ( ) ;
QModelIndex parent = P ropListModel- > parent ( index ) ;
QModelIndex parent = m_p ropListModel- > parent ( index ) ;
while ( parent . isValid ( ) ) {
path_items . prepend ( parent . data ( ) . toString ( ) ) ;
parent = P ropListModel- > parent ( parent ) ;
parent = m_p ropListModel- > parent ( parent ) ;
}
const QString old_path = path_items . join ( " / " ) ;
path_items . removeLast ( ) ;
@ -460,8 +455,8 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -460,8 +455,8 @@ void torrentAdditionDialog::renameSelectedFile() {
QString new_path = path_items . join ( " / " ) ;
if ( ! new_path . endsWith ( " / " ) ) new_path + = " / " ;
// Check for overwriting
for ( uint i = 0 ; i < nbFiles ; + + i ) {
const QString & current_name = files_p ath. at ( i ) ;
for ( uint i = 0 ; i < m_ nbFiles; + + i ) {
const QString & current_name = m_filesP ath. at ( i ) ;
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if ( current_name . startsWith ( new_path , Qt : : CaseSensitive ) ) {
# else
@ -474,19 +469,19 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -474,19 +469,19 @@ void torrentAdditionDialog::renameSelectedFile() {
}
}
// Replace path in all files
for ( uint i = 0 ; i < nbFiles ; + + i ) {
const QString & current_name = files_p ath. at ( i ) ;
for ( uint i = 0 ; i < m_ nbFiles; + + i ) {
const QString & current_name = m_filesP ath. at ( i ) ;
if ( current_name . startsWith ( old_path ) ) {
QString new_name = current_name ;
new_name . replace ( 0 , old_path . length ( ) , new_path ) ;
new_name = QDir : : cleanPath ( new_name ) ;
qDebug ( " Rename %s to %s " , qPrintable ( current_name ) , qPrintable ( new_name ) ) ;
// Rename in files_path
files_p ath. replace ( i , new_name ) ;
m_filesP ath. replace ( i , new_name ) ;
}
}
// Rename folder in torrent files model too
P ropListModel- > setData ( index , new_name_last ) ;
m_p ropListModel- > setData ( index , new_name_last ) ;
}
}
}
@ -495,19 +490,19 @@ void torrentAdditionDialog::updateDiskSpaceLabels() {
@@ -495,19 +490,19 @@ void torrentAdditionDialog::updateDiskSpaceLabels() {
qDebug ( " Updating disk space label... " ) ;
const long long available = misc : : freeDiskSpaceOnPath ( misc : : expandPath ( savePathTxt - > currentText ( ) ) ) ;
lbl_disk_space - > setText ( misc : : friendlyUnit ( available ) ) ;
if ( ! is_m agnet) {
if ( ! m_isM agnet) {
// Determine torrent size
qulonglong torrent_size = 0 ;
if ( t - > num_files ( ) > 1 ) {
const std : : vector < int > priorities = P ropListModel- > model ( ) - > getFilesPriorities ( ) ;
Q_ASSERT ( priorities . size ( ) = = t - > num_files ( ) ) ;
if ( m_ torrentInfo - > num_files ( ) > 1 ) {
const std : : vector < int > priorities = m_p ropListModel- > model ( ) - > getFilesPriorities ( ) ;
Q_ASSERT ( priorities . size ( ) = = m_ torrentInfo - > num_files ( ) ) ;
for ( unsigned int i = 0 ; i < priorities . size ( ) ; + + i ) {
if ( priorities [ i ] > 0 )
torrent_size + = t - > file_at ( i ) . size ;
torrent_size + = m_ torrentInfo - > file_at ( i ) . size ;
}
} else {
torrent_size = t - > total_size ( ) ;
torrent_size = m_ torrentInfo - > total_size ( ) ;
}
lbl_torrent_size - > setText ( misc : : friendlyUnit ( torrent_size ) ) ;
@ -531,14 +526,14 @@ void torrentAdditionDialog::on_browseButton_clicked() {
@@ -531,14 +526,14 @@ void torrentAdditionDialog::on_browseButton_clicked() {
QString new_path ;
QString root_folder ;
const QString label_name = comboLabel - > currentText ( ) ;
if ( ! is_m agnet) {
if ( t - > num_files ( ) = = 1 ) {
if ( ! m_isM agnet) {
if ( m_ torrentInfo - > num_files ( ) = = 1 ) {
new_path = QFileDialog : : getSaveFileName ( this , tr ( " Choose save path " ) , savePathTxt - > currentText ( ) , QString ( ) , 0 , QFileDialog : : DontConfirmOverwrite ) ;
if ( ! new_path . isEmpty ( ) ) {
QStringList path_parts = new_path . replace ( " \\ " , " / " ) . split ( " / " ) ;
const QString filename = path_parts . takeLast ( ) ;
// Append label
if ( QDir ( path_parts . join ( QDir : : separator ( ) ) ) = = QDir ( defaultSavePath ) & & ! label_name . isEmpty ( ) )
if ( QDir ( path_parts . join ( QDir : : separator ( ) ) ) = = QDir ( m_ defaultSavePath) & & ! label_name . isEmpty ( ) )
path_parts < < label_name ;
// Append file name
path_parts < < filename ;
@ -558,7 +553,7 @@ void torrentAdditionDialog::on_browseButton_clicked() {
@@ -558,7 +553,7 @@ void torrentAdditionDialog::on_browseButton_clicked() {
if ( path_parts . last ( ) . isEmpty ( ) )
path_parts . removeLast ( ) ;
// Append label
if ( QDir ( new_path ) = = QDir ( defaultSavePath ) & & ! label_name . isEmpty ( ) )
if ( QDir ( new_path ) = = QDir ( m_ defaultSavePath) & & ! label_name . isEmpty ( ) )
path_parts < < label_name ;
// Append root folder
if ( ! root_folder . isEmpty ( ) )
@ -571,9 +566,9 @@ void torrentAdditionDialog::on_browseButton_clicked() {
@@ -571,9 +566,9 @@ void torrentAdditionDialog::on_browseButton_clicked() {
// Check if this new path already exists in the list
QString new_truncated_path = getTruncatedSavePath ( new_path ) ;
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
const int cur_index = path_h istory. indexOf ( QRegExp ( new_truncated_path , Qt : : CaseInsensitive ) ) ;
const int cur_index = m_pathH istory. indexOf ( QRegExp ( new_truncated_path , Qt : : CaseInsensitive ) ) ;
# else
const int cur_index = path_h istory. indexOf ( QRegExp ( new_truncated_path , Qt : : CaseSensitive ) ) ;
const int cur_index = m_pathH istory. indexOf ( QRegExp ( new_truncated_path , Qt : : CaseSensitive ) ) ;
# endif
if ( cur_index > = 0 ) {
savePathTxt - > setCurrentIndex ( cur_index ) ;
@ -590,15 +585,15 @@ void torrentAdditionDialog::on_CancelButton_clicked() {
@@ -590,15 +585,15 @@ void torrentAdditionDialog::on_CancelButton_clicked() {
}
bool torrentAdditionDialog : : allFiltered ( ) const {
Q_ASSERT ( ! is_m agnet) ;
return P ropListModel- > model ( ) - > allFiltered ( ) ;
Q_ASSERT ( ! m_isM agnet) ;
return m_p ropListModel- > model ( ) - > allFiltered ( ) ;
}
void torrentAdditionDialog : : savePiecesPriorities ( ) {
qDebug ( " Saving pieces priorities " ) ;
Q_ASSERT ( ! is_m agnet) ;
const std : : vector < int > priorities = P ropListModel- > model ( ) - > getFilesPriorities ( ) ;
TorrentTempData : : setFilesPriority ( hash , priorities ) ;
Q_ASSERT ( ! m_isM agnet) ;
const std : : vector < int > priorities = m_p ropListModel- > model ( ) - > getFilesPriorities ( ) ;
TorrentTempData : : setFilesPriority ( m_ hash, priorities ) ;
}
void torrentAdditionDialog : : on_OkButton_clicked ( ) {
@ -614,12 +609,12 @@ void torrentAdditionDialog::on_OkButton_clicked() {
@@ -614,12 +609,12 @@ void torrentAdditionDialog::on_OkButton_clicked() {
# endif
save_path = misc : : expandPath ( save_path ) ;
qDebug ( " Save path is %s " , qPrintable ( save_path ) ) ;
if ( ! is_m agnet & & t - > num_files ( ) = = 1 ) {
if ( ! m_isM agnet & & m_ torrentInfo - > num_files ( ) = = 1 ) {
// Remove file name
QStringList parts = save_path . split ( " / " ) ;
const QString single_file_name = parts . takeLast ( ) ;
Q_ASSERT ( files_p ath. isEmpty ( ) ) ;
files_p ath < < single_file_name ;
Q_ASSERT ( m_filesP ath. isEmpty ( ) ) ;
m_filesP ath < < single_file_name ;
save_path = parts . join ( " / " ) ;
}
qDebug ( " Save path dir is %s " , qPrintable ( save_path ) ) ;
@ -631,27 +626,27 @@ void torrentAdditionDialog::on_OkButton_clicked() {
@@ -631,27 +626,27 @@ void torrentAdditionDialog::on_OkButton_clicked() {
}
// Save savepath
qDebug ( " Saving save path to temp data: %s " , qPrintable ( savePath . absolutePath ( ) ) ) ;
TorrentTempData : : setSavePath ( hash , savePath . absolutePath ( ) ) ;
TorrentTempData : : setSavePath ( m_ hash, savePath . absolutePath ( ) ) ;
qDebug ( " Torrent label is: %s " , qPrintable ( comboLabel - > currentText ( ) . trimmed ( ) ) ) ;
if ( ! current_label . isEmpty ( ) )
TorrentTempData : : setLabel ( hash , current_label ) ;
TorrentTempData : : setLabel ( m_ hash, current_label ) ;
// Is download sequential?
TorrentTempData : : setSequential ( hash , checkIncrementalDL - > isChecked ( ) ) ;
TorrentTempData : : setSequential ( m_ hash, checkIncrementalDL - > isChecked ( ) ) ;
// Save files path
// Loads files path in the torrent
if ( ! is_m agnet) {
if ( ! m_isM agnet) {
bool path_changed = false ;
for ( uint i = 0 ; i < nbFiles ; + + i ) {
for ( uint i = 0 ; i < m_ nbFiles; + + i ) {
# if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t - > files ( ) ;
QString old_path = misc : : toQStringU ( fs . file_path ( t - > file_at ( i ) ) ) ;
file_storage fs = m_ torrentInfo - > files ( ) ;
QString old_path = misc : : toQStringU ( fs . file_path ( m_ torrentInfo - > file_at ( i ) ) ) ;
# else
QString old_path = misc : : toQStringU ( t - > file_at ( i ) . path . string ( ) ) ;
QString old_path = misc : : toQStringU ( m_ torrentInfo - > file_at ( i ) . path . string ( ) ) ;
# endif
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if ( files_p ath. at ( i ) . compare ( old_path , Qt : : CaseSensitive ) ! = 0 ) {
if ( m_filesP ath. at ( i ) . compare ( old_path , Qt : : CaseSensitive ) ! = 0 ) {
# else
if ( files_p ath. at ( i ) . compare ( old_path , Qt : : CaseInsensitive ) ! = 0 ) {
if ( m_filesP ath. at ( i ) . compare ( old_path , Qt : : CaseInsensitive ) ! = 0 ) {
# endif
path_changed = true ;
break ;
@ -659,21 +654,21 @@ void torrentAdditionDialog::on_OkButton_clicked() {
@@ -659,21 +654,21 @@ void torrentAdditionDialog::on_OkButton_clicked() {
}
if ( path_changed ) {
qDebug ( " Changing files paths " ) ;
TorrentTempData : : setFilesPath ( hash , files_p ath) ;
TorrentTempData : : setFilesPath ( m_ hash, m_filesP ath) ;
}
}
// Skip file checking and directly start seeding
if ( addInSeed - > isChecked ( ) ) {
// Check if local file(s) actually exist
if ( is_m agnet | | QFile : : exists ( savePathTxt - > currentText ( ) ) ) {
TorrentTempData : : setSeedingMode ( hash , true ) ;
if ( m_isM agnet | | QFile : : exists ( savePathTxt - > currentText ( ) ) ) {
TorrentTempData : : setSeedingMode ( m_ hash, true ) ;
} else {
QMessageBox : : warning ( 0 , tr ( " Seeding mode error " ) , tr ( " You chose to skip file checking. However, local files do not seem to exist in the current destionation folder. Please disable this feature or update the save path. " ) ) ;
return ;
}
}
// Check if there is at least one selected file
if ( ! is_m agnet & & t - > num_files ( ) > 1 & & allFiltered ( ) ) {
if ( ! m_isM agnet & & m_ torrentInfo - > num_files ( ) > 1 & & allFiltered ( ) ) {
QMessageBox : : warning ( 0 , tr ( " Invalid file selection " ) , tr ( " You must select at least one file in the torrent " ) ) ;
return ;
}
@ -693,14 +688,14 @@ void torrentAdditionDialog::on_OkButton_clicked() {
@@ -693,14 +688,14 @@ void torrentAdditionDialog::on_OkButton_clicked() {
}
// save filtered files
if ( ! is_m agnet & & t - > num_files ( ) > 1 )
if ( ! m_isM agnet & & m_ torrentInfo - > num_files ( ) > 1 )
savePiecesPriorities ( ) ;
// Add to download list
QTorrentHandle h ;
if ( is_m agnet)
h = QBtSession : : instance ( ) - > addMagnetUri ( from_u rl, false ) ;
if ( m_isM agnet)
h = QBtSession : : instance ( ) - > addMagnetUri ( m_fromU rl, false ) ;
else
h = QBtSession : : instance ( ) - > addTorrent ( filePath , false , from_u rl) ;
h = QBtSession : : instance ( ) - > addTorrent ( m_ filePath, false , m_fromU rl) ;
if ( addInPause - > isChecked ( ) & & h . is_valid ( ) ) {
h . pause ( ) ;
}
@ -719,30 +714,30 @@ void torrentAdditionDialog::resetComboLabelIndex(QString text) {
@@ -719,30 +714,30 @@ void torrentAdditionDialog::resetComboLabelIndex(QString text) {
}
void torrentAdditionDialog : : updateLabelInSavePath ( QString label ) {
if ( appendLabelToSavePath ) {
if ( m_ appendLabelToSavePath) {
// Update Label in combobox
savePathTxt - > setItemText ( 0 , misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > itemText ( 0 ) , old_l abel, label ) ) ;
savePathTxt - > setItemText ( 0 , misc : : updateLabelInSavePath ( m_ defaultSavePath, savePathTxt - > itemText ( 0 ) , m_oldL abel, label ) ) ;
// update edit text
savePathTxt - > setEditText ( misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > currentText ( ) , old_l abel, label ) ) ;
old_l abel = label ;
savePathTxt - > setEditText ( misc : : updateLabelInSavePath ( m_ defaultSavePath, savePathTxt - > currentText ( ) , m_oldL abel, label ) ) ;
m_oldL abel = label ;
}
}
void torrentAdditionDialog : : updateSavePathCurrentText ( ) {
qDebug ( " updateSavePathCurrentText() - ENTER " ) ;
savePathTxt - > setItemText ( savePathTxt - > currentIndex ( ) , savePathTxt - > currentText ( ) ) ;
qDebug ( " path_history.size() == %d " , path_h istory. size ( ) ) ;
qDebug ( " path_history.size() == %d " , m_pathH istory. size ( ) ) ;
qDebug ( " savePathTxt->currentIndex() == %d " , savePathTxt - > currentIndex ( ) ) ;
path_h istory. replace ( savePathTxt - > currentIndex ( ) , getCurrentTruncatedSavePath ( ) ) ;
m_pathH istory. replace ( savePathTxt - > currentIndex ( ) , getCurrentTruncatedSavePath ( ) ) ;
QString root_folder_or_file_name = " " ;
getCurrentTruncatedSavePath ( & root_folder_or_file_name ) ;
// Update other combo items
for ( int i = 0 ; i < savePathTxt - > count ( ) ; + + i ) {
if ( i = = savePathTxt - > currentIndex ( ) ) continue ;
QString item_path = path_h istory. at ( i ) ;
QString item_path = m_pathH istory. at ( i ) ;
if ( item_path . isEmpty ( ) ) continue ;
// Append label
if ( i = = 0 & & appendLabelToSavePath & & QDir ( item_path ) = = QDir ( defaultSavePath ) & & ! comboLabel - > currentText ( ) . isEmpty ( ) )
if ( i = = 0 & & m_ appendLabelToSavePath & & QDir ( item_path ) = = QDir ( m_ defaultSavePath) & & ! comboLabel - > currentText ( ) . isEmpty ( ) )
item_path + = comboLabel - > currentText ( ) + " / " ;
// Append root_folder or filename
if ( ! root_folder_or_file_name . isEmpty ( ) )
@ -765,13 +760,13 @@ QString torrentAdditionDialog::getTruncatedSavePath(QString save_path, QString*
@@ -765,13 +760,13 @@ QString torrentAdditionDialog::getTruncatedSavePath(QString save_path, QString*
save_path = misc : : expandPath ( save_path ) ;
QStringList parts = save_path . replace ( " \\ " , " / " ) . split ( " / " ) ;
// Remove torrent root folder
if ( ! QDir ( save_path ) . exists ( ) | | ( ! is_m agnet & & t - > num_files ( ) = = 1 ) ) {
if ( ! QDir ( save_path ) . exists ( ) | | ( ! m_isM agnet & & m_ torrentInfo - > num_files ( ) = = 1 ) ) {
QString tmp = parts . takeLast ( ) ;
if ( root_folder_or_file_name )
* root_folder_or_file_name = tmp ;
}
// Remove label
if ( appendLabelToSavePath & & savePathTxt - > currentIndex ( ) = = 0 & & parts . last ( ) = = comboLabel - > currentText ( ) ) {
if ( m_ appendLabelToSavePath & & savePathTxt - > currentIndex ( ) = = 0 & & parts . last ( ) = = comboLabel - > currentText ( ) ) {
parts . removeLast ( ) ;
}
QString truncated_path = parts . join ( " / " ) ;
@ -806,12 +801,12 @@ void torrentAdditionDialog::loadSavePathHistory() {
@@ -806,12 +801,12 @@ void torrentAdditionDialog::loadSavePathHistory() {
// Load save path history
QStringList raw_path_history = settings . value ( " TorrentAdditionDlg/save_path_history " ) . toStringList ( ) ;
foreach ( const QString & sp , raw_path_history ) {
if ( QDir ( sp ) ! = QDir ( defaultSavePath ) ) {
if ( QDir ( sp ) ! = QDir ( m_ defaultSavePath) ) {
QString dsp = sp ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dsp . replace ( " / " , " \\ " ) ;
# endif
path_h istory < < sp ;
m_pathH istory < < sp ;
savePathTxt - > addItem ( dsp ) ;
}
}