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