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 ) { |
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 |
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 { |
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 } |