-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathimportfileprocessor.cpp
154 lines (137 loc) · 4.32 KB
/
importfileprocessor.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/** @file importfileprocessor.cpp
* Soubor s tridou ImportFileProcessor dedici ze tridy QObject
* , slouzi pro import fotografii
*/
#include "importfileprocessor.h"
ImportFileProcessor::ImportFileProcessor(QObject* parent)
: QObject(parent)
{
idRouteCount = 0;
idImageCount = 0;
}
int ImportFileProcessor::countFiles(QString fileName)
{
int count = 0;
if (QFileInfo(fileName).isDir()) {
QDir dir(fileName);
QStringList fileList = dir.entryList();
foreach (QString file, fileList) {
if (file != "." && file != "..") {
count += countFiles(dir.absoluteFilePath(file));
}
}
} else {
count = 1;
}
return count;
}
void ImportFileProcessor::processDropUrls(QList<QUrl>* urlList)
{
unrecognizedList = new QStringList;
int rec = 0;
// importSubdirs = -2; //nenarazila jsem zatim na adresar
importSubdirs = 1; // importovat podasresare
countProcessed = 0;
int count = 0;
foreach (QUrl url, *urlList) {
count += countFiles(url.toLocalFile());
}
emit setProgressMaximum(count);
foreach (QUrl url, *urlList) {
processDropFile(url.toLocalFile(), rec);
}
emit finished(unrecognizedList);
}
void ImportFileProcessor::processDropFile(QString fileName, int recursion)
{
if (QFileInfo(fileName).isDir()) {
if (recursion > 0 && importSubdirs < 0) { // v adresari je dalsi adresar, neni nastaveno prochazeni podadresaru
/* QMessageBox *askSubdir = new QMessageBox(QMessageBox::Question, tr("File import"),
tr("Import also files from subdirectories?"),
QMessageBox::Yes | QMessageBox::No);
QPalette pal = askSubdir->palette();
pal.setColor(QPalette::Window, "#D0D0E7");
askSubdir->setPalette(pal);
int ret = askSubdir->exec();
if(ret == QMessageBox::Yes)
importSubdirs = 1;
else
importSubdirs = 0;*/
}
if (importSubdirs == 1 || recursion <= 0) {
QDir dir(fileName);
QStringList fileList = dir.entryList();
foreach (QString file, fileList) {
if (file != "." && file != "..") {
processDropFile(dir.absoluteFilePath(file), recursion + 1);
}
}
}
return;
}
QString suffix = QFileInfo(fileName).suffix();
if (suffix == "gpx") { // gpx soubor
loadGpsFile(fileName);
} else if (QImageReader::imageFormat(fileName) != "") {
loadImageFile(fileName);
} else {
unrecognizedList->append(fileName);
countProcessed++;
emit setProgressValue(countProcessed);
}
}
void ImportFileProcessor::loadGpsFile(QString gpsFileName)
{
GpsRoute* gpsRoute = new GpsRoute(idRouteCount);
if (gpsRoute->loadFile(gpsFileName)) {
delete gpsRoute;
unrecognizedList->append(gpsFileName);
return;
}
idRouteCount++;
emit importRouteFinished(gpsRoute);
countProcessed++;
emit setProgressValue(countProcessed);
}
void ImportFileProcessor::loadImageFile(QString imageFileName)
{
ImageData* imageData = new ImageData;
if (imageData->loadData(imageFileName)) {
delete imageData;
unrecognizedList->append(imageFileName);
return;
}
imageData->id = idImageCount;
idImageCount++;
emit importImageFinished(imageData);
countProcessed++;
emit setProgressValue(countProcessed);
}
void ImportFileProcessor::importImages(QStringList imageList)
{
countProcessed = 0;
int count = 0;
foreach (QString imageFile, imageList) {
count += countFiles(imageFile);
}
emit setProgressMaximum(count);
unrecognizedList = new QStringList;
foreach (QString imageFile, imageList) {
loadImageFile(imageFile);
}
emit finished(unrecognizedList);
}
void ImportFileProcessor::importGpsFiles(QStringList gpsList)
{
countProcessed = 0;
int count = 0;
foreach (QString gpsFile, gpsList) {
count += countFiles(gpsFile);
}
emit setProgressMaximum(count);
unrecognizedList = new QStringList;
foreach (QString gpsFile, gpsList) {
loadGpsFile(gpsFile);
}
emit finished(unrecognizedList);
}