-
Notifications
You must be signed in to change notification settings - Fork 0
/
librarian.cpp
72 lines (59 loc) · 1.7 KB
/
librarian.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
72
#include "librarian.hpp"
Librarian::Librarian(QObject *parent) : QObject(parent)
{
}
Librarian::Librarian(const QDir &sourcePath, const QDir &outputPath, const QStringList fileNames, QObject *parent)
{
_sourcePath = sourcePath;
_outputPath = outputPath;
_fileNames = fileNames;
}
void Librarian::run(SortPrecision value)
{
QStringListIterator iterator(_fileNames);
while(iterator.hasNext())
{
QFileInfo fileInfo = QFileInfo(_sourcePath,iterator.next());
_fileInfoList.append(fileInfo);
}
auto i = 0;
for(i = 0 ;i < _fileInfoList.count(); ++i)
{
QString dirName;
switch (value) {
case day:
{
dirName = _fileInfoList[i].lastModified().date().toString("yyyy-MM-dd");
break;
}
case month:
{
dirName = _fileInfoList[i].lastModified().date().toString("yyyy-MM");
break;
}
case year:
{
dirName = _fileInfoList[i].lastModified().date().toString("yyyy");
break;
}
}
QString srcFile = _fileInfoList[i].filePath();
QString outPath = _outputPath.path()+"/"+dirName;
QString outFile = outPath+"/"+_fileInfoList[i].fileName();
QDir outPathD(outPath);
if(!outPathD.exists())
{
outPathD.mkpath(outPath);
}
QFile file(srcFile);
file.open(QIODevice::ReadWrite);
file.setPermissions(QFile::WriteOwner);
emit beeingCopy(file.fileName(), i);
if(!file.copy(outFile))
{
qDebug() << file.error() << file.errorString();
}
}
++i;
emit beeingCopy("Gotowe", _fileInfoList.count());
}