--- /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 "emufrontfile.h"
+
+EmuFrontFile::EmuFrontFile() : EmuFrontObject() { }
+
+EmuFrontFile::EmuFrontFile(int id, QString name, QString checksum, int size, int type)
+ : EmuFrontObject(id, name), checkSum(checksum), size(size), type(type) { }
+
+QString EmuFrontFile::getCheckSum() const
+{ return checkSum; }
+
+void EmuFrontFile::setCheckSum(QString s)
+{ checkSum = s; }
+
+int EmuFrontFile::getSize() const
+{ return size; }
+
+void EmuFrontFile::setSize(int s)
+{ size = s; }
+
+void EmuFrontFile::setType(int t)
+{ type = t; }
+
+int EmuFrontFile::getType() const
+{ return type; }
--- /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 EMUFRONTFILE_H
+#define EMUFRONTFILE_H
+
+#include "emufrontobject.h"
+
+class EmuFrontFile : public EmuFrontObject
+{
+public:
+ EmuFrontFile();
+ EmuFrontFile(int id, QString name, QString checksum, int size, int type);
+ QString getCheckSum() const;
+ void setCheckSum(QString);
+ int getSize() const;
+ void setSize(int);
+ void setType(int);
+ int getType() const;
+
+ enum {
+ FileType_MediaImageContainerDir = 1,
+ FileType_MediaImageContainer,
+ FileType_MediaImage,
+ FileType_ScreenShot,
+ FileType_PlatformIconPath,
+ FileType_MediaTypeIconPath
+ };
+
+protected:
+ QString checkSum;
+ int size;
+ int type;
+};
+
+#endif // EMUFRONTFILE_H
#include "emufrontfileobject.h"
-EmuFrontFileObject::EmuFrontFileObject() : EmuFrontObject(-1, ""), filename(""), filetype(-1)
-{ }
+EmuFrontFileObject::EmuFrontFileObject()
+ : EmuFrontObject(-1, ""), file(0) { }
-EmuFrontFileObject::EmuFrontFileObject(int id, QString name, QString filename)
- : EmuFrontObject(id, name), filename(filename), filetype(-1)
-{}
+EmuFrontFileObject::EmuFrontFileObject(int id, QString name, EmuFrontFile *file)
+ : EmuFrontObject(id, name), file(file) {}
-EmuFrontFileObject::EmuFrontFileObject(int id, QString name, QString filename, int filetype)
- : EmuFrontObject(id, name), filename(filename), filetype(filetype)
-{}
+EmuFrontFileObject::EmuFrontFileObject(const EmuFrontFileObject &pl)
+ : EmuFrontObject(pl.id, pl.name)
+{
+ EmuFrontFile *f = pl.file;
+ file = new EmuFrontFile(*f);
+}
+EmuFrontFileObject::~EmuFrontFileObject()
+{
+ if (file) delete file;
+}
-/*EmuFrontFileObject::EmuFrontFileObject(const EmuFrontFileObject&pl)
- : EmuFrontObject(pl.id, pl.name), filename(pl.filename)
+EmuFrontFileObject& EmuFrontFileObject::operator =(const EmuFrontFileObject &ob)
{
- // no need to perform deep copy here, see:
- // http://doc.trolltech.com/4.0/shclass.html
-}*/
+ if (this == &ob) return (*this);
+ id = ob.id;
+ name = ob.name;
+ if (file) delete file;
+ EmuFrontFile *f = ob.file;
+ file = new EmuFrontFile(*f);
+ return (*this);
+}
#define EMUFRONTFILEOBJECT_H
#include "emufrontobject.h"
+#include "emufrontfile.h"
class EmuFrontFileObject : public EmuFrontObject
{
public:
EmuFrontFileObject();
- EmuFrontFileObject( int id, QString name, QString filename);
- EmuFrontFileObject( int id, QString name, QString filename, int filetype);
+ EmuFrontFileObject(int id, QString name, EmuFrontFile *file);
+ EmuFrontFileObject(const EmuFrontFileObject&);
+ EmuFrontFileObject& operator=(const EmuFrontFileObject&);
+ ~EmuFrontFileObject();
- // No need for these as long we use QString (see Implicit Data Sharing)
- /*EmuFrontFileObject(const EmuFrontFileObject&);
- EmuFrontFileObject &operator=(const EmuFrontFileObject&);
- virtual ~EmuFrontFileObject();*/
-
- const QString getFilename() const
- { return filename; }
- void setFilename(QString filename)
- { this->filename = filename; }
- int getFiletype() const
- { return filetype; }
- void setFiletype(int t)
- { filetype = t; }
-
- enum {
- FileType_MediaImageContainerDir = 0,
- FileType_MediaImageContainer,
- FileType_MediaImage,
- FileType_ScreenShot,
- FileType_PlatformIconPath,
- FileType_MediaTypeIconPath
- };
+ EmuFrontFile* getFile() const
+ { return file; }
+ void setFile(EmuFrontFile *file)
+ { this->file = file; }
protected:
- QString filename;
- int filetype;
+ EmuFrontFile *file;
};
#endif // EMUFRONTFILEOBJECT_H
+// 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 "filepathobject.h"
#include "setup.h"
-FilePathObject::FilePathObject() : EmuFrontFileObject(), setup(0)
-{
-}
+FilePathObject::FilePathObject() : EmuFrontObject(), setup(0)
+{ }
-FilePathObject::FilePathObject(int id, QString name, QString filename, int filetype)
- : EmuFrontFileObject(id, name, filename, filetype), setup(0) {}
+FilePathObject::FilePathObject(int id, QString name, int filetype)
+ : EmuFrontObject(id, name), type(filetype), setup(0) {}
- FilePathObject::FilePathObject(int id, QString name, QString filename,
- int filetype, Setup *setup)
- : EmuFrontFileObject(id, name, filename, filetype), setup(setup) {}
+ FilePathObject::FilePathObject(int id, QString name, int filetype, Setup *setup)
+ : EmuFrontObject(id, name), type(filetype), setup(setup) {}
FilePathObject::~FilePathObject()
{
}
FilePathObject::FilePathObject(const FilePathObject &fpobj)
- : EmuFrontFileObject(fpobj.id, fpobj.name, fpobj.filename, fpobj.filetype)
+ : EmuFrontObject(fpobj.id, fpobj.name), type(fpobj.type)
{
Setup *s = fpobj.setup;
setup = new Setup(*s);
if (this == &fpobj) return *this;
id = fpobj.id;
name = fpobj.name;
- filename = fpobj.filename;
- filetype = fpobj.filetype;
+ type = fpobj.type;
if (setup) delete setup;
Setup *sup = fpobj.setup;
setup = new Setup(*sup);
{ return setup; }
void FilePathObject::setSetup(Setup *sup)
{ setup = sup; }
+
+int FilePathObject::getType() const
+{ return type; }
+void FilePathObject::setType(int t)
+{ type = t; }
class Setup;
-class FilePathObject : public EmuFrontFileObject
+class FilePathObject : public EmuFrontObject
{
public:
FilePathObject();
~FilePathObject();
- FilePathObject(int id, QString name, QString filename, int filetype);
- FilePathObject(int id, QString name, QString filename, int filetype, Setup*);
+ FilePathObject(int id, QString name, int filetype);
+ FilePathObject(int id, QString name, int filetype, Setup*);
FilePathObject(const FilePathObject &);
FilePathObject& operator=(const FilePathObject &);
Setup* getSetup() const;
void setSetup(Setup *);
+ int getType() const;
+ void setType(int);
private:
+ int type;
Setup *setup;
};
{
}
-MediaType::MediaType(int id, QString name, QString filename)
- : EmuFrontFileObject(id, name, filename)
+MediaType::MediaType(int id, QString name, EmuFrontFile *file)
+ : EmuFrontFileObject(id, name, file)
{
}
{
public:
MediaType();
- MediaType(int id, QString name, QString filename);
+ MediaType(int id, QString name);
+ MediaType(int id, QString name, EmuFrontFile*);
};
#endif // MEDIATYPE_H
#include "platform.h"
-Platform::Platform() : EmuFrontFileObject()
-{
-}
+Platform::Platform() : EmuFrontFileObject() { }
+
+Platform::Platform(int id, QString name)
+ : EmuFrontFileObject(id, name, 0) { }
-Platform::Platform(int id, QString name, QString filename)
- : EmuFrontFileObject(id, name, filename)
+Platform::Platform(int id, QString name, EmuFrontFile *file)
+ : EmuFrontFileObject(id, name, file)
{
}
{
public:
Platform();
- Platform(int id, QString name, QString filename);
+ Platform(int id, QString name);
+ Platform(int id, QString name, EmuFrontFile*);
};
#endif // PLATFORM_H
const QString DatabaseManager::DATABASE = QString("QSQLITE");
const QString DatabaseManager::DB_TABLE_NAME_MEDIATYPE = QString("mediatype");
const QString DatabaseManager::DB_TABLE_NAME_PLATFORM = QString("platform");
+const QString DatabaseManager::DB_TABLE_NAME_FILE= QString("file");
const QString DatabaseManager::DB_TABLE_NAME_FILEPATH = QString("filepath");
const QString DatabaseManager::DB_TABLE_NAME_SETUP = QString("setup");
DatabaseManager::DatabaseManager(QObject *parent)
: QObject(parent)
-{}
+{
+ sqlTableModel = 0;
+}
DatabaseManager::~DatabaseManager()
{
protected:
QSqlQueryModel* sqlTableModel;
- virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) const = 0;
+ 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;
ret = query.exec("CREATE TABLE IF NOT EXISTS file"
"(id INTEGER PRIMARY KEY, "
- "filename TEXT, "
- "filetype INTEGER, "
- "crc32 TEXT, "
- "md5 TEXT, "
- "sha1 TEXT, "
- "filesize INTEGER, "
+ "name TEXT, "
+ "type INTEGER, "
+ "checksum TEXT, "
+ "size INTEGER, "
"updatetime NUMERIC)");
qDebug() << "Creating TABLE platform";
ret = query.exec("CREATE TABLE IF NOT EXISTS platform "
"(id INTEGER PRIMARY KEY, "
"name TEXT, "
- "iconfileid INTEGER REFERENCES file(id))");
+ "fileid INTEGER REFERENCES file(id))");
if (!ret) throw QString("platform.");
ret = query.exec("CREATE TABLE IF NOT EXISTS mediatype "
"(id INTEGER PRIMARY KEY, "
"name TEXT, "
- "iconfileid INTEGER REFERENCES file(id))");
+ "fileid INTEGER REFERENCES file(id))");
if (!ret) throw QString("mediatype.");
--- /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 <QSqlRecord>
+#include <QSqlQuery>
+#include <QSqlRelationalTableModel>
+#include <QDebug>
+#include "dbemufrontfileobject.h"
+
+DbEmuFrontFileObject::DbEmuFrontFileObject(QObject *parent)
+ : DbTableModelManager(parent)
+{
+ dbFile = new DbFile(this);
+}
+
+EmuFrontObject* DbEmuFrontFileObject::recordToDataObject(const QSqlRecord *record)
+{
+ int id = record->value(EmuFrontFileObject_Id).toInt();
+ QString name = record->value(EmuFrontFileObject_Name).toString();
+ int fileId = record->value(EmuFrontFileObject_FileId).toInt();
+ EmuFrontFile *f = 0;
+ if (fileId > 0)
+ {
+ EmuFrontObject *o = dbFile->getDataObject(fileId);
+ f = dynamic_cast<EmuFrontFile*>(o);
+ }
+ EmuFrontObject *efo = createEmuFrontFileObject(id, name, f);
+ return efo;
+}
+
+bool DbEmuFrontFileObject::updateDataObjectToModel(const EmuFrontObject *ob)
+{
+ const EmuFrontFileObject *plf = dynamic_cast<const EmuFrontFileObject*>(ob);
+ bool ret = false;
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->setFilter(QString("id = %1").arg(plf->getId()));
+ tmodel->select();
+ if (tmodel->rowCount() == 1)
+ {
+ QSqlRecord record = tmodel->record(0);
+ record.setValue("name", plf->getName());
+ if (plf->getFile())
+ record.setValue("fileid", plf->getFile()->getId());
+ else record.setNull("fileid");
+ tmodel->setRecord(0, record);
+ ret = tmodel->submitAll();
+ }
+ resetModel();
+ return ret;
+}
+
+bool DbEmuFrontFileObject::insertDataObjectToModel(const EmuFrontObject *ob)
+{
+ const EmuFrontFileObject *plf = dynamic_cast<const EmuFrontFileObject *>(ob);
+ int row = 0;
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->insertRows(row, 1);
+ // the null value for index will be set implicitily
+ // when we don't assign any value to cell 0 in the sql table model
+ //sqlTableModel->setData(sqlTableModel->index(row, 0), NULL);
+ tmodel->setData(sqlTableModel->index(row, EmuFrontFileObject_Name), plf->getName());
+ if (plf->getFile())
+ tmodel->setData(sqlTableModel->index(row, EmuFrontFileObject_FileId), plf->getFile()->getId());
+ return tmodel->submitAll();
+}
+
+int DbEmuFrontFileObject::countDataObjectRefs(int id) const
+{
+ return 0; // TODO
+ // return countRows("imagecontainer", "platformid", id);
+}
+
+// WARNING: this will delete also all the databindings to selected platform
+bool DbEmuFrontFileObject::deleteDataObjectFromModel(QModelIndex *index)
+{
+ //QSqlDatabase::database().transaction();
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ /*QSqlRecord record = tmodel->record(index->row());
+ int id = record.value(EmuFrontFileObject_Id).toInt();
+ qDebug() << "Deleting platform " << id;
+ int count = countDataObjectRefs(id);
+ if (count > 0)
+ {
+ QSqlQuery query;
+ if (!query.exec(QString("DELETE FROM imagecontainer WHERE platformid = %1").arg(id)))
+ {
+ qDebug() << "Deleting data bindings failed!";
+ QSqlDatabase::database().rollback();
+ return false;
+ }
+ }*/
+ tmodel->removeRow(index->row());
+ tmodel->submitAll();
+ return QSqlDatabase::database().commit();
+}
+
+QSqlQueryModel* DbEmuFrontFileObject::getData()
+{
+ QSqlRelationalTableModel *model = new QSqlRelationalTableModel(this);
+ model->setTable(tableName);
+ model->setRelation(EmuFrontFileObject_FileId, QSqlRelation("file", "id", "name"));
+ model->setSort(EmuFrontFileObject_Name, Qt::AscendingOrder);
+ model->setHeaderData(EmuFrontFileObject_Name, Qt::Horizontal, tr("Name"));
+ model->setHeaderData(EmuFrontFileObject_FileId, Qt::Horizontal, tr("Icon"));
+ model->select();
+ return model;
+}
--- /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 DBEMUFRONTFILEOBJECT_H
+#define DBEMUFRONTFILEOBJECT_H
+
+#include "dbtablemodelmanager.h"
+#include "dbfile.h"
+#include "dataobjects/emufrontfileobject.h"
+
+class DbEmuFrontFileObject : public DbTableModelManager
+{
+public:
+ DbEmuFrontFileObject(QObject *parent);
+ virtual bool updateDataObjectToModel(const EmuFrontObject*);
+ bool insertDataObjectToModel(const EmuFrontObject*);
+ bool deleteDataObjectFromModel(QModelIndex*);
+ int countDataObjectRefs(int) const;
+ enum {
+ EmuFrontFileObject_Id= 0,
+ EmuFrontFileObject_Name,
+ EmuFrontFileObject_FileId };
+
+protected:
+ virtual EmuFrontObject* recordToDataObject(const QSqlRecord* );
+ QString tableName;
+ virtual EmuFrontObject* createEmuFrontFileObject(int id, QString name, EmuFrontFile *f) = 0;
+
+private:
+ virtual QSqlQueryModel* getData();
+ DbFile *dbFile;
+};
+
+#endif // DBEMUFRONTFILEOBJECT_H
--- /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 <QSqlRecord>
+#include <QSqlQuery>
+#include <QSqlTableModel>
+#include <QDateTime>
+#include "dbfile.h"
+
+DbFile::DbFile(QObject *parent) : DbTableModelManager(parent)
+{ }
+
+EmuFrontObject* DbFile::recordToDataObject(const QSqlRecord *record)
+{
+ int id = record->value(File_Id).toInt();
+ QString name = record->value(File_Name).toString();
+ QString checksum = record->value(File_CheckSum).toString();
+ int size = record->value(File_FileSize).toInt();
+ int type = record->value(File_FileType).toInt();
+ return new EmuFrontFile(id, name, checksum, size, type);
+}
+
+bool DbFile::updateDataObjectToModel(const EmuFrontObject *ob)
+{
+ const EmuFrontFile *plf = dynamic_cast<const EmuFrontFile*>(ob);
+ bool ret = false;
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->setFilter(QString("id = %1").arg(plf->getId()));
+ tmodel->select();
+ if (tmodel->rowCount() == 1)
+ {
+ QSqlRecord record = tmodel->record(0);
+ record.setValue("name", plf->getName());
+ record.setValue("type", plf->getType());
+ record.setValue("checksum", plf->getCheckSum());
+ record.setValue("size", plf->getSize());
+ record.setValue("updatetime", QDateTime::currentDateTime().toTime_t());
+ tmodel->setRecord(0, record);
+ ret = tmodel->submitAll();
+ }
+ resetModel();
+ return ret;
+}
+
+bool DbFile::insertDataObjectToModel(const EmuFrontObject *ob)
+{
+ const EmuFrontFile *plf = dynamic_cast<const EmuFrontFile*>(ob);
+ int row = 0;
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ tmodel->insertRows(row, 1);
+ // the null value for index will be set implicitily
+ // when we don't assign any value to cell 0 in the sql table model
+ //sqlTableModel->setData(sqlTableModel->index(row, 0), NULL);
+ tmodel->setData(sqlTableModel->index(row, File_Name), plf->getName());
+ tmodel->setData(sqlTableModel->index(row, File_FileType), plf->getType());
+ tmodel->setData(sqlTableModel->index(row, File_CheckSum), plf->getCheckSum());
+ tmodel->setData(sqlTableModel->index(row, File_FileSize), plf->getSize());
+ tmodel->setData(sqlTableModel->index(row, File_UpdateTime),
+ QDateTime::currentDateTime().toTime_t());
+ return tmodel->submitAll();
+}
+
+int DbFile::countDataObjectRefs(int id) const
+{
+ return 0; // TODO
+ // return countRows("imagecontainer", "platformid", id);
+}
+
+// WARNING: this will delete also all the databindings to selected platform
+// the delete must be confirmed in the UI
+bool DbFile::deleteDataObjectFromModel(QModelIndex *index)
+{
+ /*QSqlDatabase::database().transaction();*/
+ QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
+ /*QSqlRecord record = tmodel->record(index->row());
+ int id = record.value(File_Id).toInt();
+ int count = countDataObjectRefs(id);
+ if (count > 0)
+ {
+ QSqlQuery query;
+ if (!query.exec(QString("DELETE FROM imagecontainer WHERE platformid = %1").arg(id)))
+ {
+ qDebug() << "Deleting data bindings failed!";
+ QSqlDatabase::database().rollback();
+ return false;
+ }
+ }*/
+ tmodel->removeRow(index->row());
+ tmodel->submitAll();
+ return QSqlDatabase::database().commit();
+}
+
+QSqlQueryModel* DbFile::getData()
+{
+ QSqlTableModel *model = new QSqlTableModel(this);
+ model->setTable(DB_TABLE_NAME_FILE);
+ model->setSort(File_Name, Qt::AscendingOrder);
+ model->setHeaderData(File_Name, Qt::Horizontal, tr("Name"));
+ model->setHeaderData(File_FileType, Qt::Horizontal, tr("Type"));
+ model->setHeaderData(File_CheckSum, Qt::Horizontal, tr("Checksum"));
+ model->setHeaderData(File_FileSize, Qt::Horizontal, tr("Size"));
+ model->setHeaderData(File_UpdateTime, Qt::Horizontal, tr("Updated"));
+ model->select();
+ return model;
+}
--- /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 DBFILE_H
+#define DBFILE_H
+
+#include "dbtablemodelmanager.h"
+#include "../dataobjects/emufrontfile.h"
+
+class DbFile : public DbTableModelManager
+{
+public:
+ DbFile(QObject*);
+ virtual bool updateDataObjectToModel(const EmuFrontObject*);
+ bool insertDataObjectToModel(const EmuFrontObject*);
+ bool deleteDataObjectFromModel(QModelIndex*);
+ int countDataObjectRefs(int) const;
+ enum {
+ File_Id = 0,
+ File_Name,
+ File_FileType,
+ File_CheckSum,
+ File_FileSize,
+ File_UpdateTime };
+
+protected:
+ virtual EmuFrontObject* recordToDataObject(const QSqlRecord*);
+
+private:
+ virtual QSqlQueryModel* getData();
+};
+
+#endif // DBFILE_H
DbFilePath::DbFilePath(QObject *parent) : DbQueryModelManager(parent)
{
dbSetup = new DbSetup(this);
- sqlTableModel = 0; //getData();
}
-EmuFrontObject* DbFilePath::recordToDataObject(const QSqlRecord *rec) const
+EmuFrontObject* DbFilePath::recordToDataObject(const QSqlRecord *rec)
{
int id = rec->value(FilePath_Id).toInt();
QString fpath = rec->value(FilePath_Name).toString();
Setup *sup = dynamic_cast<Setup*>(dbSetup->getDataObject(setupId));
// TODO
//int lastScanned = 0;
- return new FilePathObject(id, fpath, fpath, 0, sup);
+ return new FilePathObject(id, fpath, /* TODO */ 0, sup);
}
bool DbFilePath::updateDataObjectToModel(const EmuFrontObject *ob)
"lastscanned=:lastscanned "
"WHERE id=:id"));
query.bindValue(":name", fpo->getName());
- query.bindValue(":filetypeid", fpo->getFiletype());
+ query.bindValue(":filetypeid", fpo->getType());
query.bindValue(":lastscanned", 0); // TODO
query.bindValue(":id", fpo->getId());
ret = query.exec();
query.prepare("INSERT INTO filepath (id, name, filetypeid, setupid, lastscanned) "
"VALUES (NULL, :name, :filetypeid, :setupid, :lastscanned) ");
query.bindValue(":name", fpo->getName());
- query.bindValue(":filetypeid", fpo->getFiletype());
+ query.bindValue(":filetypeid", fpo->getType());
if (fpo->getSetup())
query.bindValue(":setupid", fpo->getSetup()->getId());
query.bindValue(":lastscanned", 0); // TODO
FilePath_SetupName };
protected:
- virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) const;
+ virtual EmuFrontObject* recordToDataObject(const QSqlRecord* );
virtual QString constructSelectById(int id) const;
virtual QString constructSelect(QString whereClause = "") const;
// You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
-#include <QSqlRecord>
-#include <QSqlQuery>
-#include <QSqlTableModel>
-#include <QDebug>
#include "dbmediatype.h"
-#include "../dataobjects/mediatype.h"
+QString DbMediaType::tableName = DbMediaType::DB_TABLE_NAME_MEDIATYPE;
-DbMediaType::DbMediaType(QObject *parent) : DbTableModelManager(parent)
-{
- qDebug() << "Creating Media type database manager";
- sqlTableModel = 0; //getData();
-}
-
-EmuFrontObject* DbMediaType::recordToDataObject(const QSqlRecord *record) const
-{
- int id = record->value(MediaType_Id).toInt();
- QString name = record->value(MediaType_Name).toString();
- QString fileName = record->value(MediaType_Filename).toString();
- return new MediaType(id, name, fileName);
-}
-
-bool DbMediaType::updateDataObjectToModel(const EmuFrontObject *ob)
-{
- const MediaType *plf = dynamic_cast<const MediaType*>(ob);
- bool ret = false;
- QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
- tmodel->setFilter(QString("id = %1").arg(plf->getId()));
- tmodel->select();
- if (tmodel->rowCount() == 1)
- {
- QSqlRecord record = sqlTableModel->record(0);
- record.setValue("name", plf->getName());
- record.setValue("filename", plf->getFilename());
- tmodel->setRecord(0, record);
- ret = tmodel->submitAll();
- }
- resetModel();
- return ret;
-}
-
-bool DbMediaType::insertDataObjectToModel(const EmuFrontObject *ob)
-{
- const MediaType *plf = dynamic_cast<const MediaType*>(ob);
- int row = 0;
- QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
- tmodel->insertRows(row, 1);
- // the null value for index will be set implicitily
- // when we don't assign any value to cell 0 in the sql table model
- //sqlTableModel->setData(sqlTableModel->index(row, 0), NULL);
- tmodel->setData(sqlTableModel->index(row, MediaType_Name), plf->getName());
- tmodel->setData(sqlTableModel->index(row, MediaType_Filename), plf->getFilename());
- return tmodel->submitAll();
-}
-
-int DbMediaType::countDataObjectRefs(int id) const
-{
- return countRows("imagecontainer", "mediatypeid", id);
-}
-
-// WARNING: this will delete also all the databindings to selected platform
-bool DbMediaType::deleteDataObjectFromModel(QModelIndex *index)
-{
- QSqlDatabase::database().transaction();
- QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
- QSqlRecord record = tmodel->record(index->row());
- int id = record.value(MediaType_Id).toInt();
- qDebug() << "Deleting mediatype " << id;
- int count = countDataObjectRefs(id);
- if (count > 0)
- {
- QSqlQuery query;
- if (!query.exec(QString("DELETE FROM imagecontainer WHERE mediatypeid = %1").arg(id)))
- {
- qDebug() << "Deleting data bindings failed!";
- QSqlDatabase::database().rollback();
- return false;
- }
- }
- tmodel->removeRow(index->row());
- tmodel->submitAll();
- return QSqlDatabase::database().commit();
-}
-
-QSqlQueryModel* DbMediaType::getData()
-{
- QSqlTableModel *model = new QSqlTableModel(this);
- model->setTable(DB_TABLE_NAME_MEDIATYPE);
- model->setSort(MediaType_Name, Qt::AscendingOrder);
- model->setHeaderData(MediaType_Name, Qt::Horizontal, tr("Name"));
- model->select();
- qDebug() << "Created a data model for media type data";
- return model;
-}
+DbMediaType::DbMediaType(QObject *parent) : DbEmuFrontFileObject(parent)
+{ }
+EmuFrontObject* DbMediaType::createEmuFrontFileObject(int id, QString name, EmuFrontFile *f)
+{ return new MediaType(id, name, f); }
#ifndef DBMEDIATYPE_H
#define DBMEDIATYPE_H
-#include "dbtablemodelmanager.h"
+#include "dbemufrontfileobject.h"
#include "../dataobjects/mediatype.h"
-class DbMediaType : public DbTableModelManager
+class DbMediaType : public DbEmuFrontFileObject
{
public:
DbMediaType(QObject *);
- virtual bool updateDataObjectToModel(const EmuFrontObject*);
- virtual bool insertDataObjectToModel(const EmuFrontObject*);
- virtual bool deleteDataObjectFromModel(QModelIndex*);
- virtual int countDataObjectRefs(int) const;
- enum {
- MediaType_Id = 0,
- MediaType_Name = 1,
- MediaType_Filename = 2 };
protected:
- virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) const;
-
-private:
- virtual QSqlQueryModel* getData();
-
+ static QString tableName;
+ virtual EmuFrontObject* createEmuFrontFileObject(int id, QString name, EmuFrontFile *f);
};
#endif // DBMEDIATYPE_H
// You should have received a copy of the GNU General Public License
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
-#include <QSqlRecord>
-#include <QSqlQuery>
-#include <QSqlTableModel>
-#include <QDebug>
#include "dbplatform.h"
+QString DbPlatform::tableName = DbPlatform::DB_TABLE_NAME_PLATFORM;
-DbPlatform::DbPlatform(QObject *parent) : DbTableModelManager(parent)
-{
- sqlTableModel = 0; //getData();
-}
+DbPlatform::DbPlatform(QObject *parent) : DbEmuFrontFileObject(parent)
+{ }
-EmuFrontObject* DbPlatform::recordToDataObject(const QSqlRecord *record) const
-{
- int id = record->value(Platform_Id).toInt();
- QString name = record->value(Platform_Name).toString();
- QString fileName = record->value(Platform_Filename).toString();
- //qDebug() << "Got platform Name " << name << " id " << id;
- return new Platform(id, name, fileName);
-}
-
-bool DbPlatform::updateDataObjectToModel(const EmuFrontObject *ob)
-{
- const Platform *plf = dynamic_cast<const Platform*>(ob);
- bool ret = false;
- QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
- tmodel->setFilter(QString("id = %1").arg(plf->getId()));
- tmodel->select();
- if (tmodel->rowCount() == 1)
- {
- QSqlRecord record = tmodel->record(0);
- record.setValue("name", plf->getName());
- record.setValue("filename", plf->getFilename());
- tmodel->setRecord(0, record);
- ret = tmodel->submitAll();
- }
- resetModel();
- return ret;
-}
-
-bool DbPlatform::insertDataObjectToModel(const EmuFrontObject *ob)
-{
- const Platform *plf = dynamic_cast<const Platform*>(ob);
- int row = 0;
- QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
- tmodel->insertRows(row, 1);
- // the null value for index will be set implicitily
- // when we don't assign any value to cell 0 in the sql table model
- //sqlTableModel->setData(sqlTableModel->index(row, 0), NULL);
- tmodel->setData(sqlTableModel->index(row, 1), plf->getName());
- tmodel->setData(sqlTableModel->index(row, 2), plf->getFilename());
- return tmodel->submitAll();
-}
-
-int DbPlatform::countDataObjectRefs(int id) const
-{
- return countRows("imagecontainer", "platformid", id);
-}
-
-// WARNING: this will delete also all the databindings to selected platform
-bool DbPlatform::deleteDataObjectFromModel(QModelIndex *index)
-{
- QSqlDatabase::database().transaction();
- QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
- QSqlRecord record = tmodel->record(index->row());
- int id = record.value(Platform_Id).toInt();
- qDebug() << "Deleting platform " << id;
- int count = countDataObjectRefs(id);
- if (count > 0)
- {
- QSqlQuery query;
- if (!query.exec(QString("DELETE FROM imagecontainer WHERE platformid = %1").arg(id)))
- {
- qDebug() << "Deleting data bindings failed!";
- QSqlDatabase::database().rollback();
- return false;
- }
- }
- tmodel->removeRow(index->row());
- tmodel->submitAll();
- return QSqlDatabase::database().commit();
-}
-
-QSqlQueryModel* DbPlatform::getData()
-{
- QSqlTableModel *model = new QSqlTableModel(this);
- model->setTable(DB_TABLE_NAME_PLATFORM);
- model->setSort(Platform_Name, Qt::AscendingOrder);
- model->setHeaderData(Platform_Name, Qt::Horizontal, tr("Name"));
- model->select();
- return model;
-}
-
-/*void DbPlatform::filterById(int id)
-{
- QSqlTableModel *tmodel = dynamic_cast<QSqlTableModel*>(sqlTableModel);
- tmodel->setFilter(QString("id = %1").arg(id));
- tmodel->setQuery(constructSelectById(id));
- tmodel->select();
-}*/
+EmuFrontObject* DbPlatform::createEmuFrontFileObject(int id, QString name, EmuFrontFile *f)
+{ return new Platform(id, name, f); }
#ifndef DBPLATFORM_H
#define DBPLATFORM_H
-#include "dbtablemodelmanager.h"
+#include "dbemufrontfileobject.h"
#include "../dataobjects/platform.h"
class QModelIndex;
-class DbPlatform : public DbTableModelManager
+
+class DbPlatform : public DbEmuFrontFileObject
{
public:
DbPlatform(QObject *);
- virtual bool updateDataObjectToModel(const EmuFrontObject*);
- bool insertDataObjectToModel(const EmuFrontObject*);
- bool deleteDataObjectFromModel(QModelIndex*);
- int countDataObjectRefs(int) const;
- enum {
- Platform_Id = 0,
- Platform_Name = 1,
- Platform_Filename = 2 };
protected:
- virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) const;
-
-private:
- virtual QSqlQueryModel* getData();
+ static QString tableName;
+ virtual EmuFrontObject* createEmuFrontFileObject(int id, QString name, EmuFrontFile *f);
};
#endif // DBPLATFORM_H
{
dbPlatform = new DbPlatform(this);
dbMediaType = new DbMediaType(this);
- sqlTableModel = 0; //getData();
}
-EmuFrontObject* DbSetup::recordToDataObject(const QSqlRecord *rec) const
+EmuFrontObject* DbSetup::recordToDataObject(const QSqlRecord *rec)
{
Setup *s = 0;
if (!rec) return s;
static const QString FILE_TYPE_EXTENSION_SEPARATOR;
protected:
- virtual EmuFrontObject* recordToDataObject(const QSqlRecord* ) const;
+ virtual EmuFrontObject* recordToDataObject(const QSqlRecord* );
virtual QString constructSelectById(int id) const;
virtual QString constructSelect(QString whereClause = "") const;
dbManager = new DbMediaType(this);
initDataTable();
initEditDialog();
- objectList->hideColumn(DbMediaType::MediaType_Id);
+ objectList->hideColumn(DbMediaType::EmuFrontFileObject_FileId);
// do not move to parent class:
connectSignals();
void MediaTypeNameDialog::setDataObject(QString name)
{
efObject->setName(name);
- (dynamic_cast<MediaType*>(efObject))->setFilename("");
+ (dynamic_cast<MediaType*>(efObject))->setFile(0);
}
void MediaTypeNameDialog::setDataObject(EmuFrontObject *ob)
dbManager = new DbPlatform(this);
initDataTable();
initEditDialog();
- objectList->hideColumn(DbPlatform::Platform_Id);
+ objectList->hideColumn(DbPlatform::EmuFrontFileObject_Id);
// do not move to parent class:
connectSignals();
void PlatformNameDialog::setDataObject(QString name)
{
efObject->setName(name);
- (dynamic_cast<Platform*>(efObject))->setFilename("");
+ (dynamic_cast<Platform*>(efObject))->setFile(0);
}
void PlatformNameDialog::setDataObject(EmuFrontObject *ob)
if (!model) return;
qDebug() << "We have a media type data model";
mediaTypeComBox->setModel(model);
- mediaTypeComBox->setModelColumn(DbMediaType::MediaType_Name);
+ mediaTypeComBox->setModelColumn(DbMediaType::EmuFrontFileObject_Name);
}
void SetupEditDialog::populatePlatformComBox()
QSqlQueryModel *model = dbPlatform->getDataModel();
if (!model) return;
platformComBox->setModel(model);
- platformComBox->setModelColumn(DbPlatform::Platform_Name);
+ platformComBox->setModelColumn(DbPlatform::EmuFrontFileObject_Name);
qDebug() << "platform combo box populated";
}
void SetupEditDialog::setSelectedPlatform(const Platform *plf)
{
- setSelected(platformComBox, plf, DbPlatform::Platform_Id);
+ setSelected(platformComBox, plf, DbPlatform::EmuFrontFileObject_Id);
}
void SetupEditDialog::setSelectedMediaType(const MediaType *plf)
{
- setSelected(mediaTypeComBox, plf, DbMediaType::MediaType_Id);
+ setSelected(mediaTypeComBox, plf, DbMediaType::EmuFrontFileObject_Id);
}
Platform* SetupEditDialog::getSelectedPlatform() const
{
- qDebug() << "MediaImagePathDialog Selecting platform";
Platform *plf = 0;
int index = platformComBox->currentIndex();
- qDebug() << "Current index " << index;
if (index < 0) return plf;
QSqlTableModel* platformModel = dynamic_cast<QSqlTableModel*>(platformComBox->model());
if (!platformModel)
{
- qDebug() << "Data model missing";
return plf;
}
QSqlRecord rec = platformModel->record(index);
if (!rec.isEmpty())
{
- qDebug() << "We have a record";
- plf = new Platform(rec.value(DbPlatform::Platform_Id).toInt(),
- rec.value(DbPlatform::Platform_Name).toString(),
- rec.value(DbPlatform::Platform_Filename).toString());
+ EmuFrontObject *o = dbPlatform->getDataObject(rec.value(DbPlatform::EmuFrontFileObject_Id).toInt());
+ plf = dynamic_cast<Platform*>(o);
}
- else qDebug() << "Record missing";
return plf;
}
}
QSqlRecord rec = mediaTypeModel->record(index);
if (!rec.isEmpty())
- mt = new MediaType(rec.value(DbMediaType::MediaType_Id).toInt(),
- rec.value(DbMediaType::MediaType_Name).toString(),
- rec.value(DbMediaType::MediaType_Filename).toString());
+ {
+ EmuFrontObject *o = dbMediaType->getDataObject(rec.value(DbMediaType::EmuFrontFileObject_Id).toInt());
+ mt = dynamic_cast<MediaType*>(o);
+ }
return mt;
}
widgets/stringlistwidget.h \
exceptions/emufrontexception.h \
dataobjects/mediaimage.h \
- dataobjects/mediaimagecontainer.h
+ dataobjects/mediaimagecontainer.h \
+ dataobjects/emufrontfile.h \
+ db/dbfile.h \
+ db/dbemufrontfileobject.h
SOURCES += main.cpp \
mainwindow.cpp \
db/databasemanager.cpp \
widgets/stringlistwidget.cpp \
exceptions/emufrontexception.cpp \
dataobjects/mediaimage.cpp \
- dataobjects/mediaimagecontainer.cpp
+ dataobjects/mediaimagecontainer.cpp \
+ dataobjects/emufrontfile.cpp \
+ db/dbfile.cpp \
+ db/dbemufrontfileobject.cpp
OTHER_FILES +=