digiKam
metaengine_p.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-09-15
7  * Description : Exiv2 library interface.
8  * Internal private container.
9  *
10  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2006-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
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_META_ENGINE_PRIVATE_H
27 #define DIGIKAM_META_ENGINE_PRIVATE_H
28 
29 #include "metaengine.h"
30 
31  // C++ includes
32 
33 #include <cstdlib>
34 #include <cstdio>
35 #include <cmath>
36 #include <cfloat>
37 #include <iostream>
38 #include <iomanip>
39 #include <string>
40 #include <memory>
41 
42 // Qt includes
43 
44 #include <QFile>
45 #include <QSize>
46 #include <QLatin1String>
47 #include <QFileInfo>
48 #include <QSharedData>
49 #include <QMutexLocker>
50 #include <QRecursiveMutex>
51 #include <QMimeDatabase>
52 
53 // Exiv2 includes -------------------------------------------------------
54 
55 // NOTE: All Exiv2 headers must be stay there to not expose external source code to Exiv2 API
56 // and reduce Exiv2 dependency to client code.
57 
58 #if defined(Q_CC_CLANG)
59 # pragma clang diagnostic push
60 # pragma clang diagnostic ignored "-Wdeprecated-declarations"
61 #endif
62 
63 // The pragmas are required to be able to catch exceptions thrown by libexiv2:
64 // See gcc.gnu.org/wiki/Visibility, the section about c++ exceptions.
65 // They are needed for all libexiv2 versions that do not care about visibility.
66 
67 #ifdef Q_CC_GNU
68 # pragma GCC visibility push(default)
69 #endif
70 
71 #include <exiv2/exv_conf.h>
72 #include <exiv2/error.hpp>
73 #include <exiv2/convert.hpp>
74 #include <exiv2/image.hpp>
75 #include <exiv2/jpgimage.hpp>
76 #include <exiv2/datasets.hpp>
77 #include <exiv2/tags.hpp>
78 #include <exiv2/preview.hpp>
79 #include <exiv2/properties.hpp>
80 #include <exiv2/types.hpp>
81 #include <exiv2/exif.hpp>
82 #include <exiv2/xmpsidecar.hpp>
83 #include <exiv2/version.hpp>
84 
85 // Check if Exiv2 support XMP
86 
87 #ifdef EXV_HAVE_XMP_TOOLKIT
88 # define _XMP_SUPPORT_ 1
89 #endif
90 
91 #ifndef EXIV2_TEST_VERSION
92 # define EXIV2_TEST_VERSION(major,minor,patch) \
93  ( EXIV2_VERSION >= EXIV2_MAKE_VERSION(major,minor,patch) )
94 #endif
95 
96 #if EXIV2_TEST_VERSION(0,27,99)
97 # define AutoPtr UniquePtr
98 #endif
99 
100 #if EXIV2_TEST_VERSION(0,27,4)
101 # include <exiv2/bmffimage.hpp>
102 #endif
103 
104 // With exiv2 > 0.20.0, all makernote header files have been removed to increase binary compatibility.
105 // See Exiv2 bugzilla entry dev.exiv2.org/issues/719
106 // and wiki topic dev.exiv2.org/boards/3/topics/583
107 
108 #ifdef Q_CC_GNU
109 # pragma GCC visibility pop
110 #endif
111 
112 // End of Exiv2 headers ------------------------------------------------------
113 
114 // Local includes
115 
116 #include "metaengine_mergehelper.h"
117 
118 namespace Digikam
119 {
120 
121 extern QRecursiveMutex s_metaEngineMutex;
122 extern bool s_metaEngineSupportBmff;
123 
124 // --------------------------------------------------------------------------
125 
126 class Q_DECL_HIDDEN MetaEngine::Private
127 {
128 public:
129 
130  explicit Private();
131  ~Private();
132 
133  void copyPrivateData(const Private* const other);
134 
135  bool saveToXMPSidecar(const QFileInfo& finfo) const;
136  bool saveToFile(const QFileInfo& finfo) const;
137  bool saveOperations(const QFileInfo& finfo, Exiv2::Image::AutoPtr image) const;
138 
142  QString convertCommentValue(const Exiv2::Exifdatum& exifDatum) const;
143 
147  QString detectEncodingAndDecode(const std::string& value) const;
148 
152  bool isUtf8(const char* const buffer) const;
153 
154  int getXMPTagsListFromPrefix(const QString& pf, MetaEngine::TagsMap& tagsMap) const;
155 
156  const Exiv2::ExifData& exifMetadata() const;
157  const Exiv2::IptcData& iptcMetadata() const;
158  const std::string& itemComments() const;
159 
160  Exiv2::ExifData& exifMetadata();
161  Exiv2::IptcData& iptcMetadata();
162  std::string& itemComments();
163 
164 public:
165 
166 #ifdef _XMP_SUPPORT_
167 
168  const Exiv2::XmpData& xmpMetadata() const;
169  Exiv2::XmpData& xmpMetadata();
170 
171  void loadSidecarData(Exiv2::Image::AutoPtr xmpsidecar);
172 
173 #endif
174 
175 public:
176 
180  QString extractIptcTagString(const Exiv2::IptcData& iptcData, const Exiv2::Iptcdatum& iptcTag) const;
181 
182 public:
183 
188  static void printExiv2ExceptionError(const QString& msg, Exiv2::AnyError& e);
189 
194  static void printExiv2MessageHandler(int lvl, const char* msg);
195 
196 public:
197 
201 
204 
207 
210 
211  QString filePath;
212  QSize pixelSize;
213  QString mimeType;
214 
215  QExplicitlySharedDataPointer<MetaEngineData::Private> data;
216 };
217 
218 } // namespace Digikam
219 
220 #if defined(Q_CC_CLANG)
221 # pragma clang diagnostic pop
222 #endif
223 
224 #endif // DIGIKAM_META_ENGINE_PRIVATE_H
Definition: metaengine_p.h:127
QString filePath
Definition: metaengine_p.h:211
QSize pixelSize
Definition: metaengine_p.h:212
QExplicitlySharedDataPointer< MetaEngineData::Private > data
Definition: metaengine_p.h:215
bool useXMPSidecar4Reading
Definition: metaengine_p.h:202
QString mimeType
Definition: metaengine_p.h:213
bool useCompatibleFileName
Definition: metaengine_p.h:203
bool updateFileTimeStamp
Definition: metaengine_p.h:200
bool writeDngFiles
Definition: metaengine_p.h:199
int metadataWritingMode
A mode from MetadataWritingMode enum.
Definition: metaengine_p.h:206
bool loadedFromSidecar
XMP, and parts of EXIF/IPTC, were loaded from an XMP sidecar file.
Definition: metaengine_p.h:209
bool writeRawFiles
Definition: metaengine_p.h:198
Definition: metaengine.h:58
QMap< QString, QStringList > TagsMap
Definition: metaengine.h:151
qulonglong value
Definition: itemviewutilities.cpp:592
#define AutoPtr
Definition: metaengine_p.h:97
Definition: datefolderview.cpp:43
bool s_metaEngineSupportBmff
Flag for Exiv2 Base Media File Format support.
Definition: metaengine_p.cpp:79
QRecursiveMutex s_metaEngineMutex
Mutex to fix no re-entrancy from Exiv2.
Definition: metaengine_p.cpp:73