--- a/filemanager/src/inc/fmutils_win.cpp Tue Jul 06 14:06:28 2010 +0300
+++ b/filemanager/src/inc/fmutils_win.cpp Wed Aug 18 09:39:39 2010 +0300
@@ -222,25 +222,23 @@
Q_UNUSED( driverName );
}
+/*!
+ fill splash in the end of \a filePath if the path is not a file
+ All "/" and "\" will be changed to QDir::separator
+ \sa formatPath only changed "/" and "\" to QDir::separator
+*/
QString FmUtils::fillPathWithSplash( const QString &filePath )
{
- QString newFilePath;
+ QString newFilePath;
if( filePath.isEmpty() ) {
return newFilePath;
}
- foreach( QChar ch, filePath ) {
- if( ch == QChar('\\') || ch == QChar('/') ) {
- newFilePath.append( QDir::separator() );
- } else {
- newFilePath.append( ch );
- }
- }
+ newFilePath = formatPath( filePath );
if( newFilePath.right( 1 )!= QDir::separator() ){
newFilePath.append( QDir::separator() );
}
-
return newFilePath;
}
@@ -290,14 +288,14 @@
#ifdef _DEBUG_HIDE_VIEWFOLDER_WINDOWS_
QString logString;
logString = QString( "checkFolderToDriveFilter: " ) + path;
- FmLogger::log( logString );
+ FM_LOG( logString );
QString checkedPath = fillPathWithSplash( path );
logString = QString( "checkFolderToDriveFilter_fillPathWithSplash: " ) + checkedPath;
- FmLogger::log( logString );
+ FM_LOG( logString );
if( checkedPath.compare( QString( "C:/data/"), Qt::CaseInsensitive ) == 0 ) {
- FmLogger::log( QString( " change from c:/data/ to C:/" ) );
+ FM_LOG( QString( " change from c:/data/ to C:/" ) );
return QString( "C:/" );
}
#endif
@@ -437,20 +435,25 @@
return false;
}
+/*!
+ All "/" and "\" in \a path will be changed to QDir::separator
+ \sa fillPathWithSplash, fillPathWithSplash will append QDir::separator in the end if path is no a file
+*/
QString FmUtils::formatPath( const QString &path )
{
QString formatPath;
- foreach( QChar ch, path ) {
- if( ch == QChar('\\') || ch == QChar('/') ) {
- formatPath.append( QDir::separator() );
- } else {
- formatPath.append( ch );
- }
+ if( path.isEmpty() ) {
+ return formatPath;
+ }
+
+ foreach( QChar ch, path ) {
+ if( ch == QChar('\\') || ch == QChar('/') ) {
+ formatPath.append( QDir::separator() );
+ } else {
+ formatPath.append( ch );
+ }
}
- if( formatPath.right( 1 ) != QDir::separator() ){
- formatPath.append( QDir::separator() );
- }
return formatPath;
}
@@ -466,33 +469,42 @@
}
return true;
}
+
bool FmUtils::checkFolderFileName( const QString& name )
{
- if( name.endsWith( QChar('.'), Qt::CaseInsensitive ) ) {
+ // trim space firest, because there may be some spaces after "." , it is also not valid
+ // or there may only have spaces in name
+ QString trimmedName( name.trimmed() );
+ if( trimmedName.isEmpty() ) {
+ return false;
+ }
+ if( trimmedName.endsWith( QChar('.'), Qt::CaseInsensitive ) ) {
return false;
}
- if( name.contains( QChar('\\'), Qt::CaseInsensitive ) ||
- name.contains( QChar('/'), Qt::CaseInsensitive ) ||
- name.contains( QChar(':'), Qt::CaseInsensitive ) ||
- name.contains( QChar('*'), Qt::CaseInsensitive ) ||
- name.contains( QChar('?'), Qt::CaseInsensitive ) ||
- name.contains( QChar('\"'), Qt::CaseInsensitive ) ||
- name.contains( QChar('<'), Qt::CaseInsensitive ) ||
- name.contains( QChar('>'), Qt::CaseInsensitive ) ||
- name.contains( QChar('|'), Qt::CaseInsensitive ) ){
+ if( trimmedName.contains( QChar('\\'), Qt::CaseInsensitive ) ||
+ trimmedName.contains( QChar('/'), Qt::CaseInsensitive ) ||
+ trimmedName.contains( QChar(':'), Qt::CaseInsensitive ) ||
+ trimmedName.contains( QChar('*'), Qt::CaseInsensitive ) ||
+ trimmedName.contains( QChar('?'), Qt::CaseInsensitive ) ||
+ trimmedName.contains( QChar('\"'), Qt::CaseInsensitive ) ||
+ trimmedName.contains( QChar('<'), Qt::CaseInsensitive ) ||
+ trimmedName.contains( QChar('>'), Qt::CaseInsensitive ) ||
+ trimmedName.contains( QChar('|'), Qt::CaseInsensitive ) ){
return false;
}
+ // use orignal name to exam max size of file name
if( name.length() > KMaxFileName ) {
return false;
}
return true;
}
-bool FmUtils::checkNewFolderOrFile( const QString &path, QString &errString )
+bool FmUtils::checkNewFolderOrFile( const QString &fileName, const QString &path, QString &errString )
{
+ // first check if fileName is valid, then check if path length is valid, and check if file/foler is existed at last
QFileInfo fileInfo( path );
bool ret( true );
- if (!FmUtils::checkFolderFileName( fileInfo.fileName() ) ) {
+ if (!FmUtils::checkFolderFileName( fileName ) ) {
errString = hbTrId( "Invalid file or folder name, try again!" );
ret = false;
} else if( !FmUtils::checkMaxPathLength( path ) ) {
@@ -504,3 +516,42 @@
}
return ret;
}
+
+QString FmUtils::getVolumeNameWithDefaultNameIfNull( const QString &diskName, bool &defaultName )
+{
+ FmDriverInfo driverInfo = FmUtils::queryDriverInfo( diskName );
+
+ // do not add default volume for win32 version as this is only the dummy implememnt for debug on windows
+ return driverInfo.volumeName();
+}
+
+/*!
+ Check if \a dest is sub level path of \a src
+ Used to check True/False when copy a folder to itself or its subfolder
+ For example, c:\data\test is sub path of c:\data.
+ But c:\data123\test is not sub path of c:\data.
+ So after got right part of path, the first char must be \ or /
+*/
+bool FmUtils::isSubLevelPath( const QString &src, const QString &dest )
+{
+ FM_LOG("FmUtils::isSubFolder: src=" + src + " dest=" + dest);
+ QString checkedSrc( FmUtils::fillPathWithSplash( src ) );
+ QString checkedDest( FmUtils::fillPathWithSplash( dest ) );
+
+ if( checkedDest.contains( checkedSrc, Qt::CaseInsensitive) &&
+ checkedDest.length() > checkedSrc.length() ) {
+ // for example c:\data\ vs c:\data\123\
+ FM_LOG("FmUtils::isSubFolder: true");
+ return true;
+ }
+ // for example c:\data\ vs c:\data\
+ // for example c:\data\ vs c:\data123\
+
+ FM_LOG("FmUtils::isSubFolder: false");
+ return false;
+}
+
+int FmUtils::setFileAttributes( const QString &srcFile, const QString &desFile )
+{
+ return FmErrNone;
+}