|
1 /* |
|
2 * Copyright (c) 2002-2007 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: Utility class for meta data gathering for audio files |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <MetaDataUtility.h> |
|
22 #include <MetaDataFieldContainer.h> |
|
23 |
|
24 #include "upnpmetadatautility.h" |
|
25 #include "upnpcommonutils.h" |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS ============================ |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // CUPnPMetaDataUtility::CUPnPMetaDataUtility |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CUPnPMetaDataUtility::CUPnPMetaDataUtility() |
|
36 { |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CUPnPMetaDataUtility::NewL |
|
41 // Two-phased constructor. |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 EXPORT_C CUPnPMetaDataUtility* CUPnPMetaDataUtility::NewL() |
|
45 { |
|
46 CUPnPMetaDataUtility* self = new( ELeave ) CUPnPMetaDataUtility; |
|
47 |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL(); |
|
50 CleanupStack::Pop(); |
|
51 |
|
52 return self; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CUPnPMetaDataUtility::ConstructL |
|
57 // Symbian 2nd phase constructor can leave. |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 void CUPnPMetaDataUtility::ConstructL() |
|
61 { |
|
62 iMetaDataUtility = CMetaDataUtility::NewL(); |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CUPnPMetaDataUtility::~CUPnPMetaDataUtility() |
|
67 // Destructor |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 EXPORT_C CUPnPMetaDataUtility::~CUPnPMetaDataUtility() |
|
71 { |
|
72 if ( iMetaDataUtility ) |
|
73 { |
|
74 TRAP_IGNORE( iMetaDataUtility->ResetL() ); |
|
75 } |
|
76 |
|
77 delete iArtist; |
|
78 delete iAlbum; |
|
79 delete iGenre; |
|
80 delete iTitle; |
|
81 delete iDate; |
|
82 delete iMetaDataUtility; |
|
83 } |
|
84 |
|
85 // -------------------------------------------------------------------------- |
|
86 // CUPnPMetaDataUtility::LoadMetaDataL |
|
87 // Finds correct MMF controller according to give file name |
|
88 // (other items were commented in a header). |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C void CUPnPMetaDataUtility::LoadMetaDataL( const TDesC& aFileName ) |
|
92 { |
|
93 // Cleanup existing information |
|
94 Reset(); |
|
95 |
|
96 RArray<TMetaDataFieldId> wantedFields; |
|
97 CleanupClosePushL( wantedFields ); |
|
98 wantedFields.Append( EMetaDataSongTitle ); |
|
99 wantedFields.Append( EMetaDataArtist ); |
|
100 wantedFields.Append( EMetaDataAlbum ); |
|
101 wantedFields.Append( EMetaDataGenre ); |
|
102 wantedFields.Append( EMetaDataDate ); |
|
103 |
|
104 // Reset to be sure that no allocations are left over |
|
105 iMetaDataUtility->ResetL(); |
|
106 |
|
107 // Open the file |
|
108 iMetaDataUtility->OpenFileL( aFileName, wantedFields ); |
|
109 |
|
110 // wantedFields is not needed anymore |
|
111 CleanupStack::PopAndDestroy( &wantedFields ); |
|
112 |
|
113 // Go through the meta data fields and pick the required ones |
|
114 TInt count = iMetaDataUtility->MetaDataCount(); |
|
115 |
|
116 if ( count > 0 ) |
|
117 { |
|
118 const CMetaDataFieldContainer& container = |
|
119 iMetaDataUtility->MetaDataFieldsL(); |
|
120 TMetaDataFieldId fieldId; |
|
121 for ( TInt index = 0; index < count; index++ ) |
|
122 { |
|
123 TPtrC content = container.At( index, fieldId ); |
|
124 switch ( fieldId ) |
|
125 { |
|
126 case EMetaDataSongTitle: |
|
127 { |
|
128 iTitle = content.AllocL(); |
|
129 break; |
|
130 } |
|
131 case EMetaDataArtist: |
|
132 { |
|
133 iArtist = content.AllocL(); |
|
134 break; |
|
135 } |
|
136 case EMetaDataAlbum: |
|
137 { |
|
138 iAlbum = content.AllocL(); |
|
139 break; |
|
140 } |
|
141 case EMetaDataGenre: |
|
142 { |
|
143 iGenre = content.AllocL(); |
|
144 break; |
|
145 } |
|
146 case EMetaDataDate: |
|
147 { |
|
148 iDate = content.AllocL(); |
|
149 break; |
|
150 } |
|
151 default: |
|
152 { |
|
153 // Nothing to do |
|
154 break; |
|
155 } |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 if( !iDate ) |
|
161 { |
|
162 // Date was not found from metadata, so get it from file properties |
|
163 RFs fs; |
|
164 User::LeaveIfError( fs.Connect() ); |
|
165 CleanupClosePushL( fs ); |
|
166 RFile file; |
|
167 User::LeaveIfError( file.Open( fs,aFileName, EFileRead | |
|
168 EFileShareReadersOrWriters ) ); |
|
169 CleanupClosePushL( file ); |
|
170 |
|
171 TTime time; |
|
172 User::LeaveIfError( file.Modified( time ) ); |
|
173 |
|
174 |
|
175 iDate = UPnPCommonUtils::TTimeToUPnPDateL( time ); |
|
176 |
|
177 CleanupStack::PopAndDestroy( &file ); |
|
178 CleanupStack::PopAndDestroy( &fs ); |
|
179 |
|
180 } |
|
181 // Cleanup |
|
182 iMetaDataUtility->ResetL(); |
|
183 } |
|
184 |
|
185 // -------------------------------------------------------------------------- |
|
186 // CUPnPMetaDataUtility::Title |
|
187 // Returns title for the song |
|
188 // (other items were commented in a header). |
|
189 // -------------------------------------------------------------------------- |
|
190 // |
|
191 EXPORT_C const TDesC& CUPnPMetaDataUtility::Title() const |
|
192 { |
|
193 if ( iTitle ) |
|
194 { |
|
195 return *iTitle; |
|
196 } |
|
197 else |
|
198 { |
|
199 return KNullDesC; |
|
200 } |
|
201 } |
|
202 |
|
203 // -------------------------------------------------------------------------- |
|
204 // CUPnPMetaDataUtility::Artist |
|
205 // Returns artist for the song |
|
206 // (other items were commented in a header). |
|
207 // -------------------------------------------------------------------------- |
|
208 // |
|
209 EXPORT_C const TDesC& CUPnPMetaDataUtility::Artist() const |
|
210 { |
|
211 if ( iArtist ) |
|
212 { |
|
213 return *iArtist; |
|
214 } |
|
215 else |
|
216 { |
|
217 return KNullDesC; |
|
218 } |
|
219 } |
|
220 |
|
221 // -------------------------------------------------------------------------- |
|
222 // CUPnPMetaDataUtility::Album |
|
223 // Returns album for the song |
|
224 // (other items were commented in a header). |
|
225 // -------------------------------------------------------------------------- |
|
226 // |
|
227 EXPORT_C const TDesC& CUPnPMetaDataUtility::Album() const |
|
228 { |
|
229 if ( iAlbum ) |
|
230 { |
|
231 return *iAlbum; |
|
232 } |
|
233 else |
|
234 { |
|
235 return KNullDesC; |
|
236 } |
|
237 } |
|
238 |
|
239 // -------------------------------------------------------------------------- |
|
240 // CUPnPMetaDataUtility::Genre |
|
241 // Returns genre for the song |
|
242 // (other items were commented in a header). |
|
243 // -------------------------------------------------------------------------- |
|
244 // |
|
245 EXPORT_C const TDesC& CUPnPMetaDataUtility::Genre() const |
|
246 { |
|
247 if ( iGenre ) |
|
248 { |
|
249 return *iGenre; |
|
250 } |
|
251 else |
|
252 { |
|
253 return KNullDesC; |
|
254 } |
|
255 } |
|
256 |
|
257 // -------------------------------------------------------------------------- |
|
258 // CUPnPMetaDataUtility::Date |
|
259 // Returns date for the file |
|
260 // (other items were commented in a header). |
|
261 // -------------------------------------------------------------------------- |
|
262 // |
|
263 EXPORT_C const TDesC& CUPnPMetaDataUtility::Date() const |
|
264 { |
|
265 if ( iDate ) |
|
266 { |
|
267 return *iDate; |
|
268 } |
|
269 else |
|
270 { |
|
271 return KNullDesC; |
|
272 } |
|
273 } |
|
274 |
|
275 // -------------------------------------------------------------------------- |
|
276 // CUPnPMetaDataUtility::LoadTitleL |
|
277 // Finds the title(ID3 tag) of the file according to give file name |
|
278 // (other items were commented in a header). |
|
279 // -------------------------------------------------------------------------- |
|
280 // |
|
281 EXPORT_C void CUPnPMetaDataUtility::LoadTitleL( const TDesC& aFileName ) |
|
282 { |
|
283 // Cleanup existing information |
|
284 Reset(); |
|
285 |
|
286 RArray<TMetaDataFieldId> wantedFields; |
|
287 CleanupClosePushL( wantedFields ); |
|
288 wantedFields.Append( EMetaDataSongTitle ); |
|
289 |
|
290 // Reset to be sure that no allocations are left over |
|
291 iMetaDataUtility->ResetL(); |
|
292 |
|
293 // Open the file |
|
294 iMetaDataUtility->OpenFileL( aFileName, wantedFields ); |
|
295 |
|
296 // wantedFields is not needed anymore |
|
297 CleanupStack::PopAndDestroy( &wantedFields ); |
|
298 |
|
299 // Go through the meta data fields and pick the required ones |
|
300 TInt count = iMetaDataUtility->MetaDataCount(); |
|
301 |
|
302 if ( count > 0 ) |
|
303 { |
|
304 const CMetaDataFieldContainer& container = |
|
305 iMetaDataUtility->MetaDataFieldsL(); |
|
306 TMetaDataFieldId fieldId; |
|
307 for ( TInt index = 0; index < count; index++ ) |
|
308 { |
|
309 TPtrC content = container.At( index, fieldId ); |
|
310 if ( EMetaDataSongTitle == fieldId ) |
|
311 { |
|
312 iTitle = content.AllocL(); |
|
313 break; |
|
314 } |
|
315 } |
|
316 } |
|
317 |
|
318 // Cleanup |
|
319 iMetaDataUtility->ResetL(); |
|
320 } |
|
321 |
|
322 // --------------------------------------------------------------------------- |
|
323 // CUPnPMetaDataUtility::Reset |
|
324 // Reset member variables |
|
325 // (other items were commented in a header). |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 void CUPnPMetaDataUtility::Reset() |
|
329 { |
|
330 delete iTitle; |
|
331 iTitle = NULL; |
|
332 delete iArtist; |
|
333 iArtist = NULL; |
|
334 delete iAlbum; |
|
335 iAlbum = NULL; |
|
336 delete iGenre; |
|
337 iGenre = NULL; |
|
338 delete iDate; |
|
339 iDate = NULL; |
|
340 } |
|
341 |
|
342 // End of File |