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 <QSqlTableModel>
23 #include "setupeditdialog.h"
24 #include "../widgets/stringlistwidget.h"
25 #include "../widgets/effileobjectcombobox.h"
26 #include "../db/dbmediatype.h"
27 #include "../db/dbplatform.h"
28 #include "../db/dbsetup.h"
30 SetupEditDialog::SetupEditDialog(QWidget *parent, EmuFrontObject* obj)
31 : DataObjectEditDialog(parent, obj)
34 dbPlatform = new DbPlatform(this);
35 dbMediaType = new DbMediaType(this);
42 void SetupEditDialog::initWidgets()
44 mediaTypeComBox = new EFFileObjectComboBox(dbMediaType, this);
45 platformComBox = new EFFileObjectComboBox(dbPlatform, this);
46 supportedFileTypesList = new StringListWidget;
49 void SetupEditDialog::layout()
51 QLabel *platformLabel = new QLabel(tr("&Platform"));
52 platformLabel->setBuddy(platformComBox);
53 QLabel *mediaTypeLabel = new QLabel(tr("Media&Type"));
54 mediaTypeLabel->setBuddy(mediaTypeComBox);
55 QGridLayout *gridLayout = new QGridLayout;
56 gridLayout->addWidget(platformLabel, 0, 0);
57 gridLayout->addWidget(platformComBox, 0, 1);
58 gridLayout->addWidget(mediaTypeLabel, 1, 0);
59 gridLayout->addWidget(mediaTypeComBox, 1, 1);
60 gridLayout->addWidget(supportedFileTypesList, 2, 0, 2, 2);
61 QVBoxLayout *mainLayout = new QVBoxLayout;
62 mainLayout->addLayout(gridLayout);
63 mainLayout->addWidget(buttonBox);
64 setLayout(mainLayout);
65 setWindowTitle(tr("Edit setup"));
68 void SetupEditDialog::acceptChanges()
70 Setup *sup = dynamic_cast<Setup*>(efObject);
71 Platform *plf = getSelectedPlatform();
74 QMessageBox::information(this, tr("Platform"),
75 tr("Platform not selected"), QMessageBox::Ok);
78 qDebug() << "Platform selected " << plf->getName();
79 MediaType *mt = getSelectedMediaType();
82 QMessageBox::information(this, tr("Media type"), tr("Media type was not selected"), QMessageBox::Ok);
85 qDebug() << "Media type selected " << mt->getName();
89 Platform *ptmp = sup->getPlatform();
93 sup->setPlatform(plf);
96 MediaType *mtmp = sup->getMediaType();
100 sup->setMediaType(mt);
104 // "Two lists are considered equal if they contain the same values in the same order."
105 if (supportedFileTypesList->getItems() != sup->getSupportedFileTypeExtensions()) {
106 sup->setSupportedFileTypeExtensions(supportedFileTypesList->getItems());
109 if (change) emit dataObjectUpdated();
114 void SetupEditDialog::setDataObject(EmuFrontObject *ob)
117 qDebug() << "Updating Setup edit dialog data object to "
118 << ob->getName() << ".";
120 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.
122 Setup *sup= dynamic_cast<Setup*>(ob);
123 if (sup->getPlatform()) setSelectedPlatform(sup->getPlatform());
124 if (sup->getMediaType()) setSelectedMediaType(sup->getMediaType());
125 supportedFileTypesList->setItems(sup->getSupportedFileTypeExtensions());
128 void SetupEditDialog::setSelectedPlatform(const Platform *plf)
130 platformComBox->setSelected(plf);
133 void SetupEditDialog::setSelectedMediaType(const MediaType *plf)
135 mediaTypeComBox->setSelected(plf);
138 Platform* SetupEditDialog::getSelectedPlatform() const
140 EmuFrontObject *o = platformComBox->getSelected();
142 Platform *plf = dynamic_cast<Platform*>(o);
146 MediaType* SetupEditDialog::getSelectedMediaType() const
148 EmuFrontObject *o = mediaTypeComBox->getSelected();
150 MediaType *mt = dynamic_cast<MediaType*>(o);
154 void SetupEditDialog::updateData()
156 platformComBox->updateDataModel();
157 mediaTypeComBox->updateDataModel();