--- a/filemanager/src/inc/fmutils_s60.cpp Wed Jun 23 18:03:11 2010 +0300
+++ b/filemanager/src/inc/fmutils_s60.cpp Tue Jul 06 14:06:28 2010 +0300
@@ -37,6 +37,8 @@
#include <QDir>
#include <QFile>
+#include <hbglobal.h>
+
#include <xqaiwrequest.h>
#include <xqappmgr.h>
@@ -46,10 +48,12 @@
QString FmUtils::getDriveNameFromPath( const QString &path )
{
- if( path.length() <3 ) {
+ // fillPathWithSplash make sure path length will be at least 3 if it is not empty.
+ QString checkedPath( fillPathWithSplash( path ) );
+ if( checkedPath.length() < 3 ) {
return QString();
}
- return path.left( 3 );
+ return checkedPath.left( 3 );
}
QString FmUtils::getDriveLetterFromPath( const QString &path )
@@ -62,6 +66,9 @@
FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName )
{
+ if( driverName.isEmpty() ) {
+ return FmDriverInfo( 0, 0, driverName, QString(), FmDriverInfo::EDriveNotPresent );
+ }
CCoeEnv *env = CCoeEnv::Static();
RFs& fs = env->FsSession();
@@ -207,6 +214,9 @@
int FmUtils::removeDrivePwd( const QString &driverName, const QString &Pwd )
{
+ if( driverName.isEmpty() ) {
+ return FmErrWrongParam;
+ }
QString logString = "Drive name:" + driverName;
FmLogger::log( logString );
logString = "Password:" + Pwd;
@@ -245,6 +255,9 @@
int FmUtils::unlockDrive( const QString &driverName, const QString &Pwd )
{
+ if( driverName.isEmpty() ) {
+ return FmErrWrongParam;
+ }
QString logString = "Drive name:" + driverName;
FmLogger::log( logString );
logString = "Password:" + Pwd;
@@ -287,6 +300,9 @@
int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd )
{
+ if( driverName.isEmpty() ) {
+ return FmErrWrongParam;
+ }
QString logString = "checkDrivePwd Drive name:" + driverName;
logString += " password:" + pwd;
FmLogger::log( logString );
@@ -296,6 +312,9 @@
int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd)
{
+ if( driverName.isEmpty() ) {
+ return FmErrWrongParam;
+ }
QString logString = "setDrivePwd Drive name:" + driverName ;
logString += " Old password:" + oldPwd;
logString += " New password:" + newPwd;
@@ -347,6 +366,9 @@
int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName)
{
+ if( driverName.isEmpty() ) {
+ return FmErrWrongParam;
+ }
foreach( const QChar &ch, newVolumeName )
{
bool a = ch.isSpace();
@@ -382,8 +404,11 @@
}
}
-void FmUtils::ejectDrive( const QString &driverName )
+int FmUtils::ejectDrive( const QString &driverName )
{
+ if( driverName.isEmpty() ) {
+ return FmErrWrongParam;
+ }
QString logString = "FmUtils::ejectDrive start";
FmLogger::log( logString );
@@ -398,6 +423,7 @@
KCoreAppUIsMmcRemovedWithoutEject,
ECoreAppUIsEjectCommandUsedToDrive | ( drive << KDriveShift )
);
+ return FmErrNone;
}
QString FmUtils::getFileType( const QString &filePath )
@@ -480,6 +506,9 @@
bool FmUtils::isDriveC( const QString &driverName )
{
+ if( driverName.isEmpty() ) {
+ return false;
+ }
TInt drive = 0;
drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
if( drive == EDriveC ){
@@ -503,6 +532,9 @@
void FmUtils::createDefaultFolders( const QString &driverName )
{
+ if( driverName.isEmpty() ) {
+ return;
+ }
int err;
TInt drive = 0;
@@ -600,9 +632,12 @@
return newFilePath;
}
-// used to filter drive which need be hide.
-bool FmUtils::checkDriveFilter( const QString &driveName )
+// filter un-accessable drive
+bool FmUtils::checkDriveAccessFilter( const QString &driveName )
{
+ if( driveName.isEmpty() ) {
+ return false;
+ }
FmDriverInfo driveInfo = queryDriverInfo( driveName );
if( ( driveInfo.driveState()& FmDriverInfo::EDriveRam ) ||
( driveInfo.driveState()& FmDriverInfo::EDriveRom ) ) {
@@ -646,39 +681,42 @@
}
-bool FmUtils::isPathAccessabel( const QString &path )
+int FmUtils::isPathAccessabel( const QString &path )
{
+ // Used to check if path is accessable, very important feature
+ // and will return filemanager error.
FmLogger::log( QString( "isPathAccessabel:" ) + path );
+ if( path.isEmpty() ) {
+ return FmErrPathNotExist;
+ }
if( path.length() <= 3 && !isDriveAvailable( path ) ) { //used to filter locked drive
FmLogger::log( QString( "isPathAccessabel false: path is drive and not available" ) );
- return false;
+ return FmErrDriveNotAvailable;
}
QFileInfo fileInfo( path );
if( fileInfo.absoluteFilePath().contains( Drive_C, Qt::CaseInsensitive ) &&
!fileInfo.absoluteFilePath().contains( Folder_C_Data, Qt::CaseInsensitive ) ) {
FmLogger::log( QString( "isPathAccessabel false: path contain C and not in data folder" ) );
- return false;
+ return FmErrPathDenied;
}
- if( fileInfo.absoluteFilePath().contains( Drive_D, Qt::CaseInsensitive ) ) {
- FmLogger::log( QString( "isPathAccessabel false: path contain D" ) );
- return false;
- }
- if( fileInfo.absoluteFilePath().contains( Drive_Z, Qt::CaseInsensitive ) ) {
- FmLogger::log( QString( "isPathAccessabel false: path contain Z" ) );
- return false;
+ if( !checkDriveAccessFilter( FmUtils::getDriveNameFromPath( fileInfo.absoluteFilePath() ) ) ){
+ return FmErrDriveDenied;
}
if( !fileInfo.exists() ) {
FmLogger::log( QString( "isPathAccessabel false: path not exist" ) );
- return false;
+ return FmErrPathNotExist;
}
- FmLogger::log( QString( "isPathAccessabel true" ) );
- return true;
+ FmLogger::log( QString( "isPathAccessabel FmErrNone" ) );
+ return FmErrNone;
}
// only used to check drive, when MMC is not inserted, also return false
bool FmUtils::isDriveAvailable( const QString &path )
{
FmLogger::log( QString( "isDriveAvailable:" ) + path );
+ if( path.isEmpty() ) {
+ return false;
+ }
FmDriverInfo::DriveState driveState = queryDriverInfo( path ).driveState();
if( ( driveState & FmDriverInfo::EDriveAvailable ) ) {
FmLogger::log( QString( "isDriveAvailable true" ) );
@@ -699,7 +737,7 @@
foreach( QFileInfo fileInfo, infoList ) {
QString driveName = fileInfo.absolutePath();
- if( checkDriveFilter( driveName ) ) {
+ if( checkDriveAccessFilter( driveName ) ) {
if( !isHideUnAvailableDrive ) {
driveList.append( driveName );
}
@@ -714,9 +752,12 @@
QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume )
{
QString ret;
+ if( driveName.isEmpty() ) {
+ return ret;
+ }
QString tempDriveName = fillPathWithSplash( driveName );
- ret = removePathSplash( driveName );
+ QString checkedDriveName( removePathSplash( driveName ) );
FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName );
QString volumeName = driverInfo.volumeName();
@@ -726,19 +767,27 @@
if( driveState & FmDriverInfo::EDriveAvailable ){
if( driveState & FmDriverInfo::EDriveRemovable ) {
if( driveState & FmDriverInfo::EDriveMassStorage ) {
- volumeName.append( QObject::tr( "Mass Storage" ) );
+ // Mass Storage
+ ret = hbTrId( "txt_fmgr_dblist_1_mass_storage" ).arg( checkedDriveName );
} else if( driveState & FmDriverInfo::EDriveUsbMemory ) {
- volumeName.append( QObject::tr( "Usb Memory" ) );
+ // USB Memory
+ ret = hbTrId( "txt_fmgr_dblist_1_usb_memory" ).arg( checkedDriveName );
} else{
- volumeName.append( QObject::tr( "Memory Card" ) );
+ // Memory Card
+ ret = hbTrId( "txt_fmgr_dblist_1_memory_card" ).arg( checkedDriveName );
}
} else{
- volumeName.append( QObject::tr( "Phone Memory" ) );
+ // phone memory
+ ret = hbTrId( "txt_fmgr_dblist_1_device_memory" ).arg( checkedDriveName );
}
- }
+ }
}
-
- ret += QString( " " ) + volumeName;
+
+ if( ret.isEmpty() ) {
+ // set ret as volumeName
+ // txt_fmgr_dblist_1_2 is not correct, can not use.
+ ret = hbTrId( "%1 %2" ).arg( checkedDriveName ).arg( volumeName );
+ }
return ret;
}
@@ -889,3 +938,20 @@
}
return true;
}
+
+bool FmUtils::checkNewFolderOrFile( const QString &path, QString &errString )
+{
+ QFileInfo fileInfo( path );
+ bool ret( true );
+ if (!FmUtils::checkFolderFileName( fileInfo.fileName() ) ) {
+ errString = hbTrId( "Invalid file or folder name!" );
+ ret = false;
+ } else if( !FmUtils::checkMaxPathLength( path ) ) {
+ errString = hbTrId( "the path you specified is too long!" );
+ ret = false;
+ } else if (fileInfo.exists()) {
+ errString = hbTrId( "%1 already exist!" ).arg( fileInfo.fileName() );
+ ret = false;
+ }
+ return ret;
+}