#include "../widgets/setupcombobox.h"
MediaImagePathDialog::MediaImagePathDialog(QWidget *parent, EmuFrontObject *efObject)
- : DataObjectEditDialog(parent, efObject, Qt::Horizontal)
+ : BrowseFilePathDialog(parent, efObject, Qt::Horizontal)
{
initWidgets();
dbPlatform = 0;
{
}
-void MediaImagePathDialog::connectSignals()
+/*void MediaImagePathDialog::connectSignals()
{
DataObjectEditDialog::connectSignals();
connect(filePathButton, SIGNAL(clicked()), this, SLOT(browseFilePath()));
-}
+}*/
-void MediaImagePathDialog::browseFilePath()
+/*void MediaImagePathDialog::browseFilePath()
{
QString fpath = QFileDialog::getExistingDirectory(this, tr("Select a directory"), ".",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
{
filePathLabel->setText(d.path());
}
-}
+}*/
void MediaImagePathDialog::initWidgets()
{
+ BrowseFilePathDialog::initWidgets();
// these widgets will be automatically parented using layout components
- filePathLabel = new QLabel;
- filePathButton = new QPushButton(tr("&Browse filepath"));
+ //filePathLabel = new QLabel;
+ //filePathButton = new QPushButton(tr("&Browse filepath"));
dbSetup = new DbSetup(this);
- setupComBox = new SetupComboBox(dbSetup, this); //QComboBox;
- //populateSetupComBox();
+ setupComBox = new SetupComboBox(dbSetup, this);
}
-/*void MediaImagePathDialog::populateSetupComBox()
-{
- dbSetup = new DbSetup(this);
- setupComBox->setModel(dbSetup->getDataModel());
- setupComBox->setModelColumn(DbSetup::Setup_Name);
-}*/
-
void MediaImagePathDialog::layout()
{
QLabel *setupLabel = new QLabel(tr("&Set up"));
void MediaImagePathDialog::setSelectedSetup(const Setup *sup)
{
-
setupComBox->setSelected(sup);
- // setSelected(setupComBox, sup, DbSetup::Setup_Id);
}
+/* Returns a pointer to Setup object which must be deleted by calling code */
Setup* MediaImagePathDialog::getSelectedSetup()
{
- EmuFrontObject *ob = setupComBox->getSelected();
- if (!ob) return 0;
- return dynamic_cast<Setup*>(ob);
- /*if (!dbPlatform) dbPlatform => new DbPlatform(this);
- if (!dbMediaType) dbMediaType = new DbMediaType(this);
- Setup *sup = 0;
- int index = setupComBox->currentIndex();
- if (index < 0) return sup;
- QSqlQueryModel *model
- = dynamic_cast<QSqlQueryModel*>(setupComBox->model());
- if (!model)
- {
- errorMessage->showMessage(tr("Data model missing."));
- return sup;
- }
- QSqlRecord rec = model->record(index);
- if (!rec.isEmpty())
- {
- EmuFrontObject *efPlf = dbPlatform->getDataObject(rec.value(DbSetup::Setup_PlatformId).toInt());
- EmuFrontObject *efMt = dbMediaType->getDataObject(rec.value(DbSetup::Setup_MediaTypeId).toInt());
+ EmuFrontObject *ob = 0;
- Platform *plf = dynamic_cast<Platform*>(efPlf);
- MediaType *mt = dynamic_cast<MediaType*>(efMt);
- QString exts = rec.value(DbSetup::Setup_FileTypeExtensions).toString();
-
- sup = new Setup(rec.value(DbSetup::Setup_Id).toInt(), plf, mt,
- exts.split(DbSetup::FILE_TYPE_EXTENSION_SEPARATOR));
+ try {
+ ob = setupComBox->getSelected();
+ }
+ catch(EmuFrontException &e){
+ errorMessage->showMessage(e.what());
}
- else errorMessage->showMessage("Record missing");
- return sup;*/
+
+ if (!ob) return 0;
+ return dynamic_cast<Setup*>(ob);
}
void MediaImagePathDialog::acceptChanges()
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();
- if (sup != tmp)
+
+ if (!tmp || *sup != *tmp)
{
delete tmp;
fpo->setSetup(sup);
+ change = true;
}
- fpo->setName(filePath);
- emit dataObjectUpdated();
+ if (change) emit dataObjectUpdated();
efObject = 0;
close();
}