-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadatamanager.cpp
More file actions
53 lines (45 loc) · 1.45 KB
/
metadatamanager.cpp
File metadata and controls
53 lines (45 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 "MetadataManager.h"
#include <stdexcept>
MetadataManager::MetadataManager(const std::string& filePath) : filePath(filePath) {
try {
image = Exiv2::ImageFactory::open(filePath);
if (!image) {
throw std::runtime_error("Failed to open image file.");
}
} catch (const std::exception& e) {
throw std::runtime_error(std::string("Exiv2 error: ") + e.what());
}
}
MetadataManager::~MetadataManager() {
// Destructor
}
void MetadataManager::loadMetadata() {
try {
image->readMetadata();
} catch (const std::exception& e) {
throw std::runtime_error(std::string("Error reading metadata: ") + e.what());
}
}
std::map<std::string, std::string> MetadataManager::getMetadata() const {
std::map<std::string, std::string> metadata;
auto& exifData = image->exifData();
for (const auto& entry : exifData) {
metadata[entry.key()] = entry.toString();
}
return metadata;
}
void MetadataManager::updateRating(int rating) {
try {
auto& exifData = image->exifData();
exifData["Exif.Image.Rating"] = rating;
} catch (const std::exception& e) {
throw std::runtime_error(std::string("Error updating rating: ") + e.what());
}
}
void MetadataManager::saveMetadata() {
try {
image->writeMetadata();
} catch (const std::exception& e) {
throw std::runtime_error(std::string("Error saving metadata: ") + e.what());
}
}