//
//
// EmuFront is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
//
-// Foobar is distributed in the hope that it will be useful,
+// EmuFront is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
-// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+// along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
#include <QtGui>
#include <QSqlTableModel>
#include <QSqlRecord>
-#include "../db/dbplatform.h"
-#include "../db/dbmediatype.h"
#include "mediaimagepathdialog.h"
-#include "../dataobjects/platform.h"
-#include "../dataobjects/mediatype.h"
+#include "../db/dbsetup.h"
#include "../dataobjects/filepathobject.h"
+#include "../widgets/setupcombobox.h"
MediaImagePathDialog::MediaImagePathDialog(QWidget *parent, EmuFrontObject *efObject)
- : DataObjectEditDialog(parent, efObject)
+ : BrowseFilePathDialog(parent, efObject, Qt::Horizontal)
{
- qDebug() << "Creating MediaImagePathDialog";
initWidgets();
- populateMediaTypeComBox();
- populatePlatformComBox();
- layout();
+ dbPlatform = 0;
+ dbMediaType = 0;
+ dbSetup = 0;
connectSignals();
+ layout();
}
MediaImagePathDialog::~MediaImagePathDialog()
{
- qDebug() << "Destroying MediaImagePathDialog";
-}
-
-void MediaImagePathDialog::connectSignals()
-{
- qDebug() << "MediaImagePathDialog Connecting signals";
}
-void MediaImagePathDialog::initWidgets()
+/*void MediaImagePathDialog::connectSignals()
{
- qDebug() << "MediaImagePathDialog initializing widgets.";
- // these widgets will be automatically parented using layout components
- buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
- filePathLabel = new QLabel;
- filePathButton = new QPushButton(tr("&Browse filepath"));
- mediaTypeComBox = new QComboBox;
- platformComBox = new QComboBox;
-}
+ DataObjectEditDialog::connectSignals();
+ connect(filePathButton, SIGNAL(clicked()), this, SLOT(browseFilePath()));
+}*/
-void MediaImagePathDialog::populateMediaTypeComBox()
+/*void MediaImagePathDialog::browseFilePath()
{
- qDebug() << "MediaImagePathDialog populating media types combo box";
- dbMediaType = new DbMediaType(this);
- mediaTypeComBox->setModel(dbMediaType->getDataModel());
- mediaTypeComBox->setModelColumn(DbMediaType::MediaType_Name);
-}
+ QString fpath = QFileDialog::getExistingDirectory(this, tr("Select a directory"), ".",
+ QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+ QDir d(fpath);
+ if (d.exists() && d.isReadable())
+ {
+ filePathLabel->setText(d.path());
+ }
+}*/
-void MediaImagePathDialog::populatePlatformComBox()
+void MediaImagePathDialog::initWidgets()
{
- qDebug() << "MediaImagePathDialog populating platform combo box";
- dbPlatform = new DbPlatform(this);
- platformComBox->setModel(dbPlatform->getDataModel());
- platformComBox->setModelColumn(DbPlatform::Platform_Name);
+ BrowseFilePathDialog::initWidgets();
+ // these widgets will be automatically parented using layout components
+ //filePathLabel = new QLabel;
+ //filePathButton = new QPushButton(tr("&Browse filepath"));
+ dbSetup = new DbSetup(this);
+ setupComBox = new SetupComboBox(dbSetup, this);
}
void MediaImagePathDialog::layout()
{
- qDebug() << "MediaImagePathDialog setting layout";
- QLabel *platformLabel = new QLabel(tr("&Platform"));
- platformLabel->setBuddy(platformComBox);
- QLabel *mediaTypeLabel = new QLabel(tr("Media&Type"));
- mediaTypeLabel->setBuddy(mediaTypeComBox);
+ QLabel *setupLabel = new QLabel(tr("&Set up"));
+ setupLabel->setBuddy(setupComBox);
QGridLayout *gridLayout = new QGridLayout;
- gridLayout->addWidget(platformLabel, 0, 0);
- gridLayout->addWidget(platformComBox, 0, 1);
- gridLayout->addWidget(mediaTypeLabel, 1, 0);
- gridLayout->addWidget(mediaTypeComBox, 1, 1);
- gridLayout->addWidget(filePathButton, 2, 0);
- gridLayout->addWidget(filePathLabel, 2, 1);
- gridLayout->addWidget(buttonBox, 3, 0, 1, 2);
- setLayout(gridLayout);
+ gridLayout->addWidget(setupLabel, 0, 0);
+ gridLayout->addWidget(setupComBox, 0, 1);
+ gridLayout->addWidget(filePathButton, 1, 0);
+ gridLayout->addWidget(filePathLabel, 1, 1);
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(gridLayout);
+ mainLayout->addWidget(buttonBox);
+ setLayout(mainLayout);
setWindowTitle(tr("Set media image paths"));
}
FilePathObject *fpo = dynamic_cast<FilePathObject*>(ob);
QString fpath = fpo->getName();
filePathLabel->setText(fpath);
- if (fpo->getPlatform()) setSelectedPlatform(fpo->getPlatform());
- if (fpo->getMediaType()) setSelectedMediaType(fpo->getMediaType());
+ if (fpo->getSetup()) setSelectedSetup(fpo->getSetup());
}
-void MediaImagePathDialog::setSelectedPlatform(const Platform *plf)
+void MediaImagePathDialog::setSelectedSetup(const Setup *sup)
{
- setSelected(platformModel, platformComBox, plf, DbPlatform::Platform_Id);
+ setupComBox->setSelected(sup);
}
-void MediaImagePathDialog::setSelectedMediaType(const MediaType *plf)
+/* Returns a pointer to Setup object which must be deleted by calling code */
+Setup* MediaImagePathDialog::getSelectedSetup()
{
- setSelected(mediaTypeModel, mediaTypeComBox, plf, DbMediaType::MediaType_Id);
+ EmuFrontObject *ob = 0;
+
+ try {
+ ob = setupComBox->getSelected();
+ }
+ catch(EmuFrontException &e){
+ errorMessage->showMessage(e.what());
+ }
+
+ if (!ob) return 0;
+ return dynamic_cast<Setup*>(ob);
}
-// TODO: this might be useful to lever to upper classes
-void MediaImagePathDialog::setSelected(const QSqlTableModel *model, QComboBox *cbox, const EmuFrontObject *ob, int idIndex)
+void MediaImagePathDialog::acceptChanges()
{
- if (!ob) return;
- for (int i = 0; i < model->rowCount(); ++i)
+ FilePathObject *fpo = dynamic_cast<FilePathObject*>(efObject);
+ Setup *sup = getSelectedSetup();
+ if (!sup)
{
- QSqlRecord rec = model->record(i);
- if (rec.value(idIndex) == ob->getId())
- {
- cbox->setCurrentIndex(i);
- break;
- }
+ QMessageBox::information(this, tr("Set up"), tr("Set up not selected"), QMessageBox::Ok);
+ return;
+ }
+ bool change = false;
+ qDebug() << "Setup selected " << sup->getName();
+ QString filePath = filePathLabel->text();
+ if (filePath.isEmpty())
+ {
+ QMessageBox::information(this, tr("File path"), tr("File path was not selected"), QMessageBox::Ok);
+ return;
+ }
+ if (filePath != fpo->getName()) {
+ fpo->setName(filePath);
+ change = true;
}
-}
+ Setup *tmp = fpo->getSetup();
-void MediaImagePathDialog::acceptChanges()
-{
+ if (!tmp || *sup != *tmp)
+ {
+ delete tmp;
+ fpo->setSetup(sup);
+ change = true;
+ }
+ if (change) emit dataObjectUpdated();
+ efObject = 0;
+ close();
}
-void MediaImagePathDialog::rejectChanges()
+
+void MediaImagePathDialog::updateData()
{
- // we don't
- efObject = 0;
+ setupComBox->updateDataModel();
}