Skip to content

Commit

Permalink
Fix settings path code
Browse files Browse the repository at this point in the history
  • Loading branch information
loganmc10 committed Aug 1, 2023
1 parent e9c9025 commit bef5658
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 5 additions & 4 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,11 @@ MainWindow::MainWindow(QWidget *parent) :
updateOpenRecent();
updateGB(ui);

if (!settings->contains("configDirPath"))
settings->setValue("configDirPath", "$CONFIG_PATH$");
// migrate from old $CONFIG_PATH$ default
if (settings->value("configDirPath").toString().startsWith("$"))
{
settings->remove("configDirPath");
}

#ifdef CONFIG_DIR_PATH
settings->setValue("configDirPath", CONFIG_DIR_PATH);
Expand Down Expand Up @@ -932,8 +935,6 @@ void MainWindow::loadCoreLib()
ConfigGetSharedDataFilepath = (ptr_ConfigGetSharedDataFilepath) osal_dynlib_getproc(coreLib, "ConfigGetSharedDataFilepath");

QString qtConfigDir = settings->value("configDirPath").toString();
qtConfigDir.replace("$APP_PATH$", QCoreApplication::applicationDirPath());
qtConfigDir.replace("$CONFIG_PATH$", ConfigGetUserConfigPath());

if (!qtConfigDir.isEmpty())
(*CoreStartup)(CORE_API_VERSION, qtConfigDir.toUtf8().constData() /*Config dir*/, QCoreApplication::applicationDirPath().toUtf8().constData(), (char*)"Core", DebugCallback, NULL, NULL);
Expand Down
11 changes: 10 additions & 1 deletion settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ void SettingsDialog::handleConfigButton()
}
}

void SettingsDialog::handleAppPathButton()
{
configPath->setText(QCoreApplication::applicationDirPath());
w->getSettings()->setValue("configDirPath", QCoreApplication::applicationDirPath());
}

void SettingsDialog::handleClearConfigButton()
{
configPath->setText("");
Expand All @@ -41,14 +47,17 @@ void SettingsDialog::initStuff()
QPushButton *configButton = new QPushButton("Set Path", this);
connect(configButton, SIGNAL (released()),this, SLOT (handleConfigButton()));
connect(configPath, SIGNAL (editingFinished()),this, SLOT (handleConfigEdit()));
QPushButton *appPathButton = new QPushButton("Use Application Path", this);
connect(appPathButton, SIGNAL (released()),this, SLOT (handleAppPathButton()));
QPushButton *clearConfigButton = new QPushButton("Clear", this);
connect(clearConfigButton, SIGNAL (released()),this, SLOT (handleClearConfigButton()));
configPath->setStyleSheet("border: 1px solid; padding: 10px");
layout->addWidget(note,0,0,1,-1);
layout->addWidget(configLabel,1,0);
layout->addWidget(configPath,1,1);
layout->addWidget(configButton,1,2);
layout->addWidget(clearConfigButton,1,3);
layout->addWidget(appPathButton,1,3);
layout->addWidget(clearConfigButton,1,4);

#ifdef CONFIG_DIR_PATH
configPath->setEnabled(false);
Expand Down
1 change: 1 addition & 0 deletions settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SettingsDialog : public QDialog
void closeEvent(QCloseEvent *event);
private slots:
void handleConfigButton();
void handleAppPathButton();
void handleClearConfigButton();
void handleConfigEdit();
private:
Expand Down

0 comments on commit bef5658

Please sign in to comment.