2 // Copyright 2010 Mikko Keinänen
4 // This file is part of EmuFront.
7 // EmuFront is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2 as published by
9 // the Free Software Foundation and appearing in the file gpl.txt included in the
10 // packaging of this file.
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.
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/>.
21 #include "mainwindow.h"
22 #include "emulauncher.h"
23 #include "dialogs/platformdialog.h"
24 #include "dialogs/mediatypedialog.h"
25 #include "dialogs/mediaimagepathmaindialog.h"
26 #include "dialogs/setupmaindialog.h"
27 #include "dialogs/executablemaindialog.h"
28 #include "db/databasemanager.h"
29 #include "db/dbconfig.h"
31 QString MainWindow::aboutStr = tr(
33 "<p>© 2010 Mikko Keinänen</p>"
34 "<p>mikko.keinanen@gmail.com</p>"
35 "<p>EmuFront is free software: you can redistribute it and/or modify "
36 "it under the terms of the GNU General Public License version 2 as published by "
37 "the Free Software Foundation.</p>"
40 QString MainWindow::aboutTitle = tr("About EmuFront");
42 MainWindow::MainWindow()
44 setWindowTitle("EmuFront");
45 tmpDirFilePath = DbConfig::getTmpDir();
46 if (tmpDirFilePath.isEmpty())
47 tmpDirFilePath = QDir::homePath();
48 qDebug() << "Temporary dir is " << tmpDirFilePath;
49 launcher = new EmuLauncher(this, tmpDirFilePath);
50 setCentralWidget(launcher);
57 mediaImagePathDialog = 0;
59 executableMainDialog = 0;
62 void MainWindow::connectSignals()
66 void MainWindow::createActions()
68 configPlatformAction = new QAction(tr("&Platforms"), this);
69 configPlatformAction->setStatusTip(tr("Configure platforms"));
70 connect(configPlatformAction, SIGNAL(triggered()),
71 this, SLOT(configurePlatforms()));
73 configMediaTypeAction = new QAction(tr("&Media Types"), this);
74 configMediaTypeAction->setStatusTip(tr("Configure media types"));
75 connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));
77 configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
78 configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
79 connect(configMediaImagePathAction, SIGNAL(triggered()),
80 this, SLOT(configureMediaImagePaths()));
82 configSetupAction = new QAction(tr("S&etups"), this);
83 configSetupAction->setStatusTip(tr("Configure set ups"));
84 connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
86 configEmulatorAction = new QAction(tr("Em&ulators"), this);
87 configEmulatorAction->setStatusTip(tr("Configure emulators"));
88 connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));
90 configTmpDirAction = new QAction(tr("&Temp dir"), this);
91 configTmpDirAction->setStatusTip(tr("Configure directory for temporary files."));
92 connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir()));
94 exitAction = new QAction(tr("&Exit"), this);
95 exitAction->setShortcut(tr("Ctrl+Q"));
96 exitAction->setStatusTip(tr("Exit EmuFront"));
97 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
99 aboutAction = new QAction(tr("&About"), this);
100 aboutAction->setStatusTip(tr("About EmuFront"));
101 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
104 void MainWindow::configurePlatforms()
108 platformDialog = new PlatformDialog(this);
109 connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
111 activateDialog(platformDialog);
114 void MainWindow::configureMediaTypes()
116 if (!mediaTypeDialog)
118 mediaTypeDialog = new MediaTypeDialog(this);
119 connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
121 activateDialog(mediaTypeDialog);
124 void MainWindow::configureMediaImagePaths()
126 if (!mediaImagePathDialog)
128 mediaImagePathDialog = new MediaImagePathMainDialog(this);
130 activateDialog(mediaImagePathDialog);
133 void MainWindow::configureSetups()
135 if (!setupMainDialog)
137 qDebug() << "MainWindow: Creating a setup main dialog.";
138 setupMainDialog = new SetupMainDialog(this);
140 activateDialog(setupMainDialog);
141 setupMainDialog->refreshDataModel();
144 void MainWindow::configureEmulators()
146 if (!executableMainDialog) {
147 executableMainDialog = new ExecutableMainDialog(this);
148 connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
150 activateDialog(executableMainDialog);
151 executableMainDialog->refreshDataModel();
154 void MainWindow::configureTmpDir()
156 /*if (!tmpFolderDialog) {
157 tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath);
159 activateDialog(tmpFolderDialog);*/
161 QString fpath = QFileDialog::getExistingDirectory(this,
162 tr("Select a directory"), tmpDirFilePath,
163 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
165 if (d.exists() && d.isReadable()) {
166 tmpDirFilePath = fpath;
167 DbConfig::setTmpDir(tmpDirFilePath);
168 launcher->setTmpDirPath(tmpDirFilePath);
172 void MainWindow::activateDialog(EmuFrontDialog* dia) const
176 dia->activateWindow();
179 void MainWindow::createMenus()
181 fileMenu = menuBar()->addMenu(tr("&File"));
182 fileMenu->addAction(exitAction);
184 configMenu = menuBar()->addMenu(tr("&Config"));
185 configMenu->addAction(configPlatformAction);
186 configMenu->addAction(configMediaTypeAction);
187 configMenu->addAction(configMediaImagePathAction);
188 configMenu->addAction(configSetupAction);
189 configMenu->addAction(configEmulatorAction);
190 configMenu->addAction(configTmpDirAction);
192 helpMenu = menuBar()->addMenu(tr("&Help"));
193 helpMenu->addAction(aboutAction);
196 void MainWindow::createStatusBar()
198 messageLabel = new QLabel;
199 statusBar()->addWidget(messageLabel);
202 void MainWindow::readSettings()
206 void MainWindow::writeSettings()
210 void MainWindow::closeEvent(QCloseEvent *event)
214 else event->ignore();
217 bool MainWindow::okToContinue()
222 void MainWindow::updateData()
224 qDebug() << "MainWindow::updateData()";
225 launcher->updateData();
228 void MainWindow::about()
230 QMessageBox::about(this, aboutTitle, aboutStr );