Some comments about heap-objects and cleaning up some heap-objects.
[emufront] / src / dialogs / mediaimagepathdialog.cpp
index 3838657..facdf1a 100644 (file)
@@ -100,9 +100,18 @@ void MediaImagePathDialog::setSelectedSetup(const Setup *sup)
     setupComBox->setSelected(sup);
 }
 
+/* Returns a pointer to Setup object which must be deleted by calling code */
 Setup* MediaImagePathDialog::getSelectedSetup()
 {
-    EmuFrontObject *ob = setupComBox->getSelected();
+    EmuFrontObject *ob = 0;
+
+    try {
+        ob = setupComBox->getSelected();
+    }
+    catch(EmuFrontException &e){
+        errorMessage->showMessage(e.what());
+    }
+
     if (!ob) return 0;
     return dynamic_cast<Setup*>(ob);
 }
@@ -116,6 +125,7 @@ void MediaImagePathDialog::acceptChanges()
         QMessageBox::information(this, tr("Set up"), tr("Set up not selected"), QMessageBox::Ok);
         return;
     }
+    bool change = false;
     qDebug() << "Setup selected " << sup->getName();
     QString filePath = filePathLabel->text();
     if (filePath.isEmpty())
@@ -123,14 +133,20 @@ void MediaImagePathDialog::acceptChanges()
         QMessageBox::information(this, tr("File path"), tr("File path was not selected"), QMessageBox::Ok);
         return;
     }
+    if (filePath != fpo->getName()) {
+        fpo->setName(filePath);
+        change = true;
+    }
+
     Setup *tmp = fpo->getSetup();
-    if (sup != tmp)
+
+    if (!tmp || *sup != *tmp)
     {
         delete tmp;
         fpo->setSetup(sup);
+        change = true;
     }
-    fpo->setName(filePath);
-    emit dataObjectUpdated();
+    if (change) emit dataObjectUpdated();
     efObject = 0;
     close();
 }