digiKam
dmetadata.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2006-02-23
7  * Description : item metadata interface
8  *
9  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2006-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11  * Copyright (C) 2013 by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_DMETA_DATA_H
27 #define DIGIKAM_DMETA_DATA_H
28 
29 // Qt includes
30 
31 #include <QByteArray>
32 #include <QUrl>
33 
34 // Local includes
35 
36 #include "metaengine.h"
37 #include "metaengine_data.h"
39 #include "metadatainfo.h"
40 #include "captionvalues.h"
41 #include "photoinfocontainer.h"
42 #include "videoinfocontainer.h"
43 #include "digikam_export.h"
44 #include "dmetadatasettings.h"
45 
46 namespace Digikam
47 {
48 
49 class Template;
50 class IccProfile;
51 
52 // TODO: merge with MetaEngine class.
53 
54 class DIGIKAM_EXPORT DMetadata : public MetaEngine
55 {
56 
57 public:
58 
64  {
65  VIDEOCOLORMODEL_UNKNOWN = 1000,
69  VIDEOCOLORMODEL_BT601
70  };
71 
72 public:
73 
74  typedef QMap<QString, QString> CountryCodeMap;
75 
76 public:
77 
78  DMetadata();
79  explicit DMetadata(const QString& filePath);
80  explicit DMetadata(const MetaEngineData& data);
81  ~DMetadata();
82 
83 public: // Settings helpers
84 
85  void registerMetadataSettings();
86  void setSettings(const MetaEngineSettingsContainer& settings);
87 
88 public: // File I/O helpers
89 
96  bool load(const QString& filePath, Backend* backend = nullptr);
97  bool save(const QString& filePath, bool setVersion = false) const;
98  bool applyChanges(bool setVersion = false) const;
99 
103  bool loadUsingRawEngine(const QString& filePath);
104 
105 public: // History helpers
106 
107  QString getItemHistory() const;
108  bool setItemHistory(const QString& imageHistoryXml) const;
109  bool hasItemHistoryTag() const;
110 
111  QString getItemUniqueId() const;
112  bool setItemUniqueId(const QString& uuid) const;
113 
114 public: // Faces helpers
115 
120  bool getItemFacesMap(QMultiMap<QString, QVariant>& facesPath) const;
121 
128  bool setItemFacesMap(const QMultiMap<QString, QVariant>& facesPath, bool write, const QSize& size = QSize()) const;
129 
133  bool removeItemFacesMap() const;
134 
135 public: // Tags helpers
136 
137  bool getItemTagsPath(QStringList& tagsPath,
138  const DMetadataSettingsContainer& settings = DMetadataSettings::instance()->settings()) const;
139  bool setItemTagsPath(const QStringList& tagsPath,
140  const DMetadataSettingsContainer& settings = DMetadataSettings::instance()->settings()) const;
141 
142  bool getACDSeeTagsPath(QStringList& tagsPath) const;
143 
144  bool setACDSeeTagsPath(const QStringList& tagsPath) const;
145 
146 public: // Comments helpers
147 
148  CaptionsMap getItemComments(const DMetadataSettingsContainer& settings = DMetadataSettings::instance()->settings()) const;
149  bool setItemComments(const CaptionsMap& comments,
150  const DMetadataSettingsContainer& settings = DMetadataSettings::instance()->settings()) const;
151 
152  CaptionsMap getItemTitles(const DMetadataSettingsContainer& settings = DMetadataSettings::instance()->settings()) const;
153  bool setItemTitles(const CaptionsMap& title,
154  const DMetadataSettingsContainer& settings = DMetadataSettings::instance()->settings()) const;
155 
156  static MetaEngine::AltLangMap toAltLangMap(const QVariant& var);
157 
158 public: // Labels helpers
159 
160  int getItemRating(const DMetadataSettingsContainer& settings = DMetadataSettings::instance()->settings()) const;
161  bool setItemRating(int rating,
162  const DMetadataSettingsContainer& settings = DMetadataSettings::instance()->settings()) const;
163 
164  int getItemPickLabel() const;
165  bool setItemPickLabel(int pickId) const;
166 
167  int getItemColorLabel(const DMetadataSettingsContainer& settings = DMetadataSettings::instance()->settings()) const;
168  bool setItemColorLabel(int colorId,
169  const DMetadataSettingsContainer& settings = DMetadataSettings::instance()->settings()) const;
170 
171 public: // Template helpers
172 
173  bool setMetadataTemplate(const Template& t) const;
174  Template getMetadataTemplate() const;
175  bool removeMetadataTemplate() const;
176 
181  bool getCopyrightInformation(Template& t) const;
182 
183 public: // EXIF helpers
184 
191  IccProfile getIccProfile() const;
192 
196  bool setIccProfile(const IccProfile& profile);
197 
201  bool removeExifColorSpace() const;
202 
206  int getMSecsInfo() const;
207 
212  bool mSecTimeStamp(const char* const exifTagName, int& ms) const;
213 
214  bool removeExifTags(const QStringList& tagFilters);
215 
216 private:
217 
218  QString getExifTagStringFromTagsList(const QStringList& tagsList) const;
219 
220 public: // IPTC helpers
221 
222  IptcCoreContactInfo getCreatorContactInfo() const;
223  bool setCreatorContactInfo(const IptcCoreContactInfo& info) const;
224 
225  IptcCoreLocationInfo getIptcCoreLocation() const;
226  bool setIptcCoreLocation(const IptcCoreLocationInfo& location) const;
227 
228  QStringList getIptcCoreSubjects() const;
229 
230  bool removeIptcTags(const QStringList& tagFilters);
231 
232  static CountryCodeMap countryCodeMap();
233 
234 private:
235 
236  bool setIptcTag(const QString& text,
237  int maxLength,
238  const char* const debugLabel,
239  const char* const tagKey) const;
240 
241  QVariant fromIptcEmulateList(const char* const iptcTagName) const;
242  QVariant fromIptcEmulateLangAlt(const char* const iptcTagName) const;
243 
244 public: // XMP helpers
245 
252  bool addToXmpTagStringBag(const char* const xmpTagName, const QStringList& entriesToAdd) const;
253 
259  bool removeFromXmpTagStringBag(const char* const xmpTagName, const QStringList& entriesToRemove) const;
260 
264  QStringList getXmpKeywords() const;
265 
272  bool setXmpKeywords(const QStringList& newKeywords) const;
273 
278  bool removeXmpKeywords(const QStringList& keywordsToRemove);
279 
283  QStringList getXmpSubjects() const;
284 
291  bool setXmpSubjects(const QStringList& newSubjects) const;
292 
297  bool removeXmpSubjects(const QStringList& subjectsToRemove);
298 
303  QStringList getXmpSubCategories() const;
304 
311  bool setXmpSubCategories(const QStringList& newSubCategories) const;
312 
317  bool removeXmpSubCategories(const QStringList& categoriesToRemove);
318 
319  bool removeXmpTags(const QStringList& tagFilters);
320 
321 private:
322 
323  QVariant fromXmpList(const char* const xmpTagName) const;
324  QVariant fromXmpLangAlt(const char* const xmpTagName) const;
325 
326 public: // Video helpers
327 
331  bool loadUsingFFmpeg(const QString& filePath);
332 
336  VideoInfoContainer getVideoInformation() const;
337 
341  static QString videoColorModelToString(VIDEOCOLORMODEL videoColorModel);
342 
343 public: // Photo helpers
344 
352  QString getLensDescription() const;
353 
357  QString getCameraSerialNumber() const;
358 
359  PhotoInfoContainer getPhotographInformation() const;
360 
361  static double apexApertureToFNumber(double aperture);
362  static double apexShutterSpeedToExposureTime(double shutterSpeed);
363 
364 public: // Generic helpers
365 
370  QVariant getMetadataField(MetadataInfo::Field field) const;
371  QVariantList getMetadataFields(const MetadataFields& fields) const;
372 
377  static QString valueToString (const QVariant& value, MetadataInfo::Field field);
378  static QStringList valuesToString(const QVariantList& list, const MetadataFields& fields);
379 
384  static QMap<int, QString> possibleValuesForEnumField(MetadataInfo::Field field);
385 
386 private:
387 
388  QVariant fromExifOrXmp(const char* const exifTagName, const char* const xmpTagName) const;
389  QVariant fromIptcOrXmp(const char* const iptcTagName, const char* const xmpTagName) const;
390  QVariant fromExifOrXmpList(const QStringList& tagList) const;
391  bool hasValidField(const QVariantList& list) const;
392  QVariant toStringListVariant(const QStringList& list) const;
393 
394 private:
395 
399  bool loadUsingLibheif(const QString& filePath);
400 
401 private:
402 
406  bool loadUsingImageMagick(const QString& filePath);
407 };
408 
409 } // namespace Digikam
410 
411 #endif // DIGIKAM_DMETA_DATA_H
Definition: captionvalues.h:69
Definition: dmetadatasettingscontainer.h:164
static DMetadataSettings * instance()
Definition: dmetadatasettings.cpp:107
Definition: dmetadata.h:55
VIDEOCOLORMODEL
Definition: dmetadata.h:64
@ VIDEOCOLORMODEL_BT709
Definition: dmetadata.h:68
@ VIDEOCOLORMODEL_SRGB
Definition: dmetadata.h:67
@ VIDEOCOLORMODEL_OTHER
Definition: dmetadata.h:66
QMap< QString, QString > CountryCodeMap
Definition: dmetadata.h:74
Definition: iccprofile.h:43
Definition: metadatainfo.h:63
Definition: metadatainfo.h:41
Definition: metaengine_data.h:41
Definition: metaenginesettingscontainer.h:48
Definition: metaengine.h:58
Backend
Definition: metaengine.h:124
QMap< QString, QString > AltLangMap
Definition: metaengine.h:143
Definition: photoinfocontainer.h:41
Definition: template.h:46
Definition: videoinfocontainer.h:41
Definition: piwigotalker.h:48
qulonglong value
Definition: itemviewutilities.cpp:592
Field
Definition: metadatainfo.h:91
std::vector< T > location(const std::vector< T > &shape, unsigned long idx)
Definition: shapepredictor.h:109
Definition: datefolderview.cpp:43