// 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>
connect(nameDialog, SIGNAL(updateRejected()), this, SLOT(updateReject()));
connect(nameDialog, SIGNAL(test()), this, SLOT(testSlot()));
}
-
+
void DbObjectDialog::testSlot()
{
qDebug() << "TEST SIGNAL RECEIVED!";
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()
{
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();
}
int yn = QMessageBox::question(this, "Confirm", msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (yn == QMessageBox::Yes)
{
- qDebug() << "Deleting item..." << name << ".";
deleteItem();
}
}
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);
return false;
return true;
}
+
+void DbObjectDialog::refreshDataModel()
+{
+ dbManager->resetModel();
+}