diff -r 15bc28c9dd51 -r d58987eac7e8 filemanager/src/filemanager/src/fmfindthread.cpp --- a/filemanager/src/filemanager/src/fmfindthread.cpp Tue Aug 24 10:24:14 2010 +0800 +++ b/filemanager/src/filemanager/src/fmfindthread.cpp Wed Sep 29 10:37:03 2010 +0800 @@ -17,6 +17,8 @@ */ #include "fmfindthread.h" +#include "fmutils.h" +#include "fmcommon.h" #include @@ -38,86 +40,99 @@ Please connect this signal by Qt::BlockingQueuedConnection as dataList will be cleared immediately */ +/*! + Constructor, set thread LowPriority +*/ FmFindThread::FmFindThread( QObject *parent ) : QThread( parent ) { setPriority( LowPriority ); } +/*! + Destructor +*/ FmFindThread::~FmFindThread() { -} - -QString FmFindThread::findPath() const -{ - return mFindPath; + FM_LOG("FmFindThread::~FmFindThread()"); } -void FmFindThread::setFindPath( const QString &path ) +/*! + Set find path list \a pathList +*/ +void FmFindThread::setFindPathList( const QStringList &pathList ) { - mFindPath = path; + mFindPathList.clear(); + mFindPathList = pathList; } -QRegExp FmFindThread::pattern() const -{ - return findPattern; -} - +/*! + Set find pattern +*/ void FmFindThread::setPattern( const QRegExp ®Exp ) { findPattern = regExp; } +/*! + Stop find +*/ void FmFindThread::stop() { + FM_LOG("FmFindThread::stop()"); mStop = true; } +/* + Thread function +*/ void FmFindThread::run() { + FM_LOG( "FmFindThread::run() started "); mStop = false; - tempResultList.clear(); - if (findPattern.isEmpty() || !findPattern.isValid()) - return; - - QDir dir( mFindPath ); - if (!dir.exists()) - return; - - if( mFindPath.isEmpty() ){ - findInResult(); + if (findPattern.isEmpty() || !findPattern.isValid()) { + FM_LOG( "FmFindThread::run() canceled because error param "); return; } - + QList findDirs; - findDirs.append( dir ); + foreach( const QString &path, mFindPathList ) { + QDir dir( path ); + findDirs.append( dir ); + } + + count = 0; time.restart(); mStop = false; while (!findDirs.isEmpty()) { + if (mStop) { + FM_LOG("FmFindThread::run() stopped"); + return; + } QFileInfoList infoList = findDirs.first().entryInfoList(); for (QFileInfoList::Iterator it = infoList.begin(); it != infoList.end(); ++it) { + if (mStop) { + FM_LOG("FmFindThread::run() stopped"); + return; + } QString name = it->fileName(); QString absolutPath = it->absoluteFilePath(); if (findPattern.exactMatch( it->fileName() )) { - tempResultList.append( it->absoluteFilePath() ); - if (tempResultList.count() > notifyPerCount) { - emitFound(); - } else if (time.elapsed() > notifyPerElapsedTime && tempResultList.count() > 0) { - emitFound(); + if( !FmUtils::isSystemFolder( it->absoluteFilePath()) ) { + tempResultList.append( it->absoluteFilePath() ); + if (tempResultList.count() > notifyPerCount) { + emitFound(); + } else if (time.elapsed() > notifyPerElapsedTime && tempResultList.count() > 0) { + emitFound(); + } } } - //We are stopped; - if (mStop) { - if( tempResultList.count() > 0 ) { - emitFound(); - } - return; - } - // exclude directory named ".." and "." if (it->isDir() && it->fileName() != ParentDir && it->fileName() != CurrentDir ) { - findDirs.append( QDir( it->absoluteFilePath() ) ); + if( !FmUtils::isSystemFolder( it->absoluteFilePath()) ) { + findDirs.append( QDir( it->absoluteFilePath() ) ); + } } } @@ -132,42 +147,13 @@ */ void FmFindThread::emitFound() { + if (mStop) { + FM_LOG("FmFindThread::emitFound() return because stopped"); + return; + } if( tempResultList.count() > 0 ) { emit found( tempResultList ); tempResultList.clear(); time.restart(); } } - -void FmFindThread::setLastResult( QStringList r ) -{ - mLastResult = r; -} - -/* - Find keyword in last result - \sa setLastResult, this function must be called to set last result for findInResult -*/ -void FmFindThread::findInResult() -{ - if( mFindPath.isEmpty() ){ - for (QStringList::Iterator it = mLastResult.begin(); it != mLastResult.end(); ++it) { - if (mStop){ - return; - } - QString absolutPath = (*it); - QFileInfo fileInfo( absolutPath ); - QString fileName = fileInfo.fileName(); - - if (findPattern.exactMatch( fileName ) ) { - tempResultList.append( absolutPath ); - if ( tempResultList.count() > notifyPerCount ) { - emitFound(); - } else if (time.elapsed() > notifyPerElapsedTime && tempResultList.count() > 0) { - emitFound(); - } - } - } - } - emitFound(); -}