@ -53,10 +53,28 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
defaultSavePath = Preferences : : getSavePath ( ) ;
defaultSavePath = Preferences : : getSavePath ( ) ;
appendLabelToSavePath = Preferences : : appendTorrentLabel ( ) ;
appendLabelToSavePath = Preferences : : appendTorrentLabel ( ) ;
QString display_path = defaultSavePath ;
QString display_path = defaultSavePath ;
if ( ! display_path . endsWith ( " / " ) & & ! display_path . endsWith ( " \\ " ) )
display_path + = " / " ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
display_path = display_path . replace ( " / " , " \\ " ) ;
display_path = display_path . replace ( " / " , " \\ " ) ;
# endif
# endif
savePathTxt - > setText ( display_path ) ;
savePathTxt - > addItem ( display_path ) ;
// Load save path history
const QStringList path_history = getSavePathHistory ( ) ;
foreach ( const QString & sp , path_history ) {
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
if ( sp . compare ( display_path , Qt : : CaseInsensitive ) ! = 0 ) {
# else
if ( sp . compare ( display_path , Qt : : CaseSensitive ) ! = 0 ) {
# endif
QString dsp = sp ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
dsp = dsp . replace ( " / " , " \\ " ) ;
# endif
savePathTxt - > addItem ( dsp ) ;
}
}
if ( Preferences : : addTorrentsInPause ( ) ) {
if ( Preferences : : addTorrentsInPause ( ) ) {
addInPause - > setChecked ( true ) ;
addInPause - > setChecked ( true ) ;
//addInPause->setEnabled(false);
//addInPause->setEnabled(false);
@ -141,10 +159,10 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
if ( fileName . isEmpty ( ) ) {
if ( fileName . isEmpty ( ) ) {
fileName = tr ( " Magnet Link " ) ;
fileName = tr ( " Magnet Link " ) ;
} else {
} else {
QString save_path = savePathTxt - > text ( ) ;
QString save_path = savePathTxt - > curren tT ext( ) ;
if ( ! save_path . endsWith ( QDir : : separator ( ) ) )
if ( ! save_path . endsWith ( QDir : : separator ( ) ) )
save_path + = QDir : : separator ( ) ;
save_path + = QDir : : separator ( ) ;
savePathTxt - > setText ( save_path + fileName ) ;
savePathTxt - > setEdi tText ( save_path + fileName ) ;
}
}
fileNameLbl - > setText ( QString : : fromUtf8 ( " <center><b> " ) + fileName + QString : : fromUtf8 ( " </b></center> " ) ) ;
fileNameLbl - > setText ( QString : : fromUtf8 ( " <center><b> " ) + fileName + QString : : fromUtf8 ( " </b></center> " ) ) ;
// Update display
// Update display
@ -193,10 +211,10 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
}
}
if ( nbFiles = = 1 ) {
if ( nbFiles = = 1 ) {
// Update properties model whenever the file path is edited
// Update properties model whenever the file path is edited
connect ( savePathTxt , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( renameTorrentNameInModel ( QString ) ) ) ;
connect ( savePathTxt , SIGNAL ( edi tT extChanged( QString ) ) , this , SLOT ( renameTorrentNameInModel ( QString ) ) ) ;
}
}
QString root_folder = misc : : truncateRootFolder ( t ) ;
QString root_folder = misc : : truncateRootFolder ( t ) ;
QString save_path = savePathTxt - > text ( ) ;
QString save_path = savePathTxt - > curren tT ext( ) ;
# 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
# endif
@ -204,7 +222,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
save_path + = QDir : : separator ( ) ;
save_path + = QDir : : separator ( ) ;
// If the torrent has a root folder, append it to the save path
// If the torrent has a root folder, append it to the save path
if ( ! root_folder . isEmpty ( ) ) {
if ( ! root_folder . isEmpty ( ) ) {
savePathTxt - > setText ( save_path + root_folder + QDir : : separator ( ) ) ;
savePathTxt - > setEditText ( save_path + root_folder + QDir : : separator ( ) ) ;
// Update other combo items
for ( int i = 0 ; i < savePathTxt - > count ( ) ; + + i ) {
savePathTxt - > setItemText ( i , savePathTxt - > itemText ( i ) + root_folder + QDir : : separator ( ) ) ;
}
}
}
if ( nbFiles = = 1 ) {
if ( nbFiles = = 1 ) {
// single file torrent
// single file torrent
@ -212,7 +234,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
# 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
savePathTxt - > setText ( save_path + single_file_relpath ) ;
savePathTxt - > setEditText ( save_path + single_file_relpath ) ;
// Update other combo items
for ( int i = 0 ; i < savePathTxt - > count ( ) ; + + i ) {
savePathTxt - > setItemText ( i , savePathTxt - > itemText ( i ) + single_file_relpath ) ;
}
}
}
// Setting file name
// Setting file name
fileName = misc : : toQStringU ( t - > name ( ) ) ;
fileName = misc : : toQStringU ( t - > name ( ) ) ;
@ -236,7 +262,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
files_path < < misc : : toQStringU ( t - > file_at ( i ) . path . string ( ) ) ;
files_path < < misc : : toQStringU ( t - > file_at ( i ) . path . string ( ) ) ;
}
}
}
}
connect ( savePathTxt , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( updateDiskSpaceLabels ( ) ) ) ;
connect ( savePathTxt , SIGNAL ( edi tT extChanged( QString ) ) , this , SLOT ( updateDiskSpaceLabels ( ) ) ) ;
updateDiskSpaceLabels ( ) ;
updateDiskSpaceLabels ( ) ;
// Load custom labels
// Load custom labels
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
@ -389,7 +415,8 @@ void torrentAdditionDialog::renameSelectedFile() {
}
}
void torrentAdditionDialog : : updateDiskSpaceLabels ( ) {
void torrentAdditionDialog : : updateDiskSpaceLabels ( ) {
const long long available = misc : : freeDiskSpaceOnPath ( misc : : expandPath ( savePathTxt - > text ( ) ) ) ;
qDebug ( " Updating disk space label... " ) ;
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
@ -425,7 +452,7 @@ void torrentAdditionDialog::renameSelectedFile() {
void torrentAdditionDialog : : on_browseButton_clicked ( ) {
void torrentAdditionDialog : : on_browseButton_clicked ( ) {
QString new_path ;
QString new_path ;
QString save_path = savePathTxt - > text ( ) ;
QString save_path = savePathTxt - > curren tT ext( ) ;
# 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
# endif
@ -444,7 +471,7 @@ void torrentAdditionDialog::renameSelectedFile() {
# 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 - > setText ( new_path ) ;
savePathTxt - > setEdi tText ( new_path ) ;
}
}
}
}
@ -463,22 +490,22 @@ void torrentAdditionDialog::renameSelectedFile() {
}
}
void torrentAdditionDialog : : on_OkButton_clicked ( ) {
void torrentAdditionDialog : : on_OkButton_clicked ( ) {
if ( savePathTxt - > text ( ) . trimmed ( ) . isEmpty ( ) ) {
if ( savePathTxt - > curren tT ext( ) . 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 - > text ( ) ;
QString save_path = savePathTxt - > curren tT ext( ) ;
# 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
# endif
save_path = misc : : expandPath ( save_path ) ;
save_path = misc : : expandPath ( save_path ) ;
if ( ! is_magnet & & t - > num_files ( ) = = 1 ) {
if ( ! is_magnet & & t - > num_files ( ) = = 1 ) {
// Remove file name
// Remove file name
QStringList parts = save_path . split ( " / " , QString : : SkipEmptyParts ) ;
QStringList parts = save_path . split ( " / " ) ;
const QString single_file_name = parts . takeLast ( ) ;
const QString single_file_name = parts . takeLast ( ) ;
Q_ASSERT ( files_path . isEmpty ( ) ) ;
Q_ASSERT ( files_path . isEmpty ( ) ) ;
files_path < < single_file_name ;
files_path < < single_file_name ;
save_path = " / " + parts . join ( " / " ) ;
save_path = parts . join ( " / " ) ;
}
}
QDir savePath ( save_path ) ;
QDir savePath ( save_path ) ;
// Check if savePath exists
// Check if savePath exists
@ -523,7 +550,7 @@ void torrentAdditionDialog::renameSelectedFile() {
// 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 - > text ( ) ) ) {
if ( is_magnet | | QFile : : exists ( savePathTxt - > curren tT ext( ) ) ) {
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. " ) ) ;
@ -549,12 +576,61 @@ void torrentAdditionDialog::renameSelectedFile() {
h . pause ( ) ;
h . pause ( ) ;
emit torrentPaused ( h ) ;
emit torrentPaused ( h ) ;
}
}
// Save path history
saveTruncatedPathHistory ( ) ;
// Close the dialog
close ( ) ;
close ( ) ;
}
}
void torrentAdditionDialog : : updateLabelInSavePath ( QString label ) {
void torrentAdditionDialog : : updateLabelInSavePath ( QString label ) {
if ( appendLabelToSavePath ) {
if ( appendLabelToSavePath ) {
savePathTxt - > setText ( misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > text ( ) , old_label , label ) ) ;
savePathTxt - > setEditText ( misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > currentText ( ) , old_label , label ) ) ;
// Update other combo items
for ( int i = 0 ; i < savePathTxt - > count ( ) ; + + i ) {
savePathTxt - > setItemText ( i , misc : : updateLabelInSavePath ( defaultSavePath , savePathTxt - > itemText ( i ) , old_label , label ) ) ;
}
old_label = label ;
old_label = label ;
}
}
}
}
// Get current save path without last part and without label
QString torrentAdditionDialog : : getCurrentTruncatedSavePath ( ) const {
QStringList parts = savePathTxt - > currentText ( ) . replace ( " \\ " , " / " ) . split ( " / " ) ;
if ( parts . last ( ) . isEmpty ( ) )
parts . removeLast ( ) ;
// Remove last part
parts . removeLast ( ) ;
if ( appendLabelToSavePath ) {
// Remove label
if ( parts . last ( ) = = comboLabel - > currentText ( ) )
parts . removeLast ( ) ;
}
const QString truncated_path = parts . join ( " / " ) + " / " ;
qDebug ( " Truncated save path: %s " , qPrintable ( truncated_path ) ) ;
return truncated_path ;
}
void torrentAdditionDialog : : saveTruncatedPathHistory ( ) {
QSettings 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 ) ) {
# else
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 ) ;
}
}
QStringList torrentAdditionDialog : : getSavePathHistory ( ) const {
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
return settings . value ( " TorrentAdditionDlg/save_path_history " ) . toStringList ( ) ;
}