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.
This commit is contained in:
Vladimir Golovnev (Glassez) 2018-05-13 21:23:27 +03:00
parent e3ce9b2645
commit 71e5a40857
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
2 changed files with 21 additions and 19 deletions

View File

@ -70,6 +70,7 @@ namespace
const QString KEY_TOPLEVEL = SETTINGS_KEY("TopLevel"); const QString KEY_TOPLEVEL = SETTINGS_KEY("TopLevel");
const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY("SavePathHistory"); const QString KEY_SAVEPATHHISTORY = SETTINGS_KEY("SavePathHistory");
const char KEY_SAVEPATHHISTORYLENGTH[] = SETTINGS_KEY("SavePathHistoryLength"); const char KEY_SAVEPATHHISTORYLENGTH[] = SETTINGS_KEY("SavePathHistoryLength");
const QString KEY_REMEMBERLASTSAVEPATH = SETTINGS_KEY("RememberLastSavePath");
// just a shortcut // just a shortcut
inline SettingsStorage *settings() inline SettingsStorage *settings()
@ -114,7 +115,9 @@ AddNewTorrentDialog::AddNewTorrentDialog(const BitTorrent::AddTorrentParams &inP
m_ui->comboTTM->blockSignals(false); m_ui->comboTTM->blockSignals(false);
populateSavePathComboBox(); populateSavePathComboBox();
connect(m_ui->savePath, &FileSystemPathEdit::selectedPathChanged, this, &AddNewTorrentDialog::onSavePathChanged); 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) if (m_torrentParams.createSubfolder == TriStateBool::True)
m_ui->createSubfolderCheckBox->setChecked(true); m_ui->createSubfolderCheckBox->setChecked(true);
@ -453,9 +456,7 @@ void AddNewTorrentDialog::updateDiskSpaceLabel()
void AddNewTorrentDialog::onSavePathChanged(const QString &newPath) void AddNewTorrentDialog::onSavePathChanged(const QString &newPath)
{ {
// Toggle default save path setting checkbox visibility Q_UNUSED(newPath);
m_ui->defaultSavePathCheckBox->setChecked(false);
m_ui->defaultSavePathCheckBox->setVisible(QDir(newPath) != QDir(BitTorrent::Session::instance()->defaultSavePath()));
// Remember index // Remember index
m_oldIndex = m_ui->savePath->currentIndex(); m_oldIndex = m_ui->savePath->currentIndex();
updateDiskSpaceLabel(); updateDiskSpaceLabel();
@ -586,18 +587,21 @@ void AddNewTorrentDialog::renameSelectedFile()
void AddNewTorrentDialog::populateSavePathComboBox() void AddNewTorrentDialog::populateSavePathComboBox()
{ {
QString defSavePath = BitTorrent::Session::instance()->defaultSavePath();
m_ui->savePath->clear(); m_ui->savePath->clear();
m_ui->savePath->addItem(defSavePath);
QDir defaultSaveDir(defSavePath);
// Load save path history // Load save path history
foreach (const QString &savePath, settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList()) const QStringList savePathHistory {settings()->loadValue(KEY_SAVEPATHHISTORY).toStringList()};
if (QDir(savePath) != defaultSaveDir) for (const QString &savePath : savePathHistory)
m_ui->savePath->addItem(savePath); 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()) if (!m_torrentParams.savePath.isEmpty())
setSavePath(m_torrentParams.savePath); 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 &) void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
@ -650,10 +654,11 @@ void AddNewTorrentDialog::accept()
// Category // Category
m_torrentParams.category = m_ui->categoryComboBox->currentText(); m_torrentParams.category = m_ui->categoryComboBox->currentText();
if (m_ui->defaultCategoryCheckbox->isChecked()) if (m_ui->defaultCategoryCheckbox->isChecked())
settings()->storeValue(KEY_DEFAULTCATEGORY, m_torrentParams.category); settings()->storeValue(KEY_DEFAULTCATEGORY, m_torrentParams.category);
settings()->storeValue(KEY_REMEMBERLASTSAVEPATH, m_ui->checkBoxRememberLastSavePath->isChecked());
// Save file priorities // Save file priorities
if (m_contentModel) if (m_contentModel)
m_torrentParams.filePriorities = m_contentModel->model()->getFilePriorities(); m_torrentParams.filePriorities = m_contentModel->model()->getFilePriorities();
@ -666,8 +671,6 @@ void AddNewTorrentDialog::accept()
m_torrentParams.useAutoTMM = TriStateBool::False; m_torrentParams.useAutoTMM = TriStateBool::False;
m_torrentParams.savePath = savePath; m_torrentParams.savePath = savePath;
saveSavePathHistory(); saveSavePathHistory();
if (m_ui->defaultSavePathCheckBox->isChecked())
BitTorrent::Session::instance()->setDefaultSavePath(savePath);
} }
else { else {
m_torrentParams.useAutoTMM = TriStateBool::True; m_torrentParams.useAutoTMM = TriStateBool::True;
@ -807,7 +810,6 @@ void AddNewTorrentDialog::TMMChanged(int index)
m_ui->savePath->clear(); m_ui->savePath->clear();
QString savePath = BitTorrent::Session::instance()->categorySavePath(m_ui->categoryComboBox->currentText()); QString savePath = BitTorrent::Session::instance()->categorySavePath(m_ui->categoryComboBox->currentText());
m_ui->savePath->addItem(savePath); m_ui->savePath->addItem(savePath);
m_ui->defaultSavePathCheckBox->setVisible(false);
m_ui->adv_button->setChecked(true); m_ui->adv_button->setChecked(true);
m_ui->adv_button->setEnabled(false); m_ui->adv_button->setEnabled(false);
showAdvancedSettings(true); showAdvancedSettings(true);

View File

@ -62,9 +62,9 @@
<widget class="FileSystemPathComboEdit" name="savePath" native="true"/> <widget class="FileSystemPathComboEdit" name="savePath" native="true"/>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="defaultSavePathCheckBox"> <widget class="QCheckBox" name="checkBoxRememberLastSavePath">
<property name="text"> <property name="text">
<string>Set as default save path</string> <string>Remember last used save path</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -393,7 +393,7 @@
</customwidgets> </customwidgets>
<tabstops> <tabstops>
<tabstop>savePath</tabstop> <tabstop>savePath</tabstop>
<tabstop>defaultSavePathCheckBox</tabstop> <tabstop>checkBoxRememberLastSavePath</tabstop>
<tabstop>never_show_cb</tabstop> <tabstop>never_show_cb</tabstop>
<tabstop>adv_button</tabstop> <tabstop>adv_button</tabstop>
<tabstop>startTorrentCheckBox</tabstop> <tabstop>startTorrentCheckBox</tabstop>