MauiKit Image Tools

picinfomodel.cpp
1// Copyright 2018-2020 Camilo Higuita <milo.h@aol.com>
2// Copyright 2018-2020 Nitrux Latinoamericana S.C.
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6#include "picinfomodel.h"
7#include "exiv2extractor.h"
8
9#include <QDateTime>
10#include <QDebug>
11#include <QLocale>
12#include <QUrl>
13
14std::string gpsToString(Exiv2::Metadatum& value);
15PicInfoModel::PicInfoModel(QObject *parent) : MauiList(parent)
16, m_extractor(new Exiv2Extractor(this))
17
18{
19}
20
21void PicInfoModel::componentComplete()
22{
23 connect(this, &PicInfoModel::urlChanged, [this](QUrl)
24 {
25 if (!FMH::fileExists(m_url) || m_url.isEmpty() || !m_url.isValid()) {
26 return;
27 }
28
29 QFileInfo file(m_url.toLocalFile());
30 m_fileName = file.fileName();
31 Q_EMIT fileNameChanged();
32
33 m_extractor->setUrl(m_url);
34 this->parse();
35 });
36
37 if (FMH::fileExists(m_url) && !m_url.isEmpty() && m_url.isValid()) {
38 m_extractor->setUrl(m_url);
39 this->parse();
40 }
41}
42
43void PicInfoModel::setUrl(QUrl url)
44{
45 if (m_url == url)
46 {
47 return;
48 }
49
50 m_url = url;
51 Q_EMIT urlChanged(m_url);
52}
53
54bool PicInfoModel::removeTag(const QString& tag)
55{
56 if(!m_extractor)
57 return false;
58
59 if(m_extractor->removeTag(tag.toStdString().c_str()))
60 {
61 this->parse();
62 return true;
63 }
64
65 return false;
66}
67
68bool PicInfoModel::editTag(const QString& tag, const QString& value)
69{
70 qDebug() << "trying to write tag1";
71
72 if(m_extractor->writeTag(tag.toStdString().c_str(), QVariant::fromValue(value)))
73 {
74 qDebug() << "trying to write tag3";
75 this->parse();
76 return true;
77 }
78
79 return false;
80}
81
82double PicInfoModel::latitude() const
83{
84 return m_latitude;
85}
86
87double PicInfoModel::longitude() const
88{
89 return m_longitude;
90}
91
92QUrl PicInfoModel::url() const
93{
94 return m_url;
95}
96
97static FMH::MODEL_LIST basicInfo(const QUrl &url)
98{
100 QFileInfo file(url.toLocalFile());
101 QLocale locale;
102 res << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Name"}, {FMH::MODEL_KEY::VALUE, file.fileName()}, {FMH::MODEL_KEY::ICON, "edit-rename"}};
103 res << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Path"}, {FMH::MODEL_KEY::VALUE, url.toLocalFile()}, {FMH::MODEL_KEY::ICON, "folder"}};
104 res << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Size"}, {FMH::MODEL_KEY::VALUE, locale.formattedDataSize(file.size())}, {FMH::MODEL_KEY::ICON, "folder"}};
105 res << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Last Modified"}, {FMH::MODEL_KEY::VALUE, file.lastModified().toString()}, {FMH::MODEL_KEY::ICON, "view-media-recent"}};
106 res << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Date"}, {FMH::MODEL_KEY::VALUE, file.birthTime().toString()}, {FMH::MODEL_KEY::ICON, "view-calendar-birthday"}};
107
108
109 return res;
110}
111
112void PicInfoModel::parse()
113{
114 qDebug() << "Setting image medatata model info";
116 m_data.clear();
117 m_data << basicInfo(m_url);
118
119 if (!m_extractor->error())
120 {
121 auto gps = m_extractor->extractGPS();
122 m_latitude = gps.first;
123 m_longitude = gps.second;
124
125 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Max Aperture"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Photo.MaxApertureValue")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Photo.MaxApertureValue"}};
126
127 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Aperture"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.ApertureValue")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Image.ApertureValue"}};
128
129 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "BrightnessValue"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.BrightnessValue")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Image.BrightnessValue"}};
130
131 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Camera"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.Make")}, {FMH::MODEL_KEY::ICON, "camera-video"}, {FMH::MODEL_KEY::KEY, "Exif.Image.Make"}};
132
133 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Camera Model"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.Model")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Image.Model"}};
134
135 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Focal Length"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Photo.FocalLength")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Photo.FocalLength"}};
136
137 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Exposure Time"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Photo.ExposureTime")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Photo.ExposureTime"}};
138
139 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Exposure Mode"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Photo.ExposureMode")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Photo.ExposureMode"}};
140
141 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Flash"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Photo.Flash")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Photo.Flash"}};
142
143 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "ISO Speed"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Photo.ISOSpeedRatings")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Photo.ISOSpeedRatings"}};
144
145 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Shutter Speed"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Photo.ShutterSpeedValue")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Photo.ShutterSpeedValue"}};
146
147 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Compression"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Thumbnail.Compression")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Thumbnail.Compression"}};
148
149 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Color Space"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Photo.ColorSpace")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Photo.ColorSpace"}};
150
151 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "White Balance"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Photo.WhiteBalance")}, {FMH::MODEL_KEY::ICON, "documentinfo"}, {FMH::MODEL_KEY::KEY, "Exif.Photo.WhiteBalance"}};
152
153 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Notes"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifComment()}, {FMH::MODEL_KEY::ICON, "note"}, {FMH::MODEL_KEY::KEY, "Exif.Photo.UserComment"}};
154
155 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Author"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.Artist")}, {FMH::MODEL_KEY::ICON, "user"}, {FMH::MODEL_KEY::KEY, "Exif.Image.Artist"}};
156
157 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "GPS Latitude"}, {FMH::MODEL_KEY::VALUE, QString::number(m_latitude)}, {FMH::MODEL_KEY::ICON, "user"}, {FMH::MODEL_KEY::KEY, "Exif.GPSInfo.GPSLatitude"}};
158
159 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "GPS Longitude"}, {FMH::MODEL_KEY::VALUE, QString::number(m_longitude)}, {FMH::MODEL_KEY::ICON, "user"}, {FMH::MODEL_KEY::KEY, "Exif.GPSInfo.GPSLongitude"}};
160
161 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "City"}, {FMH::MODEL_KEY::VALUE, m_extractor->GPSString ()}, {FMH::MODEL_KEY::ICON, "user"}};
162
163 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Processing Software"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.ProcessingSoftware")}, {FMH::MODEL_KEY::KEY, "Exif.Image.ProcessingSoftware"}};
164
165 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "DocumentName"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.DocumentName")}, {FMH::MODEL_KEY::KEY, "Exif.Image.DocumentName"}};
166
167 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "ImageDescription"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.ImageDescription")}, {FMH::MODEL_KEY::KEY, "Exif.Image.ImageDescription"}};
168
169 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Software"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.Software")}, {FMH::MODEL_KEY::KEY, "Exif.Image.Software"}};
170
171 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "HostComputer"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.HostComputer")}, {FMH::MODEL_KEY::KEY, "Exif.Image.HostComputer"}};
172
173 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Rating"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.Rating")}, {FMH::MODEL_KEY::KEY, "Exif.Image.Rating"}};
174
175 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "Copyright"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.Copyright")}, {FMH::MODEL_KEY::KEY, "Exif.Image.Copyright"}};
176
177 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "SelfTimerMode"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.SelfTimerMode")}, {FMH::MODEL_KEY::KEY, "Exif.Image.SelfTimerMode"}};
178
179 m_data << FMH::MODEL{{FMH::MODEL_KEY::NAME, "ImageHistory"}, {FMH::MODEL_KEY::VALUE, m_extractor->getExifTagString("Exif.Image.ImageHistory")}, {FMH::MODEL_KEY::KEY, "Exif.Image.ImageHistory"}};
180
181
182 }else
183 {
184 qDebug() << "error extracting image metadata";
185 }
186
188 Q_EMIT dataReady();
189}
190
191const FMH::MODEL_LIST &PicInfoModel::items() const
192{
193 return m_data;
194}
195
Image metadata extractor.
void preListChanged()
void postListChanged()
bool fileExists(const QUrl &path)
void clear()
QString formattedDataSize(qint64 bytes, int precision, DataSizeFormats format) const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString number(double n, char format, int precision)
std::string toStdString() const const
bool isEmpty() const const
bool isValid() const const
QString toLocalFile() const const
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.