~ubuntu-branches/ubuntu/karmic/kid3/karmic

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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/**
 * \file pictureframe.h
 * Frame containing picture.
 *
 * \b Project: Kid3
 * \author Urs Fleisch
 * \date 03 Mar 2008
 *
 * Copyright (C) 2008-2009  Urs Fleisch
 *
 * This file is part of Kid3.
 *
 * Kid3 is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Kid3 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef PICTUREFRAME_H
#define PICTUREFRAME_H

#include "frame.h"

class QImage;

/** Frame containing picture. */
class PictureFrame : public Frame {
public:
	/** Picture type, compatible with ID3v2 and FLAC. */
	enum PictureType {
		PT_Other = 0,
		PT_Png32Icon = 1,
		PT_OtherIcon = 2,
		PT_CoverFront = 3,
		PT_CoverBack = 4,
		PT_LeafletPage = 5,
		PT_Media = 6,
		PT_LeadArtist = 7,
		PT_Artist = 8,
		PT_Conductor = 9,
		PT_Band = 10,
		PT_Composer = 11,
		PT_Lyricist = 12,
		PT_RecordingLocation = 13,
		PT_DuringRecording = 14,
		PT_DuringPerformance = 15,
		PT_Video = 16,
		PT_Fish = 17,
		PT_Illustration = 18,
		PT_ArtistLogo = 19,
		PT_PublisherLogo = 20
	};

	/**
	 * Constructor.
	 *
	 * @param data        binary picture data
	 * @param description description
	 * @param pictureType picture type
	 * @param mimeType    MIME type
	 * @param enc         text encoding
	 * @param imgFormat   image format
	 */
	explicit PictureFrame(
		const QByteArray& data = QByteArray(),
		const QString& description = "",
		PictureType pictureType = PT_CoverFront,
		const QString& mimeType = "image/jpeg",
		Field::TextEncoding enc = Field::TE_ISO8859_1,
		const QString& imgFormat = "JPG");

	/**
	 * Constructor.
	 *
	 * @param frame general frame
	 */
	PictureFrame(const Frame& frame);

	/**
	 * Destructor.
	 */
	~PictureFrame();

	/**
	 * Set all properties.
	 *
	 * @param frame       frame to set
	 * @param enc         text encoding
	 * @param imgFormat   image format
	 * @param mimeType    MIME type
	 * @param pictureType picture type
	 * @param description description
	 * @param data        binary picture data
	 */
	static void setFields(
		Frame& frame,
		Field::TextEncoding enc = Field::TE_ISO8859_1, const QString& imgFormat = "JPG",
		const QString& mimeType = "image/jpeg", PictureType pictureType = PT_CoverFront,
		const QString& description = "", const QByteArray& data = QByteArray());

	/**
	 * Get all properties.
	 * Unavailable fields are not set.
	 *
	 * @param frame       frame to get
	 * @param enc         text encoding
	 * @param imgFormat   image format
	 * @param mimeType    MIME type
	 * @param pictureType picture type
	 * @param description description
	 * @param data        binary picture data
	 */
	static void getFields(const Frame& frame,
												Field::TextEncoding& enc, QString& imgFormat,
												QString& mimeType, PictureType& pictureType,
												QString& description, QByteArray& data);

	/**
	 * Set text encoding.
	 *
	 * @param frame frame to set
	 * @param enc   text encoding
	 *
	 * @return true if field found and set.
	 */
	static bool setTextEncoding(Frame& frame, Field::TextEncoding enc);

	/**
	 * Get text encoding.
	 *
	 * @param frame frame to get
	 * @param enc   the text encoding is returned here
	 *
	 * @return true if field found.
	 */
	static bool getTextEncoding(const Frame& frame, Field::TextEncoding& enc);

	/**
	 * Set image format.
	 *
	 * @param frame     frame to set
	 * @param imgFormat image format
	 *
	 * @return true if field found and set.
	 */
	static bool setImageFormat(Frame& frame, const QString& imgFormat);

	/**
	 * Get image format.
	 *
	 * @param frame     frame to get
	 * @param imgFormat the image format is returned here
	 *
	 * @return true if field found.
	 */
	static bool getImageFormat(const Frame& frame, QString& imgFormat);

	/**
	 * Set MIME type.
	 *
	 * @param frame    frame to set
	 * @param mimeType MIME type
	 *
	 * @return true if field found and set.
	 */
	static bool setMimeType(Frame& frame, const QString& mimeType);

	/**
	 * Get MIME type.
	 *
	 * @param frame    frame to get
	 * @param mimeType the MIME type is returned here
	 *
	 * @return true if field found.
	 */
	static bool getMimeType(const Frame& frame, QString& mimeType);

	/**
	 * Set picture type.
	 *
	 * @param frame       frame to set
	 * @param pictureType picture type
	 *
	 * @return true if field found and set.
	 */
	static bool setPictureType(Frame& frame, PictureType pictureType);

	/**
	 * Get picture type.
	 *
	 * @param frame       frame to get
	 * @param pictureType the picture type is returned here
	 *
	 * @return true if field found.
	 */
	static bool getPictureType(const Frame& frame, PictureType& pictureType);

	/**
	 * Set description.
	 *
	 * @param frame       frame to set
	 * @param description description
	 *
	 * @return true if field found and set.
	 */
	static bool setDescription(Frame& frame, const QString& description);

	/**
	 * Get description.
	 *
	 * @param frame       frame to get
	 * @param description the description is returned here
	 *
	 * @return true if field found.
	 */
	static bool getDescription(const Frame& frame, QString& description);

	/**
	 * Set binary data.
	 *
	 * @param frame frame to set
	 * @param data  binary data
	 *
	 * @return true if field found and set.
	 */
	static bool setData(Frame& frame, const QByteArray& data);

	/**
	 * Get binary data.
	 *
	 * @param frame frame to get
	 * @param data  the binary data is returned here
	 *
	 * @return true if field found.
	 */
	static bool getData(const Frame& frame, QByteArray& data);

	/**
	 * Read binary data from file.
	 *
	 * @param frame frame to set
	 * @param fileName name of data file
	 *
	 * @return true if file read, field found and set.
	 */
	static bool setDataFromFile(Frame& frame, const QString& fileName);

	/**
	 * Get binary data from image.
	 *
	 * @param frame frame to set
	 * @param image image
	 *
	 * @return true if field found and set.
	 */
	static bool setDataFromImage(Frame& frame, const QImage& image);

	/**
	 * Save binary data to a file.
	 *
	 * @param frame    frame
	 * @param fileName name of data file to save
	 *
	 * @return true if field found and saved.
	 */
	static bool writeDataToFile(const Frame& frame, const QString& fileName);

	/**
	 * Set the MIME type and image format from the file name extension.
	 *
	 * @param frame frame to set
	 * @param fileName name of data file
	 *
	 * @return true if field found and set.
	 */
	static bool setMimeTypeFromFileName(Frame& frame, const QString& fileName);

private:
	/**
	 * Set value of a field.
	 *
	 * @param frame frame to set
	 * @param id    field ID
	 * @param value field value
	 *
	 * @return true if field found and set.
	 */
	static bool setField(Frame& frame, Field::Id id, const QVariant& value);

	/**
	 * Get value of a field.
	 *
	 * @param frame frame to get
	 * @param id    field ID
	 *
	 * @return field value, invalid if not found.
	 */
	static QVariant getField(const Frame& frame, Field::Id id);
};

#endif // PICTUREFRAME_H