-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileparser.cpp
152 lines (135 loc) · 4.09 KB
/
fileparser.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
#include "fileparser.h"
#include <QDir>
#include <QDirIterator>
#include "imagedata.h"
#include "FreeImagePlus.h"
#include <QThread>
FileParser::FileParser()
{
path = QString("./");
thread = new QThread();
connect(thread,SIGNAL(started()),this,SLOT(SearchFiles()));
connect(thread,SIGNAL(finished()),this,SLOT(Complete()));
}
FileParser::~FileParser()
{
disconnect(thread,SIGNAL(started()),this,SLOT(SearchFiles()));
disconnect(thread,SIGNAL(finished()),this,SLOT(Complete()));
delete thread;
}
FileParser::FileParser(QString start_path)
{
path = start_path;
thread = new QThread();
connect(thread,SIGNAL(started()),this,SLOT(SearchFiles()));
connect(thread,SIGNAL(finished()),this,SLOT(Complete()));
}
void FileParser::FindFilesWithExtension(QString ext)
{
QFileInfo fileInfo(path);
extension = ext;
if (fileInfo.exists() && fileInfo.isDir())
{
/* Move Object to Thread and start search image data */
this->moveToThread(thread);
thread->start();
}
}
const ImageData& FileParser::GetImageData(int index)
{
return ImageTable.at(index);
}
void FileParser::SearchFiles()
{
QDir directoryToStart(path);
FindFilesFromDir(directoryToStart);
emit Started(FileAmount());
GetGPSData();
}
void FileParser::Complete()
{
emit AllDone();
}
int FileParser::FileAmount()
{
return listOfFiles.count();
}
QString FileParser::GetFileByIndex(int index)
{
return listOfFiles.value(index);
}
void FileParser::FindFilesFromDir(QDir dir)
{
QDirIterator iterator(dir.absolutePath(), QDirIterator::Subdirectories);
QString tmpString = extension;
while (iterator.hasNext()) {
iterator.next();
if (!iterator.fileInfo().isDir()) {
QString filename = iterator.fileName();
if (filename.endsWith(extension) || filename.endsWith(extension.toUpper()))
{
listOfFiles << iterator.filePath();
}
}
}
}
void FileParser::GetGPSData()
{
fipTag tag;
fipTag tag2;
fipImage src;
QString file;
const char* value;
const char* thumbnail_tag = "thumbnail_";
char value2 = '\n';
int amount = this->FileAmount();
int index = 0;
ImageData image;
ImageTable.reserve(amount);
while (index < amount)
{
file = this->GetFileByIndex(index);
src.load(file.toStdString().c_str());
image.AddFileName(file);
if(src.getMetadata(FIMD_EXIF_GPS,"GPSLatitude",tag) && src.getMetadata(FIMD_EXIF_GPS,"GPSLatitudeRef",tag2))
{
value2 = *(tag2.toString(FIMD_EXIF_GPS));
value = tag.toString(FIMD_EXIF_GPS);
image.AddGoordinate(false,value,value2);
}
if(src.getMetadata(FIMD_EXIF_GPS,"GPSLongitude",tag) && src.getMetadata(FIMD_EXIF_GPS,"GPSLongitudeRef",tag2))
{
value2 = *(tag2.toString(FIMD_EXIF_GPS));
value = tag.toString(FIMD_EXIF_GPS);
image.AddGoordinate(true,value,value2);
}
if(src.getMetadata(FIMD_EXIF_GPS,"GPSAltitude",tag))
{
value = tag.toString(FIMD_EXIF_GPS);
image.AddAlttitude(value);
}
if(src.getMetadata(FIMD_EXIF_EXIF,"DateTimeOriginal",tag))
{
value = tag.toString(FIMD_EXIF_EXIF);
image.time_stamp = QString(value);
}
/* Make Thumbnail from original image and store it to execution folder using PNG Format */
/* TODO: Investigate why icon data is not show in map
if (src.makeThumbnail(50))
{
int size = strlen(thumbnail_tag);
char* filename = new char[(size + image->file_name->length() + 1)];
strcpy(filename,thumbnail_tag);
strcpy((filename+size),image->file_name->toStdString().c_str());
size = (strlen(filename) - 4);
strcpy((filename+size),".png");
if (FreeImage_Save(FIF_PNG, src, filename, 0))
image->thumbnail_path = new QString(filename);
delete[] filename;
}*/
ImageTable << image;
emit FileDone(index);
index++;
}
thread->quit();
}