#include <QFile>
#include <QDir>
#include <QVariant>
-#include <iostream>
const QString DatabaseManager::DB_FILENAME = QString("my.db.sqlite");
+const QString DatabaseManager::DATABASE = QString("QSQLITE");
DatabaseManager::DatabaseManager(QObject *parent)
: QObject(parent)
return db.open();
}
-bool DatabaseManager::deleteDB()
-{
- // return QFile::remove(getDbPath());
- return false;
-}
-
QString DatabaseManager::getDbPath()
{
QString path;
return path;
}
-/**
- * Check if database already exists.
- * Returns false if doesn't or we don't have a connection.
-*/
-bool DatabaseManager::dbExists()
-{
- QSqlQuery query;
- query.exec("SELECT name FROM sqlite_master WHERE name='platform'");
- return query.next();
-}
-
-bool DatabaseManager::createDB()
-{
- bool ret = false;
- QSqlQuery query;
-
- ret = query.exec("create table platform "
- "(id integer primary key, "
- "name varchar(30), "
- "filename varchar(125))");
- /*ret = query.exec("create table media "
- "(id integer primary key, "
- "name varchar(30), "
- "filename varchar(125))");*/
- return ret;
-}
-
void DatabaseManager::resetModel() const
{
if (!sqlTableModel) return;
virtual QSqlTableModel* getDataModel() = 0;
static bool openDB();
- static bool deleteDB();
- static bool dbExists();
- static bool createDB();
+ //static bool deleteDB();
+ //static bool dbExists();
+ //static bool tableExists(QString);
+ //static bool createDB();
void resetModel() const;
+ enum
+ {
+ Filetype_MediaImageContainer = 0,
+ Filetype_Screenshot = 1,
+ Filetype_PlatformIcon = 2,
+ Filetype_MediaTypeIcon = 3
+ };
protected:
QSqlTableModel *sqlTableModel;
private:
static const QString DB_FILENAME;
+ static const QString DATABASE;
virtual QSqlTableModel* getData() = 0;
static QString getDbPath();
};
--- /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 <QObject>
+#include <QSqlDatabase>
+#include <QSqlQuery>
+#include "dbcreator.h"
+
+DbCreator::DbCreator(QObject *parent) : QObject(parent)
+{
+}
+
+
+bool DbCreator::createDB()
+{
+ bool ret = false;
+ QSqlQuery query;
+
+ if (!tableExists("platform"))
+ {
+ query.exec("create table platform "
+ "(id integer primary key, "
+ "name varchar(30), "
+ "filename varchar(125))");
+ }
+ if (!tableExists("mediatype"))
+ {
+ query.exec("create table mediatype "
+ "(id integer primary key, "
+ "name varchar(30), "
+ "filename varchar(125))");
+ }
+ if (!tableExists("filetype"))
+ {
+ query.exec("create table filetype "
+ "(id integer primary key, "
+ "name varchar(30))");
+ query.exec("insert into filetype (id, name) values (1, 'media image container')");
+ query.exec("insert into filetype (id, name) values (2, 'screenshot')");
+ query.exec("insert into filetype (id, name) values (3, 'platform icon')");
+ query.exec("insert into filetype (id, name) values (4, 'media type icon')");
+ }
+ /*if (!tableExists("filepath"))
+ {
+ query.exec("create table filepath "
+ "(id integer primary key, "
+ "name varchar(255))");
+
+ }*/
+ return ret;
+}
+
+/**
+ * Check if database already exists.
+ * Returns false if doesn't or we don't have a connection.
+*/
+bool DbCreator::dbExists()
+{
+ return tableExists("platform");
+}
+
+bool DbCreator::tableExists(QString table)
+{
+ QSqlQuery query;
+ query.exec(QString("SELECT name FROM sqlite_master WHERE name='%1'").arg(table));
+ return query.next();
+}
+
+bool DbCreator::deleteDB()
+{
+ // return QFile::remove(getDbPath());
+ return false;
+}
--- /dev/null
+#ifndef DBCREATOR_H
+#define DBCREATOR_H
+
+#include <QObject>
+
+class DbCreator : public QObject
+{
+public:
+
+ DbCreator(QObject *parent = 0);
+ bool deleteDB();
+ static bool tableExists(QString);
+ static bool dbExists();
+ bool createDB();
+};
+
+#endif // DBCREATOR_H
dialogs/emufrontdialog.h \
dataobjects/emufrontobject.h \
dataobjects/platform.h \
- db/dbplatform.h
+ db/dbplatform.h \
+ db/dbcreator.h
SOURCES += main.cpp \
mainwindow.cpp \
db/databasemanager.cpp \
dialogs/emufrontdialog.cpp \
dataobjects/emufrontobject.cpp \
dataobjects/platform.cpp \
- db/dbplatform.cpp
+ db/dbplatform.cpp \
+ db/dbcreator.cpp
#include <iostream>
#include "mainwindow.h"
#include "db/databasemanager.h"
+#include "db/dbcreator.h"
+
//#include "dialogs/platformnamedialog.h"
int main(int argc, char *argv[])
cout << " Database opened succesfully!" << endl;
else cout << " Database connection failed!" << endl;
- if (DatabaseManager::dbExists())
+ if (DbCreator::dbExists())
cout << " Database exists!" << endl;
else
{
cout << " Database is missing!" << endl;
- if (DatabaseManager::createDB())
+ DbCreator dbCreator;
+ if (dbCreator.createDB())
cout << " Database created succesfully!" << endl;
else {
cout << "Failed creating database!" << endl;