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 "mediaimagepathdialog.h"
24 #include "../db/dbsetup.h"
25 #include "../dataobjects/filepathobject.h"
26 #include "../widgets/setupcombobox.h"
28 MediaImagePathDialog::MediaImagePathDialog(QWidget *parent, EmuFrontObject *efObject)
29 : DataObjectEditDialog(parent, efObject, Qt::Horizontal)
39 MediaImagePathDialog::~MediaImagePathDialog()
43 void MediaImagePathDialog::connectSignals()
45 DataObjectEditDialog::connectSignals();
46 connect(filePathButton, SIGNAL(clicked()), this, SLOT(browseFilePath()));
49 void MediaImagePathDialog::browseFilePath()
51 QString fpath = QFileDialog::getExistingDirectory(this, tr("Select a directory"), ".",
52 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
54 if (d.exists() && d.isReadable())
56 filePathLabel->setText(d.path());
60 void MediaImagePathDialog::initWidgets()
62 // these widgets will be automatically parented using layout components
63 filePathLabel = new QLabel;
64 filePathButton = new QPushButton(tr("&Browse filepath"));
65 dbSetup = new DbSetup(this);
66 setupComBox = new SetupComboBox(dbSetup, this); //QComboBox;
67 //populateSetupComBox();
70 /*void MediaImagePathDialog::populateSetupComBox()
72 dbSetup = new DbSetup(this);
73 setupComBox->setModel(dbSetup->getDataModel());
74 setupComBox->setModelColumn(DbSetup::Setup_Name);
77 void MediaImagePathDialog::layout()
79 QLabel *setupLabel = new QLabel(tr("&Set up"));
80 setupLabel->setBuddy(setupComBox);
82 QGridLayout *gridLayout = new QGridLayout;
83 gridLayout->addWidget(setupLabel, 0, 0);
84 gridLayout->addWidget(setupComBox, 0, 1);
85 gridLayout->addWidget(filePathButton, 1, 0);
86 gridLayout->addWidget(filePathLabel, 1, 1);
87 QVBoxLayout *mainLayout = new QVBoxLayout;
88 mainLayout->addLayout(gridLayout);
89 mainLayout->addWidget(buttonBox);
90 setLayout(mainLayout);
92 setWindowTitle(tr("Set media image paths"));
95 void MediaImagePathDialog::setDataObject(EmuFrontObject *ob)
99 FilePathObject *fpo = dynamic_cast<FilePathObject*>(ob);
100 QString fpath = fpo->getName();
101 filePathLabel->setText(fpath);
102 if (fpo->getSetup()) setSelectedSetup(fpo->getSetup());
105 void MediaImagePathDialog::setSelectedSetup(const Setup *sup)
108 setupComBox->setSelected(sup);
109 // setSelected(setupComBox, sup, DbSetup::Setup_Id);
112 Setup* MediaImagePathDialog::getSelectedSetup()
114 EmuFrontObject *ob = setupComBox->getSelected();
116 return dynamic_cast<Setup*>(ob);
117 /*if (!dbPlatform) dbPlatform => new DbPlatform(this);
118 if (!dbMediaType) dbMediaType = new DbMediaType(this);
120 int index = setupComBox->currentIndex();
121 if (index < 0) return sup;
122 QSqlQueryModel *model
123 = dynamic_cast<QSqlQueryModel*>(setupComBox->model());
126 errorMessage->showMessage(tr("Data model missing."));
129 QSqlRecord rec = model->record(index);
132 EmuFrontObject *efPlf = dbPlatform->getDataObject(rec.value(DbSetup::Setup_PlatformId).toInt());
133 EmuFrontObject *efMt = dbMediaType->getDataObject(rec.value(DbSetup::Setup_MediaTypeId).toInt());
135 Platform *plf = dynamic_cast<Platform*>(efPlf);
136 MediaType *mt = dynamic_cast<MediaType*>(efMt);
137 QString exts = rec.value(DbSetup::Setup_FileTypeExtensions).toString();
139 sup = new Setup(rec.value(DbSetup::Setup_Id).toInt(), plf, mt,
140 exts.split(DbSetup::FILE_TYPE_EXTENSION_SEPARATOR));
142 else errorMessage->showMessage("Record missing");
146 void MediaImagePathDialog::acceptChanges()
148 FilePathObject *fpo = dynamic_cast<FilePathObject*>(efObject);
149 Setup *sup = getSelectedSetup();
152 QMessageBox::information(this, tr("Set up"), tr("Set up not selected"), QMessageBox::Ok);
155 qDebug() << "Setup selected " << sup->getName();
156 QString filePath = filePathLabel->text();
157 if (filePath.isEmpty())
159 QMessageBox::information(this, tr("File path"), tr("File path was not selected"), QMessageBox::Ok);
162 Setup *tmp = fpo->getSetup();
168 fpo->setName(filePath);
169 emit dataObjectUpdated();
175 void MediaImagePathDialog::updateData()
177 setupComBox->updateDataModel();