commonuis/CommonDialogs/src/AknCFDUtility.h
changeset 0 2f259fa3e83a
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:  Internal utility class for CFD. Do not export this header to
       
    15 *                keep minimal maintenance effort (no BC breaks).
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef AKNCFDUTILITY_H
       
    22 #define AKNCFDUTILITY_H
       
    23 
       
    24 #include <f32file.h> // TDriveNumber
       
    25 #include <CAknCommonDialogsBase.h> // TCommonDialogType
       
    26 #include <badesca.h> // CDesCArray
       
    27 #include <e32const.h> // KMaxFileName
       
    28 
       
    29 #include "AknCommonDialogsDynMem.h"
       
    30 
       
    31 class CEikonEnv;
       
    32 class CAknIconArray;
       
    33 class MAknsSkinInstance;
       
    34 class TAknsItemID;
       
    35 
       
    36 // Debug print convenience macros - no need to use ifdef in code.
       
    37 #ifndef _LOG
       
    38     #ifdef _DEBUG
       
    39         // Print in debug mode:
       
    40         #define _LOG( msg ) RDebug::Print( _L( msg ) );
       
    41         #define _LOG1( msg, val1 ) RDebug::Print( _L( msg ), val1 );
       
    42         #define _LOG2( msg, val1, val2 ) RDebug::Print( _L( msg ), val1, val2 );
       
    43         #define _LOG3( msg, val1, val2, val3 ) RDebug::Print( _L( msg ), val1, val2, val3 );
       
    44         #define _LOG4( msg, val1, val2, val3, val4 ) RDebug::Print( _L( msg ), val1, val2, val3, val4 );
       
    45         #define _LOG5( msg, val1, val2, val3, val4, val5 ) RDebug::Print( _L( msg ), val1, val2, val3, val4, val5 );
       
    46         #define _LOG6( msg, val1, val2, val3, val4, val5, val6 ) RDebug::Print( _L( msg ), val1, val2, val3, val4, val5, val6 );
       
    47         #define _LOG7( msg, val1, val2, val3, val4, val5, val6, val7 ) RDebug::Print( _L( msg ), val1, val2, val3, val4, val5, val6, val7 );
       
    48     #else
       
    49         // No print in release mode:
       
    50         #define _LOG( msg ) ;
       
    51         #define _LOG1( msg, val1 ) ;
       
    52         #define _LOG2( msg, val1, val2 ) ;
       
    53         #define _LOG3( msg, val1, val2, val3 ) ;
       
    54         #define _LOG4( msg, val1, val2, val3, val4 ) ;
       
    55         #define _LOG5( msg, val1, val2, val3, val4, val5 ) ;
       
    56         #define _LOG6( msg, val1, val2, val3, val4, val5, val6 ) ;
       
    57         #define _LOG7( msg, val1, val2, val3, val4, val5, val6, val7 ) ;
       
    58     #endif // _DEBUG
       
    59 #endif // _LOG
       
    60 
       
    61 /**
       
    62 * Drive status. This affects functionality and appearance of lbx drive item.
       
    63 * Instead of numerous 'system wide error codes' CFD is interested only in these
       
    64 * states of a drive. If adding more states, add to the end of this enum - do
       
    65 * not alter the order.
       
    66 */
       
    67 enum TCFDDriveStatus
       
    68     {
       
    69     EDriveOK = 0,   // drive is available, unlocked and formatted
       
    70     EDriveLocked,   // drive is locked
       
    71     EDriveNotReady  // drive is not inserted or the drive is corrupted or unformatted
       
    72     };
       
    73 
       
    74 /**
       
    75  *  Data encapsulation class for CFD drive information. Used to draw list items
       
    76  *  and handle drive status logic inside CFD classes.
       
    77  */
       
    78 class TCFDDriveInfo
       
    79     {
       
    80     public:
       
    81         TDriveNumber iDriveNumber;
       
    82         TBufC<KMaxFileName> iVolumeLabel; // User defined name for drive if given.
       
    83         TInt64 iDiskSpace; // Free space in drive (Byte), negative value indicates not available.
       
    84         TMediaType iMediaType;
       
    85         TCFDDriveStatus iDriveStatus;
       
    86         /**
       
    87          * Used for remote drives only:
       
    88          * KMountStronglyConnected or KMountNotConnected.
       
    89          */
       
    90         TInt iConnectionState;
       
    91 
       
    92         /**
       
    93          * Type: DriveInfo::TStatus
       
    94          * To be used to support multiple drives.
       
    95          */
       
    96         TUint iStatus;
       
    97     };
       
    98 
       
    99 const TInt KDiskSpaceNotAvailable = -1; // Actually any negative value should do so checking should be done using 'i<0' operator.
       
   100 
       
   101 /**
       
   102 *  Static utility class for CFD
       
   103 *
       
   104 *  @lib CommonDialogs.lib
       
   105 *  @since 1.2
       
   106 */
       
   107 class AknCFDUtility
       
   108     {
       
   109     public:     // static methods
       
   110 
       
   111         /**
       
   112         * Reads information of a drive. This is the more convenient function to
       
   113         * get all necessary single drive information.
       
   114         *
       
   115         * NOTE: if reading drive info fails in some stage inside this function,
       
   116         * aDriveInfo.iDriveStatus will have a value different than EDriveOK -
       
   117         * in this case some data inside aDriveInfo wll not be updated. Check
       
   118         * implementation to see which data is updated correctly and can be used.
       
   119         *
       
   120         * @param aDriveNumber The drive to read information from.
       
   121         * @param aDriveInfo Will contain information of the drive.
       
   122         * @return KErrNone or system wide error codes...
       
   123         */
       
   124         static TInt DriveInfoL( const TDriveNumber aDriveNumber, TCFDDriveInfo& aDriveInfo );
       
   125 
       
   126         /**
       
   127         * Method for checking drive status. This is more efficient and simple
       
   128         * method to get drive status than DriveInfo() and should be used for
       
   129         * performance reasons and to maintain code simplicity. Only drive
       
   130         * status is checked in many places where any other drive information
       
   131         * is not needed and would be overkill.
       
   132         *
       
   133         * @param aDriveNumber Drive number of the drive, status is checked.
       
   134         * @return Status of the drive.
       
   135         */
       
   136         static TCFDDriveStatus DriveStatusL( const TDriveNumber aDriveNumber );
       
   137 
       
   138         /**
       
   139         * Returns drive number of a path.
       
   140         * @param aPath A path which must contain a drive, e.g: "C:\Nokia\"
       
   141         * @return Returns the number of the drive (enumeration TDriveNumber).
       
   142         *         If path contains no drive, returns KErrNotFound.
       
   143         */
       
   144         static TInt DriveNumber( const TDesC& aPath );
       
   145 
       
   146         /**
       
   147         * Returns the number of directories in a path.
       
   148         * Path must be format "Directory\Another\" in other words, w/o drive letter!
       
   149         * @param aPath A path from which directory count is calculated.
       
   150         * @return Returns the number of directories in a path.
       
   151         */
       
   152         static TInt DirectoryCount( const TDesC& aPath );
       
   153 
       
   154         /**
       
   155         * Adds trailing backslash to a path if it is missing.
       
   156         * Does nothing if already there.
       
   157         * @param aFolder A reference to a descriptor which is edited.
       
   158         * @return Returns system wide error code.
       
   159         */
       
   160         static TInt AddTrailingBackslash( TDes& aPath );
       
   161 
       
   162         /**
       
   163         * Removes trailing backslash from a path.
       
   164         * Does nothing if last character is something else than backslash
       
   165         * @param aFolder A reference to a descriptor which is edited.
       
   166         * @return Returns system wide error code.
       
   167         */
       
   168         static TInt RemoveTrailingBackslash( TDes& aPath );
       
   169 
       
   170         /**
       
   171         * Method for internal use only. See source.
       
   172         */
       
   173         static void AllocateIfValidL(
       
   174             HBufC*& aDestination, const TDesC& aSource );
       
   175 
       
   176         /**
       
   177         * Method for internal use only. See source.
       
   178         */
       
   179         static void AllocateOrNullL(
       
   180             HBufC*& aDestination, const TDesC& aSource );
       
   181 
       
   182         /**
       
   183         * Method for internal use only. See source.
       
   184         */
       
   185         static void AllocateIfNullL(
       
   186             HBufC*& aDestination, const TDesC& aSource );
       
   187 
       
   188         /**
       
   189         * DEPRECATED: Use AppendSkinnedImageToArrayL instead.
       
   190         *
       
   191         * Creates an icon and appends it to icon array using
       
   192         * CEikonEnv::CreateIconL.
       
   193         */
       
   194         static void AppendImageToArrayL( CEikonEnv& aEnv, CAknIconArray& aArray,
       
   195             const TDesC& aBitmapFile, TInt aBitmapId, TInt aMaskId );
       
   196            
       
   197         /**
       
   198         * Creates skinned icon and appends it to icon array.
       
   199         * If skinned icon is not found, Avkon bitmap is used.
       
   200         */
       
   201         static void AppendSkinnedImageToArrayL(
       
   202             CEikonEnv& aEnv, CAknIconArray& aArray,
       
   203             MAknsSkinInstance* aSkin, const TAknsItemID& aItemID,
       
   204             const TDesC& aBitmapFile, TInt aBitmapId, TInt aMaskId, TBool aColorIcon = EFalse );
       
   205 
       
   206         /**
       
   207         * Returns whether dialog type is a folder select dialog or not.
       
   208         */
       
   209         static TBool DirectoriesOnly( TCommonDialogType aType );
       
   210 
       
   211         /**
       
   212         * Reads dynamic drives and adds these to the rootpath array. Does not
       
   213         * add new drives in case they already exist in the array.
       
   214         * @param aRootPathArray Array of the already existing root paths which
       
   215         *        will be updated in case more drives exist.
       
   216         * @param aIncludedMedias bitflag list of desired media types.
       
   217         */
       
   218         static void ReadDynamicDrivesL( CDesCArrayFlat& aRootPathArray,
       
   219                                         TInt aIncludedMedias );
       
   220 
       
   221         /**
       
   222         * Checks if the drive already exists.
       
   223         * @param aRootPathArray An array of drives from which to check.
       
   224         * @param aDriveLetter Letter of the drive upon which is checked, if it
       
   225         *        already exists.
       
   226         * @return ETrue if drive already exists. Otherwise EFalse.
       
   227         */
       
   228         static TBool DriveAlreadyExists( CDesCArrayFlat& aRootPathArray,
       
   229                                          TChar aDriveLetter );
       
   230 
       
   231         /**
       
   232         * Checks if drive's type is in included medias list.
       
   233         * @param aDriveInfo info of the drive to be tested.
       
   234         * @param aIncludedMedias bitflag list of desired media types.
       
   235         * @return ETrue if drive's type is in included medias.
       
   236         */
       
   237         static TBool IsIncludedMedia( TDriveInfo aDriveInfo,
       
   238                                       TInt aIncludedMedias );
       
   239 
       
   240         /**
       
   241         * Counts effective drives: Drives which contain recognised media and
       
   242         * are not ROM or RAM. This function can be used to check if there are
       
   243         * more than one effective drives.
       
   244         *
       
   245         * This also handles default cases such as omitting EDriveD and EDriveZ
       
   246         * (ROM and RAM) because these drives should not be visible to the
       
   247         * user anyway.
       
   248         *
       
   249         * @return Number of effective drives.
       
   250         */
       
   251         static TInt EffectiveDriveCountL();
       
   252         
       
   253         /**
       
   254         * Check if one drive is a remote drive
       
   255         *
       
   256         * @since 3.2
       
   257         * @return If is a remote drive.
       
   258         */
       
   259         static TBool IsRemoteDrive( const TDesC& aDrive );
       
   260         
       
   261         /**
       
   262         * Get drive's memory type
       
   263         *
       
   264         * @since 5.0
       
   265         * @return The memory type of given drive. See TMemoryTypes.
       
   266         */
       
   267         static AknCommonDialogsDynMem::TMemoryTypes
       
   268             DriveMemoryTypeL( const TDriveNumber& aDrive );
       
   269     
       
   270         /**
       
   271          * Set free space count and unit indicating.
       
   272          * @param aFreeSpace free space with unit "Byte".
       
   273          * @param aUnitBuf return text.
       
   274          */
       
   275         static void SetSecondRowTextL( TInt64 aFreeSpace, TDes& aUnitBuf );
       
   276         
       
   277         /**
       
   278          * Get the count of user visible drives. This function can be used to
       
   279          * define if memory selection dialog should be used instead of file
       
   280          * selection dialog.
       
   281          * 
       
   282          * @param aIncludedMedias defines which medias are included in the
       
   283          *        dialog. See TMemoryTypes
       
   284          * @return Number of user visible drives.
       
   285          */
       
   286         static TInt UserVisibleDriveCountL( TInt aIncludedMedias );
       
   287     };
       
   288 
       
   289 #endif // AKNCFDUTILITY_H