-
Notifications
You must be signed in to change notification settings - Fork 0
/
sourcefiles.cpp
71 lines (57 loc) · 1.82 KB
/
sourcefiles.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <QTime>
#include <QFileInfo>
#include "sourcefiles.h"
SourceFile::SourceFile(QString nPath, int nDirIndex):
path(nPath),
dirIndex(nDirIndex) {
}
int SourceFile::getIndex() {
return dirIndex;
}
QString SourceFile::getPath() {
return path;
}
SourceFiles::SourceFiles(Settings *pSettings, SrcDirItemModel *nSrcDirModel):
settings(pSettings),
srcDirModel(nSrcDirModel) {
qsrand(QTime::currentTime().msec());
}
void SourceFiles::add(QString path,int dirIndex) {
files.append(new SourceFile(path, dirIndex));
}
QString SourceFiles::getDstPath(QString path, int index) {
int srcLength = srcDirModel->getDir(index).length();
QString dstPath = path.remove(0, srcLength);
QString additionalPath = srcDirModel->getAdditionalPath(index);
dstPath = additionalPath + dstPath;
return dstPath;
}
void SourceFiles::getFile(QString &srcPath, QString &dstPath, int index) {
SourceFile *file = files.at(index);
files.remove(index);
srcPath = file->getPath();
if (settings->getBool(Settings::DIR_TREE)) {
dstPath = getDstPath(file->getPath(), file->getIndex());
dstPath.remove(0, 1);
dstPath.replace('/', ":::");
QRegExp re(":::.*:::");
dstPath.replace(re, ":::");
dstPath.replace(":::", " - ");
dstPath = '/' + dstPath;
} else {
dstPath = getDstPath(file->getPath(), file->getIndex());
}
}
void SourceFiles::getFirstFile(QString &srcPath, QString &dstPath) {
getFile(srcPath, dstPath, 0);
}
void SourceFiles::getRndFile(QString &srcPath, QString &dstPath) {
int rand = qrand()%files.size();
getFile(srcPath, dstPath, rand);
}
bool SourceFiles::isEmpty() {
return files.isEmpty();
}
int SourceFiles::size() {
return files.size();
}