From 71e5a408571baf1f976adb030a6fa5d83ee1f329 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Sun, 13 May 2018 21:23:27 +0300 Subject: [PATCH] Add option to remember last used save path Replace in "Add new torrent" dialog confusing "Set as default save path" option with "Remember last used save path" option that affects only selected value in "Save path" combo box. Closes #7323. --- src/gui/addnewtorrentdialog.cpp | 32 +++++++++++++++++--------------- src/gui/addnewtorrentdialog.ui | 8 ++++---- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 6f392d84e..bc2763068 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -70,6 +70,7 @@ namespace const QString KEY_TOPLEVEL = SETTINGS_KEY("TopLevel"); const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY("SavePathHistory"); const char KEY_SAVEPATHHISTORYLENGTH[] = SETTINGS_KEY("SavePathHistoryLength"); + const QString KEY_REMEMBERLASTSAVEPATH = SETTINGS_KEY("RememberLastSavePath"); // just a shortcut inline SettingsStorage *settings() @@ -114,7 +115,9 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP m_ui->comboTTM->blockSignals(false); populateSavePathComboBox(); connect(m_ui->savePath, &FileSystemPathEdit::selectedPathChanged, this, &AddNewTorrentDialog::onSavePathChanged); - m_ui->defaultSavePathCheckBox->setVisible(false); // Default path is selected by default + + const bool rememberLastSavePath = settings()->loadValue(KEY_REMEMBERLASTSAVEPATH, false).toBool(); + m_ui->checkBoxRememberLastSavePath->setChecked(rememberLastSavePath); if (m_torrentParams.createSubfolder == TriStateBool::True) m_ui->createSubfolderCheckBox->setChecked(true); @@ -453,9 +456,7 @@ void AddNewTorrentDialog::updateDiskSpaceLabel() void AddNewTorrentDialog::onSavePathChanged(const QString &newPath) { - // Toggle default save path setting checkbox visibility - m_ui->defaultSavePathCheckBox->setChecked(false); - m_ui->defaultSavePathCheckBox->setVisible(QDir(newPath) != QDir(BitTorrent::Session::instance()->defaultSavePath())); + Q_UNUSED(newPath); // Remember index m_oldIndex = m_ui->savePath->currentIndex(); updateDiskSpaceLabel(); @@ -586,18 +587,21 @@ void AddNewTorrentDialog::renameSelectedFile() void AddNewTorrentDialog::populateSavePathComboBox() { - QString defSavePath = BitTorrent::Session::instance()->defaultSavePath(); - m_ui->savePath->clear(); - m_ui->savePath->addItem(defSavePath); - QDir defaultSaveDir(defSavePath); + // Load save path history - foreach (const QString &savePath, settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList()) - if (QDir(savePath) != defaultSaveDir) - m_ui->savePath->addItem(savePath); + const QStringList savePathHistory {settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList()}; + for (const QString &savePath : savePathHistory) + m_ui->savePath->addItem(savePath); + + const bool rememberLastSavePath {settings()->loadValue(KEY_REMEMBERLASTSAVEPATH, false).toBool()}; + const QString defSavePath {BitTorrent::Session::instance()->defaultSavePath()}; if (!m_torrentParams.savePath.isEmpty()) setSavePath(m_torrentParams.savePath); + else if (!rememberLastSavePath) + setSavePath(defSavePath); + // else last used save path will be selected since it is the first in the list } void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &) @@ -650,10 +654,11 @@ void AddNewTorrentDialog::accept() // Category m_torrentParams.category = m_ui->categoryComboBox->currentText(); - if (m_ui->defaultCategoryCheckbox->isChecked()) settings()->storeValue(KEY_DEFAULTCATEGORY, m_torrentParams.category); + settings()->storeValue(KEY_REMEMBERLASTSAVEPATH, m_ui->checkBoxRememberLastSavePath->isChecked()); + // Save file priorities if (m_contentModel) m_torrentParams.filePriorities = m_contentModel->model()->getFilePriorities(); @@ -666,8 +671,6 @@ void AddNewTorrentDialog::accept() m_torrentParams.useAutoTMM = TriStateBool::False; m_torrentParams.savePath = savePath; saveSavePathHistory(); - if (m_ui->defaultSavePathCheckBox->isChecked()) - BitTorrent::Session::instance()->setDefaultSavePath(savePath); } else { m_torrentParams.useAutoTMM = TriStateBool::True; @@ -807,7 +810,6 @@ void AddNewTorrentDialog::TMMChanged(int index) m_ui->savePath->clear(); QString savePath = BitTorrent::Session::instance()->categorySavePath(m_ui->categoryComboBox->currentText()); m_ui->savePath->addItem(savePath); - m_ui->defaultSavePathCheckBox->setVisible(false); m_ui->adv_button->setChecked(true); m_ui->adv_button->setEnabled(false); showAdvancedSettings(true); diff --git a/src/gui/addnewtorrentdialog.ui b/src/gui/addnewtorrentdialog.ui index 9f8747101..34230f300 100644 --- a/src/gui/addnewtorrentdialog.ui +++ b/src/gui/addnewtorrentdialog.ui @@ -59,12 +59,12 @@ - + - + - Set as default save path + Remember last used save path @@ -393,7 +393,7 @@ savePath - defaultSavePathCheckBox + checkBoxRememberLastSavePath never_show_cb adv_button startTorrentCheckBox