commonuis/CommonDialogs/src/CAknFileSelectionModel.h
changeset 0 2f259fa3e83a
child 29 a8834a2e9a96
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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:  Model class for file selection
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef C_AKNFILESELECTIONMODEL_H
       
    21 #define C_AKNFILESELECTIONMODEL_H
       
    22 
       
    23 #include <bamdesca.h>   // MDesCArray
       
    24 #include <f32file.h>    // File system
       
    25 #include <apgcli.h> // RApaLsSession
       
    26 
       
    27 #include "CAknFileSelectionDialog.h"
       
    28 
       
    29 class MAknFileFilter;
       
    30 class MAknFileSelectionObserver;
       
    31 class CDirectoryLocalizer;
       
    32 
       
    33 
       
    34 /**
       
    35  *  A model class for file selection dialog. It is derived from
       
    36  *  MDesCArray which provides an interface for listboxes to get items.
       
    37  *  Model maintains a list of directory entries.
       
    38  *
       
    39  *  @lib CommonDialogs.lib
       
    40  *  @since S60 1.2
       
    41  */
       
    42 NONSHARABLE_CLASS(CAknFileSelectionModel) : public CBase, public MDesCArray
       
    43     {
       
    44 
       
    45 public:
       
    46 
       
    47 // Enumerations
       
    48 
       
    49     /**
       
    50      * Enumerations for images.
       
    51      */
       
    52     enum TFileTypeIcon
       
    53         {
       
    54         EFolderIcon,
       
    55         EFileIcon,
       
    56         ESubFolderIcon,
       
    57         EThisFolderIcon,
       
    58         EImageFileIcon,
       
    59         EGmsFileIcon,
       
    60         ELinkFileIcon,
       
    61         EVoiceRecFileIcon,
       
    62         ESoundFileIcon,
       
    63         EPlaylistFileIcon,
       
    64         ECompoFileIcon,
       
    65         ENoteFileIcon,
       
    66         ESisFileIcon,
       
    67         EVideoFileIcon,
       
    68         EGameFileIcon,
       
    69         EJavaFileIcon,
       
    70         EUnknowTypeIcon,
       
    71         EFolderEmptyIcon,
       
    72         EFlashFileIcon
       
    73         };
       
    74 
       
    75 // Constructors and destructor
       
    76 
       
    77     /**
       
    78      * Static constructor.
       
    79      * @param aDialogType Dialog type.
       
    80      * @return Returns a pointer to an instance of itself.
       
    81      */
       
    82     static CAknFileSelectionModel* NewL(
       
    83         const TCommonDialogType& aDialogType, CCoeEnv& aCoeEnv );
       
    84 
       
    85     ~CAknFileSelectionModel();
       
    86 
       
    87 // New methods
       
    88 
       
    89     /**
       
    90      * Sets the current path, this is set as the root path.
       
    91      * @param aPath The absolute path. Browsing cannot go beyond this.
       
    92      *        This could be for example "E:\\" or "C:\\Nokia\\Images\\".
       
    93      * @return Number of items in the new folder or system wide error code if
       
    94      *         unsuccessful.
       
    95      */
       
    96     TInt SetPathL( const TDesC& aPath );
       
    97 
       
    98     /**
       
    99      * Adds a folder in the end of current path.
       
   100      * @param aFolder A folder is added in the end of current path.
       
   101      *        This folder is relative to current path. Trailing backslash is
       
   102      *        added if necessary. This could be for example "Images\\".
       
   103      * @return Number of items in the new folder or system wide error code if
       
   104      *         unsuccessful.
       
   105      */
       
   106     TInt AddFolderL( const TDesC& aFolder );
       
   107 
       
   108     /**
       
   109      * Adds a filter to filter list. Ownership is taken.
       
   110      * @param aFilter A Filter to be added.
       
   111      */
       
   112     void AddFilterL( MAknFileFilter* aFilter );
       
   113 
       
   114     /**
       
   115      * Changes directory into a subfolder. Updates entries.
       
   116      * @param aFolder The name of the subfolder, trailing backslash is added if
       
   117      *                necessary.
       
   118      * @return Number of items in the new folder or system wide error code if
       
   119      *         unsuccessful.
       
   120      */
       
   121     TInt GotoSubFolderL( const TDesC& aFolder );
       
   122 
       
   123     /**
       
   124      * Changes path to one folder up.
       
   125      * @return Number of items in the new folder or system wide error code if
       
   126      *         unsuccessful.
       
   127      */
       
   128     TInt GotoParentFolderL();
       
   129 
       
   130     /**
       
   131      * Updates the filtered entry array.
       
   132      * @return If no errors, the number of items in filtered entry array,
       
   133      *         otherwise system wide error code.
       
   134      */
       
   135     TInt UpdateItemListL();
       
   136 
       
   137     /**
       
   138      * Returns an entry from filtered entry array.
       
   139      * @param aIndex Array index.
       
   140      * @return Returns an entry from the current index.
       
   141      */
       
   142     const TEntry& Entry( const TInt& aIndex ) const;
       
   143 
       
   144     /**
       
   145      * Gets current path.
       
   146      * @param aPath A descriptor in which the current path is stored.
       
   147      */
       
   148     void GetCurrentPath( TDes& aPath ) const;
       
   149 
       
   150     /**
       
   151      * Returns directory level, 0 is root.
       
   152      * @return Returns directory level, 0 is root.
       
   153      */
       
   154     TInt DirectoryLevel() const;
       
   155 
       
   156     /**
       
   157      * Returns an index of a folder from list of filtered entries.
       
   158      * This can be used for listbox to focus wanted item.
       
   159      * @param aFolder A folder to search for.
       
   160      * @return The index of the folder in the filtered item list,
       
   161      *         KErrNotFound if not found.
       
   162      */
       
   163     TInt FolderIndex( const TDesC& aFolder ) const;
       
   164 
       
   165 // Functions from base classes
       
   166 
       
   167     /**
       
   168      * From MDesCArray
       
   169      */
       
   170     TInt MdcaCount() const;
       
   171 
       
   172     /**
       
   173      * From MDesCArray
       
   174      */
       
   175     TPtrC MdcaPoint( TInt aIndex ) const;
       
   176 
       
   177 private:    
       
   178     
       
   179 // New functions
       
   180 
       
   181     /**
       
   182      * Reads directory contents using RFs::GetDir.
       
   183      * @param aDirectory Directory.
       
   184      * @return Returns pointer to created CDir object.
       
   185      */
       
   186     CDir* ReadDirectory( const TDesC& aDirectory );
       
   187 
       
   188     /**
       
   189      * Returns ETrue if a folder contains subfolders.
       
   190      * @param aFolder Relative folder to current path.
       
   191      * @return Returns ETrue if a folder contains subfolders.
       
   192      */
       
   193     TBool ContainsSubfolders( const TDesC& aFolder );
       
   194 
       
   195     void AppendIconForFileL(const TDesC& aFileName);
       
   196 
       
   197     TPtrC GetLocalizedName(const TDesC& aFileName);
       
   198     
       
   199     /**
       
   200      * Returns ETrue if a folder contains files.
       
   201      * @param aFolder Relative folder to current path.
       
   202      * @return Returns ETrue if a folder contains files.
       
   203      */
       
   204     TBool ContainsFiles( const TDesC& aFolder );
       
   205 
       
   206 // Constructors and destructor
       
   207 
       
   208     void ConstructL();
       
   209 
       
   210     CAknFileSelectionModel(
       
   211         const TCommonDialogType& aDialogType, CCoeEnv& aCoeEnv );
       
   212 
       
   213 private:    // Data
       
   214 
       
   215     // Own: Current path being browsed.
       
   216     TParse iCurrentPath;
       
   217 
       
   218     // Own: An array of filtered directory entries.
       
   219     CArrayPakFlat<TEntry>* iEntryArray;
       
   220 
       
   221     // Own: An array for image indices
       
   222     RArray<TInt> iImageIndexArray;
       
   223 
       
   224     // Own: // An array of filters.
       
   225     CArrayPtrSeg<MAknFileFilter>* iFilterArray;
       
   226 
       
   227     // Own: File server session.
       
   228     RFs iFs;
       
   229 
       
   230     // Own: Directory level.
       
   231     TInt iDirectoryLevel;
       
   232 
       
   233     // Own: Directory localiser
       
   234     CDirectoryLocalizer* iLocalizer;
       
   235 
       
   236     // Ref: Dialog type
       
   237     const TCommonDialogType& iDialogType;
       
   238 
       
   239     // Ref: Control environment
       
   240     CCoeEnv& iCoeEnv;
       
   241 
       
   242     // Own: Root folder text
       
   243     HBufC* iRootFolderText;
       
   244 
       
   245     // Own: RApaLsSession for getting mime-types for files:
       
   246     RApaLsSession iApaSession;
       
   247 
       
   248     TEntry iFolderEntry;
       
   249 
       
   250     TParse iParse;
       
   251 
       
   252     HBufC * iItemWithImageIndex;
       
   253 
       
   254     };
       
   255 
       
   256 #endif // C_AKNFILESELECTIONMODEL_H