From dc4563dd6a1f770551e9d3e780b703b48fe5762f Mon Sep 17 00:00:00 2001 From: Jonathan Young Date: Mon, 12 May 2014 18:49:59 +1000 Subject: [PATCH] Added install wizard. So far it only has the user select their q3a location on windows. --- installwizard.cpp | 31 ++++++++++++++++++++++ installwizard.h | 33 ++++++++++++++++++++++++ installwizard.ui | 25 ++++++++++++++++++ installwizard_locatepage.cpp | 50 ++++++++++++++++++++++++++++++++++++ installwizard_locatepage.h | 32 +++++++++++++++++++++++ installwizard_locatepage.ui | 34 ++++++++++++++++++++++++ launch.pro | 12 ++++++--- mainwindow.cpp | 42 +++++++++++++++--------------- mainwindow.h | 7 +++++ mainwindow.ui | 13 ++++++++++ 10 files changed, 255 insertions(+), 24 deletions(-) create mode 100644 installwizard.cpp create mode 100644 installwizard.h create mode 100644 installwizard.ui create mode 100644 installwizard_locatepage.cpp create mode 100644 installwizard_locatepage.h create mode 100644 installwizard_locatepage.ui diff --git a/installwizard.cpp b/installwizard.cpp new file mode 100644 index 0000000..515706a --- /dev/null +++ b/installwizard.cpp @@ -0,0 +1,31 @@ +#include "installwizard.h" +#include "ui_installwizard.h" +#include "installwizard_locatepage.h" +#include "settings.h" + +InstallWizard::InstallWizard(QWidget *parent, Settings *settings) : + QWizard(parent), + ui(new Ui::InstallWizard), + settings(settings) +{ + ui->setupUi(this); + +#ifdef Q_OS_WIN32 + setPage(Page_Locate, new InstallWizard_LocatePage(this, settings)); +#endif +} + +InstallWizard::~InstallWizard() +{ + delete ui; +} + +void InstallWizard::on_InstallWizard_customButtonClicked(int which) +{ + if (which == QWizard::FinishButton) + { +#ifdef Q_OS_WIN32 + settings->setQuakePath(field("quake3Path").toString()); +#endif + } +} diff --git a/installwizard.h b/installwizard.h new file mode 100644 index 0000000..0704bc4 --- /dev/null +++ b/installwizard.h @@ -0,0 +1,33 @@ +#ifndef INSTALLWIZARD_H +#define INSTALLWIZARD_H + +#include + +namespace Ui { +class InstallWizard; +} + +class Settings; + +class InstallWizard : public QWizard +{ + Q_OBJECT + +public: + explicit InstallWizard(QWidget *parent, Settings *settings); + ~InstallWizard(); + + enum + { + Page_Locate + }; + +private slots: + void on_InstallWizard_customButtonClicked(int which); + +private: + Ui::InstallWizard *ui; + Settings *settings; +}; + +#endif // INSTALLWIZARD_H diff --git a/installwizard.ui b/installwizard.ui new file mode 100644 index 0000000..a331d73 --- /dev/null +++ b/installwizard.ui @@ -0,0 +1,25 @@ + + + InstallWizard + + + + 0 + 0 + 400 + 300 + + + + Quake 3: Arena Install Wizard + + + + :/imgs/iolICO.png:/imgs/iolICO.png + + + + + + + diff --git a/installwizard_locatepage.cpp b/installwizard_locatepage.cpp new file mode 100644 index 0000000..918cbb9 --- /dev/null +++ b/installwizard_locatepage.cpp @@ -0,0 +1,50 @@ +#include +#include +#include "installwizard_locatepage.h" +#include "ui_installwizard_locatepage.h" +#include "settings.h" + +InstallWizard_LocatePage::InstallWizard_LocatePage(QWidget *parent, Settings *settings) : + QWizardPage(parent), + ui(new Ui::InstallWizard_LocatePage), + settings(settings) +{ + ui->setupUi(this); + registerField("quake3Path*", ui->txtLocation); +} + +InstallWizard_LocatePage::~InstallWizard_LocatePage() +{ + delete ui; +} + +void InstallWizard_LocatePage::initializePage() +{ + ui->txtLocation->setText(settings->getQuakePath()); +} + +void InstallWizard_LocatePage::on_btnBrowse_clicked() +{ + const QString location = QFileDialog::getExistingDirectory(this, tr("Select Quake 3: Arena Location"), settings->getQuakePath()); + + if (!location.isEmpty()) + { + ui->txtLocation->setText(location); + } +} + +bool InstallWizard_LocatePage::validatePage() +{ + if (ui->txtLocation->text().isEmpty()) + return false; + + QDir dir(ui->txtLocation->text()); + + if (!dir.exists()) + { + QMessageBox::warning(this, "Invalid location", "The selected location doesn't exist. Please select a valid directory."); + return false; + } + + return true; +} diff --git a/installwizard_locatepage.h b/installwizard_locatepage.h new file mode 100644 index 0000000..fe52c84 --- /dev/null +++ b/installwizard_locatepage.h @@ -0,0 +1,32 @@ +#ifndef INSTALLWIZARD_LOCATEPAGE_H +#define INSTALLWIZARD_LOCATEPAGE_H + +#include + +namespace Ui { +class InstallWizard_LocatePage; +} + +class Settings; + +class InstallWizard_LocatePage : public QWizardPage +{ + Q_OBJECT + +public: + explicit InstallWizard_LocatePage(QWidget *parent, Settings *settings); + ~InstallWizard_LocatePage(); + virtual void initializePage(); + +private slots: + void on_btnBrowse_clicked(); + +protected: + virtual bool validatePage(); + +private: + Ui::InstallWizard_LocatePage *ui; + Settings *settings; +}; + +#endif // INSTALLWIZARD_LOCATEPAGE_H diff --git a/installwizard_locatepage.ui b/installwizard_locatepage.ui new file mode 100644 index 0000000..7d43c30 --- /dev/null +++ b/installwizard_locatepage.ui @@ -0,0 +1,34 @@ + + + InstallWizard_LocatePage + + + + 0 + 0 + 400 + 300 + + + + WizardPage + + + Locate Quake 3: Arena + + + + + + Browse... + + + + + + + + + + + diff --git a/launch.pro b/launch.pro index 59f0d32..cec0e3a 100644 --- a/launch.pro +++ b/launch.pro @@ -14,12 +14,18 @@ TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ - settings.cpp + settings.cpp \ + installwizard.cpp \ + installwizard_locatepage.cpp HEADERS += mainwindow.h \ - settings.h + settings.h \ + installwizard.h \ + installwizard_locatepage.h -FORMS += mainwindow.ui +FORMS += mainwindow.ui \ + installwizard.ui \ + installwizard_locatepage.ui OTHER_FILES += \ README.md \ diff --git a/mainwindow.cpp b/mainwindow.cpp index 8328117..5e8057a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -10,6 +10,7 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "installwizard.h" ioLaunch::ioLaunch(QWidget *parent) : QMainWindow(parent), @@ -86,30 +87,13 @@ void ioLaunch::on_btnLaunch_clicked() QString ioq3; #ifdef Q_OS_WIN32 - // Prompt the user to set the ioq3 path if the settings value either doesn't exist or is invalid. - bool promptForPath = true; - - if (settings.containsQuakePath()) + if(!isQuake3PathValid()) { - const QString path = settings.getQuakePath(); - const QDir dir(path); + InstallWizard wizard(this, &settings); + wizard.exec(); - if (!path.isEmpty() && dir.exists()) - promptForPath = false; - } - - if(promptForPath) - { - QMessageBox msg; - msg.setText("Please select your Quake3 directory"); - msg.exec(); - - const QString path = QFileDialog::getExistingDirectory (this, tr("Directory")); - - if (path.isEmpty()) + if(!isQuake3PathValid()) return; - - settings.setQuakePath(path); } ioq3 = QString("\"") + settings.getQuakePath() + "/ioquake3.x86.exe\""; @@ -218,6 +202,12 @@ void ioLaunch::on_sbHeight_valueChanged(int arg1) settings.setResolutionHeight(arg1); } +void ioLaunch::on_btnRunInstallWizard_clicked() +{ + InstallWizard wizard(this, &settings); + wizard.exec(); +} + // Since q3config.cfg is generated it's nice and clean and shouldn't need a full parser. static QString ParseToken(const QString &s, int &offset) { @@ -258,6 +248,16 @@ static QString ParseToken(const QString &s, int &offset) return s.mid(start, end - start); } +#ifdef Q_OS_WIN32 +bool ioLaunch::isQuake3PathValid() const +{ + if (!settings.containsQuakePath()) + return false; + + return !settings.getQuakePath().isEmpty() && QDir(settings.getQuakePath()).exists(); +} +#endif + void ioLaunch::parseQuake3Config() { QFile file(homePath + "/baseq3/q3config.cfg"); diff --git a/mainwindow.h b/mainwindow.h index ad2dfde..62545ce 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -35,7 +35,14 @@ private slots: void on_sbHeight_valueChanged(int arg1); + void on_btnRunInstallWizard_clicked(); + private: +#ifdef Q_OS_WIN32 + // Returns false if the settings ioq3 path either doesn't exist or is invalid. + bool isQuake3PathValid() const; +#endif + void parseQuake3Config(); Ui::ioLaunch *ui; diff --git a/mainwindow.ui b/mainwindow.ui index 4ae9d84..7623440 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -339,6 +339,19 @@ QTabWidget::tab-bar{ H + + + + 10 + 70 + 101 + 23 + + + + Run Install Wizard + +