Added menu option for resetting the database.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 16 Nov 2010 21:50:09 +0000 (23:50 +0200)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Tue, 16 Nov 2010 21:50:09 +0000 (23:50 +0200)
src/mainwindow.cpp
src/mainwindow.h

index 43ab762..733cefc 100644 (file)
@@ -103,6 +103,10 @@ void MainWindow::createActions()
     exitAction->setStatusTip(tr("Exit EmuFront"));
     connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
 
+    resetDbAction = new QAction( tr("Reset database"), this);
+    resetDbAction->setStatusTip(tr("Deletes all the current data and create a new database."));
+    connect(resetDbAction, SIGNAL(triggered()), this, SLOT(resetDb()));
+
     aboutAction = new QAction(tr("&About"), this);
     aboutAction->setStatusTip(tr("About EmuFront"));
     connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
@@ -176,6 +180,24 @@ void MainWindow::configureTmpDir()
     }
 }
 
+void MainWindow::resetDb()
+{
+    if (QMessageBox::question(this, "Reset database?",
+        "Are you REALLY SURE you want to do this? "
+        "All the current data WILL BE LOST!",
+        QMessageBox::No,
+        QMessageBox::Yes) == QMessageBox::No) {
+        return;
+    }
+    try {
+        createDB();
+    }
+    catch (EmuFrontException e) {
+        qDebug() << e.what();
+        QMessageBox::critical(this, "Exception", e.what());
+    }
+}
+
 void MainWindow::manageDatFiles()
 {
     DatFileUtil dfu;
@@ -192,6 +214,8 @@ void MainWindow::activateDialog(EmuFrontDialog* dia) const
 void MainWindow::createMenus()
 {
     fileMenu = menuBar()->addMenu(tr("&File"));
+    fileMenu->addAction(resetDbAction);
+    fileMenu->addSeparator();
     fileMenu->addAction(exitAction);
 
     configMenu = menuBar()->addMenu(tr("&Config"));
@@ -271,18 +295,8 @@ bool MainWindow::testDB(bool reset)
                                          " Cannot continue.");
         }
 
-        if (reset)
-        {
-            try
-            {
-                DbCreator dbCreator;
-                dbCreator.createDB();
-            }
-            catch (QString str) {
-                QString msg(tr("Exception while trying to create"
-                               " EmuFront database: %s").arg(str));
-                throw EmuFrontException(msg);
-            }
+        if (reset) {
+            createDB();
         }
         return true;
     }
@@ -292,3 +306,18 @@ bool MainWindow::testDB(bool reset)
         return false;
     }
 }
+
+void MainWindow::createDB() const
+{
+    try
+    {
+        DbCreator dbCreator;
+        dbCreator.createDB();
+    }
+    catch (QString str) {
+        QString msg(tr("Exception while trying to create"
+                       " EmuFront database: %s").arg(str));
+        throw EmuFrontException(msg);
+    }
+}
+
index 2a258ee..f28fef0 100644 (file)
@@ -53,6 +53,7 @@ private slots:
     void configureSetups();
     void configureEmulators();
     void configureTmpDir();
+    void resetDb();
     void updateData();
     void manageDatFiles();
     void about();
@@ -69,6 +70,7 @@ private:
     void connectSignals();
     void activateDialog(EmuFrontDialog*) const;
     bool testDB(bool reset);
+    void createDB() const;
        PlatformDialog *platformDialog;
     MediaTypeDialog *mediaTypeDialog;
     MediaImagePathMainDialog *mediaImagePathDialog;
@@ -84,6 +86,7 @@ private:
     QAction *configSetupAction;
     QAction *configEmulatorAction;
     QAction *exitAction;
+    QAction *resetDbAction;
     QAction *aboutAction;
     QAction *configTmpDirAction;
     QAction *manageDatFilesAction;