Modified the license text comment type.
[emufront] / src / dataobjects / mediaimagecontainer.cpp
1 /*
2 ** EmuFront
3 ** Copyright 2010 Mikko Keinänen
4 **
5 ** This file is part of EmuFront.
6 **
7 **
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.
12 **
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.
17 **
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/>.
20 */
21 #include <QDebug>
22 #include "mediaimagecontainer.h"
23
24 MediaImageContainer::MediaImageContainer()
25     : EmuFrontFile(EmuFrontFile::FileType_MediaImageContainer)
26 {
27     lstMediaImage = QMap<QString, EmuFrontObject*>();
28     filePath = 0;
29 }
30
31 MediaImageContainer::MediaImageContainer(int id, QString name, 
32     QString checksum, int size, QMap<QString, EmuFrontObject*>images, FilePathObject *fpo)
33     : EmuFrontFile(id, name, checksum, size, EmuFrontFile::FileType_MediaImageContainer),
34         lstMediaImage(images), filePath(fpo)
35 { }
36
37 MediaImageContainer::MediaImageContainer(QString name, QString checksum,
38     int size, QMap<QString, EmuFrontObject*>images, FilePathObject *fpo)
39     : EmuFrontFile(-1, name, checksum, size, EmuFrontFile::FileType_MediaImageContainer),
40         lstMediaImage(images), filePath(fpo)
41 { }
42
43 MediaImageContainer::~MediaImageContainer()
44 {
45     qDeleteAll(lstMediaImage);
46     delete filePath;
47 }
48
49 MediaImageContainer::MediaImageContainer(MediaImageContainer &mic)
50     : EmuFrontFile(mic)
51 {
52     lstMediaImage = QMap<QString, EmuFrontObject*>();
53
54     QMapIterator<QString, EmuFrontObject*> it(mic.lstMediaImage);
55     MediaImage *mi = 0;
56     while(it.hasNext()) {
57         it.next();
58         mi = dynamic_cast<MediaImage*>(it.value());
59         lstMediaImage[mi->getCheckSum()] = new MediaImage(*mi);
60     }
61
62     filePath = new FilePathObject(*(mic.filePath));
63 }
64
65 MediaImageContainer& MediaImageContainer::operator =(MediaImageContainer &mic)
66 {
67      if (this == &mic) return *this;
68     id = mic.id;
69     name = mic.name;
70     type = mic.type;
71     checkSum = mic.checkSum;
72     size = mic.size;
73     qDeleteAll(lstMediaImage);
74
75     QMapIterator<QString, EmuFrontObject*> it(mic.lstMediaImage);
76     MediaImage *mi = 0;
77     while(it.hasNext()) {
78         it.next();
79         mi = dynamic_cast<MediaImage*>(it.value());
80         lstMediaImage[mi->getCheckSum()] = new MediaImage(*mi);
81     }
82     filePath = new FilePathObject(*(mic.filePath));
83     return (*this);
84 }
85
86 void MediaImageContainer::setMediaImages(QMap<QString, EmuFrontObject*> list)
87 {
88     qDeleteAll(lstMediaImage);
89     lstMediaImage = list;
90 }
91
92 QMap<QString, EmuFrontObject*> MediaImageContainer::getMediaImages() const
93 {   return lstMediaImage; }
94
95 void MediaImageContainer::addMediaImage(MediaImage *mi)
96 {   lstMediaImage[mi->getCheckSum()] = mi; }
97
98 void MediaImageContainer::clearMediaImages()
99 {
100     qDeleteAll(lstMediaImage);
101     lstMediaImage.clear();
102 }
103
104 FilePathObject* MediaImageContainer::getFilePath() const
105 { return filePath; }
106
107 void MediaImageContainer::setFilePath(FilePathObject *fp)
108 { filePath = fp; }