Updated some comments only.
[emufront] / src / db / dbmediaimage.cpp
1 // EmuFront
2 // Copyright 2010 Mikko Keinänen
3 //
4 // This file is part of EmuFront.
5 //
6 //
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.
11 //
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.
16 //
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/>.
19
20 #include <QDebug>
21 #include <QSqlTableModel>
22 #include <QSqlQuery>
23 #include "dbmediaimage.h"
24
25 DbMediaImage::DbMediaImage(QObject *parent)
26     : DbFile(parent)
27 {
28     type = EmuFrontFile::FileType_MediaImage;
29 }
30
31 /*bool DbMediaImage::updateDataObjectToModel(const EmuFrontObject *efo)
32 {
33     // TODO
34     return false;
35 }
36
37 bool DbMediaImage::insertDataObjectToModel(const EmuFrontObject *efo)
38 {
39     // TODO
40     return false;
41 }
42
43 bool DbMediaImage::deleteDataObjectFromModel(QModelIndex *i)
44 {
45     // TODO
46     return false;
47 }
48
49 int DbMediaImage::countDataObjectRefs(int id) const
50 {
51     // TODO
52     return -1;
53 }
54
55 QString DbMediaImage::constructSelect(QString whereClause) const
56 {
57     // TODO
58     return "";
59 }
60
61 QString DbMediaImage::constructSelectById(int id) const
62 {
63     // TODO
64     return "";
65 }
66
67 EmuFrontObject* DbMediaImage::recordToDataObject(const QSqlRecord *)
68 {
69     // TODO
70     return 0;
71 }*/
72
73 /*QSqlQueryModel* DbMediaImage::getData()
74 {
75     QSqlTableModel *model = new QSqlTableModel;
76     model->setTable(DB_TABLE_NAME_FILE);
77     return model;
78 }*/
79
80 /*int DbMediaImage::insertMediaImage(const MediaImage *mi)
81 {
82     return DbFile::insertDataObjectToModel(mi);
83 }*/
84
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.
88 */
89 QList<int> DbMediaImage::storeMediaImages(QList<MediaImage *> images)
90 {
91     qDebug() << "Storing media images to database.";
92     QList<int> ids  = QList<int>();
93     foreach(MediaImage* mi, images)
94     {
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;
100         if (id >= 0)
101         {
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
106         }
107         else if (id < 0)
108         {
109             qDebug() << "This media image is not yet in the db.";
110             id = insertDataObjectToModel(mi);
111             if (id < 0)
112             {
113                 // TODO: Build an error message of failed inserts
114                 qDebug() << "Failed inserting media image" << mi->getName();
115             }
116         }
117         if (id > 0)
118             ids.append(id);
119     }
120     return ids;
121 }