Removed most of the previous database changes.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Sat, 23 Oct 2010 00:05:17 +0000 (03:05 +0300)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Sat, 23 Oct 2010 00:05:17 +0000 (03:05 +0300)
doc/er.dia
src/db/dbcreator.cpp
src/db/dbmediaimage.cpp
src/db/dbmediaimagecontainer.cpp
src/db/dbmultiinstancefile.cpp [deleted file]
src/db/dbmultiinstancefile.h [deleted file]
src/emufront.pro
src/utils/fileutil.cpp

index 0cb6716..b6ee1bb 100644 (file)
Binary files a/doc/er.dia and b/doc/er.dia differ
index f5c5f4a..5fd76b6 100644 (file)
@@ -55,8 +55,7 @@ bool DbCreator::createDB()
 
         ret = query.exec("CREATE TABLE IF NOT EXISTS file"
                         "(id INTEGER PRIMARY KEY, "
-                        "name TEXT, "   // TODO: optional here! -> mediaimagecontainer has filepath spesific name and media image has mediaimagecontainer specific name
-                                        // so no name here for those file types
+                        "name TEXT, "
                         "type INTEGER, "
                         "checksum TEXT, "
                         "size INTEGER, "
@@ -121,7 +120,6 @@ bool DbCreator::createDB()
         ret = query.exec("CREATE TABLE IF NOT EXISTS mediaimagecontainer_filepath "
                         "(fileid INTEGER REFERENCES file(id), "
                         "filepathid INTEGER REFERENCES filepath(id), "
-                        "mediaimagecontainername TEXT, " // filepath specific name for media image container
                         "updatetime NUMERIC)");
 
         if (!ret) throw QString("tbl mediaimagecontainer_filepath");
@@ -131,9 +129,7 @@ bool DbCreator::createDB()
 
         ret = query.exec("CREATE TABLE IF NOT EXISTS mediaimagecontainer_mediaimage "
                         "(mediaimagecontainerid INTEGER REFERENCES file(id), "
-                        "mediaimageid INTEGER REFERENCES file(id), "
-                        "mediaimagename TEXT " // mediaimagecontainer specific name for media image
-                        ")");
+                        "mediaimageid INTEGER REFERENCES file(id))");
 
         if (!ret) throw QString("tbl mediaimagecontainer_mediaimage");
 
index 5d0443a..fb26fff 100644 (file)
@@ -85,7 +85,6 @@ EmuFrontObject* DbMediaImage::recordToDataObject(const QSqlRecord *)
 */
 QList<int> DbMediaImage::storeMediaImages(QMap<QString, EmuFrontObject*> images)
 {
-    qDebug() << "Storing media images to database.";
     QList<int> ids  = QList<int>();
     QMapIterator<QString, EmuFrontObject*> it(images);
     MediaImage *mi = 0;
@@ -93,31 +92,12 @@ QList<int> DbMediaImage::storeMediaImages(QMap<QString, EmuFrontObject*> images)
     {
         it.next();
         mi = dynamic_cast<MediaImage*>(it.value());
-        QString cksum = mi->getCheckSum();
-        qDebug() << "Storing media image " << mi->getName()
-            << " with checksum " << cksum;
-        EmuFrontObject *o = getFileByChecksum(cksum);
-        int id = o ? o->getId() : -1;
-        if (id >= 0)
-        {
-            qDebug() << "This media image already exists with id " << id;
-
-            // this media image is already stored to db
-            // we will append the id of this media image to the list of media images
-            // and we will link this media image to the container later
-            delete o;
+        int id = insertDataObjectToModel(mi);
+        if (id < 0) {
+            // TODO: Build an error message of failed inserts
+            qDebug() << "Failed inserting media image" << mi->getName();
         }
-        else if (id < 0)
-        {
-            qDebug() << "This media image is not yet in the db.";
-            id = insertDataObjectToModel(mi);
-            if (id < 0)
-            {
-                // TODO: Build an error message of failed inserts
-                qDebug() << "Failed inserting media image" << mi->getName();
-            }
-        }
-        if (id > 0) {
+        else if (id >= 0) {
             ids.append(id);
             mi->setId(id);
         }
index f7b5fdb..735d46d 100644 (file)
@@ -52,31 +52,10 @@ int DbMediaImageContainer::storeMediaImageContainer(EmuFrontObject *efo)
         throw new EmuFrontException("Cannot install media image "
             "container to database without a file path object!");
 
-    // check if this media image container is already in the database
-
     // multiple media image containers with matching checksum will be stored
     //       if each instance is in a different file path
 
-    EmuFrontObject *o = getMediaImageContainerByChecksum(mic->getCheckSum());
-    int fileId = o ? o->getId() : -1;
-    if (fileId >= 0) {
-        qDebug() << "Media image container already in db with id " << fileId << ".";
-        // ok, we have a matching file
-        MediaImageContainer *tmpMic = dynamic_cast<MediaImageContainer*>(o);
-        // this will test if media image container is already in given path (media image container has a path spesific name!)
-        QString name = getMediaImageContainerName(mic->getFilePath()->getId(), mic->getId());
-        if (name.isEmpty()) {
-            // if file path differs, link the existing media image container to this file path with mic->getName() name
-            linkMediaImageContainerToPath(mic);
-        }
-        else if (name != mic->getName()) {
-            // if the file path is same but the file name differs update the mediaimagecontainer_filepath table entry
-            updateMediaImageContainerToPath(mic);
-        }
-        delete tmpMic;
-        return fileId;
-   }
-
+    int fileId = -1;
     QMap<QString, EmuFrontObject*> images = mic->getMediaImages();
     QList<int> ids = dbMediaImage->storeMediaImages(images);
 
@@ -136,7 +115,7 @@ QString DbMediaImageContainer::constructSelect(QString whereClause) const
 {
     // TODO, for a usual search we need a "light" version of this select
     // and MediaImageContainer (only id, name)
-    QString select = QString("SELECT file.id, mediaimagecontainer_filepath.mediaimagecontainername, file.checksum, file.size, "
+    QString select = QString("SELECT file.id, file.name, file.checksum, file.size, "
                 "        filepath.id, filepath.name, "
                 "        setup.id, "
                 "        platform.id, platform.name, "
@@ -246,16 +225,10 @@ void DbMediaImageContainer::linkMediaImagesWithContainer(int micId, QList<EmuFro
         mi = dynamic_cast<MediaImage*>(efo);
         qDebug() << "Linking media image container " << micId
             << " to media image " << mi->getId()  << ", " << mi->getName() << ".";
-        QString name = getMediaImageContainerName(micId, mi->getId());
-        if (name.isEmpty() && !linkMediaImageToMediaImageContainer(mi, micId)) {
+        if (!linkMediaImageToMediaImageContainer(mi, micId)) {
                 throw new EmuFrontException(QString("Failed linking media "
                                                     "image container %1 to a media image %2").arg(micId).arg(mi->getId()));
         }
-        else if (name != mi->getName() && !updateMediaImageToMediaImageContainer(mi, micId)) {
-                throw new EmuFrontException(QString("Failed updating media "
-                                                    "image container %1 to a media image %2").arg(micId).arg(mi->getId()));
-        }
-        // else already linked and name is up to date.
     }
 }
 
@@ -309,63 +282,21 @@ bool DbMediaImageContainer::linkMediaImageContainerToPath(const MediaImageContai
 {
     QSqlQuery q;
     q.prepare("INSERT INTO mediaimagecontainer_filepath "
-              "(fileid, filepathid, mediaimagecontainername, updatetime) "
-              "VALUES (:fileid, :filepathid, :mediaimagecontainername, :updatetime)");
-    q.bindValue(":fileid", mic->getId());
-    q.bindValue(":filepathid", mic->getFilePath()->getId());
-    q.bindValue(":mediaimagecontainername", mic->getName());
-    q.bindValue(":updatetime", DatabaseManager::getCurrentTimeStamp());
-    return q.exec();
-}
-
-bool DbMediaImageContainer::updateMediaImageContainerToPath(const MediaImageContainer *mic) const
-{
-    QSqlQuery q;
-    q.prepare("UPDATE mediaimagecontainer_filepath "
-                "SET mediaimagecontainername=:mediaimagecontainername, "
-                "updatetime=:updatetime "
-                "WHERE fileid=:fileid AND filepathid=:filepathid");
+              "(fileid, filepathid, updatetime) "
+              "VALUES (:fileid, :filepathid, :updatetime)");
     q.bindValue(":fileid", mic->getId());
     q.bindValue(":filepathid", mic->getFilePath()->getId());
-    q.bindValue(":mediaimagecontainername", mic->getName());
     q.bindValue(":updatetime", DatabaseManager::getCurrentTimeStamp());
     return q.exec();
 }
 
-QString DbMediaImageContainer::getMediaImageContainerName(int filePathId, int micId) const
-{
-    QString name = "";
-    QSqlQuery q;
-    q.prepare("SELECT mediaimagecontainername FROM mediaimagecontainer_filepath "
-        "WHERE fileid=:fileid AND filepathid=:filepathid");
-    q.bindValue(":fileid", micId);
-    q.bindValue(":filepathid", filePathId);
-    q.exec();
-    if (q.next())
-        name = q.value(0).toString();
-    return name;
-}
-
 bool DbMediaImageContainer::linkMediaImageToMediaImageContainer(const MediaImage *mi, int micId) const
 {
     QSqlQuery q;
     q.prepare("INSERT INTO mediaimagecontainer_mediaimage "
-        "(mediaimagecontainerid, mediaimageid, mediaimagename) "
-        "VALUES (:micid, :miid, :miname) ");
-    q.bindValue(":micid", micId);
-    q.bindValue(":miid", mi->getId());
-    q.bindValue(":miname", mi->getName());
-    return q.exec();
-}
-
-bool DbMediaImageContainer::updateMediaImageToMediaImageContainer(const MediaImage *mi, int micId) const
-{
-    QSqlQuery q;
-    q.prepare("UPDATE mediaimagecontainer_mediaimage "
-        " SET mediaimagename=:miname "
-        " WHERE mediaimagecontainerid=:micid AND mediaimageid=:miid");
+        "(mediaimagecontainerid, mediaimageid) "
+        "VALUES (:micid, :miid) ");
     q.bindValue(":micid", micId);
     q.bindValue(":miid", mi->getId());
-    q.bindValue(":miname", mi->getName());
     return q.exec();
 }
diff --git a/src/db/dbmultiinstancefile.cpp b/src/db/dbmultiinstancefile.cpp
deleted file mode 100644 (file)
index 1b3e1d0..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-// 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 version 2 as published by
-// the Free Software Foundation and appearing in the file gpl.txt included in the
-// packaging of this file.
-//
-// 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 <QSqlRecord>
-#include <QSqlQuery>
-#include <QSqlRelationalTableModel>
-#include "dbmultiinstancefile.h"
-
-DbMultiInstanceFile::DbMultiInstanceFile(QObject *parent) :
-    DbFile(parent)
-{
-}
-
-int DbMultiInstanceFile::insertDataObjectToModel(const EmuFrontObject *efo)
-{
-    const EmuFrontFile *fi = dynamic_cast<const EmuFrontFile*>(efo);
-    QSqlQuery q;
-    q.prepare("INSERT INTO file "
-              "(id, name, type, checksum, size, updatetime) "
-              "VALUES (NULL, "", :type, :checksum, :size, :updatetime)"); // NOTE: in this class it is ok to leave the name field empty!
-    q.bindValue(":type", fi->getType());
-    q.bindValue(":checksum", fi->getCheckSum());
-    q.bindValue(":size", fi->getSize());
-    q.bindValue(":updatetime", DatabaseManager::getCurrentTimeStamp());
-    int id = -1;
-    if (q.exec())
-        id = q.lastInsertId().toInt();
-    return id;
-}
diff --git a/src/db/dbmultiinstancefile.h b/src/db/dbmultiinstancefile.h
deleted file mode 100644 (file)
index e97f95a..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// 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 version 2 as published by
-// the Free Software Foundation and appearing in the file gpl.txt included in the
-// packaging of this file.
-//
-// 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 DBMULTIINSTANCEFILE_H
-#define DBMULTIINSTANCEFILE_H
-
-#include "dbfile.h"
-
-class DbMultiInstanceFile : public DbFile
-{
-    Q_OBJECT
-public:
-    explicit DbMultiInstanceFile(QObject *parent = 0);
-    virtual int insertDataObjectToModel(const EmuFrontObject *);
-
-
-signals:
-
-public slots:
-
-};
-
-#endif // DBMULTIINSTANCEFILE_H
index e2e0051..53879e5 100644 (file)
@@ -63,8 +63,7 @@ HEADERS += mainwindow.h \
     utils/unziphelper.h \
     utils/emuhelper.h \
     dialogs/listdialog.h \
-    dialogs/emufrontinputdialog.h \
-    db/dbmultiinstancefile.h
+    dialogs/emufrontinputdialog.h
 SOURCES += main.cpp \
     mainwindow.cpp \
     db/databasemanager.cpp \
@@ -117,6 +116,5 @@ SOURCES += main.cpp \
     utils/unziphelper.cpp \
     utils/emuhelper.cpp \
     dialogs/listdialog.cpp \
-    dialogs/emufrontinputdialog.cpp \
-    db/dbmultiinstancefile.cpp
+    dialogs/emufrontinputdialog.cpp
 OTHER_FILES += 
index f2e8359..b5d96fb 100644 (file)
@@ -59,6 +59,9 @@ int FileUtil::scanFilePath(FilePathObject *fp, QStringList filters, DbMediaImage
         throw new EmuFrontException(tr("No media type available with %1.")
             .arg(fp->getSetup()->getName()));
     }
+
+    // TODO: if this is a rescan of this filepath remove all the old entries first!
+
     int count = 0;
     qDebug() << QString("We have a platform %1, media type %2")
         .arg(fp->getSetup()->getPlatform()->getName())