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