From: Mikko Keinänen Date: Sat, 23 Oct 2010 00:05:17 +0000 (+0300) Subject: Removed most of the previous database changes. X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=ad24bbc2d3dd65116f7258afff3cd2db0ee8121e;p=emufront Removed most of the previous database changes. --- diff --git a/doc/er.dia b/doc/er.dia index 0cb6716..b6ee1bb 100644 Binary files a/doc/er.dia and b/doc/er.dia differ diff --git a/src/db/dbcreator.cpp b/src/db/dbcreator.cpp index f5c5f4a..5fd76b6 100644 --- a/src/db/dbcreator.cpp +++ b/src/db/dbcreator.cpp @@ -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"); diff --git a/src/db/dbmediaimage.cpp b/src/db/dbmediaimage.cpp index 5d0443a..fb26fff 100644 --- a/src/db/dbmediaimage.cpp +++ b/src/db/dbmediaimage.cpp @@ -85,7 +85,6 @@ EmuFrontObject* DbMediaImage::recordToDataObject(const QSqlRecord *) */ QList DbMediaImage::storeMediaImages(QMap images) { - qDebug() << "Storing media images to database."; QList ids = QList(); QMapIterator it(images); MediaImage *mi = 0; @@ -93,31 +92,12 @@ QList DbMediaImage::storeMediaImages(QMap images) { it.next(); mi = dynamic_cast(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); } diff --git a/src/db/dbmediaimagecontainer.cpp b/src/db/dbmediaimagecontainer.cpp index f7b5fdb..735d46d 100644 --- a/src/db/dbmediaimagecontainer.cpp +++ b/src/db/dbmediaimagecontainer.cpp @@ -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(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 images = mic->getMediaImages(); QList 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(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 index 1b3e1d0..0000000 --- a/src/db/dbmultiinstancefile.cpp +++ /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 . - -#include -#include -#include -#include "dbmultiinstancefile.h" - -DbMultiInstanceFile::DbMultiInstanceFile(QObject *parent) : - DbFile(parent) -{ -} - -int DbMultiInstanceFile::insertDataObjectToModel(const EmuFrontObject *efo) -{ - const EmuFrontFile *fi = dynamic_cast(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 index e97f95a..0000000 --- a/src/db/dbmultiinstancefile.h +++ /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 . - -#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 diff --git a/src/emufront.pro b/src/emufront.pro index e2e0051..53879e5 100644 --- a/src/emufront.pro +++ b/src/emufront.pro @@ -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 += diff --git a/src/utils/fileutil.cpp b/src/utils/fileutil.cpp index f2e8359..b5d96fb 100644 --- a/src/utils/fileutil.cpp +++ b/src/utils/fileutil.cpp @@ -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())