filemanager/src/inc/fmutils_s60.cpp
branchGCC_SURGE
changeset 31 e28107efca85
parent 30 6e96d2143d46
child 35 060d0b1ab845
equal deleted inserted replaced
22:b9588eb601eb 31:e28107efca85
    35 #include <QStringList>
    35 #include <QStringList>
    36 #include <QFileInfoList>
    36 #include <QFileInfoList>
    37 #include <QDir>
    37 #include <QDir>
    38 #include <QFile>
    38 #include <QFile>
    39 
    39 
       
    40 #include <hbglobal.h>
       
    41 
    40 #include <xqaiwrequest.h>
    42 #include <xqaiwrequest.h>
    41 #include <xqappmgr.h>
    43 #include <xqappmgr.h>
    42 
    44 
    43 #include <shareui.h>
    45 #include <shareui.h>
    44 
    46 
    45 #define BURCONFIGFILE  "z:/private/2002BCC0/burconfig.xml"
    47 #define BURCONFIGFILE  "z:/private/2002BCC0/burconfig.xml"
    46 
    48 
    47 QString FmUtils::getDriveNameFromPath( const QString &path )
    49 QString FmUtils::getDriveNameFromPath( const QString &path )
    48 {
    50 {
    49     if( path.length() <3 ) {
    51     // fillPathWithSplash make sure path length will be at least 3 if it is not empty.
       
    52     QString checkedPath( fillPathWithSplash( path ) );
       
    53     if( checkedPath.length() < 3 ) {
    50         return QString();
    54         return QString();
    51     }
    55     }
    52     return path.left( 3 );
    56     return checkedPath.left( 3 );
    53 }
    57 }
    54 
    58 
    55 QString FmUtils::getDriveLetterFromPath( const QString &path )
    59 QString FmUtils::getDriveLetterFromPath( const QString &path )
    56 {
    60 {
    57 	if( path.length() <2 ) {
    61 	if( path.length() <2 ) {
    60     return path.left( 1 );
    64     return path.left( 1 );
    61 }
    65 }
    62 
    66 
    63 FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName )
    67 FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName )
    64 {
    68 {
       
    69     if( driverName.isEmpty() ) {
       
    70         return FmDriverInfo( 0, 0, driverName, QString(), FmDriverInfo::EDriveNotPresent );
       
    71     }
    65     CCoeEnv *env = CCoeEnv::Static();
    72     CCoeEnv *env = CCoeEnv::Static();
    66     RFs& fs = env->FsSession();
    73     RFs& fs = env->FsSession();
    67 
    74 
    68     TVolumeInfo volumeInfo;
    75     TVolumeInfo volumeInfo;
    69     TInt drive = 0;
    76     TInt drive = 0;
   205 	}
   212 	}
   206 }
   213 }
   207 
   214 
   208 int FmUtils::removeDrivePwd( const QString &driverName,  const QString &Pwd )
   215 int FmUtils::removeDrivePwd( const QString &driverName,  const QString &Pwd )
   209 {
   216 {
       
   217     if( driverName.isEmpty() ) {
       
   218         return FmErrWrongParam;
       
   219     }
   210     QString logString = "Drive name:" + driverName;
   220     QString logString = "Drive name:" + driverName;
   211     FmLogger::log( logString );
   221     FmLogger::log( logString );
   212     logString = "Password:" + Pwd;
   222     logString = "Password:" + Pwd;
   213     FmLogger::log( logString );
   223     FmLogger::log( logString );
   214 
   224 
   243     }
   253     }
   244 }
   254 }
   245 
   255 
   246 int FmUtils::unlockDrive( const QString &driverName,  const QString &Pwd )
   256 int FmUtils::unlockDrive( const QString &driverName,  const QString &Pwd )
   247 {
   257 {
       
   258     if( driverName.isEmpty() ) {
       
   259         return FmErrWrongParam;
       
   260     }
   248     QString logString = "Drive name:" + driverName;
   261     QString logString = "Drive name:" + driverName;
   249     FmLogger::log( logString );
   262     FmLogger::log( logString );
   250     logString = "Password:" + Pwd;
   263     logString = "Password:" + Pwd;
   251     FmLogger::log( logString );
   264     FmLogger::log( logString );
   252 
   265 
   285     }
   298     }
   286 }
   299 }
   287 
   300 
   288 int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd )
   301 int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd )
   289 {
   302 {
       
   303     if( driverName.isEmpty() ) {
       
   304         return FmErrWrongParam;
       
   305     }
   290     QString logString = "checkDrivePwd Drive name:" + driverName;
   306     QString logString = "checkDrivePwd Drive name:" + driverName;
   291     logString += " password:" + pwd;
   307     logString += " password:" + pwd;
   292     FmLogger::log( logString );
   308     FmLogger::log( logString );
   293 
   309 
   294     return setDrivePwd( driverName, pwd, pwd );
   310     return setDrivePwd( driverName, pwd, pwd );
   295 }
   311 }
   296 
   312 
   297 int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd)
   313 int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd)
   298 {
   314 {
       
   315     if( driverName.isEmpty() ) {
       
   316         return FmErrWrongParam;
       
   317     }
   299     QString logString = "setDrivePwd Drive name:" + driverName ;
   318     QString logString = "setDrivePwd Drive name:" + driverName ;
   300     logString += " Old password:" + oldPwd;
   319     logString += " Old password:" + oldPwd;
   301     logString += " New password:" + newPwd;
   320     logString += " New password:" + newPwd;
   302     FmLogger::log( logString );
   321     FmLogger::log( logString );
   303 
   322 
   345     pwd = XQConversions::s60DescToQString( des );
   364     pwd = XQConversions::s60DescToQString( des );
   346 }
   365 }
   347 
   366 
   348 int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName)
   367 int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName)
   349 {
   368 {
       
   369     if( driverName.isEmpty() ) {
       
   370         return FmErrWrongParam;
       
   371     }
   350     foreach( const QChar &ch, newVolumeName )
   372     foreach( const QChar &ch, newVolumeName )
   351     {
   373     {
   352         bool a = ch.isSpace();
   374         bool a = ch.isSpace();
   353         bool b = ch.isLetterOrNumber();
   375         bool b = ch.isLetterOrNumber();
   354         // If not alphadigit or space, return error
   376         // If not alphadigit or space, return error
   380     else{
   402     else{
   381         return FmErrUnKnown;
   403         return FmErrUnKnown;
   382     }
   404     }
   383 }
   405 }
   384 
   406 
   385 void FmUtils::ejectDrive( const QString &driverName )
   407 int FmUtils::ejectDrive( const QString &driverName )
   386 {
   408 {
       
   409     if( driverName.isEmpty() ) {
       
   410         return FmErrWrongParam;
       
   411     }
   387     QString logString = "FmUtils::ejectDrive start";
   412     QString logString = "FmUtils::ejectDrive start";
   388     FmLogger::log( logString );
   413     FmLogger::log( logString );
   389 
   414 
   390     TInt drive = 0;
   415     TInt drive = 0;
   391 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   416 	drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   396     RProperty::Set(
   421     RProperty::Set(
   397         KPSUidCoreApplicationUIs,
   422         KPSUidCoreApplicationUIs,
   398         KCoreAppUIsMmcRemovedWithoutEject,
   423         KCoreAppUIsMmcRemovedWithoutEject,
   399         ECoreAppUIsEjectCommandUsedToDrive | ( drive << KDriveShift )
   424         ECoreAppUIsEjectCommandUsedToDrive | ( drive << KDriveShift )
   400         );
   425         );
       
   426     return FmErrNone;
   401 }
   427 }
   402 
   428 
   403 QString FmUtils::getFileType( const QString &filePath  )
   429 QString FmUtils::getFileType( const QString &filePath  )
   404 {
   430 {
   405     RApaLsSession apaSession;
   431     RApaLsSession apaSession;
   478     return size;  
   504     return size;  
   479 }
   505 }
   480 
   506 
   481 bool FmUtils::isDriveC( const QString &driverName )
   507 bool FmUtils::isDriveC( const QString &driverName )
   482 {
   508 {
       
   509     if( driverName.isEmpty() ) {
       
   510         return false;
       
   511     }
   483     TInt drive = 0;
   512     TInt drive = 0;
   484     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   513     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   485     if( drive == EDriveC ){
   514     if( drive == EDriveC ){
   486         return true;
   515         return true;
   487     }
   516     }
   501    return ret;   
   530    return ret;   
   502 }
   531 }
   503 
   532 
   504 void FmUtils::createDefaultFolders( const QString &driverName )
   533 void FmUtils::createDefaultFolders( const QString &driverName )
   505 {
   534 {
       
   535     if( driverName.isEmpty() ) {
       
   536         return;
       
   537     }
   506     int err;
   538     int err;
   507     
   539     
   508     TInt drive = 0;
   540     TInt drive = 0;
   509     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   541     drive = driverName[0].toUpper().toAscii() - 'A' + EDriveA;
   510     
   542     
   569     CleanupStack::PopAndDestroy( array );
   601     CleanupStack::PopAndDestroy( array );
   570 }
   602 }
   571 
   603 
   572 QString FmUtils::fillPathWithSplash( const QString &filePath )
   604 QString FmUtils::fillPathWithSplash( const QString &filePath )
   573 {
   605 {
   574     QString newFilePath( filePath );
   606 	QString newFilePath;
   575     if( filePath.isEmpty() ) {
   607     if( filePath.isEmpty() ) {
   576         return newFilePath;
   608         return newFilePath;
   577     }
   609     }
   578 
   610 
   579     if( filePath.at( filePath.length()-1 ) != QChar( '/' ) ){
   611     foreach( QChar ch, filePath ) {
   580         newFilePath.append( QChar( '/' ) );
   612         if( ch == QChar('\\') || ch == QChar('/') ) {
   581     }
   613 			newFilePath.append( QDir::separator() );
       
   614         } else {
       
   615             newFilePath.append( ch );
       
   616         }
       
   617     }
       
   618     
       
   619     if( newFilePath.right( 1 )!= QDir::separator() ){
       
   620         newFilePath.append( QDir::separator() );
       
   621     }
       
   622     
   582     return newFilePath;
   623     return newFilePath;
   583 }
   624 }
   584 
   625 
   585 QString FmUtils::removePathSplash( const QString &filePath )
   626 QString FmUtils::removePathSplash( const QString &filePath )
   586 {
   627 {
   589         newFilePath = filePath.left( filePath.length() - 1 );
   630         newFilePath = filePath.left( filePath.length() - 1 );
   590     }
   631     }
   591     return newFilePath;
   632     return newFilePath;
   592 }
   633 }
   593 
   634 
   594 // used to filter drive which need be hide.
   635 // filter un-accessable drive
   595 bool FmUtils::checkDriveFilter( const QString &driveName )
   636 bool FmUtils::checkDriveAccessFilter( const QString &driveName )
   596 {
   637 {
   597     if( driveName.contains( "D:" ) || driveName.contains( "Z:" ) ) {
   638     if( driveName.isEmpty() ) {
       
   639         return false;
       
   640     }
       
   641     FmDriverInfo driveInfo = queryDriverInfo( driveName );
       
   642     if( ( driveInfo.driveState()& FmDriverInfo::EDriveRam ) ||
       
   643         ( driveInfo.driveState()& FmDriverInfo::EDriveRom ) ) {
   598         return false;
   644         return false;
   599     }
   645     }
   600     return true;
   646     return true;
   601 }
   647 }
   602 
   648 
   607     if( !fileInfo.exists() ) {
   653     if( !fileInfo.exists() ) {
   608             return QString();
   654             return QString();
   609         }
   655         }
   610     */
   656     */
   611     QString checkedPath = fillPathWithSplash( path );
   657     QString checkedPath = fillPathWithSplash( path );
   612     if( checkedPath.compare( QString( "C:/"), Qt::CaseInsensitive ) == 0 ) {
   658     if( checkedPath.compare( Drive_C, Qt::CaseInsensitive ) == 0 ) {
   613         checkedPath += QString( "data/" );
   659         checkedPath += QString( "data" ) + QDir::separator();
   614         return checkedPath;
   660         return checkedPath;
   615     }
   661     }
   616     return path;
   662     return path;
   617 
   663 
   618 }
   664 }
   625     QString checkedPath = fillPathWithSplash( path );
   671     QString checkedPath = fillPathWithSplash( path );
   626 
   672 
   627     logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath;
   673     logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath;
   628     FmLogger::log( logString );
   674     FmLogger::log( logString );
   629     
   675     
   630     if( checkedPath.compare( QString( "C:/data/"), Qt::CaseInsensitive ) == 0 ) {
   676     if( checkedPath.compare( Folder_C_Data, Qt::CaseInsensitive ) == 0 ) {
   631         FmLogger::log( QString( " change from c:/data/ to C:/" ) );
   677         FmLogger::log( QString( " change from c:/data/ to C:/" ) );
   632         return QString( "C:/" );
   678         return Drive_C;
   633     }
   679     }
   634     return path;
   680     return path;
   635 
   681 
   636 }
   682 }
   637 
   683 
   638 bool FmUtils::isPathAccessabel( const QString &path )
   684 int FmUtils::isPathAccessabel( const QString &path )
   639 {
   685 {
       
   686     // Used to check if path is accessable, very important feature
       
   687 	// and will return filemanager error.
   640     FmLogger::log( QString( "isPathAccessabel:" ) + path );
   688     FmLogger::log( QString( "isPathAccessabel:" ) + path );
       
   689     if( path.isEmpty() ) {
       
   690         return FmErrPathNotExist;
       
   691     }
   641     if( path.length() <= 3 && !isDriveAvailable( path ) ) { //used to filter locked drive
   692     if( path.length() <= 3 && !isDriveAvailable( path ) ) { //used to filter locked drive
   642         FmLogger::log( QString( "isPathAccessabel false: path is drive and not available" ) );
   693         FmLogger::log( QString( "isPathAccessabel false: path is drive and not available" ) );
   643         return false;
   694         return FmErrDriveNotAvailable;
   644     }
   695     }
   645     QFileInfo fileInfo( path );
   696     QFileInfo fileInfo( path );
   646     if( fileInfo.absoluteFilePath().contains( QString( Drive_C ), Qt::CaseInsensitive ) &&
   697     if( fileInfo.absoluteFilePath().contains( Drive_C, Qt::CaseInsensitive ) &&
   647         !fileInfo.absoluteFilePath().contains( QString( Folder_C_Data ), Qt::CaseInsensitive ) ) {
   698         !fileInfo.absoluteFilePath().contains( Folder_C_Data, Qt::CaseInsensitive ) ) {
   648         FmLogger::log( QString( "isPathAccessabel false: path contain C and not in data folder" ) );
   699         FmLogger::log( QString( "isPathAccessabel false: path contain C and not in data folder" ) );
   649         return false;
   700         return FmErrPathDenied;
   650     }
   701     }
   651     if( fileInfo.absoluteFilePath().contains( QString( Drive_D ), Qt::CaseInsensitive ) ) {
   702     if( !checkDriveAccessFilter( FmUtils::getDriveNameFromPath( fileInfo.absoluteFilePath() ) ) ){
   652         FmLogger::log( QString( "isPathAccessabel false: path contain D" ) );
   703         return FmErrDriveDenied;
   653         return false;
       
   654     }
       
   655     if( fileInfo.absoluteFilePath().contains( QString( Drive_Z ), Qt::CaseInsensitive ) ) {
       
   656         FmLogger::log( QString( "isPathAccessabel false: path contain Z" ) );
       
   657         return false;
       
   658     }
   704     }
   659     if( !fileInfo.exists() ) {
   705     if( !fileInfo.exists() ) {
   660         FmLogger::log( QString( "isPathAccessabel false: path not exist" ) );
   706         FmLogger::log( QString( "isPathAccessabel false: path not exist" ) );
   661         return false;
   707         return FmErrPathNotExist;
   662     }
   708     }
   663     FmLogger::log( QString( "isPathAccessabel true" ) );
   709     FmLogger::log( QString( "isPathAccessabel FmErrNone" ) );
   664     return true;
   710     return FmErrNone;
   665 }
   711 }
   666 
   712 
   667 // only used to check drive, when MMC is not inserted, also return false
   713 // only used to check drive, when MMC is not inserted, also return false
   668 bool FmUtils::isDriveAvailable( const QString &path )
   714 bool FmUtils::isDriveAvailable( const QString &path )
   669 {
   715 {
   670     FmLogger::log( QString( "isDriveAvailable:" ) + path );
   716     FmLogger::log( QString( "isDriveAvailable:" ) + path );
       
   717     if( path.isEmpty() ) {
       
   718         return false;
       
   719     }
   671     FmDriverInfo::DriveState driveState = queryDriverInfo( path ).driveState();
   720     FmDriverInfo::DriveState driveState = queryDriverInfo( path ).driveState();
   672     if( ( driveState & FmDriverInfo::EDriveAvailable ) ) {
   721     if( ( driveState & FmDriverInfo::EDriveAvailable ) ) {
   673         FmLogger::log( QString( "isDriveAvailable true" ) );
   722         FmLogger::log( QString( "isDriveAvailable true" ) );
   674         return true;
   723         return true;
   675     }
   724     }
   686     }
   735     }
   687     QFileInfoList infoList = QDir::drives();
   736     QFileInfoList infoList = QDir::drives();
   688 
   737 
   689     foreach( QFileInfo fileInfo, infoList ) {
   738     foreach( QFileInfo fileInfo, infoList ) {
   690         QString driveName = fileInfo.absolutePath();
   739         QString driveName = fileInfo.absolutePath();
   691         if( checkDriveFilter( driveName ) ) {
   740         if( checkDriveAccessFilter( driveName ) ) {
   692             if( !isHideUnAvailableDrive ) {
   741             if( !isHideUnAvailableDrive ) {
   693                 driveList.append( driveName );
   742                 driveList.append( driveName );
   694             }
   743             }
   695             else if ( isDriveAvailable( driveName ) ) {
   744             else if ( isDriveAvailable( driveName ) ) {
   696                 driveList.append( driveName );
   745                 driveList.append( driveName );
   701 }
   750 }
   702 
   751 
   703 QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume )
   752 QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume )
   704 {
   753 {
   705     QString ret;
   754     QString ret;
       
   755     if( driveName.isEmpty() ) {
       
   756         return ret;
       
   757     }
   706     QString tempDriveName = fillPathWithSplash( driveName );
   758     QString tempDriveName = fillPathWithSplash( driveName );
   707 
   759 
   708     ret = removePathSplash( driveName );
   760     QString checkedDriveName( removePathSplash( driveName ) );
   709     
   761     
   710     FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName );
   762     FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName );
   711     QString volumeName = driverInfo.volumeName();
   763     QString volumeName = driverInfo.volumeName();
   712 
   764 
   713     if( volumeName.isEmpty() && isFillWithDefaultVolume ){
   765     if( volumeName.isEmpty() && isFillWithDefaultVolume ){
   714     FmDriverInfo::DriveState driveState = queryDriverInfo( tempDriveName ).driveState();
   766     FmDriverInfo::DriveState driveState = queryDriverInfo( tempDriveName ).driveState();
   715         if( driveState & FmDriverInfo::EDriveAvailable ){
   767         if( driveState & FmDriverInfo::EDriveAvailable ){
   716             if( driveState & FmDriverInfo::EDriveRemovable ) {
   768             if( driveState & FmDriverInfo::EDriveRemovable ) {
   717                 if( driveState & FmDriverInfo::EDriveMassStorage ) {
   769                 if( driveState & FmDriverInfo::EDriveMassStorage ) {
   718                     volumeName.append( QObject::tr( "Mass Storage" ) );  
   770                     // Mass Storage
       
   771                     ret = hbTrId( "txt_fmgr_dblist_1_mass_storage" ).arg( checkedDriveName );  
   719                 } else if( driveState & FmDriverInfo::EDriveUsbMemory ) {
   772                 } else if( driveState & FmDriverInfo::EDriveUsbMemory ) {
   720                     volumeName.append( QObject::tr( "Usb Memory" ) );
   773                     // USB Memory
       
   774                     ret = hbTrId( "txt_fmgr_dblist_1_usb_memory" ).arg( checkedDriveName );
   721                 } else{
   775                 } else{
   722                     volumeName.append( QObject::tr( "Memory Card" ) );
   776                     // Memory Card
       
   777                     ret = hbTrId( "txt_fmgr_dblist_1_memory_card" ).arg( checkedDriveName );
   723                 }
   778                 }
   724             } else{
   779             } else{
   725                 volumeName.append( QObject::tr( "Phone Memory" ) );
   780                 // phone memory
   726             }
   781                 ret = hbTrId( "txt_fmgr_dblist_1_device_memory" ).arg( checkedDriveName );
   727         }
   782             }
   728     }
   783         }  
   729 
   784     }
   730     ret += QString( " " ) + volumeName;
   785     
       
   786     if( ret.isEmpty() ) {
       
   787         // set ret as volumeName
       
   788         // txt_fmgr_dblist_1_2 is not correct, can not use.
       
   789         ret = hbTrId( "%1 %2" ).arg( checkedDriveName ).arg( volumeName );
       
   790     }
   731     return ret;
   791     return ret;
   732 }
   792 }
   733 
   793 
   734 int FmUtils::launchFile( const QString &filePath )
   794 int FmUtils::launchFile( const QString &filePath )
   735 {
   795 {
   736     QFile file( filePath );
   796     QFile file( filePath );
       
   797     if( !file.exists() ) {
       
   798         return false;
       
   799     }
       
   800         
   737     XQApplicationManager mAiwMgr;
   801     XQApplicationManager mAiwMgr;
   738     XQAiwRequest *request = mAiwMgr.create(file);
   802     XQAiwRequest *request = mAiwMgr.create(file);
   739     if ( request == 0 ) {
   803     if ( request == 0 ) {
   740         // No handlers for the URI
   804         // No handlers for the URI
   741         return FmErrUnKnown;
   805         return FmErrUnKnown;
   824     return QString();
   888     return QString();
   825 }
   889 }
   826 
   890 
   827 QString FmUtils::formatPath( const QString &path  )
   891 QString FmUtils::formatPath( const QString &path  )
   828 {
   892 {
   829     QString formatPath = path;
   893     QString formatPath;
   830     QRegExp regExp( "/" );
   894 	foreach( QChar ch, path ) {
   831     formatPath.replace( regExp, "\\" );
   895 		if( ch == QChar('\\') || ch == QChar('/') ) {
   832     
   896 			formatPath.append( QDir::separator() );
   833     if( path.right( 1 )!= "\\"){
   897 		} else {
   834         formatPath.append( "\\" );
   898 			formatPath.append( ch );
       
   899 		}
       
   900     }
       
   901 
       
   902     if( formatPath.right( 1 ) != QDir::separator() ){
       
   903         formatPath.append( QDir::separator() );
   835     }
   904     }
   836     return formatPath;
   905     return formatPath;
   837 }
   906 }
   838 
   907 
   839 int FmUtils::getMaxFileNameLength()
   908 int FmUtils::getMaxFileNameLength()
   840     {
   909 {
   841     return KMaxFileName;
   910     return KMaxFileName;
   842     }
   911 }
   843 
   912 
   844 bool FmUtils::checkMaxPathLength( const QString& path )
   913 bool FmUtils::checkMaxPathLength( const QString& path )
   845     {
   914 {
   846     if( path.length() > KMaxPath ) {
   915     if( path.length() > KMaxPath ) {
   847         return false;
   916         return false;
   848     }
   917     }
   849     return true;
   918     return true;
   850     }
   919 }
   851 bool FmUtils::checkFolderFileName( const QString& name )
   920 bool FmUtils::checkFolderFileName( const QString& name )
   852 {
   921 {
   853     if( name.endsWith( QChar('.'),  Qt::CaseInsensitive ) ) {
   922     if( name.endsWith( QChar('.'),  Qt::CaseInsensitive ) ) {
   854         return false;
   923         return false;
   855     }
   924     }
   867     if( name.length() > KMaxFileName ) {
   936     if( name.length() > KMaxFileName ) {
   868         return false;
   937         return false;
   869     }
   938     }
   870     return true;
   939     return true;
   871 }
   940 }
       
   941 
       
   942 bool FmUtils::checkNewFolderOrFile( const QString &path, QString &errString )
       
   943 {
       
   944     QFileInfo fileInfo( path );
       
   945     bool ret( true );   
       
   946     if (!FmUtils::checkFolderFileName( fileInfo.fileName() ) ) {
       
   947         errString = hbTrId( "Invalid file or folder name!" );
       
   948         ret = false;
       
   949     } else if( !FmUtils::checkMaxPathLength( path ) ) {
       
   950         errString = hbTrId( "the path you specified is too long!" );
       
   951         ret = false;
       
   952     } else if (fileInfo.exists()) {
       
   953         errString = hbTrId( "%1 already exist!" ).arg( fileInfo.fileName() );
       
   954         ret = false;
       
   955     }
       
   956     return ret;
       
   957 }