-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilepool.cpp
More file actions
53 lines (49 loc) · 1.45 KB
/
Copy pathfilepool.cpp
File metadata and controls
53 lines (49 loc) · 1.45 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
#include "filepool.h"
#include <QDir>
#include <QMutexLocker>
#include <QString>
#include <QDebug>
FilePool::FilePool(const QString &folder)
{
QDir dir(folder);
_canonicalRootPath = dir.absolutePath();
findFileInFolderAndSubfolders(folder);
}
void FilePool::findFileInFolderAndSubfolders(const QString &folder)
{
QDir dir(folder);
// list all the entries of the current folder
foreach (const QFileInfo &entry,
dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot)) {
if( entry.isDir() == true )
{
// it is a folder, recursive call to fill the files_
// member with the files contained in the subfolder
findFileInFolderAndSubfolders(entry.filePath());
}
else if(entry.isFile() == true) {
// it is a file with the right suffix,
// Store it in the files_ member
files_.append(entry.absoluteFilePath());
}
}
}
int FilePool::count() {
QMutexLocker locker(&mutex_);
return files_.size();
}
QString FilePool::tryGetFile() {
QString file;
// Début de d'exclusion mutuelle
QMutexLocker locker(&mutex_);
// Aucun autre thread ne peut exécuter ce code$
// pour le moment
if(files_.isEmpty() == false) {
file = files_.front();
files_.pop_front();
}
return file;
// A la destruction de locker, les autres
// threads pourront à nouveau essayer d'exécuter
// ce code.
}