|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This class provides the base class for ID3v2 parsers. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CMETADATAPARSERID3V2_H |
|
21 #define CMETADATAPARSERID3V2_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <centralrepository.h> |
|
26 #include "MetadataUtilityCRKeys.h" |
|
27 #include "MetaDataParser.h" |
|
28 #include "MetaDataSource.h" |
|
29 #include "MetaDataFieldContainer.h" |
|
30 #include "MetaDataField.h" |
|
31 |
|
32 |
|
33 |
|
34 // CONSTANTS |
|
35 const TUint KID3v2format = '('; |
|
36 |
|
37 |
|
38 // CLASS DECLARATION |
|
39 |
|
40 /** |
|
41 * This class implements the base class for ID3v2 parsers. |
|
42 * |
|
43 * @lib MetaDataUtility.lib |
|
44 * @since 3.0 |
|
45 */ |
|
46 class CMetaDataParserID3v2 : public CMetaDataParser |
|
47 { |
|
48 public: // Constructors and destructor |
|
49 |
|
50 /** |
|
51 * Two-phased constructor. |
|
52 * @param aSource A pointer to a metadata source |
|
53 * @return A pointer to a new instance of this class |
|
54 */ |
|
55 static CMetaDataParserID3v2* CreateID3v2ParserL( CMetaDataSource& aSource ); |
|
56 |
|
57 /** |
|
58 * Destructor. |
|
59 */ |
|
60 virtual ~CMetaDataParserID3v2(); |
|
61 |
|
62 public: // Functions from base classes |
|
63 |
|
64 /** |
|
65 * From CMetaDataParser |
|
66 * Parses the source and if metadata is found, the metadata fields are |
|
67 * inserted into the container. |
|
68 * @since 3.0 |
|
69 * @param aWantedFields An array of TMetaDataFieldId's. Empty array is interpreted as all fields. |
|
70 * @param aContainer On return, metadata found in aSource is stored here |
|
71 * @return void |
|
72 */ |
|
73 virtual void ParseL( const RArray<TMetaDataFieldId>& aWantedFields, CMetaDataFieldContainer& aContainer ); |
|
74 |
|
75 // Possible autodetect commands |
|
76 enum TAutoDetectCommand |
|
77 { |
|
78 EDetectFromTopList = 0, |
|
79 EDetectFromNextList, |
|
80 EDetectFromRestList |
|
81 }; |
|
82 |
|
83 /** |
|
84 * From CMetaDataParser |
|
85 * returns ID3 version |
|
86 * @since 3.0 |
|
87 * @return TID3Version |
|
88 */ |
|
89 TID3Version ID3Version(); |
|
90 |
|
91 protected: // New functions |
|
92 |
|
93 /** |
|
94 * C++ default constructor. |
|
95 */ |
|
96 CMetaDataParserID3v2( CMetaDataSource& aSource ); |
|
97 |
|
98 /** |
|
99 * Parses frames and appends supported fields to the container, if found. |
|
100 * @since 3.0 |
|
101 * @return void |
|
102 */ |
|
103 virtual void ParseFramesL(); |
|
104 |
|
105 /** |
|
106 * Parses frames and appends the wanted fields to the container, if found. |
|
107 * @since 3.0 |
|
108 * @param aWantedFields An array of TMetaDataFieldId's. |
|
109 * @return void |
|
110 */ |
|
111 virtual void ParseFramesL( const RArray<TMetaDataFieldId>& aWantedFields ); |
|
112 |
|
113 /** |
|
114 * This function is called from ParseL for header parsing and data initialization. |
|
115 * @since 3.0 |
|
116 * @return void |
|
117 */ |
|
118 virtual void PrepareToParseL() = 0; |
|
119 |
|
120 /** |
|
121 * Gets the next field's properties. |
|
122 * @since 3.0 |
|
123 * @param aFieldId Field Id, on return. |
|
124 * @param aFrameHeaderSize Frame header size. |
|
125 * @param aFrameSize Frame size, on return. |
|
126 * @return void |
|
127 */ |
|
128 virtual void GetNextFieldL( TMetaDataFieldId& aFieldId, TInt& aFrameHeaderSize, TInt& aFrameSize ) = 0; |
|
129 |
|
130 /** |
|
131 * Reads the text information from the source and appends it to the container. |
|
132 * @since 3.0 |
|
133 * @param aFieldId Field Id. |
|
134 * @param aSize Size of the data. |
|
135 * @return void |
|
136 */ |
|
137 virtual void GetTextInfoL( TMetaDataFieldId aFieldId, TInt aSize ) = 0; |
|
138 |
|
139 /** |
|
140 * From CMetaDataParserID3v2 |
|
141 * Reads the Genre from the source and appends it to the container. |
|
142 * @param aSize Size of the data. |
|
143 * @return void |
|
144 */ |
|
145 virtual void GetGenreL( TInt aSize ) = 0; |
|
146 |
|
147 /** |
|
148 * Reads the year from the source and appends it to the container. |
|
149 * @since 3.0 |
|
150 * @param aSize Size of the data. |
|
151 * @return void |
|
152 */ |
|
153 virtual void GetTextYearL( TInt aSize ) = 0; |
|
154 |
|
155 /** |
|
156 * Reads the comment from the source and appends it to the container. |
|
157 * @since 3.0 |
|
158 * @param aSize Size of the data. |
|
159 * @return void |
|
160 */ |
|
161 virtual void GetCommentL( TInt aSize ) = 0; |
|
162 |
|
163 /** |
|
164 * Reads the Url from the source and appends it to the container. |
|
165 * @since 3.0 |
|
166 * @param aSize Size of the data. |
|
167 * @return void |
|
168 */ |
|
169 virtual void GetUrlL( TInt aSize ) = 0; |
|
170 |
|
171 /** |
|
172 * Reads the user defined Url from the source and |
|
173 * appends it to the container. |
|
174 * @since 3.0 |
|
175 * @param aSize Size of the data. |
|
176 * @return void |
|
177 */ |
|
178 virtual void GetUserUrlL( TInt aSize ) = 0; |
|
179 |
|
180 /** |
|
181 * Reads the Jpeg from the source and appends it to the container. |
|
182 * @since 3.0 |
|
183 * @param aSize Size of the data. |
|
184 * @return void |
|
185 */ |
|
186 virtual void GetJpegL( TInt aSize ) = 0; |
|
187 |
|
188 /** |
|
189 * Reads the duration from the source and appends it to the container. |
|
190 * @since 3.0 |
|
191 * @param aSize Size of the data. |
|
192 * @return void |
|
193 */ |
|
194 virtual void GetDurationL( TInt aSize ) = 0; |
|
195 |
|
196 /** |
|
197 * Reads the date from the source and appends it to the container. |
|
198 * @since 3.0 |
|
199 * @param aSize Size of the data. |
|
200 * @return void |
|
201 */ |
|
202 virtual void GetTextDateL( TInt aSize ) = 0; |
|
203 |
|
204 /** |
|
205 * Reads the popularimeter from the source appends it to the container. |
|
206 * @since 3.0 |
|
207 * @param aSize Size of the data. |
|
208 * @return void |
|
209 */ |
|
210 virtual void GetRatingL (TInt aSize) = 0; |
|
211 /** |
|
212 * Converts to unicode. |
|
213 * @since 3.0 |
|
214 * @param aEncoding Encoding of aDesc. |
|
215 * @param aDesc Source to be converted to unicode. |
|
216 * @param aUnicode Contains the converted unicode on return. |
|
217 * @return The number of unconverted characters left at the end of the input descriptor |
|
218 * (e.g. because the output descriptor is not long enough to hold all the text), |
|
219 * or one of the error values defined in TError. |
|
220 */ |
|
221 virtual TInt ConvertToUnicodeL( TInt aEncoding, const TDesC8& aDesc, TDes16& aUnicode ) = 0; |
|
222 |
|
223 /** |
|
224 * Detects the character set, used to support fields with unknown or in-correct |
|
225 * text encoding, for the special case of Chinese GB2312 &BIG5 |
|
226 * @since 3.0 |
|
227 * @param aDes descriptor data |
|
228 * @return KErrNone, or any of the system wide error codes |
|
229 */ |
|
230 TInt DetectCharacterSetL(const TDesC8& aDesc); |
|
231 |
|
232 /** |
|
233 * Creates a list od character sets, top list, next top list, and rest list |
|
234 * for the special case of Chinese GB2312 &BIG5 character set detection |
|
235 * @since 3.0 |
|
236 */ |
|
237 void CreateCharacterSetsL(); |
|
238 |
|
239 TInt AutoDetectL(const TDesC8& aDesc, TDes16& aUnicode); |
|
240 |
|
241 void HandleV2GetGenreL( TInt aSize, TInt aKID3v2FrameHeaderLength, TInt aKID3v2GenreNameLength ); |
|
242 |
|
243 TBool NeedRetrieveAlbumArt( TInt aPicType ); |
|
244 |
|
245 void RetrieveAlbumArtL(); |
|
246 |
|
247 TBool IgnoreAlbumType (TInt aPicType); |
|
248 |
|
249 private: |
|
250 |
|
251 /** |
|
252 * Finds the version of ID3v2 tag. (e.g. ID3v2.4 returns 4) |
|
253 * @param aSource Data source. |
|
254 * @return ID3 tag version, KErrNotFound if none found. |
|
255 */ |
|
256 static TInt VersionL( CMetaDataSource& aSource ); |
|
257 |
|
258 |
|
259 |
|
260 protected: // Data |
|
261 |
|
262 // Metadata source |
|
263 CMetaDataSource *iSource; |
|
264 // Frame data size |
|
265 TInt iFrameDataSize; |
|
266 // Offset for frame position |
|
267 TInt iFrameOffset; |
|
268 // character set id |
|
269 TUint iCharacterSetId; |
|
270 // AutoDetect for Chinese BIG5 & GB2312 |
|
271 TBool iAutoDetectChinese; |
|
272 // AutoDetect for Japanese |
|
273 TBool iAutoDetectJapanese; |
|
274 // AutoDetect for Russian character sets |
|
275 TBool iAutoDetectRussian; |
|
276 // flag for parse from memory |
|
277 TBool iParseFromDescriptor; |
|
278 // tag descriptor |
|
279 HBufC8 *iTag; |
|
280 // memory store for tag |
|
281 CMetaDataSource *iSourceDes; |
|
282 |
|
283 //Album type |
|
284 TInt iAlbumType; |
|
285 //Album pic offset |
|
286 TInt iAlbumOffset; |
|
287 //Album pointer |
|
288 HBufC8* iAlbumPtr; |
|
289 |
|
290 }; |
|
291 |
|
292 #endif // CMETADATAPARSERID3V2_H |
|
293 |
|
294 // End of File |