Testing selected emulator and image file.
[emufront] / src / emulauncher.cpp
1 // EmuFront
2 // Copyright 2010 Mikko Keinänen
3 //
4 // This file is part of EmuFront.
5 //
6 //
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.
11 //
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.
16 //
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/>.
19
20 #include <QtGui>
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"
29
30 EmuLauncher::EmuLauncher(QWidget *parent) :
31     QWidget(parent)
32 {
33     dbPlatform = new DbPlatform(this);
34     dbMediaType = new DbMediaType(this);
35     dbExec = new DbExecutable(this);
36     dbMic = 0;
37     initWidgets();
38     layout();
39     connectSignals();
40 }
41
42 void EmuLauncher::updateData()
43 {
44     platformSelectBox->updateDataModel();
45     mediaTypeSelectBox->updateDataModel();
46     execSelectBox->updateDataModel();
47 }
48
49 void EmuLauncher::initWidgets()
50 {
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"));
58 }
59
60 void EmuLauncher::layout()
61 {
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);
69     setLayout(grid);
70 }
71
72 void EmuLauncher::connectSignals()
73 {
74     connect(selectButton, SIGNAL(clicked()), this, SLOT(updateMediaImageContainers()));
75     connect(launchButton, SIGNAL(clicked()),this, SLOT(launchEmu()));
76 }
77
78 void EmuLauncher::updateMediaImageContainers()
79 {
80     qDebug() << "updateMediaImageContainers slot";
81     int mtid = mediaTypeSelectBox->getSelected()
82         ? mediaTypeSelectBox->getSelected()->getId()
83         : -1;
84     int plfid = platformSelectBox->getSelected()
85         ? platformSelectBox->getSelected()->getId()
86         : -1;
87
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();
94 }
95
96 void EmuLauncher::launchEmu()
97 {
98     if (execSelectBox->currentIndex() == -1) {
99         QMessageBox::information(this, tr("Emulator"),
100             tr("Emulator not selected!"), QMessageBox::Ok);
101         return;
102     }
103     QModelIndex mindex = micTable->currentIndex();
104     if (!mindex.isValid()) {
105         QMessageBox::information(this, tr("File"),
106             tr("No image selected"), QMessageBox::Ok);
107         return;
108     }
109     qDebug() << "launchEmu";
110 }