Initial implementation of setup editor. Some refactoring and bug hunting
[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 // Foobar 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
19
20 #include <QtGui>
21 #include "mainwindow.h"
22 #include "dialogs/platformdialog.h"
23 #include "dialogs/mediatypedialog.h"
24 #include "dialogs/mediaimagepathmaindialog.h"
25 #include "dialogs/setupmaindialog.h"
26 #include "db/databasemanager.h"
27
28 MainWindow::MainWindow()
29 {
30     setWindowTitle("EmuFront");
31     createActions();
32     createMenus();
33     createStatusBar();
34     readSettings();
35     platformDialog = 0;
36     mediaTypeDialog = 0;
37     mediaImagePathDialog = 0;
38     setupMainDialog = 0;
39 }
40
41 void MainWindow::createActions()
42 {
43     configPlatformAction = new QAction(tr("&Platforms"), this);
44     configPlatformAction->setStatusTip(tr("Configure platforms"));
45     connect(configPlatformAction, SIGNAL(triggered()),
46             this, SLOT(configurePlatforms()));
47
48     configMediaTypeAction = new QAction(tr("&Media Types"), this);
49     configMediaTypeAction->setStatusTip(tr("Configure media types"));
50     connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));
51
52     configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
53     configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
54     connect(configMediaImagePathAction, SIGNAL(triggered()),
55         this, SLOT(configureMediaImagePaths()));
56
57     configSetupAction = new QAction(tr("S&etups"), this);
58     configSetupAction->setStatusTip(tr("Configure set ups"));
59     connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
60
61     exitAction = new QAction(tr("&Exit"), this);
62     exitAction->setShortcut(tr("Ctrl+Q"));
63     exitAction->setStatusTip(tr("Exit EmuFront"));
64     connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
65 }
66
67 void MainWindow::configurePlatforms()
68 {
69    if (!platformDialog)
70    {
71        platformDialog = new PlatformDialog(this);
72    } 
73    activateDialog(platformDialog);
74 }
75
76 void MainWindow::configureMediaTypes()
77 {
78     if (!mediaTypeDialog)
79     {
80         mediaTypeDialog = new MediaTypeDialog(this);
81    }
82    activateDialog(mediaTypeDialog);
83 }
84
85 void MainWindow::configureMediaImagePaths()
86 {
87     if (!mediaImagePathDialog)
88     {
89         mediaImagePathDialog = new MediaImagePathMainDialog(this);
90     }
91     activateDialog(mediaImagePathDialog);
92 }
93
94 void MainWindow::configureSetups()
95 {
96     if (!setupMainDialog)
97     {
98         qDebug() << "MainWindow: Creating a setup main dialog.";
99         setupMainDialog = new SetupMainDialog(this);
100     }
101     activateDialog(setupMainDialog);
102 }
103
104 void MainWindow::activateDialog(EmuFrontDialog* dia) const
105 {
106     dia->show();
107     dia->raise();
108     dia->activateWindow();
109 }
110
111 void MainWindow::createMenus()
112 {
113     fileMenu = menuBar()->addMenu(tr("&File"));
114     fileMenu->addAction(exitAction);
115
116     configMenu = menuBar()->addMenu(tr("&Config"));
117     configMenu->addAction(configPlatformAction);
118     configMenu->addAction(configMediaTypeAction);
119     configMenu->addAction(configMediaImagePathAction);
120     configMenu->addAction(configSetupAction);
121 }
122
123 void MainWindow::createStatusBar()
124 {
125     messageLabel = new QLabel;
126     statusBar()->addWidget(messageLabel);
127 }
128
129 void MainWindow::readSettings()
130 {
131 }
132
133 void MainWindow::writeSettings()
134 {
135 }
136
137 void MainWindow::closeEvent(QCloseEvent *event)
138 {
139     if (okToContinue())
140         event->accept();
141     else event->ignore();
142 }
143
144 bool MainWindow::okToContinue()
145 {
146     return true;
147 }