Skip to content

Commit

Permalink
fixed handling of base dir in settings dialog (and fixed the tab orde…
Browse files Browse the repository at this point in the history
…r in the settings dialog)
  • Loading branch information
TanninOne committed May 27, 2016
1 parent bfbb190 commit bbab59f
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 29 deletions.
33 changes: 9 additions & 24 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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()},
Expand All @@ -727,15 +707,20 @@ 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);
} else {
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)
Expand Down
43 changes: 38 additions & 5 deletions src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ void SettingsDialog::addPlugins(const std::vector<IPlugin*> &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();
}
Expand Down Expand Up @@ -112,39 +129,54 @@ 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);
}
}

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);
}
}

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);
}
}

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);
}
}

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);
}
Expand Down Expand Up @@ -222,3 +254,4 @@ void SettingsDialog::on_clearCacheButton_clicked()
QDir(Settings::instance().getCacheDirectory()).removeRecursively();
NexusInterface::instance()->clearCache();
}

3 changes: 3 additions & 0 deletions src/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ private slots:

private:
Ui::SettingsDialog *ui;

};



#endif // WORKAROUNDDIALOG_H
44 changes: 44 additions & 0 deletions src/settingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,50 @@ For the other games this is not a sufficient replacement for AI!</string>
</item>
</layout>
</widget>
<tabstops>
<tabstop>languageBox</tabstop>
<tabstop>styleBox</tabstop>
<tabstop>logLevelBox</tabstop>
<tabstop>usePrereleaseBox</tabstop>
<tabstop>compactBox</tabstop>
<tabstop>showMetaBox</tabstop>
<tabstop>resetDialogsButton</tabstop>
<tabstop>categoriesBtn</tabstop>
<tabstop>baseDirEdit</tabstop>
<tabstop>browseBaseDirBtn</tabstop>
<tabstop>downloadDirEdit</tabstop>
<tabstop>browseDownloadDirBtn</tabstop>
<tabstop>modDirEdit</tabstop>
<tabstop>browseModDirBtn</tabstop>
<tabstop>cacheDirEdit</tabstop>
<tabstop>browseCacheDirBtn</tabstop>
<tabstop>profilesDirEdit</tabstop>
<tabstop>browseProfilesDirBtn</tabstop>
<tabstop>overwriteDirEdit</tabstop>
<tabstop>browseOverwriteDirBtn</tabstop>
<tabstop>loginCheckBox</tabstop>
<tabstop>usernameEdit</tabstop>
<tabstop>passwordEdit</tabstop>
<tabstop>clearCacheButton</tabstop>
<tabstop>offlineBox</tabstop>
<tabstop>proxyBox</tabstop>
<tabstop>associateButton</tabstop>
<tabstop>knownServersList</tabstop>
<tabstop>preferredServersList</tabstop>
<tabstop>steamUserEdit</tabstop>
<tabstop>steamPassEdit</tabstop>
<tabstop>pluginsList</tabstop>
<tabstop>pluginSettingsList</tabstop>
<tabstop>pluginBlacklist</tabstop>
<tabstop>appIDEdit</tabstop>
<tabstop>mechanismBox</tabstop>
<tabstop>nmmVersionEdit</tabstop>
<tabstop>hideUncheckedBox</tabstop>
<tabstop>forceEnableBox</tabstop>
<tabstop>displayForeignBox</tabstop>
<tabstop>bsaDateBtn</tabstop>
<tabstop>tabWidget</tabstop>
</tabstops>
<resources>
<include location="resources.qrc"/>
</resources>
Expand Down

0 comments on commit bbab59f

Please sign in to comment.