omads/omadsextensions/adapters/mediads/inc/mediamanager.h
changeset 40 b63e67867dcd
equal deleted inserted replaced
39:9905f7d46607 40:b63e67867dcd
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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:  Part of SyncML Data Synchronization Plug In Adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef _CMEDIAMANAGER_H
       
    21 #define _CMEDIAMANAGER_H
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <mpxmediageneraldefs.h>
       
    25 #include <mpxcollectionutility.h>
       
    26 #include <mpxcollectionmediator.h>
       
    27 #include <mpxcollectionobserver.h>
       
    28 #include <mpxharvesterutilityobserver.h>
       
    29 #include <mpxharvesterutility.h>
       
    30 #include <mpxcollectionhelperobserver.h>
       
    31  
       
    32 #include "changefinder.h"
       
    33 #include "songitem.h"
       
    34 
       
    35 class CMPXMedia;
       
    36 class MMPXCollectionHelper;
       
    37 
       
    38 class MMediaManagerObserver : public MMPXCollectionObserver
       
    39     {
       
    40 public:
       
    41     virtual void RegisterAllPlayListsCompleted( TInt aError ) = 0;
       
    42     virtual void RegisterAllSongsCompleted( TInt aError ) = 0;
       
    43     };
       
    44 
       
    45 /**
       
    46  * @brief This class manages playlist's on media library. Also songs metadata can be queried.
       
    47  * 
       
    48  */
       
    49 class CMediaManager : public CActive, private MMPXCollectionHelperObserver
       
    50     {
       
    51 public:
       
    52 
       
    53     static CMediaManager* NewL( RFs& aFs, MMediaManagerObserver* aObserver, TKeyArrayFix aKey, CMD5& aHasher );
       
    54     
       
    55     ~CMediaManager();
       
    56     
       
    57     /**
       
    58      * Starts scanning music library.
       
    59      * Calls MMPXCollectionObserver::HandleCollectionMessage when completed.
       
    60      */
       
    61     void ScanL();
       
    62     
       
    63     /**
       
    64      * Cancel scan
       
    65      */
       
    66     void CancelScanL();
       
    67     
       
    68     /**
       
    69      * Set current snapshot.
       
    70      * @param aSnapshot
       
    71      */
       
    72     void SetSnapshot( CSnapshotArray* aSnapshot ){iSnapshotArray=aSnapshot;};
       
    73     
       
    74     /**
       
    75      * Starts registering all playlists.
       
    76      * Snapshot must be set before calling this.
       
    77      * Calls MMediaManagerObserver::RegisterAllPlayListsCompleted when ready
       
    78      * @return KErrNone if operation succesfully started.
       
    79      */
       
    80     TInt RegisterAllPlayLists();
       
    81     
       
    82     /**
       
    83      * Starts registering all songs.
       
    84      * Snapshot must be set before calling this.
       
    85      * Calls MMediaManagerObserver::RegisterAllSongsCompleted when ready
       
    86      * @return KErrNone if operation succesfully started.
       
    87      */
       
    88     TInt RegisterAllSongs();
       
    89     
       
    90     /**
       
    91      * Gets CPlaylistItem
       
    92      * @param aPlaylistId playlist id to get.
       
    93      * @param aPlaylist returned playlist.
       
    94      */
       
    95     void GetPlayListL( TInt aPlaylistId, CPlaylistItem& aPlaylist );
       
    96     
       
    97     /**
       
    98      * Gets CSongItem
       
    99      * @param aSongId song id to get.
       
   100      * @param aSongItem returned song.
       
   101      */
       
   102     void GetSongL( TInt aSongId, CSongItem& aSongItem );
       
   103     
       
   104     /**
       
   105      * Creates new playlist to music library
       
   106      * @param aNewUid returns new playlist id, if succesfully added.
       
   107      * @param aPlaylist playlist to be added. Uri is updated to aPlaylist.
       
   108      */
       
   109     void CreateNewPlaylistL( TInt& aNewUid, CPlaylistItem& aPlaylist );
       
   110     
       
   111     /**
       
   112      * Replaces existing playlist in music library
       
   113      * @param aPlaylistId playlist id to be replaced. Uri is read to aPlaylist.
       
   114      * @param aPlaylist new content.
       
   115      */
       
   116     void ReplacePlaylistL( TInt aPlaylistId, CPlaylistItem& aPlaylist );
       
   117     
       
   118     /**
       
   119      * Deletes playlist from music library
       
   120      * @param aPlaylistId playlist id to be deleted.
       
   121      */
       
   122     void DeletePlaylistL( TInt aPlaylistId );
       
   123     
       
   124 private: // From MMPXCollectionHelperObserver
       
   125     void HandleAddFileCompleteL( TInt aErr );
       
   126     
       
   127 private:
       
   128     CMediaManager( RFs& aFs, MMediaManagerObserver* aObserver, TKeyArrayFix aKey, CMD5& aHasher );
       
   129     
       
   130     void ConstructL();
       
   131     
       
   132     void RegisterPlaylistL( const CMPXMedia& aMedia );
       
   133     
       
   134     void RegisterSongL( const CMPXMedia& aMedia );
       
   135     
       
   136     CMPXMedia* FetchPlaylistContentL( TInt aId );
       
   137     
       
   138     CMPXMedia* FindPlaylistL( TInt aUid );
       
   139     
       
   140     void AddPlaylistL( CMPXMedia* aMedia );
       
   141     
       
   142     void ReadSongAttributesL( const CMPXMedia& aMedia, CSongItem& aSongItem, TBool aReadFileDetails );
       
   143     
       
   144     CMPXMedia* CreatePlaylistMediaL( const CPlaylistItem& aPlaylist );
       
   145     
       
   146     CMPXMediaArray* CreateMediaArrayLC( const CPlaylistItem& aPlaylist );
       
   147     
       
   148     void ReadPlaylistCountL();
       
   149     void ReadPlaylistItemsL();
       
   150     
       
   151     void ReadSongCountL();
       
   152     void ReadSongItemsL();
       
   153 private: // from CActive
       
   154     
       
   155     void DoCancel();
       
   156     void RunL();
       
   157     TInt RunError( TInt aError );
       
   158     
       
   159 private:
       
   160     
       
   161     enum TState
       
   162         {
       
   163         EIdle = 0,
       
   164         EReadingPlaylistCount,
       
   165         EEnumeratingPlaylists,
       
   166         EReadingSongCount,
       
   167         EEnumeratingSongs
       
   168         };
       
   169     TState iCurrentState;
       
   170     
       
   171     CMPXMedia*              iFoundedMedia;
       
   172     TInt                    iReadedItems;
       
   173     TInt                    iItemsFound;
       
   174     CSnapshotArray*         iSnapshotArray; // not owned
       
   175     
       
   176     MMediaManagerObserver*  iObserver;
       
   177     const TKeyArrayFix      iKey;
       
   178     MMPXCollectionHelper*   iCollectionHelper;
       
   179     
       
   180     CMD5&                   iHasher;
       
   181     
       
   182     MMPXHarvesterUtility*   iHarvester;
       
   183     CMPXCollectionMediator* iMediator;
       
   184     MMPXCollectionUtility*  iCollection;
       
   185     RFs&                    iFs;
       
   186     
       
   187     bool                    iWaitOngoing;
       
   188     CActiveSchedulerWait    iWait;
       
   189     };
       
   190 
       
   191 
       
   192 #endif // _CMEDIAMANAGER_H