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