filemanager/GFLM/inc/CGflmFileListModel.h
branchRCL_3
changeset 20 491b3ed49290
parent 19 95243422089a
child 21 65326cf895ed
equal deleted inserted replaced
19:95243422089a 20:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2002-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:  File list model
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CGFLMFILELISTMODEL_H
       
    21 #define CGFLMFILELISTMODEL_H
       
    22 
       
    23 
       
    24 //  INCLUDES
       
    25 #include <e32base.h>
       
    26 #include <badesca.h>        // MDesCArray
       
    27 #include <f32file.h>        // RFs
       
    28 #include "GFLM.hrh"
       
    29 
       
    30 
       
    31 // FORWARD DECLARATIONS
       
    32 class MGflmItemGroup;
       
    33 class CGflmItemGroupImpl;
       
    34 class CGflmGroupItem;
       
    35 class MGflmItemFilter;
       
    36 class CGflmDirectoryListingCache;
       
    37 class CGflmFileRecognizer;
       
    38 class CGflmItemLocalizer;
       
    39 class CGflmDriveResolver;
       
    40 class CGflmDriveItem;
       
    41 class CGflmFileFinder;
       
    42 
       
    43 
       
    44 // CLASS DECLARATION
       
    45 /**
       
    46 *  A class that implements the basic file list functionality.
       
    47 *  @lib GFLM.lib
       
    48 *  @since 2.0
       
    49 */
       
    50 class CGflmFileListModel : public CActive, public MDesCArray
       
    51     {
       
    52     public:  // Constructors and destructor
       
    53 
       
    54         /**
       
    55         * Two-phased constructor.
       
    56         * @since 3.2
       
    57         * @param aFs Shareable file server session, see RFs::ShareProtected()
       
    58         * @return Pointer to a CGflmFileListModel instance
       
    59         */
       
    60         IMPORT_C static CGflmFileListModel* NewL( RFs& aFs );
       
    61 
       
    62         /**
       
    63         * Destructor.
       
    64         */
       
    65         virtual ~CGflmFileListModel();
       
    66 
       
    67     public: // New functions
       
    68 
       
    69         /**
       
    70         * Refreshes the model
       
    71         * @since 2.0
       
    72         * @param aStatus A reference to a TRequestStatus object that
       
    73         *        is used to notify the client thread about completion of
       
    74         *        the refresh
       
    75         * @param aRefreshMode Refresh mode
       
    76         */
       
    77         IMPORT_C void RefreshListL(
       
    78             TRequestStatus& aStatus,
       
    79             TGflmRefreshMode aRefreshMode = ERefreshItems );
       
    80 
       
    81         /**
       
    82         * Cancels the asynchronous refresh request
       
    83         * @since 2.0
       
    84         */
       
    85 		IMPORT_C void CancelRefresh();
       
    86 
       
    87         /**
       
    88         * Obtains a pointer to a CGflmGroupItem object.
       
    89         * The item is indexed by a global index.
       
    90         * Raises a panic (EGlobalIndexOutOfBounds) if the index refers to a
       
    91         * non-existent item.
       
    92         * @since 2.0
       
    93         * @param aIndex Global index of the item.
       
    94         * @return A pointer to a CGflmGroupItem object.
       
    95         */
       
    96         IMPORT_C CGflmGroupItem* Item( TInt aIndex ) const;
       
    97 
       
    98         /**
       
    99         * Resets the model. All item groups are destroyed.
       
   100         * @since 2.0
       
   101         */
       
   102         IMPORT_C void ResetModel();
       
   103 
       
   104         /**
       
   105         * Obtains a pointer to a MGflmItemGroup object.
       
   106         * Raises a panic (EInvalidGroupId) if a group is not found with given id.
       
   107         * @since 2.0
       
   108         * @param aId Id of the group
       
   109         * @return A pointer to a MGflmItemGroup object.
       
   110         */
       
   111         IMPORT_C MGflmItemGroup* FindGroupById( TInt aId );
       
   112 
       
   113         /**
       
   114         * Creates a new item group with a given id.
       
   115         * @since 2.0
       
   116         * @param aId The id given to the created group
       
   117         * @return A pointer to the created MGflmItemGroup object
       
   118         */
       
   119         IMPORT_C MGflmItemGroup* CreateGroupL( TInt aId );
       
   120 
       
   121         /**
       
   122         * Creates a new item group with a given id.
       
   123         * @since 3.1
       
   124         * @param aId The id given to the created group
       
   125         * @param aInclusion The group item inclusion
       
   126         * @return A pointer to the created MGflmItemGroup object
       
   127         */
       
   128         IMPORT_C MGflmItemGroup* CreateGroupL(
       
   129             TInt aId, TUint aInclusion );
       
   130 
       
   131         /**
       
   132         * Recognizes a file and resolves it's MIME-type.
       
   133         * This method accesses GFLM's internal recognizer cache
       
   134         * and is thus recomended for efficiency. NOTE: The file doesn't
       
   135         * have to belong to the current state of the model.
       
   136         * @since 2.0
       
   137         * @param aFilename Full path of the file to be recognized
       
   138         * @return A pointer descriptor containing the MIME-type of the item.
       
   139         *         If the MIME-type couldn't be recognized, returns KNullDesC
       
   140         */
       
   141         IMPORT_C TPtrC ResolveMimeTypeL( const TDesC& aFilename );
       
   142 
       
   143         /**
       
   144         * Sets the item filter object for the model to use.
       
   145         * If aOwned is ETrue the model gets the ownership of the object.
       
   146         * @since 2.0
       
   147         * @param aFilter A pointer to a MGflmItemFilter object to be used
       
   148         */
       
   149         IMPORT_C void SetCustomFilter( MGflmItemFilter* aFilter );
       
   150 
       
   151         /**
       
   152         * Returns the validity of the model. If the refresh operation failed
       
   153         * or was canceled the model is corrupt and it's items shouldn't be
       
   154         * accessed
       
   155         * @since 2.0
       
   156         * @return ETrue if the model is corrupt. EFalse if the model is in
       
   157         *         valid state.
       
   158         */
       
   159         IMPORT_C TBool IsCorrupt() const;
       
   160 
       
   161         /**
       
   162         * Returns the localized name of a file or a directory
       
   163         * @since 2.0
       
   164         * @param aPath Full path to the file or directory
       
   165         * @return A pointer descriptor containing the localized name
       
   166         *         without the full path
       
   167         */
       
   168         IMPORT_C TPtrC LocalizedName( const TDesC& aPath ) const;
       
   169 
       
   170         /**
       
   171         * Clears the contents of the file cache
       
   172         * @since 2.0
       
   173         */
       
   174         IMPORT_C void ClearCache();
       
   175 
       
   176         /**
       
   177         * Clears the contents of the drive info
       
   178         * @since 3.1
       
   179         */
       
   180         IMPORT_C void ClearDriveInfo();
       
   181 
       
   182         /**
       
   183         * Gets drive item from given path
       
   184         * @since 3.1
       
   185         * @param aPath Given path
       
   186         * @return A pointer to drive item (not owned)
       
   187         *         or NULL if drive not found.
       
   188         */
       
   189         IMPORT_C CGflmDriveItem* DriveFromPath( const TDesC& aPath ) const;
       
   190 
       
   191         /**
       
   192         * Gets drive item from given id
       
   193         * @since 3.2
       
   194         * @param aDrive Given drive id
       
   195         * @return A pointer to drive item (not owned)
       
   196         *         or NULL if drive not found.
       
   197         */
       
   198         IMPORT_C CGflmDriveItem* DriveFromId( const TInt aDrive ) const;
       
   199 
       
   200         /**
       
   201         * Enables and disables search mode
       
   202         * @since 3.2
       
   203         * @param aEnabled Enable or disable
       
   204         */
       
   205         IMPORT_C void EnableSearchMode( const TBool aEnabled );
       
   206 
       
   207         /**
       
   208         * Get search mode
       
   209         * @since 5.0
       
   210         * @return search mode
       
   211         */       
       
   212         IMPORT_C TBool SearchMode();
       
   213         /**
       
   214         * Sets search string. Wild cards are allowed.
       
   215         * @since 3.2
       
   216         * @param aSearchString Given search string
       
   217         */
       
   218         IMPORT_C void SetSearchStringL( const TDesC& aSearchString );
       
   219 
       
   220         /**
       
   221         * Sets search folder
       
   222         * @since 3.2
       
   223         * @param aSearchFolder Given search folder
       
   224         */
       
   225         IMPORT_C void SetSearchFolderL( const TDesC& aSearchFolder );
       
   226 
       
   227         /**
       
   228         * Sets sort method
       
   229         * @since 5.0
       
   230         * @param aSortMethod Given sort method
       
   231         */
       
   232         IMPORT_C void SetSortMethod( TGflmSortMethod aSortMethod );
       
   233 
       
   234         /**
       
   235         * Gets sort method
       
   236         * @since 5.0
       
   237         * @return Currently used sort method
       
   238         */
       
   239         IMPORT_C TGflmSortMethod SortMethod() const;
       
   240         
       
   241         /**
       
   242         * Flush cache in CGflmFileRecognizer
       
   243         */
       
   244         IMPORT_C void FlushCache();
       
   245         
       
   246     public: // MDesCArray
       
   247 
       
   248         TInt MdcaCount() const;
       
   249 
       
   250         TPtrC MdcaPoint( TInt aIndex ) const;
       
   251 
       
   252     private: // CActive
       
   253 
       
   254         void RunL();
       
   255 
       
   256         TInt RunError( TInt aError );
       
   257 
       
   258         void DoCancel();
       
   259 
       
   260     protected:  // New functions
       
   261 
       
   262         /**
       
   263         * C++ default constructor.
       
   264         */
       
   265         CGflmFileListModel( RFs& aFs );
       
   266 
       
   267         /**
       
   268         * 2nd phase constructor
       
   269         */
       
   270         void ConstructL();
       
   271 
       
   272     private:
       
   273 
       
   274         static TInt WorkThreadStart( TAny* aPtr );
       
   275 
       
   276         void WorkThread();
       
   277 
       
   278         void NotifyClient( TInt aErr );
       
   279 
       
   280         void GetGroupAndLocalIndex(
       
   281             const TInt aGlobalIndex,
       
   282             TInt& aLocalIndex,
       
   283             MGflmItemGroup*& aGroup ) const;
       
   284 
       
   285         void DoRefreshL();
       
   286 
       
   287     protected:  // Data
       
   288 
       
   289         // Ref: An open shareable file server session
       
   290         RFs& iFs;
       
   291 
       
   292         // Request status of the work thread client
       
   293         TRequestStatus* iClientStatus;
       
   294 
       
   295         // Dynamic array containing all the CGflmItemGroupImpl objects that
       
   296         // belong to the model. Owned.
       
   297         CArrayPtrSeg< CGflmItemGroupImpl >* iGroups;
       
   298 
       
   299         // Instance of CGflmDirectoryListingCache. Owned.
       
   300         CGflmDirectoryListingCache* iListingCache;
       
   301 
       
   302         // Instance of CGflmFileRecognizer. Owned.
       
   303         CGflmFileRecognizer* iFileRecognizer;
       
   304 
       
   305         // Instance of CGflmItemLocalizer. Owned.
       
   306         CGflmItemLocalizer* iItemLocalizer;
       
   307 
       
   308         // Instance of CGflmDriveResolver. Owned.
       
   309         CGflmDriveResolver* iDriveResolver;
       
   310 
       
   311         // A boolean indicating wether the model is corrupt and needs to be
       
   312         // refreshed
       
   313         TBool iCorrupt;
       
   314 
       
   315         // A pointer to a class implementing MGflmItemFilter interface
       
   316         MGflmItemFilter* iFilter;
       
   317 
       
   318         // Own: For synchronising client and work thread
       
   319         RSemaphore iSemaphore;
       
   320 
       
   321         // Own: Client thread id to be informed
       
   322         TThreadId iClientId;
       
   323 
       
   324         // A boolean indicating wether the model is shutting down
       
   325         // Main thread is allowed write and work thread is allowed to read only
       
   326         TBool iShutdown;
       
   327 
       
   328         // A boolean indicating wether the refresh is canceled
       
   329         // Main thread is allowed write and work thread is allowed to read only
       
   330         TBool iCanceled;
       
   331 
       
   332         // A boolean indicating if search mode enabled or disabled
       
   333         // Main thread is allowed write and work thread is allowed to read only
       
   334         TBool iSearchEnabled;
       
   335 
       
   336         // Own: For finding files and directories from file system
       
   337         CGflmFileFinder* iFileFinder;
       
   338 
       
   339         // Own: Stores currently used sort method
       
   340         // Main thread is allowed write and work thread is allowed to read only
       
   341         TGflmSortMethod iSortMethod;
       
   342 
       
   343         // Own: Stores currently used sort method in search mode
       
   344         // Main thread is allowed write and work thread is allowed to read only
       
   345         TGflmSortMethod iSearchSortMethod;
       
   346 
       
   347         // Own: Stores currently used refresh mode
       
   348         // Main thread is allowed write and work thread is allowed to read only
       
   349         TGflmRefreshMode iRefreshMode;
       
   350 
       
   351     };
       
   352 
       
   353 #endif      // CGFLMFILELISTMODEL_H
       
   354 
       
   355 // End of File