X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fdb%2Fdatabasemanager.h;h=ef59d86d243ff2ec458b9ca565154f052df34f5e;hb=e98b4c09b55d700349bd1fa2af8ae8c63f338c24;hp=921804d5832fa751d39c545660a49a9d703b83c9;hpb=80c381371c689c72a2af10838b8cf50aa075e353;p=emufront diff --git a/src/db/databasemanager.h b/src/db/databasemanager.h index 921804d..ef59d86 100644 --- a/src/db/databasemanager.h +++ b/src/db/databasemanager.h @@ -1,12 +1,34 @@ +// 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 . + #ifndef DATABASEMANAGER_H #define DATABASEMANAGER_H #include #include +#include "../exceptions/emufrontexception.h" class QSqlError; class QFile; -class QSqlTableModel; +class QSqlQueryModel; +class QModelIndex; +class EmuFrontObject; class DatabaseManager : public QObject { @@ -14,27 +36,38 @@ public: DatabaseManager(QObject *parent = 0); ~DatabaseManager(); + QSqlQueryModel* getDataModel(); + EmuFrontObject* getDataObjectFromModel(QModelIndex*); + EmuFrontObject* getDataObject(int id); + virtual bool updateDataObjectToModel(const EmuFrontObject*) = 0; + virtual bool insertDataObjectToModel(const EmuFrontObject*) = 0; + virtual bool deleteDataObjectFromModel(QModelIndex*) = 0; + virtual int countDataObjectRefs(int id) const = 0; static bool openDB(); - static bool deleteDB(); - static bool dbExists(); - static QSqlError lastError(); - static bool createDB(); - static int insertPlatform(QString name, QString filename = ""); - static QString getPlatform(int id); - QSqlTableModel* getPlatforms(); - + void resetModel(); enum { - Platform_Id = 0, - Platform_Name = 1, - Platform_Filename = 2 - }; + Filetype_MediaImageContainer = 0, + Filetype_Screenshot = 1, + Filetype_PlatformIcon = 2, + Filetype_MediaTypeIcon = 3 }; + +protected: + QSqlQueryModel* sqlTableModel; + virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) = 0; + virtual void filterById(int id) = 0; + virtual void clearFilters() = 0; + int countRows(QString tableName, QString columnName, int id) const; + static const QString DB_TABLE_NAME_FILE; + static const QString DB_TABLE_NAME_FILEPATH; + static const QString DB_TABLE_NAME_MEDIATYPE; + static const QString DB_TABLE_NAME_PLATFORM; + static const QString DB_TABLE_NAME_SETUP; private: - //static QSqlDatabase db; static const QString DB_FILENAME; - static const QString DB_TABLE_NAME_PLATFORM; + static const QString DATABASE; + virtual QSqlQueryModel* getData() = 0; static QString getDbPath(); - }; #endif