EmuFront ... NOT Foobar :D
[emufront] / src / dialogs / dbobjectdialog.cpp
index 03085d3..9bcb91b 100644 (file)
@@ -9,13 +9,13 @@
 // the Free Software Foundation, either version 3 of the License, or
 // (at your option) any later version.
 //
-// Foobar is distributed in the hope that it will be useful,
+// EmuFront is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 // GNU General Public License for more details.
 //
 // You should have received a copy of the GNU General Public License
-// along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
+// along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <QtGui>
 #include <QSqlTableModel>
@@ -65,7 +65,7 @@ void DbObjectDialog::connectSignals()
     connect(nameDialog, SIGNAL(updateRejected()), this, SLOT(updateReject()));
     connect(nameDialog, SIGNAL(test()), this, SLOT(testSlot()));
 }
-
+    
 void DbObjectDialog::testSlot()
 {
     qDebug() << "TEST SIGNAL RECEIVED!";
@@ -73,7 +73,8 @@ void DbObjectDialog::testSlot()
 
 void DbObjectDialog::insertDb(const EmuFrontObject *ob) const
 {
-    dbManager->insertDataObjectToModel(ob);
+    if (!dbManager->insertDataObjectToModel(ob))
+        errorMessage->showMessage(tr("Inserting data object %1 failed.").arg(ob->getName()));
 }
 
 void DbObjectDialog::addObject()
@@ -101,38 +102,48 @@ bool DbObjectDialog::deleteItem()
 {
     QModelIndex index = objectList->currentIndex();
     if (!index.isValid()) return false;
+    try
+    {
+        EmuFrontObject *ob = dbManager->getDataObjectFromModel(&index);
 
-    EmuFrontObject *ob = dbManager->getDataObjectFromModel(&index);
-    if (!ob) return false;
+        if (!ob)
+        {
+            errorMessage->showMessage(tr("Couldn't find the selected data object from data model!"));
+            return false;
+        }
 
-    int numBindings = dbManager->countDataObjectRefs(ob->getId());
-    if (numBindings > 0 && !confirmDelete(ob->getName(), numBindings))
-    {
+        int numBindings = dbManager->countDataObjectRefs(ob->getId());
+
+        if (numBindings > 0 && !confirmDelete(ob->getName(), numBindings))
+        { return false; }
+        deleteCurrentObject();
+
+        bool delOk = dbManager->deleteDataObjectFromModel(&index);
+        if (!delOk)
+        {
+            errorMessage->showMessage(tr("Deleting data object %1 failed!").arg(ob->getName()));
             return false;
+        }
+        updateList();
+        objectList->setFocus();
     }
-    deleteCurrentObject();
-    bool delOk = dbManager->deleteDataObjectFromModel(&index);
-    if (!delOk)
+    catch(EmuFrontException e)
     {
-        qDebug() << "delete failed";
-        return false;
+        errorMessage->showMessage(e.what());
     }
-    updateList();
-    objectList->setFocus();
     return false;
 }
 
 void DbObjectDialog::updateDb(const EmuFrontObject *ob) const
 {
     if (!ob) return;
-    qDebug() << "Updating platform " << ob->getName();
-    dbManager->updateDataObjectToModel(ob);
+    if ( !dbManager->updateDataObjectToModel(ob) )
+    { errorMessage->showMessage("Database update failed!"); }
 }
 
 void DbObjectDialog::updateList() const
 {
     if (!dbManager) return;
-    qDebug() << "Going to reset the data model";
     dbManager->resetModel();
 }
 
@@ -163,7 +174,6 @@ void DbObjectDialog::deleteButtonClicked()
     int yn = QMessageBox::question(this, "Confirm", msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
     if (yn == QMessageBox::Yes)
     {
-        qDebug() << "Deleting item..." << name << ".";
         deleteItem();
     }
 }
@@ -214,23 +224,15 @@ void DbObjectDialog::initDataTable()
 
 void DbObjectDialog::updateReject()
 {
-    qDebug() << "Update rejected ... going to delete current object.";
     // we don't want to keep this in memory
     deleteCurrentObject();
 }
 
 void DbObjectDialog::updateData()
 {
-    qDebug() << "Update accepted.";
     // update data model
     if (!dbObject) return;
 
-    qDebug() << "dbObject is not 0";
-
-    qDebug() << "We have a " + dbObject->getName();
-
-    qDebug() << "Data will be inserted/updated...";
-
     // if data object id > -1 we are updating the data otherwise we are inserting new data
     if (dbObject->getId() > -1) updateDb(dbObject);
     else insertDb(dbObject);
@@ -256,3 +258,8 @@ bool DbObjectDialog::confirmDelete(QString name, int numRefs)
         return false;
     return true;
 }
+
+void DbObjectDialog::refreshDataModel()
+{
+    dbManager->resetModel();
+}