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