filemanager/src/inc/fmutils.cpp
changeset 48 1bebd60c0f00
parent 41 fc4654ce4fcb
child 49 81668a704644
equal deleted inserted replaced
44:22e202702210 48:1bebd60c0f00
    16 *     The source file of the file manager utilities
    16 *     The source file of the file manager utilities
    17 */
    17 */
    18 
    18 
    19 #include "fmutils.h"
    19 #include "fmutils.h"
    20 
    20 
    21 #include <QDir>
    21 #include <QRegExp>
    22 #include <QFileInfo>
    22 #include <QFileInfo>
    23 
    23 
    24 #include <hbglobal.h>
    24 #include <hbglobal.h>
       
    25 
    25 
    26 
    26 /*!
    27 /*!
    27     Used to get drive type for convenience.
    28     Used to get drive type for convenience.
    28 */
    29 */
    29 FmDriverInfo::DriveType FmDriverInfo::driveType()
    30 FmDriverInfo::DriveType FmDriverInfo::driveType()
   115    
   116    
   116    return ret;   
   117    return ret;   
   117 }
   118 }
   118 
   119 
   119 /*!
   120 /*!
   120     All "/" and "\" in \a path will be changed to QDir::separator
   121     All "/" and "\" in \a path will be changed to \a splitter
       
   122     QDir::separator is default value for splitter
   121     \sa fillPathWithSplash, fillPathWithSplash will append QDir::separator in the end
   123     \sa fillPathWithSplash, fillPathWithSplash will append QDir::separator in the end
   122 */
   124 */
   123 QString FmUtils::formatPath( const QString &path  )
   125 QString FmUtils::formatPath( const QString &path, const QChar &splitter )
   124 {
   126 {
   125     QString formatPath;
   127     QString formatPath;
   126     if( path.isEmpty() ) {
   128     if( path.isEmpty() ) {
   127         return formatPath;
   129         return formatPath;
   128     }
   130     }
   129     
   131     
   130     foreach( const QChar &ch, path ) {
   132     foreach( const QChar &ch, path ) {
   131         if( ch == QChar('\\') || ch == QChar('/') ) {
   133         if( ch == QChar('\\') || ch == QChar('/') ) {
   132             formatPath.append( QDir::separator() );
   134             formatPath.append( splitter );
   133         } else {
   135         } else {
   134             formatPath.append( ch );
   136             formatPath.append( ch );
   135         }
   137         }
   136     }
   138     }
   137 
   139 
   138     return formatPath;
   140     return formatPath;
   139 }
   141 }
   140 
   142 
   141 /*!
   143 /*!
   142     Fill splash in the end of \a filePath. And all "/" and "\" will be changed to QDir::separator
   144     Fill splash in the end of \a filePath. And all "/" and "\" will be changed to \a splitter
       
   145     QDir::separator is default value for splitter
   143     Please do not call this function if path is a file.
   146     Please do not call this function if path is a file.
   144     Use \a formatPath instead, \a formatPath will not append QDir::separator in the end.
   147     Use \a formatPath instead, \a formatPath will not append QDir::separator in the end.
   145     \sa formatPath only changed "/" and "\" to QDir::separator
   148     \sa formatPath only changed "/" and "\" to QDir::separator
   146 */
   149 */
   147 QString FmUtils::fillPathWithSplash( const QString &filePath )
   150 QString FmUtils::fillPathWithSplash( const QString &filePath, const QChar &splitter )
   148 {
   151 {
   149     QString newFilePath;
   152     QString newFilePath;
   150     if( filePath.isEmpty() ) {
   153     if( filePath.isEmpty() ) {
   151         return newFilePath;
   154         return newFilePath;
   152     }
   155     }
   153 
   156 
   154     newFilePath = formatPath( filePath );
   157     newFilePath = formatPath( filePath, splitter );
   155     
   158     
   156     if( newFilePath.right( 1 )!= QDir::separator() ){
   159     if( newFilePath.right( 1 )!= splitter ){
   157         newFilePath.append( QDir::separator() );
   160         newFilePath.append( splitter );
   158     }
   161     }
   159     return newFilePath;
   162     return newFilePath;
   160 }
   163 }
   161 
   164 
   162 /*!
   165 /*!
   408     // for example c:\data\ vs c:\data123\ 
   411     // for example c:\data\ vs c:\data123\ 
   409 
   412 
   410     FM_LOG("FmUtils::isSubFolder: false");
   413     FM_LOG("FmUtils::isSubFolder: false");
   411     return false;
   414     return false;
   412 }
   415 }
       
   416 
       
   417 /*!
       
   418     Check if \a path is system path.
       
   419 */
       
   420 bool FmUtils::isSystemFolder( const QString &path )
       
   421 {
       
   422     QFileInfo fileInfo( path );
       
   423     if( fileInfo.isDir() ) {
       
   424         QString checkedPath( fillPathWithSplash( path, Char_Slash ) );
       
   425 
       
   426         QRegExp systemFolder  ( RegexWidecard_SystemFolder,   Qt::CaseInsensitive, QRegExp::Wildcard );
       
   427         QRegExp sysFolder     ( RegexWidecard_SysFolder,      Qt::CaseInsensitive, QRegExp::Wildcard );
       
   428         QRegExp privateFolder ( RegexWidecard_PrivateFolder,  Qt::CaseInsensitive, QRegExp::Wildcard );
       
   429         QRegExp resourceFolder( RegexWidecard_ResourceFolder, Qt::CaseInsensitive, QRegExp::Wildcard );
       
   430 
       
   431         if( systemFolder.exactMatch( checkedPath ) ||
       
   432             sysFolder.exactMatch( checkedPath ) ||
       
   433             privateFolder.exactMatch( checkedPath ) ||
       
   434             resourceFolder.exactMatch( checkedPath ) ) {
       
   435             return true;
       
   436         }
       
   437     }
       
   438     return false;
       
   439 }