Refactor config loading/saving for the runtime config dialog to avoid code duplication.

This commit is contained in:
Dave Page
2020-07-11 16:41:31 +05:30
committed by Akshay Joshi
parent 6855ac1d5e
commit 5ac656c638
4 changed files with 44 additions and 114 deletions
+2 -28
View File
@@ -64,45 +64,19 @@ void MenuActions::onCopyUrl()
// Show the config dialogue
void MenuActions::onConfig()
{
QSettings settings;
bool ok;
ConfigWindow *dlg = new ConfigWindow();
dlg->setWindowTitle(QString(tr("%1 Configuration")).arg(PGA_APP_NAME));
dlg->setBrowserCommand(settings.value("BrowserCommand").toString());
dlg->setFixedPort(settings.value("FixedPort").toBool());
dlg->setPortNumber(settings.value("PortNumber").toInt());
dlg->setOpenTabAtStartup(settings.value("OpenTabAtStartup", true).toBool());
dlg->setPythonPath(settings.value("PythonPath").toString());
dlg->setApplicationPath(settings.value("ApplicationPath").toString());
dlg->LoadSettings();
dlg->setModal(true);
ok = dlg->exec();
QString browsercommand = dlg->getBrowserCommand();
bool fixedport = dlg->getFixedPort();
int portnumber = dlg->getPortNumber();
bool opentabatstartup = dlg->getOpenTabAtStartup();
QString pythonpath = dlg->getPythonPath();
QString applicationpath = dlg->getApplicationPath();
if (ok)
{
bool needRestart = (settings.value("FixedPort").toBool() != fixedport ||
settings.value("PortNumber").toInt() != portnumber ||
settings.value("PythonPath").toString() != pythonpath ||
settings.value("ApplicationPath").toString() != applicationpath);
settings.setValue("BrowserCommand", browsercommand);
settings.setValue("FixedPort", fixedport);
settings.setValue("PortNumber", portnumber);
settings.setValue("OpenTabAtStartup", opentabatstartup);
settings.setValue("PythonPath", pythonpath);
settings.setValue("ApplicationPath", applicationpath);
bool needRestart = dlg->SaveSettings();
if (needRestart && QMessageBox::Yes == QMessageBox::question(Q_NULLPTR, tr("Shut down server?"), QString(tr("The %1 server must be restarted for changes to take effect. Do you want to shut down the server now?")).arg(PGA_APP_NAME), QMessageBox::Yes | QMessageBox::No))
{
exit(0);
}
}
}