3 ** Copyright 2010 Mikko Keinänen
5 ** This file is part of EmuFront.
8 ** EmuFront is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License version 2 as published by
10 ** the Free Software Foundation and appearing in the file gpl.txt included in the
11 ** packaging of this file.
13 ** EmuFront is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
18 ** You should have received a copy of the GNU General Public License
19 ** along with EmuFront. If not, see <http://www.gnu.org/licenses/>.
22 #include "mediaimagecontainer.h"
23 #include "mediaimagecontainermodel.h"
24 #include "filepathmodel.h"
25 #include "mediaimagemodel.h"
28 MediaImageContainerModel::MediaImageContainerModel(QObject *parent) :
29 EmuFrontQueryModel(parent)
33 QString MediaImageContainerModel::constructSelect(QString where) const
35 // TODO, for a usual search need a "light" version of this select
36 // and MediaImageContainer (only id, name)
38 "SELECT file.id, file.name, file.checksum, file.size, "
39 " filepath.id, filepath.name, "
41 " platform.id, platform.name, "
42 " mediatype.id, mediatype.name "
44 "INNER JOIN mediaimagecontainer_filepath ON mediaimagecontainer_filepath.fileid = file.id "
45 "INNER JOIN filepath ON mediaimagecontainer_filepath.filepathid = filepath.id "
46 "INNER JOIN setup ON filepath.setupid = setup.id "
47 "INNER JOIN platform ON setup.platformid = platform.id "
48 "INNER JOIN mediatype ON setup.mediatypeid = mediatype.id "
54 QString MediaImageContainerModel::constructFilterById(int id) const
56 return QString("file.id = %1").arg(id);
59 void MediaImageContainerModel::refresh()
61 //setQuery(constructSelect());
62 setHeaderData(MIC_FileId, Qt::Horizontal, tr("File id"));
63 setHeaderData(MIC_FileName, Qt::Horizontal, tr("File Name"));
64 setHeaderData(MIC_FileCheckSum, Qt::Horizontal, tr("File checksum"));
65 setHeaderData(MIC_FileSize, Qt::Horizontal, tr("File Size"));
66 setHeaderData(MIC_FilePathId, Qt::Horizontal, tr("File path id"));
67 setHeaderData(MIC_FilePathName, Qt::Horizontal, tr("File path name"));
68 setHeaderData(MIC_SetupId, Qt::Horizontal, tr("Setup id"));
69 setHeaderData(MIC_PlatformId, Qt::Horizontal, tr("Platform id"));
70 setHeaderData(MIC_PlatformName, Qt::Horizontal, tr("Platform name"));
71 setHeaderData(MIC_MediaTypeId, Qt::Horizontal, tr("Media type id"));
72 setHeaderData(MIC_MediaTypeName, Qt::Horizontal, tr("Media type name"));
75 EmuFrontObject* MediaImageContainerModel::recordToDataObject(const QSqlRecord *rec)
78 MediaImageContainer *mic = 0;
80 int id = rec->value(MIC_FileId).toInt();
81 QString name = rec->value(MIC_FileName).toString();
82 QString checksum = rec->value(MIC_FileCheckSum).toString();
83 int size = rec->value(MIC_FileSize).toInt();
84 int fpId = rec->value(MIC_FilePathId).toInt();
85 FilePathModel fpModel;
86 EmuFrontObject *efo = fpModel.getDataObject(fpId);
87 FilePathObject *fpo = dynamic_cast<FilePathObject*>(efo);
89 //int supId = rec->value(MIC_SetupId).toInt();
90 //Setup *sup = dbSetup->getDataObject(supId)
91 MediaImageModel miModel;
92 QMap<QString, EmuFrontObject*> images = miModel.getMediaImages(id);
93 mic = new MediaImageContainer(
94 id, name, checksum, size, images, fpo
99 void MediaImageContainerModel::filterBySetup(int setupId)
101 QList<QString> filters;
102 filters.append(QString("setup.id = %1").arg(setupId));
103 filterDataObjects(filters);