Skip to content

Commit a035bca

Browse files
committed
Merge branch 'morewizardcleanup' into 'master'
Wizard: Clean up the existing installation page See merge request OpenMW/openmw!5198
2 parents a8c80a2 + 45db9ce commit a035bca

9 files changed

Lines changed: 171 additions & 225 deletions

File tree

apps/wizard/existinginstallationpage.cpp

Lines changed: 71 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,55 @@
99

1010
#include "mainwizard.hpp"
1111

12+
namespace
13+
{
14+
bool versionIsOK(QWidget* parent, const QString& directoryName)
15+
{
16+
const QFileInfoList infoList = QDir(directoryName).entryInfoList({ "Morrowind.bsa" });
17+
if (infoList.size() != 1)
18+
return false;
19+
20+
const qint64 actualFileSize = infoList.at(0).size();
21+
22+
// Size of Morrowind.bsa in Steam and GOG editions.
23+
constexpr qint64 expectedFileSize = 310459500;
24+
if (actualFileSize == expectedFileSize)
25+
return true;
26+
27+
QMessageBox msgBox(parent);
28+
msgBox.setWindowTitle(QObject::tr("Most recent Morrowind not detected"));
29+
msgBox.setIcon(QMessageBox::Warning);
30+
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
31+
msgBox.setDefaultButton(QMessageBox::No);
32+
msgBox.setText(
33+
QObject::tr("<br><b>There may be a more recent version of Morrowind available.</b><br><br>"
34+
"Do you wish to continue anyway?<br>"));
35+
return msgBox.exec() == QMessageBox::Yes;
36+
}
37+
}
38+
1239
Wizard::ExistingInstallationPage::ExistingInstallationPage(QWidget* parent)
1340
: QWizardPage(parent)
1441
{
1542
mWizard = qobject_cast<MainWizard*>(parent);
1643

1744
setupUi(this);
1845

46+
browseButton->setIcon(Misc::ScalableIcon::load(":folder"));
47+
connect(browseButton, &QPushButton::clicked, this, &ExistingInstallationPage::browseButtonClicked);
48+
1949
// Add a placeholder item to the list of installations
20-
QListWidgetItem* emptyItem = new QListWidgetItem(tr("No existing installations detected"));
50+
QListWidgetItem* emptyItem = new QListWidgetItem(tr("No existing installations detected"), installationsList);
2151
emptyItem->setFlags(Qt::NoItemFlags);
2252

23-
browseButton->setIcon(Misc::ScalableIcon::load(":folder"));
24-
25-
installationsList->insertItem(0, emptyItem);
53+
connect(installationsList, &QListWidget::currentTextChanged, this, &ExistingInstallationPage::textChanged);
54+
connect(installationsList, &QListWidget::itemSelectionChanged, this, &ExistingInstallationPage::completeChanged);
2655
}
2756

2857
void Wizard::ExistingInstallationPage::initializePage()
2958
{
3059
// Add the available installation paths
31-
QStringList paths(mWizard->mInstallations.keys());
60+
const QStringList paths(mWizard->mInstallations.keys());
3261

3362
// Hide the default item if there are installations to choose from
3463
installationsList->item(0)->setHidden(!paths.isEmpty());
@@ -37,14 +66,9 @@ void Wizard::ExistingInstallationPage::initializePage()
3766
{
3867
if (installationsList->findItems(path, Qt::MatchExactly).isEmpty())
3968
{
40-
QListWidgetItem* item = new QListWidgetItem(path);
41-
installationsList->addItem(item);
69+
installationsList->addItem(path);
4270
}
4371
}
44-
45-
connect(installationsList, &QListWidget::currentTextChanged, this, &ExistingInstallationPage::textChanged);
46-
47-
connect(installationsList, &QListWidget::itemSelectionChanged, this, &ExistingInstallationPage::completeChanged);
4872
}
4973

5074
bool Wizard::ExistingInstallationPage::validatePage()
@@ -53,77 +77,66 @@ bool Wizard::ExistingInstallationPage::validatePage()
5377
// It can be missing entirely
5478
// Or failed to be detected due to the target being a symlink
5579

56-
QString path(field(QLatin1String("installation.path")).toString());
80+
const QString path(field(QLatin1String("installation.path")).toString());
81+
QString& iniPath = mWizard->mInstallations[path].iniPath;
5782

58-
if (!QFile::exists(mWizard->mInstallations[path].iniPath))
59-
{
60-
QMessageBox msgBox;
61-
msgBox.setWindowTitle(tr("Error detecting Morrowind configuration"));
62-
msgBox.setIcon(QMessageBox::Warning);
63-
msgBox.setStandardButtons(QMessageBox::Cancel);
64-
msgBox.setText(
65-
QObject::tr("<br><b>Could not find Morrowind.ini</b><br><br>"
66-
"The Wizard needs to update settings in this file.<br><br>"
67-
"Press \"Browse...\" to specify the location manually.<br>"));
83+
if (QFile::exists(iniPath))
84+
return true;
6885

69-
QAbstractButton* browseButton2 = msgBox.addButton(QObject::tr("B&rowse..."), QMessageBox::ActionRole);
86+
QMessageBox msgBox(this);
87+
msgBox.setWindowTitle(tr("Error detecting Morrowind configuration"));
88+
msgBox.setIcon(QMessageBox::Warning);
89+
msgBox.setStandardButtons(QMessageBox::Cancel);
90+
msgBox.setText(
91+
tr("<br><b>Could not find Morrowind.ini</b><br><br>"
92+
"The Wizard needs to update settings in this file.<br><br>"
93+
"Press \"Browse...\" to specify the location manually.<br>"));
7094

71-
msgBox.exec();
95+
QAbstractButton* browseIniButton = msgBox.addButton(tr("B&rowse..."), QMessageBox::ActionRole);
7296

73-
QString iniFile;
74-
if (msgBox.clickedButton() == browseButton2)
75-
{
76-
iniFile = QFileDialog::getOpenFileName(this, QObject::tr("Select configuration file"), QDir::currentPath(),
77-
QString(tr("Morrowind configuration file (*.ini)")));
78-
}
97+
msgBox.exec();
7998

80-
if (iniFile.isEmpty())
81-
{
82-
return false; // Cancel was clicked;
83-
}
99+
if (msgBox.clickedButton() != browseIniButton)
100+
return false;
84101

85-
// A proper Morrowind.ini was selected, set it
86-
QFileInfo info(iniFile);
87-
mWizard->mInstallations[path].iniPath = info.absoluteFilePath();
88-
}
102+
const QString iniFile = QFileDialog::getOpenFileName(
103+
this, tr("Select configuration file"), QDir::currentPath(), tr("Morrowind configuration file (*.ini)"));
89104

105+
// Cancel was clicked
106+
if (iniFile.isEmpty())
107+
return false;
108+
109+
// A proper Morrowind.ini was selected, set it
110+
iniPath = QFileInfo(iniFile).absoluteFilePath();
90111
return true;
91112
}
92113

93-
void Wizard::ExistingInstallationPage::on_browseButton_clicked()
114+
void Wizard::ExistingInstallationPage::browseButtonClicked()
94115
{
95-
QString selectedFile
96-
= QFileDialog::getOpenFileName(this, tr("Select Morrowind.esm (located in Data Files)"), QDir::currentPath(),
97-
QString(tr("Morrowind master file (Morrowind.esm)")), nullptr, QFileDialog::DontResolveSymlinks);
116+
const QString selectedFile = QFileDialog::getOpenFileName(this, tr("Select Morrowind.esm (located in Data Files)"),
117+
QDir::currentPath(), tr("Morrowind master file (Morrowind.esm)"), nullptr, QFileDialog::DontResolveSymlinks);
98118

99119
if (selectedFile.isEmpty())
100120
return;
101121

102-
QFileInfo info(selectedFile);
103-
104-
if (!info.exists())
105-
return;
106-
107-
if (!mWizard->findFiles(QLatin1String("Morrowind"), info.absolutePath()))
122+
const QString path(QDir::toNativeSeparators(QFileInfo(selectedFile).absolutePath()));
123+
if (!mWizard->findFiles(QLatin1String("Morrowind"), path))
108124
{
109-
QMessageBox msgBox;
125+
QMessageBox msgBox(this);
110126
msgBox.setWindowTitle(tr("Error detecting Morrowind files"));
111127
msgBox.setIcon(QMessageBox::Warning);
112128
msgBox.setStandardButtons(QMessageBox::Ok);
113129
msgBox.setText(
114-
QObject::tr("<b>Morrowind.bsa</b> is missing!<br>"
115-
"Make sure your Morrowind installation is complete."));
130+
tr("<b>Morrowind.bsa</b> is missing!<br>"
131+
"Make sure your Morrowind installation is complete."));
116132
msgBox.exec();
117133
return;
118134
}
119135

120-
if (!versionIsOK(info.absolutePath()))
121-
{
136+
if (!versionIsOK(this, path))
122137
return;
123-
}
124138

125-
QString path(QDir::toNativeSeparators(info.absolutePath()));
126-
QList<QListWidgetItem*> items = installationsList->findItems(path, Qt::MatchExactly);
139+
const QList<QListWidgetItem*> items = installationsList->findItems(path, Qt::MatchExactly);
127140

128141
if (items.isEmpty())
129142
{
@@ -133,8 +146,7 @@ void Wizard::ExistingInstallationPage::on_browseButton_clicked()
133146
// Hide the default item
134147
installationsList->item(0)->setHidden(true);
135148

136-
QListWidgetItem* item = new QListWidgetItem(path);
137-
installationsList->addItem(item);
149+
QListWidgetItem* item = new QListWidgetItem(path, installationsList);
138150
installationsList->setCurrentItem(item); // Select it too
139151
}
140152
else
@@ -156,51 +168,10 @@ void Wizard::ExistingInstallationPage::textChanged(const QString& text)
156168

157169
bool Wizard::ExistingInstallationPage::isComplete() const
158170
{
159-
if (installationsList->selectionModel()->hasSelection())
160-
{
161-
return true;
162-
}
163-
else
164-
{
165-
return false;
166-
}
171+
return installationsList->selectionModel()->hasSelection();
167172
}
168173

169174
int Wizard::ExistingInstallationPage::nextId() const
170175
{
171176
return MainWizard::Page_LanguageSelection;
172177
}
173-
174-
bool Wizard::ExistingInstallationPage::versionIsOK(QString directoryName)
175-
{
176-
QDir directory = QDir(directoryName);
177-
QFileInfoList infoList = directory.entryInfoList(QStringList(QString("Morrowind.bsa")));
178-
if (infoList.size() == 1)
179-
{
180-
qint64 actualFileSize = infoList.at(0).size();
181-
const qint64 expectedFileSize = 310459500; // Size of Morrowind.bsa in Steam and GOG editions.
182-
183-
if (actualFileSize == expectedFileSize)
184-
{
185-
return true;
186-
}
187-
188-
QMessageBox msgBox;
189-
msgBox.setWindowTitle(QObject::tr("Most recent Morrowind not detected"));
190-
msgBox.setIcon(QMessageBox::Warning);
191-
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
192-
msgBox.setDefaultButton(QMessageBox::No);
193-
msgBox.setText(
194-
QObject::tr("<br><b>There may be a more recent version of Morrowind available.</b><br><br>"
195-
"Do you wish to continue anyway?<br>"));
196-
int ret = msgBox.exec();
197-
if (ret == QMessageBox::Yes)
198-
{
199-
return true;
200-
}
201-
202-
return false;
203-
}
204-
205-
return false;
206-
}

apps/wizard/existinginstallationpage.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ namespace Wizard
1818
bool validatePage() override;
1919

2020
private slots:
21-
void on_browseButton_clicked();
21+
void browseButtonClicked();
2222
void textChanged(const QString& text);
2323

2424
private:
2525
MainWizard* mWizard;
2626

27-
bool versionIsOK(QString directoryName);
28-
2927
protected:
3028
void initializePage() override;
3129
};

apps/wizard/installationpage.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ void Wizard::InstallationPage::showOldVersionDialog()
209209
QMessageBox msgBox;
210210
msgBox.setWindowTitle(tr("Morrowind Installation"));
211211
msgBox.setIcon(QMessageBox::Information);
212-
msgBox.setText(QObject::tr(
213-
"There may be a more recent version of Morrowind available.<br><br>Do you wish to continue anyway?"));
212+
msgBox.setText(
213+
QObject::tr("<br><b>There may be a more recent version of Morrowind available.</b><br><br>"
214+
"Do you wish to continue anyway?<br>"));
214215
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
215216
msgBox.setDefaultButton(QMessageBox::No);
216217

files/lang/wizard_de.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
212212
</context>
213213
<context>
214214
<name>QObject</name>
215-
<message>
216-
<source>&lt;br&gt;&lt;b&gt;Could not find Morrowind.ini&lt;/b&gt;&lt;br&gt;&lt;br&gt;The Wizard needs to update settings in this file.&lt;br&gt;&lt;br&gt;Press &quot;Browse...&quot; to specify the location manually.&lt;br&gt;</source>
217-
<translation type="unfinished"></translation>
218-
</message>
219-
<message>
220-
<source>B&amp;rowse...</source>
221-
<translation type="unfinished"></translation>
222-
</message>
223-
<message>
224-
<source>Select configuration file</source>
225-
<translation type="unfinished"></translation>
226-
</message>
227-
<message>
228-
<source>&lt;b&gt;Morrowind.bsa&lt;/b&gt; is missing!&lt;br&gt;Make sure your Morrowind installation is complete.</source>
229-
<translation type="unfinished"></translation>
230-
</message>
231215
<message>
232216
<source>&lt;br&gt;&lt;b&gt;There may be a more recent version of Morrowind available.&lt;/b&gt;&lt;br&gt;&lt;br&gt;Do you wish to continue anyway?&lt;br&gt;</source>
233217
<translation type="unfinished"></translation>
@@ -240,10 +224,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
240224
<source>Select a valid %1 installation media.&lt;br&gt;&lt;b&gt;Hint&lt;/b&gt;: make sure that it contains at least one &lt;b&gt;.cab&lt;/b&gt; file.</source>
241225
<translation type="unfinished"></translation>
242226
</message>
243-
<message>
244-
<source>There may be a more recent version of Morrowind available.&lt;br&gt;&lt;br&gt;Do you wish to continue anyway?</source>
245-
<translation type="unfinished"></translation>
246-
</message>
247227
</context>
248228
<context>
249229
<name>Wizard::ComponentSelectionPage</name>
@@ -333,6 +313,22 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
333313
<source>Error detecting Morrowind files</source>
334314
<translation type="unfinished"></translation>
335315
</message>
316+
<message>
317+
<source>&lt;br&gt;&lt;b&gt;Could not find Morrowind.ini&lt;/b&gt;&lt;br&gt;&lt;br&gt;The Wizard needs to update settings in this file.&lt;br&gt;&lt;br&gt;Press &quot;Browse...&quot; to specify the location manually.&lt;br&gt;</source>
318+
<translation type="unfinished"></translation>
319+
</message>
320+
<message>
321+
<source>B&amp;rowse...</source>
322+
<translation type="unfinished"></translation>
323+
</message>
324+
<message>
325+
<source>Select configuration file</source>
326+
<translation type="unfinished"></translation>
327+
</message>
328+
<message>
329+
<source>&lt;b&gt;Morrowind.bsa&lt;/b&gt; is missing!&lt;br&gt;Make sure your Morrowind installation is complete.</source>
330+
<translation type="unfinished"></translation>
331+
</message>
336332
</context>
337333
<context>
338334
<name>Wizard::InstallationPage</name>

files/lang/wizard_en.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -212,22 +212,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
212212
</context>
213213
<context>
214214
<name>QObject</name>
215-
<message>
216-
<source>&lt;br&gt;&lt;b&gt;Could not find Morrowind.ini&lt;/b&gt;&lt;br&gt;&lt;br&gt;The Wizard needs to update settings in this file.&lt;br&gt;&lt;br&gt;Press &quot;Browse...&quot; to specify the location manually.&lt;br&gt;</source>
217-
<translation></translation>
218-
</message>
219-
<message>
220-
<source>B&amp;rowse...</source>
221-
<translation></translation>
222-
</message>
223-
<message>
224-
<source>Select configuration file</source>
225-
<translation></translation>
226-
</message>
227-
<message>
228-
<source>&lt;b&gt;Morrowind.bsa&lt;/b&gt; is missing!&lt;br&gt;Make sure your Morrowind installation is complete.</source>
229-
<translation></translation>
230-
</message>
231215
<message>
232216
<source>Most recent Morrowind not detected</source>
233217
<translation></translation>
@@ -240,10 +224,6 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
240224
<source>Select a valid %1 installation media.&lt;br&gt;&lt;b&gt;Hint&lt;/b&gt;: make sure that it contains at least one &lt;b&gt;.cab&lt;/b&gt; file.</source>
241225
<translation></translation>
242226
</message>
243-
<message>
244-
<source>There may be a more recent version of Morrowind available.&lt;br&gt;&lt;br&gt;Do you wish to continue anyway?</source>
245-
<translation></translation>
246-
</message>
247227
</context>
248228
<context>
249229
<name>Wizard::ComponentSelectionPage</name>
@@ -333,6 +313,22 @@ to default Morrowind fonts. Check this box if you still prefer original fonts ov
333313
<source>Error detecting Morrowind files</source>
334314
<translation></translation>
335315
</message>
316+
<message>
317+
<source>&lt;br&gt;&lt;b&gt;Could not find Morrowind.ini&lt;/b&gt;&lt;br&gt;&lt;br&gt;The Wizard needs to update settings in this file.&lt;br&gt;&lt;br&gt;Press &quot;Browse...&quot; to specify the location manually.&lt;br&gt;</source>
318+
<translation></translation>
319+
</message>
320+
<message>
321+
<source>B&amp;rowse...</source>
322+
<translation></translation>
323+
</message>
324+
<message>
325+
<source>Select configuration file</source>
326+
<translation></translation>
327+
</message>
328+
<message>
329+
<source>&lt;b&gt;Morrowind.bsa&lt;/b&gt; is missing!&lt;br&gt;Make sure your Morrowind installation is complete.</source>
330+
<translation></translation>
331+
</message>
336332
</context>
337333
<context>
338334
<name>Wizard::InstallationPage</name>

0 commit comments

Comments
 (0)