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 as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
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)
33 dbSetup = 0; //new DbSetup(this);
34 dbPlatform = new DbPlatform(this);
35 dbMediaType = new DbMediaType(this);
37 qDebug() << "Connecting signals";
42 void SetupEditDialog::initWidgets()
44 mediaTypeComBox = new EFFileObjectComboBox(dbMediaType, this); //new QComboBox;
45 platformComBox = new EFFileObjectComboBox(dbPlatform, this); //new QComboBox;
46 supportedFileTypesList = new StringListWidget;
49 void SetupEditDialog::layout()
51 qDebug() << "SetupEditDialog::layout";
52 QLabel *platformLabel = new QLabel(tr("&Platform"));
53 platformLabel->setBuddy(platformComBox);
54 QLabel *mediaTypeLabel = new QLabel(tr("Media&Type"));
55 mediaTypeLabel->setBuddy(mediaTypeComBox);
56 QGridLayout *gridLayout = new QGridLayout;
57 gridLayout->addWidget(platformLabel, 0, 0);
58 gridLayout->addWidget(platformComBox, 0, 1);
59 gridLayout->addWidget(mediaTypeLabel, 1, 0);
60 gridLayout->addWidget(mediaTypeComBox, 1, 1);
61 gridLayout->addWidget(supportedFileTypesList, 2, 0, 2, 2);
62 QVBoxLayout *mainLayout = new QVBoxLayout;
63 mainLayout->addLayout(gridLayout);
64 mainLayout->addWidget(buttonBox);
65 setLayout(mainLayout);
66 qDebug() << "SetupEditDialog::layout done";
68 setWindowTitle(tr("Edit setup"));
71 void SetupEditDialog::acceptChanges()
73 Setup *sup = dynamic_cast<Setup*>(efObject);
74 Platform *plf = getSelectedPlatform();
77 QMessageBox::information(this, tr("Platform"), tr("Platform not selected"), QMessageBox::Ok);
80 qDebug() << "Platform selected " << plf->getName();
81 MediaType *mt = getSelectedMediaType();
84 QMessageBox::information(this, tr("Media type"), tr("Media type was not selected"), QMessageBox::Ok);
87 qDebug() << "Media type selected " << mt->getName();
90 Platform *ptmp = sup->getPlatform();
94 sup->setPlatform(plf);
96 MediaType *mtmp = sup->getMediaType();
100 sup->setMediaType(mt);
102 sup->setSupportedFileTypeExtensions(supportedFileTypesList->getItems());
103 emit dataObjectUpdated();
105 qDebug() << "Closing setup edit dialog";
109 void SetupEditDialog::setDataObject(EmuFrontObject *ob)
113 Setup *sup= dynamic_cast<Setup*>(ob);
114 if (sup->getPlatform()) setSelectedPlatform(sup->getPlatform());
115 if (sup->getMediaType()) setSelectedMediaType(sup->getMediaType());
116 supportedFileTypesList->setItems(sup->getSupportedFileTypeExtensions());
119 void SetupEditDialog::setSelectedPlatform(const Platform *plf)
121 //setSelected(platformComBox, plf, DbPlatform::EmuFrontFileObject_Id);
122 platformComBox->setSelected(plf);
125 void SetupEditDialog::setSelectedMediaType(const MediaType *plf)
127 //setSelected(mediaTypeComBox, plf, DbMediaType::EmuFrontFileObject_Id);
128 mediaTypeComBox->setSelected(plf);
131 Platform* SetupEditDialog::getSelectedPlatform() const
134 int index = platformComBox->currentIndex();
135 qDebug() << "Platform from index " << index << " selected";
138 QSqlQueryModel* platformModel
139 = dynamic_cast<QSqlQueryModel*>(platformComBox->model());
142 qDebug() << "No platform model";
145 QSqlRecord rec = platformModel->record(index);
148 qDebug() << "Trying to fetch platform with id "
149 << rec.value(DbPlatform::EmuFrontFileObject_Id).toInt() ;
151 = dbPlatform->getDataObject(rec.value(DbPlatform::EmuFrontFileObject_Id).toInt());
152 plf = dynamic_cast<Platform*>(o);
155 EmuFrontObject *o = platformComBox->getSelected();
157 Platform *plf = dynamic_cast<Platform*>(o);
161 MediaType* SetupEditDialog::getSelectedMediaType() const
164 int index = mediaTypeComBox->currentIndex();
165 if (index < 0) return mt;
166 QSqlQueryModel* mediaTypeModel = dynamic_cast<QSqlQueryModel*>(mediaTypeComBox->model());
169 qDebug("Media type data model missing");
172 QSqlRecord rec = mediaTypeModel->record(index);
175 EmuFrontObject *o = dbMediaType->getDataObject(rec.value(DbMediaType::EmuFrontFileObject_Id).toInt());
176 mt = dynamic_cast<MediaType*>(o);
179 EmuFrontObject *o = mediaTypeComBox->getSelected();
181 MediaType *mt = dynamic_cast<MediaType*>(o);
185 void SetupEditDialog::updateData()
187 qDebug() << "Updating combobox data";
188 platformComBox->updateDataModel();
189 mediaTypeComBox->updateDataModel();