Fixed bugs: dialogs remained disabled (signals were not attached to
[emufront] / src / dialogs / setupeditdialog.cpp
index c35042b..c6fa561 100644 (file)
@@ -21,7 +21,7 @@
 #include <QSqlTableModel>
 #include <QSqlRecord>
 #include "setupeditdialog.h"
-#include "../widgets/stringlistwidget.h"
+#include "../widgets/fileextensionwidget.h"
 #include "../widgets/effileobjectcombobox.h"
 #include "../db/dbmediatype.h"
 #include "../db/dbplatform.h"
@@ -35,6 +35,7 @@ SetupEditDialog::SetupEditDialog(QWidget *parent, EmuFrontObject* obj)
     dbMediaType = new DbMediaType(this);
     initWidgets();
     connectSignals();
+    emit test();
     layout();
 }
 
@@ -42,21 +43,24 @@ void SetupEditDialog::initWidgets()
 {
     mediaTypeComBox = new EFFileObjectComboBox(dbMediaType, this);
     platformComBox = new EFFileObjectComboBox(dbPlatform, this);
-    supportedFileTypesList = new StringListWidget;
+    supportedFileTypesList = new FileExtensionWidget;
+    supportedFileTypesList->setToolTip(tr("Set the supported file types by entering the file extension(s) (no wildcards or dots!)."));
 }
 
 void SetupEditDialog::layout()
 {
-   QLabel *platformLabel = new QLabel(tr("&Platform"));
+   QLabel *platformLabel = new QLabel(tr("&Platform:"));
    platformLabel->setBuddy(platformComBox);
-   QLabel *mediaTypeLabel = new QLabel(tr("Media&Type"));
+   QLabel *mediaTypeLabel = new QLabel(tr("Media&Type:"));
    mediaTypeLabel->setBuddy(mediaTypeComBox);
+   QLabel *fileTypesLabel = new QLabel(tr("Supported file types:"));
    QGridLayout *gridLayout = new QGridLayout;
    gridLayout->addWidget(platformLabel, 0, 0);
    gridLayout->addWidget(platformComBox, 0, 1);
    gridLayout->addWidget(mediaTypeLabel, 1, 0);
    gridLayout->addWidget(mediaTypeComBox, 1, 1);
-   gridLayout->addWidget(supportedFileTypesList, 2, 0, 2, 2);
+   gridLayout->addWidget(fileTypesLabel, 2, 0, 1, 2);
+   gridLayout->addWidget(supportedFileTypesList, 3, 0, 2, 2);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addLayout(gridLayout);
    mainLayout->addWidget(buttonBox);
@@ -84,31 +88,46 @@ void SetupEditDialog::acceptChanges()
     qDebug() << "Media type selected " << mt->getName();
 
 
+    bool change = false;
     Platform *ptmp = sup->getPlatform();
-    if (plf != ptmp)
+    if (!ptmp || *plf != *ptmp)
     {
         delete ptmp;
         sup->setPlatform(plf);
+        change = true;
     }
     MediaType *mtmp = sup->getMediaType();
-    if (mt != mtmp)
+    if (!mtmp || *mt != *mtmp)
     {
         delete mtmp;
         sup->setMediaType(mt);
+        change = true;
     }
-    sup->setSupportedFileTypeExtensions(supportedFileTypesList->getItems());
-    emit dataObjectUpdated();
+
+    // "Two lists are considered equal if they contain the same values in the same order."
+    if (supportedFileTypesList->getItems() != sup->getSupportedFileTypeExtensions()) {
+        sup->setSupportedFileTypeExtensions(supportedFileTypesList->getItems());
+        change = true;
+    }
+    // TODO: the second time around this signal is not received!
+    if (change) emit dataObjectUpdated();
     efObject = 0;
-    qDebug() << "Closing setup edit dialog";
     close();
 }
 
 void SetupEditDialog::setDataObject(EmuFrontObject *ob)
 {
     if (!ob) return;
-    qDebug() << "Updating data object with " << ob->getName() << ".";
+    qDebug() << "Updating Setup edit dialog data object to "
+        << ob->getName() << ".";
+    if (efObject)
+        delete dynamic_cast<Setup*>(efObject); // TODO: caused crash if another instance of setupeditdialog was created and new instance destroyed object being referenced in another existing dialog.
     efObject = ob;
     Setup *sup= dynamic_cast<Setup*>(ob);
+    if (!sup) {
+        qDebug() << "Failed casting to Setup";
+        return;
+    }
     if (sup->getPlatform()) setSelectedPlatform(sup->getPlatform());
     if (sup->getMediaType()) setSelectedMediaType(sup->getMediaType());
     supportedFileTypesList->setItems(sup->getSupportedFileTypeExtensions());