filemanager/src/inc/fmutils_win.cpp
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 source file of the file manager utilities on windows
       
    17 */
       
    18 
       
    19 #include "fmutils.h"
       
    20 
       
    21 #include <windows.h>
       
    22 
       
    23 #include <QDir>
       
    24 #include <QUrl>
       
    25 #include <QVariant>
       
    26 #include <QFileInfo>
       
    27 #include <QDesktopServices>
       
    28 
       
    29 #include <hbglobal.h>
       
    30 
       
    31 #define BURCONFIGFILE  "burconfig.xml"
       
    32 const int KMaxFileName=0x100;
       
    33 const int KMaxPath=0x100;
       
    34 
       
    35 FmDriverInfo FmUtils::queryDriverInfo( const QString &driveName )
       
    36 {
       
    37     quint64 size = 0;
       
    38     quint64 freeSize = 0;
       
    39     QString drive = driveName;
       
    40     
       
    41     drive.replace( '/', "\\" );
       
    42     if ( drive.right(1) != "\\" ) {
       
    43         drive.append( "\\" );
       
    44     }
       
    45     GetDiskFreeSpaceEx( (LPCWSTR)drive.constData(),
       
    46                         (PULARGE_INTEGER)&freeSize,
       
    47                         (PULARGE_INTEGER)&size,
       
    48                         0 );
       
    49 
       
    50     TCHAR volumeName[MAX_PATH + 1] = { 0 };
       
    51     GetVolumeInformation( (LPCWSTR)drive.constData(),
       
    52                           &volumeName[0],
       
    53                           MAX_PATH + 1,
       
    54                           0,
       
    55                           0,
       
    56                           0,
       
    57                           0,
       
    58                           0 );
       
    59 
       
    60     quint32 state( 0 );
       
    61     quint32 drvStatus = GetDriveType( (LPCWSTR)drive.constData() );
       
    62     if ( drvStatus == DRIVE_REMOVABLE  ) {
       
    63         state |= FmDriverInfo::EDriveRemovable;
       
    64     }
       
    65 
       
    66 	if( !(state&FmDriverInfo::EDriveNotPresent) && !(state&FmDriverInfo::EDriveLocked) &&
       
    67 		!(state&FmDriverInfo::EDriveCorrupted) ) {
       
    68 		state |= FmDriverInfo::EDriveAvailable;
       
    69 	}
       
    70     return FmDriverInfo( size, freeSize, driveName, QString::fromWCharArray( &volumeName[0] ), state );
       
    71 }
       
    72 
       
    73 int FmUtils::removeDrivePwd( const QString &driveName,  const QString &Pwd )
       
    74 {
       
    75     Q_UNUSED( driveName );
       
    76     Q_UNUSED( Pwd );
       
    77     return 0;
       
    78 }
       
    79 
       
    80 int FmUtils::unlockDrive( const QString &driveName,  const QString &Pwd )
       
    81 {
       
    82     Q_UNUSED( driveName );
       
    83     Q_UNUSED( Pwd );
       
    84     return 0;
       
    85 }
       
    86 
       
    87 int FmUtils::checkDrivePwd( const QString &driveName, const QString &pwd)
       
    88 {
       
    89     Q_UNUSED( driveName );
       
    90     Q_UNUSED( pwd );
       
    91     return 0;
       
    92 }
       
    93 
       
    94 int FmUtils::setDrivePwd( const QString &driveName, const QString &oldPwd, const QString &newPwd)
       
    95 {
       
    96     Q_UNUSED( driveName );
       
    97     Q_UNUSED( oldPwd );
       
    98     Q_UNUSED( newPwd );
       
    99     return 0;
       
   100 }
       
   101 
       
   102 void FmUtils::emptyPwd( QString &pwd )
       
   103 {
       
   104     Q_UNUSED( pwd );
       
   105 }
       
   106 
       
   107 int FmUtils::renameDrive( const QString &driveName, const QString &newVolumeName)
       
   108 {
       
   109     Q_UNUSED( driveName );
       
   110     foreach( const QChar &ch, newVolumeName )
       
   111     {
       
   112         // If not alphadigit or space, return error
       
   113         if( !ch.isLetterOrNumber() && !ch.isSpace() )
       
   114         {
       
   115             return FmErrBadName;
       
   116         }   
       
   117     }
       
   118     return 0;
       
   119 }
       
   120 
       
   121 int FmUtils::ejectDrive( const QString &driveName )
       
   122 {
       
   123     Q_UNUSED( driveName );
       
   124 	return FmErrNone; 
       
   125 }
       
   126 
       
   127 bool FmUtils::checkDriveAccessFilter( const QString &driveName )
       
   128 {
       
   129     Q_UNUSED( driveName );
       
   130     return true;
       
   131 }
       
   132 
       
   133 QString FmUtils::checkDriveToFolderFilter( const QString &path )
       
   134 {
       
   135     Q_UNUSED( path );
       
   136     return path;
       
   137 
       
   138 }
       
   139 
       
   140 QString FmUtils::checkFolderToDriveFilter( const QString &path )
       
   141 {
       
   142     Q_UNUSED( path );
       
   143     return path;
       
   144 
       
   145 }
       
   146 
       
   147 int FmUtils::isPathAccessabel( const QString &path )
       
   148 {
       
   149     Q_UNUSED( path );
       
   150     return FmErrNone;
       
   151 }
       
   152 
       
   153 bool FmUtils::isDriveAvailable( const QString &path )
       
   154 {
       
   155     Q_UNUSED( path );
       
   156 	return true;
       
   157 }
       
   158 
       
   159 bool FmUtils::isDefaultFolder( const QString &folderPath  )
       
   160 {
       
   161     Q_UNUSED( folderPath );
       
   162     return false;
       
   163 }
       
   164 
       
   165 void FmUtils::createDefaultFolders( const QString &driveName )
       
   166 {
       
   167     Q_UNUSED( driveName );
       
   168 }
       
   169 
       
   170 /*!
       
   171     set the \a desFile attributes as the same with \a srcFile
       
   172 */
       
   173 int FmUtils::setFileAttributes( const QString &srcFile, const QString &desFile )
       
   174 {
       
   175     Q_UNUSED( srcFile );
       
   176     Q_UNUSED( desFile );
       
   177     return FmErrNone;
       
   178 }
       
   179 
       
   180 /*!
       
   181     judge whether there is enough space on \a targetDrive for \a size.
       
   182     return true if has, false if not.
       
   183 */
       
   184 bool FmUtils::hasEnoughSpace( const QString &targetDrive, qint64 size )
       
   185 {
       
   186     Q_UNUSED( targetDrive );
       
   187     Q_UNUSED( size );
       
   188     return true;
       
   189 }
       
   190 
       
   191 /*!
       
   192     move one file insice the same drive, from \a source to \a target.
       
   193     return KErrNone if successful, otherwise one of the other system-wide error codes.
       
   194 */
       
   195 int FmUtils::moveInsideDrive( const QString &source, const QString &target )
       
   196 {
       
   197     Q_UNUSED( source );
       
   198     Q_UNUSED( target );
       
   199     return FmErrNone;
       
   200 }
       
   201 
       
   202 int FmUtils::launchFile( const QString &filePath )
       
   203 {
       
   204     if( QDesktopServices::openUrl( QUrl::fromLocalFile( filePath ) ) ) {
       
   205         return FmErrNone;
       
   206     } else {
       
   207         return FmErrGeneral;
       
   208     }
       
   209 }
       
   210 
       
   211 void FmUtils::sendFiles( QStringList &filePathList )
       
   212 {
       
   213     Q_UNUSED( filePathList );
       
   214 }
       
   215 
       
   216 QString FmUtils::getBurConfigPath( QString appPath )
       
   217 {
       
   218     QFileInfo fileInfo( appPath );
       
   219     QString testString = fileInfo.absolutePath();
       
   220     QString path = fillPathWithSplash( fileInfo.absolutePath() );
       
   221     path = path + QString( "src/filemanager/" );
       
   222     path = path + QString( BURCONFIGFILE );
       
   223     return path;
       
   224 }
       
   225 
       
   226 QString FmUtils::getFileType( const QString &filePath  )
       
   227 {
       
   228     Q_UNUSED( filePath );
       
   229     return QString( "" );
       
   230 }
       
   231 
       
   232 bool FmUtils::isDriveC( const QString &driveName )
       
   233 {
       
   234 	if( driveName.contains(Drive_C,Qt::CaseInsensitive) ){
       
   235         return true;
       
   236     }
       
   237     else{
       
   238         return false;
       
   239     }
       
   240 }
       
   241 
       
   242 int FmUtils::getMaxFileNameLength()
       
   243 {
       
   244     return KMaxFileName;
       
   245 }
       
   246 
       
   247 bool FmUtils::checkMaxPathLength( const QString& path )
       
   248 {
       
   249     if( path.length() > KMaxPath ) {
       
   250         return false;
       
   251     }
       
   252     return true;
       
   253 }