Sat, 06 Jun 2015 23:12:59 +0300
Renamed the src* directories into commonlib/, config/ and launcher/
--- a/CMakeLists.txt Sat Jun 06 23:06:14 2015 +0300 +++ b/CMakeLists.txt Sat Jun 06 23:12:59 2015 +0300 @@ -13,40 +13,39 @@ include_directories (${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}) -set (ZCINEMA_SOURCES - src/demo.cpp - src/main.cpp - src/prompts.cpp +set (ZCINEMA_LAUNCHER_SOURCES + launcher/demo.cpp + launcher/main.cpp + launcher/prompts.cpp ) set (ZCINEMA_COMMON_SOURCES - src-common/config.cpp - src-common/misc.cpp - src-common/version.cpp + commonlib/config.cpp + commonlib/misc.cpp + commonlib/version.cpp ) set (ZCINEMA_CONFIG_SOURCES - src-config/configwindow.cpp - src-config/addversionprompt.cpp - src-config/main.cpp + config/configwindow.cpp + config/addversionprompt.cpp + config/main.cpp ) set (ZCINEMA_HEADERS - src-common/config.h - src-common/misc.h - src-common/types.h - src-common/version.h - src-config/addversionprompt.h - src-config/configwindow.h - src/demo.h - src/prompts.h + commonlib/config.h + commonlib/misc.h + commonlib/types.h + commonlib/version.h + config/addversionprompt.h + config/configwindow.h + launcher/demo.h + launcher/prompts.h ) set (ZCINEMA_FORMS ui/findfile.ui ui/demoprompt.ui ui/unknownversion.ui - ui/versionEditor.ui ui/configbox.ui ui/addversion.ui ) @@ -58,12 +57,7 @@ endif() include_directories ("${PROJECT_BINARY_DIR}") -include_directories ("${PROJECT_SOURCE_DIR}/src") -include_directories ("${PROJECT_BINARY_DIR}/src") -include_directories ("${PROJECT_SOURCE_DIR}/src-common") -include_directories ("${PROJECT_BINARY_DIR}/src-common") -include_directories ("${PROJECT_SOURCE_DIR}/src-config") -include_directories ("${PROJECT_BINARY_DIR}/src-config") +include_directories ("${PROJECT_SOURCE_DIR}") if (USE_QT5) qt5_generate_moc (ZCINEMA_MOC ${ZCINEMA_HEADERS}) @@ -87,7 +81,7 @@ ${ZCINEMA_FORMS_HEADERS}) endif() -add_executable (${PROJECT_NAME} WIN32 ${ZCINEMA_SOURCES}) +add_executable (${PROJECT_NAME} WIN32 ${ZCINEMA_LAUNCHER_SOURCES}) add_executable (${PROJECT_NAME}-config WIN32 ${ZCINEMA_CONFIG_SOURCES}) if (USE_QT5)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commonlib/config.cpp Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,100 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <assert.h> +#include <QDir> +#include <QTextStream> +#include <QSettings> +#include "config.h" + +typedef QMap<QString, QVariant> DefaultsMap; + +// +// ------------------------------------------------------------------------------------------------- +// + +static QSettings* getSettingsObject() +{ + return new QSettings; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +static DefaultsMap& getDefaults() +{ + static DefaultsMap defaults; + + if (defaults.isEmpty()) + { + // Initialize defaults here. + } + + return defaults; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void Config::reset() +{ + DefaultsMap& defaults = getDefaults(); + + for (DefaultsMap::iterator it = defaults.begin(); it != defaults.end(); ++it) + set (it.key(), it.value()); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +QVariant Config::get (const QString& name) +{ + QSettings* settings = getSettingsObject(); + DefaultsMap& defaults = getDefaults(); + DefaultsMap::iterator it = defaults.find (name); + QVariant def = it != defaults.end() ? *it : QVariant(); + QVariant value = settings->value (name, def); + settings->deleteLater(); + 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; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void Config::sync() +{ + QSettings* settings = getSettingsObject(); + settings->sync(); + settings->deleteLater(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commonlib/config.h Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,28 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include <QVariant> + +namespace Config +{ + void reset(); + QVariant get (const QString& name); + bool set (const QString& name, const QVariant& value); + void sync(); +}; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commonlib/misc.cpp Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,61 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <QFileDialog> +#include "misc.h" +#include "config.h" + +// +// ----------------------------------------------------------------------------- +// + +void commonInit() +{ + qRegisterMetaType<ZandronumVersion> ("ZandronumVersion"); + qRegisterMetaTypeStreamOperators<ZandronumVersion> ("ZandronumVersion"); +} + +// +// ----------------------------------------------------------------------------- +// + +QString basename (const QString& path) +{ + int lastpos = path.lastIndexOf ("/"); + + if (lastpos != -1) + return path.mid (lastpos + 1); + + return path; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commonlib/misc.h Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,70 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include "types.h" + +inline quint32 makeByteID (quint8 a, quint8 b, quint8 c, quint8 d) +{ + return a | (b << 8) | (c << 16) | (d << 24); +} + +void commonInit(); +QString basename (const QString& path); +bool confirm (const QString& text); +QString getBinaryPath (QWidget* parent); + +// +// ----------------------------------------------------------------------------- +// + +template<typename T> +T clamp (T a, T min, T max) +{ + return (a > max) ? max : (a < min) ? min : a; +} + +// +// ----------------------------------------------------------------------------- +// + +template<typename T> +T min (T a, T b) +{ + return (a < b) ? a : b; +} + +// +// ----------------------------------------------------------------------------- +// + +template<typename T> +T max (T a, T b) +{ + return (a > b) ? a : b; +} + +// +// ----------------------------------------------------------------------------- +// + +template<typename T> +T abs (T a) +{ + return (a < 0) ? -a : a; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commonlib/types.h Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,62 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include <QString> +#include <QList> +#include <QVariant> + +template<class T> using list = QList<T>; +template<class T> using initlist = std::initializer_list<T>; +using std::size_t; + +typedef qint8 int8; +typedef qint16 int16; +typedef qint32 int32; +typedef qint64 int64; +typedef quint8 uint8; +typedef quint16 uint16; +typedef quint32 uint32; +typedef quint64 uint64; + +struct ZandronumVersion +{ + ZandronumVersion (QString name, bool isRelease, QString binaryPath) : + name (name), + binaryPath (binaryPath), + isRelease (isRelease) {} + + ZandronumVersion() : + isRelease (false) {} + + QString name; + QString binaryPath; + bool isRelease; +}; + +inline QDataStream& operator<< (QDataStream& out, const ZandronumVersion& version) +{ + return (out << version.name << version.binaryPath << version.isRelease); +} + +inline QDataStream& operator>> (QDataStream& in, ZandronumVersion& version) +{ + return (in >> version.name >> version.binaryPath >> version.isRelease); +} + +Q_DECLARE_METATYPE (ZandronumVersion) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commonlib/version.cpp Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,55 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "version.h" +#include "hginfo.h" + +// +// ------------------------------------------------------------------------------------------------- +// + +QString versionString() +{ +#ifndef RELEASE +# ifdef HG_NODE + // non-release with hg info + return VERSION_STRING "-" HG_NODE; +# else + // non-release, no hg info + return VERSION_STRING "-beta"; +# endif +#else + // release + return VERSION_STRING; +#endif +} + +// +// ------------------------------------------------------------------------------------------------- +// + +QString versionSignature() +{ +#ifdef HG_DATE_STRING +# define DATE_INFO " (" HG_DATE_STRING ")" +#else +# define DATE_INFO "" +#endif + + return QString (APPNAME) + " " + versionString() + DATE_INFO; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/commonlib/version.h Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,42 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#define APPNAME "ZCinema" +#define UNIXNAME "zcinema" +#define VERSION_MAJOR 1 +#define VERSION_MINOR 0 +#define VERSION_PATCH 0 +// #define RELEASE + +#define MACRO_TO_STRING(A) MACRO_TO_STRING_(A) +#define MACRO_TO_STRING_(A) #A + +#if VERSION_PATCH == 0 +# define VERSION_STRING MACRO_TO_STRING (VERSION_MAJOR) \ + "." MACRO_TO_STRING (VERSION_MINOR) +#else +# define VERSION_STRING MACRO_TO_STRING (VERSION_MAJOR) \ + "." MACRO_TO_STRING (VERSION_MINOR) \ + "." MACRO_TO_STRING (VERSION_PATCH) +#endif + +#include "config.h" + +QString versionString(); +QString versionSignature(); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/addversionprompt.cpp Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,85 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <QTableWidget> +#include <commonlib/misc.h> +#include "addversionprompt.h" +#include "configwindow.h" +#include "ui_addversion.h" + +// +// ------------------------------------------------------------------------------------------------- +// + +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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/addversionprompt.h Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,41 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <QDialog> + +// +// ------------------------------------------------------------------------------------------------- +// + +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; +}; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/configwindow.cpp Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,303 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <QFileDialog> +#include <QMessageBox> +#include <commonlib/config.h> +#include <commonlib/version.h> +#include "addversionprompt.h" +#include "configwindow.h" +#include "ui_configbox.h" + +// +// ----------------------------------------------------------------------------- +// + +bool confirm (const QString& text) +{ + return QMessageBox::question (NULL, QObject::tr ("Confirm"), text, + QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::No; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +ConfigWindow::ConfigWindow (QWidget* parent, Qt::WindowFlags f) : + QDialog (parent, f), + ui (*new Ui_ConfigBox) +{ + ui.setupUi (this); + + QStringList wadpaths = Config::get ("wadpaths").toStringList(); + QList<QVariant> versions = Config::get ("versions").toList(); + + for (int i = 0; i < wadpaths.size(); ++i) + addWadPath (wadpaths[i]); + + ui.noDemoPrompt->setChecked (Config::get ("noprompt").toBool()); + + for (int i = 0; i < versions.size(); ++i) + { + if (not versions[i].canConvert<ZandronumVersion>()) + continue; + + 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(); + } +} + +// +// ------------------------------------------------------------------------------------------------- +// + +ZandronumVersion VersionGuiEntry::toNonGuiVersion() const +{ + 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; + QList<QVariant> versions; + + for (int i = 0; i < ui.wad_pathsList->count(); ++i) + wadPathList.append (ui.wad_pathsList->item (i)->text()); + + for (int i = 0; i < m_versionEntries.size(); ++i) + { + 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::addWadPath() +{ + addWadPath (ui.wad_pathEntry->text()); + ui.wad_pathEntry->clear(); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void ConfigWindow::addWadPath (QString path) +{ + ui.wad_pathsList->addItem (path); + QListWidgetItem* item = ui.wad_pathsList->item (ui.wad_pathsList->count() - 1); + item->setFlags (item->flags() | Qt::ItemIsEditable); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void ConfigWindow::findWadPath() +{ + QString path = QFileDialog::getExistingDirectory (this); + + if (path.isEmpty()) + return; + + ui.wad_pathEntry->setText (path); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void ConfigWindow::removeCurrentWadPath() +{ + delete ui.wad_pathsList->currentItem(); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void ConfigWindow::buttonPressed (QAbstractButton* btn) +{ + if (btn == ui.buttonBox->button (QDialogButtonBox::Ok)) + { + saveSettings(); + accept(); + } + else if (btn == ui.buttonBox->button (QDialogButtonBox::Cancel)) + { + reject(); + } + else if (btn == ui.buttonBox->button (QDialogButtonBox::Apply)) + { + saveSettings(); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/configwindow.h Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,80 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include <QDialog> +#include "commonlib/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: + enum + { + LabelColumn, + PathColumn, + }; + + typedef QMap<class QTableWidgetItem*, VersionGuiEntry*> VersionEntryMap; + + ConfigWindow (QWidget* parent = NULL, Qt::WindowFlags f = 0); + virtual ~ConfigWindow(); + +public slots: + void addWadPath(); + void findWadPath(); + void removeCurrentWadPath(); + void buttonPressed (class QAbstractButton* btn); + void newVersion(); + void removeCurrentVersion(); + void editExePressed(); + void clearExePathsClicked(); + +private: + 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
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/config/main.cpp Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,32 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <QApplication> +#include <commonlib/version.h> +#include <commonlib/misc.h> +#include "configwindow.h" + +int main (int argc, char* argv[]) +{ + QApplication app (argc, argv); + app.setApplicationName (UNIXNAME); + app.setOrganizationName (UNIXNAME); + app.setApplicationVersion (versionString()); + commonInit(); + return (new ConfigWindow)->exec(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/launcher/demo.cpp Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,369 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <QFile> +#include <QDataStream> +#include <QMessageBox> +#include <QProcess> +#include <commonlib/misc.h> +#include <commonlib/config.h> +#include <commonlib/version.h> +#include "demo.h" +#include "prompts.h" +#include "ui_demoprompt.h" + +// +// ------------------------------------------------------------------------------------------------- +// + +QString uncolorize (const QString& in) +{ + // TODO: Handle long-form colors like \c[Red] + QString out; + int skip = 0; + + for (QChar c : in) + { + if (skip-- > 0) + continue; + + if (c == QChar ('\034')) + { + skip = 1; + continue; + } + + out += c; + } + + return out; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +static QString tr (const char* msg) +{ + return QObject::tr (msg); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +static void error (QString msg) +{ + QMessageBox::critical (NULL, "Error", msg); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +static ZandronumVersion findVersion (QString versionName) +{ + QList<QVariant> versions = Config::get ("versions").toList(); + + for (int i = 0; i < versions.size(); ++i) + { + if (not versions[i].canConvert<ZandronumVersion>()) + continue; + + ZandronumVersion version = versions[i].value<ZandronumVersion>(); + + if (version.name == versionName + or version.name + "M" == versionName + or version.name == versionName + "M") + { + return version; + } + } + + return ZandronumVersion(); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +static QString findWAD (QString name) +{ + QStringList wadpaths = Config::get ("wadpaths").toStringList(); + + if (wadpaths.empty()) + { + 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 (1); + } + + for (int i = 0; i < wadpaths.size(); ++i) + { + QString fullpath = QString ("%1/%2").arg (wadpaths[i]).arg (name); + QFile f (fullpath); + + if (f.exists()) + return fullpath; + } + + return ""; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +QString readString (QDataStream& stream) +{ + QString out; + uint8 ch; + + for (stream >> ch; ch != 0; stream >> ch) + out += QChar (ch); + + return out; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +struct UserInfo +{ + QString netname; + QString skin; + QString className; + uint32 color; + uint32 aimdist; + uint32 railcolor; + uint8 gender; + uint8 handicap; + uint8 unlagged; + uint8 respawnOnFire; + uint8 ticsPerUpdate; + uint8 connectionType; +}; + +struct DemoHeaders +{ + uint8 length; + uint8 version; + uint8 userInfo; + uint8 bodyStart; + uint8 wads; +}; + +int launchDemo (QString path) +{ + QFile f (path); + + if (not f.open (QIODevice::ReadOnly)) + { + error (tr ("Couldn't open '%1' for reading: %2").arg (path).arg (strerror (errno))); + return 1; + } + + QDataStream stream (&f); + stream.setByteOrder (QDataStream::LittleEndian); + + DemoHeaders headers; + uint32 length; + uint16 zanversionID, numWads; + uint32 longSink; + QString zanversion; + QStringList wads; + UserInfo userinfo; + + // Assume a release build if the build ID not supplied. The demo only got the "ZCLD" signature + // in the 1.1 release build, 1.1.1 had no testing binaries and the build ID is included in 1.2 + // onward. + BuildType buildID = ReleaseBuild; + + bool ready = false; + + // Check signature + { + uint32 demosignature; + stream >> demosignature; + + if (demosignature != makeByteID ('Z', 'C', 'L', 'D')) + { + error (tr ("'%1' is not a valid Zandronum demo file!").arg (path)); + return 1; + } + } + + stream >> headers.length; + stream >> length; + + // The remaining headers are variable and relative to the length header. + headers.version = headers.length + 1; + headers.userInfo = headers.length + 3, + headers.bodyStart = headers.length + 4; + headers.wads = headers.length + 10; + + // Read the demo header and get data + for (;;) + { + uint8 header; + stream >> header; + + if (header == headers.bodyStart) + { + ready = true; + break; + } + else if (header == headers.version) + { + stream >> zanversionID; + zanversion = readString (stream); + + if (not zanversion.startsWith ("1.1-") and not zanversion.startsWith ("1.1.1-")) + { + uint8 a; + stream >> a; + buildID = (BuildType) a; + } + + // The demo wads header accidentally changed in 1.3. :( + if (zanversion.left(1).toInt() >= 2 or zanversion.startsWith ("1.3")) + headers.wads = headers.length + 8; + + stream >> longSink; // rng seed - we don't need it + } + else if (header == headers.userInfo) + { + userinfo.netname = readString (stream); + stream >> userinfo.gender; + stream >> userinfo.color; + stream >> userinfo.aimdist; + userinfo.skin = readString (stream); + stream >> userinfo.railcolor; + stream >> userinfo.handicap; + stream >> userinfo.unlagged; + stream >> userinfo.respawnOnFire; + stream >> userinfo.ticsPerUpdate; + stream >> userinfo.connectionType; + userinfo.className = readString (stream); + } + else if (header == headers.wads) + { + QString sink; + stream >> numWads; + + for (uint8 i = 0; i < numWads; ++i) + { + QString wad = readString (stream); + wads << wad; + } + + // The demo has two checksum strings. We're not interested in them, though. + (sink = readString (stream)) = readString (stream); + } + else + { + error (tr ("Unknown header %1!\n").arg (int (header))); + return 1; + } + } + + if (not ready) + { + error (tr ("Incomplete demo header in '%s'!").arg (path)); + return 1; + } + + ZandronumVersion version = findVersion (zanversion); + + if (version.name.isNull()) + { + QDialog* prompt = new UnknownVersionPrompt (path, zanversion, (buildID == ReleaseBuild)); + + if (not prompt->exec()) + return 1; + } + + QString iwadpath; + QStringList pwadpaths; + + // Find the WADs + for (const QString& wad : wads) + { + QString path = findWAD (wad); + + // WAD names are case-sensitive under non-Windows and they can appear in uppercase + // so we need to test that too. + if (path.isEmpty()) + path = findWAD (wad.toUpper()); + + if (path.isEmpty()) + { + error (tr ("Couldn't find %1!").arg (wad)); + return 1; + } + + if (&wad == &wads.first()) + iwadpath = path; + else + pwadpaths << path; + } + + if (not Config::get ("noprompt").toBool()) + { + QString pwadtext; + + for (const QString& wad : wads) + { + if (&wad == &wads.first()) + continue; // skip the IWAD + + if (not pwadtext.isEmpty()) + pwadtext += "<br />"; + + pwadtext += wad; + } + + QDialog* dlg = new QDialog; + Ui_DemoPrompt ui; + ui.setupUi (dlg); + ui.demoNameLabel->setText (basename (path)); + ui.demoRecorder->setText (uncolorize (userinfo.netname)); + ui.versionLabel->setText (zanversion); + ui.iwadLabel->setText (wads[0]); + ui.pwadsLabel->setText (pwadtext); + dlg->setWindowTitle (versionSignature()); + + if (not dlg->exec()) + return 0; + } + + QStringList cmdlineList; + cmdlineList << "-playdemo" << path << "-iwad" << iwadpath; + + if (pwadpaths.size() > 0) + cmdlineList << "-file" << pwadpaths; + + // print ("Executing: %1 %2\n", binarypath, cmdlineList.join (" ")); + QProcess* proc = new QProcess; + proc->start (version.binaryPath, cmdlineList); + proc->waitForFinished (-1); + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/launcher/demo.h Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,30 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include <QString> + +enum BuildType +{ + OtherBuild = 0, + ReleaseBuild = 1, + InternalBuild = 2, + PrivateBuild = 3 +}; + +int launchDemo (QString path); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/launcher/main.cpp Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,50 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <QApplication> +#include <commonlib/misc.h> +#include <commonlib/version.h> +#include "demo.h" +#include "prompts.h" + +// +// ------------------------------------------------------------------------------------------------- +// + +int main (int argc, char* argv[]) +{ + QApplication app (argc, argv); + app.setApplicationName (UNIXNAME); + app.setOrganizationName (UNIXNAME); + app.setApplicationVersion (versionString()); + commonInit(); + + if (argc > 1) + { + return launchDemo (argv[1]); + } + else + { + FindFilePrompt* dlg = new FindFilePrompt (NULL); + + if (not dlg->exec()) + return 0; + + return launchDemo (dlg->path()); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/launcher/prompts.cpp Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,137 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <QFileDialog> +#include <commonlib/misc.h> +#include <commonlib/version.h> +#include <commonlib/config.h> +#include "prompts.h" +#include "ui_unknownversion.h" +#include "ui_findfile.h" + +// +// ------------------------------------------------------------------------------------------------- +// + +UnknownVersionPrompt::UnknownVersionPrompt ( + QString fileName, + QString binaryName, + bool isRelease, + QWidget* parent, + Qt::WindowFlags f +) : + QDialog (parent, f), + m_binaryString (binaryName), + m_isRelease (isRelease) +{ + 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())); + setWindowTitle (versionSignature()); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +UnknownVersionPrompt::~UnknownVersionPrompt() +{ + delete ui; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void UnknownVersionPrompt::addBinary() +{ + 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 = 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() +{ + delete m_ui; +} + +// +// ------------------------------------------------------------------------------------------------- +// + +void FindFilePrompt::findDemo() +{ + QString path = QFileDialog::getOpenFileName (this, tr ("Open Demo File"), + QDir::homePath(), tr ("Demo files (*.cld);;All files (*.*)")); + + if (not path.isEmpty()) + m_ui->m_path->setText (path); +} + +// +// ------------------------------------------------------------------------------------------------- +// + +QString FindFilePrompt::path() const +{ + return m_ui->m_path->text(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/launcher/prompts.h Sat Jun 06 23:12:59 2015 +0300 @@ -0,0 +1,65 @@ +/* + * ZCinema: Zandronum demo launcher + * Copyright (C) 2013-2015 Teemu Piippo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once +#include <QDialog> +#include <commonlib/types.h> + +// +// ------------------------------------------------------------------------------------------------- +// + +class UnknownVersionPrompt : public QDialog +{ + Q_OBJECT + +public: + UnknownVersionPrompt (QString fileName, QString binaryName, bool isRelease, + QWidget* parent = NULL, Qt::WindowFlags f = 0); + virtual ~UnknownVersionPrompt(); + +public slots: + void findBinary(); + void addBinary(); + +private: + class Ui_UnknownVersion* ui; + QString m_binaryString; + bool m_isRelease; +}; + +// +// ------------------------------------------------------------------------------------------------- +// + +class FindFilePrompt : public QDialog +{ + Q_OBJECT + +public: + FindFilePrompt (QWidget* parent = NULL, Qt::WindowFlags f = 0); + virtual ~FindFilePrompt(); + + QString path() const; + +public slots: + void findDemo(); + +private: + class Ui_FindFile* m_ui; +}; \ No newline at end of file
--- a/src-common/config.cpp Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <assert.h> -#include <QDir> -#include <QTextStream> -#include <QSettings> -#include "config.h" - -typedef QMap<QString, QVariant> DefaultsMap; - -// -// ------------------------------------------------------------------------------------------------- -// - -static QSettings* getSettingsObject() -{ - return new QSettings; -} - -// -// ------------------------------------------------------------------------------------------------- -// - -static DefaultsMap& getDefaults() -{ - static DefaultsMap defaults; - - if (defaults.isEmpty()) - { - // Initialize defaults here. - } - - return defaults; -} - -// -// ------------------------------------------------------------------------------------------------- -// - -void Config::reset() -{ - DefaultsMap& defaults = getDefaults(); - - for (DefaultsMap::iterator it = defaults.begin(); it != defaults.end(); ++it) - set (it.key(), it.value()); -} - -// -// ------------------------------------------------------------------------------------------------- -// - -QVariant Config::get (const QString& name) -{ - QSettings* settings = getSettingsObject(); - DefaultsMap& defaults = getDefaults(); - DefaultsMap::iterator it = defaults.find (name); - QVariant def = it != defaults.end() ? *it : QVariant(); - QVariant value = settings->value (name, def); - settings->deleteLater(); - 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; -} - -// -// ------------------------------------------------------------------------------------------------- -// - -void Config::sync() -{ - QSettings* settings = getSettingsObject(); - settings->sync(); - settings->deleteLater(); -}
--- a/src-common/config.h Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once -#include <QVariant> - -namespace Config -{ - void reset(); - QVariant get (const QString& name); - bool set (const QString& name, const QVariant& value); - void sync(); -}; \ No newline at end of file
--- a/src-common/misc.cpp Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <QFileDialog> -#include "misc.h" -#include "config.h" - -// -// ----------------------------------------------------------------------------- -// - -void commonInit() -{ - qRegisterMetaType<ZandronumVersion> ("ZandronumVersion"); - qRegisterMetaTypeStreamOperators<ZandronumVersion> ("ZandronumVersion"); -} - -// -// ----------------------------------------------------------------------------- -// - -QString basename (const QString& path) -{ - int lastpos = path.lastIndexOf ("/"); - - if (lastpos != -1) - return path.mid (lastpos + 1); - - return path; -} - -// -// ------------------------------------------------------------------------------------------------- -// - -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-common/misc.h Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once -#include "types.h" - -inline quint32 makeByteID (quint8 a, quint8 b, quint8 c, quint8 d) -{ - return a | (b << 8) | (c << 16) | (d << 24); -} - -void commonInit(); -QString basename (const QString& path); -bool confirm (const QString& text); -QString getBinaryPath (QWidget* parent); - -// -// ----------------------------------------------------------------------------- -// - -template<typename T> -T clamp (T a, T min, T max) -{ - return (a > max) ? max : (a < min) ? min : a; -} - -// -// ----------------------------------------------------------------------------- -// - -template<typename T> -T min (T a, T b) -{ - return (a < b) ? a : b; -} - -// -// ----------------------------------------------------------------------------- -// - -template<typename T> -T max (T a, T b) -{ - return (a > b) ? a : b; -} - -// -// ----------------------------------------------------------------------------- -// - -template<typename T> -T abs (T a) -{ - return (a < 0) ? -a : a; -} \ No newline at end of file
--- a/src-common/types.h Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once -#include <QString> -#include <QList> -#include <QVariant> - -template<class T> using list = QList<T>; -template<class T> using initlist = std::initializer_list<T>; -using std::size_t; - -typedef qint8 int8; -typedef qint16 int16; -typedef qint32 int32; -typedef qint64 int64; -typedef quint8 uint8; -typedef quint16 uint16; -typedef quint32 uint32; -typedef quint64 uint64; - -struct ZandronumVersion -{ - ZandronumVersion (QString name, bool isRelease, QString binaryPath) : - name (name), - binaryPath (binaryPath), - isRelease (isRelease) {} - - ZandronumVersion() : - isRelease (false) {} - - QString name; - QString binaryPath; - bool isRelease; -}; - -inline QDataStream& operator<< (QDataStream& out, const ZandronumVersion& version) -{ - return (out << version.name << version.binaryPath << version.isRelease); -} - -inline QDataStream& operator>> (QDataStream& in, ZandronumVersion& version) -{ - return (in >> version.name >> version.binaryPath >> version.isRelease); -} - -Q_DECLARE_METATYPE (ZandronumVersion) \ No newline at end of file
--- a/src-common/version.cpp Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "version.h" -#include "hginfo.h" - -// -// ------------------------------------------------------------------------------------------------- -// - -QString versionString() -{ -#ifndef RELEASE -# ifdef HG_NODE - // non-release with hg info - return VERSION_STRING "-" HG_NODE; -# else - // non-release, no hg info - return VERSION_STRING "-beta"; -# endif -#else - // release - return VERSION_STRING; -#endif -} - -// -// ------------------------------------------------------------------------------------------------- -// - -QString versionSignature() -{ -#ifdef HG_DATE_STRING -# define DATE_INFO " (" HG_DATE_STRING ")" -#else -# define DATE_INFO "" -#endif - - return QString (APPNAME) + " " + versionString() + DATE_INFO; -} \ No newline at end of file
--- a/src-common/version.h Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once -#define APPNAME "ZCinema" -#define UNIXNAME "zcinema" -#define VERSION_MAJOR 1 -#define VERSION_MINOR 0 -#define VERSION_PATCH 0 -// #define RELEASE - -#define MACRO_TO_STRING(A) MACRO_TO_STRING_(A) -#define MACRO_TO_STRING_(A) #A - -#if VERSION_PATCH == 0 -# define VERSION_STRING MACRO_TO_STRING (VERSION_MAJOR) \ - "." MACRO_TO_STRING (VERSION_MINOR) -#else -# define VERSION_STRING MACRO_TO_STRING (VERSION_MAJOR) \ - "." MACRO_TO_STRING (VERSION_MINOR) \ - "." MACRO_TO_STRING (VERSION_PATCH) -#endif - -#include "config.h" - -QString versionString(); -QString versionSignature(); \ No newline at end of file
--- a/src-config/addversionprompt.cpp Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <QTableWidget> -#include "addversionprompt.h" -#include "configwindow.h" -#include "misc.h" -#include "ui_addversion.h" - -// -// ------------------------------------------------------------------------------------------------- -// - -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-config/addversionprompt.h Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -#include <QDialog> - -// -// ------------------------------------------------------------------------------------------------- -// - -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; -}; \ No newline at end of file
--- a/src-config/configwindow.cpp Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,303 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <QFileDialog> -#include <QMessageBox> -#include "addversionprompt.h" -#include "config.h" -#include "configwindow.h" -#include "version.h" -#include "ui_configbox.h" - -// -// ----------------------------------------------------------------------------- -// - -bool confirm (const QString& text) -{ - return QMessageBox::question (NULL, QObject::tr ("Confirm"), text, - QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::No; -} - -// -// ------------------------------------------------------------------------------------------------- -// - -ConfigWindow::ConfigWindow (QWidget* parent, Qt::WindowFlags f) : - QDialog (parent, f), - ui (*new Ui_ConfigBox) -{ - ui.setupUi (this); - - QStringList wadpaths = Config::get ("wadpaths").toStringList(); - QList<QVariant> versions = Config::get ("versions").toList(); - - for (int i = 0; i < wadpaths.size(); ++i) - addWadPath (wadpaths[i]); - - ui.noDemoPrompt->setChecked (Config::get ("noprompt").toBool()); - - for (int i = 0; i < versions.size(); ++i) - { - if (not versions[i].canConvert<ZandronumVersion>()) - continue; - - 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(); - } -} - -// -// ------------------------------------------------------------------------------------------------- -// - -ZandronumVersion VersionGuiEntry::toNonGuiVersion() const -{ - 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; - QList<QVariant> versions; - - for (int i = 0; i < ui.wad_pathsList->count(); ++i) - wadPathList.append (ui.wad_pathsList->item (i)->text()); - - for (int i = 0; i < m_versionEntries.size(); ++i) - { - 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::addWadPath() -{ - addWadPath (ui.wad_pathEntry->text()); - ui.wad_pathEntry->clear(); -} - -// -// ------------------------------------------------------------------------------------------------- -// - -void ConfigWindow::addWadPath (QString path) -{ - ui.wad_pathsList->addItem (path); - QListWidgetItem* item = ui.wad_pathsList->item (ui.wad_pathsList->count() - 1); - item->setFlags (item->flags() | Qt::ItemIsEditable); -} - -// -// ------------------------------------------------------------------------------------------------- -// - -void ConfigWindow::findWadPath() -{ - QString path = QFileDialog::getExistingDirectory (this); - - if (path.isEmpty()) - return; - - ui.wad_pathEntry->setText (path); -} - -// -// ------------------------------------------------------------------------------------------------- -// - -void ConfigWindow::removeCurrentWadPath() -{ - delete ui.wad_pathsList->currentItem(); -} - -// -// ------------------------------------------------------------------------------------------------- -// - -void ConfigWindow::buttonPressed (QAbstractButton* btn) -{ - if (btn == ui.buttonBox->button (QDialogButtonBox::Ok)) - { - saveSettings(); - accept(); - } - else if (btn == ui.buttonBox->button (QDialogButtonBox::Cancel)) - { - reject(); - } - else if (btn == ui.buttonBox->button (QDialogButtonBox::Apply)) - { - saveSettings(); - } -} \ No newline at end of file
--- a/src-config/configwindow.h Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once -#include <QDialog> -#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: - enum - { - LabelColumn, - PathColumn, - }; - - typedef QMap<class QTableWidgetItem*, VersionGuiEntry*> VersionEntryMap; - - ConfigWindow (QWidget* parent = NULL, Qt::WindowFlags f = 0); - virtual ~ConfigWindow(); - -public slots: - void addWadPath(); - void findWadPath(); - void removeCurrentWadPath(); - void buttonPressed (class QAbstractButton* btn); - void newVersion(); - void removeCurrentVersion(); - void editExePressed(); - void clearExePathsClicked(); - -private: - 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-config/main.cpp Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <QApplication> -#include "configwindow.h" -#include "version.h" -#include "misc.h" - -int main (int argc, char* argv[]) -{ - QApplication app (argc, argv); - app.setApplicationName (UNIXNAME); - app.setOrganizationName (UNIXNAME); - app.setApplicationVersion (versionString()); - commonInit(); - return (new ConfigWindow)->exec(); -} \ No newline at end of file
--- a/src/demo.cpp Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,369 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <QFile> -#include <QDataStream> -#include <QMessageBox> -#include <QProcess> -#include "demo.h" -#include "misc.h" -#include "ui_demoprompt.h" -#include "prompts.h" -#include "config.h" -#include "version.h" - -// -// ------------------------------------------------------------------------------------------------- -// - -QString uncolorize (const QString& in) -{ - // TODO: Handle long-form colors like \c[Red] - QString out; - int skip = 0; - - for (QChar c : in) - { - if (skip-- > 0) - continue; - - if (c == QChar ('\034')) - { - skip = 1; - continue; - } - - out += c; - } - - return out; -} - -// -// ------------------------------------------------------------------------------------------------- -// - -static QString tr (const char* msg) -{ - return QObject::tr (msg); -} - -// -// ------------------------------------------------------------------------------------------------- -// - -static void error (QString msg) -{ - QMessageBox::critical (NULL, "Error", msg); -} - -// -// ------------------------------------------------------------------------------------------------- -// - -static ZandronumVersion findVersion (QString versionName) -{ - QList<QVariant> versions = Config::get ("versions").toList(); - - for (int i = 0; i < versions.size(); ++i) - { - if (not versions[i].canConvert<ZandronumVersion>()) - continue; - - ZandronumVersion version = versions[i].value<ZandronumVersion>(); - - if (version.name == versionName - or version.name + "M" == versionName - or version.name == versionName + "M") - { - return version; - } - } - - return ZandronumVersion(); -} - -// -// ------------------------------------------------------------------------------------------------- -// - -static QString findWAD (QString name) -{ - QStringList wadpaths = Config::get ("wadpaths").toStringList(); - - if (wadpaths.empty()) - { - 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 (1); - } - - for (int i = 0; i < wadpaths.size(); ++i) - { - QString fullpath = QString ("%1/%2").arg (wadpaths[i]).arg (name); - QFile f (fullpath); - - if (f.exists()) - return fullpath; - } - - return ""; -} - -// -// ------------------------------------------------------------------------------------------------- -// - -QString readString (QDataStream& stream) -{ - QString out; - uint8 ch; - - for (stream >> ch; ch != 0; stream >> ch) - out += QChar (ch); - - return out; -} - -// -// ------------------------------------------------------------------------------------------------- -// - -struct UserInfo -{ - QString netname; - QString skin; - QString className; - uint32 color; - uint32 aimdist; - uint32 railcolor; - uint8 gender; - uint8 handicap; - uint8 unlagged; - uint8 respawnOnFire; - uint8 ticsPerUpdate; - uint8 connectionType; -}; - -struct DemoHeaders -{ - uint8 length; - uint8 version; - uint8 userInfo; - uint8 bodyStart; - uint8 wads; -}; - -int launchDemo (QString path) -{ - QFile f (path); - - if (not f.open (QIODevice::ReadOnly)) - { - error (tr ("Couldn't open '%1' for reading: %2").arg (path).arg (strerror (errno))); - return 1; - } - - QDataStream stream (&f); - stream.setByteOrder (QDataStream::LittleEndian); - - DemoHeaders headers; - uint32 length; - uint16 zanversionID, numWads; - uint32 longSink; - QString zanversion; - QStringList wads; - UserInfo userinfo; - - // Assume a release build if the build ID not supplied. The demo only got the "ZCLD" signature - // in the 1.1 release build, 1.1.1 had no testing binaries and the build ID is included in 1.2 - // onward. - BuildType buildID = ReleaseBuild; - - bool ready = false; - - // Check signature - { - uint32 demosignature; - stream >> demosignature; - - if (demosignature != makeByteID ('Z', 'C', 'L', 'D')) - { - error (tr ("'%1' is not a valid Zandronum demo file!").arg (path)); - return 1; - } - } - - stream >> headers.length; - stream >> length; - - // The remaining headers are variable and relative to the length header. - headers.version = headers.length + 1; - headers.userInfo = headers.length + 3, - headers.bodyStart = headers.length + 4; - headers.wads = headers.length + 10; - - // Read the demo header and get data - for (;;) - { - uint8 header; - stream >> header; - - if (header == headers.bodyStart) - { - ready = true; - break; - } - else if (header == headers.version) - { - stream >> zanversionID; - zanversion = readString (stream); - - if (not zanversion.startsWith ("1.1-") and not zanversion.startsWith ("1.1.1-")) - { - uint8 a; - stream >> a; - buildID = (BuildType) a; - } - - // The demo wads header accidentally changed in 1.3. :( - if (zanversion.left(1).toInt() >= 2 or zanversion.startsWith ("1.3")) - headers.wads = headers.length + 8; - - stream >> longSink; // rng seed - we don't need it - } - else if (header == headers.userInfo) - { - userinfo.netname = readString (stream); - stream >> userinfo.gender; - stream >> userinfo.color; - stream >> userinfo.aimdist; - userinfo.skin = readString (stream); - stream >> userinfo.railcolor; - stream >> userinfo.handicap; - stream >> userinfo.unlagged; - stream >> userinfo.respawnOnFire; - stream >> userinfo.ticsPerUpdate; - stream >> userinfo.connectionType; - userinfo.className = readString (stream); - } - else if (header == headers.wads) - { - QString sink; - stream >> numWads; - - for (uint8 i = 0; i < numWads; ++i) - { - QString wad = readString (stream); - wads << wad; - } - - // The demo has two checksum strings. We're not interested in them, though. - (sink = readString (stream)) = readString (stream); - } - else - { - error (tr ("Unknown header %1!\n").arg (int (header))); - return 1; - } - } - - if (not ready) - { - error (tr ("Incomplete demo header in '%s'!").arg (path)); - return 1; - } - - ZandronumVersion version = findVersion (zanversion); - - if (version.name.isNull()) - { - QDialog* prompt = new UnknownVersionPrompt (path, zanversion, (buildID == ReleaseBuild)); - - if (not prompt->exec()) - return 1; - } - - QString iwadpath; - QStringList pwadpaths; - - // Find the WADs - for (const QString& wad : wads) - { - QString path = findWAD (wad); - - // WAD names are case-sensitive under non-Windows and they can appear in uppercase - // so we need to test that too. - if (path.isEmpty()) - path = findWAD (wad.toUpper()); - - if (path.isEmpty()) - { - error (tr ("Couldn't find %1!").arg (wad)); - return 1; - } - - if (&wad == &wads.first()) - iwadpath = path; - else - pwadpaths << path; - } - - if (not Config::get ("noprompt").toBool()) - { - QString pwadtext; - - for (const QString& wad : wads) - { - if (&wad == &wads.first()) - continue; // skip the IWAD - - if (not pwadtext.isEmpty()) - pwadtext += "<br />"; - - pwadtext += wad; - } - - QDialog* dlg = new QDialog; - Ui_DemoPrompt ui; - ui.setupUi (dlg); - ui.demoNameLabel->setText (basename (path)); - ui.demoRecorder->setText (uncolorize (userinfo.netname)); - ui.versionLabel->setText (zanversion); - ui.iwadLabel->setText (wads[0]); - ui.pwadsLabel->setText (pwadtext); - dlg->setWindowTitle (versionSignature()); - - if (not dlg->exec()) - return 0; - } - - QStringList cmdlineList; - cmdlineList << "-playdemo" << path << "-iwad" << iwadpath; - - if (pwadpaths.size() > 0) - cmdlineList << "-file" << pwadpaths; - - // print ("Executing: %1 %2\n", binarypath, cmdlineList.join (" ")); - QProcess* proc = new QProcess; - proc->start (version.binaryPath, cmdlineList); - proc->waitForFinished (-1); - return 0; -}
--- a/src/demo.h Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once -#include "types.h" - -enum BuildType -{ - OtherBuild = 0, - ReleaseBuild = 1, - InternalBuild = 2, - PrivateBuild = 3 -}; - -int launchDemo (QString path); \ No newline at end of file
--- a/src/main.cpp Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <QApplication> -#include "demo.h" -#include "prompts.h" -#include "misc.h" -#include "version.h" - -// -// ------------------------------------------------------------------------------------------------- -// - -int main (int argc, char* argv[]) -{ - QApplication app (argc, argv); - app.setApplicationName (UNIXNAME); - app.setOrganizationName (UNIXNAME); - app.setApplicationVersion (versionString()); - commonInit(); - - if (argc > 1) - { - return launchDemo (argv[1]); - } - else - { - FindFilePrompt* dlg = new FindFilePrompt (NULL); - - if (not dlg->exec()) - return 0; - - return launchDemo (dlg->path()); - } -} \ No newline at end of file
--- a/src/prompts.cpp Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <QFileDialog> -#include "prompts.h" -#include "misc.h" -#include "ui_unknownversion.h" -#include "ui_findfile.h" -#include "version.h" -#include "config.h" - -// -// ------------------------------------------------------------------------------------------------- -// - -UnknownVersionPrompt::UnknownVersionPrompt ( - QString fileName, - QString binaryName, - bool isRelease, - QWidget* parent, - Qt::WindowFlags f -) : - QDialog (parent, f), - m_binaryString (binaryName), - m_isRelease (isRelease) -{ - 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())); - setWindowTitle (versionSignature()); -} - -// -// ------------------------------------------------------------------------------------------------- -// - -UnknownVersionPrompt::~UnknownVersionPrompt() -{ - delete ui; -} - -// -// ------------------------------------------------------------------------------------------------- -// - -void UnknownVersionPrompt::addBinary() -{ - 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 = 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() -{ - delete m_ui; -} - -// -// ------------------------------------------------------------------------------------------------- -// - -void FindFilePrompt::findDemo() -{ - QString path = QFileDialog::getOpenFileName (this, tr ("Open Demo File"), - QDir::homePath(), tr ("Demo files (*.cld);;All files (*.*)")); - - if (not path.isEmpty()) - m_ui->m_path->setText (path); -} - -// -// ------------------------------------------------------------------------------------------------- -// - -QString FindFilePrompt::path() const -{ - return m_ui->m_path->text(); -} \ No newline at end of file
--- a/src/prompts.h Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * ZCinema: Zandronum demo launcher - * Copyright (C) 2013-2015 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#pragma once -#include <QDialog> -#include "types.h" - -// -// ------------------------------------------------------------------------------------------------- -// - -class UnknownVersionPrompt : public QDialog -{ - Q_OBJECT - -public: - UnknownVersionPrompt (QString fileName, QString binaryName, bool isRelease, - QWidget* parent = NULL, Qt::WindowFlags f = 0); - virtual ~UnknownVersionPrompt(); - -public slots: - void findBinary(); - void addBinary(); - -private: - class Ui_UnknownVersion* ui; - QString m_binaryString; - bool m_isRelease; -}; - -// -// ------------------------------------------------------------------------------------------------- -// - -class FindFilePrompt : public QDialog -{ - Q_OBJECT - -public: - FindFilePrompt (QWidget* parent = NULL, Qt::WindowFlags f = 0); - virtual ~FindFilePrompt(); - - QString path() const; - -public slots: - void findDemo(); - -private: - class Ui_FindFile* m_ui; -}; \ No newline at end of file
--- a/ui/versionEditor.ui Sat Jun 06 23:06:14 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,159 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>VersionEditor</class> - <widget class="QDialog" name="VersionEditor"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>577</width> - <height>450</height> - </rect> - </property> - <property name="windowTitle"> - <string>Edit Zandronum Versions</string> - </property> - <property name="windowIcon"> - <iconset resource="../../zcinema.qrc"> - <normaloff>:/icons/zcinema.ico</normaloff>:/icons/zcinema.ico</iconset> - </property> - <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QTableWidget" name="m_versions"> - <property name="selectionMode"> - <enum>QAbstractItemView::SingleSelection</enum> - </property> - <property name="selectionBehavior"> - <enum>QAbstractItemView::SelectRows</enum> - </property> - <property name="sortingEnabled"> - <bool>true</bool> - </property> - <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>Release</string> - </property> - </column> - <column> - <property name="text"> - <string>Binary Path</string> - </property> - </column> - </widget> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout_3"> - <item> - <widget class="QPushButton" name="m_add"> - <property name="text"> - <string>Add...</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="m_edit"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Edit...</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="m_remove"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Remove</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="m_clear"> - <property name="text"> - <string>Clear</string> - </property> - </widget> - </item> - <item> - <spacer name="verticalSpacer"> - <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> - </item> - <item> - <widget class="QDialogButtonBox" name="m_buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources> - <include location="../../zcinema.qrc"/> - </resources> - <connections> - <connection> - <sender>m_buttonBox</sender> - <signal>accepted()</signal> - <receiver>VersionEditor</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>254</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>274</y> - </hint> - </hints> - </connection> - <connection> - <sender>m_buttonBox</sender> - <signal>rejected()</signal> - <receiver>VersionEditor</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>316</x> - <y>260</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>274</y> - </hint> - </hints> - </connection> - </connections> -</ui>