mmappcomponents/harvester/utility/inc/mpxharvesterutilityimp.h
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     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:  Harvester Utility Implementation class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CMPXHARVESTERUTILITYIMP_H
       
    20 #define CMPXHARVESTERUTILITYIMP_H
       
    21 
       
    22 #include <mpxsession.h>
       
    23 #include <mpxharvestercommon.h>
       
    24 #include "mpxharvesterutility.h"
       
    25 
       
    26 // Foward Declaration
       
    27 class MMPXHarvesterUtilityObserver;
       
    28 
       
    29 /**
       
    30  *  Harvester Utility, RSession owner
       
    31  *
       
    32  *  Session class to the harvester server
       
    33  *
       
    34  *  @lib mpxharvesterutility.lib
       
    35  *  @since S60 v3.0
       
    36  */
       
    37 NONSHARABLE_CLASS( CMPXHarvesterUtilityImp ): public CActive,
       
    38                                            public MMPXHarvesterUtility
       
    39     {
       
    40 
       
    41 public:
       
    42 
       
    43     /**
       
    44     * Two Phase constructor
       
    45     * @return CMPXHarvesterUtilityImp instance
       
    46     */
       
    47     static CMPXHarvesterUtilityImp* NewL();
       
    48 
       
    49     /**
       
    50     * destructor
       
    51     */
       
    52     virtual ~CMPXHarvesterUtilityImp();
       
    53 
       
    54 protected:
       
    55 
       
    56     /*
       
    57     * From MMPXHarvesterUtility
       
    58     * Initiates a scan to refresh the database
       
    59     */
       
    60     void ScanL();
       
    61 
       
    62     /*
       
    63     * From MMPXHarvesterUtility
       
    64     * Cancels a scan to refresh the db
       
    65     */
       
    66     void CancelScanL();
       
    67 
       
    68     /*
       
    69     * From MMPXHarvesterUtility
       
    70     * Shutdown the server
       
    71     */
       
    72     void ShutdownL();
       
    73 
       
    74     /**
       
    75     * From MMPXHarvesterUtility
       
    76     * Add a single song
       
    77     * @param aFilePath path to the song to be added
       
    78     * @param aObs observer to the AddFileL() event
       
    79     */
       
    80     void AddFileL( const TDesC& aFilePath, MMPXHarvesterUtilityObserver* aObs );
       
    81 
       
    82     /**
       
    83     * From MMPXHarvesterUtility
       
    84     * Add a media object
       
    85     * @param aMedia, media object to add
       
    86     * @return, collection ID for this media property
       
    87     */
       
    88     TInt AddFileL( CMPXMedia*& aMedia );
       
    89 
       
    90     /**
       
    91     * From MMPXHarvesterUtility
       
    92     * Remove a single song
       
    93     * @param aFilePath, path to the item to be removed
       
    94     * @return, Collection ID for the item
       
    95     */
       
    96     TInt RemoveFileL( const TDesC& aFilePath );
       
    97 
       
    98     /**
       
    99     * From MMPXHarvesterUtility
       
   100     * Remove a list of songs
       
   101     * @param aFilesArray, list of songs to remove
       
   102     */
       
   103     void RemoveFilesL( const MDesCArray& aFilesArray );
       
   104 
       
   105     /**
       
   106     * From MMPXHarvesterUtility
       
   107     * Remove all songs from the harvester
       
   108     */
       
   109     void RemoveAllFilesL();
       
   110 
       
   111     /**
       
   112     * From MMPXHarvesterUtility
       
   113     * Remove all databases and re-create the db to handle corruption
       
   114     */
       
   115     void RecreateDatabasesL();
       
   116 
       
   117     /**
       
   118     * From MMPXHarvesterUtility
       
   119     * Remove a single song
       
   120     * @param aFilePath, path to the item to be removed
       
   121     * @param aObs observer to the delete operation
       
   122     */
       
   123     void DeleteFileL( const TDesC& aFilePath, MMPXHarvesterUtilityObserver* aObs  );
       
   124 
       
   125     /**
       
   126     * From MMPXHarvesterUtility
       
   127     * Remove a list of songs
       
   128     * @param aArray, list of songs to remove
       
   129     * @param aObs observer to the delete operation
       
   130     */
       
   131     void DeleteFilesL( const MDesCArray& aArray, MMPXHarvesterUtilityObserver* aObs );
       
   132 
       
   133     /**
       
   134     * From MMPXHarvesterUtility
       
   135     * Remove a list of songs
       
   136     * @param aArray, list of songs to remove
       
   137     */
       
   138     void DeleteFilesL( const MDesCArray& aArray );
       
   139 
       
   140     /**
       
   141     * From MMPXHarvesterUtility
       
   142     * Remove a list of songs
       
   143     * @param aArray, list of songs to remove
       
   144     * @param aEndTransaction ETrue to end current database transaction
       
   145     */
       
   146     void DeleteFilesL( const MDesCArray& aArray, TBool aEndTransaction );
       
   147 
       
   148     /**
       
   149      * From MMPXHarvesterUtility
       
   150      * Close the transaction.
       
   151      */
       
   152     void CloseTransactionL();
       
   153 
       
   154     /**
       
   155     * From MMPXHarvesterUtility
       
   156     * Update the collection id column in the harvester for a media
       
   157     * @param aMedia media object containing the item to update
       
   158     */
       
   159     void UpdateFileL( CMPXMedia*& aMedia );
       
   160 
       
   161     /**
       
   162     * From MMPXHarvesterUtility
       
   163     * Rename file for the given media. This method only supports
       
   164     * playlist renaming.
       
   165     * @param aMedia media to be renamed. this media must contain
       
   166     *        the new title of the playlist, the existing uri of
       
   167     *        the playlist
       
   168     * @return new URI of the renamed playlist media, ownership transferred
       
   169     */
       
   170     HBufC* RenameFileLC( const CMPXMedia& aMedia );
       
   171 
       
   172     /**
       
   173     * Rename file
       
   174     * @param aOldUri, existing URI
       
   175     * @param aNewUri, new URI
       
   176     * @param aCollection, collection Id of the collection the file belongs to
       
   177     */
       
   178     void RenameFileL( const TDesC& aOldUri,
       
   179                       const TDesC& aNewUri,
       
   180                       TInt aCollection );
       
   181 
       
   182     /*
       
   183     * From MMPXHarvesterUtility
       
   184     * Finds the collection ID based on a File name
       
   185     * @param aFile, file name to lookup
       
   186     * @return the collection ID
       
   187     */
       
   188     TInt FindCollectionIdL( const TDesC& aFile );
       
   189 
       
   190     /**
       
   191     * From MMPXHarvesterUtility
       
   192     * Export a Media property as a playlist
       
   193     * @param aProp CMPXMedia object to contain the "list" of items
       
   194     * @param aPath, path and filename
       
   195     * @param aPlaylistType, playlist type, default to M3U
       
   196     * @param aObs, observer for async callback
       
   197     */
       
   198     void ExportPlaylistL( const CMPXMedia& aProp,
       
   199                           const TDesC& aPath,
       
   200                           TInt aPlaylistType,
       
   201                           MMPXHarvesterUtilityObserver* aObs );
       
   202 
       
   203     /**
       
   204     * From MMPXHarvesterUtility
       
   205     * Import a playlist from a file
       
   206     * The user can ONLY execute 1 async op at a time!
       
   207     */
       
   208     void ImportPlaylistL( const TDesC& aFilename,
       
   209                           MMPXHarvesterUtilityObserver* aObs );
       
   210 
       
   211     /**
       
   212     * From MMPXHarvesterUtility
       
   213     * Imports a "file" in general
       
   214     * @param aFileName, file to import
       
   215     * @param aObs, observer for the import event
       
   216     */
       
   217     void ImportFileL( const TDesC& aFilename,
       
   218                       MMPXHarvesterUtilityObserver* aObs );
       
   219 
       
   220     /**
       
   221     * From MMPXHarvesterUtility
       
   222     * Query the required attributes for tracks for the specified playlist type
       
   223     * @param aPlaylistType playlist type for this query
       
   224     * @param aRequiredAttributes out parameter, an array of required attributes
       
   225     *        of the specified playlist type
       
   226     */
       
   227     void RequiredAttributesL( TInt aPlaylistType,
       
   228                               RArray<TMPXAttribute>& aRequiredAttributes );
       
   229 
       
   230     /**
       
   231     * From MMPXHarvesterUtility
       
   232     * Query the optional attributes for tracks for the specified playlist type
       
   233     * @param aPlaylistType playlist type for this query
       
   234     * @param aOptionalAttributes out parameter, an array of optional attributes
       
   235     *        of the specified playlist type
       
   236     */
       
   237     void OptionalAttributesL( TInt aPlaylistType,
       
   238                               RArray<TMPXAttribute>& aOptionalAttributes );
       
   239 
       
   240 
       
   241     /*
       
   242     * From MMPXHarvesterUtility
       
   243     * Query the file extension of the playlist of the specified type
       
   244     * @param aPlaylistType playlist type for this query
       
   245     * @return playlist file extension of the specified playlist type,
       
   246     *         this includes the period. Ownership transferred
       
   247     */
       
   248     HBufC* PlaylistFileExtensionLC( TInt aPlaylistType );
       
   249 
       
   250     /**
       
   251     * From MMPXHarvesterUtility
       
   252     * Determines whether the given file is a playlist.
       
   253     *
       
   254     * @param aUri URI of the media to be tested
       
   255     * @return ETrue if it's a playlist; otherwise EFalse.
       
   256     */
       
   257     TBool IsPlaylistL( const TDesC& aUri );
       
   258 
       
   259     /**
       
   260     * From MMPXHarvesterUtility
       
   261     * Sends a message to the harvester server to poll for any
       
   262     * system events. If there is a sytem event happening,
       
   263     * It will notify the rest of the MPX framework
       
   264     */
       
   265     void CheckForSystemEventsL();
       
   266 
       
   267     /**
       
   268     * From MMPXHarvesterUtility
       
   269     * Deletes the harvester utility and free the implementation
       
   270     */
       
   271     void Close();
       
   272 
       
   273     /**
       
   274     * Get a media object for the file
       
   275     * This method is asynchronous and will call back via the observer interface
       
   276     * @note S60 metadata utility is REALLY slow, so this has to be async
       
   277     * @param aFilePath, path to the song to be added
       
   278     * @param aObs observer to the add file event
       
   279     */
       
   280     void GetMediaForFileL( const TDesC& aFilePath, MMPXHarvesterUtilityObserver* aObs );
       
   281 
       
   282     /**
       
   283     * Get a collection ID for the file
       
   284     * @param aMedia media to add
       
   285     * @return collection ID for this media
       
   286     */
       
   287     TInt GetColUidForFileL( const TDesC& aFilePath );
       
   288 
       
   289 protected:
       
   290 
       
   291     /**
       
   292     * From CActive
       
   293     */
       
   294     void RunL();
       
   295 
       
   296     /**
       
   297     * From CActive
       
   298     */
       
   299     void DoCancel();
       
   300 
       
   301     /**
       
   302     *  From CActive
       
   303     *  Handles a leave occurring in the request completion event handler RunL()
       
   304     *
       
   305     *  @param aError error code
       
   306     *  @return system error code
       
   307     */
       
   308     TInt RunError(TInt aError);
       
   309 
       
   310 private:
       
   311 
       
   312     /**
       
   313     * Constructor
       
   314     */
       
   315     CMPXHarvesterUtilityImp();
       
   316 
       
   317     /**
       
   318     * 2nd phase constructor
       
   319     */
       
   320     void ConstructL();
       
   321 
       
   322     /**
       
   323     * Class to maintain the life time of async requests
       
   324     */
       
   325     NONSHARABLE_CLASS( CHvsUtilityTask ) : public CBase
       
   326         {
       
   327         public:
       
   328             CHvsUtilityTask( CBufBase* arg1=NULL, HBufC* arg2=NULL, HBufC* arg3=NULL,
       
   329                              TInt arg4=0, CMPXMedia* arg5=NULL );
       
   330             virtual ~CHvsUtilityTask();
       
   331             const TDesC8& Arg1();
       
   332             const TDesC&  Arg2();
       
   333             const TDesC&  Arg3();
       
   334             const TDesC8&  Arg4();
       
   335             const CMPXMedia& Arg5();
       
   336 
       
   337         private:
       
   338             CBufBase* iArg1;
       
   339             HBufC*    iArg2;
       
   340             HBufC*    iArg3;
       
   341             TPckgBuf<TInt> iArg4;
       
   342 
       
   343             TPtrC8    iPtr1;
       
   344             TPtrC     iPtr2;
       
   345             TPtrC     iPtr3;
       
   346             CMPXMedia* iArg5;
       
   347         };
       
   348 
       
   349 private: // data
       
   350     RMPXSession  iSession; // Session
       
   351     CBufBase*    iBuffer;
       
   352 
       
   353     // Callback observer for async ops.
       
   354     //
       
   355     MMPXHarvesterUtilityObserver*  iObserver;
       
   356     TMPXHarvesterServerOp          iCurAsyncOp;
       
   357     CHvsUtilityTask*               iCurTask;
       
   358     HBufC* iFile;
       
   359     };
       
   360 
       
   361 
       
   362 #endif // CMPXHarvesterUtilityImp_H