36 \fn void found( const QStringList &dataList ) |
37 \fn void found( const QStringList &dataList ) |
37 This signal is emitted when some data has been found and \a dataList is provided as data list. |
38 This signal is emitted when some data has been found and \a dataList is provided as data list. |
38 Please connect this signal by Qt::BlockingQueuedConnection as dataList will be cleared immediately |
39 Please connect this signal by Qt::BlockingQueuedConnection as dataList will be cleared immediately |
39 */ |
40 */ |
40 |
41 |
|
42 /*! |
|
43 Constructor, set thread LowPriority |
|
44 */ |
41 FmFindThread::FmFindThread( QObject *parent ) |
45 FmFindThread::FmFindThread( QObject *parent ) |
42 : QThread( parent ) |
46 : QThread( parent ) |
43 { |
47 { |
44 setPriority( LowPriority ); |
48 setPriority( LowPriority ); |
45 } |
49 } |
46 |
50 |
|
51 /*! |
|
52 Destructor |
|
53 */ |
47 FmFindThread::~FmFindThread() |
54 FmFindThread::~FmFindThread() |
48 { |
55 { |
|
56 FM_LOG("FmFindThread::~FmFindThread()"); |
49 } |
57 } |
50 |
58 |
51 QString FmFindThread::findPath() const |
59 /*! |
|
60 Set find path list \a pathList |
|
61 */ |
|
62 void FmFindThread::setFindPathList( const QStringList &pathList ) |
52 { |
63 { |
53 return mFindPath; |
64 mFindPathList.clear(); |
|
65 mFindPathList = pathList; |
54 } |
66 } |
55 |
67 |
56 void FmFindThread::setFindPath( const QString &path ) |
68 /*! |
57 { |
69 Set find pattern |
58 mFindPath = path; |
70 */ |
59 } |
|
60 |
|
61 QRegExp FmFindThread::pattern() const |
|
62 { |
|
63 return findPattern; |
|
64 } |
|
65 |
|
66 void FmFindThread::setPattern( const QRegExp ®Exp ) |
71 void FmFindThread::setPattern( const QRegExp ®Exp ) |
67 { |
72 { |
68 findPattern = regExp; |
73 findPattern = regExp; |
69 } |
74 } |
70 |
75 |
|
76 /*! |
|
77 Stop find |
|
78 */ |
71 void FmFindThread::stop() |
79 void FmFindThread::stop() |
72 { |
80 { |
|
81 FM_LOG("FmFindThread::stop()"); |
73 mStop = true; |
82 mStop = true; |
74 } |
83 } |
75 |
84 |
|
85 /* |
|
86 Thread function |
|
87 */ |
76 void FmFindThread::run() |
88 void FmFindThread::run() |
77 { |
89 { |
|
90 FM_LOG( "FmFindThread::run() started "); |
78 mStop = false; |
91 mStop = false; |
79 tempResultList.clear(); |
92 if (findPattern.isEmpty() || !findPattern.isValid()) { |
80 if (findPattern.isEmpty() || !findPattern.isValid()) |
93 FM_LOG( "FmFindThread::run() canceled because error param "); |
81 return; |
|
82 |
|
83 QDir dir( mFindPath ); |
|
84 if (!dir.exists()) |
|
85 return; |
|
86 |
|
87 if( mFindPath.isEmpty() ){ |
|
88 findInResult(); |
|
89 return; |
94 return; |
90 } |
95 } |
|
96 |
|
97 QList<QDir> findDirs; |
|
98 foreach( const QString &path, mFindPathList ) { |
|
99 QDir dir( path ); |
|
100 findDirs.append( dir ); |
|
101 } |
91 |
102 |
92 QList<QDir> findDirs; |
103 count = 0; |
93 findDirs.append( dir ); |
|
94 time.restart(); |
104 time.restart(); |
95 mStop = false; |
105 mStop = false; |
96 while (!findDirs.isEmpty()) { |
106 while (!findDirs.isEmpty()) { |
|
107 if (mStop) { |
|
108 FM_LOG("FmFindThread::run() stopped"); |
|
109 return; |
|
110 } |
97 QFileInfoList infoList = findDirs.first().entryInfoList(); |
111 QFileInfoList infoList = findDirs.first().entryInfoList(); |
98 for (QFileInfoList::Iterator it = infoList.begin(); it != infoList.end(); ++it) { |
112 for (QFileInfoList::Iterator it = infoList.begin(); it != infoList.end(); ++it) { |
|
113 if (mStop) { |
|
114 FM_LOG("FmFindThread::run() stopped"); |
|
115 return; |
|
116 } |
99 QString name = it->fileName(); |
117 QString name = it->fileName(); |
100 QString absolutPath = it->absoluteFilePath(); |
118 QString absolutPath = it->absoluteFilePath(); |
101 if (findPattern.exactMatch( it->fileName() )) { |
119 if (findPattern.exactMatch( it->fileName() )) { |
102 tempResultList.append( it->absoluteFilePath() ); |
120 tempResultList.append( it->absoluteFilePath() ); |
103 if (tempResultList.count() > notifyPerCount) { |
121 if (tempResultList.count() > notifyPerCount) { |
104 emitFound(); |
122 emitFound(); |
105 } else if (time.elapsed() > notifyPerElapsedTime && tempResultList.count() > 0) { |
123 } else if (time.elapsed() > notifyPerElapsedTime && tempResultList.count() > 0) { |
106 emitFound(); |
124 emitFound(); |
107 } |
125 } |
108 } |
|
109 |
|
110 //We are stopped; |
|
111 if (mStop) { |
|
112 if( tempResultList.count() > 0 ) { |
|
113 emitFound(); |
|
114 } |
|
115 return; |
|
116 } |
126 } |
117 |
127 |
118 // exclude directory named ".." and "." |
128 // exclude directory named ".." and "." |
119 if (it->isDir() && it->fileName() != ParentDir && it->fileName() != CurrentDir ) { |
129 if (it->isDir() && it->fileName() != ParentDir && it->fileName() != CurrentDir ) { |
120 findDirs.append( QDir( it->absoluteFilePath() ) ); |
130 findDirs.append( QDir( it->absoluteFilePath() ) ); |
130 /* |
140 /* |
131 Emit signal "found" to send out found data |
141 Emit signal "found" to send out found data |
132 */ |
142 */ |
133 void FmFindThread::emitFound() |
143 void FmFindThread::emitFound() |
134 { |
144 { |
|
145 if (mStop) { |
|
146 FM_LOG("FmFindThread::emitFound() return because stopped"); |
|
147 return; |
|
148 } |
135 if( tempResultList.count() > 0 ) { |
149 if( tempResultList.count() > 0 ) { |
136 emit found( tempResultList ); |
150 emit found( tempResultList ); |
137 tempResultList.clear(); |
151 tempResultList.clear(); |
138 time.restart(); |
152 time.restart(); |
139 } |
153 } |
140 } |
154 } |
141 |
|
142 void FmFindThread::setLastResult( QStringList r ) |
|
143 { |
|
144 mLastResult = r; |
|
145 } |
|
146 |
|
147 /* |
|
148 Find keyword in last result |
|
149 \sa setLastResult, this function must be called to set last result for findInResult |
|
150 */ |
|
151 void FmFindThread::findInResult() |
|
152 { |
|
153 if( mFindPath.isEmpty() ){ |
|
154 for (QStringList::Iterator it = mLastResult.begin(); it != mLastResult.end(); ++it) { |
|
155 if (mStop){ |
|
156 return; |
|
157 } |
|
158 QString absolutPath = (*it); |
|
159 QFileInfo fileInfo( absolutPath ); |
|
160 QString fileName = fileInfo.fileName(); |
|
161 |
|
162 if (findPattern.exactMatch( fileName ) ) { |
|
163 tempResultList.append( absolutPath ); |
|
164 if ( tempResultList.count() > notifyPerCount ) { |
|
165 emitFound(); |
|
166 } else if (time.elapsed() > notifyPerElapsedTime && tempResultList.count() > 0) { |
|
167 emitFound(); |
|
168 } |
|
169 } |
|
170 } |
|
171 } |
|
172 emitFound(); |
|
173 } |
|