3 ** Copyright 2010 Mikko Keinänen
5 ** This file is part of EmuFront.
8 ** EmuFront is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License version 2 as published by
10 ** the Free Software Foundation and appearing in the file gpl.txt included in the
11 ** packaging of this file.
13 ** EmuFront is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
18 ** You should have received a copy of the GNU General Public License
19 ** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
22 #include "executableeditdialog.h"
23 #include "dbexecutable.h"
25 #include "executable.h"
27 #include "setupcombobox.h"
28 #include "emufrontexception.h"
30 ExecutableEditDialog::ExecutableEditDialog(QWidget *parent, EmuFrontObject *obj)
31 : DataObjectEditDialog(parent, obj)
34 dbSetup = new DbSetup(this);
40 void ExecutableEditDialog::initWidgets()
42 setupComBox = new SetupComboBox(dbSetup, this);
43 nameEdit = new QLineEdit;
44 nameEdit->setToolTip(tr("Set an individual short "
45 "description for this emulator configuration."));
46 execEdit = new QLineEdit;
47 execEdit->setToolTip(tr("Emulator executable in $PATH "
48 "or absolute path to emulator executable."));
49 optEdit = new QLineEdit;
50 optEdit->setToolTip(tr("Command line parameters for the "
51 "emulator executable including $1 as file 1 to be "
52 "assigned to emulator, $2 as file 2, etc."));
55 void ExecutableEditDialog::layout()
57 QLabel *nameLabel = new QLabel(tr("&Description"));
58 nameLabel->setBuddy(nameEdit);
59 QLabel *execLabel = new QLabel(tr("&Executable"));
60 execLabel->setBuddy(execEdit);
61 QLabel *optLabel = new QLabel(tr("&Parameters"));
62 optLabel->setBuddy(optEdit);
63 QLabel *setupLabel = new QLabel(tr("&Setup"));
64 setupLabel->setBuddy(setupComBox);
65 QGridLayout *gridLayout = new QGridLayout;
66 gridLayout->addWidget(nameLabel, 0, 0);
67 gridLayout->addWidget(nameEdit, 0, 1);
68 gridLayout->addWidget(execLabel, 1, 0);
69 gridLayout->addWidget(execEdit, 1, 1);
70 gridLayout->addWidget(optLabel, 2, 0);
71 gridLayout->addWidget(optEdit, 2, 1);
72 gridLayout->addWidget(setupLabel, 3, 0);
73 gridLayout->addWidget(setupComBox, 3, 1);
74 QVBoxLayout *mainLayout = new QVBoxLayout;
75 mainLayout->addLayout(gridLayout);
76 mainLayout->addWidget(buttonBox);
77 setLayout(mainLayout);
78 setWindowTitle(tr("Edit emulator configuration"));
81 void ExecutableEditDialog::acceptChanges()
83 Executable *ex = dynamic_cast<Executable*>(efObject);
85 Setup *su = getSelectedSetup();
87 throw EmuFrontException(tr("Setup not selected"));
89 QString name = nameEdit->text().trimmed();
91 throw EmuFrontException(tr("Name is not set"));
93 QString exec = execEdit->text().trimmed();
95 throw EmuFrontException(tr("Executable is not set"));
97 QString opts = optEdit->text().trimmed();
99 throw EmuFrontException(tr("Options not set"));
102 Setup *supTmp = ex->getSetup();
103 if (!supTmp || *supTmp != *su) {
109 if (name != ex->getName()) {
114 if (exec != ex->getExecutable()) {
115 ex->setExecutable(exec);
118 if (opts != ex->getOptions()) {
119 ex->setOptions(opts);
122 if (change) emit dataObjectUpdated();
125 } catch(EmuFrontException x) {
126 QMessageBox::information(this,
127 tr("Updating emulator"),
128 x.what(), QMessageBox::Ok);
133 void ExecutableEditDialog::setDataObject(EmuFrontObject *ob)
137 Executable *ex = dynamic_cast<Executable*>(ob);
139 qDebug("No executable");
143 if (!ex->getSetup()) {
144 qDebug() << "No setup";
147 if (ex->getSetup() && ex->getSetup()->getId() >= 0)
148 setSelectedSetup(ex->getSetup());
149 nameEdit->setText(ex->getName());
150 execEdit->setText(ex->getExecutable());
151 optEdit->setText(ex->getOptions());
154 void ExecutableEditDialog::clear()
159 setupComBox->setCurrentIndex(-1);
162 void ExecutableEditDialog::setSelectedSetup(const Setup *su)
164 setupComBox->setSelected(su);
167 /* Returns a pointer to a Setup object which must be deleted by calling code! */
168 Setup* ExecutableEditDialog::getSelectedSetup()
170 EmuFrontObject *o = 0;
171 try { o = setupComBox->getSelected(); }
172 catch(EmuFrontException &e){ errorMessage->showMessage(e.what()); }
175 Setup *ex = dynamic_cast<Setup*>(o);
179 void ExecutableEditDialog::updateData()
181 setupComBox->updateDataModel();