2 // Copyright 2010 Mikko Keinänen
4 // This file is part of EmuFront.
7 // EmuFront is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2 as published by
9 // the Free Software Foundation and appearing in the file gpl.txt included in the
10 // packaging of this file.
12 // EmuFront is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
21 #include "executableeditdialog.h"
22 #include "../db/dbexecutable.h"
23 #include "../db/dbsetup.h"
24 #include "../dataobjects/executable.h"
25 #include "../dataobjects/setup.h"
26 #include "../widgets/setupcombobox.h"
27 #include "../exceptions/emufrontexception.h"
29 ExecutableEditDialog::ExecutableEditDialog(QWidget *parent, EmuFrontObject *obj)
30 : DataObjectEditDialog(parent, obj)
33 dbSetup = new DbSetup(this);
39 void ExecutableEditDialog::initWidgets()
41 setupComBox = new SetupComboBox(dbSetup, this);
42 nameEdit = new QLineEdit;
43 nameEdit->setToolTip(tr("Set an individual short "
44 "description for this emulator configuration."));
45 execEdit = new QLineEdit;
46 execEdit->setToolTip(tr("Emulator executable in $PATH "
47 "or absolute path to emulator executable."));
48 optEdit = new QLineEdit;
49 optEdit->setToolTip(tr("Command line parameters for the "
50 "emulator executable including $1 as file 1 to be "
51 "assigned to emulator, $2 as file 2, etc."));
54 void ExecutableEditDialog::layout()
56 QLabel *nameLabel = new QLabel(tr("&Description"));
57 nameLabel->setBuddy(nameEdit);
58 QLabel *execLabel = new QLabel(tr("&Executable"));
59 execLabel->setBuddy(execEdit);
60 QLabel *optLabel = new QLabel(tr("&Parameters"));
61 optLabel->setBuddy(optEdit);
62 QLabel *setupLabel = new QLabel(tr("&Setup"));
63 setupLabel->setBuddy(setupComBox);
64 QGridLayout *gridLayout = new QGridLayout;
65 gridLayout->addWidget(nameLabel, 0, 0);
66 gridLayout->addWidget(nameEdit, 0, 1);
67 gridLayout->addWidget(execLabel, 1, 0);
68 gridLayout->addWidget(execEdit, 1, 1);
69 gridLayout->addWidget(optLabel, 2, 0);
70 gridLayout->addWidget(optEdit, 2, 1);
71 gridLayout->addWidget(setupLabel, 3, 0);
72 gridLayout->addWidget(setupComBox, 3, 1);
73 QVBoxLayout *mainLayout = new QVBoxLayout;
74 mainLayout->addLayout(gridLayout);
75 mainLayout->addWidget(buttonBox);
76 setLayout(mainLayout);
77 setWindowTitle(tr("Edit emulator configuration"));
80 void ExecutableEditDialog::acceptChanges()
82 Executable *ex = dynamic_cast<Executable*>(efObject);
84 Setup *su = getSelectedSetup();
86 throw new EmuFrontException(tr("Setup not selected"));
88 QString name = nameEdit->text().trimmed();
90 throw new EmuFrontException(tr("Name is not set"));
92 QString exec = execEdit->text().trimmed();
94 throw new EmuFrontException(tr("Executable is not set"));
96 QString opts = optEdit->text().trimmed();
98 throw new EmuFrontException(tr("Options not set"));
101 Setup *supTmp = ex->getSetup();
102 if (*supTmp != *su) {
108 if (name != ex->getName()) {
113 if (exec != ex->getExecutable()) {
114 ex->setExecutable(exec);
117 if (opts != ex->getOptions()) {
118 ex->setOptions(opts);
121 if (change) emit dataObjectUpdated();
124 } catch(EmuFrontException x) {
125 QMessageBox::information(this,
126 tr("Updating emulator"),
127 x.what(), QMessageBox::Ok);
132 void ExecutableEditDialog::setDataObject(EmuFrontObject *ob)
136 Executable *ex = dynamic_cast<Executable*>(ob);
138 qDebug("No executable");
141 if (!ex->getSetup()) {
142 qDebug() << "No setup";
145 if (ex->getSetup() && ex->getSetup()->getId() >= 0)
146 setSelectedSetup(ex->getSetup());
147 nameEdit->setText(ex->getName());
148 execEdit->setText(ex->getExecutable());
149 optEdit->setText(ex->getOptions());
152 void ExecutableEditDialog::setSelectedSetup(const Setup *su)
154 setupComBox->setSelected(su);
157 Setup* ExecutableEditDialog::getSelectedSetup() const
159 EmuFrontObject *o = setupComBox->getSelected();
161 Setup *ex = dynamic_cast<Setup*>(o);
165 void ExecutableEditDialog::updateData()
167 setupComBox->updateDataModel();