@ -53,10 +53,28 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
@@ -53,10 +53,28 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
defaultSavePath = Preferences : : getSavePath ( ) ;
appendLabelToSavePath = Preferences : : appendTorrentLabel ( ) ;
QString display_path = defaultSavePath ;
if ( ! display_path . endsWith ( " / " ) & & ! display_path . endsWith ( " \\ " ) )
display_path + = " / " ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
display_path = display_path . replace ( " / " , " \\ " ) ;
# 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 ( ) ) {
addInPause - > setChecked ( true ) ;
//addInPause->setEnabled(false);
@ -66,15 +84,15 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
@@ -66,15 +84,15 @@ torrentAdditionDialog::torrentAdditionDialog(GUI *parent, Bittorrent* _BTSession
# endif
// Set Add button as default
OkButton - > setDefault ( true ) ;
}
}
torrentAdditionDialog : : ~ torrentAdditionDialog ( ) {
torrentAdditionDialog : : ~ torrentAdditionDialog ( ) {
saveSettings ( ) ;
delete PropDelegate ;
delete PropListModel ;
}
}
void torrentAdditionDialog : : readSettings ( ) {
void torrentAdditionDialog : : readSettings ( ) {
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
// Restore size and position
resize ( settings . value ( QString : : fromUtf8 ( " TorrentAdditionDlg/size " ) , size ( ) ) . toSize ( ) ) ;
@ -88,9 +106,9 @@ void torrentAdditionDialog::readSettings() {
@@ -88,9 +106,9 @@ void torrentAdditionDialog::readSettings() {
torrentContentList - > setColumnWidth ( i , contentColsWidths . at ( i ) ) ;
}
}
}
}
void torrentAdditionDialog : : saveSettings ( ) {
void torrentAdditionDialog : : saveSettings ( ) {
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
if ( ! is_magnet & & t . get ( ) & & t - > is_valid ( ) & & t - > num_files ( ) > 1 ) {
QStringList contentColsWidths ;
@ -103,15 +121,15 @@ void torrentAdditionDialog::saveSettings() {
@@ -103,15 +121,15 @@ void torrentAdditionDialog::saveSettings() {
settings . setValue ( " TorrentAdditionDlg/size " , size ( ) + QSize ( 0 , hidden_height ) ) ;
qDebug ( " pos: (%d, %d) " , pos ( ) . x ( ) , pos ( ) . y ( ) ) ;
settings . setValue ( " TorrentAdditionDlg/pos " , pos ( ) ) ;
}
}
void torrentAdditionDialog : : renameTorrentNameInModel ( QString file_path ) {
void torrentAdditionDialog : : renameTorrentNameInModel ( QString file_path ) {
file_path = file_path . replace ( " \\ " , " / " ) ;
// Rename in torrent files model too
PropListModel - > setData ( PropListModel - > index ( 0 , 0 ) , file_path . split ( " / " , QString : : SkipEmptyParts ) . last ( ) ) ;
}
}
void torrentAdditionDialog : : hideTorrentContent ( ) {
void torrentAdditionDialog : : hideTorrentContent ( ) {
// Disable useless widgets
hidden_height + = torrentContentList - > height ( ) ;
torrentContentList - > setVisible ( false ) ;
@ -124,9 +142,9 @@ void torrentAdditionDialog::hideTorrentContent() {
@@ -124,9 +142,9 @@ void torrentAdditionDialog::hideTorrentContent() {
// Resize main window
setMinimumSize ( 0 , 0 ) ;
resize ( width ( ) , height ( ) - hidden_height ) ;
}
}
void torrentAdditionDialog : : showLoadMagnetURI ( QString magnet_uri ) {
void torrentAdditionDialog : : showLoadMagnetURI ( QString magnet_uri ) {
show ( ) ;
is_magnet = true ;
this - > from_url = magnet_uri ;
@ -141,10 +159,10 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
@@ -141,10 +159,10 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
if ( fileName . isEmpty ( ) ) {
fileName = tr ( " Magnet Link " ) ;
} else {
QString save_path = savePathTxt - > text ( ) ;
QString save_path = savePathTxt - > curren tT ext( ) ;
if ( ! save_path . endsWith ( 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> " ) ) ;
// Update display
@ -159,9 +177,9 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
@@ -159,9 +177,9 @@ void torrentAdditionDialog::showLoadMagnetURI(QString magnet_uri) {
}
// No need to display torrent content
hideTorrentContent ( ) ;
}
}
void torrentAdditionDialog : : showLoad ( QString filePath , QString from_url ) {
void torrentAdditionDialog : : showLoad ( QString filePath , QString from_url ) {
is_magnet = false ;
if ( ! QFile : : exists ( filePath ) ) {
close ( ) ;
@ -193,10 +211,10 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -193,10 +211,10 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
}
if ( nbFiles = = 1 ) {
// 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 save_path = savePathTxt - > text ( ) ;
QString save_path = savePathTxt - > curren tT ext( ) ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path . replace ( " / " , " \\ " ) ;
# endif
@ -204,7 +222,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -204,7 +222,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
save_path + = QDir : : separator ( ) ;
// If the torrent has a root folder, append it to the save path
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 ) {
// single file torrent
@ -212,7 +234,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -212,7 +234,11 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
single_file_relpath = single_file_relpath . replace ( " / " , " \\ " ) ;
# 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
fileName = misc : : toQStringU ( t - > name ( ) ) ;
@ -236,7 +262,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -236,7 +262,7 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
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 ( ) ;
// Load custom labels
QSettings settings ( QString : : fromUtf8 ( " qBittorrent " ) , QString : : fromUtf8 ( " qBittorrent " ) ) ;
@ -250,9 +276,9 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
@@ -250,9 +276,9 @@ void torrentAdditionDialog::showLoad(QString filePath, QString from_url) {
show ( ) ;
if ( t - > num_files ( ) < = 1 )
hideTorrentContent ( ) ;
}
}
void torrentAdditionDialog : : displayContentListMenu ( const QPoint & ) {
void torrentAdditionDialog : : displayContentListMenu ( const QPoint & ) {
QMenu myFilesLlistMenu ;
const QModelIndexList & selectedRows = torrentContentList - > selectionModel ( ) - > selectedRows ( 0 ) ;
QAction * actRename = 0 ;
@ -287,9 +313,9 @@ void torrentAdditionDialog::displayContentListMenu(const QPoint&) {
@@ -287,9 +313,9 @@ void torrentAdditionDialog::displayContentListMenu(const QPoint&) {
}
}
}
}
}
void torrentAdditionDialog : : renameSelectedFile ( ) {
void torrentAdditionDialog : : renameSelectedFile ( ) {
const QModelIndexList & selectedIndexes = torrentContentList - > selectionModel ( ) - > selectedRows ( 0 ) ;
Q_ASSERT ( selectedIndexes . size ( ) = = 1 ) ;
const QModelIndex & index = selectedIndexes . first ( ) ;
@ -389,7 +415,8 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -389,7 +415,8 @@ void torrentAdditionDialog::renameSelectedFile() {
}
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 ) ) ;
if ( ! is_magnet ) {
// Determine torrent size
@ -425,7 +452,7 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -425,7 +452,7 @@ void torrentAdditionDialog::renameSelectedFile() {
void torrentAdditionDialog : : on_browseButton_clicked ( ) {
QString new_path ;
QString save_path = savePathTxt - > text ( ) ;
QString save_path = savePathTxt - > curren tT ext( ) ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path . replace ( " \\ " , " / " ) ;
# endif
@ -444,7 +471,7 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -444,7 +471,7 @@ void torrentAdditionDialog::renameSelectedFile() {
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
new_path = new_path . replace ( " / " , " \\ " ) ;
# endif
savePathTxt - > setText ( new_path ) ;
savePathTxt - > setEdi tText ( new_path ) ;
}
}
@ -463,22 +490,22 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -463,22 +490,22 @@ void torrentAdditionDialog::renameSelectedFile() {
}
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 " ) ) ;
return ;
}
QString save_path = savePathTxt - > text ( ) ;
QString save_path = savePathTxt - > curren tT ext( ) ;
# if defined(Q_WS_WIN) || defined(Q_OS_OS2)
save_path = save_path . replace ( " \\ " , " / " ) ;
# endif
save_path = misc : : expandPath ( save_path ) ;
if ( ! is_magnet & & t - > num_files ( ) = = 1 ) {
// Remove file name
QStringList parts = save_path . split ( " / " , QString : : SkipEmptyParts ) ;
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 ( " / " ) ;
save_path = parts . join ( " / " ) ;
}
QDir savePath ( save_path ) ;
// Check if savePath exists
@ -523,7 +550,7 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -523,7 +550,7 @@ void torrentAdditionDialog::renameSelectedFile() {
// Skip file checking and directly start seeding
if ( addInSeed - > isChecked ( ) ) {
// 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 ) ;
} 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. " ) ) ;
@ -549,12 +576,61 @@ void torrentAdditionDialog::renameSelectedFile() {
@@ -549,12 +576,61 @@ void torrentAdditionDialog::renameSelectedFile() {
h . pause ( ) ;
emit torrentPaused ( h ) ;
}
// Save path history
saveTruncatedPathHistory ( ) ;
// Close the dialog
close ( ) ;
}
void torrentAdditionDialog : : updateLabelInSavePath ( QString label ) {
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 ;
}
}
// 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 ( ) ;
}