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 <QSqlTableModel>
24 #include "setupeditdialog.h"
25 #include "fileextensionwidget.h"
26 #include "effileobjectcombobox.h"
27 #include "dbmediatype.h"
28 #include "dbplatform.h"
31 SetupEditDialog::SetupEditDialog(QWidget *parent, EmuFrontObject* obj)
32 : DataObjectEditDialog(parent, obj)
35 dbPlatform = new DbPlatform(this);
36 dbMediaType = new DbMediaType(this);
43 void SetupEditDialog::initWidgets()
45 mediaTypeComBox = new EFFileObjectComboBox(dbMediaType, this);
46 platformComBox = new EFFileObjectComboBox(dbPlatform, this);
47 supportedFileTypesList = new FileExtensionWidget;
48 supportedFileTypesList->setToolTip(tr("Set the supported file types by entering the file extension(s) (no wildcards or dots!)."));
51 void SetupEditDialog::layout()
53 QLabel *platformLabel = new QLabel(tr("&Platform:"));
54 platformLabel->setBuddy(platformComBox);
55 QLabel *mediaTypeLabel = new QLabel(tr("Media&Type:"));
56 mediaTypeLabel->setBuddy(mediaTypeComBox);
57 QLabel *fileTypesLabel = new QLabel(tr("Supported file types:"));
58 QGridLayout *gridLayout = new QGridLayout;
59 gridLayout->addWidget(platformLabel, 0, 0);
60 gridLayout->addWidget(platformComBox, 0, 1);
61 gridLayout->addWidget(mediaTypeLabel, 1, 0);
62 gridLayout->addWidget(mediaTypeComBox, 1, 1);
63 gridLayout->addWidget(fileTypesLabel, 2, 0, 1, 2);
64 gridLayout->addWidget(supportedFileTypesList, 3, 0, 2, 2);
65 QVBoxLayout *mainLayout = new QVBoxLayout;
66 mainLayout->addLayout(gridLayout);
67 mainLayout->addWidget(buttonBox);
68 setLayout(mainLayout);
69 setWindowTitle(tr("Edit setup"));
72 void SetupEditDialog::acceptChanges()
74 Setup *sup = dynamic_cast<Setup*>(efObject);
75 Platform *plf = getSelectedPlatform();
78 QMessageBox::information(this, tr("Platform"),
79 tr("Platform not selected"), QMessageBox::Ok);
82 qDebug() << "Platform selected " << plf->getName();
83 MediaType *mt = getSelectedMediaType();
86 QMessageBox::information(this, tr("Media type"), tr("Media type was not selected"), QMessageBox::Ok);
89 qDebug() << "Media type selected " << mt->getName();
93 Platform *ptmp = sup->getPlatform();
94 if (!ptmp || *plf != *ptmp)
97 sup->setPlatform(plf);
100 MediaType *mtmp = sup->getMediaType();
101 if (!mtmp || *mt != *mtmp)
104 sup->setMediaType(mt);
108 // "Two lists are considered equal if they contain the same values in the same order."
109 if (supportedFileTypesList->getItems() != sup->getSupportedFileTypeExtensions()) {
110 sup->setSupportedFileTypeExtensions(supportedFileTypesList->getItems());
113 // TODO: the second time around this signal is not received!
114 if (change) emit dataObjectUpdated();
119 void SetupEditDialog::setDataObject(EmuFrontObject *ob)
122 qDebug() << "Updating Setup edit dialog data object to "
123 << ob->getName() << ".";
125 delete dynamic_cast<Setup*>(efObject); // TODO: caused crash if another instance of setupeditdialog was created and new instance destroyed object being referenced in another existing dialog.
127 Setup *sup= dynamic_cast<Setup*>(ob);
129 qDebug() << "Failed casting to Setup";
132 if (sup->getPlatform()) setSelectedPlatform(sup->getPlatform());
133 if (sup->getMediaType()) setSelectedMediaType(sup->getMediaType());
134 supportedFileTypesList->setItems(sup->getSupportedFileTypeExtensions());
137 void SetupEditDialog::setSelectedPlatform(const Platform *plf)
139 platformComBox->setSelected(plf);
142 void SetupEditDialog::setSelectedMediaType(const MediaType *plf)
144 mediaTypeComBox->setSelected(plf);
147 /* Returns a pointer to an object which must be deleted by calling code */
148 Platform* SetupEditDialog::getSelectedPlatform()
150 EmuFrontObject *o = 0;
151 try { o = platformComBox->getSelected(); }
152 catch(EmuFrontException &e){
153 errorMessage->showMessage(e.what());
157 Platform *plf = dynamic_cast<Platform*>(o);
161 /* Returns a pointer to an object which must be deleted by calling code */
162 MediaType* SetupEditDialog::getSelectedMediaType()
164 EmuFrontObject *o = 0;
165 try { o = mediaTypeComBox->getSelected(); }
166 catch(EmuFrontException &e){ errorMessage->showMessage(e.what()); }
168 MediaType *mt = dynamic_cast<MediaType*>(o);
172 void SetupEditDialog::updateData()
174 platformComBox->updateDataModel();
175 mediaTypeComBox->updateDataModel();
178 void SetupEditDialog::clear()
180 platformComBox->setCurrentIndex(-1);
181 mediaTypeComBox->setCurrentIndex(-1);
182 supportedFileTypesList->clear();