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);
69 void MediaImagePathDialog::layout()
71 QLabel *setupLabel = new QLabel(tr("&Set up"));
72 setupLabel->setBuddy(setupComBox);
74 QGridLayout *gridLayout = new QGridLayout;
75 gridLayout->addWidget(setupLabel, 0, 0);
76 gridLayout->addWidget(setupComBox, 0, 1);
77 gridLayout->addWidget(filePathButton, 1, 0);
78 gridLayout->addWidget(filePathLabel, 1, 1);
79 QVBoxLayout *mainLayout = new QVBoxLayout;
80 mainLayout->addLayout(gridLayout);
81 mainLayout->addWidget(buttonBox);
82 setLayout(mainLayout);
84 setWindowTitle(tr("Set media image paths"));
87 void MediaImagePathDialog::setDataObject(EmuFrontObject *ob)
91 FilePathObject *fpo = dynamic_cast<FilePathObject*>(ob);
92 QString fpath = fpo->getName();
93 filePathLabel->setText(fpath);
94 if (fpo->getSetup()) setSelectedSetup(fpo->getSetup());
97 void MediaImagePathDialog::setSelectedSetup(const Setup *sup)
99 setupComBox->setSelected(sup);
102 Setup* MediaImagePathDialog::getSelectedSetup()
104 EmuFrontObject *ob = setupComBox->getSelected();
106 return dynamic_cast<Setup*>(ob);
109 void MediaImagePathDialog::acceptChanges()
111 FilePathObject *fpo = dynamic_cast<FilePathObject*>(efObject);
112 Setup *sup = getSelectedSetup();
115 QMessageBox::information(this, tr("Set up"), tr("Set up not selected"), QMessageBox::Ok);
118 qDebug() << "Setup selected " << sup->getName();
119 QString filePath = filePathLabel->text();
120 if (filePath.isEmpty())
122 QMessageBox::information(this, tr("File path"), tr("File path was not selected"), QMessageBox::Ok);
125 Setup *tmp = fpo->getSetup();
131 fpo->setName(filePath);
132 emit dataObjectUpdated();
138 void MediaImagePathDialog::updateData()
140 setupComBox->updateDataModel();