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 "utils/datfileutil.h"
29 #include "db/databasemanager.h"
30 #include "db/dbconfig.h"
32 QString MainWindow::aboutStr = trUtf8(
34 "<p>© 2010 Mikko Keinänen</p>"
35 "<p>mikko.keinanen@gmail.com</p>"
36 "<p>EmuFront is free software: you can redistribute it and/or modify "
37 "it under the terms of the GNU General Public License version 2 as published by "
38 "the Free Software Foundation.</p>"
41 QString MainWindow::aboutTitle = tr("About EmuFront");
43 MainWindow::MainWindow()
45 setWindowTitle("EmuFront");
46 tmpDirFilePath = DbConfig::getTmpDir();
47 if (tmpDirFilePath.isEmpty())
48 tmpDirFilePath = QDir::homePath();
49 qDebug() << "Temporary dir is " << tmpDirFilePath;
50 launcher = new EmuLauncher(this, tmpDirFilePath);
51 setCentralWidget(launcher);
58 mediaImagePathDialog = 0;
60 executableMainDialog = 0;
63 void MainWindow::connectSignals()
67 void MainWindow::createActions()
69 configPlatformAction = new QAction(tr("&Platforms"), this);
70 configPlatformAction->setStatusTip(tr("Configure platforms"));
71 connect(configPlatformAction, SIGNAL(triggered()),
72 this, SLOT(configurePlatforms()));
74 configMediaTypeAction = new QAction(tr("&Media Types"), this);
75 configMediaTypeAction->setStatusTip(tr("Configure media types"));
76 connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));
78 configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
79 configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
80 connect(configMediaImagePathAction, SIGNAL(triggered()),
81 this, SLOT(configureMediaImagePaths()));
83 configSetupAction = new QAction(tr("S&etups"), this);
84 configSetupAction->setStatusTip(tr("Configure set ups"));
85 connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
87 configEmulatorAction = new QAction(tr("Em&ulators"), this);
88 configEmulatorAction->setStatusTip(tr("Configure emulators"));
89 connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));
91 configTmpDirAction = new QAction(tr("&Temp dir"), this);
92 configTmpDirAction->setStatusTip(tr("Configure directory for temporary files."));
93 connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir()));
95 manageDatFilesAction = new QAction(tr("&Manage dats"), this);
96 manageDatFilesAction->setStatusTip(tr("Read dat files to database."));
97 connect(manageDatFilesAction, SIGNAL(triggered()), this, SLOT(manageDatFiles()));
99 exitAction = new QAction(tr("&Exit"), this);
100 exitAction->setShortcut(tr("Ctrl+Q"));
101 exitAction->setStatusTip(tr("Exit EmuFront"));
102 connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
104 aboutAction = new QAction(tr("&About"), this);
105 aboutAction->setStatusTip(tr("About EmuFront"));
106 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
109 void MainWindow::configurePlatforms()
113 platformDialog = new PlatformDialog(this);
114 connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
116 activateDialog(platformDialog);
119 void MainWindow::configureMediaTypes()
121 if (!mediaTypeDialog)
123 mediaTypeDialog = new MediaTypeDialog(this);
124 connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
126 activateDialog(mediaTypeDialog);
129 void MainWindow::configureMediaImagePaths()
131 if (!mediaImagePathDialog)
133 mediaImagePathDialog = new MediaImagePathMainDialog(this);
135 activateDialog(mediaImagePathDialog);
138 void MainWindow::configureSetups()
140 if (!setupMainDialog)
142 qDebug() << "MainWindow: Creating a setup main dialog.";
143 setupMainDialog = new SetupMainDialog(this);
145 activateDialog(setupMainDialog);
146 setupMainDialog->refreshDataModel();
149 void MainWindow::configureEmulators()
151 if (!executableMainDialog) {
152 executableMainDialog = new ExecutableMainDialog(this);
153 connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
155 activateDialog(executableMainDialog);
156 executableMainDialog->refreshDataModel();
159 void MainWindow::configureTmpDir()
161 /*if (!tmpFolderDialog) {
162 tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath);
164 activateDialog(tmpFolderDialog);*/
166 QString fpath = QFileDialog::getExistingDirectory(this,
167 tr("Select a directory"), tmpDirFilePath,
168 QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
170 if (d.exists() && d.isReadable()) {
171 tmpDirFilePath = fpath;
172 DbConfig::setTmpDir(tmpDirFilePath);
173 launcher->setTmpDirPath(tmpDirFilePath);
177 void MainWindow::manageDatFiles()
183 void MainWindow::activateDialog(EmuFrontDialog* dia) const
187 dia->activateWindow();
190 void MainWindow::createMenus()
192 fileMenu = menuBar()->addMenu(tr("&File"));
193 fileMenu->addAction(exitAction);
195 configMenu = menuBar()->addMenu(tr("&Config"));
196 configMenu->addAction(configTmpDirAction);
197 configMenu->addSeparator();
198 configMenu->addAction(configPlatformAction);
199 configMenu->addAction(configMediaTypeAction);
200 configMenu->addAction(configSetupAction);
201 configMenu->addAction(configMediaImagePathAction);
202 configMenu->addAction(configEmulatorAction);
203 configMenu->addSeparator();
204 configMenu->addAction(manageDatFilesAction);
206 helpMenu = menuBar()->addMenu(tr("&Help"));
207 helpMenu->addAction(aboutAction);
210 void MainWindow::createStatusBar()
212 messageLabel = new QLabel;
213 statusBar()->addWidget(messageLabel);
216 void MainWindow::readSettings()
220 void MainWindow::writeSettings()
224 void MainWindow::closeEvent(QCloseEvent *event)
228 else event->ignore();
231 bool MainWindow::okToContinue()
236 void MainWindow::updateData()
238 qDebug() << "MainWindow::updateData()";
239 launcher->updateData();
242 void MainWindow::about()
244 QMessageBox::about(this, aboutTitle, aboutStr );