signals not connected for SetupEditDialog!
[emufront] / src / dialogs / setupeditdialog.cpp
1 // EmuFront
2 // Copyright 2010 Mikko Keinänen
3 //
4 // This file is part of EmuFront.
5 //
6 //
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.
11 //
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.
16 //
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/>.
19
20 #include <QtGui>
21 #include <QSqlTableModel>
22 #include <QSqlRecord>
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"
29
30 SetupEditDialog::SetupEditDialog(QWidget *parent, EmuFrontObject* obj)
31     : DataObjectEditDialog(parent, obj)
32 {
33     dbSetup = 0;
34     dbPlatform = new DbPlatform(this);
35     dbMediaType = new DbMediaType(this);
36     initWidgets();
37     connectSignals();
38     emit test();
39     layout();
40 }
41
42 void SetupEditDialog::initWidgets()
43 {
44     mediaTypeComBox = new EFFileObjectComboBox(dbMediaType, this);
45     platformComBox = new EFFileObjectComboBox(dbPlatform, this);
46     supportedFileTypesList = new StringListWidget;
47 }
48
49 void SetupEditDialog::layout()
50 {
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"));
66 }
67
68 void SetupEditDialog::acceptChanges()
69 {
70     Setup *sup = dynamic_cast<Setup*>(efObject);
71     Platform *plf = getSelectedPlatform();
72     if (!plf)
73     {
74         QMessageBox::information(this, tr("Platform"),
75             tr("Platform not selected"), QMessageBox::Ok);
76         return;
77     }
78     qDebug() << "Platform selected " << plf->getName();
79     MediaType *mt = getSelectedMediaType();
80     if (!mt)
81     {
82         QMessageBox::information(this, tr("Media type"), tr("Media type was not selected"), QMessageBox::Ok);
83         return;
84     }
85     qDebug() << "Media type selected " << mt->getName();
86
87
88     Platform *ptmp = sup->getPlatform();
89     if (plf != ptmp)
90     {
91         delete ptmp;
92         sup->setPlatform(plf);
93     }
94     MediaType *mtmp = sup->getMediaType();
95     if (mt != mtmp)
96     {
97         delete mtmp;
98         sup->setMediaType(mt);
99     }
100     sup->setSupportedFileTypeExtensions(supportedFileTypesList->getItems());
101     qDebug() << "Emitting dataObjectUpdated";
102     // TODO: this is not received
103     emit dataObjectUpdated();
104     efObject = 0;
105     qDebug() << "Closing setup edit dialog";
106     close();
107 }
108
109 void SetupEditDialog::setDataObject(EmuFrontObject *ob)
110 {
111     if (!ob) return;
112     qDebug() << "Updating Setup edit dialog data object to "
113         << ob->getName() << ".";
114     if (efObject) delete efObject;
115     efObject = ob;
116     Setup *sup= dynamic_cast<Setup*>(ob);
117     if (sup->getPlatform()) setSelectedPlatform(sup->getPlatform());
118     if (sup->getMediaType()) setSelectedMediaType(sup->getMediaType());
119     supportedFileTypesList->setItems(sup->getSupportedFileTypeExtensions());
120 }
121
122 void SetupEditDialog::setSelectedPlatform(const Platform *plf)
123 {
124     platformComBox->setSelected(plf);
125 }
126
127 void SetupEditDialog::setSelectedMediaType(const MediaType *plf)
128 {
129     mediaTypeComBox->setSelected(plf);
130 }
131
132 Platform* SetupEditDialog::getSelectedPlatform() const
133 {
134     EmuFrontObject *o = platformComBox->getSelected();
135     if (!o) return 0;
136     Platform *plf = dynamic_cast<Platform*>(o);
137     return plf;
138 }
139
140 MediaType* SetupEditDialog::getSelectedMediaType() const
141 {
142     EmuFrontObject *o = mediaTypeComBox->getSelected();
143     if (!o) return 0;
144     MediaType *mt = dynamic_cast<MediaType*>(o);
145     return mt;
146 }
147
148 void SetupEditDialog::updateData()
149 {
150     platformComBox->updateDataModel();
151     mediaTypeComBox->updateDataModel();
152 }