X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Femulauncher.cpp;h=0e15d4649235a0f79a88e2ea2cb88423302aacc0;hb=6bd5521ba6eedac17d194df82eda4e36de2ccb20;hp=f141afede7cdfc79cc25a9e4fbc34bfaeadcec7f;hpb=db7b38f568631de29c215f1828c1f823966cc3a3;p=emufront diff --git a/src/emulauncher.cpp b/src/emulauncher.cpp index f141afe..0e15d46 100644 --- a/src/emulauncher.cpp +++ b/src/emulauncher.cpp @@ -1,43 +1,40 @@ -// 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 . - +/* +** 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 . +*/ #include #include #include #include #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" +#include "setupmodel.h" +#include "externalexecutablemodel.h" +#include "dbmediaimagecontainer.h" +#include "effileobjectcombobox.h" +#include "executablecombobox.h" +#include "executable.h" +#include "emuhelper.h" +#include "emufrontinputdialog.h" EmuLauncher::EmuLauncher(QErrorMessage *errorMessage, QWidget *parent, QString tmp) : QWidget(parent), tmpDirPath(tmp), errorMessage(errorMessage) { - dbPlatform = new DbPlatform(this); - dbMediaType = new DbMediaType(this); - dbExec = new DbExecutable(this); dbMic = 0; emuHelper = new EmuHelper(this); initWidgets(); @@ -57,9 +54,6 @@ EmuLauncher::~EmuLauncher() void EmuLauncher::updateData() { - platformSelectBox->updateDataModel(); - mediaTypeSelectBox->updateDataModel(); - //execSelectBox->updateDataModel(); } void EmuLauncher::initWidgets() @@ -68,11 +62,18 @@ 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); + + SetupModel *supModel = new SetupModel(this); + setupSelectBox = new QComboBox(this); + setupSelectBox->setModel(supModel); + setupSelectBox->setModelColumn(SetupModel::Setup_Name); + + ExternalExecutableModel *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); } @@ -80,15 +81,14 @@ void EmuLauncher::initWidgets() 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); } @@ -102,23 +102,22 @@ void EmuLauncher::connectSignals() void EmuLauncher::updateMediaImageContainers() { - qDebug() << "updateMediaImageContainers slot"; - int mtid, plfid = -1; - MediaType *mt = 0; - Platform *plf = 0; - try { - mt = dynamic_cast(mediaTypeSelectBox->getSelected()); - plf = dynamic_cast(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 (setupSelectBox->currentIndex() == -1) return; + + // 1. get selected platform and media type id + QAbstractItemModel *setupAbsModel = setupSelectBox->model(); + SetupModel *supModel = qobject_cast(setupAbsModel); + if (!supModel) return; + QModelIndex plfInd = + supModel->index(setupSelectBox->currentIndex(), SetupModel::Setup_PlatformId); + int plfid = supModel->data(plfInd).toInt(); + QModelIndex mtInd = + supModel->index(setupSelectBox->currentIndex(), SetupModel::Setup_MediaTypeId); + int mtid = supModel->data(mtInd).toInt(); + + if (mtid < 0 || plfid < 0) return; + // 2. fetch available media image containers if (!dbMic) dbMic = new DbMediaImageContainer(this); dbMic->filter(mtid, plfid); micTable->setModel(dbMic->getDataModel()); @@ -133,9 +132,15 @@ void EmuLauncher::updateMediaImageContainers() micTable->hideColumn(DbMediaImageContainer::MIC_MediaTypeName); micTable->hideColumn(DbMediaImageContainer::MIC_MediaTypeId); micTable->resizeColumnsToContents(); - platformSelectBox->updateDataModel(); - mediaTypeSelectBox->updateDataModel(); - execSelectBox->updateToSetup(plfid, mtid); + + // 3. filter available emulators + QModelIndex supInd = + supModel->index(setupSelectBox->currentIndex(), SetupModel::Setup_Id); + int supid = supModel->data(supInd).toInt(); + QAbstractItemModel *execAbsModel = execSelectBox->model(); + ExternalExecutableModel *execModel = qobject_cast(execAbsModel); + if (!execModel) return; + execModel->filterBySetup(supid); } void EmuLauncher::launchEmu() @@ -159,14 +164,16 @@ void EmuLauncher::launchEmu() } qDebug() << listMIndex.count() << " items selected."; - EmuFrontObject *obExe = execSelectBox->getSelected(); + // TODO: write a method to ExternalExecutable to return an Executable object of a selected row. + // TODO2: rewrite ExecutableComboBox and reimplement getSelected? + /*EmuFrontObject *obExe = execSelectBox->getSelected(); if (!obExe) { throw EmuFrontException(tr("Failed fetching selected emulator!")); } exe = dynamic_cast(obExe); if (!exe) { throw EmuFrontException(tr("Failed creating Emulator object!")); - } + }*/ qDebug() << "File types; " << exe->getSetup()->getSupportedFileTypeExtensions().count();