mmappcomponents/audiofetcher/inc/audiofetcherfilehandler.h
changeset 0 a2952bb97e68
child 63 91d5ad76f5c6
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2009 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: File handlder for Media Fetch plug-in
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef AUDIOFETCHERFILEHANDLER_H
       
    19 #define AUDIOFETCHERFILEHANDLER_H
       
    20 
       
    21 
       
    22 // INCLUDES
       
    23 
       
    24 #include "audiofetcherdialogutils.h"
       
    25 
       
    26 
       
    27 #include <mdesession.h>
       
    28 #include <mdequery.h>
       
    29 #include <mdelogiccondition.h>
       
    30 #include <mdeconstants.h>
       
    31 #include <mdeobjectquery.h>
       
    32 #include <mdccommon.h>
       
    33 #include <mdeitem.h>
       
    34 #include <mdeobject.h>
       
    35 
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 class CSearchList;
       
    39 
       
    40 // CONSTANTS
       
    41 
       
    42 _LIT( KMimeTypeAMR, "audio/amr" );
       
    43 _LIT( KMimeTypeWAV, "audio/wav" );
       
    44 _LIT( KMimeMp3, "mp3" );
       
    45 _LIT( KDriveZ, "z:\\" );
       
    46 _LIT( KSpace, " " );
       
    47 
       
    48 /**
       
    49 * MMediaFileHandlerObserver
       
    50 *
       
    51 * For observing CMediaFileHandler events.  
       
    52 */
       
    53 NONSHARABLE_CLASS (MAudioFetcherFileHandlerObserver)
       
    54     {
       
    55     public:
       
    56     enum TFileHandlerEvent
       
    57         {
       
    58         EInitComplete,
       
    59         EQueryComplete,
       
    60         EQueryCanceled,
       
    61         EUnknownQueryComplete,
       
    62         EMediaFileChanged,
       
    63         EError
       
    64         };
       
    65     
       
    66     public:
       
    67         virtual void HandleFileEventL( TInt aEvent, TInt aError ) = 0;
       
    68     };
       
    69 
       
    70 
       
    71 
       
    72 /**
       
    73 * CAudioFetcherFileHandler
       
    74 *
       
    75 * Used for making media file queries. For example get all songs for
       
    76 * one artist. Uses metadata engine.
       
    77 */
       
    78 NONSHARABLE_CLASS (CAudioFetcherFileHandler) : public CBase, 
       
    79                                         public MMdESessionObserver,
       
    80                                         public MMdEQueryObserver,
       
    81                                         public MMdEObjectObserver,
       
    82                                         public MMdEObjectPresentObserver,
       
    83                                         public MActiveCallerObserver
       
    84     {
       
    85     public:
       
    86     enum TMediaType
       
    87         {
       
    88         EMediaTypeTone = 0,
       
    89         EMediaTypeVideo,
       
    90         EMediaTypeRecording,
       
    91         EMediaTypeMusic,
       
    92         EMediaTypeImage,
       
    93         EMediaTypeAny,
       
    94         };
       
    95 
       
    96     enum TStorageType
       
    97          {
       
    98          EPhoneMemory = 0,
       
    99          EMassStorage,
       
   100          EMemoryCard
       
   101          };
       
   102 
       
   103     enum TQueryAttribute
       
   104         {
       
   105         EAttrMediaType = 20,  // integer
       
   106         EAttrFileSize,        // integer
       
   107         EAttrStorageType,     // integer
       
   108         EAttrMediaFileId,     // integer
       
   109         EAttrFileName,     // string
       
   110         EAttrFullName,     // string
       
   111         EAttrSongName,     // string
       
   112         EAttrArtist,       // string
       
   113         EAttrAlbum,        // string
       
   114         EAttrGenre,        // string
       
   115         EAttrComposer      // string
       
   116         };
       
   117 
       
   118     enum TQueryType
       
   119         {
       
   120         EQueryNone = 0,
       
   121         EQueryAudio,
       
   122         EQueryMusic,
       
   123         EQueryVideo,
       
   124         EQueryRecording,
       
   125         EQueryTone,
       
   126         EQueryRomFile,
       
   127         EQueryImage,
       
   128         ESearchAudio,
       
   129         ESearchVideo,
       
   130         ESearchMusic,
       
   131         ESearchTones,
       
   132         EQueryEmpty,
       
   133         EQueryUnknown,
       
   134         
       
   135         EQueryArtist,
       
   136         EQueryArtistAlbum,
       
   137         EQueryArtistAll,
       
   138         EQueryArtistUnknown,
       
   139         EQueryArtistEmpty,
       
   140         };
       
   141 
       
   142     public:
       
   143         static CAudioFetcherFileHandler* NewL();
       
   144         virtual ~CAudioFetcherFileHandler();
       
   145 
       
   146     private:
       
   147         CAudioFetcherFileHandler();
       
   148         void ConstructL();
       
   149 
       
   150     public:
       
   151         void QueryAudioL();
       
   152         void QueryImageL();
       
   153         void QueryVideoL();
       
   154         TInt QueryType();
       
   155         
       
   156         
       
   157     public:
       
   158         TInt ResultCount();
       
   159         TBool QueryReady();
       
   160         TInt Attribute( TInt aIndex, TInt aAttr, TInt aQueryId );
       
   161         void GetAttributeL( TInt aIndex, TInt aAttr, TDes& aValue, TInt aQueryId );
       
   162         void GetAttribute( TInt aIndex, TInt aAttr, TDes& aValue, TInt aQueryId );
       
   163         void CancelQuery();
       
   164 
       
   165     public:
       
   166         void SetObserver( MAudioFetcherFileHandlerObserver* aObserver );
       
   167         void SetQueryId( TInt aId );
       
   168         void EnableObserverCall( TBool aEnable );
       
   169         
       
   170     public:
       
   171         TInt RomFileAttribute( TInt aIndex, TInt aAttr );
       
   172         void GetRomFileAttribute( TInt aIndex, TInt aAttr, TDes& aValue );
       
   173            
       
   174     private:
       
   175         CMdEPropertyDef& PropertyDefL( TInt aAttr );
       
   176         void StrCopy( TDes& aTarget, const TDesC& aSource );
       
   177         void CheckAttrL( TInt aAttr );
       
   178         void CallObserverWithDelay();
       
   179         void CallObserver( TInt aEvent, TInt aError );
       
   180         void AddObjectObserverL();
       
   181         
       
   182     public:
       
   183         static CMdEPropertyDef& PropertyDefL( CMdESession* aSession, TInt aAttr );
       
   184         
       
   185     private:
       
   186 
       
   187         void ExcludeRomFilesL( CMdELogicCondition& aCondition );
       
   188 
       
   189     private:
       
   190         void LeaveIfSessionClosedL();
       
   191         void Panic( TInt aReason );
       
   192         TInt MediaType( TInt aQueryType );
       
   193 
       
   194     private:  // from MMdESessionObserver
       
   195         void HandleSessionOpened(CMdESession& aSession, TInt aError);
       
   196         void HandleSessionError(CMdESession& aSession, TInt aError);
       
   197         
       
   198     
       
   199     private:  // from MMdEQueryObserver (mdequery.h)
       
   200         void HandleQueryNewResults( CMdEQuery& aQuery, TInt aFirstNewItemIndex,
       
   201                                     TInt aNewItemCount );
       
   202         void HandleQueryCompleted( CMdEQuery& aQuery, TInt aError );
       
   203         void HandleQueryCompletedL( CMdEQuery& aQuery, TInt aError );
       
   204         
       
   205     private:  // from MMdEObjectObserver
       
   206         void HandleObjectNotification( CMdESession& aSession, 
       
   207                                        TObserverNotificationType aType,
       
   208                                        const RArray<TItemId>& aObjectIdArray);
       
   209                                        
       
   210     private:  // from MMdEObjectPresentObserver
       
   211         void HandleObjectPresentNotification( CMdESession& aSession, 
       
   212                          TBool aPresent, const RArray<TItemId>& aObjectIdArray);
       
   213         
       
   214     private:   // from MActiveCallerObserver
       
   215          void HandleActiveCallL( TInt aCallId );
       
   216 
       
   217     private:
       
   218     
       
   219         // media file event observer
       
   220         MAudioFetcherFileHandlerObserver* iObserver;
       
   221        
       
   222         // session to metadata engine
       
   223         CMdESession* iSession;
       
   224       
       
   225         // metadata query
       
   226         CMdEObjectQuery* iQuery;
       
   227 
       
   228         // search result list - ui shows items from this list
       
   229         CSearchList* iSearchList;
       
   230 
       
   231         // metadata search text
       
   232         TBuf<128> iSearchText;
       
   233          
       
   234         // for generating active object calls
       
   235         CActiveCaller* iQueryCaller;
       
   236         // for generating active object calls
       
   237         CActiveCaller* iObjectNotificationCaller;
       
   238         
       
   239         // for finding out file drive type
       
   240         CDriveUtil* iDriveUtil;
       
   241 
       
   242         // used to prevent observer call when query is canceled fro ui
       
   243         TBool iObserverCallEnabled;
       
   244         
       
   245         // query id from UI, not used in this class
       
   246         TInt iQueryId;
       
   247         
       
   248         // max audio file file size
       
   249         TInt iMaxFileSize;
       
   250         
       
   251         // is metadata session open
       
   252         TBool iSessionOpen;
       
   253 
       
   254         // query type 
       
   255         TInt iQueryType;
       
   256 
       
   257         // query error
       
   258         TInt iQueryError;
       
   259         
       
   260         // query event
       
   261         TInt iQueryEvent;
       
   262 
       
   263     };
       
   264 
       
   265 
       
   266 
       
   267 
       
   268 /**
       
   269 * CSearchListItem
       
   270 *
       
   271 * Data for one media file item CSearchList.
       
   272 */
       
   273 NONSHARABLE_CLASS (CSearchListItem) : public CBase 
       
   274     {
       
   275     public:
       
   276         static CSearchListItem* NewLC();
       
   277         virtual ~CSearchListItem();
       
   278 
       
   279     private:
       
   280         CSearchListItem();
       
   281         void ConstructL();
       
   282         
       
   283     public:
       
   284         void SetTitleL( const TDesC& aText, TBool aFullName );
       
   285         const TDesC& Title() const;
       
   286  
       
   287     public:
       
   288         TInt iId;
       
   289         TInt iMediaType;
       
   290         TInt iStorageType;
       
   291     private:
       
   292         HBufC* iTitle;
       
   293     };
       
   294 
       
   295 
       
   296 /**
       
   297 * CSearchList
       
   298 *
       
   299 * List for storing search result for one (most recent) metadata query.
       
   300 */
       
   301 NONSHARABLE_CLASS (CSearchList) : public CBase 
       
   302     {
       
   303     public:
       
   304         static CSearchList* NewL();
       
   305         virtual ~CSearchList();
       
   306 
       
   307     private:
       
   308         CSearchList();
       
   309         void ConstructL();
       
   310         
       
   311     public:
       
   312         void SetSession( CMdESession* aSession );
       
   313         void TakeResultL( CMdEObjectQuery* aQuery, TInt aMediaType );
       
   314         //void TakeArtistResultL( CArtistQuery* aArtistQuery );
       
   315         void TakeDistinctResultL( CMdEObjectQuery* aQuery, TInt aMediaType );
       
   316   
       
   317         void AddAlbumItemL( const TDesC& aAlbum );
       
   318         void AddItemL( CMdEObject& aObject, TInt aMediaType );
       
   319         void AddArtistItemL( CMdEObject& aObject, TInt aQueryType, const TDesC& aAlbum );
       
   320 
       
   321         void Reset();
       
   322         void Sort();
       
   323         TInt Count();
       
   324         void GetAttributeL( TInt aIndex, TInt aAttr, TDes& aValue );
       
   325         TInt Attribute( TInt aIndex, TInt aAttr );
       
   326         void SetSearchId( TInt aId );
       
   327         TInt SearchId();
       
   328         
       
   329     private:
       
   330         static TInt Compare( const CSearchListItem& aFirst, 
       
   331                              const CSearchListItem& aSecond );
       
   332         
       
   333         static void StrCopy( TDes& aTarget, const TDesC& aSource );
       
   334         void Panic( TInt aReason );
       
   335         const TDesC& TextL( CMdEObject& aObject, TInt aId );
       
   336        
       
   337     private:
       
   338         CMdESession* iSession;  // does not own
       
   339         
       
   340         // list of search results
       
   341         RPointerArray<CSearchListItem> iList;
       
   342         
       
   343         // for finding out drive type (eg memory card)
       
   344         CDriveUtil* iDriveUtil;
       
   345         
       
   346         // search id - not used in this class
       
   347         TInt iSearchId;
       
   348     };
       
   349 
       
   350 #endif  // AUDIOFETCHERFILEHANDLER_H
       
   351 
       
   352 // End of File