Renamed database file.
[emufront] / src / mainwindow.cpp
index b6334fa..d5d5583 100644 (file)
@@ -5,34 +5,63 @@
 //
 //
 // EmuFront is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
+// it under the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation and appearing in the file gpl.txt included in the
+// packaging of this file.
 //
-// Foobar is distributed in the hope that it will be useful,
+// EmuFront is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 // GNU General Public License for more details.
 //
 // You should have received a copy of the GNU General Public License
-// along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
+// along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <QtGui>
 #include "mainwindow.h"
+#include "emulauncher.h"
 #include "dialogs/platformdialog.h"
 #include "dialogs/mediatypedialog.h"
 #include "dialogs/mediaimagepathmaindialog.h"
+#include "dialogs/setupmaindialog.h"
+#include "dialogs/executablemaindialog.h"
+#include "utils/datfileutil.h"
 #include "db/databasemanager.h"
+#include "db/dbconfig.h"
+
+QString MainWindow::aboutStr = trUtf8(
+        "<h2>EmuFront</h2>"
+        "<p>&copy; 2010 Mikko Keinänen</p>"
+        "<p>mikko.keinanen@gmail.com</p>"
+        "<p>EmuFront is free software: you can redistribute it and/or modify "
+        "it under the terms of the GNU General Public License version 2 as published by "
+        "the Free Software Foundation.</p>"
+);
+
+QString MainWindow::aboutTitle = tr("About EmuFront");
 
 MainWindow::MainWindow()
 {
     setWindowTitle("EmuFront");
+    tmpDirFilePath = DbConfig::getTmpDir();
+    if (tmpDirFilePath.isEmpty())
+        tmpDirFilePath = QDir::homePath();
+    qDebug() << "Temporary dir is " << tmpDirFilePath;
+    launcher = new EmuLauncher(this, tmpDirFilePath);
+    setCentralWidget(launcher);
     createActions();
     createMenus();
     createStatusBar();
     readSettings();
     platformDialog = 0;
     mediaTypeDialog = 0;
+    mediaImagePathDialog = 0;
+    setupMainDialog = 0;
+    executableMainDialog = 0;
+}
+
+void MainWindow::connectSignals()
+{
 }
 
 void MainWindow::createActions()
@@ -51,10 +80,30 @@ void MainWindow::createActions()
     connect(configMediaImagePathAction, SIGNAL(triggered()),
         this, SLOT(configureMediaImagePaths()));
 
+    configSetupAction = new QAction(tr("S&etups"), this);
+    configSetupAction->setStatusTip(tr("Configure set ups"));
+    connect(configSetupAction, SIGNAL(triggered()), this, SLOT(configureSetups()));
+
+    configEmulatorAction = new QAction(tr("Em&ulators"), this);
+    configEmulatorAction->setStatusTip(tr("Configure emulators"));
+    connect(configEmulatorAction, SIGNAL(triggered()), this, SLOT(configureEmulators()));
+
+    configTmpDirAction = new QAction(tr("&Temp dir"), this);
+    configTmpDirAction->setStatusTip(tr("Configure directory for temporary files."));
+    connect(configTmpDirAction, SIGNAL(triggered()), this, SLOT(configureTmpDir()));
+
+    manageDatFilesAction = new QAction(tr("&Manage dats"), this);
+    manageDatFilesAction->setStatusTip(tr("Read dat files to database."));
+    connect(manageDatFilesAction, SIGNAL(triggered()), this, SLOT(manageDatFiles()));
+
     exitAction = new QAction(tr("&Exit"), this);
     exitAction->setShortcut(tr("Ctrl+Q"));
     exitAction->setStatusTip(tr("Exit EmuFront"));
     connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
+
+    aboutAction = new QAction(tr("&About"), this);
+    aboutAction->setStatusTip(tr("About EmuFront"));
+    connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
 }
 
 void MainWindow::configurePlatforms()
@@ -62,7 +111,8 @@ void MainWindow::configurePlatforms()
    if (!platformDialog)
    {
        platformDialog = new PlatformDialog(this);
-   } 
+       connect(platformDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
+   }
    activateDialog(platformDialog);
 }
 
@@ -71,6 +121,7 @@ void MainWindow::configureMediaTypes()
     if (!mediaTypeDialog)
     {
         mediaTypeDialog = new MediaTypeDialog(this);
+        connect(mediaTypeDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
    }
    activateDialog(mediaTypeDialog);
 }
@@ -84,6 +135,51 @@ void MainWindow::configureMediaImagePaths()
     activateDialog(mediaImagePathDialog);
 }
 
+void MainWindow::configureSetups()
+{
+    if (!setupMainDialog)
+    {
+        qDebug() << "MainWindow: Creating a setup main dialog.";
+        setupMainDialog = new SetupMainDialog(this);
+    }
+    activateDialog(setupMainDialog);
+    setupMainDialog->refreshDataModel();
+}
+
+void MainWindow::configureEmulators()
+{
+    if (!executableMainDialog) {
+        executableMainDialog = new ExecutableMainDialog(this);
+        connect(executableMainDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
+    }
+    activateDialog(executableMainDialog);
+    executableMainDialog->refreshDataModel();
+}
+
+void MainWindow::configureTmpDir()
+{
+    /*if (!tmpFolderDialog) {
+        tmpFolderDialog = new TmpFolderEditDialog(this, tmpDirFilePath);
+    }
+    activateDialog(tmpFolderDialog);*/
+
+    QString fpath = QFileDialog::getExistingDirectory(this,
+        tr("Select a directory"), tmpDirFilePath,
+        QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
+    QDir d(fpath);
+    if (d.exists() && d.isReadable()) {
+        tmpDirFilePath = fpath;
+        DbConfig::setTmpDir(tmpDirFilePath);
+        launcher->setTmpDirPath(tmpDirFilePath);
+    }
+}
+
+void MainWindow::manageDatFiles()
+{
+    DatFileUtil dfu;
+    dfu.open();
+}
+
 void MainWindow::activateDialog(EmuFrontDialog* dia) const
 {
     dia->show();
@@ -91,16 +187,24 @@ void MainWindow::activateDialog(EmuFrontDialog* dia) const
     dia->activateWindow();
 }
 
-
 void MainWindow::createMenus()
 {
     fileMenu = menuBar()->addMenu(tr("&File"));
     fileMenu->addAction(exitAction);
 
     configMenu = menuBar()->addMenu(tr("&Config"));
+    configMenu->addAction(configTmpDirAction);
+    configMenu->addSeparator();
     configMenu->addAction(configPlatformAction);
     configMenu->addAction(configMediaTypeAction);
+    configMenu->addAction(configSetupAction);
     configMenu->addAction(configMediaImagePathAction);
+    configMenu->addAction(configEmulatorAction);
+    configMenu->addSeparator();
+    configMenu->addAction(manageDatFilesAction);
+
+    helpMenu = menuBar()->addMenu(tr("&Help"));
+    helpMenu->addAction(aboutAction);
 }
 
 void MainWindow::createStatusBar()
@@ -128,3 +232,14 @@ bool MainWindow::okToContinue()
 {
     return true;
 }
+
+void MainWindow::updateData()
+{
+    qDebug() << "MainWindow::updateData()";
+    launcher->updateData();
+}
+
+void MainWindow::about()
+{
+    QMessageBox::about(this, aboutTitle, aboutStr );
+}