profilesservices/MediaFileList/Inc/mediafilehandler.h
branchRCL_3
changeset 24 8ee96d21d9bf
parent 23 8bda91a87a00
child 25 7e0eff37aedb
equal deleted inserted replaced
23:8bda91a87a00 24:8ee96d21d9bf
     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         /**
       
   233         * Remove an item from list of search reuslt
       
   234         * @param aIndex Search list's index.
       
   235         * @return None.
       
   236         */
       
   237         void Remove( TInt aIndex );
       
   238 
       
   239     public:
       
   240         TInt ItemIndex( const TDesC& aItemText, TInt aIndex );
       
   241         TInt ItemIndex( TInt aItemId, TInt aIndex );
       
   242         
       
   243     private:
       
   244         
       
   245         void SearchVideoL( const TDesC& aSearchText );
       
   246         void SearchMusicL( const TDesC& aSearchText );
       
   247         void SearchTonesL( const TDesC& aSearchText );
       
   248         static TInt SearchTones( TAny *aObj );
       
   249         static TInt SearchVideo( TAny *aObj );
       
   250 
       
   251       
       
   252     public:
       
   253         void SetObserver( MMediaFileHandlerObserver* aObserver );
       
   254         void SetQueryId( TInt aId );
       
   255         void EnableObserverCall( TBool aEnable );
       
   256         
       
   257         
       
   258     public:
       
   259 	CMediaFileData* RomMediaFileDataL( TInt aId ,TInt aMediaType );
       
   260            
       
   261     private:
       
   262         CMdEPropertyDef& PropertyDefL( TInt aAttr );
       
   263         void StrCopy( TDes& aTarget, const TDesC& aSource );
       
   264         void CheckAttrL( TInt aAttr );
       
   265         void CallObserverWithDelay();
       
   266         void CallObserver( TInt aEvent, TInt aError );
       
   267         void AddObjectObserverL();
       
   268         
       
   269     public:
       
   270         static CMdEPropertyDef& PropertyDefL( CMdESession* aSession, TInt aAttr );
       
   271         
       
   272     private:
       
   273         void ExcludeRecordingsL( CMdELogicCondition& aCondition );
       
   274         void ExcludeRomFilesL( CMdELogicCondition& aCondition );
       
   275         void ExcludeMimeTypesL( CMdELogicCondition& aCondition, TInt aAttr );
       
   276         void IncludeMusicPropertiesL( CMdELogicCondition& aCondition );
       
   277         void ExcludeMusicPropertiesL( CMdELogicCondition& aCondition );
       
   278         void IncludeMusicSearchConditionL( CMdELogicCondition& aCondition,
       
   279                                            const TDesC& aSearchText );
       
   280         void IncludeToneSearchConditionL( CMdELogicCondition& aCondition,
       
   281                                            const TDesC& aSearchText );
       
   282         void IncludeVideoSearchConditionL( CMdELogicCondition& aCondition,
       
   283                                            const TDesC& aSearchText );
       
   284 
       
   285 
       
   286         
       
   287     private:
       
   288         void LeaveIfSessionClosedL();
       
   289         void Panic( TInt aReason );
       
   290         TInt MediaType( TInt aQueryType );
       
   291         
       
   292 
       
   293     private:  // from MMdESessionObserver
       
   294         void HandleSessionOpened(CMdESession& aSession, TInt aError);
       
   295         void HandleSessionError(CMdESession& aSession, TInt aError);
       
   296         
       
   297     
       
   298     private:  // from MMdEQueryObserver (mdequery.h)
       
   299         void HandleQueryNewResults( CMdEQuery& aQuery, TInt aFirstNewItemIndex,
       
   300                                     TInt aNewItemCount );
       
   301         void HandleQueryCompleted( CMdEQuery& aQuery, TInt aError );
       
   302         void HandleQueryCompletedL( CMdEQuery& aQuery, TInt aError );
       
   303         
       
   304     private:  // from MMdEObjectObserver
       
   305         void HandleObjectNotification( CMdESession& aSession, 
       
   306                                        TObserverNotificationType aType,
       
   307                                        const RArray<TItemId>& aObjectIdArray);
       
   308                                        
       
   309     private:  // from MMdEObjectPresentObserver
       
   310         void HandleObjectPresentNotification( CMdESession& aSession, 
       
   311                          TBool aPresent, const RArray<TItemId>& aObjectIdArray);
       
   312         
       
   313     private:   // from MMFActiveCallerObserver
       
   314          void HandleActiveCallL( TInt aCallId );
       
   315 
       
   316     private:
       
   317     
       
   318         // media file event observer
       
   319         MMediaFileHandlerObserver* iObserver;
       
   320        
       
   321         // session to metadata engine
       
   322         CMdESession* iSession;
       
   323       
       
   324         // metadata query
       
   325         CMdEObjectQuery* iQuery;
       
   326         
       
   327         // used for optimizing artist queries
       
   328         CArtistQuery* iArtistQuery;
       
   329 
       
   330         // search result list - ui shows items from this list
       
   331         CSearchList* iSearchList;
       
   332 
       
   333         // metadata search text
       
   334         TBuf<KBufSize128> iSearchText;
       
   335          
       
   336         // for generating active object calls
       
   337         CMFActiveCaller* iQueryCaller;
       
   338         // for generating active object calls
       
   339         CMFActiveCaller* iObjectNotificationCaller;
       
   340         
       
   341         // for finding out file drive type
       
   342         CDriveUtil* iDriveUtil;
       
   343         
       
   344         // mime types that are exluded from queries
       
   345         CMimeTypeList* iExcludedMimeTypes;
       
   346 
       
   347         // for starting video query after short delay
       
   348         CIdle* iIdle;
       
   349 
       
   350         // used to prevent observer call when query is canceled fro ui
       
   351         TBool iObserverCallEnabled;
       
   352         
       
   353         // query id from UI, not used in this class
       
   354         TInt iQueryId;
       
   355         
       
   356         // max audio file file size
       
   357         TInt iMaxFileSize;
       
   358         
       
   359         // is metadata session open
       
   360         TBool iSessionOpen;
       
   361 
       
   362         // query type 
       
   363         TInt iQueryType;
       
   364 
       
   365         // query error
       
   366         TInt iQueryError;
       
   367         
       
   368         // query event
       
   369         TInt iQueryEvent;
       
   370         
       
   371 	    TBool iVideoSearchDisabled; 
       
   372         
       
   373         TInt iMediaFileCounter;
       
   374         //for scan data from rom
       
   375         CRomFileList* iRomFileList;
       
   376 	    //Record the rom scan state.
       
   377 	    TInt iRomScanState;
       
   378 	    //Tone query in progress
       
   379 	    TBool iQueryinProgress;
       
   380 
       
   381     };
       
   382 
       
   383 
       
   384 
       
   385 
       
   386 /**
       
   387 * CSearchListItem
       
   388 *
       
   389 * Data for one media file item CSearchList.
       
   390 */
       
   391 NONSHARABLE_CLASS (CSearchListItem) : public CBase 
       
   392     {
       
   393     public:
       
   394         static CSearchListItem* NewLC();
       
   395         static CSearchListItem* NewL();
       
   396         virtual ~CSearchListItem();
       
   397 
       
   398     private:
       
   399         CSearchListItem();
       
   400         void ConstructL();
       
   401         
       
   402     public:
       
   403         void SetTitleL( const TDesC& aText, TBool aFullName );
       
   404         const TDesC& Title() const;
       
   405  
       
   406     public:
       
   407         TInt iId;
       
   408         TInt iMediaType;
       
   409         TInt iStorageType;
       
   410     private:
       
   411         HBufC* iTitle;
       
   412     };
       
   413 
       
   414 
       
   415 /**
       
   416 * CRomFileList
       
   417 * 
       
   418 * Used for reading media files from rom.
       
   419 */
       
   420 NONSHARABLE_CLASS (CRomFileList) : public CBase
       
   421     {
       
   422     public:
       
   423         static CRomFileList* NewL();
       
   424         virtual ~CRomFileList();
       
   425 
       
   426     private:
       
   427         CRomFileList();
       
   428         void ConstructL();
       
   429     public:
       
   430         void ReadDirectoryL( const TDesC& aDirectory, RArray<TFileName>& aList );
       
   431         void ReadDirectoryL( const TDesC& aDirectory, 
       
   432                                          RPointerArray<CSearchListItem>& aList );
       
   433 
       
   434         void ReadRomFilesL();
       
   435         void ReadRomVediosL();
       
   436         const TDesC& Item( TInt aIndex , TInt aType );
       
   437         TInt RomFileItem( CSearchListItem* aItem, TInt aIndex);
       
   438         TInt RomVedioItem( CSearchListItem* aItem, TInt aIndex);
       
   439         TInt Count( TInt aType );
       
   440         void Reset();
       
   441         
       
   442     public:
       
   443 //    //Used to return the rom file attribute in rom;
       
   444 //    TInt RomFileAttribute(TInt aIndex, TInt aAttr);
       
   445     //Used to return the title of rom item
       
   446     TInt GetRomFileName(TInt aIndex, TInt aType, TDes& aValue);
       
   447 private:
       
   448     CSearchListItem* SearchListItemFromRomL(const TDesC& aFileName,
       
   449             TInt aIndex);
       
   450 	//Used to get the title of rom item
       
   451 	void RomItemTitle(TInt aIndex, TDes& aTitle );
       
   452         
       
   453 private:
       
   454         TFileName iFileName;
       
   455         RArray<TFileName> iList;
       
   456         RArray<TFileName> iVedioList;
       
   457         RPointerArray<CSearchListItem> iRomToneList;
       
   458         RPointerArray<CSearchListItem> iRomVideoList;
       
   459 
       
   460     };
       
   461 
       
   462 /**
       
   463 * CSearchList
       
   464 *
       
   465 * List for storing search result for one (most recent) metadata query.
       
   466 */
       
   467 NONSHARABLE_CLASS (CSearchList) : public CBase 
       
   468     {
       
   469     public:
       
   470         static CSearchList* NewL();
       
   471         virtual ~CSearchList();
       
   472 
       
   473     private:
       
   474         CSearchList();
       
   475         void ConstructL();
       
   476         
       
   477     public:
       
   478         void SetSession( CMdESession* aSession );
       
   479         void SetRomFileList( CRomFileList* aRomFileList );
       
   480         void TakeResultL( CMdEObjectQuery* aQuery, TInt aMediaType );
       
   481         void TakeArtistResultL( CArtistQuery* aArtistQuery );
       
   482         void TakeDistinctResultL( CMdEObjectQuery* aQuery, TInt aMediaType );
       
   483         void SearchInToneL( CRomFileList* aQuery,  const TDesC& aSearchText );
       
   484         void VideoSearchInRomL( CRomFileList* aQuery,  const TDesC& aSearchText );
       
   485   
       
   486         void AddAlbumItemL( const TDesC& aAlbum );
       
   487         void AddItemL( CMdEObject& aObject, TInt aMediaType );
       
   488         void AddRomItemL( CRomFileList* aRomList, TInt aMediaType );
       
   489         void AddArtistItemL( CMdEObject& aObject, TInt aQueryType, const TDesC& aAlbum );
       
   490 
       
   491         void Reset();
       
   492         void Sort();
       
   493         TInt Count();
       
   494         void GetAttributeL( TInt aIndex, TInt aAttr, TDes& aValue );
       
   495         TInt Attribute( TInt aIndex, TInt aAttr );
       
   496         void SetSearchId( TInt aId );
       
   497         TInt SearchId();
       
   498         
       
   499         /**
       
   500         * Remove an item from the list of search results.
       
   501         * @param aIndex List's index.
       
   502         * @return None.
       
   503         */
       
   504         void Remove( TInt aIndex );
       
   505         
       
   506     public:
       
   507         TInt ItemIndex( TInt aId );
       
   508         TInt ItemIndex( const TDesC& aText );
       
   509         TInt ItemIndex( const TDesC& aText, TInt aIndex );
       
   510         TInt ItemIndex( TInt aId, TInt aIndex );
       
   511         
       
   512     private:
       
   513         static TInt Compare( const CSearchListItem& aFirst, 
       
   514                              const CSearchListItem& aSecond );
       
   515         void Panic( TInt aReason );
       
   516         const TDesC& TextL( CMdEObject& aObject, TInt aId );
       
   517        
       
   518     private:
       
   519         CMdESession* iSession;  // does not own
       
   520         
       
   521         CRomFileList* iRomFileList; //does not own
       
   522         
       
   523         // list of search results
       
   524         RPointerArray<CSearchListItem> iList;
       
   525         
       
   526         // for finding out drive type (eg memory card)
       
   527         CDriveUtil* iDriveUtil;
       
   528         
       
   529         // search id - not used in this class
       
   530         TInt iSearchId;
       
   531     };
       
   532 
       
   533 
       
   534 
       
   535 
       
   536 
       
   537 /**
       
   538 * CArtistQuery
       
   539 * 
       
   540 * CArtistQuery is for storing all metadata for one artist.
       
   541 * Once CArtistQuery is initialized it can be used to get artist 
       
   542 * subqueries without making more metadata queries.
       
   543 */
       
   544 NONSHARABLE_CLASS (CArtistQuery) : public CBase 
       
   545     {
       
   546     public:
       
   547         static CArtistQuery* NewL();
       
   548         virtual ~CArtistQuery();
       
   549 
       
   550     private:
       
   551         CArtistQuery();
       
   552         void ConstructL();
       
   553         
       
   554     public:
       
   555         void ResetL();
       
   556         
       
   557         void SetArtistL( const TDesC& aText );
       
   558         void SetAlbumL( const TDesC& aText );
       
   559         void SetQueryType( TInt aType );
       
   560         void SetQuery( CMdEObjectQuery* aQuery );
       
   561 
       
   562         const TDesC& Artist();
       
   563         const TDesC& Album();
       
   564         TInt QueryType();
       
   565         CMdEObjectQuery* Query();
       
   566         TInt UnknownCount();
       
   567         
       
   568     private:
       
   569         CMdEObjectQuery* iQuery;
       
   570         TInt iQueryType;
       
   571         
       
   572         HBufC* iArtist;
       
   573         HBufC* iAlbum;
       
   574     };
       
   575 
       
   576 
       
   577 
       
   578 #endif  // MEDIAFILEHANDLER_H
       
   579 
       
   580 // End of File