2013-12-08 20:35:57 +00:00
|
|
|
#include "existinginstallationpage.hpp"
|
|
|
|
|
2013-12-13 12:38:49 +00:00
|
|
|
#include <QDebug>
|
2013-12-24 22:09:31 +00:00
|
|
|
#include <QMessageBox>
|
2013-12-13 12:38:49 +00:00
|
|
|
#include <QFileDialog>
|
2013-12-24 22:09:31 +00:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QFile>
|
2013-12-13 12:38:49 +00:00
|
|
|
|
2013-12-08 21:58:29 +00:00
|
|
|
#include "mainwizard.hpp"
|
|
|
|
|
2014-04-18 11:17:37 +00:00
|
|
|
Wizard::ExistingInstallationPage::ExistingInstallationPage(QWidget *parent) :
|
|
|
|
QWizardPage(parent)
|
2013-12-08 20:35:57 +00:00
|
|
|
{
|
2014-04-18 11:17:37 +00:00
|
|
|
mWizard = qobject_cast<MainWizard*>(parent);
|
|
|
|
|
2013-12-08 20:35:57 +00:00
|
|
|
setupUi(this);
|
2013-12-13 12:38:49 +00:00
|
|
|
|
2014-05-30 00:12:48 +00:00
|
|
|
// Add a placeholder item to the list of installations
|
|
|
|
QListWidgetItem *emptyItem = new QListWidgetItem(tr("No existing installations detected"));
|
|
|
|
emptyItem->setFlags(Qt::NoItemFlags);
|
|
|
|
|
|
|
|
installationsList->insertItem(0, emptyItem);
|
|
|
|
|
2014-04-18 11:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wizard::ExistingInstallationPage::initializePage()
|
|
|
|
{
|
2014-04-16 21:59:25 +00:00
|
|
|
// Add the available installation paths
|
2013-12-24 22:09:31 +00:00
|
|
|
QStringList paths(mWizard->mInstallations.keys());
|
2013-12-13 12:38:49 +00:00
|
|
|
|
2014-04-16 21:59:25 +00:00
|
|
|
// Hide the default item if there are installations to choose from
|
2015-03-14 19:08:55 +00:00
|
|
|
installationsList->item(0)->setHidden(!paths.isEmpty());
|
2013-12-13 12:38:49 +00:00
|
|
|
|
2019-10-06 11:39:27 +00:00
|
|
|
for (const QString &path : paths)
|
2018-11-08 08:44:48 +00:00
|
|
|
{
|
2014-05-30 00:12:48 +00:00
|
|
|
if (installationsList->findItems(path, Qt::MatchExactly).isEmpty())
|
2018-11-08 08:44:48 +00:00
|
|
|
{
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(path);
|
2014-05-30 00:12:48 +00:00
|
|
|
installationsList->addItem(item);
|
2018-11-08 08:44:48 +00:00
|
|
|
}
|
2013-12-13 12:38:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-16 21:59:25 +00:00
|
|
|
connect(installationsList, SIGNAL(currentTextChanged(QString)),
|
|
|
|
this, SLOT(textChanged(QString)));
|
|
|
|
|
|
|
|
connect(installationsList,SIGNAL(itemSelectionChanged()),
|
|
|
|
this, SIGNAL(completeChanged()));
|
2013-12-13 12:38:49 +00:00
|
|
|
}
|
|
|
|
|
2013-12-24 22:09:31 +00:00
|
|
|
bool Wizard::ExistingInstallationPage::validatePage()
|
|
|
|
{
|
|
|
|
// See if Morrowind.ini is detected, if not, ask the user
|
|
|
|
// It can be missing entirely
|
|
|
|
// Or failed to be detected due to the target being a symlink
|
|
|
|
|
2014-02-18 11:44:27 +00:00
|
|
|
QString path(field(QLatin1String("installation.path")).toString());
|
2014-04-17 00:15:06 +00:00
|
|
|
QFile file(mWizard->mInstallations[path].iniPath);
|
2013-12-24 22:09:31 +00:00
|
|
|
|
|
|
|
if (!file.exists()) {
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle(tr("Error detecting Morrowind configuration"));
|
|
|
|
msgBox.setIcon(QMessageBox::Warning);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Cancel);
|
|
|
|
msgBox.setText(QObject::tr("<br><b>Could not find Morrowind.ini</b><br><br> \
|
|
|
|
The Wizard needs to update settings in this file.<br><br> \
|
|
|
|
Press \"Browse...\" to specify the location manually.<br>"));
|
|
|
|
|
2016-10-30 15:23:51 +00:00
|
|
|
QAbstractButton *browseButton2 =
|
2013-12-24 22:09:31 +00:00
|
|
|
msgBox.addButton(QObject::tr("B&rowse..."), QMessageBox::ActionRole);
|
|
|
|
|
|
|
|
msgBox.exec();
|
|
|
|
|
|
|
|
QString iniFile;
|
2016-10-30 15:23:51 +00:00
|
|
|
if (msgBox.clickedButton() == browseButton2) {
|
2013-12-24 22:09:31 +00:00
|
|
|
iniFile = QFileDialog::getOpenFileName(
|
2014-04-16 16:34:24 +00:00
|
|
|
this,
|
2013-12-24 22:09:31 +00:00
|
|
|
QObject::tr("Select configuration file"),
|
|
|
|
QDir::currentPath(),
|
|
|
|
QString(tr("Morrowind configuration file (*.ini)")));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iniFile.isEmpty()) {
|
|
|
|
return false; // Cancel was clicked;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A proper Morrowind.ini was selected, set it
|
|
|
|
QFileInfo info(iniFile);
|
2014-04-17 00:15:06 +00:00
|
|
|
mWizard->mInstallations[path].iniPath = info.absoluteFilePath();
|
2013-12-24 22:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-17 17:28:05 +00:00
|
|
|
void Wizard::ExistingInstallationPage::on_browseButton_clicked()
|
|
|
|
{
|
|
|
|
QString selectedFile = QFileDialog::getOpenFileName(
|
|
|
|
this,
|
2021-01-27 19:57:11 +00:00
|
|
|
tr("Select Morrowind.esm (located in Data Files)"),
|
2014-03-17 17:28:05 +00:00
|
|
|
QDir::currentPath(),
|
2021-01-27 19:57:11 +00:00
|
|
|
QString(tr("Morrowind master file (Morrowind.esm)")),
|
2018-10-09 06:21:12 +00:00
|
|
|
nullptr,
|
2014-03-17 17:28:05 +00:00
|
|
|
QFileDialog::DontResolveSymlinks);
|
|
|
|
|
2014-04-16 16:34:24 +00:00
|
|
|
if (selectedFile.isEmpty())
|
|
|
|
return;
|
|
|
|
|
2014-03-17 17:28:05 +00:00
|
|
|
QFileInfo info(selectedFile);
|
|
|
|
|
|
|
|
if (!info.exists())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!mWizard->findFiles(QLatin1String("Morrowind"), info.absolutePath()))
|
2021-01-27 19:57:11 +00:00
|
|
|
{
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setWindowTitle(tr("Error detecting Morrowind files"));
|
|
|
|
msgBox.setIcon(QMessageBox::Warning);
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setText(QObject::tr(
|
|
|
|
"<b>Morrowind.bsa</b> is missing!<br>\
|
|
|
|
Make sure your Morrowind installation is complete."
|
|
|
|
));
|
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
2014-03-17 17:28:05 +00:00
|
|
|
|
|
|
|
QString path(QDir::toNativeSeparators(info.absolutePath()));
|
|
|
|
QList<QListWidgetItem*> items = installationsList->findItems(path, Qt::MatchExactly);
|
|
|
|
|
|
|
|
if (items.isEmpty()) {
|
|
|
|
// Path is not yet in the list, add it
|
|
|
|
mWizard->addInstallation(path);
|
|
|
|
|
|
|
|
// Hide the default item
|
2014-04-16 21:59:25 +00:00
|
|
|
installationsList->item(0)->setHidden(true);
|
2014-03-17 17:28:05 +00:00
|
|
|
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(path);
|
|
|
|
installationsList->addItem(item);
|
|
|
|
installationsList->setCurrentItem(item); // Select it too
|
|
|
|
} else {
|
|
|
|
installationsList->setCurrentItem(items.first());
|
|
|
|
}
|
|
|
|
|
2014-05-29 19:02:06 +00:00
|
|
|
// Update the button
|
|
|
|
emit completeChanged();
|
2014-03-17 17:28:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Wizard::ExistingInstallationPage::textChanged(const QString &text)
|
|
|
|
{
|
|
|
|
// Set the installation path manually, as registerField doesn't work
|
|
|
|
// Because it doesn't accept two widgets operating on a single field
|
|
|
|
if (!text.isEmpty())
|
|
|
|
mWizard->setField(QLatin1String("installation.path"), text);
|
|
|
|
}
|
|
|
|
|
2013-12-13 12:38:49 +00:00
|
|
|
bool Wizard::ExistingInstallationPage::isComplete() const
|
|
|
|
{
|
2013-12-24 22:47:04 +00:00
|
|
|
if (installationsList->selectionModel()->hasSelection()) {
|
2013-12-13 12:38:49 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-08 20:35:57 +00:00
|
|
|
}
|
2013-12-08 21:58:29 +00:00
|
|
|
|
|
|
|
int Wizard::ExistingInstallationPage::nextId() const
|
|
|
|
{
|
2014-04-16 21:59:25 +00:00
|
|
|
return MainWizard::Page_LanguageSelection;
|
2013-12-08 21:58:29 +00:00
|
|
|
}
|