File: Image.cc

package info (click to toggle)
libcoverart 1.0.0%2Bgit20150706-6
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 424 kB
  • ctags: 285
  • sloc: cpp: 2,213; ansic: 303; sh: 91; xml: 63; makefile: 32
file content (228 lines) | stat: -rw-r--r-- 5,101 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/* --------------------------------------------------------------------------

   libcoverart - Client library to access MusicBrainz

   Copyright (C) 2012 Andrew Hawkins

   This file is part of libcoverart.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   libcoverart is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this library.  If not, see <http://www.gnu.org/licenses/>.

     $Id$

----------------------------------------------------------------------------*/

#include "config.h"
#include "coverart/defines.h"

#include <iostream>
#include <string>

#include <jansson.h>

#include "coverart/Image.h"
#include "coverart/Thumbnails.h"
#include "coverart/TypeList.h"

class CoverArtArchive::CImagePrivate
{
	public:
		CImagePrivate()
		:	m_Approved(false),
			m_Back(false),
			m_Edit(0),
			m_Front(false),
			m_Thumbnails(0),
			m_TypeList(0)
		{
		};

		bool m_Approved;
		bool m_Back;
		std::string m_Comment;
		int m_Edit;
		bool m_Front;
		std::string m_ID;
		std::string m_Image;
		CThumbnails *m_Thumbnails;
		CTypeList *m_TypeList;
};

CoverArtArchive::CImage::CImage(json_t *Root)
:	m_d(new CImagePrivate)
{
	if (Root && json_is_object(Root))
	{
		json_t *Approved=json_object_get(Root,"approved");
		if (json_is_boolean(Approved))
			m_d->m_Approved=json_is_true(Approved);

		json_t *Back=json_object_get(Root,"back");
		if (json_is_boolean(Back))
			m_d->m_Back=json_is_true(Back);

		json_t *Comment=json_object_get(Root,"comment");
		if (json_is_string(Comment))
		{
			const char *str=json_string_value(Comment);
			if (str)
				m_d->m_Comment=str;
		}

		json_t *Edit=json_object_get(Root,"edit");
		if (json_is_integer(Edit))
			m_d->m_Edit=json_integer_value(Edit);

		json_t *Front=json_object_get(Root,"front");
		if (json_is_boolean(Front))
			m_d->m_Front=json_is_true(Front);

		json_t *ID=json_object_get(Root,"id");
		if (json_is_string(ID))
		{
			const char *str=json_string_value(ID);
			if (str)
				m_d->m_ID=str;
		}

		json_t *Image=json_object_get(Root,"image");
		if (json_is_string(Image))
		{
			const char *str=json_string_value(Image);
			if (str)
				m_d->m_Image=str;
		}

		json_t *Thumbnails=json_object_get(Root,"thumbnails");
		if (json_is_object(Thumbnails))
			m_d->m_Thumbnails=new CThumbnails(Thumbnails);

		json_t *Types=json_object_get(Root,"types");
		if (json_is_array(Types))
			m_d->m_TypeList=new CTypeList(Types);
	}
}

CoverArtArchive::CImage::CImage(const CImage& Other)
:	m_d(new CImagePrivate)
{
	*this=Other;
}

CoverArtArchive::CImage& CoverArtArchive::CImage::operator =(const CImage& Other)
{
	if (this!=&Other)
	{
		Cleanup();

		m_d->m_Approved=Other.m_d->m_Approved;
		m_d->m_Back=Other.m_d->m_Back;
		m_d->m_Comment=Other.m_d->m_Comment;
		m_d->m_Edit=Other.m_d->m_Edit;
		m_d->m_Front=Other.m_d->m_Front;
		m_d->m_ID=Other.m_d->m_ID;
		m_d->m_Image=Other.m_d->m_Image;

		if (Other.m_d->m_Thumbnails)
			m_d->m_Thumbnails=new CThumbnails(*Other.m_d->m_Thumbnails);

		if (Other.m_d->m_TypeList)
			m_d->m_TypeList=new CTypeList(*Other.m_d->m_TypeList);
	}

	return *this;
}

CoverArtArchive::CImage::~CImage()
{
	Cleanup();

	delete m_d;
}

void CoverArtArchive::CImage::Cleanup()
{
	delete m_d->m_Thumbnails;
	m_d->m_Thumbnails=0;

	delete m_d->m_TypeList;
	m_d->m_TypeList=0;
}

bool CoverArtArchive::CImage::Approved() const
{
	return m_d->m_Approved;
}

bool CoverArtArchive::CImage::Back() const
{
	return m_d->m_Back;
}

std::string CoverArtArchive::CImage::Comment() const
{
	return m_d->m_Comment;
}

int CoverArtArchive::CImage::Edit() const
{
	return m_d->m_Edit;
}

bool CoverArtArchive::CImage::Front() const
{
	return m_d->m_Front;
}

std::string CoverArtArchive::CImage::ID() const
{
	return m_d->m_ID;
}

std::string CoverArtArchive::CImage::Image() const
{
	return m_d->m_Image;
}

CoverArtArchive::CThumbnails *CoverArtArchive::CImage::Thumbnails() const
{
	return m_d->m_Thumbnails;
}

CoverArtArchive::CTypeList *CoverArtArchive::CImage::TypeList() const
{
	return m_d->m_TypeList;
}

std::ostream& operator << (std::ostream& os, const CoverArtArchive::CImage& Image)
{
	os << "  Image:" << std::endl;

	os << "    Approved: " << Image.Approved() << std::endl;
	os << "    Back: " << Image.Back() << std::endl;
	os << "    Comment: " << Image.Comment() << std::endl;
	os << "    Edit: " << Image.Edit() << std::endl;
	os << "    Front: " << Image.Front() << std::endl;
	os << "    ID: " << Image.ID() << std::endl;
	os << "    Image: " << Image.Image() << std::endl;

	if (Image.Thumbnails())
		os << *Image.Thumbnails() << std::endl;

	if (Image.TypeList())
		os << *Image.TypeList() << std::endl;

	return os;
}