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