File indexing completed on 2025-01-19 03:55:57

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-02-23
0007  * Description : item metadata interface - history helpers.
0008  *
0009  * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2006-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0011  * SPDX-FileCopyrightText: 2011      by Leif Huhn <leif at dkstat dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #include "dmetadata.h"
0018 
0019 // Local includes
0020 
0021 #include "metaenginesettings.h"
0022 #include "digikam_version.h"
0023 #include "digikam_globals.h"
0024 #include "digikam_debug.h"
0025 
0026 namespace Digikam
0027 {
0028 
0029 bool DMetadata::setItemHistory(const QString& imageHistoryXml) const
0030 {
0031     if (supportXmp())
0032     {
0033         if (!setXmpTagString("Xmp.digiKam.ImageHistory", imageHistoryXml))
0034         {
0035             return false;
0036         }
0037         else
0038         {
0039             return true;
0040         }
0041     }
0042 
0043     return false;
0044 }
0045 
0046 QString DMetadata::getItemHistory() const
0047 {
0048     if (hasXmp())
0049     {
0050         QString value = getXmpTagString("Xmp.digiKam.ImageHistory", false);
0051 /*
0052         qCDebug(DIGIKAM_METAENGINE_LOG) << "Loading image history " << value;
0053 */
0054         return value;
0055     }
0056 
0057     return QString();
0058 }
0059 
0060 bool DMetadata::hasItemHistoryTag() const
0061 {
0062     if (hasXmp())
0063     {
0064         if (QString(getXmpTagString("Xmp.digiKam.ImageHistory", false)).length() > 0)
0065         {
0066             return true;
0067         }
0068         else
0069         {
0070             return false;
0071         }
0072     }
0073 
0074     return false;
0075 }
0076 
0077 QString DMetadata::getItemUniqueId() const
0078 {
0079     QString exifUid;
0080 
0081     if (hasXmp())
0082     {
0083         QString uuid = getXmpTagString("Xmp.digiKam.ImageUniqueID");
0084 
0085         if (!uuid.isEmpty())
0086         {
0087             return uuid;
0088         }
0089 
0090         exifUid = getXmpTagString("Xmp.exif.ImageUniqueId");
0091     }
0092 
0093     if (exifUid.isEmpty())
0094     {
0095         exifUid = getExifTagString("Exif.Photo.ImageUniqueID");
0096     }
0097 
0098     // same makers may choose to use a "click counter" to generate the id,
0099     // which is then weak and not a universally unique id
0100     // The Exif ImageUniqueID is 128bit, or 32 hex digits.
0101     // If the first 20 are zero, it's probably a counter,
0102     // the left 12 are sufficient for more then 10^14 clicks.
0103 
0104     if (!exifUid.isEmpty()                                         &&
0105         !exifUid.startsWith(QLatin1String("00000000000000000000")) &&
0106         !getExifTagString("Exif.Image.Make").contains(QLatin1String("SAMSUNG"), Qt::CaseInsensitive))
0107     {
0108         return exifUid;
0109     }
0110 
0111     // Exif.Image.ImageID can also be a pathname, so it's not sufficiently unique
0112 
0113     QString dngUid = getExifTagString("Exif.Image.RawDataUniqueID");
0114 
0115     if (!dngUid.isEmpty())
0116     {
0117         return dngUid;
0118     }
0119 
0120     return QString();
0121 }
0122 
0123 bool DMetadata::setItemUniqueId(const QString& uuid) const
0124 {
0125     if (supportXmp())
0126     {
0127         return setXmpTagString("Xmp.digiKam.ImageUniqueID", uuid);
0128     }
0129 
0130     return false;
0131 }
0132 
0133 } // namespace Digikam