-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchthread.cpp
More file actions
71 lines (57 loc) · 1.67 KB
/
searchthread.cpp
File metadata and controls
71 lines (57 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "searchthread.h"
#include "stringutil.h"
#include <QFileInfo>
#include <QDir>
#include <regex>
SearchThread::SearchThread(QObject *parent):QThread(parent) {
}
SearchThread::~SearchThread()
{
}
void SearchThread::stop()
{
this->m_stop = true;
}
void SearchThread::findFile(QString location, QString filter)
{
m_location = location;
m_filter = filter.toLower();
start();
}
void SearchThread::incFound(int &processCount,QStringList& results, QString newFile,bool finished){
++ processCount;
if(!newFile.isEmpty()){
results.append(newFile);
}
qint64 costMs = m_elapsedTimer.elapsed();
if(costMs >= 100){
emit file_found(results,finished);
results.clear();
m_elapsedTimer.restart();
}
}
#include "fileutil.h"
void SearchThread::findInDir(const QDir &dir, const QList<std::regex>& regs, int &processCount ,QStringList& results ){
if(m_stop) return;
for(auto &fileInfo: dir.entryInfoList(QDir::NoDotAndDotDot|QDir::Files|QDir::Dirs)){
if(StringUtil::match(regs,fileInfo.fileName())){
incFound(processCount,results,fileInfo.absoluteFilePath());
}
if(FileUtil::isLocalDir(fileInfo)){
findInDir(QDir(fileInfo.absoluteFilePath()),regs,processCount,results);
}
}
}
void SearchThread::run()
{
QList<std::regex> regList;
QList<QString> filters = m_filter.split(";");
m_elapsedTimer.start();
for(QString filter: filters){
regList.append(StringUtil::wildchardRex(filter.toStdString()));
}
int processCount = 0;
QStringList results;
findInDir(QDir(m_location),regList,processCount, results);
emit file_found(results,true);
}