675a9274b1b31de34a82d3dc1638da96b47ce440
[emufront] / src / dataobjects / mediaimagecontainer.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 version 2 as published by
9 // the Free Software Foundation and appearing in the file gpl.txt included in the
10 // packaging of this file.
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 "mediaimagecontainer.h"
22
23 MediaImageContainer::MediaImageContainer()
24     : EmuFrontFile(EmuFrontFile::FileType_MediaImageContainer)
25 {
26     lstMediaImage = QMap<QString, EmuFrontObject*>();
27     filePath = 0;
28 }
29
30 MediaImageContainer::MediaImageContainer(int id, QString name, 
31     QString checksum, int size, QMap<QString, EmuFrontObject*>images, FilePathObject *fpo)
32     : EmuFrontFile(id, name, checksum, size, EmuFrontFile::FileType_MediaImageContainer),
33         lstMediaImage(images), filePath(fpo)
34 { }
35
36 MediaImageContainer::MediaImageContainer(QString name, QString checksum,
37     int size, QMap<QString, EmuFrontObject*>images, FilePathObject *fpo)
38     : EmuFrontFile(-1, name, checksum, size, EmuFrontFile::FileType_MediaImageContainer),
39         lstMediaImage(images), filePath(fpo)
40 { }
41
42 MediaImageContainer::~MediaImageContainer()
43 {
44     qDeleteAll(lstMediaImage);
45     delete filePath;
46 }
47
48 MediaImageContainer::MediaImageContainer(MediaImageContainer &mic)
49     : EmuFrontFile(mic)
50 {
51     lstMediaImage = QMap<QString, EmuFrontObject*>();
52
53     QMapIterator<QString, EmuFrontObject*> it(mic.lstMediaImage);
54     MediaImage *mi = 0;
55     while(it.hasNext()) {
56         it.next();
57         mi = dynamic_cast<MediaImage*>(it.value());
58         lstMediaImage[mi->getCheckSum()] = new MediaImage(*mi);
59     }
60
61     filePath = new FilePathObject(*(mic.filePath));
62 }
63
64 MediaImageContainer& MediaImageContainer::operator =(MediaImageContainer &mic)
65 {
66      if (this == &mic) return *this;
67     id = mic.id;
68     name = mic.name;
69     type = mic.type;
70     checkSum = mic.checkSum;
71     size = mic.size;
72     qDeleteAll(lstMediaImage);
73
74     QMapIterator<QString, EmuFrontObject*> it(mic.lstMediaImage);
75     MediaImage *mi = 0;
76     while(it.hasNext()) {
77         it.next();
78         mi = dynamic_cast<MediaImage*>(it.value());
79         lstMediaImage[mi->getCheckSum()] = new MediaImage(*mi);
80     }
81     filePath = new FilePathObject(*(mic.filePath));
82     return (*this);
83 }
84
85 void MediaImageContainer::setMediaImages(QMap<QString, EmuFrontObject*> list)
86 {
87     qDeleteAll(lstMediaImage);
88     lstMediaImage = list;
89 }
90
91 QMap<QString, EmuFrontObject*> MediaImageContainer::getMediaImages() const
92 {   return lstMediaImage; }
93
94 void MediaImageContainer::addMediaImage(MediaImage *mi)
95 {   lstMediaImage[mi->getCheckSum()] = mi; }
96
97 void MediaImageContainer::clearMediaImages()
98 {
99     qDeleteAll(lstMediaImage);
100     lstMediaImage.clear();
101 }
102
103 FilePathObject* MediaImageContainer::getFilePath() const
104 { return filePath; }
105
106 void MediaImageContainer::setFilePath(FilePathObject *fp)
107 { filePath = fp; }