From bbab59f68112278bb23ff3bdc69737515b916667 Mon Sep 17 00:00:00 2001 From: Tannin Date: Fri, 27 May 2016 15:51:01 +0200 Subject: [PATCH] fixed handling of base dir in settings dialog (and fixed the tab order in the settings dialog) --- src/settings.cpp | 33 +++++++++---------------------- src/settingsdialog.cpp | 43 ++++++++++++++++++++++++++++++++++++----- src/settingsdialog.h | 3 +++ src/settingsdialog.ui | 44 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 29 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index a0625c4c..d9fa833d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -224,8 +224,7 @@ QString Settings::getConfigurablePath(const QString &key, bool resolve) const { QString result = QDir::fromNativeSeparators( - m_Settings.value(QString("settings/") + key, - qApp->property("dataPath").toString() + "/" + def) + m_Settings.value(QString("settings/") + key, QString("%BASE_DIR%/") + def) .toString()); if (resolve) { result.replace("%BASE_DIR%", getBaseDirectory()); @@ -677,12 +676,7 @@ Settings::PathsTab::PathsTab(Settings *parent, SettingsDialog &dialog) std::make_pair(m_overwriteDirEdit, m_parent->getOverwriteDirectory(false)) }) { QString storePath = baseDir.relativeFilePath(dir.second); - qDebug("%s -> %s", qPrintable(dir.second), qPrintable(storePath)); - if (storePath.startsWith("..") || QDir::isAbsolutePath(storePath)) { - storePath = dir.second; - } else { - storePath = QString("%BASE_DIR%/") + storePath; - } + storePath = dir.second; dir.first->setText(storePath); } } @@ -693,20 +687,6 @@ void Settings::PathsTab::update() QString basePath = m_parent->getBaseDirectory(); - if ((QDir::fromNativeSeparators(m_modDirEdit->text()) - != QDir::fromNativeSeparators(m_parent->getModDirectory())) - && (QMessageBox::question( - nullptr, tr("Confirm"), - tr("Changing the mod directory affects all your profiles! " - "Mods not present (or named differently) in the new location " - "will be disabled in all profiles. " - "There is no way to undo this unless you backed up your " - "profiles manually. Proceed?"), - QMessageBox::Yes | QMessageBox::No) - == QMessageBox::No)) { - m_modDirEdit->setText(m_parent->getModDirectory()); - } - for (const Directory &dir :{ Directory{m_downloadDirEdit->text(), "download_directory", AppConfig::downloadPath()}, Directory{m_cacheDirEdit->text(), "cache_directory", AppConfig::cachePath()}, @@ -727,8 +707,6 @@ void Settings::PathsTab::update() QDir().mkpath(realPath); } - qDebug("%s -> %s", qPrintable(path), qPrintable(realPath)); - if (QFileInfo(realPath) != QFileInfo(basePath + "/" + QString::fromStdWString(defaultName))) { m_Settings.setValue(settingsKey, path); @@ -736,6 +714,13 @@ void Settings::PathsTab::update() m_Settings.remove(settingsKey); } } + + if (QFileInfo(m_baseDirEdit->text()) != + QFileInfo(qApp->property("dataPath").toString())) { + m_Settings.setValue("Settings/base_directory", m_baseDirEdit->text()); + } else { + m_Settings.remove("Settings/base_directory"); + } } Settings::NexusTab::NexusTab(Settings *parent, SettingsDialog &dialog) diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 0d86018c..62134c9b 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -65,6 +65,23 @@ void SettingsDialog::addPlugins(const std::vector &plugins) void SettingsDialog::accept() { + QString newModPath = ui->modDirEdit->text(); + newModPath.replace("%BASE_DIR%", ui->baseDirEdit->text()); + + if ((QDir::fromNativeSeparators(newModPath) != + QDir::fromNativeSeparators( + Settings::instance().getModDirectory(true))) && + (QMessageBox::question( + nullptr, tr("Confirm"), + tr("Changing the mod directory affects all your profiles! " + "Mods not present (or named differently) in the new location " + "will be disabled in all profiles. " + "There is no way to undo this unless you backed up your " + "profiles manually. Proceed?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) { + return; + } + storeSettings(ui->pluginsList->currentItem()); TutorableDialog::accept(); } @@ -112,7 +129,10 @@ void SettingsDialog::on_browseBaseDirBtn_clicked() void SettingsDialog::on_browseDownloadDirBtn_clicked() { - QString temp = QFileDialog::getExistingDirectory(this, tr("Select download directory"), ui->downloadDirEdit->text()); + QString searchPath = ui->downloadDirEdit->text(); + searchPath.replace("%BASE_DIR%", ui->baseDirEdit->text()); + + QString temp = QFileDialog::getExistingDirectory(this, tr("Select download directory"), searchPath); if (!temp.isEmpty()) { ui->downloadDirEdit->setText(temp); } @@ -120,7 +140,10 @@ void SettingsDialog::on_browseDownloadDirBtn_clicked() void SettingsDialog::on_browseModDirBtn_clicked() { - QString temp = QFileDialog::getExistingDirectory(this, tr("Select mod directory"), ui->modDirEdit->text()); + QString searchPath = ui->modDirEdit->text(); + searchPath.replace("%BASE_DIR%", ui->baseDirEdit->text()); + + QString temp = QFileDialog::getExistingDirectory(this, tr("Select mod directory"), searchPath); if (!temp.isEmpty()) { ui->modDirEdit->setText(temp); } @@ -128,7 +151,10 @@ void SettingsDialog::on_browseModDirBtn_clicked() void SettingsDialog::on_browseCacheDirBtn_clicked() { - QString temp = QFileDialog::getExistingDirectory(this, tr("Select cache directory"), ui->cacheDirEdit->text()); + QString searchPath = ui->cacheDirEdit->text(); + searchPath.replace("%BASE_DIR%", ui->baseDirEdit->text()); + + QString temp = QFileDialog::getExistingDirectory(this, tr("Select cache directory"), searchPath); if (!temp.isEmpty()) { ui->cacheDirEdit->setText(temp); } @@ -136,7 +162,10 @@ void SettingsDialog::on_browseCacheDirBtn_clicked() void SettingsDialog::on_browseProfilesDirBtn_clicked() { - QString temp = QFileDialog::getExistingDirectory(this, tr("Select profiles directory"), ui->profilesDirEdit->text()); + QString searchPath = ui->profilesDirEdit->text(); + searchPath.replace("%BASE_DIR%", ui->baseDirEdit->text()); + + QString temp = QFileDialog::getExistingDirectory(this, tr("Select profiles directory"), searchPath); if (!temp.isEmpty()) { ui->profilesDirEdit->setText(temp); } @@ -144,7 +173,10 @@ void SettingsDialog::on_browseProfilesDirBtn_clicked() void SettingsDialog::on_browseOverwriteDirBtn_clicked() { - QString temp = QFileDialog::getExistingDirectory(this, tr("Select overwrite directory"), ui->overwriteDirEdit->text()); + QString searchPath = ui->overwriteDirEdit->text(); + searchPath.replace("%BASE_DIR%", ui->baseDirEdit->text()); + + QString temp = QFileDialog::getExistingDirectory(this, tr("Select overwrite directory"), searchPath); if (!temp.isEmpty()) { ui->overwriteDirEdit->setText(temp); } @@ -222,3 +254,4 @@ void SettingsDialog::on_clearCacheButton_clicked() QDir(Settings::instance().getCacheDirectory()).removeRecursively(); NexusInterface::instance()->clearCache(); } + diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 658fbce4..e9d995d3 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -87,6 +87,9 @@ private slots: private: Ui::SettingsDialog *ui; + }; + + #endif // WORKAROUNDDIALOG_H diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 1f751da8..6ae415d1 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -1026,6 +1026,50 @@ For the other games this is not a sufficient replacement for AI! + + languageBox + styleBox + logLevelBox + usePrereleaseBox + compactBox + showMetaBox + resetDialogsButton + categoriesBtn + baseDirEdit + browseBaseDirBtn + downloadDirEdit + browseDownloadDirBtn + modDirEdit + browseModDirBtn + cacheDirEdit + browseCacheDirBtn + profilesDirEdit + browseProfilesDirBtn + overwriteDirEdit + browseOverwriteDirBtn + loginCheckBox + usernameEdit + passwordEdit + clearCacheButton + offlineBox + proxyBox + associateButton + knownServersList + preferredServersList + steamUserEdit + steamPassEdit + pluginsList + pluginSettingsList + pluginBlacklist + appIDEdit + mechanismBox + nmmVersionEdit + hideUncheckedBox + forceEnableBox + displayForeignBox + bsaDateBtn + tabWidget +