filemanager/src/inc/fmutils.h
branchRCL_3
changeset 39 65326cf895ed
parent 38 491b3ed49290
child 42 f5c50b8af68c
equal deleted inserted replaced
38:491b3ed49290 39:65326cf895ed
     1 /*
       
     2 * Copyright (c) 2009 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 *     Zhiqiang Yang <zhiqiang.yang@nokia.com>
       
    14 * 
       
    15 * Description:
       
    16 *     The header file of the file manager utilities
       
    17 */
       
    18 
       
    19 #ifndef FMUTILS_H
       
    20 #define FMUTILS_H
       
    21 
       
    22 #include "fmcommon.h"
       
    23 
       
    24 #include <QString>
       
    25 
       
    26 /*!
       
    27     \class FmDriverInfo
       
    28     \brief The class FmDriverInfo provide drive info data
       
    29  */
       
    30 class FmDriverInfo
       
    31 {
       
    32 public:
       
    33     /*!
       
    34         Used to get drive status for convenience.
       
    35         /sa DriveType is used to get drive type.
       
    36     */
       
    37     enum driveState
       
    38     {
       
    39         EDriveNotPresent = 0x1, // true when Drive have not inserted, for example, MMC Card
       
    40         EDriveAvailable = 0x2,  // false when drive is locked or corrupted, for example MMC Card
       
    41         EDriveLocked = 0x4,
       
    42         EDriveCorrupted = 0x8,
       
    43         EDriveWriteProtected = 0x10,
       
    44         EDriveRemovable = 0x20,
       
    45         EDriveRom = 0x40,
       
    46         EDriveFormattable = 0x80,
       
    47         EDriveFormatted = 0x100,
       
    48         EDriveLockable = 0x200,
       
    49         EDrivePasswordProtected = 0x400,
       
    50         EDriveBackupped = 0x800,
       
    51         EDriveConnected = 0x1000,
       
    52         EDriveEjectable = 0x2000,
       
    53         EDriveInUse = 0x4000,
       
    54         EDriveMassStorage = 0x8000,
       
    55         EDriveRam = 0x10000,
       
    56         EDriveUsbMemory = 0x20000,
       
    57         EDriveRemote = 0x40000,
       
    58      };
       
    59     
       
    60     /*!
       
    61         Used to get drive type for convenience.
       
    62     */
       
    63     enum DriveType
       
    64     {
       
    65         EDriveTypeNotExist = -1, // specified drive is not existed in device
       
    66         EDriveTypeRom,
       
    67         EDriveTypeRam,
       
    68         EDriveTypePhoneMemory,
       
    69         EDriveTypeMassStorage,
       
    70         EDriveTypeMemoryCard,
       
    71         EDriveTypeUsbMemory,
       
    72         EDriveTypeRemote,
       
    73     };
       
    74     
       
    75     Q_DECLARE_FLAGS( DriveState, driveState )
       
    76     
       
    77     FmDriverInfo( quint64 s, quint64 f, const QString &n, const QString &vN, const quint32 driveState ) :
       
    78         mSize( s ), mFreeSize( f ), mName( n ), mVolumeName( vN ), mDriveState( driveState ) {}
       
    79     FmDriverInfo( const FmDriverInfo &other )
       
    80     {
       
    81         *this = other;
       
    82     }
       
    83 
       
    84     FmDriverInfo &operator= ( const FmDriverInfo &rhs )
       
    85     {
       
    86         this->mSize = rhs.mSize;
       
    87         this->mFreeSize = rhs.mFreeSize;
       
    88         this->mName = rhs.mName;
       
    89         this->mVolumeName = rhs.mVolumeName;
       
    90         this->mDriveState = rhs.mDriveState;
       
    91         return *this;
       
    92     }
       
    93     
       
    94     /*!
       
    95         Total size for drive
       
    96     */
       
    97     quint64 size() const { return mSize; }
       
    98     
       
    99     /*!
       
   100         Free size for drive
       
   101     */
       
   102     quint64 freeSize() const { return mFreeSize; }
       
   103     
       
   104     /*!
       
   105         path for drive
       
   106     */
       
   107     QString name() const { return mName; }
       
   108     
       
   109     /*!
       
   110         volume for drive
       
   111     */
       
   112     QString volumeName() const { return mVolumeName; }
       
   113     
       
   114     /*!
       
   115         status for drive
       
   116     */
       
   117     DriveState driveState() const { return mDriveState; }
       
   118     
       
   119     /*!
       
   120         drive type
       
   121     */
       
   122     DriveType driveType();
       
   123     
       
   124 private:
       
   125     quint64 mSize;
       
   126     quint64 mFreeSize;
       
   127     QString mName;
       
   128     QString mVolumeName;
       
   129     DriveState mDriveState;
       
   130     DriveType mDriveType;
       
   131 };
       
   132 Q_DECLARE_OPERATORS_FOR_FLAGS( FmDriverInfo::DriveState )
       
   133 
       
   134 /*!
       
   135     \class FmUtils
       
   136     \brief The class FmUtils provide util functions
       
   137     This class is implemented by three parts:
       
   138     fmutils.cpp for Qt Based functions
       
   139     fmutils_s60.cpp is symbian implement version for platform based functions
       
   140     fmutils_win.cpp is win32 implement version for platform based functions( a simple wrapper )
       
   141  */
       
   142 class FmUtils
       
   143 {
       
   144 public:
       
   145     //////////////////////////////////////////////////////////////////
       
   146     // <QtBasedFunctions>
       
   147     static QString  getDriveNameFromPath( const QString &path );
       
   148     static QString  getDriveLetterFromPath( const QString &path );
       
   149     static QString  formatStorageSize( quint64 size );
       
   150     static bool     isDrive( const QString &path );
       
   151     static QString  formatPath( const QString &path  );
       
   152     static QString  fillPathWithSplash( const QString &filePath );
       
   153     static QString  removePathSplash( const QString &filePath );
       
   154     static void     getDriveList( QStringList &driveList, bool isHideUnAvailableDrive );
       
   155     static QString  fillDriveVolume( QString driveName, bool isFillWithDefaultVolume );
       
   156     static QString  getDefaultVolumeName( const QString &driveName );
       
   157     static QString  getVolumeNameWithDefaultNameIfNull( const QString &diskName, bool &defaultName );
       
   158     static bool     isPathEqual( const QString &pathFst, const QString &pathLast );
       
   159     static bool     checkFolderFileName( const QString& name );
       
   160     static bool     checkNewFolderOrFile( const QString& fileName, const QString &path, QString &errString );
       
   161     static bool     isSubLevelPath( const QString &src, const QString &dest );
       
   162     // </QtBasedFunctions>
       
   163     //////////////////////////////////////////////////////////////////
       
   164     
       
   165     
       
   166     //////////////////////////////////////////////////////////////////
       
   167     // <platformBasedFunctions>
       
   168     static FmDriverInfo queryDriverInfo( const QString &driverName );
       
   169     
       
   170     // password related functions
       
   171     static int      removeDrivePwd( const QString &driverName, const QString &Pwd );
       
   172     static int      unlockDrive( const QString &driverName, const QString &Pwd );
       
   173     static int      checkDrivePwd( const QString &driverName, const QString &pwd);
       
   174     static int      setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd);
       
   175     static void     emptyPwd( QString &pwd );
       
   176     
       
   177     // external drive related functions
       
   178     static int      renameDrive( const QString &driverName, const QString &newVolumeName);
       
   179     static int      ejectDrive( const QString &driverName );
       
   180     
       
   181     // drive security related functions
       
   182     static bool     checkDriveAccessFilter( const QString &driveName );
       
   183     static QString  checkDriveToFolderFilter( const QString &path );
       
   184     static QString  checkFolderToDriveFilter( const QString &path );
       
   185     static int      isPathAccessabel( const QString &path );
       
   186     static bool     isDriveAvailable( const QString &path );
       
   187     
       
   188     // system default folder related functions
       
   189     static bool     isDefaultFolder( const QString &folderPath  );
       
   190     static void     createDefaultFolders( const QString &driverName );
       
   191     static QString  localize( const QString &path );
       
   192         
       
   193     // copy move related functions
       
   194     static int      setFileAttributes( const QString &srcFile, const QString &desFile );
       
   195     static bool     hasEnoughSpace( const QString &targetDrive, qint64 size );
       
   196     static int      moveInsideDrive( const QString &source, const QString &target );
       
   197 	
       
   198     // other fucntions
       
   199     static int      launchFile( const QString &filePath );
       
   200     static void     sendFiles( QStringList &filePathList );
       
   201     static QString  getBurConfigPath( QString appPath );
       
   202     static QString  getFileType( const QString &filePath  );
       
   203     static bool     isDriveC( const QString &driverName );
       
   204     static int      getMaxFileNameLength();
       
   205     static bool     checkMaxPathLength( const QString& path );
       
   206     // </platformBasedFunctions>
       
   207     //////////////////////////////////////////////////////////////////
       
   208 };
       
   209 
       
   210 #endif
       
   211