Modified the license text comment type.
[emufront] / src / db / dbmediaimagecontainer.cpp
index 3d2464b..7b3ec7a 100644 (file)
@@ -1,22 +1,23 @@
-// 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/>.
-
+/*
+** 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 <QDebug>
 #include <QSqlRecord>
 #include <QSqlQuery>
@@ -41,14 +42,14 @@ bool DbMediaImageContainer::updateDataObjectToModel(const EmuFrontObject *efo)
     return false;
 }
 
-
+/* Throws EmuFrontException */
 int DbMediaImageContainer::storeMediaImageContainer(EmuFrontObject *efo)
 {
     MediaImageContainer *mic
         = dynamic_cast<MediaImageContainer *>(efo);
 
     if (!mic->getFilePath())
-        throw new EmuFrontException("Cannot install media image "
+        throw EmuFrontException("Cannot install media image "
             "container to database without a file path object!");
 
     // multiple media image containers with matching checksum will be stored
@@ -58,7 +59,7 @@ int DbMediaImageContainer::storeMediaImageContainer(EmuFrontObject *efo)
     QMap<QString, EmuFrontObject*> images = mic->getMediaImages();
     QList<int> ids = dbMediaImage->storeMediaImages(images);
 
-    qDebug() << "Stored " << ids.count() << " media images.";
+    //qDebug() << "Stored " << ids.count() << " media images.";
 
     if (ids.count() <= 0)
         return -1;
@@ -73,16 +74,17 @@ int DbMediaImageContainer::storeMediaImageContainer(EmuFrontObject *efo)
         // File id is used to store the media image container instance to database,
         // file id is also the media image container id
 
+        // TODO: if this fails, the remove the media images in ids
         fileId = insertDataObjectToModel(mic);
 
-        qDebug() << "Inserted media image container to file table with id " << fileId << ".";
+        //qDebug() << "Inserted media image container to file table with id " << fileId << ".";
 
         if (fileId < 0) {
             // TODO: note we most surely need to catch the exception
             // in the calling code block and clean
             // all the media image and ...containers from
             // the memory!
-            throw new EmuFrontException(
+            throw EmuFrontException(
                     QString(tr("Inserting media image container %1 to file database failed"))
                     .arg(mic->getName()));
         }
@@ -91,11 +93,11 @@ int DbMediaImageContainer::storeMediaImageContainer(EmuFrontObject *efo)
 
         if (!linkMediaImageContainerToPath(mic)){
             DbFile::deleteDataObject(fileId);
-            throw new EmuFrontException("Failed inserting media image to database!");
+            throw EmuFrontException("Failed inserting media image to database!");
         }
-        qDebug() << "Inserted media image container " << fileId << " to mediaimagecontainer table.";
+        //qDebug() << "Inserted media image container " << fileId << " to mediaimagecontainer table.";
         linkMediaImagesWithContainer(fileId, images.values());
-        qDebug() << "Linked media image container with media images.";
+        //qDebug() << "Linked media image container with media images.";
     } catch (EmuFrontException e) {
         dbMediaImage->removeOrphanedMediaImages(ids);
         throw e;
@@ -127,7 +129,7 @@ QString DbMediaImageContainer::constructSelect(QString whereClause) const
                 "INNER JOIN mediatype ON setup.mediatypeid = mediatype.id "
                 "%1 "
                 "ORDER BY file.name").arg(whereClause);
-    qDebug() << select;
+    //qDebug() << select;
     return select;
 }
 
@@ -143,6 +145,7 @@ QString DbMediaImageContainer::constructSelectById(int id) const
         );
 }
 
+/* Throws EmuFrontException */
 EmuFrontObject* DbMediaImageContainer::recordToDataObject(const QSqlRecord *rec)
 {
     // TODO: checks!
@@ -154,7 +157,7 @@ EmuFrontObject* DbMediaImageContainer::recordToDataObject(const QSqlRecord *rec)
     int size = rec->value(MIC_FileSize).toInt();
     int fpId = rec->value(MIC_FilePathId).toInt();
     FilePathObject *fpo
-        = dynamic_cast<FilePathObject*>(dbFilePath->getDataObject(fpId));
+        = dynamic_cast<FilePathObject*>(dbFilePath->getDataObject(fpId)); /* Throws EmuFrontException */
     //int supId = rec->value(MIC_SetupId).toInt();
     //Setup *sup = dbSetup->getDataObject(supId)
     QMap<QString, EmuFrontObject*> images = dbMediaImage->getMediaImages(id);
@@ -203,17 +206,19 @@ int DbMediaImageContainer::getMediaImageContainer(QString checksum) const
 /**
 * Stores media image containers, including the media images included
 * to database.
+*
+* Throws EmuFrontException
 */
 void DbMediaImageContainer::storeContainers(QList<MediaImageContainer *> lst, FilePathObject *fpo)
 {
-    qDebug() << "Storing media image containers to database.";
     foreach(MediaImageContainer *mic, lst)
     {
-        qDebug() << "Media image container " << mic->getName();
+        //qDebug() << "Media image container " << mic->getName();
         int micFileId = storeMediaImageContainer(mic);
     }
 }
 
+/* Throws EmuFrontException */
 void DbMediaImageContainer::linkMediaImagesWithContainer(int micId, QList<EmuFrontObject*> mediaImages)
 {
     if (micId < 0 || mediaImages.count() <= 0)
@@ -222,10 +227,10 @@ void DbMediaImageContainer::linkMediaImagesWithContainer(int micId, QList<EmuFro
     MediaImage *mi = 0;
     foreach(EmuFrontObject *efo, mediaImages) {
         mi = dynamic_cast<MediaImage*>(efo);
-        qDebug() << "Linking media image container " << micId
-            << " to media image " << mi->getId()  << ", " << mi->getName() << ".";
+        /*qDebug() << "Linking media image container " << micId
+            << " to media image " << mi->getId()  << ", " << mi->getName() << ".";*/
         if (!linkMediaImageToMediaImageContainer(mi, micId)) {
-                throw new EmuFrontException(QString("Failed linking media "
+                throw EmuFrontException(QString("Failed linking media "
                                                     "image container %1 to a media image %2").arg(micId).arg(mi->getId()));
         }
     }
@@ -233,8 +238,8 @@ void DbMediaImageContainer::linkMediaImagesWithContainer(int micId, QList<EmuFro
 
 void DbMediaImageContainer::filter(int mediaTypeId, int platformId)
 {
-    qDebug() << "Filtering media images with media type " << mediaTypeId
-        << " and platform " << platformId;
+    /*qDebug() << "Filtering media images with media type " << mediaTypeId
+        << " and platform " << platformId;*/
     QList<QString> filters;
     if (mediaTypeId >= 0)
         filters.append(QString("mediatype.id=%1").arg(mediaTypeId));
@@ -272,6 +277,7 @@ QString DbMediaImageContainer::getDeleteObjectSql() const
        return QString("DELETE FROM file WHERE id=:id");
 }
 
+/* Throws EmuFrontException */
 EmuFrontObject* DbMediaImageContainer::getMediaImageContainerByChecksum(QString checksum)
 {
     return getDataObject(QString("file.checksum LIKE '%1'").arg(checksum));