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::tempPath();
37 launcher = new EmuLauncher(this, tmpDirFilePath);
38 setCentralWidget(launcher);
45 mediaImagePathDialog = 0;
47 executableMainDialog = 0;
50 void MainWindow::connectSignals()
54 void MainWindow::createActions()
56 configPlatformAction = new QAction(tr("&Platforms"), this);
57 configPlatformAction->setStatusTip(tr("Configure platforms"));
58 connect(configPlatformAction, SIGNAL(triggered()),
59 this, SLOT(configurePlatforms()));
61 configMediaTypeAction = new QAction(tr("&Media Types"), this);
62 configMediaTypeAction->setStatusTip(tr("Configure media types"));
63 connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));
65 configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
66 configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
67 connect(configMediaImagePathAction, SIGNAL(triggered()),
68 this, SLOT(configureMediaImagePaths()));
70 configSetupAction = new QAction(tr("S&etups"), this);
71 configSetupAction->setStatusTip(tr("Configure set ups"));
72 connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
74 configEmulatorAction = new QAction(tr("Em&ulators"), this);
75 configEmulatorAction->setStatusTip(tr("Configure emulators"));
76 connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));
78 configTmpDirAction = new QAction(tr("&Temp dir"), this);
79 configTmpDirAction->setStatusTip(tr("Configure directory for temporary files."));
80 connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir()));
82 exitAction = new QAction(tr("&Exit"), this);
83 exitAction->setShortcut(tr("Ctrl+Q"));
84 exitAction->setStatusTip(tr("Exit EmuFront"));
85 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
87 aboutAction = new QAction(tr("&About"), this);
88 aboutAction->setStatusTip(tr("About EmuFront"));
89 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
92 void MainWindow::configurePlatforms()
96 platformDialog = new PlatformDialog(this);
97 connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
99 activateDialog(platformDialog);
102 void MainWindow::configureMediaTypes()
104 if (!mediaTypeDialog)
106 mediaTypeDialog = new MediaTypeDialog(this);
107 connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
109 activateDialog(mediaTypeDialog);
112 void MainWindow::configureMediaImagePaths()
114 if (!mediaImagePathDialog)
116 mediaImagePathDialog = new MediaImagePathMainDialog(this);
118 activateDialog(mediaImagePathDialog);
121 void MainWindow::configureSetups()
123 if (!setupMainDialog)
125 qDebug() << "MainWindow: Creating a setup main dialog.";
126 setupMainDialog = new SetupMainDialog(this);
128 activateDialog(setupMainDialog);
129 setupMainDialog->refreshDataModel();
132 void MainWindow::configureEmulators()
134 if (!executableMainDialog) {
135 executableMainDialog = new ExecutableMainDialog(this);
136 connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
138 activateDialog(executableMainDialog);
139 executableMainDialog->refreshDataModel();
142 void MainWindow::configureTmpDir()
144 /*if (!tmpFolderDialog) {
145 tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath);
147 activateDialog(tmpFolderDialog);*/
149 QString fpath = QFileDialog::getExistingDirectory(this,
150 tr("Select a directory"), tmpDirFilePath,
151 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
153 if (d.exists() && d.isReadable()) {
154 tmpDirFilePath = fpath;
155 DbConfig::setTmpDir(tmpDirFilePath);
156 launcher->setTmpDirPath(tmpDirFilePath);
160 void MainWindow::activateDialog(EmuFrontDialog* dia) const
164 dia->activateWindow();
167 void MainWindow::createMenus()
169 fileMenu = menuBar()->addMenu(tr("&File"));
170 fileMenu->addAction(exitAction);
172 configMenu = menuBar()->addMenu(tr("&Config"));
173 configMenu->addAction(configPlatformAction);
174 configMenu->addAction(configMediaTypeAction);
175 configMenu->addAction(configMediaImagePathAction);
176 configMenu->addAction(configSetupAction);
177 configMenu->addAction(configEmulatorAction);
178 configMenu->addAction(configTmpDirAction);
180 helpMenu = menuBar()->addMenu(tr("&Help"));
181 helpMenu->addAction(aboutAction);
184 void MainWindow::createStatusBar()
186 messageLabel = new QLabel;
187 statusBar()->addWidget(messageLabel);
190 void MainWindow::readSettings()
194 void MainWindow::writeSettings()
198 void MainWindow::closeEvent(QCloseEvent *event)
202 else event->ignore();
205 bool MainWindow::okToContinue()
210 void MainWindow::updateData()
212 qDebug() << "MainWindow::updateData()";
213 launcher->updateData();
216 void MainWindow::about()
218 QMessageBox::about(this, tr("About EmuFront"),
220 "<p>© 2010 Mikko Keinänen</p>"
221 "<p>EmuFront is free software: you can redistribute it and/or modify "
222 "it under the terms of the GNU General Public License version 2 as published by "
223 "the Free Software Foundation.</p>"