#include <QFile>
#include <QDir>
#include <QVariant>
+#include <QDebug>
const QString DatabaseManager::DB_FILENAME = QString("my.db.sqlite");
const QString DatabaseManager::DATABASE = QString("QSQLITE");
EmuFrontObject* DatabaseManager::getDataObject(int id)
{
+ qDebug() << "DatabaseManager::getDataObject, id " << id;
filterById(id);
EmuFrontObject *plf = 0;
if (sqlTableModel->rowCount() == 1)
{
QSqlRecord record = sqlTableModel->record(0);
- plf = recordToDataObject(&record);
+ if (record.isEmpty())
+ {
+ qDebug() << "No record";
+ }
+ else plf = recordToDataObject(&record);
}
return plf;
}
EmuFrontObject* DatabaseManager::getDataObjectFromModel(QModelIndex *index)
{
+ qDebug() << "Data-object from row " << index->row() << " requested.";
QSqlRecord record = sqlTableModel->record(index->row());
return recordToDataObject(&record);
}
#include <QObject>
#include <QSqlDatabase>
+#include "../exceptions/emufrontexception.h"
class QSqlError;
class QFile;
EmuFrontObject* DbSetup::recordToDataObject(const QSqlRecord *rec) const
{
+ Setup *s = 0;
+ if (!rec) return s;
int id = rec->value(Setup_Id).toInt();
+ qDebug() << "Creating a Setup object with id " << id;
QString extensions = rec->value(Setup_FileTypeExtensions).toString();
+ qDebug() << "Supported file types" << extensions;
QStringList list = extensions.split(FILE_TYPE_EXTENSION_SEPARATOR);
int plfId = rec->value(Setup_PlatformId).toInt();
+ qDebug() << "Platform id " << plfId;
int mtId = rec->value(Setup_MediaTypeId).toInt();
+ qDebug() << "Media type id " << mtId;
Platform *plf = dynamic_cast<Platform*>(dbPlatform->getDataObject(plfId));
+ qDebug() << "Platform " << plf->getName();
MediaType *mt = dynamic_cast<MediaType*>(dbMediaType->getDataObject(mtId));
- return new Setup(id, plf, mt, list);
+ qDebug() << "Media type " << mt->getName();
+ s = new Setup(id, plf, mt, list);
+ return s;
}
bool DbSetup::updateDataObjectToModel(const EmuFrontObject *ob)
"setup.platformid AS PlatformId, "
"setup.mediatypeid AS MediaTypeId, "
"setup.filetypeextensions AS SupportedFileTypeExtensions, "
- "platform.name || ' ' || mediatype.name AS SetupName, "
+ "platform.name || ' ' || mediatype.name AS SetupName "
"FROM setup %1"
"INNER JOIN platform ON setup.platformid=platform.id "
"INNER JOIN mediatype ON setup.mediatypeid=mediatype.id "
QSqlQueryModel* DbSetup::getData()
{
QSqlQueryModel *model = new QSqlQueryModel;
- model->setQuery(constructSelect());
+ QString select = constructSelect();
+ qDebug() << select;
+ model->setQuery(select);
model->setHeaderData(Setup_Id, Qt::Horizontal, tr("Id"));
model->setHeaderData(Setup_PlatformId, Qt::Horizontal, tr("Platform id"));
model->setHeaderData(Setup_MediaTypeId, Qt::Horizontal, tr("Media type id"));
model->setHeaderData(Setup_FileTypeExtensions, Qt::Horizontal, tr("File types"));
model->setHeaderData(Setup_Name, Qt::Horizontal, tr("Name"));
return model;
-
- /*QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this);
- model->setTable(DB_TABLE_NAME_FILEPATH);
- model->setRelation(FilePath_PlatformId,
- QSqlRelation(DB_TABLE_NAME_PLATFORM, "id", "name"));
- model->setRelation(FilePath_MediaTypeId,
- QSqlRelation(DB_TABLE_NAME_MEDIATYPE, "id", "name"));
- model->setSort(FilePath_Name, Qt::AscendingOrder);
- model->setHeaderData(FilePath_MediaTypeId, Qt::Horizontal, tr("Media type"));
- model->setHeaderData(FilePath_PlatformId, Qt::Horizontal, tr("Platform"));
- model->select();
- return model;*/
}
/*void DbMediaType::filterById(int id)
void DbTableModelManager::filterById(int id)
{
+ if (!sqlTableModel) throw EmuFrontException("Data model not available!");
QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
tmodel->setFilter(QString("id = %1").arg(id));
tmodel->select();
QModelIndex index = objectList->currentIndex();
if (!index.isValid()) return false;
- EmuFrontObject *ob = dbManager->getDataObjectFromModel(&index);
- if (!ob) return false;
+ qDebug() << "DbObjectDialog going to delete item at row " << index.row();
- int numBindings = dbManager->countDataObjectRefs(ob->getId());
- if (numBindings > 0 && !confirmDelete(ob->getName(), numBindings))
+ try
{
+ EmuFrontObject *ob = dbManager->getDataObjectFromModel(&index);
+
+ if (!ob) return false;
+ qDebug() << "DbObjectDialog going to delete item" << ob->getName();
+
+ int numBindings = dbManager->countDataObjectRefs(ob->getId());
+
+ qDebug() << "Got " << numBindings << " bindings.";
+
+ if (numBindings > 0 && !confirmDelete(ob->getName(), numBindings))
+ { return false; }
+ deleteCurrentObject();
+
+ qDebug() << "Deleted object from memory, going to delete from db.";
+
+ bool delOk = dbManager->deleteDataObjectFromModel(&index);
+ if (!delOk)
+ {
+ qDebug() << "delete failed";
return false;
+ }
+ qDebug() << "Object deleted from database";
+ 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;
}
#ifndef EMUFRONTDIALOG_H
#define EMUFRONTDIALOG_H
#include <QDialog>
+#include "../exceptions/emufrontexception.h"
class QErrorMessage;
db/dbquerymodelmanager.h \
dialogs/setupmaindialog.h \
dialogs/setupeditdialog.h \
- widgets/stringlistwidget.h
+ widgets/stringlistwidget.h \
+ exceptions/emufrontexception.h
SOURCES += main.cpp \
mainwindow.cpp \
db/databasemanager.cpp \
db/dbquerymodelmanager.cpp \
dialogs/setupmaindialog.cpp \
dialogs/setupeditdialog.cpp \
- widgets/stringlistwidget.cpp
-
-OTHER_FILES +=
+ widgets/stringlistwidget.cpp \
+ exceptions/emufrontexception.cpp
+OTHER_FILES +=
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// 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,
+// 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/>.
+
+#include "emufrontexception.h"
+
+EmuFrontException::EmuFrontException(QString msg) : msg(msg)
+{ }
+
+const QString EmuFrontException::what() const
+{ return msg; }
+
+void EmuFrontException::addInfo(QString str)
+{ msg.append(str); }
--- /dev/null
+// EmuFront
+// Copyright 2010 Mikko Keinänen
+//
+// This file is part of EmuFront.
+//
+//
+// EmuFront is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// 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,
+// 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/>.
+
+#ifndef EMUFRONTEXCEPTION_H
+#define EMUFRONTEXCEPTION_H
+
+#include <QString>
+
+class EmuFrontException
+{
+public:
+ EmuFrontException(QString str);
+ const QString what() const;
+ void addInfo(QString);
+
+private:
+ QString msg;
+};
+
+#endif // EMUFRONTEXCEPTION_H