mmappcomponents/harvester/filehandler/inc/mpxharvesterfilehandlerimp.h
changeset 0 a2952bb97e68
child 9 bee149131e4b
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 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 handler class to handle all file related requests
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CMPXHARVESTERFILEHANDLERIMP_H
       
    20 #define CMPXHARVESTERFILEHANDLERIMP_H
       
    21 
       
    22 #include <f32file.h>
       
    23 #include <badesca.h>
       
    24 #include <apgcli.h>
       
    25 #include <mpxattribute.h>
       
    26 #include <DRMEventObserver.h>
       
    27 
       
    28 #include "mpxfilescanstateobserver.h"
       
    29 #include "mpxdbsyncobserver.h"
       
    30 #include "mpxfileadditionobserver.h"
       
    31 #include "mpxharvesterfilehandler.h"
       
    32 #include "mpxmetadatascanobserver.h"
       
    33 #include "mpxplaylistscanobserver.h"
       
    34 #include "mpxmediatorobserver.h"
       
    35 #include "mpxdiskspacewatcher.h"
       
    36 #include "mpxdiskspacewatcherobserver.h"
       
    37 #include "mpxfoldermonitor.h"
       
    38 #include "mpxfoldermonitorobserver.h"
       
    39 #include "mpxbrokenlinkcleanupobserver.h"
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 class CMPXFolderScanner;
       
    43 class CMPXDbSynchronizer;
       
    44 class CMPXMetadataScanner;
       
    45 class CMPXPlaylistScanner;
       
    46 class CMPXBrokenLinkCleanup;
       
    47 class CMPXDiskSpaceWatcher;
       
    48 class CMPXFolderMonitor;
       
    49 class CMPXHarvesterDatabaseManager;
       
    50 class CMPXHarvesterDB;
       
    51 class CMPXHarvesterDatabaseTable;
       
    52 class CMPXHarvesterDbItem;
       
    53 class CMPXCollectionType;
       
    54 class MMPXCollectionUtility;
       
    55 class MMPXCollection;
       
    56 class CDRMNotifier;
       
    57 
       
    58 /**
       
    59  *  File handler class to take care of all file related operations
       
    60  *
       
    61  *  @lib mpxfilehandler
       
    62  *  @since S60 3.0
       
    63  */
       
    64 NONSHARABLE_CLASS( CMPXHarvesterFileHandlerImp ) : public CMPXHarvesterFileHandler,
       
    65                                                    public MMPXFileScanStateObserver,
       
    66                                                    public MMPXDbSyncObserver,
       
    67                                                    public MMPXFileAdditionObserver,
       
    68                                                    public MMPXPlaylistScanObserver,
       
    69                                                    public MMPXMetadataScanObserver,
       
    70                                                    public MMPXMediatorObserver,
       
    71                                                    public MMPXDiskSpaceObserver,
       
    72                                                    public MMPXFolderMonitorObserver,
       
    73                                                    public MMPXBrokenLinkObserver,
       
    74                                                    public MDRMEventObserver
       
    75     {
       
    76 public:
       
    77 
       
    78     /**
       
    79     * Two-Phased Constructor
       
    80     * @param aFs file server session
       
    81     */
       
    82     static CMPXHarvesterFileHandlerImp* NewL( RFs& aFs );
       
    83 
       
    84     /**
       
    85     * Virtual destructor
       
    86     */
       
    87     virtual ~CMPXHarvesterFileHandlerImp();
       
    88 
       
    89 protected: // From Base Class
       
    90 
       
    91     /**
       
    92     * From CMPXHarvesterFileHandler
       
    93     */
       
    94     void ScanL();
       
    95 
       
    96     /**
       
    97     * From CMPXHarvesterFileHandler
       
    98     */
       
    99     void CancelScan();
       
   100 
       
   101     /**
       
   102     * From CMPXHarvesterFileHandler
       
   103     */
       
   104     void HandleSystemEventL( TSystemEvent aEvent,
       
   105                              TInt aData );
       
   106 
       
   107     /**
       
   108     * From CMPXHarvesterFileHandler
       
   109     */
       
   110     CMPXMedia* AddFileL( const TDesC& aPath );
       
   111 
       
   112     /**
       
   113     * From CMPXHarvesterFileHandler
       
   114     */
       
   115     TInt AddFileL( CMPXMedia& aMediaProp );
       
   116 
       
   117     /**
       
   118     * From CMPXHarvesterFileHandler
       
   119     */
       
   120     TInt RemoveFileL( const TDesC& aPath, TBool aEndTransaction );
       
   121 
       
   122     /**
       
   123     * From CMPXHarvesterFileHandler
       
   124     */
       
   125     void RemoveFilesL( const MDesCArray& aFilePaths );
       
   126 
       
   127     /**
       
   128     * From CMPXHarvesterFileHandler
       
   129     */
       
   130     void RemoveAllFilesL();
       
   131 
       
   132     /**
       
   133     * From CMPXHarvesterFileHandler
       
   134     */
       
   135     void UpdateFileL( const TDesC& aFile, TInt aCollection );
       
   136 
       
   137     /**
       
   138     * From CMPXHarvesterFileHandler
       
   139     */
       
   140     void RenameFileL( const TDesC& aOldPath, const TDesC& aNewPath, TInt aCollection );
       
   141 
       
   142     /**
       
   143     * From CMPXHarvesterFileHandler
       
   144     */
       
   145     TInt FindCollectionIdL( const TDesC& aFile );
       
   146 
       
   147     /**
       
   148     * From CMPXHarvesterFileHandler
       
   149     */
       
   150     void RecreateDatabases();
       
   151 
       
   152     /**
       
   153     * From CMPXHarvesterFileHandler
       
   154     */
       
   155     void CloseTransactionL();
       
   156 
       
   157     /**
       
   158     * Get a media object for the file
       
   159     * @param aPath File to add
       
   160     * @return CMPXMedia object for the item pointed to by aPath
       
   161     *         ownership transferred
       
   162     */
       
   163     virtual CMPXMedia* GetMediaForFileL( const TDesC& aPath );
       
   164 
       
   165     /**
       
   166     * Get Collection Uid for the file
       
   167     * @param aMediaProp Media Property to add
       
   168     * @return TInt collection ID for the item added
       
   169     */
       
   170     virtual TInt GetColUidForFileL( const TDesC& aPath );
       
   171 
       
   172     /**
       
   173     * From MMPXFileScanStateObserver
       
   174     */
       
   175     void HandleScanStateCompleteL( TScanState aState, TInt aErr );
       
   176 
       
   177     /**
       
   178     * From MMPXDbSyncObserver
       
   179     */
       
   180     void HandleSynchronizationComplete( TInt aErr );
       
   181 
       
   182     /**
       
   183     * From MMPXFileAdditionObserver
       
   184     */
       
   185     void HandleFileAdditionL( const TDesC& aFileName,
       
   186                               TInt aColIndex,
       
   187                               TBool aPlaylist = EFalse  );   //lint !e1735
       
   188 
       
   189     /**
       
   190     * From MMPXFileAdditionObserver
       
   191     */
       
   192     void HandleOpenDriveL( TDriveNumber aDrive, const TDesC& aFolder );
       
   193 
       
   194     /**
       
   195     * From MMPXFIleAdditionObserver
       
   196     */
       
   197     void HandleDirectoryChangedL( const TDesC& aPath );
       
   198 
       
   199     /**
       
   200     * From MMPXFileAdditionObserver
       
   201     */
       
   202     TInt IsMediaFileL( const TDesC& aFile );
       
   203 
       
   204     /**
       
   205     * From MMPXFileAdditionObserver
       
   206     */
       
   207     TInt IsPlaylistFileL( const TDesC& aFile );
       
   208 
       
   209     /**
       
   210     * From MMPXFileAdditionObserver
       
   211     */
       
   212     TBool IsPathBlockedL( const TDesC& aPath );
       
   213 
       
   214     /**
       
   215     * From MMPXMetadataScanObserver
       
   216     */
       
   217     void AddFilesToCollectionL( CMPXMediaArray& aMediaArray );
       
   218 
       
   219     /**
       
   220     * From MMPXMetadataScanObserver
       
   221     */
       
   222     void UpdatesFilesInCollectionL( CMPXMediaArray& aMediaArray );
       
   223 
       
   224     /**
       
   225     * From MMPXMediatorObserver
       
   226     */
       
   227     void HandleMediatorPathUpdatedL( CMPXMedia*& aProperty,
       
   228                                      TUid  aOldPath );
       
   229 
       
   230     /**
       
   231     * From MMPXPlaylistScanObserver
       
   232     */
       
   233     void AddPlaylistToCollectionL( CMPXMediaArray& aMediaArray );
       
   234 
       
   235     /**
       
   236     * From MMPXPlaylistScanObserver
       
   237     */
       
   238     void UpdatePlaylistToCollectionL( CMPXMediaArray& aMediaArray );
       
   239 
       
   240     /**
       
   241     * From MMPXDiskSpaceObserver
       
   242     */
       
   243     void HandleLowDiskEvent( TInt aDrive );
       
   244 
       
   245     /**
       
   246     * From MMPXBrokenLinkObserver
       
   247     */
       
   248     void HandleBrokenLinkL( MDesCArray& aFileArray,
       
   249                             RArray<TInt>& aColId ,
       
   250                             RPointerArray<CMPXHarvesterDB>& aDb,
       
   251                             TInt aCount );
       
   252                                      
       
   253     /**
       
   254     * From MDRMEventObserver
       
   255     */
       
   256     void HandleEventL( MDRMEvent* aEvent );
       
   257     
       
   258 private: // New Functions
       
   259 
       
   260     /**
       
   261     * Parses cenrep string (KHarvesterScanPathKey)
       
   262     * to get a list of scan paths
       
   263     */
       
   264     void ParseScanPathL();
       
   265 
       
   266     /**
       
   267     * Parse cenrep string (KHarvesterContainerKey)
       
   268     * for a list of containers
       
   269     */
       
   270     void ParseContainersL();
       
   271 
       
   272     /**
       
   273     * Parses the auto scan cenrep key
       
   274     * for a list of folders to automatically scan
       
   275     */
       
   276     void ParseAutoScanL();
       
   277 
       
   278     /***
       
   279     * Resets the current scan directory and frees memory
       
   280     */
       
   281     void Reset();
       
   282 
       
   283     /**
       
   284     * Handles a new item
       
   285     * @param aFileName new file to add
       
   286     */
       
   287     void HandleNewItemL( const TDesC& aFileName );
       
   288 
       
   289     /**
       
   290     * Handles broken items
       
   291     */
       
   292     void HandleBrokenItemsL();
       
   293 
       
   294     /**
       
   295     * Handles updated items
       
   296     * @param aFile file to update
       
   297     */
       
   298     void HandleUpdatedItemL( const TDesC& aFile );
       
   299 
       
   300     /**
       
   301     * Resolves the collection UID for a file
       
   302     * @param aFile file and path to a file for resolution
       
   303     * @return TInt collection ID on return
       
   304     */
       
   305     TInt CollectionForExtensionL( const TDesC& aFile );
       
   306 
       
   307     /**
       
   308     * Sets up the internal DB variables for a path
       
   309     * @param aPath path to open a view to the database
       
   310     */
       
   311     void OpenDBForPathL( const TDesC& aPath );
       
   312 
       
   313     /**
       
   314     * Final step for the refresh operation
       
   315     * @param aErr error code to complete with
       
   316     */
       
   317     void DoCompleteRefreshL( TInt aErr );
       
   318 
       
   319     /**
       
   320     * Perform a command on the collection
       
   321     * @param aCommandId Id of the command
       
   322     * @param aMediaAttribute TMPXAttriubte for the media payload
       
   323     * @param aCollectionId collection to perform the command on
       
   324     * @param aMedia the Media for the command
       
   325     * @param aSync Sync operation or not. (Default ETrue)
       
   326     */
       
   327     void DoCommandL( TInt aCommandId,
       
   328                      TUid aCollectionId,
       
   329                      const TMPXAttribute& aMediaAttribute,
       
   330                      CMPXMedia* aMedia = NULL,
       
   331                      TBool aSync = ETrue );
       
   332 
       
   333     /**
       
   334     * Remove an item to a collection
       
   335     * @param aMedia, media to add
       
   336     * @param aCollectionId, collection UID
       
   337     */
       
   338     void DoRemoveL( CMPXMedia* aMedia, TUid aCollectionId );
       
   339 
       
   340     /**
       
   341     * Verifies if harvester and collection databases are in sync by comparing the number of records
       
   342     * if records counts are different delete harvester db and repopulate it from collection
       
   343     * @return TBool ETrue if synchronization is started, EFalse otherwise
       
   344     */
       
   345     TBool CheckDbInSyncL();
       
   346 
       
   347     /**
       
   348      * Get a list of files with DRM flag set from the Harvester DB.
       
   349      * @return list of files
       
   350      */
       
   351     RPointerArray<CMPXHarvesterDbItem>* GetDrmFilesL();
       
   352 
       
   353     /**
       
   354      * Verifies if aDrive is ready.
       
   355      * @param aDrive, certain drive name, such as EDRIVEE
       
   356      * @return TBool ETrue if aDrive is ready,otherwise EFalse
       
   357      */
       
   358     TBool IsDriveReady( TDriveNumber aDrive );
       
   359 
       
   360 public:
       
   361 
       
   362     /**
       
   363     * Delayed callback function
       
   364     */
       
   365     static TInt Callback( TAny* aPtr );
       
   366 
       
   367     /**
       
   368     * Perform the auto scan
       
   369     */
       
   370     TBool DoAutoScanL();
       
   371 
       
   372 private:
       
   373 
       
   374     /**
       
   375     * Private Constructor
       
   376     */
       
   377     CMPXHarvesterFileHandlerImp( RFs& aFs );
       
   378 
       
   379     /**
       
   380     * 2nd Phased Constructor
       
   381     */
       
   382     void ConstructL();
       
   383 
       
   384     //helper function used inside CheckDbInSyncL
       
   385     inline TInt GetTrackCountL(TDriveNumber aDrive,TInt aColDbId, TInt aColTable);
       
   386 
       
   387 private: // data
       
   388     // File scanning related
       
   389     CMPXFolderScanner*                iFolderScanner;
       
   390     CMPXDbSynchronizer*               iDbSynchronizer;
       
   391     RPointerArray<CMPXDiskSpaceWatcher> iDiskMonitors;
       
   392     RPointerArray<CMPXFolderMonitor>  iFolderMonitors;  // Multiple drives
       
   393     RPointerArray<CMPXCollectionType> iSupportedTypes;
       
   394     CDesCArray*                       iContainerTypes;
       
   395     RArray<TPath>                     iDrivesToScan;
       
   396     RArray<TPath>                     iFilteredDrivesToScan;
       
   397     RArray<TPath>                     iPathsToBlock;
       
   398     TBool                             iOutOfDisk;
       
   399 #ifdef RD_MULTIPLE_DRIVE
       
   400     TInt                              iRemovedDrive;
       
   401 #endif // RD_MULTIPLE_DRIVE
       
   402 
       
   403     // Metadata related
       
   404     CMPXMetadataScanner*              iMetadataScanner;
       
   405     CMPXPlaylistScanner*              iPlaylistScanner;
       
   406     CMPXBrokenLinkCleanup*            iBrokenLink;
       
   407 
       
   408     // Session to the collection
       
   409     // Only valid during a scan
       
   410     //
       
   411     MMPXCollectionUtility*            iCollectionUtil;
       
   412 
       
   413     // Database related
       
   414     CMPXHarvesterDatabaseManager*    iDBManager; // DB manager
       
   415 
       
   416     CMPXHarvesterDB*                 iCurDB;     // Current db reference
       
   417     CMPXHarvesterDatabaseTable*      iCurTable;  // owned, must delete
       
   418     RPointerArray<CMPXHarvesterDbItem>*    iCurList; // owned, must delete
       
   419 
       
   420     // Misc
       
   421     RFs& iFs;
       
   422     RApaLsSession iAppArc;
       
   423     TInt iAddedCount;
       
   424 
       
   425     TBool                            iRefreshing; // Are we currently refreshing
       
   426     TBool                            iSynchronizing; // Are we currently synchronizing
       
   427     TInt                             iRefreshCount; // refresh reference count
       
   428     CPeriodic*                       iIdle;       // Delayed callback
       
   429     RArray<TPath>                    iAutoScanPaths; // list of auto scanning paths
       
   430 
       
   431     TUid                             iMusicCollectionId;
       
   432     TUid                             iPodcastCollectionId;
       
   433 
       
   434     TBool                            iDisablePodcasting;
       
   435     
       
   436     // DRM
       
   437     CDRMNotifier*                    iDrmNotifier;
       
   438     };
       
   439 
       
   440 #endif // CMPXHARVESTERFILEHANDLERIMP_H