1 /* |
|
2 * Copyright (c) 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: Used to interact with the MDE. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef MEDIAFILEHANDLER_H |
|
21 #define MEDIAFILEHANDLER_H |
|
22 |
|
23 |
|
24 // INCLUDES |
|
25 |
|
26 #include "mediafiledialogutils.h" |
|
27 |
|
28 |
|
29 #include <mdesession.h> |
|
30 #include <mdequery.h> |
|
31 #include <mdelogiccondition.h> |
|
32 #include <mdeconstants.h> |
|
33 #include <mdeobjectquery.h> |
|
34 #include <mdccommon.h> |
|
35 #include <mdeitem.h> |
|
36 #include <mdeobject.h> |
|
37 |
|
38 |
|
39 // FORWARD DECLARATIONS |
|
40 class CSearchList; |
|
41 class CRomFileList; |
|
42 class CArtistQuery; |
|
43 |
|
44 // CONSTANTS |
|
45 |
|
46 _LIT( KMimeTypeAMR, "audio/amr" ); |
|
47 _LIT( KMimeTypeWAV, "audio/wav" ); |
|
48 _LIT( KMimeMp3, "mp3" ); |
|
49 _LIT( KDriveZ, "z:\\" ); |
|
50 _LIT( KSpace, " " ); |
|
51 |
|
52 |
|
53 /** |
|
54 * CMediaFileData |
|
55 * |
|
56 * Used for storing metadata information for one media file. |
|
57 */ |
|
58 NONSHARABLE_CLASS (CMediaFileData) : public CBase |
|
59 { |
|
60 public: |
|
61 static CMediaFileData* NewL(); |
|
62 virtual ~CMediaFileData(); |
|
63 |
|
64 private: |
|
65 CMediaFileData(); |
|
66 void ConstructL(); |
|
67 |
|
68 public: |
|
69 const TDesC& Attr( TInt aAttr ); |
|
70 void GetAttr( TInt aAttr, TDes& aValue ); |
|
71 void SetAttrL( TInt aAttr, const TDesC& aValue ); |
|
72 |
|
73 public: |
|
74 TInt iMediaFileType; |
|
75 |
|
76 private: |
|
77 HBufC* iFullName; |
|
78 HBufC* iName; |
|
79 HBufC* iArtist; |
|
80 HBufC* iAlbum; |
|
81 HBufC* iGenre; |
|
82 HBufC* iComposer; |
|
83 }; |
|
84 |
|
85 |
|
86 /** |
|
87 * MMediaFileHandlerObserver |
|
88 * |
|
89 * For observing CMediaFileHandler events. |
|
90 */ |
|
91 NONSHARABLE_CLASS (MMediaFileHandlerObserver) |
|
92 { |
|
93 public: |
|
94 enum TMediaFileHandlerEvent |
|
95 { |
|
96 EInitComplete, |
|
97 EQueryComplete, |
|
98 EQueryCanceled, |
|
99 EUnknownQueryComplete, |
|
100 EMediaFileChanged, |
|
101 EScanRomComplete, |
|
102 EError |
|
103 }; |
|
104 |
|
105 enum TScanRomState |
|
106 { |
|
107 ENoneRomScan, |
|
108 ERomScanInProgress, |
|
109 ERomScanComplete, |
|
110 ERomScanError |
|
111 }; |
|
112 |
|
113 public: |
|
114 virtual void HandleMFEventL( TInt aEvent, TInt aError ) = 0; |
|
115 }; |
|
116 |
|
117 |
|
118 |
|
119 /** |
|
120 * CMediaFileHandler |
|
121 * |
|
122 * Used for making media file queries. For example get all songs for |
|
123 * one artist. Uses metadata engine. |
|
124 */ |
|
125 NONSHARABLE_CLASS (CMediaFileHandler) : public CBase, |
|
126 public MMdESessionObserver, |
|
127 public MMdEQueryObserver, |
|
128 public MMdEObjectObserver, |
|
129 public MMdEObjectPresentObserver, |
|
130 public MMFActiveCallerObserver |
|
131 { |
|
132 public: |
|
133 enum TMediaType |
|
134 { |
|
135 EMediaTypeTone = 0, |
|
136 EMediaTypeVideo, |
|
137 EMediaTypeRecording, |
|
138 EMediaTypeMusic |
|
139 }; |
|
140 |
|
141 enum TStorageType |
|
142 { |
|
143 EPhoneMemory = 0, |
|
144 ERomStorage, |
|
145 EMassStorage, |
|
146 EMemoryCard |
|
147 }; |
|
148 |
|
149 enum TQueryAttribute |
|
150 { |
|
151 EAttrMediaType = 20, // integer |
|
152 EAttrFileSize, // integer |
|
153 EAttrStorageType, // integer |
|
154 EAttrMediaFileId, // integer |
|
155 EAttrFileName, // string |
|
156 EAttrFullName, // string |
|
157 EAttrSongName, // string |
|
158 EAttrArtist, // string |
|
159 EAttrAlbum, // string |
|
160 EAttrGenre, // string |
|
161 EAttrComposer // string |
|
162 }; |
|
163 |
|
164 enum TQueryType |
|
165 { |
|
166 EQueryNone = 0, |
|
167 EQueryAudio, |
|
168 EQueryMusic, |
|
169 EQueryVideo, |
|
170 EQueryRecording, |
|
171 EQueryTone, |
|
172 ESearchAudio, |
|
173 ESearchVideo, |
|
174 ESearchMusic, |
|
175 ESearchTones, |
|
176 EQueryEmpty, |
|
177 EQueryUnknown, |
|
178 |
|
179 EQueryArtist, |
|
180 EQueryArtistAlbum, |
|
181 EQueryArtistAll, |
|
182 EQueryArtistUnknown, |
|
183 EQueryArtistEmpty, |
|
184 }; |
|
185 |
|
186 public: |
|
187 static CMediaFileHandler* NewL(); |
|
188 virtual ~CMediaFileHandler(); |
|
189 |
|
190 private: |
|
191 CMediaFileHandler(); |
|
192 void ConstructL(); |
|
193 |
|
194 public: |
|
195 void SetAttrL( TInt aAttr, TInt aValue ); |
|
196 void SetAttrL( TInt aAttr, const TDesC& aValue ); |
|
197 void SetAttrL( TInt aAttr, TAny* aValue ); |
|
198 |
|
199 public: |
|
200 void QueryMusicL( TInt aAttr ); |
|
201 void QueryMusicL( TInt aAttr, const TDesC& aFindText ); |
|
202 void QueryMusicUnknownL( TInt aAttr ); |
|
203 void QueryMusicUnknownCountL( TInt aAttr ); |
|
204 void QueryAttributeValuesL( TInt aAttr ); |
|
205 void QueryArtistL( TInt aAttr, const TDesC& aArtist, |
|
206 const TDesC& aAlbum, TBool aRefresh = EFalse ); |
|
207 void QueryArtistEmptyL(); |
|
208 void QueryEmptyL(); |
|
209 void QueryRomEmptyL( TInt aQueryType ); |
|
210 |
|
211 void QueryVideosL( TInt aAttr ); |
|
212 void QueryRecordingsL( TInt aAttr ); |
|
213 void QueryTonesL( TInt aAttr ); |
|
214 void QueryDefaultTonesL( TInt /*aAttr*/ ); |
|
215 |
|
216 void SearchL( const TDesC& aSearchText ); |
|
217 void SearchAudioL( const TDesC& aSearchText ); |
|
218 |
|
219 void StartRomScaning( TInt aQueryType ); |
|
220 |
|
221 public: |
|
222 TInt UnknownArtistCount(); |
|
223 TInt UnknownArtistCountL(); |
|
224 TInt ResultCount(); |
|
225 TBool QueryReady(); |
|
226 TInt Attribute( TInt aIndex, TInt aAttr, TInt aQueryId ); |
|
227 void GetAttributeL( TInt aIndex, TInt aAttr, TDes& aValue, TInt aQueryId ); |
|
228 void GetAttribute( TInt aIndex, TInt aAttr, TDes& aValue, TInt aQueryId ); |
|
229 CMediaFileData* ReadMediaFileDataL( TInt aId ); |
|
230 void CancelQuery(); |
|
231 |
|
232 public: |
|
233 TInt ItemIndex( const TDesC& aItemText, TInt aIndex ); |
|
234 TInt ItemIndex( TInt aItemId, TInt aIndex ); |
|
235 |
|
236 private: |
|
237 |
|
238 void SearchVideoL( const TDesC& aSearchText ); |
|
239 void SearchMusicL( const TDesC& aSearchText ); |
|
240 void SearchTonesL( const TDesC& aSearchText ); |
|
241 static TInt SearchTones( TAny *aObj ); |
|
242 static TInt SearchVideo( TAny *aObj ); |
|
243 |
|
244 |
|
245 public: |
|
246 void SetObserver( MMediaFileHandlerObserver* aObserver ); |
|
247 void SetQueryId( TInt aId ); |
|
248 void EnableObserverCall( TBool aEnable ); |
|
249 |
|
250 |
|
251 public: |
|
252 CMediaFileData* RomMediaFileDataL( TInt aId ,TInt aMediaType ); |
|
253 |
|
254 private: |
|
255 CMdEPropertyDef& PropertyDefL( TInt aAttr ); |
|
256 void StrCopy( TDes& aTarget, const TDesC& aSource ); |
|
257 void CheckAttrL( TInt aAttr ); |
|
258 void CallObserverWithDelay(); |
|
259 void CallObserver( TInt aEvent, TInt aError ); |
|
260 void AddObjectObserverL(); |
|
261 |
|
262 public: |
|
263 static CMdEPropertyDef& PropertyDefL( CMdESession* aSession, TInt aAttr ); |
|
264 |
|
265 private: |
|
266 void ExcludeRecordingsL( CMdELogicCondition& aCondition ); |
|
267 void ExcludeRomFilesL( CMdELogicCondition& aCondition ); |
|
268 void ExcludeMimeTypesL( CMdELogicCondition& aCondition, TInt aAttr ); |
|
269 void IncludeMusicPropertiesL( CMdELogicCondition& aCondition ); |
|
270 void ExcludeMusicPropertiesL( CMdELogicCondition& aCondition ); |
|
271 void IncludeMusicSearchConditionL( CMdELogicCondition& aCondition, |
|
272 const TDesC& aSearchText ); |
|
273 void IncludeToneSearchConditionL( CMdELogicCondition& aCondition, |
|
274 const TDesC& aSearchText ); |
|
275 void IncludeVideoSearchConditionL( CMdELogicCondition& aCondition, |
|
276 const TDesC& aSearchText ); |
|
277 |
|
278 |
|
279 |
|
280 private: |
|
281 void LeaveIfSessionClosedL(); |
|
282 void Panic( TInt aReason ); |
|
283 TInt MediaType( TInt aQueryType ); |
|
284 |
|
285 |
|
286 private: // from MMdESessionObserver |
|
287 void HandleSessionOpened(CMdESession& aSession, TInt aError); |
|
288 void HandleSessionError(CMdESession& aSession, TInt aError); |
|
289 |
|
290 |
|
291 private: // from MMdEQueryObserver (mdequery.h) |
|
292 void HandleQueryNewResults( CMdEQuery& aQuery, TInt aFirstNewItemIndex, |
|
293 TInt aNewItemCount ); |
|
294 void HandleQueryCompleted( CMdEQuery& aQuery, TInt aError ); |
|
295 void HandleQueryCompletedL( CMdEQuery& aQuery, TInt aError ); |
|
296 |
|
297 private: // from MMdEObjectObserver |
|
298 void HandleObjectNotification( CMdESession& aSession, |
|
299 TObserverNotificationType aType, |
|
300 const RArray<TItemId>& aObjectIdArray); |
|
301 |
|
302 private: // from MMdEObjectPresentObserver |
|
303 void HandleObjectPresentNotification( CMdESession& aSession, |
|
304 TBool aPresent, const RArray<TItemId>& aObjectIdArray); |
|
305 |
|
306 private: // from MMFActiveCallerObserver |
|
307 void HandleActiveCallL( TInt aCallId ); |
|
308 |
|
309 private: |
|
310 |
|
311 // media file event observer |
|
312 MMediaFileHandlerObserver* iObserver; |
|
313 |
|
314 // session to metadata engine |
|
315 CMdESession* iSession; |
|
316 |
|
317 // metadata query |
|
318 CMdEObjectQuery* iQuery; |
|
319 |
|
320 // used for optimizing artist queries |
|
321 CArtistQuery* iArtistQuery; |
|
322 |
|
323 // search result list - ui shows items from this list |
|
324 CSearchList* iSearchList; |
|
325 |
|
326 // metadata search text |
|
327 TBuf<KBufSize128> iSearchText; |
|
328 |
|
329 // for generating active object calls |
|
330 CMFActiveCaller* iQueryCaller; |
|
331 // for generating active object calls |
|
332 CMFActiveCaller* iObjectNotificationCaller; |
|
333 |
|
334 // for finding out file drive type |
|
335 CDriveUtil* iDriveUtil; |
|
336 |
|
337 // mime types that are exluded from queries |
|
338 CMimeTypeList* iExcludedMimeTypes; |
|
339 |
|
340 // for starting video query after short delay |
|
341 CIdle* iIdle; |
|
342 |
|
343 // used to prevent observer call when query is canceled fro ui |
|
344 TBool iObserverCallEnabled; |
|
345 |
|
346 // query id from UI, not used in this class |
|
347 TInt iQueryId; |
|
348 |
|
349 // max audio file file size |
|
350 TInt iMaxFileSize; |
|
351 |
|
352 // is metadata session open |
|
353 TBool iSessionOpen; |
|
354 |
|
355 // query type |
|
356 TInt iQueryType; |
|
357 |
|
358 // query error |
|
359 TInt iQueryError; |
|
360 |
|
361 // query event |
|
362 TInt iQueryEvent; |
|
363 |
|
364 TBool iVideoSearchDisabled; |
|
365 |
|
366 TInt iMediaFileCounter; |
|
367 //for scan data from rom |
|
368 CRomFileList* iRomFileList; |
|
369 //Record the rom scan state. |
|
370 TInt iRomScanState; |
|
371 //Tone query in progress |
|
372 TBool iQueryinProgress; |
|
373 |
|
374 }; |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 /** |
|
380 * CSearchListItem |
|
381 * |
|
382 * Data for one media file item CSearchList. |
|
383 */ |
|
384 NONSHARABLE_CLASS (CSearchListItem) : public CBase |
|
385 { |
|
386 public: |
|
387 static CSearchListItem* NewLC(); |
|
388 static CSearchListItem* NewL(); |
|
389 virtual ~CSearchListItem(); |
|
390 |
|
391 private: |
|
392 CSearchListItem(); |
|
393 void ConstructL(); |
|
394 |
|
395 public: |
|
396 void SetTitleL( const TDesC& aText, TBool aFullName ); |
|
397 const TDesC& Title() const; |
|
398 |
|
399 public: |
|
400 TInt iId; |
|
401 TInt iMediaType; |
|
402 TInt iStorageType; |
|
403 private: |
|
404 HBufC* iTitle; |
|
405 }; |
|
406 |
|
407 |
|
408 /** |
|
409 * CRomFileList |
|
410 * |
|
411 * Used for reading media files from rom. |
|
412 */ |
|
413 NONSHARABLE_CLASS (CRomFileList) : public CBase |
|
414 { |
|
415 public: |
|
416 static CRomFileList* NewL(); |
|
417 virtual ~CRomFileList(); |
|
418 |
|
419 private: |
|
420 CRomFileList(); |
|
421 void ConstructL(); |
|
422 public: |
|
423 void ReadDirectoryL( const TDesC& aDirectory, RArray<TFileName>& aList ); |
|
424 void ReadDirectoryL( const TDesC& aDirectory, |
|
425 RPointerArray<CSearchListItem>& aList ); |
|
426 |
|
427 void ReadRomFilesL(); |
|
428 void ReadRomVediosL(); |
|
429 const TDesC& Item( TInt aIndex , TInt aType ); |
|
430 TInt RomFileItem( CSearchListItem* aItem, TInt aIndex); |
|
431 TInt RomVedioItem( CSearchListItem* aItem, TInt aIndex); |
|
432 TInt Count( TInt aType ); |
|
433 void Reset(); |
|
434 |
|
435 public: |
|
436 // //Used to return the rom file attribute in rom; |
|
437 // TInt RomFileAttribute(TInt aIndex, TInt aAttr); |
|
438 //Used to return the title of rom item |
|
439 TInt GetRomFileName(TInt aIndex, TInt aType, TDes& aValue); |
|
440 private: |
|
441 CSearchListItem* SearchListItemFromRomL(const TDesC& aFileName, |
|
442 TInt aIndex); |
|
443 //Used to get the title of rom item |
|
444 void RomItemTitle(TInt aIndex, TDes& aTitle ); |
|
445 |
|
446 private: |
|
447 TFileName iFileName; |
|
448 RArray<TFileName> iList; |
|
449 RArray<TFileName> iVedioList; |
|
450 RPointerArray<CSearchListItem> iRomToneList; |
|
451 RPointerArray<CSearchListItem> iRomVideoList; |
|
452 |
|
453 }; |
|
454 |
|
455 /** |
|
456 * CSearchList |
|
457 * |
|
458 * List for storing search result for one (most recent) metadata query. |
|
459 */ |
|
460 NONSHARABLE_CLASS (CSearchList) : public CBase |
|
461 { |
|
462 public: |
|
463 static CSearchList* NewL(); |
|
464 virtual ~CSearchList(); |
|
465 |
|
466 private: |
|
467 CSearchList(); |
|
468 void ConstructL(); |
|
469 |
|
470 public: |
|
471 void SetSession( CMdESession* aSession ); |
|
472 void SetRomFileList( CRomFileList* aRomFileList ); |
|
473 void TakeResultL( CMdEObjectQuery* aQuery, TInt aMediaType ); |
|
474 void TakeArtistResultL( CArtistQuery* aArtistQuery ); |
|
475 void TakeDistinctResultL( CMdEObjectQuery* aQuery, TInt aMediaType ); |
|
476 void SearchInToneL( CRomFileList* aQuery, const TDesC& aSearchText ); |
|
477 void VideoSearchInRomL( CRomFileList* aQuery, const TDesC& aSearchText ); |
|
478 |
|
479 void AddAlbumItemL( const TDesC& aAlbum ); |
|
480 void AddItemL( CMdEObject& aObject, TInt aMediaType ); |
|
481 void AddRomItemL( CRomFileList* aRomList, TInt aMediaType ); |
|
482 void AddArtistItemL( CMdEObject& aObject, TInt aQueryType, const TDesC& aAlbum ); |
|
483 |
|
484 void Reset(); |
|
485 void Sort(); |
|
486 TInt Count(); |
|
487 void GetAttributeL( TInt aIndex, TInt aAttr, TDes& aValue ); |
|
488 TInt Attribute( TInt aIndex, TInt aAttr ); |
|
489 void SetSearchId( TInt aId ); |
|
490 TInt SearchId(); |
|
491 |
|
492 public: |
|
493 TInt ItemIndex( TInt aId ); |
|
494 TInt ItemIndex( const TDesC& aText ); |
|
495 TInt ItemIndex( const TDesC& aText, TInt aIndex ); |
|
496 TInt ItemIndex( TInt aId, TInt aIndex ); |
|
497 |
|
498 private: |
|
499 static TInt Compare( const CSearchListItem& aFirst, |
|
500 const CSearchListItem& aSecond ); |
|
501 void Panic( TInt aReason ); |
|
502 const TDesC& TextL( CMdEObject& aObject, TInt aId ); |
|
503 |
|
504 private: |
|
505 CMdESession* iSession; // does not own |
|
506 |
|
507 CRomFileList* iRomFileList; //does not own |
|
508 |
|
509 // list of search results |
|
510 RPointerArray<CSearchListItem> iList; |
|
511 |
|
512 // for finding out drive type (eg memory card) |
|
513 CDriveUtil* iDriveUtil; |
|
514 |
|
515 // search id - not used in this class |
|
516 TInt iSearchId; |
|
517 }; |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 /** |
|
524 * CArtistQuery |
|
525 * |
|
526 * CArtistQuery is for storing all metadata for one artist. |
|
527 * Once CArtistQuery is initialized it can be used to get artist |
|
528 * subqueries without making more metadata queries. |
|
529 */ |
|
530 NONSHARABLE_CLASS (CArtistQuery) : public CBase |
|
531 { |
|
532 public: |
|
533 static CArtistQuery* NewL(); |
|
534 virtual ~CArtistQuery(); |
|
535 |
|
536 private: |
|
537 CArtistQuery(); |
|
538 void ConstructL(); |
|
539 |
|
540 public: |
|
541 void ResetL(); |
|
542 |
|
543 void SetArtistL( const TDesC& aText ); |
|
544 void SetAlbumL( const TDesC& aText ); |
|
545 void SetQueryType( TInt aType ); |
|
546 void SetQuery( CMdEObjectQuery* aQuery ); |
|
547 |
|
548 const TDesC& Artist(); |
|
549 const TDesC& Album(); |
|
550 TInt QueryType(); |
|
551 CMdEObjectQuery* Query(); |
|
552 TInt UnknownCount(); |
|
553 |
|
554 private: |
|
555 CMdEObjectQuery* iQuery; |
|
556 TInt iQueryType; |
|
557 |
|
558 HBufC* iArtist; |
|
559 HBufC* iAlbum; |
|
560 }; |
|
561 |
|
562 |
|
563 |
|
564 #endif // MEDIAFILEHANDLER_H |
|
565 |
|
566 // End of File |
|