From 5024f1bf7763ccaf569c483b8e1a6a3c36029e65 Mon Sep 17 00:00:00 2001 From: pvdk Date: Tue, 28 Jan 2014 13:27:09 +0100 Subject: [PATCH] Added a warning when trying to install tribunal after bloodmoon --- apps/wizard/componentselectionpage.cpp | 61 ++++++++++++++++++++--- apps/wizard/componentselectionpage.hpp | 1 + apps/wizard/existinginstallationpage.cpp | 6 +-- apps/wizard/installationpage.cpp | 16 +++++- apps/wizard/installationtargetpage.cpp | 4 +- apps/wizard/languageselectionpage.cpp | 5 +- apps/wizard/mainwizard.cpp | 17 +++---- apps/wizard/methodselectionpage.cpp | 6 ++- apps/wizard/utils/componentlistwidget.cpp | 18 ++++--- apps/wizard/utils/componentlistwidget.hpp | 3 +- 10 files changed, 99 insertions(+), 38 deletions(-) diff --git a/apps/wizard/componentselectionpage.cpp b/apps/wizard/componentselectionpage.cpp index 7d934fe84..87779e93d 100644 --- a/apps/wizard/componentselectionpage.cpp +++ b/apps/wizard/componentselectionpage.cpp @@ -1,7 +1,9 @@ #include "componentselectionpage.hpp" #include +#include #include +#include #include "mainwizard.hpp" @@ -51,7 +53,7 @@ void Wizard::ComponentSelectionPage::initializePage() { componentsList->clear(); - QString path = field("installation.path").toString(); + QString path(field("installation.path").toString()); QListWidgetItem *morrowindItem = new QListWidgetItem(QLatin1String("Morrowind")); QListWidgetItem *tribunalItem = new QListWidgetItem(QLatin1String("Tribunal")); @@ -72,7 +74,7 @@ void Wizard::ComponentSelectionPage::initializePage() componentsList->addItem(bloodmoonItem); } else { - if (mWizard->mInstallations[path]->hasMorrowind == true) { + if (mWizard->mInstallations[path]->hasMorrowind) { morrowindItem->setText(tr("Morrowind\t\t(installed)")); morrowindItem->setFlags(morrowindItem->flags() & !Qt::ItemIsEnabled & Qt::ItemIsUserCheckable); morrowindItem->setData(Qt::CheckStateRole, Qt::Unchecked); @@ -83,7 +85,7 @@ void Wizard::ComponentSelectionPage::initializePage() componentsList->addItem(morrowindItem); - if (mWizard->mInstallations[path]->hasTribunal == true) { + if (mWizard->mInstallations[path]->hasTribunal) { tribunalItem->setText(tr("Tribunal\t\t(installed)")); tribunalItem->setFlags(tribunalItem->flags() & !Qt::ItemIsEnabled & Qt::ItemIsUserCheckable); tribunalItem->setData(Qt::CheckStateRole, Qt::Unchecked); @@ -94,7 +96,7 @@ void Wizard::ComponentSelectionPage::initializePage() componentsList->addItem(tribunalItem); - if (mWizard->mInstallations[path]->hasBloodmoon == true) { + if (mWizard->mInstallations[path]->hasBloodmoon) { bloodmoonItem->setText(tr("Bloodmoon\t\t(installed)")); bloodmoonItem->setFlags(bloodmoonItem->flags() & !Qt::ItemIsEnabled & Qt::ItemIsUserCheckable); bloodmoonItem->setData(Qt::CheckStateRole, Qt::Unchecked); @@ -107,10 +109,55 @@ void Wizard::ComponentSelectionPage::initializePage() } } +bool Wizard::ComponentSelectionPage::validatePage() +{ + QStringList components(field("installation.components").toStringList()); + QString path(field("installation.path").toString()); + + qDebug() << components << path << mWizard->mInstallations[path]; + + if (field("installation.new").toBool() == false) { + if (components.contains(QLatin1String("Tribunal")) && !components.contains(QLatin1String("Bloodmoon"))) + { + if (mWizard->mInstallations[path]->hasBloodmoon) + { + QMessageBox msgBox; + msgBox.setWindowTitle(tr("About to install Tribunal after Bloodmoon")); + msgBox.setIcon(QMessageBox::Information); + msgBox.setStandardButtons(QMessageBox::Cancel); + msgBox.setText(tr("

You are about to install Tribunal

\ +

Bloodmoon is already installed on your computer.

\ +

However, it is recommended that you install Tribunal before Bloodmoon.

\ +

Would you like to re-install Bloodmoon?

")); + + QAbstractButton *reinstallButton = msgBox.addButton(tr("Re-install &Bloodmoon"), QMessageBox::ActionRole); + msgBox.exec(); + + + if (msgBox.clickedButton() == reinstallButton) { + // Force reinstallation + mWizard->mInstallations[path]->hasBloodmoon = false; + QList items = componentsList->findItems(QLatin1String("Bloodmoon"), Qt::MatchStartsWith); + + foreach (QListWidgetItem *item, items) { + item->setText(QLatin1String("Bloodmoon")); + item->setCheckState(Qt::Checked); + } + + return true; + } + } + } + } + + return true; +} + int Wizard::ComponentSelectionPage::nextId() const { - if (isCommitPage()) + if (isCommitPage()) { return MainWizard::Page_Installation; - - return MainWizard::Page_Import; + } else { + return MainWizard::Page_Import; + } } diff --git a/apps/wizard/componentselectionpage.hpp b/apps/wizard/componentselectionpage.hpp index 8b4c186d0..ed007fd08 100644 --- a/apps/wizard/componentselectionpage.hpp +++ b/apps/wizard/componentselectionpage.hpp @@ -16,6 +16,7 @@ namespace Wizard ComponentSelectionPage(MainWizard *wizard); int nextId() const; + virtual bool validatePage(); private slots: void updateButton(QListWidgetItem *item); diff --git a/apps/wizard/existinginstallationpage.cpp b/apps/wizard/existinginstallationpage.cpp index 5c66ceb4f..c1dbf8e9b 100644 --- a/apps/wizard/existinginstallationpage.cpp +++ b/apps/wizard/existinginstallationpage.cpp @@ -57,7 +57,7 @@ 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("installation.path", text); + mWizard->setField(QLatin1String("installation.path"), text); } void Wizard::ExistingInstallationPage::initializePage() @@ -135,7 +135,7 @@ int Wizard::ExistingInstallationPage::nextId() const QString path(field("installation.path").toString()); if (path.isEmpty()) - return MainWizard::Page_ComponentSelection; + return MainWizard::Page_LanguageSelection; if (mWizard->mInstallations[path]->hasMorrowind == true && mWizard->mInstallations[path]->hasTribunal == true && @@ -143,6 +143,6 @@ int Wizard::ExistingInstallationPage::nextId() const { return MainWizard::Page_Import; } else { - return MainWizard::Page_ComponentSelection; + return MainWizard::Page_LanguageSelection; } } diff --git a/apps/wizard/installationpage.cpp b/apps/wizard/installationpage.cpp index fc527ed3f..e838a19c1 100644 --- a/apps/wizard/installationpage.cpp +++ b/apps/wizard/installationpage.cpp @@ -138,9 +138,23 @@ void Wizard::InstallationPage::startInstallation() void Wizard::InstallationPage::showFileDialog(Wizard::Component component) { + QString name; + switch (component) { + + case Wizard::Component_Morrowind: + name = QLatin1String("Morrowind"); + break; + case Wizard::Component_Tribunal: + name = QLatin1String("Tribunal"); + break; + case Wizard::Component_Bloodmoon: + name = QLatin1String("Bloodmoon"); + break; + } + QString fileName = QFileDialog::getOpenFileName( this, - tr("Select installation file"), + tr("Select %1 installation file").arg(name), QDir::rootPath(), tr("InstallShield header files (*.hdr)")); diff --git a/apps/wizard/installationtargetpage.cpp b/apps/wizard/installationtargetpage.cpp index 459e7145d..900a978cf 100644 --- a/apps/wizard/installationtargetpage.cpp +++ b/apps/wizard/installationtargetpage.cpp @@ -34,7 +34,7 @@ void Wizard::InstallationTargetPage::on_browseButton_clicked() QString selectedPath = QFileDialog::getExistingDirectory( this, tr("Select where to install Morrowind"), - QDir::currentPath(), + QDir::homePath(), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); qDebug() << selectedPath; @@ -49,5 +49,5 @@ void Wizard::InstallationTargetPage::on_browseButton_clicked() int Wizard::InstallationTargetPage::nextId() const { - return MainWizard::Page_ComponentSelection; + return MainWizard::Page_LanguageSelection; } diff --git a/apps/wizard/languageselectionpage.cpp b/apps/wizard/languageselectionpage.cpp index 102a4c39a..b921d5ddb 100644 --- a/apps/wizard/languageselectionpage.cpp +++ b/apps/wizard/languageselectionpage.cpp @@ -27,8 +27,5 @@ void Wizard::LanguageSelectionPage::initializePage() int Wizard::LanguageSelectionPage::nextId() const { - if (field("installation.new").toBool() == true) - return MainWizard::Page_InstallationTarget; - - return MainWizard::Page_ExistingInstallation; + return MainWizard::Page_ComponentSelection; } diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp index aef59fa4e..0913cf9e4 100644 --- a/apps/wizard/mainwizard.cpp +++ b/apps/wizard/mainwizard.cpp @@ -73,14 +73,10 @@ void Wizard::MainWizard::setupInstallations() file.close(); } - // Check if the paths actually contain data files + // Check if the paths actually contains a Morrowind installation foreach (const QString path, mGameSettings.getDataDirs()) { - QDir dir(path); - QStringList filters; - filters << "*.esp" << "*.esm" << "*.omwgame" << "*.omwaddon"; - // Add to Wizard installations - if (!dir.entryList(filters).isEmpty()) + if (findFiles(QLatin1String("Morrowind"), path)) addInstallation(path); } @@ -112,8 +108,10 @@ void Wizard::MainWizard::addInstallation(const QString &path) mInstallations.insert(QDir::toNativeSeparators(path), install); // Add it to the openmw.cfg too - mGameSettings.setMultiValue(QString("data"), path); - mGameSettings.addDataDir(path); + if (!mGameSettings.getDataDirs().contains(path)) { + mGameSettings.setMultiValue(QString("data"), path); + mGameSettings.addDataDir(path); + } } void Wizard::MainWizard::setupPages() @@ -168,8 +166,7 @@ bool Wizard::MainWizard::findFiles(const QString &name, const QString &path) return false; // TODO: add MIME handling to make sure the files are real - if (dir.exists(name + QLatin1String(".esm")) && dir.exists(name + QLatin1String(".bsa"))) - { + if (dir.exists(name + QLatin1String(".esm")) && dir.exists(name + QLatin1String(".bsa"))) { return true; } else { return false; diff --git a/apps/wizard/methodselectionpage.cpp b/apps/wizard/methodselectionpage.cpp index 4185fa2bc..6db0779a6 100644 --- a/apps/wizard/methodselectionpage.cpp +++ b/apps/wizard/methodselectionpage.cpp @@ -13,5 +13,9 @@ Wizard::MethodSelectionPage::MethodSelectionPage(MainWizard *wizard) : int Wizard::MethodSelectionPage::nextId() const { - return MainWizard::Page_LanguageSelection; + if (field("installation.new").toBool() == true) { + return MainWizard::Page_InstallationTarget; + } else { + return MainWizard::Page_ExistingInstallation; + } } diff --git a/apps/wizard/utils/componentlistwidget.cpp b/apps/wizard/utils/componentlistwidget.cpp index c9a1c1940..6a5d019b5 100644 --- a/apps/wizard/utils/componentlistwidget.cpp +++ b/apps/wizard/utils/componentlistwidget.cpp @@ -10,15 +10,9 @@ ComponentListWidget::ComponentListWidget(QWidget *parent) : connect(this, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(updateCheckedItems(QListWidgetItem *))); -} - -void ComponentListWidget::addItem(QListWidgetItem *item) -{ - // The model does not emit a dataChanged signal when items are added - // So we need to update manually - QListWidget::insertItem(count(), item); - updateCheckedItems(item); + connect(model(), SIGNAL(rowsInserted(QModelIndex, int, int)), + this, SLOT(updateCheckedItems(QModelIndex, int, int))); } QStringList ComponentListWidget::checkedItems() @@ -27,8 +21,16 @@ QStringList ComponentListWidget::checkedItems() return mCheckedItems; } +void ComponentListWidget::updateCheckedItems(const QModelIndex &index, int start, int end) +{ + updateCheckedItems(item(start)); +} + void ComponentListWidget::updateCheckedItems(QListWidgetItem *item) { + if (!item) + return; + QString text = item->text(); if (item->checkState() == Qt::Checked) { diff --git a/apps/wizard/utils/componentlistwidget.hpp b/apps/wizard/utils/componentlistwidget.hpp index 6869629d3..23965f8a6 100644 --- a/apps/wizard/utils/componentlistwidget.hpp +++ b/apps/wizard/utils/componentlistwidget.hpp @@ -15,13 +15,12 @@ public: QStringList mCheckedItems; QStringList checkedItems(); - void addItem(QListWidgetItem *item); - signals: void checkedItemsChanged(const QStringList &items); private slots: void updateCheckedItems(QListWidgetItem *item); + void updateCheckedItems(const QModelIndex &index, int start, int end); }; #endif // COMPONENTLISTWIDGET_HPP