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