3 ** Copyright 2010 Mikko Keinänen
5 ** This file is part of EmuFront.
8 ** EmuFront is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License version 2 as published by
10 ** the Free Software Foundation and appearing in the file gpl.txt included in the
11 ** packaging of this file.
13 ** EmuFront is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
18 ** You should have received a copy of the GNU General Public License
19 ** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
22 #include <QSqlTableModel>
24 #include "mediaimagepathdialog.h"
26 #include "filepathobject.h"
27 #include "setupcombobox.h"
29 MediaImagePathDialog::MediaImagePathDialog(QWidget *parent, EmuFrontObject *efObject)
30 : BrowseFilePathDialog(parent, efObject, Qt::Horizontal)
40 MediaImagePathDialog::~MediaImagePathDialog()
44 /*void MediaImagePathDialog::connectSignals()
46 DataObjectEditDialog::connectSignals();
47 connect(filePathButton, SIGNAL(clicked()), this, SLOT(browseFilePath()));
50 /*void MediaImagePathDialog::browseFilePath()
52 QString fpath = QFileDialog::getExistingDirectory(this, tr("Select a directory"), ".",
53 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
55 if (d.exists() && d.isReadable())
57 filePathLabel->setText(d.path());
61 void MediaImagePathDialog::initWidgets()
63 BrowseFilePathDialog::initWidgets();
64 // these widgets will be automatically parented using layout components
65 //filePathLabel = new QLabel;
66 //filePathButton = new QPushButton(tr("&Browse filepath"));
67 dbSetup = new DbSetup(this);
68 setupComBox = new SetupComboBox(dbSetup, this);
71 void MediaImagePathDialog::layout()
73 QLabel *setupLabel = new QLabel(tr("&Set up"));
74 setupLabel->setBuddy(setupComBox);
76 QGridLayout *gridLayout = new QGridLayout;
77 gridLayout->addWidget(setupLabel, 0, 0);
78 gridLayout->addWidget(setupComBox, 0, 1);
79 gridLayout->addWidget(filePathButton, 1, 0);
80 gridLayout->addWidget(filePathLabel, 1, 1);
81 QVBoxLayout *mainLayout = new QVBoxLayout;
82 mainLayout->addLayout(gridLayout);
83 mainLayout->addWidget(buttonBox);
84 setLayout(mainLayout);
86 setWindowTitle(tr("Set media image paths"));
89 void MediaImagePathDialog::setDataObject(EmuFrontObject *ob)
93 FilePathObject *fpo = dynamic_cast<FilePathObject*>(ob);
94 QString fpath = fpo->getName();
95 filePathLabel->setText(fpath);
96 if (fpo->getSetup()) setSelectedSetup(fpo->getSetup());
99 void MediaImagePathDialog::setSelectedSetup(const Setup *sup)
101 setupComBox->setSelected(sup);
104 /* Returns a pointer to Setup object which must be deleted by calling code */
105 Setup* MediaImagePathDialog::getSelectedSetup()
107 EmuFrontObject *ob = 0;
110 ob = setupComBox->getSelected();
112 catch(EmuFrontException &e){
113 errorMessage->showMessage(e.what());
117 return dynamic_cast<Setup*>(ob);
120 void MediaImagePathDialog::acceptChanges()
122 FilePathObject *fpo = dynamic_cast<FilePathObject*>(efObject);
123 Setup *sup = getSelectedSetup();
126 QMessageBox::information(this, tr("Set up"), tr("Set up not selected"), QMessageBox::Ok);
130 qDebug() << "Setup selected " << sup->getName();
131 QString filePath = filePathLabel->text();
132 if (filePath.isEmpty())
134 QMessageBox::information(this, tr("File path"), tr("File path was not selected"), QMessageBox::Ok);
137 if (filePath != fpo->getName()) {
138 fpo->setName(filePath);
142 Setup *tmp = fpo->getSetup();
144 if (!tmp || *sup != *tmp)
150 if (change) emit dataObjectUpdated();
156 void MediaImagePathDialog::updateData()
158 setupComBox->updateDataModel();
161 void MediaImagePathDialog::clear()
163 BrowseFilePathDialog::clear();
164 setupComBox->setCurrentIndex(-1);