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 MainWindow::MainWindow()
33 setWindowTitle("EmuFront");
34 tmpDirFilePath = DbConfig::getTmpDir();
35 if (tmpDirFilePath.isEmpty())
36 tmpDirFilePath = QDir::homePath();
37 qDebug() << "Temporary dir is " << tmpDirFilePath;
38 launcher = new EmuLauncher(this, tmpDirFilePath);
39 setCentralWidget(launcher);
46 mediaImagePathDialog = 0;
48 executableMainDialog = 0;
51 void MainWindow::connectSignals()
55 void MainWindow::createActions()
57 configPlatformAction = new QAction(tr("&Platforms"), this);
58 configPlatformAction->setStatusTip(tr("Configure platforms"));
59 connect(configPlatformAction, SIGNAL(triggered()),
60 this, SLOT(configurePlatforms()));
62 configMediaTypeAction = new QAction(tr("&Media Types"), this);
63 configMediaTypeAction->setStatusTip(tr("Configure media types"));
64 connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));
66 configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
67 configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
68 connect(configMediaImagePathAction, SIGNAL(triggered()),
69 this, SLOT(configureMediaImagePaths()));
71 configSetupAction = new QAction(tr("S&etups"), this);
72 configSetupAction->setStatusTip(tr("Configure set ups"));
73 connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
75 configEmulatorAction = new QAction(tr("Em&ulators"), this);
76 configEmulatorAction->setStatusTip(tr("Configure emulators"));
77 connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));
79 configTmpDirAction = new QAction(tr("&Temp dir"), this);
80 configTmpDirAction->setStatusTip(tr("Configure directory for temporary files."));
81 connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir()));
83 exitAction = new QAction(tr("&Exit"), this);
84 exitAction->setShortcut(tr("Ctrl+Q"));
85 exitAction->setStatusTip(tr("Exit EmuFront"));
86 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
88 aboutAction = new QAction(tr("&About"), this);
89 aboutAction->setStatusTip(tr("About EmuFront"));
90 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
93 void MainWindow::configurePlatforms()
97 platformDialog = new PlatformDialog(this);
98 connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
100 activateDialog(platformDialog);
103 void MainWindow::configureMediaTypes()
105 if (!mediaTypeDialog)
107 mediaTypeDialog = new MediaTypeDialog(this);
108 connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
110 activateDialog(mediaTypeDialog);
113 void MainWindow::configureMediaImagePaths()
115 if (!mediaImagePathDialog)
117 mediaImagePathDialog = new MediaImagePathMainDialog(this);
119 activateDialog(mediaImagePathDialog);
122 void MainWindow::configureSetups()
124 if (!setupMainDialog)
126 qDebug() << "MainWindow: Creating a setup main dialog.";
127 setupMainDialog = new SetupMainDialog(this);
129 activateDialog(setupMainDialog);
130 setupMainDialog->refreshDataModel();
133 void MainWindow::configureEmulators()
135 if (!executableMainDialog) {
136 executableMainDialog = new ExecutableMainDialog(this);
137 connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
139 activateDialog(executableMainDialog);
140 executableMainDialog->refreshDataModel();
143 void MainWindow::configureTmpDir()
145 /*if (!tmpFolderDialog) {
146 tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath);
148 activateDialog(tmpFolderDialog);*/
150 QString fpath = QFileDialog::getExistingDirectory(this,
151 tr("Select a directory"), tmpDirFilePath,
152 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
154 if (d.exists() && d.isReadable()) {
155 tmpDirFilePath = fpath;
156 DbConfig::setTmpDir(tmpDirFilePath);
157 launcher->setTmpDirPath(tmpDirFilePath);
161 void MainWindow::activateDialog(EmuFrontDialog* dia) const
165 dia->activateWindow();
168 void MainWindow::createMenus()
170 fileMenu = menuBar()->addMenu(tr("&File"));
171 fileMenu->addAction(exitAction);
173 configMenu = menuBar()->addMenu(tr("&Config"));
174 configMenu->addAction(configPlatformAction);
175 configMenu->addAction(configMediaTypeAction);
176 configMenu->addAction(configMediaImagePathAction);
177 configMenu->addAction(configSetupAction);
178 configMenu->addAction(configEmulatorAction);
179 configMenu->addAction(configTmpDirAction);
181 helpMenu = menuBar()->addMenu(tr("&Help"));
182 helpMenu->addAction(aboutAction);
185 void MainWindow::createStatusBar()
187 messageLabel = new QLabel;
188 statusBar()->addWidget(messageLabel);
191 void MainWindow::readSettings()
195 void MainWindow::writeSettings()
199 void MainWindow::closeEvent(QCloseEvent *event)
203 else event->ignore();
206 bool MainWindow::okToContinue()
211 void MainWindow::updateData()
213 qDebug() << "MainWindow::updateData()";
214 launcher->updateData();
217 void MainWindow::about()
219 QMessageBox::about(this, tr("About EmuFront"),
221 "<p>© 2010 Mikko Keinänen</p>"
222 "<p>EmuFront is free software: you can redistribute it and/or modify "
223 "it under the terms of the GNU General Public License version 2 as published by "
224 "the Free Software Foundation.</p>"