From c975a192dd68ef6008f1610dbcdeed74fc0f1b46 Mon Sep 17 00:00:00 2001
From: Alexei Kotov
Date: Sat, 14 Mar 2026 22:17:58 +0300
Subject: [PATCH] More wizard cleanup I can't be bothered to categorize
This also fixes language repopulation when you return to the language selection page.
---
apps/wizard/conclusionpage.cpp | 9 +++--
apps/wizard/installationtargetpage.cpp | 14 ++------
apps/wizard/languageselectionpage.cpp | 11 +++---
apps/wizard/languageselectionpage.hpp | 3 --
apps/wizard/mainwizard.cpp | 48 +++++++++-----------------
apps/wizard/mainwizard.hpp | 5 ++-
apps/wizard/methodselectionpage.cpp | 1 -
7 files changed, 30 insertions(+), 61 deletions(-)
diff --git a/apps/wizard/conclusionpage.cpp b/apps/wizard/conclusionpage.cpp
index 938535aca0..4d6db673f0 100644
--- a/apps/wizard/conclusionpage.cpp
+++ b/apps/wizard/conclusionpage.cpp
@@ -15,8 +15,9 @@ Wizard::ConclusionPage::ConclusionPage(QWidget* parent)
void Wizard::ConclusionPage::initializePage()
{
+ const bool retailDisc = field(QLatin1String("installation.retailDisc")).toBool();
// Write the path to openmw.cfg
- if (field(QLatin1String("installation.retailDisc")).toBool() == true)
+ if (retailDisc)
{
const QString path(field(QLatin1String("installation.path")).toString());
mWizard->addInstallation(path);
@@ -24,17 +25,15 @@ void Wizard::ConclusionPage::initializePage()
if (!mWizard->mError)
{
- if ((field(QLatin1String("installation.retailDisc")).toBool() == true)
- || (field(QLatin1String("installation.import-settings")).toBool() == true))
+ if (retailDisc || field(QLatin1String("installation.import-settings")).toBool())
{
- qDebug() << "IMPORT SETTINGS";
mWizard->runSettingsImporter();
}
}
if (!mWizard->mError)
{
- if (field(QLatin1String("installation.retailDisc")).toBool() == true)
+ if (retailDisc)
{
textLabel->setText(
tr("
The OpenMW Wizard successfully installed Morrowind on your "
diff --git a/apps/wizard/installationtargetpage.cpp b/apps/wizard/installationtargetpage.cpp
index f3da85f473..f399935f97 100644
--- a/apps/wizard/installationtargetpage.cpp
+++ b/apps/wizard/installationtargetpage.cpp
@@ -1,13 +1,11 @@
#include "installationtargetpage.hpp"
-#include
-
#include
#include
#include
#include
-#include
+#include
#include
#include "mainwizard.hpp"
@@ -28,10 +26,7 @@ Wizard::InstallationTargetPage::InstallationTargetPage(QWidget* parent, const Fi
void Wizard::InstallationTargetPage::initializePage()
{
- QString path(QFile::decodeName(Files::pathToUnicodeString(mCfgMgr.getUserDataPath()).c_str()));
- path.append(QDir::separator() + QLatin1String("basedata"));
-
- const QDir dir(path);
+ const QDir dir(Files::pathToQString(mCfgMgr.getUserDataPath() / "basedata"));
targetLineEdit->setText(QDir::toNativeSeparators(dir.absolutePath()));
}
@@ -101,10 +96,7 @@ void Wizard::InstallationTargetPage::browseButtonClicked()
qDebug() << selectedPath;
const QFileInfo info(selectedPath);
- if (!info.exists())
- return;
-
- if (info.isWritable())
+ if (info.exists() && info.isWritable())
targetLineEdit->setText(info.absoluteFilePath());
}
diff --git a/apps/wizard/languageselectionpage.cpp b/apps/wizard/languageselectionpage.cpp
index 500edc6c73..ed5faef196 100644
--- a/apps/wizard/languageselectionpage.cpp
+++ b/apps/wizard/languageselectionpage.cpp
@@ -14,15 +14,12 @@ Wizard::LanguageSelectionPage::LanguageSelectionPage(QWidget* parent)
flagIcon->setIcon(Misc::ScalableIcon::load(":preferences-desktop-locale"));
registerField(QLatin1String("installation.language"), languageComboBox, "currentData", "currentDataChanged");
-}
-void Wizard::LanguageSelectionPage::initializePage()
-{
- const QVector> languages = { { "English", tr("English") }, { "French", tr("French") },
- { "German", tr("German") }, { "Italian", tr("Italian") }, { "Polish", tr("Polish") },
- { "Russian", tr("Russian") }, { "Spanish", tr("Spanish") } };
+ const QVector> languages = { { tr("English"), "English" }, { tr("French"), "French" },
+ { tr("German"), "German" }, { tr("Italian"), "Italian" }, { tr("Polish"), "Polish" },
+ { tr("Russian"), "Russian" }, { tr("Spanish"), "Spanish" } };
- for (const auto& [name, localizedName] : languages)
+ for (const auto& [localizedName, name] : languages)
{
languageComboBox->addItem(localizedName, name);
}
diff --git a/apps/wizard/languageselectionpage.hpp b/apps/wizard/languageselectionpage.hpp
index 93ec630a47..e01e83be17 100644
--- a/apps/wizard/languageselectionpage.hpp
+++ b/apps/wizard/languageselectionpage.hpp
@@ -23,9 +23,6 @@ namespace Wizard
private:
MainWizard* mWizard;
-
- protected:
- void initializePage() override;
};
}
diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp
index e4c1a99741..62eb6fb0b0 100644
--- a/apps/wizard/mainwizard.cpp
+++ b/apps/wizard/mainwizard.cpp
@@ -1,5 +1,7 @@
#include "mainwizard.hpp"
+#include
+
#include
#include
#include
@@ -25,15 +27,10 @@
#include "installationpage.hpp"
#endif
-#include
-
-using namespace Process;
-
Wizard::MainWizard::MainWizard(Files::ConfigurationManager&& cfgMgr, QWidget* parent)
: QWizard(parent)
- , mInstallations()
, mCfgMgr(cfgMgr)
- , mError(false)
+ , mImporterInvoker(new Process::ProcessInvoker())
, mGameSettings(mCfgMgr)
{
#ifndef Q_OS_MAC
@@ -49,10 +46,6 @@ Wizard::MainWizard::MainWizard(Files::ConfigurationManager&& cfgMgr, QWidget* pa
// Set the property for comboboxes to the text instead of index
setDefaultProperty("QComboBox", "currentText", "currentIndexChanged");
- mImporterInvoker = new ProcessInvoker();
-
- connect(mImporterInvoker->getProcess(), &QProcess::started, this, &MainWizard::importerStarted);
-
connect(mImporterInvoker->getProcess(), qOverload(&QProcess::finished), this,
&MainWizard::importerFinished);
@@ -73,10 +66,7 @@ Wizard::MainWizard::MainWizard(Files::ConfigurationManager&& cfgMgr, QWidget* pa
}
}
-Wizard::MainWizard::~MainWizard()
-{
- delete mImporterInvoker;
-}
+Wizard::MainWizard::~MainWizard() = default;
void Wizard::MainWizard::setupGameSettings()
{
@@ -109,10 +99,9 @@ void Wizard::MainWizard::setupGameSettings()
Misc::ensureUtf8Encoding(stream);
mGameSettings.readUserFile(stream, QFileInfo(path).dir().path());
+ file.close();
}
- file.close();
-
// Now the rest
const QStringList paths = Files::getActiveConfigPathsQString(mCfgMgr);
@@ -138,15 +127,15 @@ void Wizard::MainWizard::setupGameSettings()
Misc::ensureUtf8Encoding(stream);
mGameSettings.readFile(stream, QFileInfo(path2).dir().path());
+ file.close();
}
- file.close();
}
}
void Wizard::MainWizard::setupLauncherSettings()
{
- QString path(Files::pathToQString(mCfgMgr.getUserConfigPath()));
- path.append(QLatin1String(Config::LauncherSettings::sLauncherConfigFileName));
+ const std::filesystem::path configPath = mCfgMgr.getUserConfigPath();
+ const QString path(Files::pathToQString(configPath / Config::LauncherSettings::sLauncherConfigFileName));
const QString message(
tr("Could not open %1 for reading
"
@@ -175,8 +164,6 @@ void Wizard::MainWizard::setupLauncherSettings()
mLauncherSettings.readFile(stream);
}
-
- file.close();
}
void Wizard::MainWizard::setupInstallations()
@@ -194,6 +181,7 @@ void Wizard::MainWizard::runSettingsImporter()
writeSettings();
const QString path(field(QLatin1String("installation.path")).toString());
+ const bool retailDisc(field(QLatin1String("installation.retailDisc")).toBool());
QFile file(Files::getUserConfigPathQString(mCfgMgr));
@@ -201,8 +189,7 @@ void Wizard::MainWizard::runSettingsImporter()
QStringList arguments;
// Import plugin selection?
- if (field(QLatin1String("installation.retailDisc")).toBool() == true
- || field(QLatin1String("installation.import-addons")).toBool() == true)
+ if (retailDisc || field(QLatin1String("installation.import-addons")).toBool())
arguments.append(QLatin1String("--game-files"));
arguments.append(QLatin1String("--encoding"));
@@ -223,15 +210,15 @@ void Wizard::MainWizard::runSettingsImporter()
}
// Import fonts
- if (field(QLatin1String("installation.import-fonts")).toBool() == true)
+ if (field(QLatin1String("installation.import-fonts")).toBool())
arguments.append(QLatin1String("--fonts"));
// Now the paths
arguments.append(QLatin1String("--ini"));
- if (field(QLatin1String("installation.retailDisc")).toBool() == true)
+ if (retailDisc)
{
- arguments.append(path + QDir::separator() + QLatin1String("Morrowind.ini"));
+ arguments.append(QDir(path).filePath(QLatin1String("Morrowind.ini")));
}
else
{
@@ -248,7 +235,7 @@ void Wizard::MainWizard::runSettingsImporter()
void Wizard::MainWizard::addInstallation(const QString& path)
{
qDebug() << "add installation in: " << path;
- Installation install; // = new Installation();
+ Installation install;
install.hasMorrowind = findFiles(QLatin1String("Morrowind"), path);
install.hasTribunal = findFiles(QLatin1String("Tribunal"), path);
@@ -290,8 +277,6 @@ void Wizard::MainWizard::setupPages()
setStartId(Page_Intro);
}
-void Wizard::MainWizard::importerStarted() {}
-
void Wizard::MainWizard::importerFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
if (exitCode != 0 || exitStatus == QProcess::CrashExit)
@@ -430,7 +415,8 @@ bool Wizard::MainWizard::findFiles(const QString& name, const QString& path)
if (!dir.exists())
return false;
+ const QStringList entries = dir.entryList();
// TODO: add MIME handling to make sure the files are real
- return (dir.entryList().contains(name + QLatin1String(".esm"), Qt::CaseInsensitive)
- && dir.entryList().contains(name + QLatin1String(".bsa"), Qt::CaseInsensitive));
+ return entries.contains(name + QLatin1String(".esm"), Qt::CaseInsensitive)
+ && entries.contains(name + QLatin1String(".bsa"), Qt::CaseInsensitive);
}
diff --git a/apps/wizard/mainwizard.hpp b/apps/wizard/mainwizard.hpp
index 6e95fa0c13..e8adf60814 100644
--- a/apps/wizard/mainwizard.hpp
+++ b/apps/wizard/mainwizard.hpp
@@ -56,9 +56,9 @@ namespace Wizard
Files::ConfigurationManager mCfgMgr;
- Process::ProcessInvoker* mImporterInvoker;
+ std::unique_ptr mImporterInvoker;
- bool mError;
+ bool mError{ false };
private:
void setupGameSettings();
@@ -73,7 +73,6 @@ namespace Wizard
private slots:
- void importerStarted();
void importerFinished(int exitCode, QProcess::ExitStatus exitStatus);
void accept() override;
diff --git a/apps/wizard/methodselectionpage.cpp b/apps/wizard/methodselectionpage.cpp
index 505dc4cc1f..579c28675a 100644
--- a/apps/wizard/methodselectionpage.cpp
+++ b/apps/wizard/methodselectionpage.cpp
@@ -20,7 +20,6 @@ Wizard::MethodSelectionPage::MethodSelectionPage(QWidget* parent)
#ifndef OPENMW_USE_UNSHIELD
retailDiscRadioButton->setEnabled(false);
existingLocationRadioButton->setChecked(true);
- buyLinkButton->released();
#endif
QFont font = existingLocationRadioButton->font();