Fixed bugs: dialogs remained disabled (signals were not attached to
[emufront] / src / dialogs / mediaimagepathmaindialog.cpp
index 18b915b..1ba8a02 100644 (file)
@@ -5,9 +5,9 @@
 //
 //
 // 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.
 //
 // EmuFront is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -38,8 +38,10 @@ MediaImagePathMainDialog::MediaImagePathMainDialog(QWidget *parent)
     buttonBox->addButton(scanButton, QDialogButtonBox::ActionRole);
 
     initEditDialog();
-    objectList->hideColumn(DbFilePath::FilePath_Id);
-    objectList->hideColumn(DbFilePath::FilePath_SetupId);
+    hiddenColumns << DbFilePath::FilePath_Id;
+    hiddenColumns << DbFilePath::FilePath_SetupId;
+    hideColumns();
+
     // do not move to parent class:
     connectSignals();
 }
@@ -53,12 +55,21 @@ void MediaImagePathMainDialog::connectSignals()
 void MediaImagePathMainDialog::initEditDialog()
 {
     nameDialog = new MediaImagePathDialog(this, dynamic_cast<FilePathObject*>(dbObject));
+    connectNameDialogSignals();
 }
 
 void MediaImagePathMainDialog::beginScanFilePath()
 {
     QModelIndex index = objectList->currentIndex();
     if (!index.isValid()) return;
+    if (QMessageBox::question(this,
+        tr("Confirm"),
+        tr("Do you want to continue? "
+        "If you have tons of huge files this may take even hours! "
+        "If you are low on battery power, consider carefully!"),
+        QMessageBox::Yes, QMessageBox::No, QMessageBox::NoButton ) == QMessageBox::No) {
+            return;
+        }
     FileUtil fileUtil(this);
     EmuFrontObject *ob = dbManager->getDataObjectFromModel(&index);
     if (!ob) return;
@@ -68,23 +79,20 @@ void MediaImagePathMainDialog::beginScanFilePath()
         QStringList l;
         l << "*.zip"; // TODO set filters in a global constant class
 
-        QList<MediaImageContainer*> files = fileUtil.scanFilePath(fpo, l);
-        qDebug() << "Storing scanned " << files.size() << " files to database";
-        dbMediaImageContainer->storeContainers(files, fpo);
-        qDebug() << "Done storing scanned " << files.size() << " files to database";
-        // the media image and media image container objects can be deleted now
-        // qDeleteAll could be used also... maybe?
-        // TODO: this is not yet functional:
-        foreach(MediaImageContainer* mic, files) {
-            /*QList<MediaImage*> mis = mic->getMediaImages();
-            foreach(MediaImage* mi, mis) {
-                delete mi;
-                mi = 0;
-            }
-            delete mic;
-            mic = 0;
-            */
-        }
+        dbMediaImageContainer->removeFromFilePath(fpo->getId());
+
+        QProgressDialog progressDialog(this);
+        progressDialog.setWindowTitle("Scanning files...");
+        progressDialog.setCancelButtonText("Abort");
+        progressDialog.setWindowModality(Qt::WindowModal);
+        progressDialog.show();
+
+        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;
     }
     catch (EmuFrontException s)
     {
@@ -94,7 +102,7 @@ void MediaImagePathMainDialog::beginScanFilePath()
 
 EmuFrontObject* MediaImagePathMainDialog::createObject()
 {
-    return new FilePathObject;
+    return new FilePathObject(FilePathObject::FilePathType_MediaImageDir);
 }
 
 MediaImagePathMainDialog::~MediaImagePathMainDialog()
@@ -104,6 +112,22 @@ MediaImagePathMainDialog::~MediaImagePathMainDialog()
 
 void MediaImagePathMainDialog::deleteCurrentObject()
 {
-    delete dynamic_cast<FilePathObject*>(dbObject);
-    dbObject = 0;
+    if (dbObject) {
+        FilePathObject* fpo =  dynamic_cast<FilePathObject*>(dbObject);
+        if (fpo) delete fpo;
+        else qDebug() << "Failed deleteing FilePathObject";
+        dbObject = 0;
+    }
+}
+
+void MediaImagePathMainDialog::cleanUp()
+{
+    deleteCurrentObject();
+    if (nameDialog) {
+        MediaImagePathDialog *pnd =
+            dynamic_cast<MediaImagePathDialog*>(nameDialog);
+        if (pnd) delete pnd;
+        else qDebug() << "Failed to delete MediaImagePathDialog";
+        nameDialog = 0;
+    }
 }