--- /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.
+//
+// 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+
+#include <QDebug>
+#include "dbmediaimage.h"
+
+DbMediaImage::DbMediaImage(QObject *parent)
+ : DbQueryModelManager(parent)
+{ }
+
+bool DbMediaImage::updateDataObjectToModel(const EmuFrontObject *efo)
+{
+ return false;
+}
+
+bool DbMediaImage::insertDataObjectToModel(const EmuFrontObject *efo)
+{
+ return false;
+}
+
+bool DbMediaImage::deleteDataObjectFromModel(QModelIndex *i)
+{
+ return false;
+}
+
+int DbMediaImage::countDataObjectRefs(int id) const
+{
+ return -1;
+}
+
+QString DbMediaImage::constructSelect(QString whereClause) const
+{
+ return "";
+}
+
+QString DbMediaImage::constructSelectById(int id) const
+{
+ return "";
+}
+
+EmuFrontObject* DbMediaImage::recordToDataObject(const QSqlRecord *)
+{
+ return 0;
+}
+
+QSqlQueryModel* DbMediaImage::getData()
+{
+ return 0;
+}
+
+int DbMediaImage::getMediaImage(QString checksum) const
+{
+ return -1;
+
+}
+
+int DbMediaImage::insertMediaImage(const MediaImage *mi)
+{
+ return -1;
+}
+
+QList<int> DbMediaImage::storeMediaImages(QList<MediaImage *> images)
+{
+ QList<int> ids = QList<int>();
+ foreach(MediaImage* mi, images)
+ {
+ QString cksum = mi->getCheckSum();
+ int id = getMediaImage(cksum);
+ if (id >= 0)
+ {
+ // this media image is already in the database
+ // TODO: what if the name differs?
+ ids.append(id);
+ continue;
+ }
+ if (id < 0)
+ {
+ // insert new media image to db
+ id = insertMediaImage(mi);
+ if (id < 0)
+ {
+ // TODO: Build an error message of failed inserts
+ qDebug() << "Failed inserting media image" << mi->getName();
+ }
+ else
+ {
+ ids.append(id);
+ }
+ }
+ }
+}
--- /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.
+//
+// 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 EmuFront. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef DBMEDIAIMAGE_H
+#define DBMEDIAIMAGE_H
+
+#include "dbquerymodelmanager.h"
+#include "../dataobjects/mediaimage.h"
+
+class DbMediaImage : public DbQueryModelManager
+{
+public:
+ DbMediaImage(QObject *parent);
+ QList<int> storeMediaImages(QList<MediaImage*>);
+ virtual bool updateDataObjectToModel(const EmuFrontObject *);
+ virtual bool insertDataObjectToModel(const EmuFrontObject *);
+ virtual bool deleteDataObjectFromModel(QModelIndex *);
+ virtual int countDataObjectRefs(int id) const;
+ int getMediaImage(QString checksum) const;
+ int insertMediaImage(const MediaImage*);
+protected:
+ virtual QString constructSelect(QString whereClause) const;
+ virtual QString constructSelectById(int id) const;
+ virtual EmuFrontObject* recordToDataObject(const QSqlRecord *);
+private:
+ virtual QSqlQueryModel* getData();
+};
+
+#endif // DBMEDIAIMAGE_H
#include "dbmediaimagecontainer.h"
DbMediaImageContainer::DbMediaImageContainer(QObject *parent)
- : DbQueryModelManager(parent) { }
+ : DbQueryModelManager(parent)
+{
+ dbMediaImage = 0;
+}
bool DbMediaImageContainer::updateDataObjectToModel(const EmuFrontObject *efo)
{
{
return 0;
}
+
+int DbMediaImageContainer::getMediaImageContainer(QString checksum) const
+{
+ return -1;
+}
+
+void DbMediaImageContainer::storeContainers(QList<MediaImageContainer *> lst)
+{
+ foreach(MediaImageContainer *mic, lst)
+ {
+ QList<MediaImage*> images = mic->getMediaImages();
+ if (getMediaImageContainer(mic->getCheckSum()) >= 0)
+ continue;
+ // this is a new media image container, lets build a list
+ // of media image id's for this container
+ QList<int> ids = dbMediaImage->storeMediaImages(images);
+
+ if (ids.count() > 0)
+ {
+ // store media image to id
+
+ // get last insert id of stored media image
+
+ // link all the ids in ids-list to media image id
+ }
+ }
+}
#define DBMEDIAIMAGECONTAINER_H
#include "dbquerymodelmanager.h"
+#include "dbmediaimage.h"
+#include "../dataobjects/mediaimagecontainer.h"
class DbMediaImageContainer : public DbQueryModelManager
{
virtual bool insertDataObjectToModel(const EmuFrontObject *);
virtual bool deleteDataObjectFromModel(QModelIndex *);
virtual int countDataObjectRefs(int id) const;
+ void storeContainers(QList<MediaImageContainer*>);
+ int getMediaImageContainer(QString checksum) const;
protected:
virtual QString constructSelect(QString whereClause) const;
virtual QString constructSelectById(int id) const;
virtual EmuFrontObject* recordToDataObject(const QSqlRecord *);
private:
virtual QSqlQueryModel* getData();
+ DbMediaImage *dbMediaImage;
};
#endif // DBMEDIAIMAGECONTAINER_H
l << "*.zip"; // TODO set filters in a global constant class
QList<MediaImageContainer*> files = fileUtil.scanFilePath(fpo, l);
-
- // TODO
+ dbMediaImageContainer->storeContainers(files);
}
catch (EmuFrontException s)
{
dataobjects/emufrontfile.h \
db/dbfile.h \
db/dbemufrontfileobject.h \
- db/dbmediaimagecontainer.h
+ db/dbmediaimagecontainer.h \
+ db/dbmediaimage.h
SOURCES += main.cpp \
mainwindow.cpp \
db/databasemanager.cpp \
dataobjects/emufrontfile.cpp \
db/dbfile.cpp \
db/dbemufrontfileobject.cpp \
- db/dbmediaimagecontainer.cpp
+ db/dbmediaimagecontainer.cpp \
+ db/dbmediaimage.cpp
OTHER_FILES +=