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 // Foobar 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
21 #include <QSqlTableModel>
23 #include "../db/dbplatform.h"
24 #include "../db/dbmediatype.h"
25 #include "mediaimagepathdialog.h"
26 #include "../dataobjects/platform.h"
27 #include "../dataobjects/mediatype.h"
28 #include "../dataobjects/filepathobject.h"
30 MediaImagePathDialog::MediaImagePathDialog(QWidget *parent, EmuFrontObject *efObject)
31 : DataObjectEditDialog(parent, efObject)
34 populateMediaTypeComBox();
35 populatePlatformComBox();
40 MediaImagePathDialog::~MediaImagePathDialog()
44 void MediaImagePathDialog::connectSignals()
48 void MediaImagePathDialog::initWidgets()
50 // these widgets will be automatically parented using layout components
51 buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
52 filePathLabel = new QLabel;
53 filePathButton = new QPushButton(tr("&Browse filepath"));
54 mediaTypeComBox = new QComboBox;
55 platformComBox = new QComboBox;
58 void MediaImagePathDialog::populateMediaTypeComBox()
60 dbMediaType = new DbMediaType(this);
61 mediaTypeComBox->setModel(dbMediaType->getDataModel());
62 mediaTypeComBox->setModelColumn(DbMediaType::MediaType_Name);
65 void MediaImagePathDialog::populatePlatformComBox()
67 dbPlatform = new DbPlatform(this);
68 platformComBox->setModel(dbPlatform->getDataModel());
69 platformComBox->setModelColumn(DbPlatform::Platform_Name);
72 void MediaImagePathDialog::layout()
74 QLabel *platformLabel = new QLabel(tr("&Platform"));
75 platformLabel->setBuddy(platformComBox);
76 QLabel *mediaTypeLabel = new QLabel(tr("Media&Type"));
77 mediaTypeLabel->setBuddy(mediaTypeComBox);
79 QGridLayout *gridLayout = new QGridLayout;
80 gridLayout->addWidget(platformLabel, 0, 0);
81 gridLayout->addWidget(platformComBox, 0, 1);
82 gridLayout->addWidget(mediaTypeLabel, 1, 0);
83 gridLayout->addWidget(mediaTypeComBox, 1, 1);
84 gridLayout->addWidget(filePathButton, 2, 0);
85 gridLayout->addWidget(filePathLabel, 2, 1);
86 gridLayout->addWidget(buttonBox, 3, 0, 1, 2);
87 setLayout(gridLayout);
89 setWindowTitle(tr("Set media image paths"));
92 void MediaImagePathDialog::setDataObject(EmuFrontObject *ob)
96 FilePathObject *fpo = dynamic_cast<FilePathObject*>(ob);
97 QString fpath = fpo->getName();
98 filePathLabel->setText(fpath);
99 setSelectedPlatform(fpo->getPlatform());
100 setSelectedMediaType(fpo->getMediaType());
103 void MediaImagePathDialog::setSelectedPlatform(const Platform *plf)
105 setSelected(platformModel, platformComBox, plf, DbPlatform::Platform_Id);
108 void MediaImagePathDialog::setSelectedMediaType(const MediaType *plf)
110 setSelected(mediaTypeModel, mediaTypeComBox, plf, DbMediaType::MediaType_Id);
113 // TODO: this might be useful to lever to upper classes
114 void MediaImagePathDialog::setSelected(const QSqlTableModel *model, QComboBox *cbox, const EmuFrontObject *ob, int idIndex)
117 for (int i = 0; i < model->rowCount(); ++i)
119 QSqlRecord rec = model->record(i);
120 if (rec.value(idIndex) == ob->getId())
122 cbox->setCurrentIndex(i);
129 void MediaImagePathDialog::acceptChanges()
133 void MediaImagePathDialog::rejectChanges()