Modified the license text comment type.
[emufront] / src / dialogs / mediaimagepathmaindialog.cpp
index 1ba8a02..54b07f6 100644 (file)
@@ -1,28 +1,29 @@
-// EmuFront
-// Copyright 2010 Mikko Keinänen
-//
-// This file is part of EmuFront.
-//
-//
-// 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 and appearing in the file gpl.txt included in the
-// packaging of this file.
-//
-// 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 EmuFront.  If not, see <http://www.gnu.org/licenses/>.
-
+/*
+** EmuFront
+** Copyright 2010 Mikko Keinänen
+**
+** This file is part of EmuFront.
+**
+**
+** 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 and appearing in the file gpl.txt included in the
+** packaging of this file.
+**
+** 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 EmuFront.  If not, see <http://www.gnu.org/licenses/>.
+*/
 #include <QtGui>
 
-#include "../dataobjects/filepathobject.h"
-#include "../dataobjects/emufrontfileobject.h"
-#include "../db/dbfilepath.h"
-#include "../utils/fileutil.h"
+#include "filepathobject.h"
+#include "emufrontfileobject.h"
+#include "dbfilepath.h"
+#include "fileutil.h"
 #include "mediaimagepathmaindialog.h"
 #include "mediaimagepathdialog.h"
 
@@ -42,10 +43,21 @@ MediaImagePathMainDialog::MediaImagePathMainDialog(QWidget *parent)
     hiddenColumns << DbFilePath::FilePath_SetupId;
     hideColumns();
 
+    fileUtil = new FileUtil(this);
+    initProgressDialog();
+
     // do not move to parent class:
     connectSignals();
 }
 
+void MediaImagePathMainDialog::initProgressDialog()
+{
+    progressDialog = new QProgressDialog(this);
+    progressDialog->setWindowTitle(tr("Scanning files"));
+    progressDialog->setCancelButtonText(tr("Abort"));
+    progressDialog->setWindowModality(Qt::WindowModal);
+}
+
 void MediaImagePathMainDialog::connectSignals()
 {
     DbObjectDialog::connectSignals();
@@ -70,34 +82,39 @@ void MediaImagePathMainDialog::beginScanFilePath()
         QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton ) == QMessageBox::No) {
             return;
         }
-    FileUtil fileUtil(this);
-    EmuFrontObject *ob = dbManager->getDataObjectFromModel(&index);
-    if (!ob) return;
-    FilePathObject *fpo = dynamic_cast<FilePathObject*>(ob);
+    FilePathObject *fpo = 0;
     try
     {
+        EmuFrontObject *ob = dbManager->getDataObjectFromModel(&index); // throws EmuFrontException
+        if (!ob) return;
+        fpo = dynamic_cast<FilePathObject*>(ob);
+        if (!fpo) return;
         QStringList l;
         l << "*.zip"; // TODO set filters in a global constant class
 
         dbMediaImageContainer->removeFromFilePath(fpo->getId());
 
-        QProgressDialog progressDialog(this);
-        progressDialog.setWindowTitle("Scanning files...");
-        progressDialog.setCancelButtonText("Abort");
-        progressDialog.setWindowModality(Qt::WindowModal);
-        progressDialog.show();
+        progressDialog->show();
+
+        setUIEnabled(false);
+        int count = fileUtil->scanFilePath(fpo, l, dbMediaImageContainer, progressDialog);
+        progressDialog->hide();
 
-        int count = fileUtil.scanFilePath(fpo, l, dbMediaImageContainer, progressDialog);
-        progressDialog.hide();
         QMessageBox msgBox;
         msgBox.setText(tr("Scanned %1 files to database.").arg(count));
         msgBox.exec();
-        delete fpo;
+        DbFilePath *dbfp = dynamic_cast<DbFilePath*>(dbManager);
+        if (!(dbfp && dbfp->setScanned(fpo)))
+            throw EmuFrontException(tr("Failed updating the last scanned time stamp for selected file path!"));
+        else updateList();
     }
     catch (EmuFrontException s)
     {
         errorMessage->showMessage( s.what() );
-   }
+    }
+    setUIEnabled(true);
+    delete fpo;
+    fpo = 0;
 }
 
 EmuFrontObject* MediaImagePathMainDialog::createObject()