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 as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
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>
22 #include "emulauncher.h"
23 #include "db/dbmediatype.h"
24 #include "db/dbplatform.h"
25 #include "db/dbexecutable.h"
26 #include "db/dbmediaimagecontainer.h"
27 #include "widgets/effileobjectcombobox.h"
28 #include "widgets/executablecombobox.h"
30 EmuLauncher::EmuLauncher(QWidget *parent) :
33 dbPlatform = new DbPlatform(this);
34 dbMediaType = new DbMediaType(this);
35 dbExec = new DbExecutable(this);
42 void EmuLauncher::updateData()
44 platformSelectBox->updateDataModel();
45 mediaTypeSelectBox->updateDataModel();
46 execSelectBox->updateDataModel();
49 void EmuLauncher::initWidgets()
51 micTable = new QTableView(this);
52 micTable->setSelectionMode(QAbstractItemView::SingleSelection);
53 mediaTypeSelectBox = new EFFileObjectComboBox(dbMediaType, this);
54 platformSelectBox = new EFFileObjectComboBox(dbPlatform, this);
55 execSelectBox = new ExecutableComboBox(dbExec, this);
56 selectButton = new QPushButton(tr("&Update"));
57 launchButton = new QPushButton(tr("&Launch"));
60 void EmuLauncher::layout()
62 QGridLayout *grid = new QGridLayout;
63 grid->addWidget(platformSelectBox, 0, 0);
64 grid->addWidget(mediaTypeSelectBox, 1, 0);
65 grid->addWidget(selectButton, 1, 1);
66 grid->addWidget(micTable, 2, 0, 1, 2);
67 grid->addWidget(execSelectBox, 3, 0);
68 grid->addWidget(launchButton, 3, 1);
72 void EmuLauncher::connectSignals()
74 connect(selectButton, SIGNAL(clicked()), this, SLOT(updateMediaImageContainers()));
75 connect(launchButton, SIGNAL(clicked()),this, SLOT(launchEmu()));
78 void EmuLauncher::updateMediaImageContainers()
80 qDebug() << "updateMediaImageContainers slot";
81 int mtid = mediaTypeSelectBox->getSelected()
82 ? mediaTypeSelectBox->getSelected()->getId()
84 int plfid = platformSelectBox->getSelected()
85 ? platformSelectBox->getSelected()->getId()
88 if (!dbMic) dbMic = new DbMediaImageContainer(this);
89 dbMic->filter(mtid, plfid);
90 micTable->setModel(dbMic->getDataModel());
91 micTable->resizeColumnsToContents();
92 platformSelectBox->updateDataModel();
93 mediaTypeSelectBox->updateDataModel();
96 void EmuLauncher::launchEmu()
98 if (execSelectBox->currentIndex() == -1) {
99 QMessageBox::information(this, tr("Emulator"),
100 tr("Emulator not selected!"), QMessageBox::Ok);
103 QModelIndex mindex = micTable->currentIndex();
104 if (!mindex.isValid()) {
105 QMessageBox::information(this, tr("File"),
106 tr("No image selected"), QMessageBox::Ok);
109 qDebug() << "launchEmu";