From d6353fc3b2349c5756d5983a52f0e6af4681e6d2 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Wed, 28 Nov 2012 01:45:42 +0200 Subject: [PATCH 1/6] Fix behaviour of the torrent addition dialog. The 'set as default path' didn't work as intended. Closes issues #251 and #243. --- src/addnewtorrentdialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/addnewtorrentdialog.cpp b/src/addnewtorrentdialog.cpp index 18aa0fc09..507f8b82f 100644 --- a/src/addnewtorrentdialog.cpp +++ b/src/addnewtorrentdialog.cpp @@ -65,7 +65,7 @@ AddNewTorrentDialog::AddNewTorrentDialog(QWidget *parent) : QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); Preferences pref; ui->start_torrent_cb->setChecked(!pref.addTorrentsInPause()); - ui->save_path_combo->addItem(fsutils::toDisplayPath(pref.getSavePath())); + ui->save_path_combo->addItem(fsutils::toDisplayPath(pref.getSavePath()), pref.getSavePath()); loadSavePathHistory(); ui->save_path_combo->insertSeparator(ui->save_path_combo->count()); ui->save_path_combo->addItem(tr("Other...", "Other save path...")); From 93cdd1b98cfed97c3db5f0c067b9e197e9068021 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Wed, 28 Nov 2012 02:02:54 +0200 Subject: [PATCH 2/6] Update the qbtsession when set a new default path. --- src/addnewtorrentdialog.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/addnewtorrentdialog.cpp b/src/addnewtorrentdialog.cpp index 507f8b82f..3518f4642 100644 --- a/src/addnewtorrentdialog.cpp +++ b/src/addnewtorrentdialog.cpp @@ -594,6 +594,8 @@ void AddNewTorrentDialog::on_buttonBox_accepted() saveSavePathHistory(); // Save settings pref.useAdditionDialog(!ui->never_show_cb->isChecked()); - if (ui->default_save_path_cb->isChecked()) + if (ui->default_save_path_cb->isChecked()) { pref.setSavePath(ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString()); + QBtSession::instance()->configureSession(); + } } From a50aa2d8e5d942817b2a2d6ad1806ed3f6889106 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Fri, 30 Nov 2012 01:32:11 +0200 Subject: [PATCH 3/6] Save preferences before updating QBtSession. --- src/addnewtorrentdialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/addnewtorrentdialog.cpp b/src/addnewtorrentdialog.cpp index 3518f4642..773019032 100644 --- a/src/addnewtorrentdialog.cpp +++ b/src/addnewtorrentdialog.cpp @@ -596,6 +596,7 @@ void AddNewTorrentDialog::on_buttonBox_accepted() pref.useAdditionDialog(!ui->never_show_cb->isChecked()); if (ui->default_save_path_cb->isChecked()) { pref.setSavePath(ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString()); + pref.sync(); QBtSession::instance()->configureSession(); } } From 3e979931d0a6a97f25d97b8bfabb71695e417ceb Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 1 Dec 2012 14:48:08 +0200 Subject: [PATCH 4/6] Make a setter for defaultSave path in qbtsession and do some other optimizations to avoid potential pitfalls. --- src/addnewtorrentdialog.cpp | 3 +-- src/qtlibtorrent/qbtsession.cpp | 14 ++++++++++---- src/qtlibtorrent/qbtsession.h | 3 ++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/addnewtorrentdialog.cpp b/src/addnewtorrentdialog.cpp index 773019032..ac1c67f6b 100644 --- a/src/addnewtorrentdialog.cpp +++ b/src/addnewtorrentdialog.cpp @@ -596,7 +596,6 @@ void AddNewTorrentDialog::on_buttonBox_accepted() pref.useAdditionDialog(!ui->never_show_cb->isChecked()); if (ui->default_save_path_cb->isChecked()) { pref.setSavePath(ui->save_path_combo->itemData(ui->save_path_combo->currentIndex()).toString()); - pref.sync(); - QBtSession::instance()->configureSession(); + QBtSession::instance()->setDefaultSavePath(pref.getSavePath()); } } diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 949a2614f..cd4c3f421 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -1773,7 +1773,13 @@ void QBtSession::addTorrentsFromScanFolder(QStringList &pathList) { } } -void QBtSession::setDefaultTempPath(QString temppath) { +void QBtSession::setDefaultSavePath(const QString &savepath) { + if (defaultSavePath == savepath || savepath.isEmpty()) + return; + defaultSavePath = QDir::fromNativeSeparators(savepath); +} + +void QBtSession::setDefaultTempPath(const QString &temppath) { if (defaultTempPath == temppath) return; if (temppath.isEmpty()) { @@ -1799,13 +1805,13 @@ void QBtSession::setDefaultTempPath(QString temppath) { QTorrentHandle h = QTorrentHandle(*torrentIT); if (!h.is_valid()) continue; if (!h.is_seed()) { - QString torrent_tmp_path = temppath.replace("\\", "/"); - qDebug("Moving torrent to its temp save path: %s", qPrintable(torrent_tmp_path)); + QString torrent_tmp_path = QDir::fromNativeSeparators(temppath); + qDebug("Moving torrent to its temp save path: %s", qPrintable(fsutils::toDisplayPath(torrent_tmp_path))); h.move_storage(torrent_tmp_path); } } } - defaultTempPath = temppath; + defaultTempPath = QDir::fromNativeSeparators(temppath); } void QBtSession::appendqBextensionToTorrent(const QTorrentHandle &h, bool append) { diff --git a/src/qtlibtorrent/qbtsession.h b/src/qtlibtorrent/qbtsession.h index 67aac09da..1ddb09b6f 100755 --- a/src/qtlibtorrent/qbtsession.h +++ b/src/qtlibtorrent/qbtsession.h @@ -147,7 +147,8 @@ public slots: void setDHTPort(int dht_port); void setProxySettings(libtorrent::proxy_settings proxySettings); void setSessionSettings(const libtorrent::session_settings &sessionSettings); - void setDefaultTempPath(QString temppath); + void setDefaultSavePath(const QString &savepath); + void setDefaultTempPath(const QString &temppath); void setAppendLabelToSavePath(bool append); void appendLabelToTorrentSavePath(const QTorrentHandle &h); void changeLabelInTorrentSavePath(const QTorrentHandle &h, QString old_label, QString new_label); From a899209a01fb42ebdb5e6444f5471b16d0709c84 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 1 Dec 2012 15:40:18 +0200 Subject: [PATCH 5/6] Optimize check of paths in qbtsession. --- src/qtlibtorrent/qbtsession.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index cd4c3f421..8235901a3 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -1774,14 +1774,16 @@ void QBtSession::addTorrentsFromScanFolder(QStringList &pathList) { } void QBtSession::setDefaultSavePath(const QString &savepath) { - if (defaultSavePath == savepath || savepath.isEmpty()) + if (QDir(defaultSavePath) == QDir(savepath) || savepath.isEmpty()) return; + defaultSavePath = QDir::fromNativeSeparators(savepath); } void QBtSession::setDefaultTempPath(const QString &temppath) { - if (defaultTempPath == temppath) + if (QDir(defaultTempPath) == QDir(temppath)) return; + if (temppath.isEmpty()) { // Disabling temp dir // Moving all torrents to their destination folder From 47c40b04e4ef10a107eb6d385f7f775c5d320c01 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 1 Dec 2012 17:48:18 +0200 Subject: [PATCH 6/6] Remove equality check from QBtSession::setDefaultSavePath(). --- src/qtlibtorrent/qbtsession.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 8235901a3..bb5f0d926 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -1774,7 +1774,7 @@ void QBtSession::addTorrentsFromScanFolder(QStringList &pathList) { } void QBtSession::setDefaultSavePath(const QString &savepath) { - if (QDir(defaultSavePath) == QDir(savepath) || savepath.isEmpty()) + if (savepath.isEmpty()) return; defaultSavePath = QDir::fromNativeSeparators(savepath);