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"
43 QString MainWindow::aboutStr = trUtf8(
45 "<p>© 2010 Mikko Keinänen</p>"
46 "<p>mikko.keinanen@gmail.com</p>"
47 "<p>EmuFront is free software: you can redistribute it and/or modify "
48 "it under the terms of the GNU General Public License version 2 as published by "
49 "the Free Software Foundation.</p>"
52 QString MainWindow::aboutTitle = tr("About EmuFront");
54 MainWindow::MainWindow(bool reset)
56 if (!testDB(reset)) close();
57 errorMessage = new QErrorMessage(this);
58 setWindowTitle("EmuFront");
59 tmpDirFilePath = DbConfig::getTmpDir();
60 if (tmpDirFilePath.isEmpty())
61 tmpDirFilePath = QDir::homePath();
62 qDebug() << "Temporary dir is " << tmpDirFilePath;
63 launcher = new EmuLauncher(errorMessage, this, tmpDirFilePath);
64 setCentralWidget(launcher);
73 //mediaTypeDialog = 0;
76 //mediaImagePathDialog = 0;
77 mediaImagePathView = 0;
79 //setupMainDialog = 0;
82 //executableMainDialog = 0;
86 void MainWindow::connectSignals()
90 void MainWindow::createActions()
93 /*configPlatformAction = new QAction(tr("&Platforms"), this);
94 configPlatformAction->setStatusTip(tr("Configure platforms"));
95 connect(configPlatformAction, SIGNAL(triggered()),
96 this, SLOT(configurePlatforms()));*/
98 configPlatformsAction = new QAction(tr("&Set Platforms"), this);
99 configPlatformsAction->setStatusTip(tr("Add, edit and delete platforms"));
100 connect(configPlatformsAction, SIGNAL(triggered()),
101 this, SLOT(configurePlatformss()));
104 /*configMediaTypeAction = new QAction(tr("&Media Types"), this);
105 configMediaTypeAction->setStatusTip(tr("Configure media types"));
106 connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));*/
108 configMediaTypesAction = new QAction(tr("&Set Media Types"), this);
109 configMediaTypesAction->setStatusTip(tr("Add, edit and delete media types"));
110 connect(configMediaTypesAction, SIGNAL(triggered()), this, SLOT(configureMediaTypess()));
113 /*configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
114 configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
115 connect(configMediaImagePathAction, SIGNAL(triggered()),
116 this, SLOT(configureMediaImagePaths()));*/
118 configMediaImagePathsAction = new QAction(tr("Set media &image paths"), this);
119 configMediaImagePathsAction->setStatusTip(tr("Add, edit and delete media image file paths."));
120 connect(configMediaImagePathsAction, SIGNAL(triggered()),
121 this, SLOT(configureMediaImagePathss()));
124 /*configSetupAction = new QAction(tr("S&etups"), this);
125 configSetupAction->setStatusTip(tr("Configure set ups"));
126 connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));*/
128 configSetupsAction = new QAction(tr("Configure S&etups"), this);
129 configSetupsAction->setStatusTip(tr("Add, edit and delete setups"));
130 connect(configSetupsAction, SIGNAL(triggered()), this, SLOT(configureSetupss()));
132 /*configEmulatorAction = new QAction(tr("Em&ulators"), this);
133 configEmulatorAction->setStatusTip(tr("Configure emulators"));
134 connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));*/
136 configEmulatorsAction = new QAction(tr("Configure Em&ulators"), this);
137 configEmulatorsAction->setStatusTip(tr("Add, edit and delete emulator configurations"));
138 connect(configEmulatorsAction, SIGNAL(triggered()), this, SLOT(configureEmulatorss()));
141 configTmpDirAction = new QAction(tr("&Temp dir"), this);
142 configTmpDirAction->setStatusTip(tr("Configure directory for temporary files."));
143 connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir()));
145 manageDatFilesAction = new QAction(tr("&Manage dats"), this);
146 manageDatFilesAction->setStatusTip(tr("Read dat files to database."));
147 connect(manageDatFilesAction, SIGNAL(triggered()), this, SLOT(manageDatFiles()));
149 exitAction = new QAction(tr("&Exit"), this);
150 exitAction->setShortcut(tr("Ctrl+Q"));
151 exitAction->setStatusTip(tr("Exit EmuFront"));
152 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
154 resetDbAction = new QAction( tr("Reset database"), this);
155 resetDbAction->setStatusTip(tr("Deletes all the current data and create a new database."));
156 connect(resetDbAction, SIGNAL(triggered()), this, SLOT(resetDb()));
158 aboutAction = new QAction(tr("&About"), this);
159 aboutAction->setStatusTip(tr("About EmuFront"));
160 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
164 /*void MainWindow::configurePlatforms()
168 platformDialog = new PlatformDialog(this);
169 connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
171 activateDialog(platformDialog);
174 void MainWindow::configurePlatformss()
177 plfDialog = new PlatformEditView(this);
178 connect(plfDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
180 activateDialog(plfDialog);
184 /*void MainWindow::configureMediaTypes()
186 if (!mediaTypeDialog)
188 mediaTypeDialog = new MediaTypeDialog(this);
189 connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
191 activateDialog(mediaTypeDialog);
194 void MainWindow::configureMediaTypess()
198 mdtDialog = new MediaTypeEditView(this);
199 connect(mdtDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
201 activateDialog(mdtDialog);
206 /*void MainWindow::configureMediaImagePaths()
208 if (!mediaImagePathDialog)
210 mediaImagePathDialog = new MediaImagePathMainDialog(this);
212 activateDialog(mediaImagePathDialog);
215 void MainWindow::configureMediaImagePathss()
217 if (!mediaImagePathView)
219 mediaImagePathView = new FilePathEditView(this);
221 activateDialog(mediaImagePathView);
225 /*void MainWindow::configureSetups()
227 if (!setupMainDialog)
229 setupMainDialog = new SetupMainDialog(this);
231 activateDialog(setupMainDialog);
232 setupMainDialog->refreshDataModel();
235 void MainWindow::configureSetupss()
237 if (!setupMainView) {
238 setupMainView = new SetupEditView(this);
240 activateDialog(setupMainView);
245 /*void MainWindow::configureEmulators()
247 if (!executableMainDialog) {
248 executableMainDialog = new ExecutableMainDialog(this);
249 connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
251 activateDialog(executableMainDialog);
252 executableMainDialog->refreshDataModel();
255 void MainWindow::configureEmulatorss()
257 if (!emulatorEditView) {
258 emulatorEditView = new ExternalExecutableEditView(this);
259 connect(emulatorEditView, SIGNAL(finished(int)), this, SLOT(updateData()));
261 activateDialog(emulatorEditView);
264 void MainWindow::configureTmpDir()
266 /*if (!tmpFolderDialog) {
267 tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath);
269 activateDialog(tmpFolderDialog);*/
271 QString fpath = QFileDialog::getExistingDirectory(this,
272 tr("Select a directory"), tmpDirFilePath,
273 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
275 if (d.exists() && d.isReadable()) {
276 tmpDirFilePath = fpath;
277 DbConfig::setTmpDir(tmpDirFilePath);
278 launcher->setTmpDirPath(tmpDirFilePath);
282 void MainWindow::resetDb()
284 if (QMessageBox::question(this, "Reset database?",
285 "Are you REALLY SURE you want to do this? "
286 "All the current data WILL BE LOST!",
288 QMessageBox::Yes) == QMessageBox::No) {
294 catch (EmuFrontException e) {
295 errorMessage->showMessage(e.what());
299 void MainWindow::manageDatFiles()
305 void MainWindow::activateDialog(EmuFrontDialog* dia) const
309 dia->activateWindow();
312 void MainWindow::createMenus()
314 fileMenu = menuBar()->addMenu(tr("&File"));
315 fileMenu->addAction(resetDbAction);
316 fileMenu->addSeparator();
317 fileMenu->addAction(exitAction);
319 configMenu = menuBar()->addMenu(tr("&Config"));
320 configMenu->addAction(configTmpDirAction);
321 configMenu->addSeparator();
323 //configMenu->addAction(configPlatformAction);
324 configMenu->addAction(configPlatformsAction);
326 //configMenu->addAction(configMediaTypeAction);
327 configMenu->addAction(configMediaTypesAction);
329 //configMenu->addAction(configSetupAction);
330 configMenu->addAction(configSetupsAction);
332 //configMenu->addAction(configMediaImagePathAction);
333 configMenu->addAction(configMediaImagePathsAction);
335 //configMenu->addAction(configEmulatorAction);
336 configMenu->addAction(configEmulatorsAction);
337 configMenu->addSeparator();
338 configMenu->addAction(manageDatFilesAction);
340 helpMenu = menuBar()->addMenu(tr("&Help"));
341 helpMenu->addAction(aboutAction);
344 void MainWindow::createStatusBar()
346 messageLabel = new QLabel;
347 statusBar()->addWidget(messageLabel);
350 void MainWindow::readSettings()
354 void MainWindow::writeSettings()
358 void MainWindow::closeEvent(QCloseEvent *event)
362 else event->ignore();
365 bool MainWindow::okToContinue()
370 void MainWindow::updateData()
372 qDebug() << "MainWindow::updateData()";
373 launcher->updateData();
376 void MainWindow::about()
378 QMessageBox::about(this, aboutTitle, aboutStr);
381 bool MainWindow::testDB(bool reset)
384 if (DatabaseManager::openDB()) {
385 qDebug() << " Database opened succesfully!";
388 throw EmuFrontException("Database connection failed!");
391 int dbVer = DbCreator::dbExists();
392 if (dbVer == 0) reset = true;
393 if (!reset && dbVer != DbCreator::DB_VERSION) {
394 QString msg("Database is not compatible "
395 "with current version of EmuFront!"
396 "Do you want to continue to recreate the database?"
397 "ALL THE CURRENT DATA WILL BE LOST!!!");
398 if (QMessageBox::question(this, "Database not compatible!", msg,
399 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
402 else throw EmuFrontException("The current database is not compatible!"
403 " Cannot continue.");
411 catch (EmuFrontException e) {
412 qDebug() << e.what();
413 errorMessage->showMessage(e.what());
418 void MainWindow::createDB() const
423 dbCreator.createDB();
425 catch (QString str) {
426 QString msg(tr("Exception while trying to create"
427 " EmuFront database: %s").arg(str));
428 errorMessage->showMessage(msg);