Sat, 06 Jun 2015 22:03:00 +0300
Finally done with the new Zandronum version handling
src/cfg.cpp | file | annotate | diff | comparison | revisions | |
src/cfg.h | file | annotate | diff | comparison | revisions | |
src/config.cpp | file | annotate | diff | comparison | revisions | |
src/config.h | file | annotate | diff | comparison | revisions | |
src/demo.cpp | file | annotate | diff | comparison | revisions | |
src/demo.h | file | annotate | diff | comparison | revisions | |
src/misc.cpp | file | annotate | diff | comparison | revisions | |
src/misc.h | file | annotate | diff | comparison | revisions | |
src/prompts.cpp | file | annotate | diff | comparison | revisions | |
src/prompts.h | file | annotate | diff | comparison | revisions | |
src/types.h | file | annotate | diff | comparison | revisions | |
ui/addversion.ui | file | annotate | diff | comparison | revisions | |
ui/configbox.ui | file | annotate | diff | comparison | revisions |
--- a/src/cfg.cpp Fri Jun 05 19:13:44 2015 +0300 +++ b/src/cfg.cpp Sat Jun 06 22:03:00 2015 +0300 @@ -25,11 +25,19 @@ typedef QMap<QString, QVariant> DefaultsMap; +// +// ------------------------------------------------------------------------------------------------- +// + static QSettings* getSettingsObject() { return new QSettings; } +// +// ------------------------------------------------------------------------------------------------- +// + static DefaultsMap& getDefaults() { static DefaultsMap defaults; @@ -42,6 +50,10 @@ return defaults; } +// +// ------------------------------------------------------------------------------------------------- +// + void Config::reset() { DefaultsMap& defaults = getDefaults(); @@ -50,6 +62,10 @@ set (it.key(), it.value()); } +// +// ------------------------------------------------------------------------------------------------- +// + QVariant Config::get (const QString& name) { QSettings* settings = getSettingsObject(); @@ -61,10 +77,25 @@ return value; } +// +// ------------------------------------------------------------------------------------------------- +// + bool Config::set (const QString& name, const QVariant& value) { QSettings* settings = getSettingsObject(); settings->setValue (name, value); settings->deleteLater(); return settings->status() == QSettings::NoError; -} \ No newline at end of file +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void Config::sync() +{ + QSettings* settings = getSettingsObject(); + settings->sync(); + settings->deleteLater(); +}
--- a/src/cfg.h Fri Jun 05 19:13:44 2015 +0300 +++ b/src/cfg.h Sat Jun 06 22:03:00 2015 +0300 @@ -24,5 +24,6 @@ { void reset(); QVariant get (const QString& name); - bool set(const QString& name, const QVariant& value); + bool set (const QString& name, const QVariant& value); + void sync(); }; \ No newline at end of file
--- a/src/config.cpp Fri Jun 05 19:13:44 2015 +0300 +++ b/src/config.cpp Sat Jun 06 22:03:00 2015 +0300 @@ -16,106 +16,160 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <QLabel> #include <QFileDialog> -#include <QFormLayout> -#include <QProgressBar> -#include <QMessageBox> -#include <QLineEdit> -#include <QListWidget> -#include <QPushButton> -#include <QCheckBox> -#include <QDialogButtonBox> -#include <QVBoxLayout> #include "config.h" #include "ui_configbox.h" #include "misc.h" #include "demo.h" - -class FindPathButton : public QPushButton -{ -public: - explicit FindPathButton (QWidget* parent = NULL) : - QPushButton (parent) - { - setText ("..."); - } +#include "prompts.h" - QLineEdit* editWidget() const - { - return m_editWidget; - } - - void setEditWidget (QLineEdit* edit) - { - m_editWidget = edit; - } - -private: - QLineEdit* m_editWidget; -}; +// +// ------------------------------------------------------------------------------------------------- +// ConfigWindow::ConfigWindow (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f), - ui (new Ui_ConfigBox), - m_releaseLayout (NULL), - m_testLayout (NULL) -{ - ui->setupUi (this); - - initVersions(); - initFromSettings(); - - connect (ui->wad_add, SIGNAL (clicked()), this, SLOT (addPath())); - connect (ui->wad_pathEntry, SIGNAL (returnPressed()), this, SLOT (addPath())); - connect (ui->wad_findPath, SIGNAL (clicked()), this, SLOT (findPath())); - connect (ui->wad_del, SIGNAL (clicked()), this, SLOT (delPath())); - connect (ui->buttonBox, SIGNAL (clicked (QAbstractButton*)), this, - SLOT (buttonPressed (QAbstractButton*))); - setWindowTitle (versionSignature()); -} - -// -// ----------------------------------------------------------------------------- -// - -ConfigWindow::~ConfigWindow() + ui (*new Ui_ConfigBox) { - delete ui; -} + ui.setupUi (this); -// -// ----------------------------------------------------------------------------- -// + QStringList wadpaths = Config::get ("wadpaths").toStringList(); + QList<QVariant> versions = Config::get ("versions").toList(); -void ConfigWindow::initVersions() -{ - if (m_releaseLayout == NULL) - { - m_releaseLayout = new QVBoxLayout; - m_testLayout = new QVBoxLayout; - ui->releaseVersions->setLayout (m_releaseLayout); - ui->testingVersions->setLayout (m_testLayout); - } - else - { - // Versions are being re-initialized, clear everything - for (QWidget* w : m_binaryLayoutWidgets) - w->deleteLater(); - - m_binaryLayoutWidgets.clear(); - m_pathInputFields.clear(); - } + for (int i = 0; i < wadpaths.size(); ++i) + addWadPath (wadpaths[i]); - QList<QVariant> versions = getVersions(); + ui.noDemoPrompt->setChecked (Config::get ("noprompt").toBool()); for (int i = 0; i < versions.size(); ++i) { if (not versions[i].canConvert<ZandronumVersion>()) continue; - ZandronumVersion version = versions[i].value<ZandronumVersion>(); - addVersion (version); + addVersion (versions[i].value<ZandronumVersion>()); + } + + connect (ui.wad_add, SIGNAL (clicked()), this, SLOT (addWadPath())); + connect (ui.wad_pathEntry, SIGNAL (returnPressed()), this, SLOT (addWadPath())); + connect (ui.wad_findPath, SIGNAL (clicked()), this, SLOT (findWadPath())); + connect (ui.wad_del, SIGNAL (clicked()), this, SLOT (removeCurrentWadPath())); + connect (ui.buttonBox, SIGNAL (clicked (QAbstractButton*)), this, + SLOT (buttonPressed (QAbstractButton*))); + connect (ui.addExePath, SIGNAL (clicked()), this, SLOT (newVersion())); + connect (ui.editExePath, SIGNAL (clicked()), this, SLOT (editExePressed())); + connect (ui.removeExePath, SIGNAL (clicked()), this, SLOT (removeCurrentVersion())); + connect (ui.clearExePaths, SIGNAL (clicked()), this, SLOT (clearExePathsClicked())); + setWindowTitle (versionSignature()); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +ConfigWindow::~ConfigWindow() +{ + delete &ui; + + for (int i = 0; i < m_versionEntries.size(); ++i) + delete m_versionEntries[i]; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +VersionGuiEntry* ConfigWindow::addVersion (const ZandronumVersion& version) +{ + QTableWidgetItem* labelItem = new QTableWidgetItem (version.name); + QTableWidgetItem* pathItem = new QTableWidgetItem (version.binaryPath); + int rownum = ui.exePaths->rowCount(); + ui.exePaths->setSortingEnabled (false); + ui.exePaths->insertRow (rownum); + ui.exePaths->setItem (rownum, LabelColumn, labelItem); + ui.exePaths->setItem (rownum, PathColumn, pathItem); + ui.exePaths->setSortingEnabled (true); + + VersionGuiEntry* entry = new VersionGuiEntry; + entry->isRelease = version.isRelease; + entry->name = version.name; + entry->labelItem = labelItem; + entry->pathItem = pathItem; + m_versionEntries.append (entry); + m_versionEntryMap[pathItem] = entry; + return entry; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void ConfigWindow::removeVersion (VersionGuiEntry* entry) +{ + for (int i = 0; i < m_versionEntries.size(); ++i) + { + if (m_versionEntries[i] == entry) + { + m_versionEntries.removeAt (i); + break; + } + } + + m_versionEntryMap.remove (entry->pathItem); + ui.exePaths->removeRow (entry->pathItem->row()); + delete entry; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void ConfigWindow::removeCurrentVersion() +{ + VersionGuiEntry* entry = currentVersionEntry(); + + if (entry) + removeVersion (entry); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void ConfigWindow::newVersion() +{ + VersionGuiEntry* entry = addVersion (ZandronumVersion()); + AddVersionPrompt* prompt = new AddVersionPrompt (entry, this); + + if (not prompt->exec()) + removeVersion (entry); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void ConfigWindow::editExePressed() +{ + VersionGuiEntry* entry = currentVersionEntry(); + (new AddVersionPrompt (entry, this))->exec(); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void ConfigWindow::clearExePathsClicked() +{ + if (confirm ("Are you sure you want to clear all Zandronum versions?")) + { + ui.exePaths->clearContents(); + ui.exePaths->setRowCount (0); + + for (int i = 0; i < m_versionEntries.size(); ++i) + delete m_versionEntries[i]; + + m_versionEntries.clear(); + m_versionEntryMap.clear(); } } @@ -123,166 +177,116 @@ // ------------------------------------------------------------------------------------------------- // -void ConfigWindow::addVersion (const ZandronumVersion& version) +ZandronumVersion VersionGuiEntry::toNonGuiVersion() const { - QLabel* label = new QLabel (version.name + ":"); - QLineEdit* pathInput = new QLineEdit; - FindPathButton* pathFindButton = new FindPathButton; - pathFindButton->setEditWidget (pathInput); - connect (pathFindButton, SIGNAL (clicked()), this, SLOT (findZanBinary())); - - QHBoxLayout* pathInputLayout = new QHBoxLayout; - pathInputLayout->addWidget (label); - pathInputLayout->addWidget (pathInput); - pathInputLayout->addWidget (pathFindButton); - pathInput->setText (version.binaryPath); - - m_pathInputFields[version.name] = pathInput; - - if (version.isRelease) - m_releaseLayout->addLayout (pathInputLayout); - else - m_testLayout->addLayout (pathInputLayout); - - m_binaryLayoutWidgets << pathInput << pathFindButton << label; -} - -// ============================================================================= -// ----------------------------------------------------------------------------- -void ConfigWindow::initFromSettings() -{ - ui->wad_pathsList->clear(); - - for (const QVariant& it : Config::get ("wadpaths").toList()) - addPath (it.toString()); - - QList<QVariant> versions = Config::get ("versions").toList(); - - for (int i = 0; i < versions.size(); ++i) - { - ZandronumVersion version = versions[i].value<ZandronumVersion>(); - m_pathInputFields[version.name]->setText (version.binaryPath); - } - - ui->noDemoPrompt->setChecked (Config::get ("noprompt").toBool()); + return ZandronumVersion (name, isRelease, pathItem->text()); } // -// ----------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- +// + +VersionGuiEntry* ConfigWindow::currentVersionEntry() +{ + int row = ui.exePaths->currentRow(); + + if (row != -1) + { + VersionEntryMap::iterator it = m_versionEntryMap.find (ui.exePaths->item (row, PathColumn)); + + if (it != m_versionEntryMap.end()) + return it.value(); + } + + return NULL; +} + +// +// ------------------------------------------------------------------------------------------------- // void ConfigWindow::saveSettings() { QList<QVariant> wadPathList; - - for (int i = 0; i < ui->wad_pathsList->count(); ++i) - wadPathList << ui->wad_pathsList->item (i)->text(); - - Config::set ("wadpaths", wadPathList); - Config::set ("noprompt", ui->noDemoPrompt->isChecked()); + QList<QVariant> versions; - QList<QVariant> versions = getVersions(); + for (int i = 0; i < ui.wad_pathsList->count(); ++i) + wadPathList.append (ui.wad_pathsList->item (i)->text()); - for (int i = 0; i < versions.size(); ++i) + for (int i = 0; i < m_versionEntries.size(); ++i) { - if (not versions[i].canConvert<ZandronumVersion>()) - continue; - - ZandronumVersion version = versions[i].value<ZandronumVersion>(); - version.binaryPath = m_pathInputFields[version.name]->text(); - versions[i].setValue (version); + QVariant var; + var.setValue (m_versionEntries[i]->toNonGuiVersion()); + versions.append (var); } + Config::set ("wadpaths", wadPathList); + Config::set ("noprompt", ui.noDemoPrompt->isChecked()); Config::set ("versions", versions); + Config::sync(); } // -// ----------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // -void ConfigWindow::addPath() +void ConfigWindow::addWadPath() { - addPath (ui->wad_pathEntry->text()); - ui->wad_pathEntry->clear(); + addWadPath (ui.wad_pathEntry->text()); + ui.wad_pathEntry->clear(); } // -// ----------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // -void ConfigWindow::addPath (QString path) +void ConfigWindow::addWadPath (QString path) { - ui->wad_pathsList->addItem (path); - QListWidgetItem* item = ui->wad_pathsList->item (ui->wad_pathsList->count() - 1); + ui.wad_pathsList->addItem (path); + QListWidgetItem* item = ui.wad_pathsList->item (ui.wad_pathsList->count() - 1); item->setFlags (item->flags() | Qt::ItemIsEditable); } // -// ----------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // -void ConfigWindow::findPath() +void ConfigWindow::findWadPath() { QString path = QFileDialog::getExistingDirectory (this); if (path.isEmpty()) return; - ui->wad_pathEntry->setText (path); -} - -// -// ----------------------------------------------------------------------------- -// - -void ConfigWindow::delPath() -{ - delete ui->wad_pathsList->currentItem(); + ui.wad_pathEntry->setText (path); } // -// ----------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // -void ConfigWindow::findZanBinary() +void ConfigWindow::removeCurrentWadPath() { - FindPathButton* button = static_cast<FindPathButton*> (sender()); - QString path = getBinaryPath (this); - - if (path.isEmpty()) - return; - - button->editWidget()->setText (path); + delete ui.wad_pathsList->currentItem(); } // -// ----------------------------------------------------------------------------- +// ------------------------------------------------------------------------------------------------- // -QString ConfigWindow::getBinaryPath (QWidget* parent) -{ -#ifdef _WIN32 -# define ZAN_EXE_NAME "zandronum.exe" -#else -# define ZAN_EXE_NAME "zandronum" -#endif - - return QFileDialog::getOpenFileName (parent, "", "", - "Zandronum Binaries (" ZAN_EXE_NAME ")(" ZAN_EXE_NAME ");;All files (*.*)(*.*)"); -} - -// -// ----------------------------------------------------------------------------- -// - -void ConfigWindow::buttonPressed (QAbstractButton* btn) { - if (btn == ui->buttonBox->button (QDialogButtonBox::Ok)) +void ConfigWindow::buttonPressed (QAbstractButton* btn) +{ + if (btn == ui.buttonBox->button (QDialogButtonBox::Ok)) { saveSettings(); accept(); } - else if (btn == ui->buttonBox->button (QDialogButtonBox::Cancel)) + else if (btn == ui.buttonBox->button (QDialogButtonBox::Cancel)) + { reject(); - else if (btn == ui->buttonBox->button (QDialogButtonBox::Apply)) + } + else if (btn == ui.buttonBox->button (QDialogButtonBox::Apply)) + { saveSettings(); + } } \ No newline at end of file
--- a/src/config.h Fri Jun 05 19:13:44 2015 +0300 +++ b/src/config.h Sat Jun 06 22:03:00 2015 +0300 @@ -21,35 +21,61 @@ #include "main.h" #include "types.h" +// +// ------------------------------------------------------------------------------------------------- +// +// A ZandronumVersion represented in the config window. +// + +struct VersionGuiEntry +{ + class QTableWidgetItem* labelItem; + class QTableWidgetItem* pathItem; + QString name; + bool isRelease; + + ZandronumVersion toNonGuiVersion() const; +}; + +// +// ------------------------------------------------------------------------------------------------- +// + class ConfigWindow : public QDialog { Q_OBJECT - + public: - typedef QMap<QString, class QLineEdit*> ZanBinaryMap; + enum + { + LabelColumn, + PathColumn, + }; + + typedef QMap<class QTableWidgetItem*, VersionGuiEntry*> VersionEntryMap; ConfigWindow (QWidget* parent = NULL, Qt::WindowFlags f = 0); virtual ~ConfigWindow(); - void addPath (QString path); - void initFromSettings(); - void saveSettings(); - void initVersions(); - - static QString getBinaryPath (QWidget* parent); - + public slots: - void addPath(); - void findPath(); - void delPath(); - void findZanBinary(); + void addWadPath(); + void findWadPath(); + void removeCurrentWadPath(); void buttonPressed (class QAbstractButton* btn); - + void newVersion(); + void removeCurrentVersion(); + void editExePressed(); + void clearExePathsClicked(); + private: - class Ui_ConfigBox* ui; - ZanBinaryMap m_pathInputFields; - QList<QWidget*> m_binaryLayoutWidgets; - class QVBoxLayout* m_releaseLayout; - class QVBoxLayout* m_testLayout; - - void addVersion (const ZandronumVersion& version); + class Ui_ConfigBox& ui; + QList<VersionGuiEntry*> m_versionEntries; + VersionEntryMap m_versionEntryMap; + + void addWadPath (QString path); + VersionGuiEntry* addVersion (const ZandronumVersion& version); + VersionGuiEntry* currentVersionEntry(); + void initFromSettings(); + void removeVersion (VersionGuiEntry* entry); + void saveSettings(); }; \ No newline at end of file
--- a/src/demo.cpp Fri Jun 05 19:13:44 2015 +0300 +++ b/src/demo.cpp Sat Jun 06 22:03:00 2015 +0300 @@ -76,9 +76,14 @@ static ZandronumVersion findVersion (QString versionName) { - for (const QVariant& it : getVersions()) + QList<QVariant> versions = Config::get ("versions").toList(); + + for (int i = 0; i < versions.size(); ++i) { - ZandronumVersion version = it.value<ZandronumVersion>(); + if (not versions[i].canConvert<ZandronumVersion>()) + continue; + + ZandronumVersion version = versions[i].value<ZandronumVersion>(); if (version.name == versionName or version.name + "M" == versionName @@ -87,7 +92,7 @@ return version; } } - + return ZandronumVersion(); } @@ -103,9 +108,9 @@ { error (tr ("No WAD paths configured!")); - // Cannot just return an empty string here since that'd trigger - // another error prompt - skip ahead and exit. - exit (9); + // Cannot just return an empty string here since that'd trigger another error prompt - skip + // ahead and exit. + exit (1); } for (int i = 0; i < wadpaths.size(); ++i) @@ -204,8 +209,8 @@ } } - stream >> headers.length - >> length; + stream >> headers.length; + stream >> length; // The remaining headers are variable and relative to the length header. headers.version = headers.length + 1;
--- a/src/demo.h Fri Jun 05 19:13:44 2015 +0300 +++ b/src/demo.h Sat Jun 06 22:03:00 2015 +0300 @@ -27,11 +27,4 @@ PrivateBuild = 3 }; -struct VersionInfo -{ - QString shortVersion; - QString versionString; - bool release; -}; - int launchDemo (QString path); \ No newline at end of file
--- a/src/misc.cpp Fri Jun 05 19:13:44 2015 +0300 +++ b/src/misc.cpp Sat Jun 06 22:03:00 2015 +0300 @@ -16,8 +16,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <QFileDialog> +#include <QMessageBox> #include "misc.h" -#include <QMessageBox> + +// +// ----------------------------------------------------------------------------- +// uint32 makeByteID (uint8 a, uint8 b, uint8 c, uint8 d) { @@ -37,19 +42,6 @@ // ----------------------------------------------------------------------------- // -void addVersion (const ZandronumVersion& version) -{ - QList<QVariant> versions = getVersions(); - QVariant var; - var.setValue (version); - versions.append (var); - Config::set ("versions", versions); -} - -// -// ----------------------------------------------------------------------------- -// - QString basename (const QString& path) { int lastpos = path.lastIndexOf ("/"); @@ -68,4 +60,20 @@ { return QMessageBox::question (NULL, QObject::tr ("Confirm"), text, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::No; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +QString getBinaryPath (QWidget* parent) +{ +#ifdef _WIN32 +# define ZAN_EXE_NAME "zandronum.exe" +#else +# define ZAN_EXE_NAME "zandronum" +#endif + + return QFileDialog::getOpenFileName (parent, "", "", + "Zandronum Binaries (" ZAN_EXE_NAME ")(" ZAN_EXE_NAME ");;All files (*)(*)"); } \ No newline at end of file
--- a/src/misc.h Fri Jun 05 19:13:44 2015 +0300 +++ b/src/misc.h Sat Jun 06 22:03:00 2015 +0300 @@ -21,9 +21,9 @@ uint32 makeByteID (uint8 a, uint8 b, uint8 c, uint8 d); QString basename (const QString& path); -void addVersion (const ZandronumVersion& version); bool confirm (const QString& text); QList<QVariant> getVersions(); +QString getBinaryPath (QWidget* parent); // // -----------------------------------------------------------------------------
--- a/src/prompts.cpp Fri Jun 05 19:13:44 2015 +0300 +++ b/src/prompts.cpp Sat Jun 06 22:03:00 2015 +0300 @@ -16,15 +16,19 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <QTableWidgetItem> +#include <QFileDialog> #include "prompts.h" #include "ui_unknownversion.h" #include "misc.h" #include "config.h" #include "ui_findfile.h" -#include <QFileDialog> +#include "ui_addversion.h" -// ============================================================================= -// ----------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------- +// + UnknownVersionPrompt::UnknownVersionPrompt ( QString fileName, QString binaryName, @@ -38,73 +42,159 @@ { ui = new Ui_UnknownVersion; ui->setupUi (this); - + // Replace the placeholders QString text = ui->m_description->text(); text.replace ("<DEMO>", basename (fileName)); text.replace ("<VERSION>", binaryName); ui->m_description->setText (text); - - connect (ui->m_addVersion, SIGNAL (clicked(bool)), this, SLOT (addBinary())); - connect (ui->m_findBinary, SIGNAL (clicked(bool)), this, SLOT (findBinary())); + + connect (ui->m_addVersion, SIGNAL (clicked (bool)), this, SLOT (addBinary())); + connect (ui->m_findBinary, SIGNAL (clicked (bool)), this, SLOT (findBinary())); setWindowTitle (versionSignature()); } -// ============================================================================= -// ----------------------------------------------------------------------------- -UnknownVersionPrompt::~UnknownVersionPrompt() { +// +// ------------------------------------------------------------------------------------------------- +// + +UnknownVersionPrompt::~UnknownVersionPrompt() +{ delete ui; } -// ============================================================================= -// ----------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------- +// + void UnknownVersionPrompt::addBinary() { - addVersion (ZandronumVersion (m_binaryString, m_isRelease, ui->m_binaryPath->text())); + ZandronumVersion version (m_binaryString, m_isRelease, ui->m_binaryPath->text()); + QList<QVariant> versions = Config::get ("versions").toList(); + QVariant var; + var.setValue (version); + versions.append (var); + Config::set ("versions", versions); accept(); } -// ============================================================================= -// ----------------------------------------------------------------------------- -void UnknownVersionPrompt::findBinary() { - QString path = ConfigWindow::getBinaryPath (this); - +// +// ------------------------------------------------------------------------------------------------- +// + +void UnknownVersionPrompt::findBinary() +{ + QString path = getBinaryPath (this); + if (path.isEmpty()) return; - + ui->m_binaryPath->setText (path); } -// ============================================================================= -// ----------------------------------------------------------------------------- +// +// ------------------------------------------------------------------------------------------------- +// + FindFilePrompt::FindFilePrompt (QWidget* parent, Qt::WindowFlags f) : QDialog (parent, f), m_ui (new Ui_FindFile) { m_ui->setupUi (this); connect (m_ui->m_find, SIGNAL (clicked()), this, SLOT (findDemo())); - + setWindowTitle (versionSignature()); } -// ============================================================================= -// ----------------------------------------------------------------------------- -FindFilePrompt::~FindFilePrompt() { +// +// ------------------------------------------------------------------------------------------------- +// + +FindFilePrompt::~FindFilePrompt() +{ delete m_ui; } -// ============================================================================= -// ----------------------------------------------------------------------------- -void FindFilePrompt::findDemo() { +// +// ------------------------------------------------------------------------------------------------- +// + +void FindFilePrompt::findDemo() +{ QString path = QFileDialog::getOpenFileName (this, tr ("Open Demo File"), - QDir::homePath(), tr ("Demo files (*.cld);;All files (*.*)")); - - if (!path.isEmpty()) + QDir::homePath(), tr ("Demo files (*.cld);;All files (*.*)")); + + if (not path.isEmpty()) m_ui->m_path->setText (path); } -// ============================================================================= -// ----------------------------------------------------------------------------- -QString FindFilePrompt::path() const { +// +// ------------------------------------------------------------------------------------------------- +// + +QString FindFilePrompt::path() const +{ return m_ui->m_path->text(); } + +// +// ------------------------------------------------------------------------------------------------- +// + +AddVersionPrompt::AddVersionPrompt (VersionGuiEntry* entry, QWidget* parent, Qt::WindowFlags f) + : QDialog (parent, f), + ui (*new Ui_AddVersion), + m_entry (entry) +{ + ui.setupUi (this); + connect (ui.buttonBox, SIGNAL (accepted()), this, SLOT (acceptPressed())); + connect (ui.buttonBox, SIGNAL (rejected()), this, SLOT (reject())); + connect (ui.findExeButton, SIGNAL (clicked()), this, SLOT (findExePath())); + + ui.nameField->setText (entry->name); + ui.exePathField->setText (entry->pathItem->text()); + ui.releaseCheckbox->setChecked (entry->isRelease); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void AddVersionPrompt::acceptPressed() +{ + m_entry->name = ui.nameField->text(); + m_entry->isRelease = ui.releaseCheckbox->isChecked(); + m_entry->labelItem->setText (m_entry->name); + m_entry->pathItem->setText (ui.exePathField->text()); + accept(); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +AddVersionPrompt::~AddVersionPrompt() +{ + delete &ui; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void AddVersionPrompt::findExePath() +{ + QString path = getBinaryPath (this); + + if (not path.isEmpty()) + ui.exePathField->setText (path); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +VersionGuiEntry* AddVersionPrompt::getVersionInfo() +{ + return m_entry; +} \ No newline at end of file
--- a/src/prompts.h Fri Jun 05 19:13:44 2015 +0300 +++ b/src/prompts.h Sat Jun 06 22:03:00 2015 +0300 @@ -16,53 +16,73 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef ZCINEMA_PROMPTS_H -#define ZCINEMA_PROMPTS_H - +#pragma once #include <QDialog> #include "main.h" #include "types.h" -class QAbstractButton; -class Ui_UnknownVersion; -class Ui_FindFile; +// +// ------------------------------------------------------------------------------------------------- +// -// ============================================================================= -// ----------------------------------------------------------------------------- -class UnknownVersionPrompt : public QDialog { +class UnknownVersionPrompt : public QDialog +{ Q_OBJECT - + public: - explicit UnknownVersionPrompt (QString fileName, QString binaryName, bool isRelease, - QWidget* parent = NULL, Qt::WindowFlags f = 0); + UnknownVersionPrompt (QString fileName, QString binaryName, bool isRelease, + QWidget* parent = NULL, Qt::WindowFlags f = 0); virtual ~UnknownVersionPrompt(); - + public slots: void findBinary(); void addBinary(); - + private: - Ui_UnknownVersion* ui; - QString m_binaryString; - bool m_isRelease; + class Ui_UnknownVersion* ui; + QString m_binaryString; + bool m_isRelease; }; -// ============================================================================= -// ----------------------------------------------------------------------------- -class FindFilePrompt : public QDialog { +// +// ------------------------------------------------------------------------------------------------- +// + +class FindFilePrompt : public QDialog +{ Q_OBJECT - + public: - explicit FindFilePrompt (QWidget* parent = 0, Qt::WindowFlags f = 0); + FindFilePrompt (QWidget* parent = NULL, Qt::WindowFlags f = 0); virtual ~FindFilePrompt(); - + QString path() const; - + public slots: void findDemo(); - + private: - Ui_FindFile* m_ui; + class Ui_FindFile* m_ui; }; -#endif // ZCINEMA_PROMPTS_H \ No newline at end of file +// +// ------------------------------------------------------------------------------------------------- +// + +class AddVersionPrompt : public QDialog +{ + Q_OBJECT + +public: + AddVersionPrompt (struct VersionGuiEntry* entry, QWidget* parent = NULL, Qt::WindowFlags f = 0); + virtual ~AddVersionPrompt(); + VersionGuiEntry* getVersionInfo(); + +private slots: + void acceptPressed(); + void findExePath(); + +private: + class Ui_AddVersion& ui; + struct VersionGuiEntry* m_entry; +};
--- a/src/types.h Fri Jun 05 19:13:44 2015 +0300 +++ b/src/types.h Sat Jun 06 22:03:00 2015 +0300 @@ -35,10 +35,6 @@ typedef quint32 uint32; typedef quint64 uint64; -#ifdef IN_IDE_PARSER // :| -typedef void FILE; -#endif - struct ZandronumVersion { ZandronumVersion (QString name, bool isRelease, QString binaryPath) :
--- a/ui/addversion.ui Fri Jun 05 19:13:44 2015 +0300 +++ b/ui/addversion.ui Sat Jun 06 22:03:00 2015 +0300 @@ -6,8 +6,8 @@ <rect> <x>0</x> <y>0</y> - <width>400</width> - <height>149</height> + <width>472</width> + <height>144</height> </rect> </property> <property name="windowTitle"> @@ -15,38 +15,31 @@ </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string><b>Add a Zandronum Version</b></string> - </property> - </widget> - </item> - <item> <layout class="QFormLayout" name="formLayout"> <item row="0" column="0"> - <widget class="QLabel" name="label"> + <widget class="QLabel" name="nameLabel"> <property name="text"> - <string>Name:</string> + <string>Name</string> </property> </widget> </item> <item row="0" column="1"> - <widget class="QLineEdit" name="m_binaryName"/> + <widget class="QLineEdit" name="nameField"/> </item> <item row="1" column="0"> - <widget class="QLabel" name="label_2"> + <widget class="QLabel" name="exePathLabel"> <property name="text"> - <string>Path to Binary:</string> + <string>Path to Executable</string> </property> </widget> </item> <item row="1" column="1"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> - <widget class="QLineEdit" name="m_binaryPath"/> + <widget class="QLineEdit" name="exePathField"/> </item> <item> - <widget class="QPushButton" name="m_findBinary"> + <widget class="QPushButton" name="findExeButton"> <property name="text"> <string>...</string> </property> @@ -55,7 +48,7 @@ </layout> </item> <item row="2" column="1"> - <widget class="QCheckBox" name="m_release"> + <widget class="QCheckBox" name="releaseCheckbox"> <property name="text"> <string>Release</string> </property>
--- a/ui/configbox.ui Fri Jun 05 19:13:44 2015 +0300 +++ b/ui/configbox.ui Sat Jun 06 22:03:00 2015 +0300 @@ -117,57 +117,88 @@ </item> </layout> </widget> - <widget class="QWidget" name="binaryPaths"> + <widget class="QWidget" name="exePathsTab"> <attribute name="title"> - <string>Binary Paths</string> + <string>Zandronum Paths</string> </attribute> - <layout class="QVBoxLayout" name="verticalLayout_4"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> - <widget class="QScrollArea" name="scrollArea"> - <property name="frameShape"> - <enum>QFrame::NoFrame</enum> + <widget class="QTableWidget" name="exePaths"> + <property name="editTriggers"> + <set>QAbstractItemView::NoEditTriggers</set> </property> - <property name="widgetResizable"> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="selectionBehavior"> + <enum>QAbstractItemView::SelectRows</enum> + </property> + <property name="sortingEnabled"> <bool>true</bool> </property> - <widget class="QWidget" name="scrollAreaWidgetContents"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>504</width> - <height>207</height> - </rect> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> + <column> + <property name="text"> + <string>Version</string> + </property> + </column> + <column> + <property name="text"> + <string>Executable Path</string> </property> - <layout class="QVBoxLayout" name="verticalLayout_5" stretch="0,0"> - <item> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>Release versions</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_7"> - <item> - <widget class="QWidget" name="releaseVersions" native="true"/> - </item> - </layout> - </widget> - </item> - <item> - <widget class="QGroupBox" name="groupBox_2"> - <property name="title"> - <string>Testing versions</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_8"> - <item> - <widget class="QWidget" name="testingVersions" native="true"/> - </item> - </layout> - </widget> - </item> - </layout> - </widget> + </column> </widget> </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_8"> + <item> + <widget class="QPushButton" name="addExePath"> + <property name="text"> + <string>Add</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="editExePath"> + <property name="text"> + <string>Edit</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="removeExePath"> + <property name="text"> + <string>Remove</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="clearExePaths"> + <property name="text"> + <string>Clear</string> + </property> + </widget> + </item> + <item> + <spacer name="verticalSpacer_5"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> </layout> </widget> <widget class="QWidget" name="tab_3"> @@ -181,7 +212,7 @@ <string>If this is not set, a prompt showing demo info is displayed first.</string> </property> <property name="text"> - <string>Launch without prompt</string> + <string>Launch demos without info dialog</string> </property> </widget> </item>