File indexing completed on 2025-01-05 03:56:25
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 - Xmp 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 // Qt includes 0020 0021 #include <QLocale> 0022 0023 // Local includes 0024 0025 #include "metaenginesettings.h" 0026 #include "digikam_version.h" 0027 #include "digikam_globals.h" 0028 #include "digikam_debug.h" 0029 0030 namespace Digikam 0031 { 0032 0033 QVariant DMetadata::fromXmpList(const char* const xmpTagName) const 0034 { 0035 QVariant var = getXmpTagVariant(xmpTagName); 0036 0037 if (var.isNull()) 0038 { 0039 0040 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) 0041 0042 return QVariant(QMetaType(QMetaType::QStringList)); 0043 0044 #else 0045 0046 return QVariant(QVariant::StringList); 0047 0048 #endif 0049 0050 } 0051 0052 return var; 0053 } 0054 0055 QVariant DMetadata::fromXmpLangAlt(const char* const xmpTagName) const 0056 { 0057 QVariant var = getXmpTagVariant(xmpTagName); 0058 0059 if (var.isNull()) 0060 { 0061 0062 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) 0063 0064 return QVariant(QMetaType(QMetaType::QVariantMap)); 0065 0066 #else 0067 0068 return QVariant(QVariant::Map); 0069 0070 #endif 0071 0072 } 0073 0074 return var; 0075 } 0076 0077 bool DMetadata::addToXmpTagStringBag(const char* const xmpTagName, const QStringList& entriesToAdd) const 0078 { 0079 QStringList oldEntries = getXmpTagStringBag(xmpTagName, false); 0080 QStringList newEntries = entriesToAdd; 0081 0082 // Create a list of keywords including old one which already exists. 0083 0084 for (QStringList::const_iterator it = oldEntries.constBegin() ; it != oldEntries.constEnd() ; ++it ) 0085 { 0086 if (!newEntries.contains(*it)) 0087 { 0088 newEntries.append(*it); 0089 } 0090 } 0091 0092 if (setXmpTagStringBag(xmpTagName, newEntries)) 0093 { 0094 return true; 0095 } 0096 0097 return false; 0098 } 0099 0100 bool DMetadata::removeFromXmpTagStringBag(const char* const xmpTagName, const QStringList& entriesToRemove) const 0101 { 0102 QStringList currentEntries = getXmpTagStringBag(xmpTagName, false); 0103 QStringList newEntries; 0104 0105 // Create a list of current keywords except those that shall be removed 0106 0107 for (QStringList::const_iterator it = currentEntries.constBegin() ; it != currentEntries.constEnd() ; ++it ) 0108 { 0109 if (!entriesToRemove.contains(*it)) 0110 { 0111 newEntries.append(*it); 0112 } 0113 } 0114 0115 if (setXmpTagStringBag(xmpTagName, newEntries)) 0116 { 0117 return true; 0118 } 0119 0120 return false; 0121 } 0122 0123 QStringList DMetadata::getXmpKeywords() const 0124 { 0125 return (getXmpTagStringBag("Xmp.dc.subject", false)); 0126 } 0127 0128 bool DMetadata::setXmpKeywords(const QStringList& newKeywords) const 0129 { 0130 return setXmpTagStringBag("Xmp.dc.subject", newKeywords); 0131 } 0132 0133 bool DMetadata::removeXmpKeywords(const QStringList& keywordsToRemove) 0134 { 0135 return removeFromXmpTagStringBag("Xmp.dc.subject", keywordsToRemove); 0136 } 0137 0138 QStringList DMetadata::getXmpSubCategories() const 0139 { 0140 return (getXmpTagStringBag("Xmp.photoshop.SupplementalCategories", false)); 0141 } 0142 0143 bool DMetadata::setXmpSubCategories(const QStringList& newSubCategories) const 0144 { 0145 return addToXmpTagStringBag("Xmp.photoshop.SupplementalCategories", newSubCategories); 0146 } 0147 0148 bool DMetadata::removeXmpSubCategories(const QStringList& subCategoriesToRemove) 0149 { 0150 return removeFromXmpTagStringBag("Xmp.photoshop.SupplementalCategories", subCategoriesToRemove); 0151 } 0152 0153 QStringList DMetadata::getXmpSubjects() const 0154 { 0155 return (getXmpTagStringBag("Xmp.iptc.SubjectCode", false)); 0156 } 0157 0158 bool DMetadata::setXmpSubjects(const QStringList& newSubjects) const 0159 { 0160 return addToXmpTagStringBag("Xmp.iptc.SubjectCode", newSubjects); 0161 } 0162 0163 bool DMetadata::removeXmpSubjects(const QStringList& subjectsToRemove) 0164 { 0165 return removeFromXmpTagStringBag("Xmp.iptc.SubjectCode", subjectsToRemove); 0166 } 0167 0168 bool DMetadata::removeXmpTags(const QStringList& tagFilters) 0169 { 0170 MetaDataMap m = getXmpTagsDataList(tagFilters); 0171 0172 if (m.isEmpty()) 0173 { 0174 return false; 0175 } 0176 0177 for (MetaDataMap::iterator it = m.begin() ; it != m.end() ; ++it) 0178 { 0179 removeXmpTag(it.key().toLatin1().constData()); 0180 } 0181 0182 return true; 0183 } 0184 0185 } // namespace Digikam