diff --git a/apps/wizard/componentselectionpage.cpp b/apps/wizard/componentselectionpage.cpp index 0293bdc054..1ec1380b13 100644 --- a/apps/wizard/componentselectionpage.cpp +++ b/apps/wizard/componentselectionpage.cpp @@ -1,14 +1,115 @@ #include "componentselectionpage.hpp" +#include +#include + #include "mainwizard.hpp" -Wizard::ComponentSelectionPage::ComponentSelectionPage(QWidget *parent) : - QWizardPage(parent) +Wizard::ComponentSelectionPage::ComponentSelectionPage(MainWizard *wizard) : + QWizardPage(wizard), + mWizard(wizard) { setupUi(this); + + setCommitPage(true); + setButtonText(QWizard::CommitButton, tr("&Install")); + + connect(componentsList, SIGNAL(itemChanged(QListWidgetItem*)), + this, SLOT(updateButton(QListWidgetItem*))); +} + +void Wizard::ComponentSelectionPage::updateButton(QListWidgetItem *item) +{ + if (field("installation.new").toBool() == true) + return; // Morrowind is always checked here + + bool unchecked = true; + + for (int i =0; i < componentsList->count(); ++i) { + QListWidgetItem *item = componentsList->item(i); + + qDebug() << "item is " << item->text(); + + if (!item) + continue; + + if (item->checkState() == Qt::Checked) { + unchecked = false; + } + } + + if (unchecked) { + setCommitPage(false); + setButtonText(QWizard::NextButton, tr("&Skip")); + } else { + setCommitPage(true); + } +} + +void Wizard::ComponentSelectionPage::initializePage() +{ + componentsList->clear(); + + QString path = field("installation.path").toString(); + + QListWidgetItem *morrowindItem = new QListWidgetItem(QString("Morrowind")); + QListWidgetItem *tribunalItem = new QListWidgetItem(QString("Tribunal")); + QListWidgetItem *bloodmoonItem = new QListWidgetItem(QString("Bloodmoon")); + + if (field("installation.new").toBool() == true) + { + morrowindItem->setFlags(morrowindItem->flags() & !Qt::ItemIsEnabled & Qt::ItemIsUserCheckable); + morrowindItem->setData(Qt::CheckStateRole, Qt::Checked); + componentsList->addItem(morrowindItem); + + tribunalItem->setFlags(tribunalItem->flags() | Qt::ItemIsUserCheckable); + tribunalItem->setData(Qt::CheckStateRole, Qt::Checked); + componentsList->addItem(tribunalItem); + + bloodmoonItem->setFlags(bloodmoonItem->flags() | Qt::ItemIsUserCheckable); + bloodmoonItem->setData(Qt::CheckStateRole, Qt::Checked); + componentsList->addItem(bloodmoonItem); + } else { + + if (mWizard->mInstallations[path]->hasMorrowind == true) { + morrowindItem->setText(tr("Morrowind\t\t(installed)")); + morrowindItem->setFlags(morrowindItem->flags() & !Qt::ItemIsEnabled & Qt::ItemIsUserCheckable); + morrowindItem->setData(Qt::CheckStateRole, Qt::Unchecked); + } else { + morrowindItem->setText(tr("Morrowind")); + morrowindItem->setData(Qt::CheckStateRole, Qt::Checked); + } + + componentsList->addItem(morrowindItem); + + if (mWizard->mInstallations[path]->hasTribunal == true) { + tribunalItem->setText(tr("Tribunal\t\t(installed)")); + tribunalItem->setFlags(tribunalItem->flags() & !Qt::ItemIsEnabled & Qt::ItemIsUserCheckable); + tribunalItem->setData(Qt::CheckStateRole, Qt::Unchecked); + } else { + tribunalItem->setText(tr("Tribunal")); + tribunalItem->setData(Qt::CheckStateRole, Qt::Checked); + } + + componentsList->addItem(tribunalItem); + + if (mWizard->mInstallations[path]->hasBloodmoon == true) { + bloodmoonItem->setText(tr("Bloodmoon\t\t(installed)")); + bloodmoonItem->setFlags(bloodmoonItem->flags() & !Qt::ItemIsEnabled & Qt::ItemIsUserCheckable); + bloodmoonItem->setData(Qt::CheckStateRole, Qt::Unchecked); + } else { + bloodmoonItem->setText(tr("Bloodmoon")); + bloodmoonItem->setData(Qt::CheckStateRole, Qt::Checked); + } + + componentsList->addItem(bloodmoonItem); + } } int Wizard::ComponentSelectionPage::nextId() const { - return MainWizard::Page_Installation; + if (isCommitPage()) + return MainWizard::Page_Installation; + + return MainWizard::Page_Import; } diff --git a/apps/wizard/componentselectionpage.hpp b/apps/wizard/componentselectionpage.hpp index 277845774c..8b4c186d09 100644 --- a/apps/wizard/componentselectionpage.hpp +++ b/apps/wizard/componentselectionpage.hpp @@ -7,15 +7,25 @@ namespace Wizard { + class MainWizard; class ComponentSelectionPage : public QWizardPage, private Ui::ComponentSelectionPage { Q_OBJECT public: - ComponentSelectionPage(QWidget *parent = 0); + ComponentSelectionPage(MainWizard *wizard); int nextId() const; + private slots: + void updateButton(QListWidgetItem *item); + + private: + MainWizard *mWizard; + + protected: + void initializePage(); + }; } diff --git a/apps/wizard/conclusionpage.cpp b/apps/wizard/conclusionpage.cpp index 567d325b3e..55b03b9129 100644 --- a/apps/wizard/conclusionpage.cpp +++ b/apps/wizard/conclusionpage.cpp @@ -1,11 +1,28 @@ #include "conclusionpage.hpp" -Wizard::ConclusionPage::ConclusionPage(QWidget *parent) : - QWizardPage(parent) +#include + +#include "mainwizard.hpp" + +Wizard::ConclusionPage::ConclusionPage(MainWizard *wizard) : + QWizardPage(wizard), + mWizard(wizard) { setupUi(this); } +void Wizard::ConclusionPage::initializePage() +{ + if (field("installation.new").toBool() == true) + { + textLabel->setText(tr("The OpenMW Wizard successfully installed Morrowind on your computer.\n\n") + + tr("Click Finish to close the Wizard.")); + } else { + textLabel->setText(tr("The OpenMW Wizard successfully modified your existing Morrowind installation.\n\n") + + tr("Click Finish to close the Wizard.")); + } +} + int Wizard::ConclusionPage::nextId() const { return -1; diff --git a/apps/wizard/conclusionpage.hpp b/apps/wizard/conclusionpage.hpp index e00fc0fe3b..e050684e15 100644 --- a/apps/wizard/conclusionpage.hpp +++ b/apps/wizard/conclusionpage.hpp @@ -7,15 +7,22 @@ namespace Wizard { + class MainWizard; class ConclusionPage : public QWizardPage, private Ui::ConclusionPage { Q_OBJECT public: - ConclusionPage(QWidget *parent = 0); + ConclusionPage(MainWizard *wizard); int nextId() const; + private: + MainWizard *mWizard; + + protected: + void initializePage(); + }; } diff --git a/apps/wizard/existinginstallationpage.cpp b/apps/wizard/existinginstallationpage.cpp index d6dea0af92..f9eb7c283c 100644 --- a/apps/wizard/existinginstallationpage.cpp +++ b/apps/wizard/existinginstallationpage.cpp @@ -1,14 +1,105 @@ #include "existinginstallationpage.hpp" +#include +#include + #include "mainwizard.hpp" -Wizard::ExistingInstallationPage::ExistingInstallationPage(QWidget *parent) : - QWizardPage(parent) +Wizard::ExistingInstallationPage::ExistingInstallationPage(MainWizard *wizard) : + QWizardPage(wizard), + mWizard(wizard) { setupUi(this); + + connect(detectedList, SIGNAL(currentTextChanged(QString)), + this, SLOT(textChanged(QString))); + + connect(detectedList,SIGNAL(itemSelectionChanged()), + this, SIGNAL(completeChanged())); +} + +void Wizard::ExistingInstallationPage::on_browseButton_clicked() +{ + QString selectedFile = QFileDialog::getOpenFileName( + this, + tr("Select master file"), + QDir::currentPath(), + QString(tr("Morrowind master file (*.esm)")), + NULL, + QFileDialog::DontResolveSymlinks); + + QFileInfo info(selectedFile); + if (!info.exists()) + return; + + QDir dir(info.absolutePath()); + if (!dir.cdUp()) + return; // Cannot move out of the Data Files directory + + QString path = QDir::toNativeSeparators(dir.absolutePath()); + QList items = detectedList->findItems(path, Qt::MatchExactly); + + if (items.isEmpty()) + { + // Path is not yet in the list, add it + QListWidgetItem *item = new QListWidgetItem(path); + detectedList->addItem(item); + detectedList->setCurrentItem(item); // Select it too + } else { + detectedList->setCurrentItem(items.first()); + } + +} + +void Wizard::ExistingInstallationPage::textChanged(const QString &text) +{ + // Set the installation path manually, as registerField doesn't work + if (!text.isEmpty()) + wizard()->setField("installation.path", text); +} + +void Wizard::ExistingInstallationPage::initializePage() +{ + + QStringList paths = mWizard->mInstallations.keys(); + + if (paths.isEmpty()) + return; + + detectedList->clear(); + + foreach (const QString &path, paths) { + QListWidgetItem *item = new QListWidgetItem(path); + detectedList->addItem(item); + } + +} + +bool Wizard::ExistingInstallationPage::isComplete() const +{ + if (detectedList->selectionModel()->hasSelection()) { + return true; + } else { + return false; + } } int Wizard::ExistingInstallationPage::nextId() const { - return MainWizard::Page_ComponentSelection; + QString path = field("installation.path").toString(); + + if (path.isEmpty()) + return MainWizard::Page_ComponentSelection; + + if (!mWizard->mInstallations.contains(path)) + return MainWizard::Page_ComponentSelection; + + if (mWizard->mInstallations[path]->hasMorrowind == true && + mWizard->mInstallations[path]->hasTribunal == true && + mWizard->mInstallations[path]->hasBloodmoon == true) + { + return MainWizard::Page_Import; + } else { + return MainWizard::Page_ComponentSelection; + } } diff --git a/apps/wizard/existinginstallationpage.hpp b/apps/wizard/existinginstallationpage.hpp index 823bc2140b..88d6913bc2 100644 --- a/apps/wizard/existinginstallationpage.hpp +++ b/apps/wizard/existinginstallationpage.hpp @@ -7,14 +7,27 @@ namespace Wizard { + class MainWizard; class ExistingInstallationPage : public QWizardPage, private Ui::ExistingInstallationPage { Q_OBJECT public: - ExistingInstallationPage(QWidget *parent = 0); + ExistingInstallationPage(MainWizard *wizard); int nextId() const; + virtual bool isComplete() const; + + private slots: + void on_browseButton_clicked(); + void textChanged(const QString &text); + + + private: + MainWizard *mWizard; + + protected: + void initializePage(); }; diff --git a/apps/wizard/importpage.cpp b/apps/wizard/importpage.cpp index 29db6919dd..059683cf0a 100644 --- a/apps/wizard/importpage.cpp +++ b/apps/wizard/importpage.cpp @@ -2,8 +2,9 @@ #include "mainwizard.hpp" -Wizard::ImportPage::ImportPage(QWidget *parent) : - QWizardPage(parent) +Wizard::ImportPage::ImportPage(MainWizard *wizard) : + QWizardPage(wizard), + mWizard(wizard) { setupUi(this); } diff --git a/apps/wizard/importpage.hpp b/apps/wizard/importpage.hpp index f1cc11e03c..2eae08531c 100644 --- a/apps/wizard/importpage.hpp +++ b/apps/wizard/importpage.hpp @@ -7,15 +7,19 @@ namespace Wizard { + class MainWizard; class ImportPage : public QWizardPage, private Ui::ImportPage { Q_OBJECT public: - ImportPage(QWidget *parent = 0); + ImportPage(MainWizard *wizard); int nextId() const; + private: + MainWizard *mWizard; + }; } diff --git a/apps/wizard/installationpage.cpp b/apps/wizard/installationpage.cpp index 092cf62e0e..de0720ecbd 100644 --- a/apps/wizard/installationpage.cpp +++ b/apps/wizard/installationpage.cpp @@ -1,13 +1,22 @@ #include "installationpage.hpp" +#include + #include "mainwizard.hpp" -Wizard::InstallationPage::InstallationPage(QWidget *parent) : - QWizardPage(parent) +Wizard::InstallationPage::InstallationPage(MainWizard *wizard) : + QWizardPage(wizard), + mWizard(wizard) { setupUi(this); } +void Wizard::InstallationPage::initializePage() +{ + qDebug() << "installing to: " << field("installation.path").toString(); + logTextEdit->setText(QString("Installing to %1").arg(field("installation.path").toString())); +} + int Wizard::InstallationPage::nextId() const { return MainWizard::Page_Import; diff --git a/apps/wizard/installationpage.hpp b/apps/wizard/installationpage.hpp index 125fcc2e1e..cb206e2251 100644 --- a/apps/wizard/installationpage.hpp +++ b/apps/wizard/installationpage.hpp @@ -7,15 +7,22 @@ namespace Wizard { + class MainWizard; class InstallationPage : public QWizardPage, private Ui::InstallationPage { Q_OBJECT public: - InstallationPage(QWidget *parent = 0); + InstallationPage(MainWizard *wizard); int nextId() const; + private: + MainWizard *mWizard; + + protected: + void initializePage(); + }; } diff --git a/apps/wizard/installationtargetpage.cpp b/apps/wizard/installationtargetpage.cpp index fa178f9136..43941f0dca 100644 --- a/apps/wizard/installationtargetpage.cpp +++ b/apps/wizard/installationtargetpage.cpp @@ -1,11 +1,40 @@ #include "installationtargetpage.hpp" +#include +#include + #include "mainwizard.hpp" -Wizard::InstallationTargetPage::InstallationTargetPage(QWidget *parent) : - QWizardPage(parent) +Wizard::InstallationTargetPage::InstallationTargetPage(MainWizard *wizard) : + QWizardPage(wizard), + mWizard(wizard) { setupUi(this); + + registerField("installation.path*", targetLineEdit); +} + +void Wizard::InstallationTargetPage::initializePage() +{ + +} + +void Wizard::InstallationTargetPage::on_browseButton_clicked() +{ + QString selectedPath = QFileDialog::getExistingDirectory( + this, + tr("Select where to install Morrowind"), + QDir::currentPath(), + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + + qDebug() << selectedPath; + QFileInfo info(selectedPath); + if (!info.exists()) + return; + + if (info.isWritable()) + targetLineEdit->setText(info.absoluteFilePath()); + } int Wizard::InstallationTargetPage::nextId() const diff --git a/apps/wizard/installationtargetpage.hpp b/apps/wizard/installationtargetpage.hpp index 4e399b707d..ccaac5969d 100644 --- a/apps/wizard/installationtargetpage.hpp +++ b/apps/wizard/installationtargetpage.hpp @@ -7,15 +7,25 @@ namespace Wizard { + class MainWizard; class InstallationTargetPage : public QWizardPage, private Ui::InstallationTargetPage { Q_OBJECT public: - InstallationTargetPage(QWidget *parent = 0); + InstallationTargetPage(MainWizard *wizard); int nextId() const; + private slots: + void on_browseButton_clicked(); + + private: + MainWizard *mWizard; + + protected: + void initializePage(); + }; } diff --git a/apps/wizard/intropage.cpp b/apps/wizard/intropage.cpp index 72c769ae6a..93510cd210 100644 --- a/apps/wizard/intropage.cpp +++ b/apps/wizard/intropage.cpp @@ -2,8 +2,10 @@ #include "mainwizard.hpp" -Wizard::IntroPage::IntroPage(QWidget *parent) : - QWizardPage(parent) +Wizard::IntroPage::IntroPage(MainWizard *wizard) : + QWizardPage(wizard), + mWizard(wizard) + { setupUi(this); } diff --git a/apps/wizard/intropage.hpp b/apps/wizard/intropage.hpp index 603d283fa4..78bac3155e 100644 --- a/apps/wizard/intropage.hpp +++ b/apps/wizard/intropage.hpp @@ -7,15 +7,18 @@ namespace Wizard { + class MainWizard; class IntroPage : public QWizardPage, private Ui::IntroPage { Q_OBJECT public: - IntroPage(QWidget *parent = 0); + IntroPage(MainWizard *wizard); int nextId() const; + private: + MainWizard *mWizard; }; } diff --git a/apps/wizard/mainwizard.cpp b/apps/wizard/mainwizard.cpp index 438d9e5763..a741546fdc 100644 --- a/apps/wizard/mainwizard.cpp +++ b/apps/wizard/mainwizard.cpp @@ -1,4 +1,8 @@ #include "mainwizard.hpp" + +#include +#include + #include "intropage.hpp" #include "methodselectionpage.hpp" #include "existinginstallationpage.hpp" @@ -19,18 +23,67 @@ Wizard::MainWizard::MainWizard(QWidget *parent) : #endif setWindowTitle(tr("OpenMW Wizard")); + setupInstallations(); setupPages(); + + QDir dir("/home/pvdk/data"); + QFileInfo info(dir.absoluteFilePath("../Morrowind.ini")); + + qDebug() << "exists? " << info.exists(); +} + +void Wizard::MainWizard::setupInstallations() +{ + // TODO: detect existing installations + QStringList paths; + paths << QString("/home/pvdk/.wine/drive_c/Program Files/Bethesda Softworks/Morrowind"); + paths << QString("/home/pvdk/openmw/Data Files"); + paths << QString("/usr/games/morrowind"); + + foreach (const QString &path, paths) + { + Installation* install = new Installation(); + + install->hasMorrowind = (findFiles(QString("Morrowind"), path)); + install->hasTribunal = true; + install->hasBloodmoon = false; + + mInstallations.insert(QDir::toNativeSeparators(path), install); + } + } void Wizard::MainWizard::setupPages() { - setPage(Page_Intro, new IntroPage); - setPage(Page_MethodSelection, new MethodSelectionPage); - setPage(Page_ExistingInstallation, new ExistingInstallationPage); - setPage(Page_InstallationTarget, new InstallationTargetPage); - setPage(Page_ComponentSelection, new ComponentSelectionPage); - setPage(Page_Installation, new InstallationPage); - setPage(Page_Import, new ImportPage); - setPage(Page_Conclusion, new ConclusionPage); + setPage(Page_Intro, new IntroPage(this)); + setPage(Page_MethodSelection, new MethodSelectionPage(this)); + setPage(Page_ExistingInstallation, new ExistingInstallationPage(this)); + setPage(Page_InstallationTarget, new InstallationTargetPage(this)); + setPage(Page_ComponentSelection, new ComponentSelectionPage(this)); + setPage(Page_Installation, new InstallationPage(this)); + setPage(Page_Import, new ImportPage(this)); + setPage(Page_Conclusion, new ConclusionPage(this)); setStartId(Page_Intro); } + +bool Wizard::MainWizard::findFiles(const QString &name, const QString &path) +{ + QDir dir(path); + + if (!dir.exists()) + return false; + + if (!dir.cd(QString("Data Files"))) + return false; + + qDebug() << "name: " << name + QString(".esm") << dir.absolutePath(); + + // TODO: add MIME handling to make sure the files are real + if (dir.exists(name + QString(".esm")) && dir.exists(name + QString(".bsa"))) + { + return true; + } else { + return false; + } + +} diff --git a/apps/wizard/mainwizard.hpp b/apps/wizard/mainwizard.hpp index e5cdc866bd..15706e8e35 100644 --- a/apps/wizard/mainwizard.hpp +++ b/apps/wizard/mainwizard.hpp @@ -2,6 +2,7 @@ #define MAINWIZARD_HPP #include +#include namespace Wizard { @@ -11,6 +12,12 @@ namespace Wizard Q_OBJECT public: + struct Installation { + bool hasMorrowind; + bool hasTribunal; + bool hasBloodmoon; + }; + enum { Page_Intro, Page_MethodSelection, @@ -24,8 +31,14 @@ namespace Wizard MainWizard(QWidget *parent = 0); + static bool findFiles(const QString &name, const QString &path); + QMap mInstallations; + private: + void setupInstallations(); void setupPages(); + + }; } diff --git a/apps/wizard/methodselectionpage.cpp b/apps/wizard/methodselectionpage.cpp index 59125f2518..1efffc13d8 100644 --- a/apps/wizard/methodselectionpage.cpp +++ b/apps/wizard/methodselectionpage.cpp @@ -1,18 +1,23 @@ #include "methodselectionpage.hpp" - +#include #include "mainwizard.hpp" -Wizard::MethodSelectionPage::MethodSelectionPage(QWidget *parent) : - QWizardPage(parent) +Wizard::MethodSelectionPage::MethodSelectionPage(MainWizard *wizard) : + QWizardPage(wizard), + mWizard(wizard) { setupUi(this); + + registerField("installation.new", newLocationRadioButton); } int Wizard::MethodSelectionPage::nextId() const { if (newLocationRadioButton->isChecked()) { + //wizard()->setField("installation.new", true); return MainWizard::Page_InstallationTarget; } else { + //wizard()->setField("installation.new", false); return MainWizard::Page_ExistingInstallation; } } diff --git a/apps/wizard/methodselectionpage.hpp b/apps/wizard/methodselectionpage.hpp index 1555ea157d..de34ff555d 100644 --- a/apps/wizard/methodselectionpage.hpp +++ b/apps/wizard/methodselectionpage.hpp @@ -7,15 +7,19 @@ namespace Wizard { + class MainWizard; class MethodSelectionPage : public QWizardPage, private Ui::MethodSelectionPage { Q_OBJECT public: - MethodSelectionPage(QWidget *parent = 0); + MethodSelectionPage(MainWizard *wizard); int nextId() const; + private: + MainWizard *mWizard; + }; } diff --git a/files/ui/wizard/conclusionpage.ui b/files/ui/wizard/conclusionpage.ui index bedad3e2aa..a27f667899 100644 --- a/files/ui/wizard/conclusionpage.ui +++ b/files/ui/wizard/conclusionpage.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 398 + 298 @@ -20,9 +20,7 @@ - The OpenMW Wizard successfully installed Morrowind on your computer. - -Click Finish to close the Wizard. + Placeholder true diff --git a/files/ui/wizard/existinginstallationpage.ui b/files/ui/wizard/existinginstallationpage.ui index 579ddbe672..3ca8316361 100644 --- a/files/ui/wizard/existinginstallationpage.ui +++ b/files/ui/wizard/existinginstallationpage.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 396 + 296 @@ -23,7 +23,7 @@ - Detected Installations: + Detected installations: @@ -33,6 +33,9 @@ No existing installations detected + + NoItemFlags + diff --git a/files/ui/wizard/languageselectionpage.ui b/files/ui/wizard/languageselectionpage.ui new file mode 100644 index 0000000000..134a9de86b --- /dev/null +++ b/files/ui/wizard/languageselectionpage.ui @@ -0,0 +1,72 @@ + + + WizardPage + + + + 0 + 0 + 398 + 298 + + + + WizardPage + + + + + + + + + 0 + 0 + + + + <html><head/><body><p><img src=":/icons/tango/48x48/preferences-desktop-locale.png"/></p></body></html> + + + Qt::RichText + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + What is the language of the Morrowind installation? + + + true + + + + + + + + + + + + Qt::Vertical + + + + 20 + 230 + + + + + + + + + + + diff --git a/files/wizard/wizard.qrc b/files/wizard/wizard.qrc index 86b3795c44..b3bb722c9f 100644 --- a/files/wizard/wizard.qrc +++ b/files/wizard/wizard.qrc @@ -1,7 +1,8 @@ - - + + + icons/tango/48x48/preferences-desktop-locale.png icons/tango/index.theme icons/tango/48x48/folder.png icons/tango/48x48/system-installer.png - +