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/>.
23 #include "mainwindow.h"
24 #include "emulauncher.h"
26 //#include "platformdialog.h"
27 #include "platformeditview.h"
28 //#include "mediatypedialog.h"
29 #include "mediatypeeditview.h"
31 //#include "mediaimagepathmaindialog.h"
32 #include "filepatheditview.h"
34 //#include "setupmaindialog.h"
35 #include "setupeditview.h"
37 //#include "executablemaindialog.h"
38 #include "externalexecutableeditview.h"
39 #include "externalexecutablemodel.h"
40 #include "datfileutil.h"
41 #include "databasemanager.h"
42 #include "dbcreator.h"
44 #include "setupmodel.h"
46 QString MainWindow::aboutStr = trUtf8(
48 "<p>© 2010 Mikko Keinänen</p>"
49 "<p>mikko.keinanen@gmail.com</p>"
50 "<p>EmuFront is free software: you can redistribute it and/or modify "
51 "it under the terms of the GNU General Public License version 2 as published by "
52 "the Free Software Foundation.</p>"
55 QString MainWindow::aboutTitle = tr("About EmuFront");
57 MainWindow::MainWindow(bool reset)
59 if (!testDB(reset)) close();
60 errorMessage = new QErrorMessage(this);
61 setWindowTitle("EmuFront");
62 tmpDirFilePath = DbConfig::getTmpDir();
63 if (tmpDirFilePath.isEmpty())
64 tmpDirFilePath = QDir::homePath();
65 qDebug() << "Temporary dir is " << tmpDirFilePath;
66 supModel = new SetupModel(this);
67 emuModel = new ExternalExecutableModel(this);
68 launcher = new EmuLauncher(errorMessage, supModel, emuModel, this, tmpDirFilePath);
69 setCentralWidget(launcher);
78 //mediaTypeDialog = 0;
81 //mediaImagePathDialog = 0;
82 mediaImagePathView = 0;
84 //setupMainDialog = 0;
87 //executableMainDialog = 0;
91 void MainWindow::connectSignals()
95 void MainWindow::createActions()
98 /*configPlatformAction = new QAction(tr("&Platforms"), this);
99 configPlatformAction->setStatusTip(tr("Configure platforms"));
100 connect(configPlatformAction, SIGNAL(triggered()),
101 this, SLOT(configurePlatforms()));*/
103 configPlatformsAction = new QAction(tr("&Set Platforms"), this);
104 configPlatformsAction->setStatusTip(tr("Add, edit and delete platforms"));
105 connect(configPlatformsAction, SIGNAL(triggered()),
106 this, SLOT(configurePlatformss()));
109 /*configMediaTypeAction = new QAction(tr("&Media Types"), this);
110 configMediaTypeAction->setStatusTip(tr("Configure media types"));
111 connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));*/
113 configMediaTypesAction = new QAction(tr("&Set Media Types"), this);
114 configMediaTypesAction->setStatusTip(tr("Add, edit and delete media types"));
115 connect(configMediaTypesAction, SIGNAL(triggered()), this, SLOT(configureMediaTypess()));
118 /*configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
119 configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
120 connect(configMediaImagePathAction, SIGNAL(triggered()),
121 this, SLOT(configureMediaImagePaths()));*/
123 configMediaImagePathsAction = new QAction(tr("Set media &image paths"), this);
124 configMediaImagePathsAction->setStatusTip(tr("Add, edit and delete media image file paths."));
125 connect(configMediaImagePathsAction, SIGNAL(triggered()),
126 this, SLOT(configureMediaImagePathss()));
129 /*configSetupAction = new QAction(tr("S&etups"), this);
130 configSetupAction->setStatusTip(tr("Configure set ups"));
131 connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));*/
133 configSetupsAction = new QAction(tr("Configure S&etups"), this);
134 configSetupsAction->setStatusTip(tr("Add, edit and delete setups"));
135 connect(configSetupsAction, SIGNAL(triggered()), this, SLOT(configureSetupss()));
137 /*configEmulatorAction = new QAction(tr("Em&ulators"), this);
138 configEmulatorAction->setStatusTip(tr("Configure emulators"));
139 connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));*/
141 configEmulatorsAction = new QAction(tr("Configure Em&ulators"), this);
142 configEmulatorsAction->setStatusTip(tr("Add, edit and delete emulator configurations"));
143 connect(configEmulatorsAction, SIGNAL(triggered()), this, SLOT(configureEmulatorss()));
146 configTmpDirAction = new QAction(tr("&Temp dir"), this);
147 configTmpDirAction->setStatusTip(tr("Configure directory for temporary files."));
148 connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir()));
150 manageDatFilesAction = new QAction(tr("&Manage dats"), this);
151 manageDatFilesAction->setStatusTip(tr("Read dat files to database."));
152 connect(manageDatFilesAction, SIGNAL(triggered()), this, SLOT(manageDatFiles()));
154 exitAction = new QAction(tr("&Exit"), this);
155 exitAction->setShortcut(tr("Ctrl+Q"));
156 exitAction->setStatusTip(tr("Exit EmuFront"));
157 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
159 resetDbAction = new QAction( tr("Reset database"), this);
160 resetDbAction->setStatusTip(tr("Deletes all the current data and create a new database."));
161 connect(resetDbAction, SIGNAL(triggered()), this, SLOT(resetDb()));
163 aboutAction = new QAction(tr("&About"), this);
164 aboutAction->setStatusTip(tr("About EmuFront"));
165 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
169 /*void MainWindow::configurePlatforms()
173 platformDialog = new PlatformDialog(this);
174 connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
176 activateDialog(platformDialog);
179 void MainWindow::configurePlatformss()
182 plfDialog = new PlatformEditView(this);
183 connect(plfDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
185 activateDialog(plfDialog);
189 /*void MainWindow::configureMediaTypes()
191 if (!mediaTypeDialog)
193 mediaTypeDialog = new MediaTypeDialog(this);
194 connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
196 activateDialog(mediaTypeDialog);
199 void MainWindow::configureMediaTypess()
203 mdtDialog = new MediaTypeEditView(this);
204 connect(mdtDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
206 activateDialog(mdtDialog);
211 /*void MainWindow::configureMediaImagePaths()
213 if (!mediaImagePathDialog)
215 mediaImagePathDialog = new MediaImagePathMainDialog(this);
217 activateDialog(mediaImagePathDialog);
220 void MainWindow::configureMediaImagePathss()
222 if (!mediaImagePathView)
224 mediaImagePathView = new FilePathEditView(this);
226 activateDialog(mediaImagePathView);
230 /*void MainWindow::configureSetups()
232 if (!setupMainDialog)
234 setupMainDialog = new SetupMainDialog(this);
236 activateDialog(setupMainDialog);
237 setupMainDialog->refreshDataModel();
240 void MainWindow::configureSetupss()
242 //TODO: maybe a common setup model in MainWindow, so the data would be in sync without refresh with updateData!
243 if (!setupMainView) {
244 setupMainView = new SetupEditView(supModel, this);
245 //connect(setupMainView, SIGNAL(finished(int)), this, SLOT(updateData()));
247 activateDialog(setupMainView);
252 /*void MainWindow::configureEmulators()
254 if (!executableMainDialog) {
255 executableMainDialog = new ExecutableMainDialog(this);
256 connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
258 activateDialog(executableMainDialog);
259 executableMainDialog->refreshDataModel();
262 void MainWindow::configureEmulatorss()
264 if (!emulatorEditView) {
265 emulatorEditView = new ExternalExecutableEditView(emuModel, this);
266 //connect(emulatorEditView, SIGNAL(finished(int)), this, SLOT(updateData()));
268 activateDialog(emulatorEditView);
271 void MainWindow::configureTmpDir()
273 /*if (!tmpFolderDialog) {
274 tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath);
276 activateDialog(tmpFolderDialog);*/
278 QString fpath = QFileDialog::getExistingDirectory(this,
279 tr("Select a directory"), tmpDirFilePath,
280 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
282 if (d.exists() && d.isReadable()) {
283 tmpDirFilePath = fpath;
284 DbConfig::setTmpDir(tmpDirFilePath);
285 launcher->setTmpDirPath(tmpDirFilePath);
289 void MainWindow::resetDb()
291 if (QMessageBox::question(this, "Reset database?",
292 "Are you REALLY SURE you want to do this? "
293 "All the current data WILL BE LOST!",
295 QMessageBox::Yes) == QMessageBox::No) {
301 catch (EmuFrontException e) {
302 errorMessage->showMessage(e.what());
306 void MainWindow::manageDatFiles()
312 void MainWindow::activateDialog(EmuFrontDialog* dia) const
316 dia->activateWindow();
319 void MainWindow::createMenus()
321 fileMenu = menuBar()->addMenu(tr("&File"));
322 fileMenu->addAction(resetDbAction);
323 fileMenu->addSeparator();
324 fileMenu->addAction(exitAction);
326 configMenu = menuBar()->addMenu(tr("&Config"));
327 configMenu->addAction(configTmpDirAction);
328 configMenu->addSeparator();
330 //configMenu->addAction(configPlatformAction);
331 configMenu->addAction(configPlatformsAction);
333 //configMenu->addAction(configMediaTypeAction);
334 configMenu->addAction(configMediaTypesAction);
336 //configMenu->addAction(configSetupAction);
337 configMenu->addAction(configSetupsAction);
339 //configMenu->addAction(configMediaImagePathAction);
340 configMenu->addAction(configMediaImagePathsAction);
342 //configMenu->addAction(configEmulatorAction);
343 configMenu->addAction(configEmulatorsAction);
344 configMenu->addSeparator();
345 configMenu->addAction(manageDatFilesAction);
347 helpMenu = menuBar()->addMenu(tr("&Help"));
348 helpMenu->addAction(aboutAction);
351 void MainWindow::createStatusBar()
353 messageLabel = new QLabel;
354 statusBar()->addWidget(messageLabel);
357 void MainWindow::readSettings()
361 void MainWindow::writeSettings()
365 void MainWindow::closeEvent(QCloseEvent *event)
369 else event->ignore();
372 bool MainWindow::okToContinue()
377 void MainWindow::updateData()
379 qDebug() << "MainWindow::updateData()";
380 launcher->updateData();
383 void MainWindow::about()
385 QMessageBox::about(this, aboutTitle, aboutStr);
388 bool MainWindow::testDB(bool reset)
391 if (DatabaseManager::openDB()) {
392 qDebug() << " Database opened succesfully!";
395 throw EmuFrontException("Database connection failed!");
398 int dbVer = DbCreator::dbExists();
399 if (dbVer == 0) reset = true;
400 if (!reset && dbVer != DbCreator::DB_VERSION) {
401 QString msg("Database is not compatible "
402 "with current version of EmuFront!"
403 "Do you want to continue to recreate the database?"
404 "ALL THE CURRENT DATA WILL BE LOST!!!");
405 if (QMessageBox::question(this, "Database not compatible!", msg,
406 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
409 else throw EmuFrontException("The current database is not compatible!"
410 " Cannot continue.");
418 catch (EmuFrontException e) {
419 qDebug() << e.what();
420 errorMessage->showMessage(e.what());
425 void MainWindow::createDB() const
430 dbCreator.createDB();
432 catch (QString str) {
433 QString msg(tr("Exception while trying to create"
434 " EmuFront database: %s").arg(str));
435 errorMessage->showMessage(msg);