Implemented Executable editor (for configurating emulators).
[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 as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
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 }
45
46 void MainWindow::createActions()
47 {
48     configPlatformAction = new QAction(tr("&Platforms"), this);
49     configPlatformAction->setStatusTip(tr("Configure platforms"));
50     connect(configPlatformAction, SIGNAL(triggered()),
51             this, SLOT(configurePlatforms()));
52
53     configMediaTypeAction = new QAction(tr("&Media Types"), this);
54     configMediaTypeAction->setStatusTip(tr("Configure media types"));
55     connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));
56
57     configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
58     configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
59     connect(configMediaImagePathAction, SIGNAL(triggered()),
60         this, SLOT(configureMediaImagePaths()));
61
62     configSetupAction = new QAction(tr("S&etups"), this);
63     configSetupAction->setStatusTip(tr("Configure set ups"));
64     connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
65
66     configEmulatorAction = new QAction(tr("Em&ulators"), this);
67     configEmulatorAction->setStatusTip(tr("Configure emulators"));
68     connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));
69
70     exitAction = new QAction(tr("&Exit"), this);
71     exitAction->setShortcut(tr("Ctrl+Q"));
72     exitAction->setStatusTip(tr("Exit EmuFront"));
73     connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
74 }
75
76 void MainWindow::configurePlatforms()
77 {
78    if (!platformDialog)
79    {
80        platformDialog = new PlatformDialog(this);
81    } 
82    activateDialog(platformDialog);
83 }
84
85 void MainWindow::configureMediaTypes()
86 {
87     if (!mediaTypeDialog)
88     {
89         mediaTypeDialog = new MediaTypeDialog(this);
90    }
91    activateDialog(mediaTypeDialog);
92 }
93
94 void MainWindow::configureMediaImagePaths()
95 {
96     if (!mediaImagePathDialog)
97     {
98         mediaImagePathDialog = new MediaImagePathMainDialog(this);
99     }
100     activateDialog(mediaImagePathDialog);
101 }
102
103 void MainWindow::configureSetups()
104 {
105     if (!setupMainDialog)
106     {
107         qDebug() << "MainWindow: Creating a setup main dialog.";
108         setupMainDialog = new SetupMainDialog(this);
109     }
110     activateDialog(setupMainDialog);
111     setupMainDialog->refreshDataModel();
112 }
113
114 void MainWindow::configureEmulators()
115 {
116     if (!executableMainDialog) {
117         executableMainDialog = new ExecutableMainDialog(this);
118     }
119     activateDialog(executableMainDialog);
120     executableMainDialog->refreshDataModel();
121 }
122
123 void MainWindow::activateDialog(EmuFrontDialog* dia) const
124 {
125     dia->show();
126     dia->raise();
127     dia->activateWindow();
128 }
129
130 void MainWindow::createMenus()
131 {
132     fileMenu = menuBar()->addMenu(tr("&File"));
133     fileMenu->addAction(exitAction);
134
135     configMenu = menuBar()->addMenu(tr("&Config"));
136     configMenu->addAction(configPlatformAction);
137     configMenu->addAction(configMediaTypeAction);
138     configMenu->addAction(configMediaImagePathAction);
139     configMenu->addAction(configSetupAction);
140     configMenu->addAction(configEmulatorAction);
141 }
142
143 void MainWindow::createStatusBar()
144 {
145     messageLabel = new QLabel;
146     statusBar()->addWidget(messageLabel);
147 }
148
149 void MainWindow::readSettings()
150 {
151 }
152
153 void MainWindow::writeSettings()
154 {
155 }
156
157 void MainWindow::closeEvent(QCloseEvent *event)
158 {
159     if (okToContinue())
160         event->accept();
161     else event->ignore();
162 }
163
164 bool MainWindow::okToContinue()
165 {
166     return true;
167 }