Sat, 06 Jun 2015 22:26:05 +0300
rename config.cpp/h to configwindow.cpp/h
CMakeLists.txt | file | annotate | diff | comparison | revisions | |
src/cfg.cpp | file | annotate | diff | comparison | revisions | |
src/config.cpp | file | annotate | diff | comparison | revisions | |
src/config.h | file | annotate | diff | comparison | revisions | |
src/configwindow.cpp | file | annotate | diff | comparison | revisions | |
src/configwindow.h | file | annotate | diff | comparison | revisions | |
src/main.cpp | file | annotate | diff | comparison | revisions | |
src/prompts.cpp | file | annotate | diff | comparison | revisions |
--- a/CMakeLists.txt Sat Jun 06 22:20:21 2015 +0300 +++ b/CMakeLists.txt Sat Jun 06 22:26:05 2015 +0300 @@ -15,7 +15,7 @@ set (ZCINEMA_SOURCES src/cfg.cpp - src/config.cpp + src/configwindow.cpp src/demo.cpp src/main.cpp src/misc.cpp @@ -24,7 +24,7 @@ set (ZCINEMA_HEADERS src/cfg.h - src/config.h + src/configwindow.h src/demo.h src/main.h src/misc.h @@ -54,13 +54,13 @@ qt5_generate_moc (ZCINEMA_MOC ${ZCINEMA_HEADERS}) qt5_add_resources (ZCINEMA_QRC ${ZCINEMA_RESOURCES}) qt5_wrap_ui (ZCINEMA_FORMS_HEADERS ${ZCINEMA_FORMS}) - add_executable (${PROJECT_NAME} WIN32 ${ZCINEMA_SOURCES} ${ZCINEMA_MOC} + add_executable (${PROJECT_NAME} WIN32 ${ZCINEMA_SOURCES} ${ZCINEMA_HEADERS} ${ZCINEMA_MOC} ${ZCINEMA_QRC} ${ZCINEMA_FORMS_HEADERS}) else() qt4_wrap_cpp (ZCINEMA_MOC ${ZCINEMA_HEADERS}) qt4_wrap_ui (ZCINEMA_FORMS_HEADERS ${ZCINEMA_FORMS}) qt4_add_resources (ZCINEMA_RCC ${ZCINEMA_RESOURCES}) - add_executable (${PROJECT_NAME} WIN32 ${ZCINEMA_SOURCES} ${ZCINEMA_RCC} + add_executable (${PROJECT_NAME} WIN32 ${ZCINEMA_SOURCES} ${ZCINEMA_HEADERS} ${ZCINEMA_RCC} ${ZCINEMA_FORMS_HEADERS} ${ZCINEMA_MOC}) endif()
--- a/src/cfg.cpp Sat Jun 06 22:20:21 2015 +0300 +++ b/src/cfg.cpp Sat Jun 06 22:26:05 2015 +0300 @@ -21,7 +21,6 @@ #include <QTextStream> #include <QSettings> #include "main.h" -#include "config.h" typedef QMap<QString, QVariant> DefaultsMap;
--- a/src/config.cpp Sat Jun 06 22:20:21 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,292 +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 "config.h" -#include "ui_configbox.h" -#include "misc.h" -#include "demo.h" -#include "prompts.h" - -// -// ------------------------------------------------------------------------------------------------- -// - -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.h Sat Jun 06 22:20:21 2015 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +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 "main.h" -#include "types.h" - -// -// ------------------------------------------------------------------------------------------------- -// -// A ZandronumVersion represented in the config window. -// - -struct VersionGuiEntry -{ - class QTableWidgetItem* labelItem; - class QTableWidgetItem* pathItem; - QString name; - bool isRelease; - - ZandronumVersion toNonGuiVersion() const; -}; - -// -// ------------------------------------------------------------------------------------------------- -// - -class ConfigWindow : public QDialog -{ - Q_OBJECT - -public: - 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/src/configwindow.cpp Sat Jun 06 22:26:05 2015 +0300 @@ -0,0 +1,292 @@ +/* + * 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 "configwindow.h" +#include "ui_configbox.h" +#include "misc.h" +#include "demo.h" +#include "prompts.h" + +// +// ------------------------------------------------------------------------------------------------- +// + +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/src/configwindow.h Sat Jun 06 22:26:05 2015 +0300 @@ -0,0 +1,81 @@ +/* + * 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 "main.h" +#include "types.h" + +// +// ------------------------------------------------------------------------------------------------- +// +// A ZandronumVersion represented in the config window. +// + +struct VersionGuiEntry +{ + class QTableWidgetItem* labelItem; + class QTableWidgetItem* pathItem; + QString name; + bool isRelease; + + ZandronumVersion toNonGuiVersion() const; +}; + +// +// ------------------------------------------------------------------------------------------------- +// + +class ConfigWindow : public QDialog +{ + Q_OBJECT + +public: + 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