@ -252,6 +252,9 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -252,6 +252,9 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
close ( ) ;
return ;
}
# if LIBTORRENT_VERSION_MINOR >= 16
file_storage fs = t - > files ( ) ;
# endif
// Truncate root folder
QString root_folder = misc : : truncateRootFolder ( t ) ;
// Setting file name
@ -271,8 +274,13 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -271,8 +274,13 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
connect ( PropDelegate , SIGNAL ( filteredFilesChanged ( ) ) , this , SLOT ( updateDiskSpaceLabels ( ) ) ) ;
// Loads files path in the torrent
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 ( ) ) ;
# endif
}
}
// Load save path history
@ -298,7 +306,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -298,7 +306,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
}
if ( nbFiles = = 1 ) {
// 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 ( ) ) ;
# endif
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
single_file_relpath = single_file_relpath . replace ( " / " , " \\ " ) ;
# endif
@ -402,366 +414,372 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -402,366 +414,372 @@ void torrentAdditionDialog::renameSelectedFile() {
# if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
if ( files_path . at ( i ) . compare ( new_name , Qt : : CaseSensitive ) = = 0 ) {
# else
if ( files_path . at ( i ) . compare ( new_name , Qt : : CaseInsensitive ) = = 0 ) {
if ( files_path . at ( i ) . compare ( new_name , Qt : : CaseInsensitive ) = = 0 ) {
# endif
// Display error message
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. " ) ,
QMessageBox : : Ok ) ;
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 ) ;
// Display error message
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. " ) ,
QMessageBox : : Ok ) ;
return ;
}
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 ) ;
}
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 ( ) ;
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 ( current_name . startsWith ( new_path , Qt : : CaseSensitive ) ) {
if ( current_name . startsWith ( new_path , Qt : : CaseSensitive ) ) {
# else
if ( current_name . startsWith ( new_path , Qt : : CaseInsensitive ) ) {
if ( current_name . startsWith ( new_path , Qt : : CaseInsensitive ) ) {
# endif
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. " ) ,
QMessageBox : : Ok ) ;
return ;
}
}
// Replace path in all files
for ( uint i = 0 ; i < nbFiles ; + + i ) {
const QString & current_name = files_path . 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_path . replace ( i , new_name ) ;
}
}
// Rename folder in torrent files model too
PropListModel - > setData ( index , new_name_last ) ;
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. " ) ,
QMessageBox : : Ok ) ;
return ;
}
}
// Replace path in all files
for ( uint i = 0 ; i < nbFiles ; + + i ) {
const QString & current_name = files_path . 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_path . replace ( i , new_name ) ;
}
}
// Rename folder in torrent files model too
PropListModel - > setData ( index , new_name_last ) ;
}
}
}
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_magnet ) {
// Determine torrent size
qulonglong torrent_size = 0 ;
if ( t - > num_files ( ) > 1 ) {
const unsigned int nbFiles = t - > num_files ( ) ;
const std : : vector < int > priorities = PropListModel - > getFilesPriorities ( nbFiles ) ;
for ( unsigned int i = 0 ; i < nbFiles ; + + i ) {
if ( priorities [ i ] > 0 )
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 ( " " ) ;
}
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_magnet ) {
// Determine torrent size
qulonglong torrent_size = 0 ;
if ( t - > num_files ( ) > 1 ) {
const unsigned int nbFiles = t - > num_files ( ) ;
const std : : vector < int > priorities = PropListModel - > getFilesPriorities ( nbFiles ) ;
for ( unsigned int i = 0 ; i < nbFiles ; + + i ) {
if ( priorities [ i ] > 0 )
torrent_size + = t - > file_at ( i ) . size ;
}
} else {
torrent_size = t - > total_size ( ) ;
}
lbl_torrent_size - > setText ( misc : : friendlyUnit ( torrent_size ) ) ;
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 ( ) ) ;
// 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 {
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 ( ) ) ;
}
// 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> " ) ;
}
if ( ! new_path . isEmpty ( ) ) {
// Check if this new path already exists in the list
QString new_truncated_path = getTruncatedSavePath ( new_path ) ;
} else {
// Available disk space is unknown
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)
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
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
if ( cur_index > = 0 ) {
savePathTxt - > setCurrentIndex ( cur_index ) ;
}
if ( cur_index > = 0 ) {
savePathTxt - > setCurrentIndex ( cur_index ) ;
}
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
new_path = new_path . replace ( " / " , " \\ " ) ;
new_path = new_path . replace ( " / " , " \\ " ) ;
# endif
savePathTxt - > setEditText ( new_path ) ;
}
}
savePathTxt - > setEditText ( new_path ) ;
}
}
void torrentAdditionDialog : : on_CancelButton_clicked ( ) {
close ( ) ;
}
void torrentAdditionDialog : : on_CancelButton_clicked ( ) {
close ( ) ;
}
bool torrentAdditionDialog : : allFiltered ( ) const {
Q_ASSERT ( ! is_magnet ) ;
return PropListModel - > allFiltered ( ) ;
}
bool torrentAdditionDialog : : allFiltered ( ) const {
Q_ASSERT ( ! is_magnet ) ;
return PropListModel - > allFiltered ( ) ;
}
void torrentAdditionDialog : : savePiecesPriorities ( ) {
qDebug ( " Saving pieces priorities " ) ;
Q_ASSERT ( ! is_magnet ) ;
const std : : vector < int > priorities = PropListModel - > getFilesPriorities ( t - > num_files ( ) ) ;
TorrentTempData : : setFilesPriority ( hash , priorities ) ;
}
void torrentAdditionDialog : : savePiecesPriorities ( ) {
qDebug ( " Saving pieces priorities " ) ;
Q_ASSERT ( ! is_magnet ) ;
const std : : vector < int > priorities = PropListModel - > getFilesPriorities ( t - > num_files ( ) ) ;
TorrentTempData : : setFilesPriority ( hash , priorities ) ;
}
void torrentAdditionDialog : : on_OkButton_clicked ( ) {
qDebug ( ) < < " void torrentAdditionDialog::on_OkButton_clicked() - ENTER " ;
if ( savePathTxt - > currentText ( ) . trimmed ( ) . isEmpty ( ) ) {
QMessageBox : : critical ( 0 , tr ( " Empty save path " ) , tr ( " Please enter a save path " ) ) ;
return ;
}
QString save_path = savePathTxt - > currentText ( ) ;
void torrentAdditionDialog : : on_OkButton_clicked ( ) {
qDebug ( ) < < " void torrentAdditionDialog::on_OkButton_clicked() - ENTER " ;
if ( savePathTxt - > currentText ( ) . trimmed ( ) . isEmpty ( ) ) {
QMessageBox : : critical ( 0 , tr ( " Empty save path " ) , tr ( " Please enter a save path " ) ) ;
return ;
}
QString save_path = savePathTxt - > currentText ( ) ;
# 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
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 ( 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
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
path_changed = true ;
break ;
}
}
if ( path_changed ) {
qDebug ( " Changing files paths " ) ;
TorrentTempData : : setFilesPath ( hash , files_path ) ;
}
}
path_changed = true ;
break ;
}
}
if ( path_changed ) {
qDebug ( " Changing files paths " ) ;
TorrentTempData : : setFilesPath ( hash , files_path ) ;
}
}
# if LIBTORRENT_VERSION_MINOR > 14
// Skip file checking and directly start seeding
if ( addInSeed - > isChecked ( ) ) {
// Check if local file(s) actually exist
if ( is_magnet | | QFile : : exists ( savePathTxt - > currentText ( ) ) ) {
TorrentTempData : : setSeedingMode ( 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 ;
}
}
// Skip file checking and directly start seeding
if ( addInSeed - > isChecked ( ) ) {
// Check if local file(s) actually exist
if ( is_magnet | | QFile : : exists ( savePathTxt - > currentText ( ) ) ) {
TorrentTempData : : setSeedingMode ( 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 ;
}
}
# endif
// Check if there is at least one selected file
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 " ) ) ;
return ;
}
// Save path history
saveTruncatedPathHistory ( ) ;
// 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 filtered files
if ( ! is_magnet & & t - > num_files ( ) > 1 )
savePiecesPriorities ( ) ;
// Add to download list
QTorrentHandle h ;
if ( is_magnet )
h = QBtSession : : instance ( ) - > addMagnetUri ( from_url , false ) ;
else
h = QBtSession : : instance ( ) - > addTorrent ( filePath , false , from_url ) ;
if ( addInPause - > isChecked ( ) & & h . is_valid ( ) ) {
h . pause ( ) ;
}
// Close the dialog
qDebug ( " Closing torrent addition dialog... " ) ;
close ( ) ;
qDebug ( " Closed " ) ;
}
// Check if there is at least one selected file
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 " ) ) ;
return ;
}
// Save path history
saveTruncatedPathHistory ( ) ;
// 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 filtered files
if ( ! is_magnet & & t - > num_files ( ) > 1 )
savePiecesPriorities ( ) ;
// Add to download list
QTorrentHandle h ;
if ( is_magnet )
h = QBtSession : : instance ( ) - > addMagnetUri ( from_url , false ) ;
else
h = QBtSession : : instance ( ) - > addTorrent ( filePath , false , from_url ) ;
if ( addInPause - > isChecked ( ) & & h . is_valid ( ) ) {
h . pause ( ) ;
}
// Close the dialog
qDebug ( " Closing torrent addition dialog... " ) ;
close ( ) ;
qDebug ( " Closed " ) ;
}
void torrentAdditionDialog : : resetComboLabelIndex ( QString text ) {
// Select first index
if ( text ! = comboLabel - > itemText ( comboLabel - > currentIndex ( ) ) ) {
comboLabel - > setItemText ( 0 , text ) ;
comboLabel - > setCurrentIndex ( 0 ) ;
}
}
void torrentAdditionDialog : : resetComboLabelIndex ( QString text ) {
// Select first index
if ( text ! = comboLabel - > itemText ( comboLabel - > currentIndex ( ) ) ) {
comboLabel - > setItemText ( 0 , text ) ;
comboLabel - > setCurrentIndex ( 0 ) ;
}
}
void torrentAdditionDialog : : updateLabelInSavePath ( QString label ) {
if ( appendLabelToSavePath ) {
// Update Label in combobox
savePathTxt - > setItemText ( 0 , misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > itemText ( 0 ) , old_label , label ) ) ;
// update edit text
savePathTxt - > setEditText ( misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > currentText ( ) , old_label , label ) ) ;
old_label = label ;
}
}
void torrentAdditionDialog : : updateLabelInSavePath ( QString label ) {
if ( appendLabelToSavePath ) {
// Update Label in combobox
savePathTxt - > setItemText ( 0 , misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > itemText ( 0 ) , old_label , label ) ) ;
// update edit text
savePathTxt - > setEditText ( misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > currentText ( ) , old_label , label ) ) ;
old_label = label ;
}
}
void torrentAdditionDialog : : updateSavePathCurrentText ( ) {
qDebug ( " updateSavePathCurrentText() - ENTER " ) ;
savePathTxt - > setItemText ( savePathTxt - > currentIndex ( ) , savePathTxt - > currentText ( ) ) ;
qDebug ( " path_history.size() == %d " , path_history . size ( ) ) ;
qDebug ( " savePathTxt->currentIndex() == %d " , savePathTxt - > currentIndex ( ) ) ;
path_history . 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_history . at ( i ) ;
if ( item_path . isEmpty ( ) ) continue ;
// Append label
if ( i = = 0 & & appendLabelToSavePath & & QDir ( item_path ) = = QDir ( defaultSavePath ) & & ! comboLabel - > currentText ( ) . isEmpty ( ) )
item_path + = comboLabel - > currentText ( ) + " / " ;
// Append root_folder or filename
if ( ! root_folder_or_file_name . isEmpty ( ) )
item_path + = root_folder_or_file_name ;
void torrentAdditionDialog : : updateSavePathCurrentText ( ) {
qDebug ( " updateSavePathCurrentText() - ENTER " ) ;
savePathTxt - > setItemText ( savePathTxt - > currentIndex ( ) , savePathTxt - > currentText ( ) ) ;
qDebug ( " path_history.size() == %d " , path_history . size ( ) ) ;
qDebug ( " savePathTxt->currentIndex() == %d " , savePathTxt - > currentIndex ( ) ) ;
path_history . 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_history . at ( i ) ;
if ( item_path . isEmpty ( ) ) continue ;
// Append label
if ( i = = 0 & & appendLabelToSavePath & & QDir ( item_path ) = = QDir ( defaultSavePath ) & & ! comboLabel - > currentText ( ) . isEmpty ( ) )
item_path + = comboLabel - > currentText ( ) + " / " ;
// Append root_folder or filename
if ( ! root_folder_or_file_name . isEmpty ( ) )
item_path + = root_folder_or_file_name ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
item_path = item_path . replace ( " / " , " \\ " ) ;
item_path = item_path . replace ( " / " , " \\ " ) ;
# endif
savePathTxt - > setItemText ( i , item_path ) ;
}
}
savePathTxt - > setItemText ( i , item_path ) ;
}
}
QString torrentAdditionDialog : : getCurrentTruncatedSavePath ( QString * root_folder_or_file_name ) const {
QString save_path = savePathTxt - > currentText ( ) ;
return getTruncatedSavePath ( save_path , root_folder_or_file_name ) ;
}
QString torrentAdditionDialog : : getCurrentTruncatedSavePath ( QString * root_folder_or_file_name ) const {
QString save_path = savePathTxt - > currentText ( ) ;
return getTruncatedSavePath ( save_path , root_folder_or_file_name ) ;
}
// 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 {
// Expand and clean path (~, .., .)
save_path = misc : : expandPath ( save_path ) ;
QStringList parts = save_path . replace ( " \\ " , " / " ) . split ( " / " ) ;
// Remove torrent root folder
if ( ! QDir ( save_path ) . exists ( ) | | ( ! is_magnet & & t - > 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 ( ) ) {
parts . removeLast ( ) ;
}
QString truncated_path = parts . join ( " / " ) ;
if ( ! truncated_path . endsWith ( " / " ) )
truncated_path + = " / " ;
qDebug ( " Truncated save path: %s " , qPrintable ( truncated_path ) ) ;
return truncated_path ;
}
// 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 {
// Expand and clean path (~, .., .)
save_path = misc : : expandPath ( save_path ) ;
QStringList parts = save_path . replace ( " \\ " , " / " ) . split ( " / " ) ;
// Remove torrent root folder
if ( ! QDir ( save_path ) . exists ( ) | | ( ! is_magnet & & t - > 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 ( ) ) {
parts . removeLast ( ) ;
}
QString truncated_path = parts . join ( " / " ) ;
if ( ! truncated_path . endsWith ( " / " ) )
truncated_path + = " / " ;
qDebug ( " Truncated save path: %s " , qPrintable ( truncated_path ) ) ;
return truncated_path ;
}
void torrentAdditionDialog : : saveTruncatedPathHistory ( ) {
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
const QString current_save_path = getCurrentTruncatedSavePath ( ) ;
// Get current history
QStringList history = settings . value ( " TorrentAdditionDlg/save_path_history " ) . toStringList ( ) ;
void torrentAdditionDialog : : saveTruncatedPathHistory ( ) {
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
const QString current_save_path = getCurrentTruncatedSavePath ( ) ;
// Get current history
QStringList history = settings . value ( " TorrentAdditionDlg/save_path_history " ) . toStringList ( ) ;
# 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
if ( ! history . contains ( current_save_path , Qt : : CaseInsensitive ) ) {
if ( ! history . contains ( current_save_path , Qt : : CaseInsensitive ) ) {
# endif
// Add save path to history
history < < current_save_path ;
// Limit list size
if ( history . size ( ) > 8 )
history . removeFirst ( ) ;
// Save history
settings . setValue ( " TorrentAdditionDlg/save_path_history " , history ) ;
}
}
// Add save path to history
history < < current_save_path ;
// Limit list size
if ( history . size ( ) > 8 )
history . removeFirst ( ) ;
// Save history
settings . setValue ( " TorrentAdditionDlg/save_path_history " , history ) ;
}
}
void torrentAdditionDialog : : loadSavePathHistory ( ) {
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
// 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 ) ) {
QString dsp = sp ;
void torrentAdditionDialog : : loadSavePathHistory ( ) {
QIniSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
// 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 ) ) {
QString dsp = sp ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dsp = dsp . replace ( " / " , " \\ " ) ;
dsp = dsp . replace ( " / " , " \\ " ) ;
# endif
path_history < < sp ;
savePathTxt - > addItem ( dsp ) ;
}
}
}
path_history < < sp ;
savePathTxt - > addItem ( dsp ) ;
}
}
}