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"
45 #include "platformmodel.h"
46 #include "mediatypemodel.h"
48 QString MainWindow::aboutStr = trUtf8(
50 "<p>© 2010 Mikko Keinänen</p>"
51 "<p>mikko.keinanen@gmail.com</p>"
52 "<p>EmuFront is free software: you can redistribute it and/or modify "
53 "it under the terms of the GNU General Public License version 2 as published by "
54 "the Free Software Foundation.</p>"
57 QString MainWindow::aboutTitle = tr("About EmuFront");
59 MainWindow::MainWindow(bool reset)
61 if (!testDB(reset)) close();
62 errorMessage = new QErrorMessage(this);
63 setWindowTitle("EmuFront");
64 tmpDirFilePath = DbConfig::getTmpDir();
65 if (tmpDirFilePath.isEmpty())
66 tmpDirFilePath = QDir::homePath();
67 qDebug() << "Temporary dir is " << tmpDirFilePath;
68 supModel = new SetupModel(this);
69 plfModel = new PlatformModel(this);
70 mdtModel = new MediaTypeModel(this);
71 emuModel = new ExternalExecutableModel(this);
72 launcher = new EmuLauncher(errorMessage, supModel, emuModel, this, tmpDirFilePath);
73 setCentralWidget(launcher);
82 //mediaTypeDialog = 0;
85 //mediaImagePathDialog = 0;
86 mediaImagePathView = 0;
88 //setupMainDialog = 0;
91 //executableMainDialog = 0;
95 void MainWindow::connectSignals()
99 void MainWindow::createActions()
102 /*configPlatformAction = new QAction(tr("&Platforms"), this);
103 configPlatformAction->setStatusTip(tr("Configure platforms"));
104 connect(configPlatformAction, SIGNAL(triggered()),
105 this, SLOT(configurePlatforms()));*/
107 configPlatformsAction = new QAction(tr("&Set Platforms"), this);
108 configPlatformsAction->setStatusTip(tr("Add, edit and delete platforms"));
109 connect(configPlatformsAction, SIGNAL(triggered()),
110 this, SLOT(configurePlatformss()));
113 /*configMediaTypeAction = new QAction(tr("&Media Types"), this);
114 configMediaTypeAction->setStatusTip(tr("Configure media types"));
115 connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));*/
117 configMediaTypesAction = new QAction(tr("&Set Media Types"), this);
118 configMediaTypesAction->setStatusTip(tr("Add, edit and delete media types"));
119 connect(configMediaTypesAction, SIGNAL(triggered()), this, SLOT(configureMediaTypess()));
122 /*configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
123 configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
124 connect(configMediaImagePathAction, SIGNAL(triggered()),
125 this, SLOT(configureMediaImagePaths()));*/
127 configMediaImagePathsAction = new QAction(tr("Set media &image paths"), this);
128 configMediaImagePathsAction->setStatusTip(tr("Add, edit and delete media image file paths."));
129 connect(configMediaImagePathsAction, SIGNAL(triggered()),
130 this, SLOT(configureMediaImagePathss()));
133 /*configSetupAction = new QAction(tr("S&etups"), this);
134 configSetupAction->setStatusTip(tr("Configure set ups"));
135 connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));*/
137 configSetupsAction = new QAction(tr("Configure S&etups"), this);
138 configSetupsAction->setStatusTip(tr("Add, edit and delete setups"));
139 connect(configSetupsAction, SIGNAL(triggered()), this, SLOT(configureSetupss()));
141 /*configEmulatorAction = new QAction(tr("Em&ulators"), this);
142 configEmulatorAction->setStatusTip(tr("Configure emulators"));
143 connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));*/
145 configEmulatorsAction = new QAction(tr("Configure Em&ulators"), this);
146 configEmulatorsAction->setStatusTip(tr("Add, edit and delete emulator configurations"));
147 connect(configEmulatorsAction, SIGNAL(triggered()), this, SLOT(configureEmulatorss()));
150 configTmpDirAction = new QAction(tr("&Temp dir"), this);
151 configTmpDirAction->setStatusTip(tr("Configure directory for temporary files."));
152 connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir()));
154 manageDatFilesAction = new QAction(tr("&Manage dats"), this);
155 manageDatFilesAction->setStatusTip(tr("Read dat files to database."));
156 connect(manageDatFilesAction, SIGNAL(triggered()), this, SLOT(manageDatFiles()));
158 exitAction = new QAction(tr("&Exit"), this);
159 exitAction->setShortcut(tr("Ctrl+Q"));
160 exitAction->setStatusTip(tr("Exit EmuFront"));
161 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
163 resetDbAction = new QAction( tr("Reset database"), this);
164 resetDbAction->setStatusTip(tr("Deletes all the current data and create a new database."));
165 connect(resetDbAction, SIGNAL(triggered()), this, SLOT(resetDb()));
167 aboutAction = new QAction(tr("&About"), this);
168 aboutAction->setStatusTip(tr("About EmuFront"));
169 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
173 /*void MainWindow::configurePlatforms()
177 platformDialog = new PlatformDialog(this);
178 connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
180 activateDialog(platformDialog);
183 void MainWindow::configurePlatformss()
186 plfDialog = new PlatformEditView(plfModel, this);
187 connect(plfDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
189 activateDialog(plfDialog);
193 /*void MainWindow::configureMediaTypes()
195 if (!mediaTypeDialog)
197 mediaTypeDialog = new MediaTypeDialog(this);
198 connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
200 activateDialog(mediaTypeDialog);
203 void MainWindow::configureMediaTypess()
207 mdtDialog = new MediaTypeEditView(mdtModel, this);
208 connect(mdtDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
210 activateDialog(mdtDialog);
215 /*void MainWindow::configureMediaImagePaths()
217 if (!mediaImagePathDialog)
219 mediaImagePathDialog = new MediaImagePathMainDialog(this);
221 activateDialog(mediaImagePathDialog);
224 void MainWindow::configureMediaImagePathss()
226 if (!mediaImagePathView)
228 mediaImagePathView = new FilePathEditView(supModel, this);
230 activateDialog(mediaImagePathView);
234 /*void MainWindow::configureSetups()
236 if (!setupMainDialog)
238 setupMainDialog = new SetupMainDialog(this);
240 activateDialog(setupMainDialog);
241 setupMainDialog->refreshDataModel();
244 void MainWindow::configureSetupss()
246 if (!setupMainView) {
247 setupMainView = new SetupEditView(plfModel, mdtModel, supModel, this);
249 activateDialog(setupMainView);
254 /*void MainWindow::configureEmulators()
256 if (!executableMainDialog) {
257 executableMainDialog = new ExecutableMainDialog(this);
258 connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
260 activateDialog(executableMainDialog);
261 executableMainDialog->refreshDataModel();
264 void MainWindow::configureEmulatorss()
266 if (!emulatorEditView) {
267 emulatorEditView = new ExternalExecutableEditView(supModel, emuModel, this);
269 activateDialog(emulatorEditView);
272 void MainWindow::configureTmpDir()
274 QString fpath = QFileDialog::getExistingDirectory(this,
275 tr("Select a directory"), tmpDirFilePath,
276 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
278 if (d.exists() && d.isReadable()) {
279 tmpDirFilePath = fpath;
280 if (DbConfig::setTmpDir(tmpDirFilePath)) {
281 QMessageBox::information(
283 tr("Temp dir updated"),
284 tr("The directory for temporary files "
285 "has been updated to '%1'.")
288 launcher->setTmpDirPath(tmpDirFilePath);
293 void MainWindow::resetDb()
295 if (QMessageBox::question(this, "Reset database?",
296 "Are you REALLY SURE you want to do this? "
297 "All the current data WILL BE LOST!",
299 QMessageBox::Yes) == QMessageBox::No) {
305 catch (EmuFrontException e) {
306 errorMessage->showMessage(e.what());
310 void MainWindow::manageDatFiles()
316 void MainWindow::activateDialog(EmuFrontDialog* dia) const
320 dia->activateWindow();
323 void MainWindow::createMenus()
325 fileMenu = menuBar()->addMenu(tr("&File"));
326 fileMenu->addAction(resetDbAction);
327 fileMenu->addSeparator();
328 fileMenu->addAction(exitAction);
330 configMenu = menuBar()->addMenu(tr("&Config"));
331 configMenu->addAction(configTmpDirAction);
332 configMenu->addSeparator();
334 //configMenu->addAction(configPlatformAction);
335 configMenu->addAction(configPlatformsAction);
337 //configMenu->addAction(configMediaTypeAction);
338 configMenu->addAction(configMediaTypesAction);
340 //configMenu->addAction(configSetupAction);
341 configMenu->addAction(configSetupsAction);
343 //configMenu->addAction(configMediaImagePathAction);
344 configMenu->addAction(configMediaImagePathsAction);
346 //configMenu->addAction(configEmulatorAction);
347 configMenu->addAction(configEmulatorsAction);
348 configMenu->addSeparator();
349 configMenu->addAction(manageDatFilesAction);
351 helpMenu = menuBar()->addMenu(tr("&Help"));
352 helpMenu->addAction(aboutAction);
355 void MainWindow::createStatusBar()
357 messageLabel = new QLabel;
358 statusBar()->addWidget(messageLabel);
361 void MainWindow::readSettings()
365 void MainWindow::writeSettings()
369 void MainWindow::closeEvent(QCloseEvent *event)
373 else event->ignore();
376 bool MainWindow::okToContinue()
381 void MainWindow::updateData()
383 qDebug() << "MainWindow::updateData()";
384 launcher->updateData();
387 void MainWindow::about()
389 QMessageBox::about(this, aboutTitle, aboutStr);
392 bool MainWindow::testDB(bool reset)
395 if (DatabaseManager::openDB()) {
396 qDebug() << " Database opened succesfully!";
399 throw EmuFrontException("Database connection failed!");
402 int dbVer = DbCreator::dbExists();
403 if (dbVer == 0) reset = true;
404 if (!reset && dbVer != DbCreator::DB_VERSION) {
405 QString msg("Database is not compatible "
406 "with current version of EmuFront!"
407 "Do you want to continue to recreate the database?"
408 "ALL THE CURRENT DATA WILL BE LOST!!!");
409 if (QMessageBox::question(this, "Database not compatible!", msg,
410 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
413 else throw EmuFrontException("The current database is not compatible!"
414 " Cannot continue.");
422 catch (EmuFrontException e) {
423 qDebug() << e.what();
424 errorMessage->showMessage(e.what());
429 void MainWindow::createDB() const
434 dbCreator.createDB();
436 catch (QString str) {
437 QString msg(tr("Exception while trying to create"
438 " EmuFront database: %s").arg(str));
439 errorMessage->showMessage(msg);