Added TODO notes.
[emufront] / src / dialogs / mediaimagepathmaindialog.cpp
index 1ba8a02..be1c07d 100644 (file)
@@ -42,16 +42,46 @@ 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();
     connect(scanButton, SIGNAL(clicked()), this, SLOT(beginScanFilePath()));
+    connect(fileUtil, SIGNAL(dbUpdateFinished()), this, SLOT(hideDbUpdating()));
+    connect(fileUtil, SIGNAL(dbUpdateInProgress()), this, SLOT(showDbUpdating()));
+}
+
+void MediaImagePathMainDialog::showDbUpdating()
+{
+    qDebug() << "DB updating";
+    // TODO: the following is not currently working
+    progressDialog->setWindowTitle(tr("Updating DB... please wait!"));
+    progressDialog->setEnabled(false);
 }
 
+void MediaImagePathMainDialog::hideDbUpdating()
+{
+    qDebug() << "DB update finished";
+    // TODO: the following is not currently working
+    progressDialog->setEnabled(true);
+    progressDialog->setWindowTitle(tr("Scanning files"));
+}
+
+
 void MediaImagePathMainDialog::initEditDialog()
 {
     nameDialog = new MediaImagePathDialog(this, dynamic_cast<FilePathObject*>(dbObject));
@@ -70,34 +100,40 @@ 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();
+        progressDialog->setEnabled(true);
+
+        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()