2 // Copyright 2010 Mikko Keinänen
4 // This file is part of EmuFront.
7 // EmuFront is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
12 // EmuFront is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
21 #include <QSqlTableModel>
23 #include "dbmediaimage.h"
25 DbMediaImage::DbMediaImage(QObject *parent)
28 type = EmuFrontFile::FileType_MediaImage;
31 /*bool DbMediaImage::updateDataObjectToModel(const EmuFrontObject *efo)
37 bool DbMediaImage::insertDataObjectToModel(const EmuFrontObject *efo)
43 bool DbMediaImage::deleteDataObjectFromModel(QModelIndex *i)
49 int DbMediaImage::countDataObjectRefs(int id) const
55 QString DbMediaImage::constructSelect(QString whereClause) const
61 QString DbMediaImage::constructSelectById(int id) const
67 EmuFrontObject* DbMediaImage::recordToDataObject(const QSqlRecord *)
73 /*QSqlQueryModel* DbMediaImage::getData()
75 QSqlTableModel *model = new QSqlTableModel;
76 model->setTable(DB_TABLE_NAME_FILE);
80 /*int DbMediaImage::insertMediaImage(const MediaImage *mi)
82 return DbFile::insertDataObjectToModel(mi);
85 /* Stores a list of media images to the database.
86 Returns a list of media image id corresponding to the given list of media
87 images inserted to the database or already in the database.
89 QList<int> DbMediaImage::storeMediaImages(QList<MediaImage *> images)
91 qDebug() << "Storing media images to database.";
92 QList<int> ids = QList<int>();
93 foreach(MediaImage* mi, images)
95 QString cksum = mi->getCheckSum();
96 qDebug() << "Storing media image " << mi->getName()
97 << " with checksum " << cksum;
98 EmuFrontObject *o = getFileByChecksum(cksum);
99 int id = o ? o->getId() : -1;
102 qDebug() << "This media image already exists with id " << id;
103 // this media image is already in the database
104 // TODO: what if the name differs? (cannot update to database, since the same media image
105 // might be inside another container
109 qDebug() << "This media image is not yet in the db.";
110 id = insertDataObjectToModel(mi);
113 // TODO: Build an error message of failed inserts
114 qDebug() << "Failed inserting media image" << mi->getName();