f5bbfb178a6ebc7e5f6bea5ed0c961e47af938c1
[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
30 MainWindow::MainWindow()
31 {
32     setWindowTitle("EmuFront");
33     launcher = new EmuLauncher(this);
34     setCentralWidget(launcher);
35     createActions();
36     createMenus();
37     createStatusBar();
38     readSettings();
39     platformDialog = 0;
40     mediaTypeDialog = 0;
41     mediaImagePathDialog = 0;
42     setupMainDialog = 0;
43     executableMainDialog = 0;
44     connectSignals();
45 }
46
47 void MainWindow::connectSignals()
48 {
49 }
50
51 void MainWindow::createActions()
52 {
53     configPlatformAction = new QAction(tr("&Platforms"), this);
54     configPlatformAction->setStatusTip(tr("Configure platforms"));
55     connect(configPlatformAction, SIGNAL(triggered()),
56             this, SLOT(configurePlatforms()));
57
58     configMediaTypeAction = new QAction(tr("&Media Types"), this);
59     configMediaTypeAction->setStatusTip(tr("Configure media types"));
60     connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));
61
62     configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
63     configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
64     connect(configMediaImagePathAction, SIGNAL(triggered()),
65         this, SLOT(configureMediaImagePaths()));
66
67     configSetupAction = new QAction(tr("S&etups"), this);
68     configSetupAction->setStatusTip(tr("Configure set ups"));
69     connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
70
71     configEmulatorAction = new QAction(tr("Em&ulators"), this);
72     configEmulatorAction->setStatusTip(tr("Configure emulators"));
73     connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));
74
75     exitAction = new QAction(tr("&Exit"), this);
76     exitAction->setShortcut(tr("Ctrl+Q"));
77     exitAction->setStatusTip(tr("Exit EmuFront"));
78     connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
79
80     aboutAction = new QAction(tr("&About"), this);
81     aboutAction->setStatusTip(tr("About EmuFront"));
82     connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
83 }
84
85 void MainWindow::configurePlatforms()
86 {
87    if (!platformDialog)
88    {
89        platformDialog = new PlatformDialog(this);
90        connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
91    }
92    activateDialog(platformDialog);
93 }
94
95 void MainWindow::configureMediaTypes()
96 {
97     if (!mediaTypeDialog)
98     {
99         mediaTypeDialog = new MediaTypeDialog(this);
100         connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
101    }
102    activateDialog(mediaTypeDialog);
103 }
104
105 void MainWindow::configureMediaImagePaths()
106 {
107     if (!mediaImagePathDialog)
108     {
109         mediaImagePathDialog = new MediaImagePathMainDialog(this);
110     }
111     activateDialog(mediaImagePathDialog);
112 }
113
114 void MainWindow::configureSetups()
115 {
116     if (!setupMainDialog)
117     {
118         qDebug() << "MainWindow: Creating a setup main dialog.";
119         setupMainDialog = new SetupMainDialog(this);
120     }
121     activateDialog(setupMainDialog);
122     setupMainDialog->refreshDataModel();
123 }
124
125 void MainWindow::configureEmulators()
126 {
127     if (!executableMainDialog) {
128         executableMainDialog = new ExecutableMainDialog(this);
129         connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
130     }
131     activateDialog(executableMainDialog);
132     executableMainDialog->refreshDataModel();
133 }
134
135 void MainWindow::activateDialog(EmuFrontDialog* dia) const
136 {
137     dia->show();
138     dia->raise();
139     dia->activateWindow();
140 }
141
142 void MainWindow::createMenus()
143 {
144     fileMenu = menuBar()->addMenu(tr("&File"));
145     fileMenu->addAction(exitAction);
146
147     configMenu = menuBar()->addMenu(tr("&Config"));
148     configMenu->addAction(configPlatformAction);
149     configMenu->addAction(configMediaTypeAction);
150     configMenu->addAction(configMediaImagePathAction);
151     configMenu->addAction(configSetupAction);
152     configMenu->addAction(configEmulatorAction);
153
154     helpMenu = menuBar()->addMenu(tr("&Help"));
155     helpMenu->addAction(aboutAction);
156 }
157
158 void MainWindow::createStatusBar()
159 {
160     messageLabel = new QLabel;
161     statusBar()->addWidget(messageLabel);
162 }
163
164 void MainWindow::readSettings()
165 {
166 }
167
168 void MainWindow::writeSettings()
169 {
170 }
171
172 void MainWindow::closeEvent(QCloseEvent *event)
173 {
174     if (okToContinue())
175         event->accept();
176     else event->ignore();
177 }
178
179 bool MainWindow::okToContinue()
180 {
181     return true;
182 }
183
184 void MainWindow::updateData()
185 {
186     qDebug() << "MainWindow::updateData()";
187     launcher->updateData();
188 }
189
190 void MainWindow::about()
191 {
192     QMessageBox::about(this, tr("About EmuFront"),
193         "<h2>EmuFront</h2>"
194         "<p>&copy; 2010 Mikko Keinänen</p>"
195         "<p>EmuFront is free software: you can redistribute it and/or modify "
196         "it under the terms of the GNU General Public License version 2 as published by "
197         "the Free Software Foundation.</p>"
198         );
199 }