Changes in the data model: this is not tested yet at all! (compiles
[emufront] / src / dialogs / mediatypedialog.cpp
index d97dd15..3f03d8b 100644 (file)
@@ -30,10 +30,10 @@ MediaTypeDialog::MediaTypeDialog(QWidget* parent)
     :DbObjectDialog(parent)
 {
     setWindowTitle(tr("Set media types"));
-    //nameDialog = 0;
-    nameDialog = new MediaTypeNameDialog(this, dynamic_cast<MediaType*>(dbObject));
     dbManager = new DbMediaType(this);
     initDataTable();
+    initEditDialog();
+    objectList->hideColumn(DbMediaType::EmuFrontFileObject_FileId);
 
     // do not move to parent class:
     connectSignals();
@@ -42,85 +42,21 @@ MediaTypeDialog::MediaTypeDialog(QWidget* parent)
 
 MediaTypeDialog::~MediaTypeDialog()
 {
-    delete dynamic_cast<MediaType*>(dbObject);
+    deleteCurrentObject();
 }
 
-void MediaTypeDialog::addObject()
+void MediaTypeDialog::initEditDialog()
 {
-    delete dynamic_cast<MediaType*>(dbObject);
-    dbObject = new MediaType;
-    nameDialog->setDataObject(dbObject);
-    activateNameDialog();
+    nameDialog = new MediaTypeNameDialog(this, dynamic_cast<MediaType*>(dbObject));
 }
 
-void MediaTypeDialog::editObject()
+EmuFrontObject* MediaTypeDialog::createObject()
 {
-    qDebug() << "editObject called";
-    QModelIndex index = objectList->currentIndex();
-    if (!index.isValid())
-        return;
-    qDebug() << "we have a valid index";
-    delete dbObject;
-    dbObject = (dynamic_cast<DbMediaType*>(dbManager))->getDataObjectFromModel(&index);
-    nameDialog->setDataObject(dbObject);
-    activateNameDialog();
+    return new MediaType;
 }
 
 void MediaTypeDialog::deleteCurrentObject()
 {
     delete dynamic_cast<MediaType*>(dbObject);
-}
-
-int MediaTypeDialog::deleteObject()
-{
-    return 0;
-}
-
-void MediaTypeDialog::updateDb(const EmuFrontObject *ob) const
-{
-    if (!ob) return;
-    qDebug() << "Updating media type" << ob->getName();
-    (dynamic_cast<DbMediaType*>(dbManager))->updateDataObjectToModel(ob);
-}
-
-void MediaTypeDialog::insertDb(const EmuFrontObject *ob) const
-{
-    (dynamic_cast<DbMediaType*>(dbManager))->insertDataObjectToModel(ob);
-}
-
-bool MediaTypeDialog::deleteItem()
-{
-    qDebug() << "MediaTypeDialog::deleteItem()";
-    QModelIndex index = objectList->currentIndex();
-    if (!index.isValid()) return false;
-
-    qDebug() << "Index is valid";
-
-    // TODO: when implementing data bindings to platform
-    // we need to check if platform being removed has bindings
-    // and a) ask user if this platform should be removed
-    // b) remove all the data associated to this platform
-
-    EmuFrontObject *ob = dynamic_cast<DbMediaType*>(dbManager)->getDataObjectFromModel(&index);
-    if (!ob) return false;
-
-    MediaType *plf = dynamic_cast<MediaType*>(ob);
-
-    qDebug() << "Got platform" << plf->getName();
-
-    int numBindings = dynamic_cast<DbMediaType*>(dbManager)->countDataObjectRefs(plf->getId());
-    if (numBindings > 0 && !confirmDelete(plf->getName(), numBindings))
-    {
-        return false;
-    }
-    delete plf;
-    bool delOk = (dynamic_cast<DbMediaType *>(dbManager))->deleteDataObjectFromModel(&index);
-    if (!delOk)
-    {
-        qDebug() << "delete failed";
-        return false;
-    }
-    updateList();
-    objectList->setFocus();
-    return false;
+    dbObject = 0;
 }