Skeletal implementation of DbMediaImage.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Sun, 20 Jun 2010 22:09:52 +0000 (01:09 +0300)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Sun, 20 Jun 2010 22:09:52 +0000 (01:09 +0300)
src/db/dbmediaimage.cpp [new file with mode: 0644]
src/db/dbmediaimage.h [new file with mode: 0644]
src/db/dbmediaimagecontainer.cpp
src/db/dbmediaimagecontainer.h
src/dialogs/mediaimagepathmaindialog.cpp
src/emufront.pro

diff --git a/src/db/dbmediaimage.cpp b/src/db/dbmediaimage.cpp
new file mode 100644 (file)
index 0000000..b050b42
--- /dev/null
@@ -0,0 +1,107 @@
+// 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);
+            }
+        }
+    }
+}
diff --git a/src/db/dbmediaimage.h b/src/db/dbmediaimage.h
new file mode 100644 (file)
index 0000000..b77e942
--- /dev/null
@@ -0,0 +1,45 @@
+// 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
index 2d9cfdb..aaea4f0 100644 (file)
 #include "dbmediaimagecontainer.h"
 
 DbMediaImageContainer::DbMediaImageContainer(QObject *parent)
-    : DbQueryModelManager(parent) { }
+    : DbQueryModelManager(parent)
+{
+    dbMediaImage = 0;
+}
 
 bool DbMediaImageContainer::updateDataObjectToModel(const EmuFrontObject *efo)
 {
@@ -61,3 +64,30 @@ QSqlQueryModel* DbMediaImageContainer::getData()
 {
     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
+        }
+    }
+}
index 5ef0c43..9ffef65 100644 (file)
@@ -21,6 +21,8 @@
 #define DBMEDIAIMAGECONTAINER_H
 
 #include "dbquerymodelmanager.h"
+#include "dbmediaimage.h"
+#include "../dataobjects/mediaimagecontainer.h"
 
 class DbMediaImageContainer : public DbQueryModelManager
 {
@@ -30,12 +32,15 @@ public:
     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
index fa53f0b..8af45ef 100644 (file)
@@ -69,8 +69,7 @@ void MediaImagePathMainDialog::beginScanFilePath()
         l << "*.zip"; // TODO set filters in a global constant class
 
         QList<MediaImageContainer*> files = fileUtil.scanFilePath(fpo, l);
-
-        // TODO
+        dbMediaImageContainer->storeContainers(files);
     }
     catch (EmuFrontException s)
     {
index 0f208db..2e9ce87 100644 (file)
@@ -49,7 +49,8 @@ HEADERS += mainwindow.h \
     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 \
@@ -88,5 +89,6 @@ SOURCES += main.cpp \
     dataobjects/emufrontfile.cpp \
     db/dbfile.cpp \
     db/dbemufrontfileobject.cpp \
-    db/dbmediaimagecontainer.cpp
+    db/dbmediaimagecontainer.cpp \
+    db/dbmediaimage.cpp
 OTHER_FILES +=