File indexing completed on 2025-04-27 03:58:35

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-07-19
0007  * Description : A widget to display XMP metadata
0008  *
0009  * SPDX-FileCopyrightText: 2007-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "xmpwidget.h"
0016 
0017 // Qt includes
0018 
0019 #include <QMap>
0020 #include <QFile>
0021 #include <QScopedPointer>
0022 
0023 // KDE includes
0024 
0025 #include <klocalizedstring.h>
0026 
0027 // Local includes
0028 
0029 #include "dmetadata.h"
0030 
0031 namespace Digikam
0032 {
0033 
0034 namespace
0035 {
0036 
0037 static const char* StandardXmpEntryList[] =
0038 {
0039 
0040     "acdsee",          ///< Schema for ACDSee.
0041     "audio",           ///< Exiv2 Audio Metadata Schema
0042     "aux",             ///< Schema for Additional Exif Properties.
0043     "crs",             ///< Camera Raw schema.
0044     "dc",              ///< Dublin Core schema.
0045     "digiKam",         ///< Our Xmp schema used to store private information (see MetaEngine classes for details).
0046     "dwc",             ///< Qualified Dublin Core schema.
0047     "exif",            ///< Schema for Exif-specific Properties.
0048     "iptc",            ///< IPTC Core schema.
0049     "iptcExt",         ///< IPTC Extension schema.
0050     "kipi",            ///< Xmp schema used to store private information from tools.
0051     "lr",              ///< Adobe LightRoom schema.
0052     "MicrosoftPhoto",  ///< Microsoft schema.
0053     "MP",              ///< Microsoft Photo 1.2 schema.
0054     "mwg-rs",          ///< Metadata Working Group schema.
0055     "pdf",             ///< Adobe PDF schema.
0056     "photoshop",       ///< Adobe Photoshop schema.
0057     "plus",            ///< PLUS License Data Format Schema.
0058     "tiff",            ///< Schema for TIFF Properties
0059     "video",           ///< Exiv2 Video Metadata Schema
0060     "xmp",             ///< Basic schema.
0061     "xmpBJ",           ///< Basic Job Ticket schema.
0062     "xmpDM",           ///< Dynamic Media schema.
0063     "xmpMM",           ///< Media Management schema.
0064     "xmpRights",       ///< Rights Management schema.
0065     "xmpTPg",          ///< Paged-Text schema.
0066 
0067     "-1"
0068 };
0069 
0070 } // namespace
0071 
0072 XmpWidget::XmpWidget(QWidget* const parent, const QString& name)
0073     : MetadataWidget(parent, name)
0074 {
0075     setup();
0076 
0077     for (int i = 0 ; QLatin1String(StandardXmpEntryList[i]) != QLatin1String("-1") ; ++i)
0078     {
0079         m_keysFilter << QLatin1String(StandardXmpEntryList[i]);
0080     }
0081 }
0082 
0083 XmpWidget::~XmpWidget()
0084 {
0085 }
0086 
0087 QString XmpWidget::getMetadataTitle() const
0088 {
0089     return i18n("XMP Schema");
0090 }
0091 
0092 bool XmpWidget::loadFromURL(const QUrl& url)
0093 {
0094     setFileName(url.fileName());
0095 
0096     if (url.isEmpty())
0097     {
0098         setMetadata();
0099         return false;
0100     }
0101     else
0102     {
0103         QScopedPointer<DMetadata> metadata(new DMetadata(url.toLocalFile()));
0104 
0105         if (!metadata->hasXmp())
0106         {
0107             setMetadata();
0108             return false;
0109         }
0110         else
0111         {
0112             setMetadata(*metadata);
0113         }
0114     }
0115 
0116     return true;
0117 }
0118 
0119 bool XmpWidget::decodeMetadata()
0120 {
0121     QScopedPointer<DMetadata> data(new DMetadata(getMetadata()->data()));
0122 
0123     if (!data->hasXmp())
0124     {
0125         return false;
0126     }
0127 
0128     // Update all metadata contents.
0129 
0130     setMetadataMap(data->getXmpTagsDataList(QStringList()));
0131 
0132     return true;
0133 }
0134 
0135 void XmpWidget::buildView()
0136 {
0137     switch (getMode())
0138     {
0139         case CUSTOM:
0140         {
0141             setIfdList(getMetadataMap(), m_keysFilter, getTagsFilter());
0142             break;
0143         }
0144 
0145         case PHOTO:
0146         {
0147             setIfdList(getMetadataMap(), m_keysFilter, QStringList() << QLatin1String("FULL"));
0148             break;
0149         }
0150 
0151         default: // NONE
0152         {
0153             setIfdList(getMetadataMap(), QStringList());
0154             break;
0155         }
0156     }
0157 
0158     MetadataWidget::buildView();
0159 }
0160 
0161 QString XmpWidget::getTagTitle(const QString& key)
0162 {
0163     QScopedPointer<DMetadata> metadataIface(new DMetadata);
0164     QString title = metadataIface->getXmpTagTitle(key.toLatin1().constData());
0165 
0166     if (title.isEmpty())
0167     {
0168         return key.section(QLatin1Char('.'), -1);
0169     }
0170 
0171     return title;
0172 }
0173 
0174 QString XmpWidget::getTagDescription(const QString& key)
0175 {
0176     QScopedPointer<DMetadata> metadataIface(new DMetadata);
0177     QString desc = metadataIface->getXmpTagDescription(key.toLatin1().constData());
0178 
0179     if (desc.isEmpty())
0180     {
0181         return i18n("No description available");
0182     }
0183 
0184     return desc;
0185 }
0186 
0187 void XmpWidget::slotSaveMetadataToFile()
0188 {
0189     QUrl url = saveMetadataToFile(i18n("XMP File to Save"),
0190                                   QString(QLatin1String("*.xmp|") + i18n("XMP text Files (*.xmp)")));
0191     storeMetadataToFile(url, getMetadata()->getXmp());
0192 }
0193 
0194 } // namespace Digikam
0195 
0196 #include "moc_xmpwidget.cpp"