3 ** Copyright 2010 Mikko Keinänen
5 ** This file is part of EmuFront.
8 ** EmuFront is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License version 2 as published by
10 ** the Free Software Foundation and appearing in the file gpl.txt included in the
11 ** packaging of this file.
13 ** EmuFront is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
18 ** You should have received a copy of the GNU General Public License
19 ** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
22 #include "mainwindow.h"
23 #include "emulauncher.h"
25 //#include "platformdialog.h"
26 #include "platformeditview.h"
27 //#include "mediatypedialog.h"
28 #include "mediatypeeditview.h"
30 //#include "mediaimagepathmaindialog.h"
31 #include "filepatheditview.h"
33 //#include "setupmaindialog.h"
34 #include "setupeditview.h"
36 //#include "executablemaindialog.h"
37 #include "externalexecutableeditview.h"
38 #include "datfileutil.h"
39 #include "databasemanager.h"
40 #include "dbcreator.h"
42 #include "setupmodel.h"
44 QString MainWindow::aboutStr = trUtf8(
46 "<p>© 2010 Mikko Keinänen</p>"
47 "<p>mikko.keinanen@gmail.com</p>"
48 "<p>EmuFront is free software: you can redistribute it and/or modify "
49 "it under the terms of the GNU General Public License version 2 as published by "
50 "the Free Software Foundation.</p>"
53 QString MainWindow::aboutTitle = tr("About EmuFront");
55 MainWindow::MainWindow(bool reset)
57 if (!testDB(reset)) close();
58 errorMessage = new QErrorMessage(this);
59 setWindowTitle("EmuFront");
60 tmpDirFilePath = DbConfig::getTmpDir();
61 if (tmpDirFilePath.isEmpty())
62 tmpDirFilePath = QDir::homePath();
63 qDebug() << "Temporary dir is " << tmpDirFilePath;
64 supModel = new SetupModel(this);
65 launcher = new EmuLauncher(errorMessage, supModel, this, tmpDirFilePath);
66 setCentralWidget(launcher);
75 //mediaTypeDialog = 0;
78 //mediaImagePathDialog = 0;
79 mediaImagePathView = 0;
81 //setupMainDialog = 0;
84 //executableMainDialog = 0;
88 void MainWindow::connectSignals()
92 void MainWindow::createActions()
95 /*configPlatformAction = new QAction(tr("&Platforms"), this);
96 configPlatformAction->setStatusTip(tr("Configure platforms"));
97 connect(configPlatformAction, SIGNAL(triggered()),
98 this, SLOT(configurePlatforms()));*/
100 configPlatformsAction = new QAction(tr("&Set Platforms"), this);
101 configPlatformsAction->setStatusTip(tr("Add, edit and delete platforms"));
102 connect(configPlatformsAction, SIGNAL(triggered()),
103 this, SLOT(configurePlatformss()));
106 /*configMediaTypeAction = new QAction(tr("&Media Types"), this);
107 configMediaTypeAction->setStatusTip(tr("Configure media types"));
108 connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));*/
110 configMediaTypesAction = new QAction(tr("&Set Media Types"), this);
111 configMediaTypesAction->setStatusTip(tr("Add, edit and delete media types"));
112 connect(configMediaTypesAction, SIGNAL(triggered()), this, SLOT(configureMediaTypess()));
115 /*configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
116 configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
117 connect(configMediaImagePathAction, SIGNAL(triggered()),
118 this, SLOT(configureMediaImagePaths()));*/
120 configMediaImagePathsAction = new QAction(tr("Set media &image paths"), this);
121 configMediaImagePathsAction->setStatusTip(tr("Add, edit and delete media image file paths."));
122 connect(configMediaImagePathsAction, SIGNAL(triggered()),
123 this, SLOT(configureMediaImagePathss()));
126 /*configSetupAction = new QAction(tr("S&etups"), this);
127 configSetupAction->setStatusTip(tr("Configure set ups"));
128 connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));*/
130 configSetupsAction = new QAction(tr("Configure S&etups"), this);
131 configSetupsAction->setStatusTip(tr("Add, edit and delete setups"));
132 connect(configSetupsAction, SIGNAL(triggered()), this, SLOT(configureSetupss()));
134 /*configEmulatorAction = new QAction(tr("Em&ulators"), this);
135 configEmulatorAction->setStatusTip(tr("Configure emulators"));
136 connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));*/
138 configEmulatorsAction = new QAction(tr("Configure Em&ulators"), this);
139 configEmulatorsAction->setStatusTip(tr("Add, edit and delete emulator configurations"));
140 connect(configEmulatorsAction, SIGNAL(triggered()), this, SLOT(configureEmulatorss()));
143 configTmpDirAction = new QAction(tr("&Temp dir"), this);
144 configTmpDirAction->setStatusTip(tr("Configure directory for temporary files."));
145 connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir()));
147 manageDatFilesAction = new QAction(tr("&Manage dats"), this);
148 manageDatFilesAction->setStatusTip(tr("Read dat files to database."));
149 connect(manageDatFilesAction, SIGNAL(triggered()), this, SLOT(manageDatFiles()));
151 exitAction = new QAction(tr("&Exit"), this);
152 exitAction->setShortcut(tr("Ctrl+Q"));
153 exitAction->setStatusTip(tr("Exit EmuFront"));
154 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
156 resetDbAction = new QAction( tr("Reset database"), this);
157 resetDbAction->setStatusTip(tr("Deletes all the current data and create a new database."));
158 connect(resetDbAction, SIGNAL(triggered()), this, SLOT(resetDb()));
160 aboutAction = new QAction(tr("&About"), this);
161 aboutAction->setStatusTip(tr("About EmuFront"));
162 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
166 /*void MainWindow::configurePlatforms()
170 platformDialog = new PlatformDialog(this);
171 connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
173 activateDialog(platformDialog);
176 void MainWindow::configurePlatformss()
179 plfDialog = new PlatformEditView(this);
180 connect(plfDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
182 activateDialog(plfDialog);
186 /*void MainWindow::configureMediaTypes()
188 if (!mediaTypeDialog)
190 mediaTypeDialog = new MediaTypeDialog(this);
191 connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
193 activateDialog(mediaTypeDialog);
196 void MainWindow::configureMediaTypess()
200 mdtDialog = new MediaTypeEditView(this);
201 connect(mdtDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
203 activateDialog(mdtDialog);
208 /*void MainWindow::configureMediaImagePaths()
210 if (!mediaImagePathDialog)
212 mediaImagePathDialog = new MediaImagePathMainDialog(this);
214 activateDialog(mediaImagePathDialog);
217 void MainWindow::configureMediaImagePathss()
219 if (!mediaImagePathView)
221 mediaImagePathView = new FilePathEditView(this);
223 activateDialog(mediaImagePathView);
227 /*void MainWindow::configureSetups()
229 if (!setupMainDialog)
231 setupMainDialog = new SetupMainDialog(this);
233 activateDialog(setupMainDialog);
234 setupMainDialog->refreshDataModel();
237 void MainWindow::configureSetupss()
239 //TODO: maybe a common setup model in MainWindow, so the data would be in sync without refresh with updateData!
240 if (!setupMainView) {
241 setupMainView = new SetupEditView(supModel, this);
242 //connect(setupMainView, SIGNAL(finished(int)), this, SLOT(updateData()));
244 activateDialog(setupMainView);
249 /*void MainWindow::configureEmulators()
251 if (!executableMainDialog) {
252 executableMainDialog = new ExecutableMainDialog(this);
253 connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
255 activateDialog(executableMainDialog);
256 executableMainDialog->refreshDataModel();
259 void MainWindow::configureEmulatorss()
261 if (!emulatorEditView) {
262 emulatorEditView = new ExternalExecutableEditView(this);
263 connect(emulatorEditView, SIGNAL(finished(int)), this, SLOT(updateData()));
265 activateDialog(emulatorEditView);
268 void MainWindow::configureTmpDir()
270 /*if (!tmpFolderDialog) {
271 tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath);
273 activateDialog(tmpFolderDialog);*/
275 QString fpath = QFileDialog::getExistingDirectory(this,
276 tr("Select a directory"), tmpDirFilePath,
277 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
279 if (d.exists() && d.isReadable()) {
280 tmpDirFilePath = fpath;
281 DbConfig::setTmpDir(tmpDirFilePath);
282 launcher->setTmpDirPath(tmpDirFilePath);
286 void MainWindow::resetDb()
288 if (QMessageBox::question(this, "Reset database?",
289 "Are you REALLY SURE you want to do this? "
290 "All the current data WILL BE LOST!",
292 QMessageBox::Yes) == QMessageBox::No) {
298 catch (EmuFrontException e) {
299 errorMessage->showMessage(e.what());
303 void MainWindow::manageDatFiles()
309 void MainWindow::activateDialog(EmuFrontDialog* dia) const
313 dia->activateWindow();
316 void MainWindow::createMenus()
318 fileMenu = menuBar()->addMenu(tr("&File"));
319 fileMenu->addAction(resetDbAction);
320 fileMenu->addSeparator();
321 fileMenu->addAction(exitAction);
323 configMenu = menuBar()->addMenu(tr("&Config"));
324 configMenu->addAction(configTmpDirAction);
325 configMenu->addSeparator();
327 //configMenu->addAction(configPlatformAction);
328 configMenu->addAction(configPlatformsAction);
330 //configMenu->addAction(configMediaTypeAction);
331 configMenu->addAction(configMediaTypesAction);
333 //configMenu->addAction(configSetupAction);
334 configMenu->addAction(configSetupsAction);
336 //configMenu->addAction(configMediaImagePathAction);
337 configMenu->addAction(configMediaImagePathsAction);
339 //configMenu->addAction(configEmulatorAction);
340 configMenu->addAction(configEmulatorsAction);
341 configMenu->addSeparator();
342 configMenu->addAction(manageDatFilesAction);
344 helpMenu = menuBar()->addMenu(tr("&Help"));
345 helpMenu->addAction(aboutAction);
348 void MainWindow::createStatusBar()
350 messageLabel = new QLabel;
351 statusBar()->addWidget(messageLabel);
354 void MainWindow::readSettings()
358 void MainWindow::writeSettings()
362 void MainWindow::closeEvent(QCloseEvent *event)
366 else event->ignore();
369 bool MainWindow::okToContinue()
374 void MainWindow::updateData()
376 qDebug() << "MainWindow::updateData()";
377 launcher->updateData();
380 void MainWindow::about()
382 QMessageBox::about(this, aboutTitle, aboutStr);
385 bool MainWindow::testDB(bool reset)
388 if (DatabaseManager::openDB()) {
389 qDebug() << " Database opened succesfully!";
392 throw EmuFrontException("Database connection failed!");
395 int dbVer = DbCreator::dbExists();
396 if (dbVer == 0) reset = true;
397 if (!reset && dbVer != DbCreator::DB_VERSION) {
398 QString msg("Database is not compatible "
399 "with current version of EmuFront!"
400 "Do you want to continue to recreate the database?"
401 "ALL THE CURRENT DATA WILL BE LOST!!!");
402 if (QMessageBox::question(this, "Database not compatible!", msg,
403 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
406 else throw EmuFrontException("The current database is not compatible!"
407 " Cannot continue.");
415 catch (EmuFrontException e) {
416 qDebug() << e.what();
417 errorMessage->showMessage(e.what());
422 void MainWindow::createDB() const
427 dbCreator.createDB();
429 catch (QString str) {
430 QString msg(tr("Exception while trying to create"
431 " EmuFront database: %s").arg(str));
432 errorMessage->showMessage(msg);