--- a/filemanager/src/inc/fmutils_win.cpp Mon May 03 12:24:39 2010 +0300
+++ b/filemanager/src/inc/fmutils_win.cpp Tue Aug 24 10:24:14 2010 +0800
@@ -16,50 +16,39 @@
* The source file of the file manager utilities on windows
*/
+#include "fmutils.h"
+
#include <windows.h>
-#include "fmutils.h"
#include <QDir>
+#include <QUrl>
+#include <QVariant>
#include <QFileInfo>
#include <QDesktopServices>
-#include <QUrl>
-#include <QVariant>
+
+#include <hbglobal.h>
#define BURCONFIGFILE "burconfig.xml"
-
-QString FmUtils::getDriveNameFromPath( const QString &path )
-{
- if( path.length() <3 ) {
- return QString();
- }
- return path.left( 3 );
-}
+const int KMaxFileName=0x100;
+const int KMaxPath=0x100;
-QString FmUtils::getDriveLetterFromPath( const QString &path )
-{
- if( path.length() <3 ) {
- return QString();
- }
- return path.left( 1 );
-}
-
-FmDriverInfo FmUtils::queryDriverInfo( const QString &driverName )
+FmDriverInfo FmUtils::queryDriverInfo( const QString &driveName )
{
quint64 size = 0;
quint64 freeSize = 0;
- QString driver = driverName;
+ QString drive = driveName;
- driver.replace( '/', "\\" );
- if ( driver.right(1) != "\\" ) {
- driver.append( "\\" );
+ drive.replace( '/', "\\" );
+ if ( drive.right(1) != "\\" ) {
+ drive.append( "\\" );
}
- GetDiskFreeSpaceEx( (LPCWSTR)driver.constData(),
+ GetDiskFreeSpaceEx( (LPCWSTR)drive.constData(),
(PULARGE_INTEGER)&freeSize,
(PULARGE_INTEGER)&size,
0 );
TCHAR volumeName[MAX_PATH + 1] = { 0 };
- GetVolumeInformation( (LPCWSTR)driver.constData(),
+ GetVolumeInformation( (LPCWSTR)drive.constData(),
&volumeName[0],
MAX_PATH + 1,
0,
@@ -69,71 +58,42 @@
0 );
quint32 state( 0 );
- quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() );
- if ( drvStatus == DRIVE_REMOVABLE ) {
- state |= FmDriverInfo::EDriveRemovable;
- }
- return FmDriverInfo( size, freeSize, driverName, QString::fromWCharArray( &volumeName[0] ), state );
-}
-
-QString FmUtils::formatStorageSize( quint64 size )
-{
- if ( size < 1000 ) {
- return QString::number( size ) + " B";
- } else if ( size < 1000 * 1000 ) {
- return QString::number( size / 1024.0, 'f', 2 ) + " KB";
- } else if ( size < 1000 * 1000 * 1000 ) {
- return QString::number( size / (1024.0 * 1024.0), 'f', 1 ) + " MB";
- } else {
- return QString::number( size / ( 1024.0 * 1024.0 * 1024.0 ), 'f', 1 ) + " GB";
- }
-}
-/*
-quint32 FmUtils::getDriverState( const QString &driverName )
-{
- quint32 state( 0 );
-
- QString driver = driverName;
-
- driver.replace( '/', "\\" );
- if ( driver.right(1) != "\\" ) {
- driver.append( "\\" );
- }
-
- quint32 drvStatus = GetDriveType( (LPCWSTR)driver.constData() );
-
+ quint32 drvStatus = GetDriveType( (LPCWSTR)drive.constData() );
if ( drvStatus == DRIVE_REMOVABLE ) {
state |= FmDriverInfo::EDriveRemovable;
}
- return state;
-
+ if( !(state&FmDriverInfo::EDriveNotPresent) && !(state&FmDriverInfo::EDriveLocked) &&
+ !(state&FmDriverInfo::EDriveCorrupted) ) {
+ state |= FmDriverInfo::EDriveAvailable;
+ }
+ return FmDriverInfo( size, freeSize, driveName, QString::fromWCharArray( &volumeName[0] ), state );
}
-*/
-int FmUtils::removeDrivePwd( const QString &driverName, const QString &Pwd )
+
+int FmUtils::removeDrivePwd( const QString &driveName, const QString &Pwd )
{
- Q_UNUSED( driverName );
+ Q_UNUSED( driveName );
Q_UNUSED( Pwd );
return 0;
}
-int FmUtils::unlockDrive( const QString &driverName, const QString &Pwd )
+int FmUtils::unlockDrive( const QString &driveName, const QString &Pwd )
{
- Q_UNUSED( driverName );
+ Q_UNUSED( driveName );
Q_UNUSED( Pwd );
return 0;
}
-int FmUtils::checkDrivePwd( const QString &driverName, const QString &pwd)
+int FmUtils::checkDrivePwd( const QString &driveName, const QString &pwd)
{
- Q_UNUSED( driverName );
+ Q_UNUSED( driveName );
Q_UNUSED( pwd );
return 0;
}
-int FmUtils::setDrivePwd( const QString &driverName, const QString &oldPwd, const QString &newPwd)
+int FmUtils::setDrivePwd( const QString &driveName, const QString &oldPwd, const QString &newPwd)
{
- Q_UNUSED( driverName );
+ Q_UNUSED( driveName );
Q_UNUSED( oldPwd );
Q_UNUSED( newPwd );
return 0;
@@ -144,10 +104,10 @@
Q_UNUSED( pwd );
}
-int FmUtils::renameDrive( const QString &driverName, const QString &newVolumeName)
+int FmUtils::renameDrive( const QString &driveName, const QString &newVolumeName)
{
- Q_UNUSED( driverName );
- foreach( QChar ch, newVolumeName )
+ Q_UNUSED( driveName );
+ foreach( const QChar &ch, newVolumeName )
{
// If not alphadigit or space, return error
if( !ch.isLetterOrNumber() && !ch.isSpace() )
@@ -158,201 +118,85 @@
return 0;
}
-void FmUtils::ejectDrive( const QString &driverName )
-{
- Q_UNUSED( driverName );
-}
-
-QString FmUtils::getFileType( const QString &filePath )
-{
- Q_UNUSED( filePath );
- return QString( "" );
-}
-
-quint64 FmUtils::getDriveDetailsResult( const QString &folderPath, const QString &extension )
+int FmUtils::ejectDrive( const QString &driveName )
{
- Q_UNUSED( folderPath );
- Q_UNUSED( extension );
- return 0;
-}
-
-bool FmUtils::isDriveC( const QString &driverName )
-{
- Q_UNUSED( driverName );
- return false;
-}
-
-bool FmUtils::isDrive( const QString &path )
-{
- bool ret( false );
- if( path.length() <= 3 && path.length() >=2 ) {
- ret = true;
- }
-
- return ret;
+ Q_UNUSED( driveName );
+ return FmErrNone;
}
-void FmUtils::createDefaultFolders( const QString &driverName )
-{
- Q_UNUSED( driverName );
-}
-
-QString FmUtils::fillPathWithSplash( const QString &filePath )
+bool FmUtils::checkDriveAccessFilter( const QString &driveName )
{
- QString newFilePath( filePath );
- if( filePath.isEmpty() ) {
- return newFilePath;
- }
-
- if( filePath.at( filePath.length()-1 ) != QChar( '/' ) ){
- newFilePath.append( QChar( '/' ) );
- }
- return newFilePath;
-}
-
-QString FmUtils::removePathSplash( const QString &filePath )
-{
- QString newFilePath( filePath );
- if( filePath.right( 1 ) == QChar( '/' ) || filePath.right(1) == QString( "\\" ) ) {
- newFilePath = filePath.left( filePath.length() - 1 );
- }
- return newFilePath;
-}
-
-bool FmUtils::checkDriveFilter( const QString &driveName )
-{
-#ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_
- if( driveName.contains( "D:" ) || driveName.contains( "Z:" ) ) {
- return false;
- }
-#endif
+ Q_UNUSED( driveName );
return true;
}
QString FmUtils::checkDriveToFolderFilter( const QString &path )
{
- QFileInfo fileInfo( path );
- if( !fileInfo.exists() ) {
- return QString();
- }
-
-#ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_
- QString checkedPath = fillPathWithSplash( path );
- if( checkedPath.compare( QString( "C:/"), Qt::CaseInsensitive ) == 0 ) {
- checkedPath += QString( "data/" );
- QFileInfo fileInfo( checkedPath );
- if( !fileInfo.exists() ) {
- return QString();
- }
- return checkedPath;
- }
-#endif
+ Q_UNUSED( path );
return path;
}
QString FmUtils::checkFolderToDriveFilter( const QString &path )
{
-#ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_
- QString logString;
- logString = QString( "checkFolderToDriveFilter: " ) + path;
- FmLogger::log( logString );
- QString checkedPath = fillPathWithSplash( path );
-
- logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath;
- FmLogger::log( logString );
-
- if( checkedPath.compare( QString( "C:/data/"), Qt::CaseInsensitive ) == 0 ) {
- FmLogger::log( QString( " change from c:/data/ to C:/" ) );
- return QString( "C:/" );
- }
-#endif
+ Q_UNUSED( path );
return path;
}
-bool FmUtils::isPathAccessabel( const QString &path )
+int FmUtils::isPathAccessabel( const QString &path )
{
-#ifdef _DEBUG_DISABLE_DRIVE_D_TEST_DRIVEHIDE_
- if(path.contains("D:"))
- return false;
-#endif
- QFileInfo fileInfo( path );
-
-#ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_
- if( fileInfo.absoluteFilePath().contains( QString( Drive_C ), Qt::CaseInsensitive ) &&
- !fileInfo.absoluteFilePath().contains( QString( Folder_C_Data ), Qt::CaseInsensitive ) ) {
- return false;
- }
- if( fileInfo.absoluteFilePath().contains( QString( Drive_D ), Qt::CaseInsensitive ) ) {
- return false;
- }
- if( fileInfo.absoluteFilePath().contains( QString( Drive_Z ), Qt::CaseInsensitive ) ) {
- return false;
- }
-#endif
- if( !fileInfo.exists() ) {
- return false;
- }
- return true;
+ Q_UNUSED( path );
+ return FmErrNone;
}
bool FmUtils::isDriveAvailable( const QString &path )
{
- QFileInfo fileInfo( path );
- if( !fileInfo.exists() ) {
- return false;
- }
+ Q_UNUSED( path );
+ return true;
+}
+
+bool FmUtils::isDefaultFolder( const QString &folderPath )
+{
+ Q_UNUSED( folderPath );
+ return false;
+}
+
+void FmUtils::createDefaultFolders( const QString &driveName )
+{
+ Q_UNUSED( driveName );
+}
+
+/*!
+ set the \a desFile attributes as the same with \a srcFile
+*/
+int FmUtils::setFileAttributes( const QString &srcFile, const QString &desFile )
+{
+ Q_UNUSED( srcFile );
+ Q_UNUSED( desFile );
+ return FmErrNone;
+}
+
+/*!
+ judge whether there is enough space on \a targetDrive for \a size.
+ return true if has, false if not.
+*/
+bool FmUtils::hasEnoughSpace( const QString &targetDrive, qint64 size )
+{
+ Q_UNUSED( targetDrive );
+ Q_UNUSED( size );
return true;
}
-void FmUtils::getDriveList( QStringList &driveList, bool isHideUnAvailableDrive )
-{
- QFileInfoList infoList = QDir::drives();
-
- foreach( QFileInfo fileInfo, infoList ) {
- QString driveName = fileInfo.absolutePath();
- if( checkDriveFilter( driveName ) ) {
- if( !isHideUnAvailableDrive ) {
- driveList.append( driveName );
- }
- else if ( isDriveAvailable( driveName ) ) {
- driveList.append( driveName );
- }
- }
- }
- return;
-}
-
-QString FmUtils::fillDriveVolume( QString driveName, bool isFillWithDefaultVolume )
+/*!
+ move one file insice the same drive, from \a source to \a target.
+ return KErrNone if successful, otherwise one of the other system-wide error codes.
+*/
+int FmUtils::moveInsideDrive( const QString &source, const QString &target )
{
- QString ret;
- QString tempDriveName = fillPathWithSplash( driveName );
-
- ret = removePathSplash( driveName );
-
- FmDriverInfo driverInfo = FmUtils::queryDriverInfo( tempDriveName );
- QString volumeName = driverInfo.volumeName();
-
- if( volumeName.isEmpty() && isFillWithDefaultVolume ){
- FmDriverInfo::DriveState driveState = FmUtils::queryDriverInfo( tempDriveName ).FmDriverInfo::driveState();
- if( !( driveState & FmDriverInfo::EDriveNotPresent ) ){
- if( driveState & FmDriverInfo::EDriveRemovable ) {
- if( driveState & FmDriverInfo::EDriveMassStorage ) {
- volumeName.append( QObject::tr( "Mass Storage" ) );
- }
- else{
- volumeName.append( QObject::tr( "Memory Card" ) );
- }
- }
- else{
- volumeName.append( QObject::tr( "Phone Memory" ) );
- }
- }
- }
-
- ret += QString( " " ) + volumeName;
- return ret;
+ Q_UNUSED( source );
+ Q_UNUSED( target );
+ return FmErrNone;
}
int FmUtils::launchFile( const QString &filePath )
@@ -366,7 +210,7 @@
void FmUtils::sendFiles( QStringList &filePathList )
{
-
+ Q_UNUSED( filePathList );
}
QString FmUtils::getBurConfigPath( QString appPath )
@@ -379,24 +223,31 @@
return path;
}
-bool FmUtils::isPathEqual( const QString &pathFst, const QString &pathLast )
+QString FmUtils::getFileType( const QString &filePath )
{
- QString fst( fillPathWithSplash( pathFst ) );
- QString last( fillPathWithSplash( pathLast ) );
- if( fst.compare( last, Qt::CaseInsensitive ) == 0 ) {
- return true;
- }
- return false;
+ Q_UNUSED( filePath );
+ return QString( "" );
}
-bool FmUtils::isDefaultFolder( const QString &folderPath )
+bool FmUtils::isDriveC( const QString &driveName )
{
- Q_UNUSED( folderPath );
- return false;
+ if( driveName.contains(Drive_C,Qt::CaseInsensitive) ){
+ return true;
+ }
+ else{
+ return false;
+ }
}
-QString FmUtils::formatPath( const QString &path )
+int FmUtils::getMaxFileNameLength()
{
- Q_UNUSED( path );
- return false;
+ return KMaxFileName;
}
+
+bool FmUtils::checkMaxPathLength( const QString& path )
+{
+ if( path.length() > KMaxPath ) {
+ return false;
+ }
+ return true;
+}