About text updated.
[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 #include "db/dbconfig.h"
30
31 QString MainWindow::aboutStr = tr(
32         "<h2>EmuFront</h2>"
33         "<p>&copy; 2010 Mikko Keinänen</p>"
34         "<p>mikko.keinanen@gmail.com</p>"
35         "<p>EmuFront is free software: you can redistribute it and/or modify "
36         "it under the terms of the GNU General Public License version 2 as published by "
37         "the Free Software Foundation.</p>"
38 );
39
40 QString MainWindow::aboutTitle = tr("About EmuFront");
41
42 MainWindow::MainWindow()
43 {
44     setWindowTitle("EmuFront");
45     tmpDirFilePath = DbConfig::getTmpDir();
46     if (tmpDirFilePath.isEmpty())
47         tmpDirFilePath = QDir::homePath();
48     qDebug() << "Temporary dir is " << tmpDirFilePath;
49     launcher = new EmuLauncher(this, tmpDirFilePath);
50     setCentralWidget(launcher);
51     createActions();
52     createMenus();
53     createStatusBar();
54     readSettings();
55     platformDialog = 0;
56     mediaTypeDialog = 0;
57     mediaImagePathDialog = 0;
58     setupMainDialog = 0;
59     executableMainDialog = 0;
60 }
61
62 void MainWindow::connectSignals()
63 {
64 }
65
66 void MainWindow::createActions()
67 {
68     configPlatformAction = new QAction(tr("&Platforms"), this);
69     configPlatformAction->setStatusTip(tr("Configure platforms"));
70     connect(configPlatformAction, SIGNAL(triggered()),
71             this, SLOT(configurePlatforms()));
72
73     configMediaTypeAction = new QAction(tr("&Media Types"), this);
74     configMediaTypeAction->setStatusTip(tr("Configure media types"));
75     connect(configMediaTypeAction, SIGNAL(triggered()), this, SLOT(configureMediaTypes()));
76
77     configMediaImagePathAction = new QAction(tr("Media &Image Paths"), this);
78     configMediaImagePathAction->setStatusTip(tr("Configure media image file paths."));
79     connect(configMediaImagePathAction, SIGNAL(triggered()),
80         this, SLOT(configureMediaImagePaths()));
81
82     configSetupAction = new QAction(tr("S&etups"), this);
83     configSetupAction->setStatusTip(tr("Configure set ups"));
84     connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
85
86     configEmulatorAction = new QAction(tr("Em&ulators"), this);
87     configEmulatorAction->setStatusTip(tr("Configure emulators"));
88     connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));
89
90     configTmpDirAction = new QAction(tr("&Temp dir"), this);
91     configTmpDirAction->setStatusTip(tr("Configure directory for temporary files."));
92     connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir()));
93
94     exitAction = new QAction(tr("&Exit"), this);
95     exitAction->setShortcut(tr("Ctrl+Q"));
96     exitAction->setStatusTip(tr("Exit EmuFront"));
97     connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
98
99     aboutAction = new QAction(tr("&About"), this);
100     aboutAction->setStatusTip(tr("About EmuFront"));
101     connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
102 }
103
104 void MainWindow::configurePlatforms()
105 {
106    if (!platformDialog)
107    {
108        platformDialog = new PlatformDialog(this);
109        connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
110    }
111    activateDialog(platformDialog);
112 }
113
114 void MainWindow::configureMediaTypes()
115 {
116     if (!mediaTypeDialog)
117     {
118         mediaTypeDialog = new MediaTypeDialog(this);
119         connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
120    }
121    activateDialog(mediaTypeDialog);
122 }
123
124 void MainWindow::configureMediaImagePaths()
125 {
126     if (!mediaImagePathDialog)
127     {
128         mediaImagePathDialog = new MediaImagePathMainDialog(this);
129     }
130     activateDialog(mediaImagePathDialog);
131 }
132
133 void MainWindow::configureSetups()
134 {
135     if (!setupMainDialog)
136     {
137         qDebug() << "MainWindow: Creating a setup main dialog.";
138         setupMainDialog = new SetupMainDialog(this);
139     }
140     activateDialog(setupMainDialog);
141     setupMainDialog->refreshDataModel();
142 }
143
144 void MainWindow::configureEmulators()
145 {
146     if (!executableMainDialog) {
147         executableMainDialog = new ExecutableMainDialog(this);
148         connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
149     }
150     activateDialog(executableMainDialog);
151     executableMainDialog->refreshDataModel();
152 }
153
154 void MainWindow::configureTmpDir()
155 {
156     /*if (!tmpFolderDialog) {
157         tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath);
158     }
159     activateDialog(tmpFolderDialog);*/
160
161     QString fpath = QFileDialog::getExistingDirectory(this,
162         tr("Select a directory"), tmpDirFilePath,
163         QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
164     QDir d(fpath);
165     if (d.exists() && d.isReadable()) {
166         tmpDirFilePath = fpath;
167         DbConfig::setTmpDir(tmpDirFilePath);
168         launcher->setTmpDirPath(tmpDirFilePath);
169     }
170 }
171
172 void MainWindow::activateDialog(EmuFrontDialog* dia) const
173 {
174     dia->show();
175     dia->raise();
176     dia->activateWindow();
177 }
178
179 void MainWindow::createMenus()
180 {
181     fileMenu = menuBar()->addMenu(tr("&File"));
182     fileMenu->addAction(exitAction);
183
184     configMenu = menuBar()->addMenu(tr("&Config"));
185     configMenu->addAction(configPlatformAction);
186     configMenu->addAction(configMediaTypeAction);
187     configMenu->addAction(configMediaImagePathAction);
188     configMenu->addAction(configSetupAction);
189     configMenu->addAction(configEmulatorAction);
190     configMenu->addAction(configTmpDirAction);
191
192     helpMenu = menuBar()->addMenu(tr("&Help"));
193     helpMenu->addAction(aboutAction);
194 }
195
196 void MainWindow::createStatusBar()
197 {
198     messageLabel = new QLabel;
199     statusBar()->addWidget(messageLabel);
200 }
201
202 void MainWindow::readSettings()
203 {
204 }
205
206 void MainWindow::writeSettings()
207 {
208 }
209
210 void MainWindow::closeEvent(QCloseEvent *event)
211 {
212     if (okToContinue())
213         event->accept();
214     else event->ignore();
215 }
216
217 bool MainWindow::okToContinue()
218 {
219     return true;
220 }
221
222 void MainWindow::updateData()
223 {
224     qDebug() << "MainWindow::updateData()";
225     launcher->updateData();
226 }
227
228 void MainWindow::about()
229 {
230     QMessageBox::about(this, aboutTitle, aboutStr );
231 }