-
Notifications
You must be signed in to change notification settings - Fork 0
/
FilePool.cpp
52 lines (42 loc) · 926 Bytes
/
FilePool.cpp
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
#include "FilePool.hh"
FilePool::FilePool(const QString &folder)
: m_folder(folder)
{
fillPool(m_folder);
}
quint32 FilePool::count()
{
QMutexLocker locker(&m_mutex);
return m_files.count();
}
const QStringList &FilePool::files() const
{
return m_files;
}
QString FilePool::tryGetFile()
{
QString file("");
QMutexLocker locker(&m_mutex);
if (m_files.isEmpty() == false)
{
file = m_files.front();
m_files.pop_front();
}
return file;
}
void FilePool::fillPool(const QString &folder)
{
QDir dir(folder);
dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::NoSymLinks);
for (const QFileInfo &entry : dir.entryInfoList())
{
if (entry.isDir())
{
fillPool(entry.filePath());
}
else if (entry.isFile())
{
m_files.append(entry.filePath());
}
}
}