@ -252,6 +252,9 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
close ( ) ;
close ( ) ;
return ;
return ;
}
}
# if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t - > files ( ) ;
# endif
// Truncate root folder
// Truncate root folder
QString root_folder = misc : : truncateRootFolder ( t ) ;
QString root_folder = misc : : truncateRootFolder ( t ) ;
// Setting file name
// Setting file name
@ -271,8 +274,13 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
connect ( PropDelegate , SIGNAL ( filteredFilesChanged ( ) ) , this , SLOT ( updateDiskSpaceLabels ( ) ) ) ;
connect ( PropDelegate , SIGNAL ( filteredFilesChanged ( ) ) , this , SLOT ( updateDiskSpaceLabels ( ) ) ) ;
// Loads files path in the torrent
// Loads files path in the torrent
for ( uint i = 0 ; i < nbFiles ; + + i ) {
for ( uint i = 0 ; i < nbFiles ; + + i ) {
# if LIBTORRENT_VERSION_MINOR >= 16
files_path < < misc : : toQStringU ( fs . file_path ( t - > file_at ( i ) ) ) ;
# else
files_path < < misc : : toQStringU ( t - > file_at ( i ) . path . string ( ) ) ;
files_path < < misc : : toQStringU ( t - > file_at ( i ) . path . string ( ) ) ;
# endif
}
}
}
}
// Load save path history
// Load save path history
@ -298,7 +306,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
}
}
if ( nbFiles = = 1 ) {
if ( nbFiles = = 1 ) {
// single file torrent
// single file torrent
# if LIBTORRENT_VERSION_MINOR >= 16
QString single_file_relpath = misc : : toQStringU ( fs . file_path ( t - > file_at ( 0 ) ) ) ;
# else
QString single_file_relpath = misc : : toQStringU ( t - > file_at ( 0 ) . path . string ( ) ) ;
QString single_file_relpath = misc : : toQStringU ( t - > file_at ( 0 ) . path . string ( ) ) ;
# endif
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
single_file_relpath = single_file_relpath . replace ( " / " , " \\ " ) ;
single_file_relpath = single_file_relpath . replace ( " / " , " \\ " ) ;
# endif
# endif
@ -402,366 +414,372 @@ void torrentAdditionDialog::renameSelectedFile() {
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if ( files_path . at ( i ) . compare ( new_name , Qt : : CaseSensitive ) = = 0 ) {
if ( files_path . at ( i ) . compare ( new_name , Qt : : CaseSensitive ) = = 0 ) {
# else
# else
if ( files_path . at ( i ) . compare ( new_name , Qt : : CaseInsensitive ) = = 0 ) {
if ( files_path . at ( i ) . compare ( new_name , Qt : : CaseInsensitive ) = = 0 ) {
# endif
# endif
// Display error message
// Display error message
QMessageBox : : warning ( this , tr ( " The file could not be renamed " ) ,
QMessageBox : : warning ( this , tr ( " The file could not be renamed " ) ,
tr ( " This name is already in use in this folder. Please use a different name. " ) ,
tr ( " This name is already in use in this folder. Please use a different name. " ) ,
QMessageBox : : Ok ) ;
QMessageBox : : Ok ) ;
return ;
return ;
}
}
new_name = QDir : : cleanPath ( new_name ) ;
qDebug ( " Renaming %s to %s " , qPrintable ( old_name ) , qPrintable ( new_name ) ) ;
// Rename file in files_path
files_path . replace ( file_index , new_name ) ;
// Rename in torrent files model too
PropListModel - > setData ( index , new_name_last ) ;
} else {
// Folder renaming
QStringList path_items ;
path_items < < index . data ( ) . toString ( ) ;
QModelIndex parent = PropListModel - > parent ( index ) ;
while ( parent . isValid ( ) ) {
path_items . prepend ( parent . data ( ) . toString ( ) ) ;
parent = PropListModel - > parent ( parent ) ;
}
}
const QString old_path = path_items . join ( " / " ) ;
}
path_items . removeLast ( ) ;
new_name = QDir : : cleanPath ( new_name ) ;
path_items < < new_name_last ;
qDebug ( " Renaming %s to %s " , qPrintable ( old_name ) , qPrintable ( new_name ) ) ;
QString new_path = path_items . join ( " / " ) ;
// Rename file in files_path
if ( ! new_path . endsWith ( " / " ) ) new_path + = " / " ;
files_path . replace ( file_index , new_name ) ;
// Check for overwriting
// Rename in torrent files model too
for ( uint i = 0 ; i < nbFiles ; + + i ) {
PropListModel - > setData ( index , new_name_last ) ;
const QString & current_name = files_path . at ( i ) ;
} else {
// Folder renaming
QStringList path_items ;
path_items < < index . data ( ) . toString ( ) ;
QModelIndex parent = PropListModel - > parent ( index ) ;
while ( parent . isValid ( ) ) {
path_items . prepend ( parent . data ( ) . toString ( ) ) ;
parent = PropListModel - > parent ( parent ) ;
}
const QString old_path = path_items . join ( " / " ) ;
path_items . removeLast ( ) ;
path_items < < new_name_last ;
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_path . at ( i ) ;
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if ( current_name . startsWith ( new_path , Qt : : CaseSensitive ) ) {
if ( current_name . startsWith ( new_path , Qt : : CaseSensitive ) ) {
# else
# else
if ( current_name . startsWith ( new_path , Qt : : CaseInsensitive ) ) {
if ( current_name . startsWith ( new_path , Qt : : CaseInsensitive ) ) {
# endif
# endif
QMessageBox : : warning ( this , tr ( " The folder could not be renamed " ) ,
QMessageBox : : warning ( this , tr ( " The folder could not be renamed " ) ,
tr ( " This name is already in use in this folder. Please use a different name. " ) ,
tr ( " This name is already in use in this folder. Please use a different name. " ) ,
QMessageBox : : Ok ) ;
QMessageBox : : Ok ) ;
return ;
return ;
}
}
}
}
// Replace path in all files
// Replace path in all files
for ( uint i = 0 ; i < nbFiles ; + + i ) {
for ( uint i = 0 ; i < nbFiles ; + + i ) {
const QString & current_name = files_path . at ( i ) ;
const QString & current_name = files_path . at ( i ) ;
if ( current_name . startsWith ( old_path ) ) {
if ( current_name . startsWith ( old_path ) ) {
QString new_name = current_name ;
QString new_name = current_name ;
new_name . replace ( 0 , old_path . length ( ) , new_path ) ;
new_name . replace ( 0 , old_path . length ( ) , new_path ) ;
new_name = QDir : : cleanPath ( new_name ) ;
new_name = QDir : : cleanPath ( new_name ) ;
qDebug ( " Rename %s to %s " , qPrintable ( current_name ) , qPrintable ( new_name ) ) ;
qDebug ( " Rename %s to %s " , qPrintable ( current_name ) , qPrintable ( new_name ) ) ;
// Rename in files_path
// Rename in files_path
files_path . replace ( i , new_name ) ;
files_path . replace ( i , new_name ) ;
}
}
// Rename folder in torrent files model too
PropListModel - > setData ( index , new_name_last ) ;
}
}
}
}
// Rename folder in torrent files model too
PropListModel - > setData ( index , new_name_last ) ;
}
}
}
}
void torrentAdditionDialog : : updateDiskSpaceLabels ( ) {
void torrentAdditionDialog : : updateDiskSpaceLabels ( ) {
qDebug ( " Updating disk space label... " ) ;
qDebug ( " Updating disk space label... " ) ;
const long long available = misc : : freeDiskSpaceOnPath ( misc : : expandPath ( savePathTxt - > currentText ( ) ) ) ;
const long long available = misc : : freeDiskSpaceOnPath ( misc : : expandPath ( savePathTxt - > currentText ( ) ) ) ;
lbl_disk_space - > setText ( misc : : friendlyUnit ( available ) ) ;
lbl_disk_space - > setText ( misc : : friendlyUnit ( available ) ) ;
if ( ! is_magnet ) {
if ( ! is_magnet ) {
// Determine torrent size
// Determine torrent size
qulonglong torrent_size = 0 ;
qulonglong torrent_size = 0 ;
if ( t - > num_files ( ) > 1 ) {
if ( t - > num_files ( ) > 1 ) {
const unsigned int nbFiles = t - > num_files ( ) ;
const unsigned int nbFiles = t - > num_files ( ) ;
const std : : vector < int > priorities = PropListModel - > getFilesPriorities ( nbFiles ) ;
const std : : vector < int > priorities = PropListModel - > getFilesPriorities ( nbFiles ) ;
for ( unsigned int i = 0 ; i < nbFiles ; + + i ) {
for ( unsigned int i = 0 ; i < nbFiles ; + + i ) {
if ( priorities [ i ] > 0 )
if ( priorities [ i ] > 0 )
torrent_size + = t - > file_at ( i ) . size ;
torrent_size + = t - > file_at ( i ) . size ;
}
} else {
torrent_size = t - > total_size ( ) ;
}
lbl_torrent_size - > setText ( misc : : friendlyUnit ( torrent_size ) ) ;
// Check if free space is sufficient
if ( available > 0 ) {
if ( ( unsigned long long ) available > torrent_size ) {
// 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> " ) ;
}
} else {
// Available disk space is unknown
label_space_msg - > setText ( " " ) ;
}
}
}
} else {
torrent_size = t - > total_size ( ) ;
}
}
lbl_torrent_size - > setText ( misc : : friendlyUnit ( torrent_size ) ) ;
void torrentAdditionDialog : : on_browseButton_clicked ( ) {
// Check if free space is sufficient
Q_ASSERT ( ! is_magnet ) ;
if ( available > 0 ) {
QString new_path ;
if ( ( unsigned long long ) available > torrent_size ) {
if ( t - > num_files ( ) = = 1 ) {
// Space is sufficient
new_path = QFileDialog : : getSaveFileName ( this , tr ( " Choose save path " ) , savePathTxt - > currentText ( ) ) ;
label_space_msg - > setText ( tr ( " (%1 left after torrent download) " , " e.g. (100MiB left after torrent download) " ) . arg ( misc : : friendlyUnit ( available - torrent_size ) ) ) ;
} else {
} else {
QString root_folder ;
// Space is unsufficient
QString truncated_path = getCurrentTruncatedSavePath ( & root_folder ) ;
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> " ) ;
if ( ! truncated_path . isEmpty ( ) & & QDir ( truncated_path ) . exists ( ) ) {
new_path = QFileDialog : : getExistingDirectory ( this , tr ( " Choose save path " ) , truncated_path ) ;
} else {
new_path = QFileDialog : : getExistingDirectory ( this , tr ( " Choose save path " ) , QDir : : homePath ( ) ) ;
}
if ( ! new_path . isEmpty ( ) ) {
QStringList path_parts = new_path . replace ( " \\ " , " / " ) . split ( " / " ) ;
if ( path_parts . last ( ) . isEmpty ( ) )
path_parts . removeLast ( ) ;
// Append label
const QString label_name = comboLabel - > currentText ( ) ;
if ( QDir ( new_path ) = = QDir ( defaultSavePath ) & & ! label_name . isEmpty ( ) )
path_parts < < label_name ;
// Append root folder
if ( ! root_folder . isEmpty ( ) )
path_parts < < root_folder ;
// Construct new_path
new_path = path_parts . join ( QDir : : separator ( ) ) ;
}
}
}
if ( ! new_path . isEmpty ( ) ) {
} else {
// Check if this new path already exists in the list
// Available disk space is unknown
QString new_truncated_path = getTruncatedSavePath ( new_path ) ;
label_space_msg - > setText ( " " ) ;
}
}
}
void torrentAdditionDialog : : on_browseButton_clicked ( ) {
Q_ASSERT ( ! is_magnet ) ;
QString new_path ;
if ( t - > num_files ( ) = = 1 ) {
new_path = QFileDialog : : getSaveFileName ( this , tr ( " Choose save path " ) , savePathTxt - > currentText ( ) ) ;
} else {
QString root_folder ;
QString truncated_path = getCurrentTruncatedSavePath ( & root_folder ) ;
if ( ! truncated_path . isEmpty ( ) & & QDir ( truncated_path ) . exists ( ) ) {
new_path = QFileDialog : : getExistingDirectory ( this , tr ( " Choose save path " ) , truncated_path ) ;
} else {
new_path = QFileDialog : : getExistingDirectory ( this , tr ( " Choose save path " ) , QDir : : homePath ( ) ) ;
}
if ( ! new_path . isEmpty ( ) ) {
QStringList path_parts = new_path . replace ( " \\ " , " / " ) . split ( " / " ) ;
if ( path_parts . last ( ) . isEmpty ( ) )
path_parts . removeLast ( ) ;
// Append label
const QString label_name = comboLabel - > currentText ( ) ;
if ( QDir ( new_path ) = = QDir ( defaultSavePath ) & & ! label_name . isEmpty ( ) )
path_parts < < label_name ;
// Append root folder
if ( ! root_folder . isEmpty ( ) )
path_parts < < root_folder ;
// Construct new_path
new_path = path_parts . join ( QDir : : separator ( ) ) ;
}
}
if ( ! new_path . isEmpty ( ) ) {
// 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)
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
const int cur_index = path_history . indexOf ( QRegExp ( new_truncated_path , Qt : : CaseInsensitive ) ) ;
const int cur_index = path_history . indexOf ( QRegExp ( new_truncated_path , Qt : : CaseInsensitive ) ) ;
# else
# else
const int cur_index = path_history . indexOf ( QRegExp ( new_truncated_path , Qt : : CaseSensitive ) ) ;
const int cur_index = path_history . indexOf ( QRegExp ( new_truncated_path , Qt : : CaseSensitive ) ) ;
# endif
# endif
if ( cur_index > = 0 ) {
if ( cur_index > = 0 ) {
savePathTxt - > setCurrentIndex ( cur_index ) ;
savePathTxt - > setCurrentIndex ( cur_index ) ;
}
}
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
new_path = new_path . replace ( " / " , " \\ " ) ;
new_path = new_path . replace ( " / " , " \\ " ) ;
# endif
# endif
savePathTxt - > setEditText ( new_path ) ;
savePathTxt - > setEditText ( new_path ) ;
}
}
}
}
void torrentAdditionDialog : : on_CancelButton_clicked ( ) {
void torrentAdditionDialog : : on_CancelButton_clicked ( ) {
close ( ) ;
close ( ) ;
}
}
bool torrentAdditionDialog : : allFiltered ( ) const {
bool torrentAdditionDialog : : allFiltered ( ) const {
Q_ASSERT ( ! is_magnet ) ;
Q_ASSERT ( ! is_magnet ) ;
return PropListModel - > allFiltered ( ) ;
return PropListModel - > allFiltered ( ) ;
}
}
void torrentAdditionDialog : : savePiecesPriorities ( ) {
void torrentAdditionDialog : : savePiecesPriorities ( ) {
qDebug ( " Saving pieces priorities " ) ;
qDebug ( " Saving pieces priorities " ) ;
Q_ASSERT ( ! is_magnet ) ;
Q_ASSERT ( ! is_magnet ) ;
const std : : vector < int > priorities = PropListModel - > getFilesPriorities ( t - > num_files ( ) ) ;
const std : : vector < int > priorities = PropListModel - > getFilesPriorities ( t - > num_files ( ) ) ;
TorrentTempData : : setFilesPriority ( hash , priorities ) ;
TorrentTempData : : setFilesPriority ( hash , priorities ) ;
}
}
void torrentAdditionDialog : : on_OkButton_clicked ( ) {
void torrentAdditionDialog : : on_OkButton_clicked ( ) {
qDebug ( ) < < " void torrentAdditionDialog::on_OkButton_clicked() - ENTER " ;
qDebug ( ) < < " void torrentAdditionDialog::on_OkButton_clicked() - ENTER " ;
if ( savePathTxt - > currentText ( ) . trimmed ( ) . isEmpty ( ) ) {
if ( savePathTxt - > currentText ( ) . trimmed ( ) . isEmpty ( ) ) {
QMessageBox : : critical ( 0 , tr ( " Empty save path " ) , tr ( " Please enter a save path " ) ) ;
QMessageBox : : critical ( 0 , tr ( " Empty save path " ) , tr ( " Please enter a save path " ) ) ;
return ;
return ;
}
}
QString save_path = savePathTxt - > currentText ( ) ;
QString save_path = savePathTxt - > currentText ( ) ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path . replace ( " \\ " , " / " ) ;
save_path = save_path . replace ( " \\ " , " / " ) ;
# endif
save_path = misc : : expandPath ( save_path ) ;
qDebug ( " Save path is %s " , qPrintable ( save_path ) ) ;
if ( ! is_magnet & & t - > num_files ( ) = = 1 ) {
// Remove file name
QStringList parts = save_path . split ( " / " ) ;
const QString single_file_name = parts . takeLast ( ) ;
Q_ASSERT ( files_path . isEmpty ( ) ) ;
files_path < < single_file_name ;
save_path = parts . join ( " / " ) ;
}
qDebug ( " Save path dir is %s " , qPrintable ( save_path ) ) ;
QDir savePath ( save_path ) ;
const QString current_label = comboLabel - > currentText ( ) . trimmed ( ) ;
if ( ! current_label . isEmpty ( ) & & ! misc : : isValidFileSystemName ( current_label ) ) {
QMessageBox : : warning ( this , tr ( " Invalid label name " ) , tr ( " Please don't use any special characters in the label name. " ) ) ;
return ;
}
// Save savepath
qDebug ( " Saving save path to temp data: %s " , qPrintable ( savePath . absolutePath ( ) ) ) ;
TorrentTempData : : setSavePath ( hash , savePath . absolutePath ( ) ) ;
qDebug ( " Torrent label is: %s " , qPrintable ( comboLabel - > currentText ( ) . trimmed ( ) ) ) ;
if ( ! current_label . isEmpty ( ) )
TorrentTempData : : setLabel ( hash , current_label ) ;
// Is download sequential?
TorrentTempData : : setSequential ( hash , checkIncrementalDL - > isChecked ( ) ) ;
// Save files path
// Loads files path in the torrent
if ( ! is_magnet ) {
bool path_changed = false ;
for ( uint i = 0 ; i < nbFiles ; + + i ) {
# if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t - > files ( ) ;
QString old_path = misc : : toQStringU ( fs . file_path ( t - > file_at ( i ) ) ) ;
# else
QString old_path = misc : : toQStringU ( t - > file_at ( i ) . path . string ( ) ) ;
# endif
# endif
save_path = misc : : expandPath ( save_path ) ;
qDebug ( " Save path is %s " , qPrintable ( save_path ) ) ;
if ( ! is_magnet & & t - > num_files ( ) = = 1 ) {
// Remove file name
QStringList parts = save_path . split ( " / " ) ;
const QString single_file_name = parts . takeLast ( ) ;
Q_ASSERT ( files_path . isEmpty ( ) ) ;
files_path < < single_file_name ;
save_path = parts . join ( " / " ) ;
}
qDebug ( " Save path dir is %s " , qPrintable ( save_path ) ) ;
QDir savePath ( save_path ) ;
const QString current_label = comboLabel - > currentText ( ) . trimmed ( ) ;
if ( ! current_label . isEmpty ( ) & & ! misc : : isValidFileSystemName ( current_label ) ) {
QMessageBox : : warning ( this , tr ( " Invalid label name " ) , tr ( " Please don't use any special characters in the label name. " ) ) ;
return ;
}
// Save savepath
qDebug ( " Saving save path to temp data: %s " , qPrintable ( savePath . absolutePath ( ) ) ) ;
TorrentTempData : : setSavePath ( hash , savePath . absolutePath ( ) ) ;
qDebug ( " Torrent label is: %s " , qPrintable ( comboLabel - > currentText ( ) . trimmed ( ) ) ) ;
if ( ! current_label . isEmpty ( ) )
TorrentTempData : : setLabel ( hash , current_label ) ;
// Is download sequential?
TorrentTempData : : setSequential ( hash , checkIncrementalDL - > isChecked ( ) ) ;
// Save files path
// Loads files path in the torrent
if ( ! is_magnet ) {
bool path_changed = false ;
for ( uint i = 0 ; i < nbFiles ; + + i ) {
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if ( files_path . at ( i ) . compare ( misc : : toQStringU ( t - > file_at ( i ) . path . string ( ) ) , Qt : : CaseSensitive ) ! = 0 ) {
if ( files_path . at ( i ) . compare ( old_path , Qt : : CaseSensitive ) ! = 0 ) {
# else
# else
if ( files_path . at ( i ) . compare ( misc : : toQStringU ( t - > file_at ( i ) . path . string ( ) ) , Qt : : CaseInsensitive ) ! = 0 ) {
if ( files_path . at ( i ) . compare ( old_path , Qt : : CaseInsensitive ) ! = 0 ) {
# endif
# endif
path_changed = true ;
path_changed = true ;
break ;
break ;
}
}
}
}
if ( path_changed ) {
if ( path_changed ) {
qDebug ( " Changing files paths " ) ;
qDebug ( " Changing files paths " ) ;
TorrentTempData : : setFilesPath ( hash , files_path ) ;
TorrentTempData : : setFilesPath ( hash , files_path ) ;
}
}
}
}
# if LIBTORRENT_VERSION_MINOR > 14
# if LIBTORRENT_VERSION_MINOR > 14
// Skip file checking and directly start seeding
// Skip file checking and directly start seeding
if ( addInSeed - > isChecked ( ) ) {
if ( addInSeed - > isChecked ( ) ) {
// Check if local file(s) actually exist
// Check if local file(s) actually exist
if ( is_magnet | | QFile : : exists ( savePathTxt - > currentText ( ) ) ) {
if ( is_magnet | | QFile : : exists ( savePathTxt - > currentText ( ) ) ) {
TorrentTempData : : setSeedingMode ( hash , true ) ;
TorrentTempData : : setSeedingMode ( hash , true ) ;
} else {
} 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. " ) ) ;
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 ;
return ;
}
}
}
}
# endif
# endif
// Check if there is at least one selected file
// Check if there is at least one selected file
if ( ! is_magnet & & t - > num_files ( ) > 1 & & allFiltered ( ) ) {
if ( ! is_magnet & & t - > num_files ( ) > 1 & & allFiltered ( ) ) {
QMessageBox : : warning ( 0 , tr ( " Invalid file selection " ) , tr ( " You must select at least one file in the torrent " ) ) ;
QMessageBox : : warning ( 0 , tr ( " Invalid file selection " ) , tr ( " You must select at least one file in the torrent " ) ) ;
return ;
return ;
}
}
// Save path history
// Save path history
saveTruncatedPathHistory ( ) ;
saveTruncatedPathHistory ( ) ;
// Check if savePath exists
// Check if savePath exists
if ( ! savePath . exists ( ) ) {
if ( ! savePath . exists ( ) ) {
if ( ! savePath . mkpath ( savePath . path ( ) ) ) {
if ( ! savePath . mkpath ( savePath . path ( ) ) ) {
QMessageBox : : critical ( 0 , tr ( " Save path creation error " ) , tr ( " Could not create the save path " ) ) ;
QMessageBox : : critical ( 0 , tr ( " Save path creation error " ) , tr ( " Could not create the save path " ) ) ;
return ;
return ;
}
}
}
}
// save filtered files
// save filtered files
if ( ! is_magnet & & t - > num_files ( ) > 1 )
if ( ! is_magnet & & t - > num_files ( ) > 1 )
savePiecesPriorities ( ) ;
savePiecesPriorities ( ) ;
// Add to download list
// Add to download list
QTorrentHandle h ;
QTorrentHandle h ;
if ( is_magnet )
if ( is_magnet )
h = QBtSession : : instance ( ) - > addMagnetUri ( from_url , false ) ;
h = QBtSession : : instance ( ) - > addMagnetUri ( from_url , false ) ;
else
else
h = QBtSession : : instance ( ) - > addTorrent ( filePath , false , from_url ) ;
h = QBtSession : : instance ( ) - > addTorrent ( filePath , false , from_url ) ;
if ( addInPause - > isChecked ( ) & & h . is_valid ( ) ) {
if ( addInPause - > isChecked ( ) & & h . is_valid ( ) ) {
h . pause ( ) ;
h . pause ( ) ;
}
}
// Close the dialog
// Close the dialog
qDebug ( " Closing torrent addition dialog... " ) ;
qDebug ( " Closing torrent addition dialog... " ) ;
close ( ) ;
close ( ) ;
qDebug ( " Closed " ) ;
qDebug ( " Closed " ) ;
}
}
void torrentAdditionDialog : : resetComboLabelIndex ( QString text ) {
void torrentAdditionDialog : : resetComboLabelIndex ( QString text ) {
// Select first index
// Select first index
if ( text ! = comboLabel - > itemText ( comboLabel - > currentIndex ( ) ) ) {
if ( text ! = comboLabel - > itemText ( comboLabel - > currentIndex ( ) ) ) {
comboLabel - > setItemText ( 0 , text ) ;
comboLabel - > setItemText ( 0 , text ) ;
comboLabel - > setCurrentIndex ( 0 ) ;
comboLabel - > setCurrentIndex ( 0 ) ;
}
}
}
}
void torrentAdditionDialog : : updateLabelInSavePath ( QString label ) {
void torrentAdditionDialog : : updateLabelInSavePath ( QString label ) {
if ( appendLabelToSavePath ) {
if ( appendLabelToSavePath ) {
// Update Label in combobox
// Update Label in combobox
savePathTxt - > setItemText ( 0 , misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > itemText ( 0 ) , old_label , label ) ) ;
savePathTxt - > setItemText ( 0 , misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > itemText ( 0 ) , old_label , label ) ) ;
// update edit text
// update edit text
savePathTxt - > setEditText ( misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > currentText ( ) , old_label , label ) ) ;
savePathTxt - > setEditText ( misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > currentText ( ) , old_label , label ) ) ;
old_label = label ;
old_label = label ;
}
}
}
}
void torrentAdditionDialog : : updateSavePathCurrentText ( ) {
void torrentAdditionDialog : : updateSavePathCurrentText ( ) {
qDebug ( " updateSavePathCurrentText() - ENTER " ) ;
qDebug ( " updateSavePathCurrentText() - ENTER " ) ;
savePathTxt - > setItemText ( savePathTxt - > currentIndex ( ) , savePathTxt - > currentText ( ) ) ;
savePathTxt - > setItemText ( savePathTxt - > currentIndex ( ) , savePathTxt - > currentText ( ) ) ;
qDebug ( " path_history.size() == %d " , path_history . size ( ) ) ;
qDebug ( " path_history.size() == %d " , path_history . size ( ) ) ;
qDebug ( " savePathTxt->currentIndex() == %d " , savePathTxt - > currentIndex ( ) ) ;
qDebug ( " savePathTxt->currentIndex() == %d " , savePathTxt - > currentIndex ( ) ) ;
path_history . replace ( savePathTxt - > currentIndex ( ) , getCurrentTruncatedSavePath ( ) ) ;
path_history . replace ( savePathTxt - > currentIndex ( ) , getCurrentTruncatedSavePath ( ) ) ;
QString root_folder_or_file_name = " " ;
QString root_folder_or_file_name = " " ;
getCurrentTruncatedSavePath ( & root_folder_or_file_name ) ;
getCurrentTruncatedSavePath ( & root_folder_or_file_name ) ;
// Update other combo items
// Update other combo items
for ( int i = 0 ; i < savePathTxt - > count ( ) ; + + i ) {
for ( int i = 0 ; i < savePathTxt - > count ( ) ; + + i ) {
if ( i = = savePathTxt - > currentIndex ( ) ) continue ;
if ( i = = savePathTxt - > currentIndex ( ) ) continue ;
QString item_path = path_history . at ( i ) ;
QString item_path = path_history . at ( i ) ;
if ( item_path . isEmpty ( ) ) continue ;
if ( item_path . isEmpty ( ) ) continue ;
// Append label
// Append label
if ( i = = 0 & & appendLabelToSavePath & & QDir ( item_path ) = = QDir ( defaultSavePath ) & & ! comboLabel - > currentText ( ) . isEmpty ( ) )
if ( i = = 0 & & appendLabelToSavePath & & QDir ( item_path ) = = QDir ( defaultSavePath ) & & ! comboLabel - > currentText ( ) . isEmpty ( ) )
item_path + = comboLabel - > currentText ( ) + " / " ;
item_path + = comboLabel - > currentText ( ) + " / " ;
// Append root_folder or filename
// Append root_folder or filename
if ( ! root_folder_or_file_name . isEmpty ( ) )
if ( ! root_folder_or_file_name . isEmpty ( ) )
item_path + = root_folder_or_file_name ;
item_path + = root_folder_or_file_name ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
item_path = item_path . replace ( " / " , " \\ " ) ;
item_path = item_path . replace ( " / " , " \\ " ) ;
# endif
# endif
savePathTxt - > setItemText ( i , item_path ) ;
savePathTxt - > setItemText ( i , item_path ) ;
}
}
}
}
QString torrentAdditionDialog : : getCurrentTruncatedSavePath ( QString * root_folder_or_file_name ) const {
QString torrentAdditionDialog : : getCurrentTruncatedSavePath ( QString * root_folder_or_file_name ) const {
QString save_path = savePathTxt - > currentText ( ) ;
QString save_path = savePathTxt - > currentText ( ) ;
return getTruncatedSavePath ( save_path , root_folder_or_file_name ) ;
return getTruncatedSavePath ( save_path , root_folder_or_file_name ) ;
}
}
// Get current save path without the torrent root folder nor the label label
// Get current save path without the torrent root folder nor the label label
QString torrentAdditionDialog : : getTruncatedSavePath ( QString save_path , QString * root_folder_or_file_name ) const {
QString torrentAdditionDialog : : getTruncatedSavePath ( QString save_path , QString * root_folder_or_file_name ) const {
// Expand and clean path (~, .., .)
// Expand and clean path (~, .., .)
save_path = misc : : expandPath ( save_path ) ;
save_path = misc : : expandPath ( save_path ) ;
QStringList parts = save_path . replace ( " \\ " , " / " ) . split ( " / " ) ;
QStringList parts = save_path . replace ( " \\ " , " / " ) . split ( " / " ) ;
// Remove torrent root folder
// Remove torrent root folder
if ( ! QDir ( save_path ) . exists ( ) | | ( ! is_magnet & & t - > num_files ( ) = = 1 ) ) {
if ( ! QDir ( save_path ) . exists ( ) | | ( ! is_magnet & & t - > num_files ( ) = = 1 ) ) {
QString tmp = parts . takeLast ( ) ;
QString tmp = parts . takeLast ( ) ;
if ( root_folder_or_file_name )
if ( root_folder_or_file_name )
* root_folder_or_file_name = tmp ;
* root_folder_or_file_name = tmp ;
}
}
// Remove label
// Remove label
if ( appendLabelToSavePath & & savePathTxt - > currentIndex ( ) = = 0 & & parts . last ( ) = = comboLabel - > currentText ( ) ) {
if ( appendLabelToSavePath & & savePathTxt - > currentIndex ( ) = = 0 & & parts . last ( ) = = comboLabel - > currentText ( ) ) {
parts . removeLast ( ) ;
parts . removeLast ( ) ;
}
}
QString truncated_path = parts . join ( " / " ) ;
QString truncated_path = parts . join ( " / " ) ;
if ( ! truncated_path . endsWith ( " / " ) )
if ( ! truncated_path . endsWith ( " / " ) )
truncated_path + = " / " ;
truncated_path + = " / " ;
qDebug ( " Truncated save path: %s " , qPrintable ( truncated_path ) ) ;
qDebug ( " Truncated save path: %s " , qPrintable ( truncated_path ) ) ;
return truncated_path ;
return truncated_path ;
}
}
void torrentAdditionDialog : : saveTruncatedPathHistory ( ) {
void torrentAdditionDialog : : saveTruncatedPathHistory ( ) {
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
const QString current_save_path = getCurrentTruncatedSavePath ( ) ;
const QString current_save_path = getCurrentTruncatedSavePath ( ) ;
// Get current history
// Get current history
QStringList history = settings . value ( " TorrentAdditionDlg/save_path_history " ) . toStringList ( ) ;
QStringList history = settings . value ( " TorrentAdditionDlg/save_path_history " ) . toStringList ( ) ;
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if ( ! history . contains ( current_save_path , Qt : : CaseSensitive ) ) {
if ( ! history . contains ( current_save_path , Qt : : CaseSensitive ) ) {
# else
# else
if ( ! history . contains ( current_save_path , Qt : : CaseInsensitive ) ) {
if ( ! history . contains ( current_save_path , Qt : : CaseInsensitive ) ) {
# endif
# endif
// Add save path to history
// Add save path to history
history < < current_save_path ;
history < < current_save_path ;
// Limit list size
// Limit list size
if ( history . size ( ) > 8 )
if ( history . size ( ) > 8 )
history . removeFirst ( ) ;
history . removeFirst ( ) ;
// Save history
// Save history
settings . setValue ( " TorrentAdditionDlg/save_path_history " , history ) ;
settings . setValue ( " TorrentAdditionDlg/save_path_history " , history ) ;
}
}
}
}
void torrentAdditionDialog : : loadSavePathHistory ( ) {
void torrentAdditionDialog : : loadSavePathHistory ( ) {
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
// Load save path history
// Load save path history
QStringList raw_path_history = settings . value ( " TorrentAdditionDlg/save_path_history " ) . toStringList ( ) ;
QStringList raw_path_history = settings . value ( " TorrentAdditionDlg/save_path_history " ) . toStringList ( ) ;
foreach ( const QString & sp , raw_path_history ) {
foreach ( const QString & sp , raw_path_history ) {
if ( QDir ( sp ) ! = QDir ( defaultSavePath ) ) {
if ( QDir ( sp ) ! = QDir ( defaultSavePath ) ) {
QString dsp = sp ;
QString dsp = sp ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dsp = dsp . replace ( " / " , " \\ " ) ;
dsp = dsp . replace ( " / " , " \\ " ) ;
# endif
# endif
path_history < < sp ;
path_history < < sp ;
savePathTxt - > addItem ( dsp ) ;
savePathTxt - > addItem ( dsp ) ;
}
}
}
}
}
}