src/versionEditor.cpp

changeset 37
c82a86ea87be
parent 36
b8fa9171be6e
child 38
db677d321cf4
--- a/src/versionEditor.cpp	Mon Jun 01 17:06:13 2015 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,238 +0,0 @@
-/*
- *  ZCinema: Zandronum demo launcher
- *  Copyright (C) 2013 Santeri 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 "versionEditor.h"
-#include "ui_versionEditor.h"
-#include "ui_addversion.h"
-#include "config.h"
-#include "misc.h"
-
-EXTERN_CONFIG (Map,  binaryPaths)
-EXTERN_CONFIG (List, devBuildNames)
-EXTERN_CONFIG (List, releaseNames)
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-VersionEditor::VersionEditor (QWidget* parent, Qt::WindowFlags f) :
-	QDialog (parent, f),
-	m_ui (new Ui_VersionEditor)
-{
-	m_ui->setupUi (this);
-	
-	connect (m_ui->m_versions, SIGNAL (currentCellChanged (int, int, int, int)),
-	         this, SLOT (selectionChanged (int)));
-	
-	connect (m_ui->m_add,    SIGNAL (clicked (bool)), this, SLOT (add()));
-	connect (m_ui->m_edit,   SIGNAL (clicked (bool)), this, SLOT (edit()));
-	connect (m_ui->m_remove, SIGNAL (clicked (bool)), this, SLOT (remove()));
-	connect (m_ui->m_clear,  SIGNAL (clicked (bool)), this, SLOT (clear()));
-	
-	initVersions();
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-VersionEditor::~VersionEditor() {
-	delete m_ui;
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void VersionEditor::initVersions() {
-	int i = 0;
-	
-	for (const QVariant& ver : (cfg::releaseNames + cfg::devBuildNames)) {
-		bool isRelease = (i < cfg::releaseNames.size());
-		addVersion (ver.toString(), cfg::binaryPaths[ver.toString()].toString(), isRelease);
-		
-		++i;
-	}
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void VersionEditor::add() {
-	AddVersionPrompt* dlg = new AddVersionPrompt (this);
-	if (!dlg->exec())
-		return;
-	
-	addVersion (dlg->name(), dlg->path(), dlg->release());
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void VersionEditor::edit() {
-	QTableWidget* const vers = m_ui->m_versions;
-	int row = vers->currentRow();
-	
-	if (row < 0)
-		return;
-	
-	AddVersionPrompt* dlg = new AddVersionPrompt (this);
-	dlg->setName (vers->item (row, NameColumn)->text());
-	dlg->setPath (vers->item (row, PathColumn)->text());
-	dlg->setRelease (getReleaseCheckbox(row)->isChecked());
-	
-	if (!dlg->exec())
-		return;
-	
-	addVersion (dlg->name(), dlg->path(), dlg->release());
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void VersionEditor::remove() {
-	QTableWidget* const vers = m_ui->m_versions;
-	
-	str name = vers->item (vers->currentRow(), NameColumn)->text();
-	vers->removeRow (vers->currentRow());
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void VersionEditor::clear() {
-	if (!confirm (tr ("Really remove all versions?")))
-		return;
-	
-	for (int i = m_ui->m_versions->rowCount() - 1; i >= 0; --i)
-		m_ui->m_versions->removeRow (i);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void VersionEditor::addVersion (str name, str path, bool isRelease) {
-	QTableWidget* const vers = m_ui->m_versions;
-	
-	int row = vers->rowCount();
-	vers->insertRow (row);
-	vers->setItem (row, NameColumn, new QTableWidgetItem);
-	vers->setItem (row, PathColumn, new QTableWidgetItem);
-	vers->item (row, NameColumn)->setText (name);
-	vers->item (row, PathColumn)->setText (path);
-	
-	QCheckBox* cb = new QCheckBox;
-	cb->setChecked (isRelease);
-	vers->setCellWidget (row, ReleaseColumn, cb);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void VersionEditor::saveChanges() {
-	QTableWidget* const vers = m_ui->m_versions;
-	
-	cfg::devBuildNames.clear();
-	cfg::releaseNames.clear();
-	cfg::binaryPaths.clear();
-	
-	for (int i = 0; i < vers->rowCount(); ++i) {
-		const QCheckBox* cb = getReleaseCheckbox (i);
-		bool isRelease = cb->isChecked();
-		const str name = vers->item (i, NameColumn)->text(),
-		          path = vers->item (i, PathColumn)->text();
-		
-		if (isRelease)
-			cfg::releaseNames << QVariant (name);
-		else
-			cfg::devBuildNames << QVariant (name);
-		
-		cfg::binaryPaths[name] = path;
-	}
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void VersionEditor::selectionChanged (int row) {
-	bool ok = (row != -1);
-	m_ui->m_edit->setEnabled (ok);
-	m_ui->m_remove->setEnabled (ok);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-QCheckBox* VersionEditor::getReleaseCheckbox (int i) {
-	return static_cast<QCheckBox*> (m_ui->m_versions->cellWidget (i, ReleaseColumn));
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-AddVersionPrompt::AddVersionPrompt (QWidget* parent, Qt::WindowFlags f) :
-	QDialog (parent, f),
-	m_ui (new Ui_AddVersion)
-{
-	m_ui->setupUi (this);
-	connect (m_ui->m_binaryName, SIGNAL (textChanged (QString)), this, SLOT (fieldsChanged()));
-	connect (m_ui->m_binaryPath, SIGNAL (textChanged (QString)), this, SLOT (fieldsChanged()));
-	connect (m_ui->m_findBinary, SIGNAL (clicked (bool)), this, SLOT (findPath()));
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-AddVersionPrompt::~AddVersionPrompt() {
-	delete m_ui;
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void AddVersionPrompt::findPath() {
-	str path = ConfigBox::getBinaryPath (this);
-	if (!path.isEmpty())
-		m_ui->m_binaryPath->setText (path);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-str AddVersionPrompt::name() {
-	return m_ui->m_binaryName->text();
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-str AddVersionPrompt::path() {
-	return m_ui->m_binaryPath->text();
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-bool AddVersionPrompt::release() {
-	return m_ui->m_release->isChecked();
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void AddVersionPrompt::setName (const str& a) {
-	m_ui->m_binaryName->setText (a);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void AddVersionPrompt::setPath (const str& a) {
-	m_ui->m_binaryPath->setText (a);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void AddVersionPrompt::setRelease (bool a) {
-	m_ui->m_release->setChecked (a);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void AddVersionPrompt::fieldsChanged() {
-	bool ok = (!m_ui->m_binaryName->text().isEmpty()) && (!m_ui->m_binaryPath->text().isEmpty());
-	m_ui->buttonBox->button (QDialogButtonBox::Ok)->setEnabled (ok);
-}

mercurial