filemanager/src/inc/fmutils_s60.cpp
author hgs
Thu, 02 Sep 2010 17:00:51 +0800
changeset 40 4167eb56f30d
parent 33 328cf6fbe40c
child 47 12b82dc0e8db
permissions -rw-r--r--
201035
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*     Zhiqiang Yang <zhiqiang.yang@nokia.com>
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* 
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
* Description:
40
hgs
parents: 33
diff changeset
    16
*     The source file of the file manager utilities on Symbian
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
*/
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    19
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
#include "fmutils.h"
40
hgs
parents: 33
diff changeset
    21
#include "fmcommon.h"
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    22
#include "fms60utils.h"
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    23
40
hgs
parents: 33
diff changeset
    24
#include <apgcli.h>
hgs
parents: 33
diff changeset
    25
#include <sysutil.h>
hgs
parents: 33
diff changeset
    26
#include <f32file.h>
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    27
#include <coemain.h>
40
hgs
parents: 33
diff changeset
    28
#include <pathinfo.h>
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    29
#include <driveinfo.h>
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    30
#include <e32property.h>
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    31
#include <coreapplicationuisdomainpskeys.h>
40
hgs
parents: 33
diff changeset
    32
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
#include <QDir>
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
#include <QFile>
40
hgs
parents: 33
diff changeset
    35
#include <QRegExp>
hgs
parents: 33
diff changeset
    36
#include <QStringList>
hgs
parents: 33
diff changeset
    37
#include <QFileInfoList>
25
hgs
parents: 16
diff changeset
    38
40
hgs
parents: 33
diff changeset
    39
#include <xqappmgr.h>
hgs
parents: 33
diff changeset
    40
#include <XQConversions>
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    41
#include <xqaiwrequest.h>
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
40
hgs
parents: 33
diff changeset
    43
#include <hbglobal.h>
hgs
parents: 33
diff changeset
    44
#include <hbdirectorynamelocalizer.h>
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    45
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    46
#define BURCONFIGFILE  "z:/private/2002BCC0/burconfig.xml"
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    47
33
hgs
parents: 32
diff changeset
    48
/*!
40
hgs
parents: 33
diff changeset
    49
    query drive info and status for \a driveName
hgs
parents: 33
diff changeset
    50
    return \a FmDriverInfo
33
hgs
parents: 32
diff changeset
    51
*/
40
hgs
parents: 33
diff changeset
    52
FmDriverInfo FmUtils::queryDriverInfo( const QString &driveName )
33
hgs
parents: 32
diff changeset
    53
{
40
hgs
parents: 33
diff changeset
    54
    if( driveName.isEmpty() ) {
hgs
parents: 33
diff changeset
    55
        return FmDriverInfo( 0, 0, driveName, QString(), FmDriverInfo::EDriveNotPresent );
25
hgs
parents: 16
diff changeset
    56
    }
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    57
    CCoeEnv *env = CCoeEnv::Static();
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    58
    RFs& fs = env->FsSession();
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    59
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    60
    TVolumeInfo volumeInfo;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    61
    TInt drive = 0;
40
hgs
parents: 33
diff changeset
    62
    drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    63
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    64
    quint32 state( 0 );
40
hgs
parents: 33
diff changeset
    65
    
25
hgs
parents: 16
diff changeset
    66
    int volumeInfoErr( KErrNone );
hgs
parents: 16
diff changeset
    67
    int driveInfoErr( KErrNone );
hgs
parents: 16
diff changeset
    68
    int errorCode( KErrNone );
hgs
parents: 16
diff changeset
    69
    volumeInfoErr = fs.Volume( volumeInfo, drive );
hgs
parents: 16
diff changeset
    70
    errorCode = volumeInfoErr;
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    71
    QString volumeName( (QChar*)( volumeInfo.iName.Des().Ptr() ), volumeInfo.iName.Length() );
25
hgs
parents: 16
diff changeset
    72
    
hgs
parents: 16
diff changeset
    73
    TDriveInfo driveInfo;
hgs
parents: 16
diff changeset
    74
    if( volumeInfoErr == KErrNone ) {
hgs
parents: 16
diff changeset
    75
        driveInfo = volumeInfo.iDrive;
hgs
parents: 16
diff changeset
    76
    } else {
hgs
parents: 16
diff changeset
    77
        driveInfoErr = fs.Drive( driveInfo, drive );
hgs
parents: 16
diff changeset
    78
        if( driveInfoErr != KErrNone ) {
hgs
parents: 16
diff changeset
    79
            errorCode = driveInfoErr;
hgs
parents: 16
diff changeset
    80
        }
hgs
parents: 16
diff changeset
    81
    }
hgs
parents: 16
diff changeset
    82
    
27
hgs
parents: 25
diff changeset
    83
    if( volumeInfoErr == KErrNone || driveInfoErr == KErrNone ) {
25
hgs
parents: 16
diff changeset
    84
        //TDriveInfo driveInfo = volumeInfo.iDrive;
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    85
    
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    86
        quint32 drvStatus( 0 );
25
hgs
parents: 16
diff changeset
    87
        int err = DriveInfo::GetDriveStatus( fs, drive, drvStatus );
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    88
        if( err == KErrNone ) {
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    89
            
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    90
            if ( ( drvStatus & DriveInfo::EDriveInternal ) &&
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    91
                 ( drvStatus & DriveInfo::EDriveExternallyMountable ) ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    92
                // Handle mass storage bits here
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    93
                state |= FmDriverInfo::EDriveMassStorage | FmDriverInfo::EDriveRemovable;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    94
            }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
    95
        
25
hgs
parents: 16
diff changeset
    96
            if ( drvStatus & DriveInfo::EDriveUsbMemory )
hgs
parents: 16
diff changeset
    97
                {
hgs
parents: 16
diff changeset
    98
                state |= FmDriverInfo::EDriveUsbMemory;
hgs
parents: 16
diff changeset
    99
                }
33
hgs
parents: 32
diff changeset
   100
            
hgs
parents: 32
diff changeset
   101
            if ( drvStatus & DriveInfo::EDriveRemote )
hgs
parents: 32
diff changeset
   102
                {
hgs
parents: 32
diff changeset
   103
                state |= FmDriverInfo::EDriveRemote;
hgs
parents: 32
diff changeset
   104
                }
hgs
parents: 32
diff changeset
   105
            
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   106
            if ( drvStatus & DriveInfo::EDriveRom ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   107
                state |= FmDriverInfo::EDriveRom;  
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   108
            }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   109
            
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   110
            if ( drvStatus & DriveInfo::EDriveRam ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   111
                state |= FmDriverInfo::EDriveRam;  
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   112
            }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   113
        
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   114
            if ( driveInfo.iMediaAtt & KMediaAttFormattable ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   115
                state |= FmDriverInfo::EDriveFormattable;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   116
            }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   117
            if ( driveInfo.iMediaAtt & KMediaAttWriteProtected ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   118
                state |= FmDriverInfo::EDriveWriteProtected;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   119
            }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   120
            if ( driveInfo.iMediaAtt & KMediaAttHasPassword ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   121
                state |= FmDriverInfo::EDrivePasswordProtected;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   122
            }    
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   123
            if ( driveInfo.iMediaAtt & KMediaAttLocked ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   124
                state |= FmDriverInfo::EDriveLocked;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   125
            }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   126
        
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   127
            if ( driveInfo.iDriveAtt & KDriveAttRemovable ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   128
                state |= FmDriverInfo::EDriveRemovable;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   129
        
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   130
                if ( drvStatus & DriveInfo::EDriveSwEjectable ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   131
                    state |= FmDriverInfo::EDriveEjectable;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   132
                }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   133
            }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   134
            
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   135
            if( driveInfo.iType == EMediaNotPresent ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   136
                state |= FmDriverInfo::EDriveNotPresent;    
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   137
            }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   138
        }
25
hgs
parents: 16
diff changeset
   139
        // If memory card is not ready but type is present,
hgs
parents: 16
diff changeset
   140
        // then check if it is reserved.
hgs
parents: 16
diff changeset
   141
        if( err == KErrNone && volumeInfoErr == KErrNotReady &&
hgs
parents: 16
diff changeset
   142
            driveInfo.iType != EMediaNotPresent )
hgs
parents: 16
diff changeset
   143
            {
hgs
parents: 16
diff changeset
   144
            // Check USB file transfer state
hgs
parents: 16
diff changeset
   145
            TInt prop( ECoreAppUIsUSBFileTransferUninitialized );
hgs
parents: 16
diff changeset
   146
            RProperty::Get(
hgs
parents: 16
diff changeset
   147
                KPSUidCoreApplicationUIs,
hgs
parents: 16
diff changeset
   148
                KCoreAppUIsUSBFileTransfer, prop );
hgs
parents: 16
diff changeset
   149
            if ( prop == ECoreAppUIsUSBFileTransferActive )
hgs
parents: 16
diff changeset
   150
                {
hgs
parents: 16
diff changeset
   151
                errorCode = KErrInUse; // Reserved for file transfer
hgs
parents: 16
diff changeset
   152
                }
hgs
parents: 16
diff changeset
   153
            }
hgs
parents: 16
diff changeset
   154
        if( err!= KErrNone )
hgs
parents: 16
diff changeset
   155
            {
hgs
parents: 16
diff changeset
   156
            errorCode = err;
hgs
parents: 16
diff changeset
   157
            }
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   158
    }
25
hgs
parents: 16
diff changeset
   159
hgs
parents: 16
diff changeset
   160
    // handle error code
hgs
parents: 16
diff changeset
   161
    // volumeInfoErr will occur while drive is lock,corrupted...
hgs
parents: 16
diff changeset
   162
    // driveInfoErr can not be promoted for locked, corrupted drive.
hgs
parents: 16
diff changeset
   163
    // so we can not use driveInfoErr to justify EDriveAvailable
hgs
parents: 16
diff changeset
   164
    switch( errorCode )
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   165
    {
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   166
    case KErrNone:
25
hgs
parents: 16
diff changeset
   167
        // this drive could be used as it is not be locked, or corrupt.
hgs
parents: 16
diff changeset
   168
        state |= FmDriverInfo::EDriveAvailable; 
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   169
        break;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   170
    case KErrLocked:
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   171
        state |= FmDriverInfo::EDriveLocked;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   172
        break;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   173
    case KErrCorrupt:
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   174
        state |= FmDriverInfo::EDriveCorrupted;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   175
        break;
25
hgs
parents: 16
diff changeset
   176
    case KErrInUse:
hgs
parents: 16
diff changeset
   177
        state |= FmDriverInfo::EDriveInUse;
hgs
parents: 16
diff changeset
   178
        break;
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   179
    default: // other errors
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   180
        state |= FmDriverInfo::EDriveNotPresent;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   181
        break;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   182
    }
40
hgs
parents: 33
diff changeset
   183
    QString logString ( "FmUtils::queryDriverInfo_" + driveName + 
25
hgs
parents: 16
diff changeset
   184
            "_volumeInfoErr:" + QString::number( volumeInfoErr ) +
hgs
parents: 16
diff changeset
   185
            "_driveInfoErr:" + QString::number( driveInfoErr ) +
hgs
parents: 16
diff changeset
   186
            "_errorCode:" + QString::number( errorCode ) + 
hgs
parents: 16
diff changeset
   187
            "_driveSatus:" + QString::number( state ) );
32
hgs
parents: 27
diff changeset
   188
    FM_LOG( logString );
40
hgs
parents: 33
diff changeset
   189
    return FmDriverInfo( volumeInfo.iSize, volumeInfo.iFree, driveName, volumeName, state );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   190
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   191
40
hgs
parents: 33
diff changeset
   192
/*!
hgs
parents: 33
diff changeset
   193
    remove drive password for \a driveName
hgs
parents: 33
diff changeset
   194
    \a Pwd is original password.
hgs
parents: 33
diff changeset
   195
*/
hgs
parents: 33
diff changeset
   196
int FmUtils::removeDrivePwd( const QString &driveName,  const QString &Pwd )
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   197
{
40
hgs
parents: 33
diff changeset
   198
    if( driveName.isEmpty() || Pwd.length() > FmMaxLengthofDrivePassword ) {
25
hgs
parents: 16
diff changeset
   199
        return FmErrWrongParam;
hgs
parents: 16
diff changeset
   200
    }
40
hgs
parents: 33
diff changeset
   201
    QString logString = "Drive name:" + driveName;
32
hgs
parents: 27
diff changeset
   202
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   203
    logString = "Password:" + Pwd;
32
hgs
parents: 27
diff changeset
   204
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   205
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   206
    CCoeEnv *env = CCoeEnv::Static();
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   207
	RFs& fs = env->FsSession();
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   208
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   209
    TInt drive = 0;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   210
40
hgs
parents: 33
diff changeset
   211
    drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   212
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   213
    HBufC* password16 = XQConversions::qStringToS60Desc( Pwd );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   214
    TMediaPassword password;   
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   215
    TPtr ptrPassword16( password16->Des() );  
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   216
    FmS60Utils::ConvertCharsToPwd( ptrPassword16, password );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   217
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   218
    int err( fs.ClearPassword( drive, password ) );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   219
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   220
    logString = "Drive:" + QString::number( drive );
32
hgs
parents: 27
diff changeset
   221
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   222
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   223
    logString = "Clear password error:" + QString::number( err );
32
hgs
parents: 27
diff changeset
   224
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   225
33
hgs
parents: 32
diff changeset
   226
    delete password16;
hgs
parents: 32
diff changeset
   227
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   228
    if( err == KErrNone ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   229
        return FmErrNone;   
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   230
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   231
    else if( err == KErrAccessDenied ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   232
        return FmErrAccessDenied;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   233
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   234
    else{
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   235
        return FmErrUnKnown;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   236
    }
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   237
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   238
40
hgs
parents: 33
diff changeset
   239
/*!
hgs
parents: 33
diff changeset
   240
    Unlock drive \a driveName with provided password \a Pwd
hgs
parents: 33
diff changeset
   241
*/
hgs
parents: 33
diff changeset
   242
int FmUtils::unlockDrive( const QString &driveName,  const QString &Pwd )
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   243
{
40
hgs
parents: 33
diff changeset
   244
    if( driveName.isEmpty() || Pwd.length() > FmMaxLengthofDrivePassword ) {
25
hgs
parents: 16
diff changeset
   245
        return FmErrWrongParam;
hgs
parents: 16
diff changeset
   246
    }
40
hgs
parents: 33
diff changeset
   247
    QString logString = "Drive name:" + driveName;
32
hgs
parents: 27
diff changeset
   248
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   249
    logString = "Password:" + Pwd;
32
hgs
parents: 27
diff changeset
   250
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   251
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   252
    CCoeEnv *env = CCoeEnv::Static();
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   253
	RFs& fs = env->FsSession();
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   254
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   255
    TInt drive = 0;
40
hgs
parents: 33
diff changeset
   256
	drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   257
    
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   258
    HBufC* password16 = XQConversions::qStringToS60Desc( Pwd );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   259
    TMediaPassword password;   
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   260
    TPtr ptrPassword16( password16->Des() );  
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   261
    FmS60Utils::ConvertCharsToPwd( ptrPassword16, password );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   262
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   263
    int err( fs.UnlockDrive( drive, password, ETrue) );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   264
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   265
    logString = "Drive:" + QString::number( drive );
32
hgs
parents: 27
diff changeset
   266
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   267
    logString = "Unlock drive error:" + QString::number( err );
32
hgs
parents: 27
diff changeset
   268
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   269
33
hgs
parents: 32
diff changeset
   270
    delete password16;
hgs
parents: 32
diff changeset
   271
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   272
    if( err == KErrNone ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   273
        return FmErrNone;   
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   274
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   275
    else if( err == KErrAccessDenied ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   276
        return FmErrAccessDenied;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   277
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   278
    else if( err == KErrAlreadyExists ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   279
        return FmErrAlreadyExists;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   280
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   281
    else if( err == KErrNotSupported ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   282
        return FmErrNotSupported;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   283
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   284
    else{
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   285
        return FmErrUnKnown;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   286
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   287
}
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   288
40
hgs
parents: 33
diff changeset
   289
/*!
hgs
parents: 33
diff changeset
   290
    Check if \a pwd is the right password for drive \a driveName
hgs
parents: 33
diff changeset
   291
*/
hgs
parents: 33
diff changeset
   292
int FmUtils::checkDrivePwd( const QString &driveName, const QString &pwd )
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   293
{
40
hgs
parents: 33
diff changeset
   294
    if( driveName.isEmpty() || pwd.length() > FmMaxLengthofDrivePassword ) {
25
hgs
parents: 16
diff changeset
   295
        return FmErrWrongParam;
hgs
parents: 16
diff changeset
   296
    }
40
hgs
parents: 33
diff changeset
   297
    QString logString = "checkDrivePwd Drive name:" + driveName;
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   298
    logString += " password:" + pwd;
32
hgs
parents: 27
diff changeset
   299
    FM_LOG( logString );
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   300
40
hgs
parents: 33
diff changeset
   301
    return setDrivePwd( driveName, pwd, pwd );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   302
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   303
40
hgs
parents: 33
diff changeset
   304
/*!
hgs
parents: 33
diff changeset
   305
    Set new password \a newPwd for drive \a driveName. \a oldPwd is old password
hgs
parents: 33
diff changeset
   306
*/
hgs
parents: 33
diff changeset
   307
int FmUtils::setDrivePwd( const QString &driveName, const QString &oldPwd, const QString &newPwd)
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   308
{
40
hgs
parents: 33
diff changeset
   309
    if( driveName.isEmpty() || 
33
hgs
parents: 32
diff changeset
   310
        oldPwd.length() > FmMaxLengthofDrivePassword || newPwd.length() > FmMaxLengthofDrivePassword  ) {
25
hgs
parents: 16
diff changeset
   311
        return FmErrWrongParam;
hgs
parents: 16
diff changeset
   312
    }
40
hgs
parents: 33
diff changeset
   313
    QString logString = "setDrivePwd Drive name:" + driveName ;
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   314
    logString += " Old password:" + oldPwd;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   315
    logString += " New password:" + newPwd;
32
hgs
parents: 27
diff changeset
   316
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   317
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   318
    CCoeEnv *env = CCoeEnv::Static();
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   319
	RFs& fs = env->FsSession();
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   320
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   321
    TInt drive = 0;
40
hgs
parents: 33
diff changeset
   322
	drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   323
	
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   324
    HBufC* newPassword16 = XQConversions::qStringToS60Desc( newPwd);
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   325
    HBufC* oldPassword16 = XQConversions::qStringToS60Desc( oldPwd );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   326
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   327
    TMediaPassword oldPassword;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   328
    TMediaPassword newPassword;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   329
    
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   330
    TPtr ptrNewPassword16( newPassword16->Des() );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   331
    TPtr ptrOldPassword16( oldPassword16->Des() );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   332
    
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   333
    FmS60Utils::ConvertCharsToPwd( ptrNewPassword16, newPassword );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   334
    FmS60Utils::ConvertCharsToPwd( ptrOldPassword16, oldPassword );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   335
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   336
    int err( fs.LockDrive( drive, oldPassword, newPassword, ETrue ) );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   337
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   338
    logString = "Drive:" + QString::number( drive );
32
hgs
parents: 27
diff changeset
   339
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   340
    logString = "Password set error:" + QString::number( err );
32
hgs
parents: 27
diff changeset
   341
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   342
33
hgs
parents: 32
diff changeset
   343
    delete newPassword16;
hgs
parents: 32
diff changeset
   344
    delete oldPassword16;
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   345
    if( err == KErrNone ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   346
        return FmErrNone;   
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   347
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   348
    else if( err == KErrNotSupported ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   349
        return FmErrNotSupported;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   350
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   351
    else{
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   352
        return FmErrUnKnown;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   353
    }
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   354
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   355
40
hgs
parents: 33
diff changeset
   356
/*!
hgs
parents: 33
diff changeset
   357
    Set \a pwd as empty password
hgs
parents: 33
diff changeset
   358
*/
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   359
void FmUtils::emptyPwd( QString &pwd )
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   360
{
33
hgs
parents: 32
diff changeset
   361
    TBuf< FmMaxLengthofDrivePassword > nullPwd;
hgs
parents: 32
diff changeset
   362
    nullPwd.FillZ( nullPwd.MaxLength() );
hgs
parents: 32
diff changeset
   363
    nullPwd.Zero();
hgs
parents: 32
diff changeset
   364
    pwd = XQConversions::s60DescToQString( nullPwd );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   365
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   366
40
hgs
parents: 33
diff changeset
   367
/*!
hgs
parents: 33
diff changeset
   368
    Set drive volume for drive \a driveName
hgs
parents: 33
diff changeset
   369
*/
hgs
parents: 33
diff changeset
   370
int FmUtils::renameDrive( const QString &driveName, const QString &newVolumeName)
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   371
{
40
hgs
parents: 33
diff changeset
   372
    if( driveName.isEmpty() ) {
25
hgs
parents: 16
diff changeset
   373
        return FmErrWrongParam;
hgs
parents: 16
diff changeset
   374
    }
hgs
parents: 16
diff changeset
   375
    foreach( const QChar &ch, newVolumeName )
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   376
    {
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   377
        bool a = ch.isSpace();
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   378
        bool b = ch.isLetterOrNumber();
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   379
        // If not alphadigit or space, return error
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   380
        if( !ch.isLetterOrNumber() && !ch.isSpace() )
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   381
        {
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   382
            return FmErrBadName;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   383
        }   
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   384
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   385
        
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   386
    CCoeEnv *env = CCoeEnv::Static();
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   387
	RFs& fs = env->FsSession();
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   388
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   389
    TInt drive = 0;
40
hgs
parents: 33
diff changeset
   390
	drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   391
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   392
    TPtr newName ( ( XQConversions::qStringToS60Desc( newVolumeName ) )->Des() );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   393
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   394
    int err( fs.SetVolumeLabel( newName, drive ));
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   395
    
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   396
    QString logString = "Rename error:" + QString::number( err );
32
hgs
parents: 27
diff changeset
   397
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   398
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   399
    if( err == KErrNone ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   400
        return FmErrNone;   
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   401
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   402
    else if( err == KErrNotReady ){
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   403
        return FmErrNotReady;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   404
    }
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   405
    else{
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   406
        return FmErrUnKnown;
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   407
    }
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   408
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   409
40
hgs
parents: 33
diff changeset
   410
/*!
hgs
parents: 33
diff changeset
   411
    Eject drive \a driveName
hgs
parents: 33
diff changeset
   412
*/
hgs
parents: 33
diff changeset
   413
int FmUtils::ejectDrive( const QString &driveName )
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   414
{
40
hgs
parents: 33
diff changeset
   415
    if( driveName.isEmpty() ) {
25
hgs
parents: 16
diff changeset
   416
        return FmErrWrongParam;
hgs
parents: 16
diff changeset
   417
    }
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   418
    QString logString = "FmUtils::ejectDrive start";
32
hgs
parents: 27
diff changeset
   419
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   420
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   421
    TInt drive = 0;
40
hgs
parents: 33
diff changeset
   422
	drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   423
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   424
    const int KDriveShift = 16;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   425
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   426
    // Let SysAp handle eject
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   427
    RProperty::Set(
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   428
        KPSUidCoreApplicationUIs,
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   429
        KCoreAppUIsMmcRemovedWithoutEject,
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   430
        ECoreAppUIsEjectCommandUsedToDrive | ( drive << KDriveShift )
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   431
        );
25
hgs
parents: 16
diff changeset
   432
    return FmErrNone;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   433
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   434
40
hgs
parents: 33
diff changeset
   435
/*!
hgs
parents: 33
diff changeset
   436
    Check if drive \a driveName is accessable for user
hgs
parents: 33
diff changeset
   437
*/
hgs
parents: 33
diff changeset
   438
bool FmUtils::checkDriveAccessFilter( const QString &driveName )
hgs
parents: 33
diff changeset
   439
{
hgs
parents: 33
diff changeset
   440
    if( driveName.isEmpty() ) {
hgs
parents: 33
diff changeset
   441
        return false;
hgs
parents: 33
diff changeset
   442
    }
hgs
parents: 33
diff changeset
   443
    FmDriverInfo driveInfo = queryDriverInfo( driveName );
hgs
parents: 33
diff changeset
   444
    if( ( driveInfo.driveState()& FmDriverInfo::EDriveRam ) ||
hgs
parents: 33
diff changeset
   445
        ( driveInfo.driveState()& FmDriverInfo::EDriveRom ) ) {
hgs
parents: 33
diff changeset
   446
        return false;
hgs
parents: 33
diff changeset
   447
    }
hgs
parents: 33
diff changeset
   448
    return true;
hgs
parents: 33
diff changeset
   449
}
hgs
parents: 33
diff changeset
   450
hgs
parents: 33
diff changeset
   451
/*!
hgs
parents: 33
diff changeset
   452
    This function should be called to adjust path if user goto a drive.
hgs
parents: 33
diff changeset
   453
    data folder will be append to C:\ becuase user could only view C:\data instead C:\ 
hgs
parents: 33
diff changeset
   454
*/
hgs
parents: 33
diff changeset
   455
QString FmUtils::checkDriveToFolderFilter( const QString &path )
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   456
{
40
hgs
parents: 33
diff changeset
   457
    QString checkedPath = fillPathWithSplash( path );
hgs
parents: 33
diff changeset
   458
    if( checkedPath.compare( Drive_C, Qt::CaseInsensitive ) == 0 ) {
hgs
parents: 33
diff changeset
   459
        checkedPath += QString( "data" ) + QDir::separator();
hgs
parents: 33
diff changeset
   460
        return checkedPath;
hgs
parents: 33
diff changeset
   461
    }
hgs
parents: 33
diff changeset
   462
    return path;
hgs
parents: 33
diff changeset
   463
hgs
parents: 33
diff changeset
   464
}
hgs
parents: 33
diff changeset
   465
hgs
parents: 33
diff changeset
   466
/*!
hgs
parents: 33
diff changeset
   467
    This function should be called to adjust path if user back to up level path.
hgs
parents: 33
diff changeset
   468
    If user is at C:\data then path level should be returned as C:\
hgs
parents: 33
diff changeset
   469
    Becuase C:\data is root path for C drive 
hgs
parents: 33
diff changeset
   470
*/
hgs
parents: 33
diff changeset
   471
QString FmUtils::checkFolderToDriveFilter( const QString &path )
hgs
parents: 33
diff changeset
   472
{
hgs
parents: 33
diff changeset
   473
    QString logString;
hgs
parents: 33
diff changeset
   474
    logString = QString( "checkFolderToDriveFilter: " ) + path;
hgs
parents: 33
diff changeset
   475
    FM_LOG( logString );
hgs
parents: 33
diff changeset
   476
    QString checkedPath = fillPathWithSplash( path );
hgs
parents: 33
diff changeset
   477
hgs
parents: 33
diff changeset
   478
    logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath;
hgs
parents: 33
diff changeset
   479
    FM_LOG( logString );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   480
    
40
hgs
parents: 33
diff changeset
   481
    if( checkedPath.compare( Folder_C_Data, Qt::CaseInsensitive ) == 0 ) {
hgs
parents: 33
diff changeset
   482
        FM_LOG( QString( " change from c:/data/ to C:/" ) );
hgs
parents: 33
diff changeset
   483
        return Drive_C;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   484
    }
40
hgs
parents: 33
diff changeset
   485
    return path;
hgs
parents: 33
diff changeset
   486
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   487
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   488
40
hgs
parents: 33
diff changeset
   489
/*!
hgs
parents: 33
diff changeset
   490
    Check if \a path is accessable for user
hgs
parents: 33
diff changeset
   491
*/
hgs
parents: 33
diff changeset
   492
int FmUtils::isPathAccessabel( const QString &path )
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   493
{
40
hgs
parents: 33
diff changeset
   494
    // Used to check if path is accessable, very important feature
hgs
parents: 33
diff changeset
   495
    // and will return filemanager error.
hgs
parents: 33
diff changeset
   496
    FM_LOG( QString( "isPathAccessabel:" ) + path );
hgs
parents: 33
diff changeset
   497
    if( path.isEmpty() ) {
hgs
parents: 33
diff changeset
   498
        return FmErrPathNotExist;
hgs
parents: 33
diff changeset
   499
    }
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   500
40
hgs
parents: 33
diff changeset
   501
    // used to filter locked/ejected/corrupted drive
hgs
parents: 33
diff changeset
   502
    // check if drive is available, no matter if it is a drive, a folder, or a file.
hgs
parents: 33
diff changeset
   503
    if( !isDriveAvailable( path ) ) {
hgs
parents: 33
diff changeset
   504
        FM_LOG( QString( "isPathAccessabel false: path is drive and not available" ) );
hgs
parents: 33
diff changeset
   505
        return FmErrDriveNotAvailable;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   506
    }
40
hgs
parents: 33
diff changeset
   507
hgs
parents: 33
diff changeset
   508
    QFileInfo fileInfo( path );
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   509
40
hgs
parents: 33
diff changeset
   510
    if( fileInfo.absoluteFilePath().contains( Drive_C, Qt::CaseInsensitive ) &&
hgs
parents: 33
diff changeset
   511
        !fileInfo.absoluteFilePath().contains( Folder_C_Data, Qt::CaseInsensitive ) ) {
hgs
parents: 33
diff changeset
   512
        FM_LOG( QString( "isPathAccessabel false: path contain C and not in data folder" ) );
hgs
parents: 33
diff changeset
   513
        return FmErrPathDenied;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   514
    }
40
hgs
parents: 33
diff changeset
   515
    if( !checkDriveAccessFilter( FmUtils::getDriveNameFromPath( fileInfo.absoluteFilePath() ) ) ){
hgs
parents: 33
diff changeset
   516
        return FmErrDriveDenied;
hgs
parents: 33
diff changeset
   517
    }
hgs
parents: 33
diff changeset
   518
    if( !fileInfo.exists() ) {
hgs
parents: 33
diff changeset
   519
        FM_LOG( QString( "isPathAccessabel false: path not exist" ) );
hgs
parents: 33
diff changeset
   520
        return FmErrPathNotExist;
hgs
parents: 33
diff changeset
   521
    }
hgs
parents: 33
diff changeset
   522
    FM_LOG( QString( "isPathAccessabel FmErrNone" ) );
hgs
parents: 33
diff changeset
   523
    return FmErrNone;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   524
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   525
40
hgs
parents: 33
diff changeset
   526
/*!
hgs
parents: 33
diff changeset
   527
    Check if drive related to \a path is available.
hgs
parents: 33
diff changeset
   528
    This function should not check if path is available. Only responsible for checking drive  
hgs
parents: 33
diff changeset
   529
    When MMC is not inserted, also return false
hgs
parents: 33
diff changeset
   530
*/
hgs
parents: 33
diff changeset
   531
bool FmUtils::isDriveAvailable( const QString &path )
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   532
{
40
hgs
parents: 33
diff changeset
   533
    FM_LOG( QString( "isDriveAvailable:" ) + path );
hgs
parents: 33
diff changeset
   534
    if( path.isEmpty() ) {
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   535
        return false;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   536
    }
40
hgs
parents: 33
diff changeset
   537
    FmDriverInfo::DriveState driveState = queryDriverInfo( path ).driveState();
hgs
parents: 33
diff changeset
   538
    if( ( driveState & FmDriverInfo::EDriveAvailable ) ) {
hgs
parents: 33
diff changeset
   539
        FM_LOG( QString( "isDriveAvailable true" ) );
hgs
parents: 33
diff changeset
   540
        return true;
hgs
parents: 33
diff changeset
   541
    }
hgs
parents: 33
diff changeset
   542
    FM_LOG( QString( "isDriveAvailable false" ) );
hgs
parents: 33
diff changeset
   543
    return false;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   544
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   545
40
hgs
parents: 33
diff changeset
   546
/*!
hgs
parents: 33
diff changeset
   547
    Check if \a folderPath is default folder for system
hgs
parents: 33
diff changeset
   548
*/
hgs
parents: 33
diff changeset
   549
bool FmUtils::isDefaultFolder( const QString &folderPath  )
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   550
{
40
hgs
parents: 33
diff changeset
   551
    HBufC *path = XQConversions::qStringToS60Desc( folderPath );
hgs
parents: 33
diff changeset
   552
    TPtrC desFolderPath( path->Des() );
hgs
parents: 33
diff changeset
   553
    
hgs
parents: 33
diff changeset
   554
    bool ret( true );
hgs
parents: 33
diff changeset
   555
    TInt pathType( PathInfo::PathType( desFolderPath ) );
hgs
parents: 33
diff changeset
   556
    switch( pathType ){
hgs
parents: 33
diff changeset
   557
       case PathInfo::ENotSystemPath:{
hgs
parents: 33
diff changeset
   558
           QString locString( localize( folderPath ) );
hgs
parents: 33
diff changeset
   559
            if ( locString.isEmpty() ){
hgs
parents: 33
diff changeset
   560
                ret = false;
hgs
parents: 33
diff changeset
   561
                break;
hgs
parents: 33
diff changeset
   562
            }
hgs
parents: 33
diff changeset
   563
            ret = true;
hgs
parents: 33
diff changeset
   564
            break;
hgs
parents: 33
diff changeset
   565
            }
hgs
parents: 33
diff changeset
   566
        case PathInfo::EPhoneMemoryRootPath: // FALL THROUGH
hgs
parents: 33
diff changeset
   567
        case PathInfo::EMemoryCardRootPath: // FALL THROUGH
hgs
parents: 33
diff changeset
   568
        case PathInfo::ERomRootPath:{
hgs
parents: 33
diff changeset
   569
            ret = false;
hgs
parents: 33
diff changeset
   570
            break;
hgs
parents: 33
diff changeset
   571
        }
hgs
parents: 33
diff changeset
   572
        // Accept other folders
hgs
parents: 33
diff changeset
   573
        default:{
hgs
parents: 33
diff changeset
   574
            ret = true;
hgs
parents: 33
diff changeset
   575
            break;
hgs
parents: 33
diff changeset
   576
        }
hgs
parents: 33
diff changeset
   577
    }
hgs
parents: 33
diff changeset
   578
    delete path;
hgs
parents: 33
diff changeset
   579
    return ret;
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   580
}
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   581
40
hgs
parents: 33
diff changeset
   582
/*!
hgs
parents: 33
diff changeset
   583
    Create system default folders for drive \a driveName.
hgs
parents: 33
diff changeset
   584
    Default folders should be created after format a drive.
hgs
parents: 33
diff changeset
   585
*/
hgs
parents: 33
diff changeset
   586
void FmUtils::createDefaultFolders( const QString &driveName )
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   587
{
40
hgs
parents: 33
diff changeset
   588
    if( driveName.isEmpty() ) {
25
hgs
parents: 16
diff changeset
   589
        return;
hgs
parents: 16
diff changeset
   590
    }
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   591
    int err;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   592
    
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   593
    TInt drive = 0;
40
hgs
parents: 33
diff changeset
   594
    drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
14
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   595
    
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   596
    RFs fs;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   597
    err = fs.Connect();
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   598
    
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   599
    if( err != KErrNone ){
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   600
        return;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   601
    }
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   602
    
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   603
    quint32 drvStatus( 0 );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   604
    err = DriveInfo::GetDriveStatus( fs, drive, drvStatus );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   605
    if ( !( drvStatus & DriveInfo::EDriveUserVisible ) ||
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   606
        ( drvStatus & ( DriveInfo::EDriveRemote |
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   607
                        DriveInfo::EDriveReadOnly |
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   608
                        DriveInfo::EDriveUsbMemory ) ) ){
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   609
            return; 
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   610
        }
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   611
    
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   612
    TEntry entry;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   613
    CDesCArray* array = PathInfo::GetListOfPathsLC( drive );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   614
    
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   615
    TInt count( array->MdcaCount() );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   616
    for ( TInt i( 0 ); i < count; ++i )
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   617
        {
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   618
        TPtrC fullPath( array->MdcaPoint( i ) );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   619
        TBool allow( ETrue );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   620
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   621
        if ( drvStatus & DriveInfo::EDriveRemovable )
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   622
            {
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   623
            // Filter few folder types from physically removable memory cards
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   624
            TInt pathType( PathInfo::PathType( fullPath ) );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   625
            switch( pathType )
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   626
                {
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   627
                case PathInfo::EGamesPath: // FALL THROUGH
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   628
                case PathInfo::EInstallsPath: // FALL THROUGH
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   629
                case PathInfo::EGsmPicturesPath: // FALL THROUGH
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   630
                case PathInfo::EMmsBackgroundImagesPath: // FALL THROUGH
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   631
                case PathInfo::EPresenceLogosPath:
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   632
                    {
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   633
                    allow = EFalse;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   634
                    }
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   635
                default:
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   636
                    {
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   637
                    break;
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   638
                    }
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   639
                }
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   640
            }
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   641
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   642
        if ( allow ){
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   643
            fs.MkDirAll( fullPath ); // Ignore error
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   644
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   645
            if ( fs.Entry( fullPath, entry ) == KErrNone ){
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   646
                if( entry.IsHidden() ){
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   647
                // If setting fails, File Manager can still go on
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   648
                    fs.SetEntry(
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   649
                         fullPath, entry.iModified, 0, KEntryAttHidden );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   650
                }
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   651
            }
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   652
        }
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   653
    }
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   654
    CleanupStack::PopAndDestroy( array );
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   655
}
1957042d8c7e Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   656
33
hgs
parents: 32
diff changeset
   657
/*!
40
hgs
parents: 33
diff changeset
   658
    In Symbian system, default folders will be localized.
hgs
parents: 33
diff changeset
   659
    So localize is used to check if a path is a default folder
hgs
parents: 33
diff changeset
   660
    \sa isDefaultFolder
33
hgs
parents: 32
diff changeset
   661
*/
40
hgs
parents: 33
diff changeset
   662
QString FmUtils::localize( const QString &path )
33
hgs
parents: 32
diff changeset
   663
{
40
hgs
parents: 33
diff changeset
   664
    // HbDirectoryNameLocalizer can not recognize path with \ in the end
hgs
parents: 33
diff changeset
   665
    QString locPath( removePathSplash( path ) );
16
ada7962b4308 Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 14
diff changeset
   666
    
40
hgs
parents: 33
diff changeset
   667
    HbDirectoryNameLocalizer localizer;
hgs
parents: 33
diff changeset
   668
    return localizer.translate( locPath );
27
hgs
parents: 25
diff changeset
   669
}
33
hgs
parents: 32
diff changeset
   670
hgs
parents: 32
diff changeset
   671
/*!
hgs
parents: 32
diff changeset
   672
    set the \a desFile attributes as the same with \a srcFile
hgs
parents: 32
diff changeset
   673
*/
hgs
parents: 32
diff changeset
   674
int FmUtils::setFileAttributes( const QString &srcFile, const QString &desFile )
hgs
parents: 32
diff changeset
   675
{
hgs
parents: 32
diff changeset
   676
    RFs fsSession;
hgs
parents: 32
diff changeset
   677
    User::LeaveIfError( fsSession.Connect() ); 
hgs
parents: 32
diff changeset
   678
    CleanupClosePushL( fsSession );
hgs
parents: 32
diff changeset
   679
    RFile64 src;
hgs
parents: 32
diff changeset
   680
    RFile64 des;
hgs
parents: 32
diff changeset
   681
    HBufC *buf1 = XQConversions::qStringToS60Desc( removePathSplash( formatPath( srcFile ) ) );
hgs
parents: 32
diff changeset
   682
    HBufC *buf2 = XQConversions::qStringToS60Desc( removePathSplash( formatPath( desFile ) ) );
hgs
parents: 32
diff changeset
   683
    User::LeaveIfError( src.Open( fsSession, *buf1, EFileRead | EFileShareReadersOnly ) );
hgs
parents: 32
diff changeset
   684
    User::LeaveIfError( des.Open( fsSession, *buf2, EFileWrite | EFileShareExclusive ) );
hgs
parents: 32
diff changeset
   685
    TTime mod;
hgs
parents: 32
diff changeset
   686
    int err = src.Modified( mod );;
hgs
parents: 32
diff changeset
   687
    if ( err == FmErrNone ) {
hgs
parents: 32
diff changeset
   688
        err = des.SetModified( mod );    
hgs
parents: 32
diff changeset
   689
    }
hgs
parents: 32
diff changeset
   690
    TUint att( 0 );
hgs
parents: 32
diff changeset
   691
    if ( err == FmErrNone ) {
hgs
parents: 32
diff changeset
   692
        err = src.Att( att );        
hgs
parents: 32
diff changeset
   693
    }
hgs
parents: 32
diff changeset
   694
    if ( err == FmErrNone ) {
hgs
parents: 32
diff changeset
   695
        des.SetAtt( att, ( ~att ) & KEntryAttMaskSupported );
hgs
parents: 32
diff changeset
   696
    }    
hgs
parents: 32
diff changeset
   697
    src.Close();
hgs
parents: 32
diff changeset
   698
    des.Close();
hgs
parents: 32
diff changeset
   699
    fsSession.Close();
hgs
parents: 32
diff changeset
   700
    CleanupStack::PopAndDestroy(); // fsSession
hgs
parents: 32
diff changeset
   701
    return err;
hgs
parents: 32
diff changeset
   702
}
40
hgs
parents: 33
diff changeset
   703
hgs
parents: 33
diff changeset
   704
/*!
hgs
parents: 33
diff changeset
   705
    judge whether there is enough space on \a targetDrive for \a size.
hgs
parents: 33
diff changeset
   706
    return true if has, false if not.
hgs
parents: 33
diff changeset
   707
*/
hgs
parents: 33
diff changeset
   708
bool FmUtils::hasEnoughSpace( const QString &targetDrive, qint64 size )
hgs
parents: 33
diff changeset
   709
{
hgs
parents: 33
diff changeset
   710
    RFs fsSession;
hgs
parents: 33
diff changeset
   711
    QT_TRAP_THROWING( fsSession.Connect() ); 
hgs
parents: 33
diff changeset
   712
    CleanupClosePushL( fsSession );
hgs
parents: 33
diff changeset
   713
    TInt dstDrv(0);
hgs
parents: 33
diff changeset
   714
    HBufC* hbuf = XQConversions::qStringToS60Desc( targetDrive );
hgs
parents: 33
diff changeset
   715
    QT_TRAP_THROWING( RFs::CharToDrive( hbuf->operator [](0), dstDrv ) );
hgs
parents: 33
diff changeset
   716
    bool ret = !SysUtil::DiskSpaceBelowCriticalLevelL( &fsSession,  size , dstDrv );
hgs
parents: 33
diff changeset
   717
    CleanupStack::PopAndDestroy(); // fsSession
hgs
parents: 33
diff changeset
   718
    return ret;
hgs
parents: 33
diff changeset
   719
    
hgs
parents: 33
diff changeset
   720
}
hgs
parents: 33
diff changeset
   721
hgs
parents: 33
diff changeset
   722
/*!
hgs
parents: 33
diff changeset
   723
    move one file insice the same drive, from \a source to \a target.
hgs
parents: 33
diff changeset
   724
    return KErrNone if successful, otherwise one of the other system-wide error codes.
hgs
parents: 33
diff changeset
   725
*/
hgs
parents: 33
diff changeset
   726
int FmUtils::moveInsideDrive( const QString &source, const QString &target )
hgs
parents: 33
diff changeset
   727
{
hgs
parents: 33
diff changeset
   728
    RFs fsSession;
hgs
parents: 33
diff changeset
   729
    QT_TRAP_THROWING( fsSession.Connect() ); 
hgs
parents: 33
diff changeset
   730
    CleanupClosePushL( fsSession );
hgs
parents: 33
diff changeset
   731
    HBufC* oldName = XQConversions::qStringToS60Desc( source );
hgs
parents: 33
diff changeset
   732
    HBufC* newName = XQConversions::qStringToS60Desc( target );
hgs
parents: 33
diff changeset
   733
    int ret = fsSession.Rename( *oldName, *newName );
hgs
parents: 33
diff changeset
   734
    CleanupStack::PopAndDestroy(); // fsSession
hgs
parents: 33
diff changeset
   735
    return ret;    
hgs
parents: 33
diff changeset
   736
}
hgs
parents: 33
diff changeset
   737
hgs
parents: 33
diff changeset
   738
/*!
hgs
parents: 33
diff changeset
   739
   Launch a file with associated application.
hgs
parents: 33
diff changeset
   740
*/
hgs
parents: 33
diff changeset
   741
int FmUtils::launchFile( const QString &filePath )
hgs
parents: 33
diff changeset
   742
hgs
parents: 33
diff changeset
   743
{
hgs
parents: 33
diff changeset
   744
    QFile file( filePath );
hgs
parents: 33
diff changeset
   745
    if( !file.exists() ) {
hgs
parents: 33
diff changeset
   746
        return false;
hgs
parents: 33
diff changeset
   747
    }
hgs
parents: 33
diff changeset
   748
        
hgs
parents: 33
diff changeset
   749
    XQApplicationManager mAiwMgr;
hgs
parents: 33
diff changeset
   750
    XQAiwRequest *request = mAiwMgr.create(file);
hgs
parents: 33
diff changeset
   751
    if ( request == 0 ) {
hgs
parents: 33
diff changeset
   752
        // No handlers for the URI
hgs
parents: 33
diff changeset
   753
        return FmErrUnKnown;
hgs
parents: 33
diff changeset
   754
    }
hgs
parents: 33
diff changeset
   755
    
hgs
parents: 33
diff changeset
   756
    // Set function parameters
hgs
parents: 33
diff changeset
   757
    QList<QVariant> args;
hgs
parents: 33
diff changeset
   758
    args << file.fileName();
hgs
parents: 33
diff changeset
   759
    request->setArguments(args);
hgs
parents: 33
diff changeset
   760
    
hgs
parents: 33
diff changeset
   761
    // Send the request
hgs
parents: 33
diff changeset
   762
    bool res = request->send();
hgs
parents: 33
diff changeset
   763
    if  (!res) 
hgs
parents: 33
diff changeset
   764
    {
hgs
parents: 33
diff changeset
   765
       // Request failed. 
hgs
parents: 33
diff changeset
   766
      int error = request->lastError();
hgs
parents: 33
diff changeset
   767
      
hgs
parents: 33
diff changeset
   768
      delete request;
hgs
parents: 33
diff changeset
   769
      return FmErrUnKnown;
hgs
parents: 33
diff changeset
   770
    }
hgs
parents: 33
diff changeset
   771
    
hgs
parents: 33
diff changeset
   772
    delete request;
hgs
parents: 33
diff changeset
   773
    return FmErrNone;
hgs
parents: 33
diff changeset
   774
}
hgs
parents: 33
diff changeset
   775
hgs
parents: 33
diff changeset
   776
/*!
hgs
parents: 33
diff changeset
   777
    return path for backup restore config file.
hgs
parents: 33
diff changeset
   778
    Currently \a appPath is not used.
hgs
parents: 33
diff changeset
   779
*/
hgs
parents: 33
diff changeset
   780
QString FmUtils::getBurConfigPath( QString appPath )
hgs
parents: 33
diff changeset
   781
{
hgs
parents: 33
diff changeset
   782
    Q_UNUSED( appPath );
hgs
parents: 33
diff changeset
   783
    QString path( BURCONFIGFILE );
hgs
parents: 33
diff changeset
   784
    return path;
hgs
parents: 33
diff changeset
   785
}
hgs
parents: 33
diff changeset
   786
hgs
parents: 33
diff changeset
   787
/*!
hgs
parents: 33
diff changeset
   788
    return MetaData string for \a filePath
hgs
parents: 33
diff changeset
   789
*/
hgs
parents: 33
diff changeset
   790
QString FmUtils::getFileType( const QString &filePath  )
hgs
parents: 33
diff changeset
   791
{
hgs
parents: 33
diff changeset
   792
    RApaLsSession apaSession;
hgs
parents: 33
diff changeset
   793
    TDataType dataType;
hgs
parents: 33
diff changeset
   794
    TUid appUid;
hgs
parents: 33
diff changeset
   795
    
hgs
parents: 33
diff changeset
   796
    TBuf<128> mimeTypeBuf;
hgs
parents: 33
diff changeset
   797
        
hgs
parents: 33
diff changeset
   798
    int err = apaSession.Connect();
hgs
parents: 33
diff changeset
   799
    
hgs
parents: 33
diff changeset
   800
    if ( err == KErrNone ){   
hgs
parents: 33
diff changeset
   801
        err = apaSession.AppForDocument( XQConversions::qStringToS60Desc( filePath )->Des(), 
hgs
parents: 33
diff changeset
   802
                                         appUid, dataType );
hgs
parents: 33
diff changeset
   803
        
hgs
parents: 33
diff changeset
   804
        if( err == KErrNone ){
hgs
parents: 33
diff changeset
   805
            mimeTypeBuf.Copy(dataType.Des8());
hgs
parents: 33
diff changeset
   806
        }  
hgs
parents: 33
diff changeset
   807
    }
hgs
parents: 33
diff changeset
   808
    
hgs
parents: 33
diff changeset
   809
    apaSession.Close();
hgs
parents: 33
diff changeset
   810
    return XQConversions::s60DescToQString( mimeTypeBuf );
hgs
parents: 33
diff changeset
   811
}
hgs
parents: 33
diff changeset
   812
hgs
parents: 33
diff changeset
   813
/*!
hgs
parents: 33
diff changeset
   814
    Check if drive \a driveName is drive C
hgs
parents: 33
diff changeset
   815
*/
hgs
parents: 33
diff changeset
   816
bool FmUtils::isDriveC( const QString &driveName )
hgs
parents: 33
diff changeset
   817
{
hgs
parents: 33
diff changeset
   818
    if( driveName.isEmpty() ) {
hgs
parents: 33
diff changeset
   819
        return false;
hgs
parents: 33
diff changeset
   820
    }
hgs
parents: 33
diff changeset
   821
    TInt drive = 0;
hgs
parents: 33
diff changeset
   822
    drive = driveName[0].toUpper().toAscii() - 'A' + EDriveA;
hgs
parents: 33
diff changeset
   823
    if( drive == EDriveC ){
hgs
parents: 33
diff changeset
   824
        return true;
hgs
parents: 33
diff changeset
   825
    }
hgs
parents: 33
diff changeset
   826
    else{
hgs
parents: 33
diff changeset
   827
        return false;
hgs
parents: 33
diff changeset
   828
    }
hgs
parents: 33
diff changeset
   829
   
hgs
parents: 33
diff changeset
   830
}
hgs
parents: 33
diff changeset
   831
hgs
parents: 33
diff changeset
   832
/*!
hgs
parents: 33
diff changeset
   833
    return max file name length
hgs
parents: 33
diff changeset
   834
*/
hgs
parents: 33
diff changeset
   835
int FmUtils::getMaxFileNameLength()
hgs
parents: 33
diff changeset
   836
{
hgs
parents: 33
diff changeset
   837
    return KMaxFileName;
hgs
parents: 33
diff changeset
   838
}
hgs
parents: 33
diff changeset
   839
hgs
parents: 33
diff changeset
   840
/*!
hgs
parents: 33
diff changeset
   841
    Check if length of \a path is exceed max path length. 
hgs
parents: 33
diff changeset
   842
*/
hgs
parents: 33
diff changeset
   843
bool FmUtils::checkMaxPathLength( const QString& path )
hgs
parents: 33
diff changeset
   844
{
hgs
parents: 33
diff changeset
   845
    if( path.length() > KMaxPath ) {
hgs
parents: 33
diff changeset
   846
        return false;
hgs
parents: 33
diff changeset
   847
    }
hgs
parents: 33
diff changeset
   848
    return true;
hgs
parents: 33
diff changeset
   849
}