-// EmuFront
-// Copyright 2010 Mikko Keinänen
-//
-// This file is part of EmuFront.
-//
-//
-// EmuFront is free software: you can redistribute it and/or modify
-// 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.
-//
-// 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+/*
+** EmuFront
+** Copyright 2010 Mikko Keinänen
+**
+** This file is part of EmuFront.
+**
+**
+** EmuFront is free software: you can redistribute it and/or modify
+** 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.
+**
+** 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+*/
#include <QtGui>
#include <QProcess>
#include <QSqlTableModel>
#include <QItemSelectionModel>
#include "emulauncher.h"
-#include "db/dbmediatype.h"
-#include "db/dbplatform.h"
-#include "db/dbexecutable.h"
-#include "db/dbmediaimagecontainer.h"
-#include "widgets/effileobjectcombobox.h"
-#include "widgets/executablecombobox.h"
-#include "dataobjects/executable.h"
-#include "utils/emuhelper.h"
-#include "dialogs/emufrontinputdialog.h"
-
-EmuLauncher::EmuLauncher(QErrorMessage *errorMessage, QWidget *parent, QString tmp) :
- QWidget(parent), tmpDirPath(tmp), errorMessage(errorMessage)
+#include "setup.h"
+#include "setupmodel.h"
+#include "externalexecutablemodel.h"
+#include "mediaimagecontainer.h"
+#include "mediaimagecontainermodel.h"
+#include "effileobjectcombobox.h"
+#include "executablecombobox.h"
+#include "executable.h"
+#include "emuhelper.h"
+#include "emufrontinputdialog.h"
+
+EmuLauncher::EmuLauncher(QErrorMessage *errorMessage, SetupModel *supModel, ExternalExecutableModel
+ *emuModel, QWidget *parent, QString tmp) :
+ QWidget(parent), supModel(supModel), emuModel(emuModel), tmpDirPath(tmp), errorMessage(errorMessage)
{
- dbPlatform = new DbPlatform(this);
- dbMediaType = new DbMediaType(this);
- dbExec = new DbExecutable(this);
- dbMic = 0;
emuHelper = new EmuHelper(this);
initWidgets();
layout();
void EmuLauncher::updateData()
{
- platformSelectBox->updateDataModel();
- mediaTypeSelectBox->updateDataModel();
- //execSelectBox->updateDataModel();
+ qDebug() << "EmuLauncher::updateData";
+ micModel->refresh();
+ emuModel->refresh();
}
void EmuLauncher::initWidgets()
micTable->setSelectionMode(QAbstractItemView::ExtendedSelection);
micTable->setCornerButtonEnabled(false);
micTable->verticalHeader()->setVisible(false);
- //micTable->horizontalHeader()->setDisabled(true);
micTable->horizontalHeader()->setClickable(false);
- mediaTypeSelectBox = new EFFileObjectComboBox(dbMediaType, this);
- platformSelectBox = new EFFileObjectComboBox(dbPlatform, this);
- execSelectBox = new ExecutableComboBox(dbExec, this);
+
+ micModel = new MediaImageContainerModel(this);
+ micTable->setModel(micModel);
+
+ //supModel = new SetupModel(this);
+ setupSelectBox = new QComboBox(this);
+ setupSelectBox->setModel(supModel);
+ setupSelectBox->setModelColumn(SetupModel::Setup_Name);
+
+ //emuModel = new ExternalExecutableModel(this);
+ execSelectBox = new QComboBox(this);
+ execSelectBox->setModel(emuModel);
+ execSelectBox->setModelColumn(ExternalExecutableModel::Executable_Name);
+
selectButton = new QPushButton(tr("&Update"), this);
launchButton = new QPushButton(tr("&Launch"), this);
}
void EmuLauncher::layout()
{
QGridLayout *grid = new QGridLayout;
- grid->addWidget(platformSelectBox, 0, 0);
- grid->addWidget(mediaTypeSelectBox, 0, 1);
+ grid->addWidget(setupSelectBox, 0, 0, 1, 2);
grid->addWidget(selectButton, 0, 2);
grid->setColumnStretch(3, 1);
grid->addWidget(micTable, 1, 0, 1, 4);
grid->addWidget(execSelectBox, 2, 0);
grid->addWidget(launchButton, 2, 1);
- // grid will be implicitily parented to this
+ // grid will be implicitly parented to this
setLayout(grid);
}
void EmuLauncher::updateMediaImageContainers()
{
- qDebug() << "updateMediaImageContainers slot";
- int mtid, plfid = -1;
- MediaType *mt = 0;
- Platform *plf = 0;
- try {
- mt = dynamic_cast<MediaType*>(mediaTypeSelectBox->getSelected());
- plf = dynamic_cast<Platform*>(platformSelectBox->getSelected());
- }
- catch(EmuFrontException &e){
- errorMessage->showMessage(e.what());
- return;
- }
- mtid = mt ? mt->getId() : -1;
- plfid = plf ? plf->getId() : -1;
- if (mt) delete mt;
- if (plf) delete plf;
-
- if (!dbMic) dbMic = new DbMediaImageContainer(this);
- dbMic->filter(mtid, plfid);
- micTable->setModel(dbMic->getDataModel());
- micTable->hideColumn(DbMediaImageContainer::MIC_FileId);
- micTable->hideColumn(DbMediaImageContainer::MIC_FileSize);
- micTable->hideColumn(DbMediaImageContainer::MIC_FileCheckSum);
- micTable->hideColumn(DbMediaImageContainer::MIC_FilePathId);
- micTable->hideColumn(DbMediaImageContainer::MIC_FilePathName);
- micTable->hideColumn(DbMediaImageContainer::MIC_SetupId);
- micTable->hideColumn(DbMediaImageContainer::MIC_PlatformName);
- micTable->hideColumn(DbMediaImageContainer::MIC_PlatformId);
- micTable->hideColumn(DbMediaImageContainer::MIC_MediaTypeName);
- micTable->hideColumn(DbMediaImageContainer::MIC_MediaTypeId);
+ if (setupSelectBox->currentIndex() == -1) return;
+
+ // 1. get selected platform and media type id
+ QAbstractItemModel *setupAbsModel = setupSelectBox->model();
+ //SetupModel *supModel = qobject_cast<SetupModel *>(setupAbsModel);
+ //if (!supModel) return;
+
+ QModelIndex supInd =
+ supModel->index(setupSelectBox->currentIndex(), SetupModel::Setup_Id);
+ int supId = supModel->data(supInd).toInt();
+ if (supId < 0) return;
+
+ // 2. fetch available media image containers
+
+ QAbstractItemModel *absModel = micTable->model();
+ MediaImageContainerModel *micModel = qobject_cast<MediaImageContainerModel*>(absModel);
+ micModel->filterBySetup(supId);
+
+ micTable->hideColumn(MediaImageContainerModel::MIC_FileId);
+ micTable->hideColumn(MediaImageContainerModel::MIC_FileSize);
+ micTable->hideColumn(MediaImageContainerModel::MIC_FileCheckSum);
+ micTable->hideColumn(MediaImageContainerModel::MIC_FilePathId);
+ micTable->hideColumn(MediaImageContainerModel::MIC_FilePathName);
+ micTable->hideColumn(MediaImageContainerModel::MIC_SetupId);
+ micTable->hideColumn(MediaImageContainerModel::MIC_PlatformName);
+ micTable->hideColumn(MediaImageContainerModel::MIC_PlatformId);
+ micTable->hideColumn(MediaImageContainerModel::MIC_MediaTypeName);
+ micTable->hideColumn(MediaImageContainerModel::MIC_MediaTypeId);
micTable->resizeColumnsToContents();
- platformSelectBox->updateDataModel();
- mediaTypeSelectBox->updateDataModel();
- execSelectBox->updateToSetup(plfid, mtid);
+
+ // 3. filter available emulators
+ QAbstractItemModel *execAbsModel = execSelectBox->model();
+ ExternalExecutableModel *execModel = qobject_cast<ExternalExecutableModel*>(execAbsModel);
+ if (!execModel) return;
+ execModel->filterBySetup(supId);
}
void EmuLauncher::launchEmu()
}
qDebug() << listMIndex.count() << " items selected.";
- EmuFrontObject *obExe = execSelectBox->getSelected();
- if (!obExe) {
- throw EmuFrontException(tr("Failed fetching selected emulator!"));
- }
- exe = dynamic_cast<Executable*>(obExe);
+ QAbstractItemModel *absModel = execSelectBox->model();
+ ExternalExecutableModel *extModel = qobject_cast<ExternalExecutableModel*>(absModel);
+ exe = extModel->getExecutable(execSelectBox->currentIndex());
if (!exe) {
- throw EmuFrontException(tr("Failed creating Emulator object!"));
+ errorMessage->showMessage(tr("Failed creating an executable object from selection."));
+ return;
}
- qDebug() << "File types; " << exe->getSetup()->getSupportedFileTypeExtensions().count();
-
bool mame = exe->getSetup()->getSupportedFileTypeExtensions().isEmpty();
if (mame && listMIndex.count() > 1) {
// Now we have one or more media image containers and an emulator selected,
// let's fetch the media image container data.
+ QAbstractItemModel *micAbsModel = micTable->model();
+ MediaImageContainerModel *micModel = qobject_cast<MediaImageContainerModel *>(micAbsModel);
+ if (!micModel) {
+ throw new EmuFrontException(tr("Failed creating data model for media image containers."));
+ }
+
foreach(QModelIndex mind, listMIndex) {
if (!mind.isValid()) continue;
- EmuFrontObject *obImg = dbMic->getDataObjectFromModel(&mind); // throws EmuFrontException
+
+ EmuFrontObject *obImg = micModel->getDataObject(mind);
+
if (!obImg) {
qDebug() << "Failed creating media image container at row " << mind.row();
continue;