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