Removed include for non-existing header
[emufront] / src / mainwindow.cpp
1 // EmuFront
2 // Copyright 2010 Mikko Keinänen
3 //
4 // This file is part of EmuFront.
5 //
6 //
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.
11 //
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.
16 //
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/>.
19
20 #include <QtGui>
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"
30
31 MainWindow::MainWindow()
32 {
33     setWindowTitle("EmuFront");
34     tmpDirFilePath = DbConfig::getTmpDir();
35     if (tmpDirFilePath.isEmpty())
36         tmpDirFilePath = QDir::tempPath();
37     launcher = new EmuLauncher(this, tmpDirFilePath);
38     setCentralWidget(launcher);
39     createActions();
40     createMenus();
41     createStatusBar();
42     readSettings();
43     platformDialog = 0;
44     mediaTypeDialog = 0;
45     mediaImagePathDialog = 0;
46     setupMainDialog = 0;
47     executableMainDialog = 0;
48 }
49
50 void MainWindow::connectSignals()
51 {
52 }
53
54 void MainWindow::createActions()
55 {
56     configPlatformAction = new QAction(tr("&Platforms"), this);
57     configPlatformAction->setStatusTip(tr("Configure platforms"));
58     connect(configPlatformAction, SIGNAL(triggered()),
59             this, SLOT(configurePlatforms()));
60
61     configMediaTypeAction = new QAction(tr("&Media Types"), this);
62     configMediaTypeAction->setStatusTip(tr("Configure media types"));
63     connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));
64
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()));
69
70     configSetupAction = new QAction(tr("S&etups"), this);
71     configSetupAction->setStatusTip(tr("Configure set ups"));
72     connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
73
74     configEmulatorAction = new QAction(tr("Em&ulators"), this);
75     configEmulatorAction->setStatusTip(tr("Configure emulators"));
76     connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));
77
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()));
81
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()));
86
87     aboutAction = new QAction(tr("&About"), this);
88     aboutAction->setStatusTip(tr("About EmuFront"));
89     connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
90 }
91
92 void MainWindow::configurePlatforms()
93 {
94    if (!platformDialog)
95    {
96        platformDialog = new PlatformDialog(this);
97        connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
98    }
99    activateDialog(platformDialog);
100 }
101
102 void MainWindow::configureMediaTypes()
103 {
104     if (!mediaTypeDialog)
105     {
106         mediaTypeDialog = new MediaTypeDialog(this);
107         connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
108    }
109    activateDialog(mediaTypeDialog);
110 }
111
112 void MainWindow::configureMediaImagePaths()
113 {
114     if (!mediaImagePathDialog)
115     {
116         mediaImagePathDialog = new MediaImagePathMainDialog(this);
117     }
118     activateDialog(mediaImagePathDialog);
119 }
120
121 void MainWindow::configureSetups()
122 {
123     if (!setupMainDialog)
124     {
125         qDebug() << "MainWindow: Creating a setup main dialog.";
126         setupMainDialog = new SetupMainDialog(this);
127     }
128     activateDialog(setupMainDialog);
129     setupMainDialog->refreshDataModel();
130 }
131
132 void MainWindow::configureEmulators()
133 {
134     if (!executableMainDialog) {
135         executableMainDialog = new ExecutableMainDialog(this);
136         connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
137     }
138     activateDialog(executableMainDialog);
139     executableMainDialog->refreshDataModel();
140 }
141
142 void MainWindow::configureTmpDir()
143 {
144     /*if (!tmpFolderDialog) {
145         tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath);
146     }
147     activateDialog(tmpFolderDialog);*/
148
149     QString fpath = QFileDialog::getExistingDirectory(this,
150         tr("Select a directory"), tmpDirFilePath,
151         QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
152     QDir d(fpath);
153     if (d.exists() && d.isReadable()) {
154         tmpDirFilePath = fpath;
155         DbConfig::setTmpDir(tmpDirFilePath);
156         launcher->setTmpDirPath(tmpDirFilePath);
157     }
158 }
159
160 void MainWindow::activateDialog(EmuFrontDialog* dia) const
161 {
162     dia->show();
163     dia->raise();
164     dia->activateWindow();
165 }
166
167 void MainWindow::createMenus()
168 {
169     fileMenu = menuBar()->addMenu(tr("&File"));
170     fileMenu->addAction(exitAction);
171
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);
179
180     helpMenu = menuBar()->addMenu(tr("&Help"));
181     helpMenu->addAction(aboutAction);
182 }
183
184 void MainWindow::createStatusBar()
185 {
186     messageLabel = new QLabel;
187     statusBar()->addWidget(messageLabel);
188 }
189
190 void MainWindow::readSettings()
191 {
192 }
193
194 void MainWindow::writeSettings()
195 {
196 }
197
198 void MainWindow::closeEvent(QCloseEvent *event)
199 {
200     if (okToContinue())
201         event->accept();
202     else event->ignore();
203 }
204
205 bool MainWindow::okToContinue()
206 {
207     return true;
208 }
209
210 void MainWindow::updateData()
211 {
212     qDebug() << "MainWindow::updateData()";
213     launcher->updateData();
214 }
215
216 void MainWindow::about()
217 {
218     QMessageBox::about(this, tr("About EmuFront"),
219         "<h2>EmuFront</h2>"
220         "<p>&copy; 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>"
224         );
225 }