Started implementing better MVC support: thanks Petro for the idea! ;)
[emufront] / src / mainwindow.cpp
index cdc0f29..eecab39 100644 (file)
@@ -21,6 +21,7 @@
 #include "mainwindow.h"
 #include "emulauncher.h"
 #include "dialogs/platformdialog.h"
+#include "dialogs/platformmaindialog.h"
 #include "dialogs/mediatypedialog.h"
 #include "dialogs/mediaimagepathmaindialog.h"
 #include "dialogs/setupmaindialog.h"
@@ -44,12 +45,13 @@ QString MainWindow::aboutTitle = tr("About EmuFront");
 MainWindow::MainWindow(bool reset)
 {
     if (!testDB(reset)) close();
+    errorMessage = new QErrorMessage(this);
     setWindowTitle("EmuFront");
     tmpDirFilePath = DbConfig::getTmpDir();
     if (tmpDirFilePath.isEmpty())
         tmpDirFilePath = QDir::homePath();
     qDebug() << "Temporary dir is " << tmpDirFilePath;
-    launcher = new EmuLauncher(this, tmpDirFilePath);
+    launcher = new EmuLauncher(errorMessage, this, tmpDirFilePath);
     setCentralWidget(launcher);
     createActions();
     createMenus();
@@ -71,7 +73,12 @@ void MainWindow::createActions()
     configPlatformAction = new QAction(tr("&Platforms"), this);
     configPlatformAction->setStatusTip(tr("Configure platforms"));
     connect(configPlatformAction, SIGNAL(triggered()),
-           this, SLOT(configurePlatforms()));
+        this, SLOT(configurePlatforms()));
+
+    configPlatformsAction = new QAction(tr("&Set Platforms"), this);
+    configPlatformsAction->setStatusTip(tr("Add, edit and delete platforms"));
+    connect(configPlatformsAction, SIGNAL(triggered()),
+        this, SLOT(configurePlatformss()));
 
     configMediaTypeAction = new QAction(tr("&Media Types"), this);
     configMediaTypeAction->setStatusTip(tr("Configure media types"));
@@ -122,6 +129,13 @@ void MainWindow::configurePlatforms()
    activateDialog(platformDialog);
 }
 
+void MainWindow::configurePlatformss()
+{
+    plfDialog = new PlatformMainDialog(this);
+    connect(plfDialog, SIGNAL(finished(int)), this, SLOT(updateData()));
+    activateDialog(plfDialog);
+}
+
 void MainWindow::configureMediaTypes()
 {
     if (!mediaTypeDialog)
@@ -193,8 +207,7 @@ void MainWindow::resetDb()
         createDB();
     }
     catch (EmuFrontException e) {
-        qDebug() << e.what();
-        QMessageBox::critical(this, "Exception", e.what());
+        errorMessage->showMessage(e.what());
     }
 }
 
@@ -222,6 +235,7 @@ void MainWindow::createMenus()
     configMenu->addAction(configTmpDirAction);
     configMenu->addSeparator();
     configMenu->addAction(configPlatformAction);
+    configMenu->addAction(configPlatformsAction);
     configMenu->addAction(configMediaTypeAction);
     configMenu->addAction(configSetupAction);
     configMenu->addAction(configMediaImagePathAction);
@@ -267,7 +281,7 @@ void MainWindow::updateData()
 
 void MainWindow::about()
 {
-    QMessageBox::about(this, aboutTitle, aboutStr );
+    QMessageBox::about(this, aboutTitle, aboutStr);
 }
 
 bool MainWindow::testDB(bool reset)
@@ -302,12 +316,11 @@ bool MainWindow::testDB(bool reset)
     }
     catch (EmuFrontException e) {
         qDebug() << e.what();
-        QMessageBox::critical(this, "Exception", e.what());
+        errorMessage->showMessage(e.what());
         return false;
     }
 }
 
-/* Throws EmuFrontException */
 void MainWindow::createDB() const
 {
     try
@@ -318,7 +331,7 @@ void MainWindow::createDB() const
     catch (QString str) {
         QString msg(tr("Exception while trying to create"
                        " EmuFront database: %s").arg(str));
-        throw EmuFrontException(msg);
+        errorMessage->showMessage(msg);
     }
 }