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"),
78 tr("Platform not selected"), QMessageBox::Ok);
81 qDebug() << "Platform selected " << plf->getName();
82 MediaType *mt = getSelectedMediaType();
85 QMessageBox::information(this, tr("Media type"), tr("Media type was not selected"), QMessageBox::Ok);
88 qDebug() << "Media type selected " << mt->getName();
91 Platform *ptmp = sup->getPlatform();
95 sup->setPlatform(plf);
97 MediaType *mtmp = sup->getMediaType();
101 sup->setMediaType(mt);
103 sup->setSupportedFileTypeExtensions(supportedFileTypesList->getItems());
104 emit dataObjectUpdated();
106 qDebug() << "Closing setup edit dialog";
110 void SetupEditDialog::setDataObject(EmuFrontObject *ob)
114 Setup *sup= dynamic_cast<Setup*>(ob);
115 if (sup->getPlatform()) setSelectedPlatform(sup->getPlatform());
116 if (sup->getMediaType()) setSelectedMediaType(sup->getMediaType());
117 supportedFileTypesList->setItems(sup->getSupportedFileTypeExtensions());
120 void SetupEditDialog::setSelectedPlatform(const Platform *plf)
122 //setSelected(platformComBox, plf, DbPlatform::EmuFrontFileObject_Id);
123 platformComBox->setSelected(plf);
126 void SetupEditDialog::setSelectedMediaType(const MediaType *plf)
128 //setSelected(mediaTypeComBox, plf, DbMediaType::EmuFrontFileObject_Id);
129 mediaTypeComBox->setSelected(plf);
132 Platform* SetupEditDialog::getSelectedPlatform() const
135 int index = platformComBox->currentIndex();
136 qDebug() << "Platform from index " << index << " selected";
139 QSqlQueryModel* platformModel
140 = dynamic_cast<QSqlQueryModel*>(platformComBox->model());
143 qDebug() << "No platform model";
146 QSqlRecord rec = platformModel->record(index);
149 qDebug() << "Trying to fetch platform with id "
150 << rec.value(DbPlatform::EmuFrontFileObject_Id).toInt() ;
152 = dbPlatform->getDataObject(rec.value(DbPlatform::EmuFrontFileObject_Id).toInt());
153 plf = dynamic_cast<Platform*>(o);
156 EmuFrontObject *o = platformComBox->getSelected();
158 Platform *plf = dynamic_cast<Platform*>(o);
162 MediaType* SetupEditDialog::getSelectedMediaType() const
165 int index = mediaTypeComBox->currentIndex();
166 if (index < 0) return mt;
167 QSqlQueryModel* mediaTypeModel = dynamic_cast<QSqlQueryModel*>(mediaTypeComBox->model());
170 qDebug("Media type data model missing");
173 QSqlRecord rec = mediaTypeModel->record(index);
176 EmuFrontObject *o = dbMediaType->getDataObject(rec.value(DbMediaType::EmuFrontFileObject_Id).toInt());
177 mt = dynamic_cast<MediaType*>(o);
180 EmuFrontObject *o = mediaTypeComBox->getSelected();
182 MediaType *mt = dynamic_cast<MediaType*>(o);
186 void SetupEditDialog::updateData()
188 qDebug() << "Updating combobox data";
189 platformComBox->updateDataModel();
190 mediaTypeComBox->updateDataModel();