File indexing completed on 2025-04-27 03:58:34
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2006-02-20 0007 * Description : A widget to display IPTC metadata 0008 * 0009 * SPDX-FileCopyrightText: 2006-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 "iptcwidget.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 0032 { 0033 0034 static const char* StandardIptcEntryList[] = 0035 { 0036 "Envelope", 0037 "Application2", 0038 "-1" 0039 }; 0040 0041 } // namespace 0042 0043 namespace Digikam 0044 { 0045 0046 IptcWidget::IptcWidget(QWidget* const parent, const QString& name) 0047 : MetadataWidget(parent, name) 0048 { 0049 setup(); 0050 0051 for (int i = 0 ; QLatin1String(StandardIptcEntryList[i]) != QLatin1String("-1") ; ++i) 0052 { 0053 m_keysFilter << QLatin1String(StandardIptcEntryList[i]); 0054 } 0055 } 0056 0057 IptcWidget::~IptcWidget() 0058 { 0059 } 0060 0061 QString IptcWidget::getMetadataTitle() const 0062 { 0063 return i18n("IPTC Records"); 0064 } 0065 0066 bool IptcWidget::loadFromURL(const QUrl& url) 0067 { 0068 setFileName(url.fileName()); 0069 0070 if (url.isEmpty()) 0071 { 0072 setMetadata(); 0073 return false; 0074 } 0075 else 0076 { 0077 QScopedPointer<DMetadata> metadata(new DMetadata(url.toLocalFile())); 0078 0079 if (!metadata->hasIptc()) 0080 { 0081 setMetadata(); 0082 return false; 0083 } 0084 else 0085 { 0086 setMetadata(*metadata); 0087 } 0088 } 0089 0090 return true; 0091 } 0092 0093 bool IptcWidget::decodeMetadata() 0094 { 0095 QScopedPointer<DMetadata> data(new DMetadata(getMetadata()->data())); 0096 0097 if (!data->hasIptc()) 0098 { 0099 return false; 0100 } 0101 0102 // Update all metadata contents. 0103 0104 setMetadataMap(data->getIptcTagsDataList(m_keysFilter)); 0105 0106 return true; 0107 } 0108 0109 void IptcWidget::buildView() 0110 { 0111 switch (getMode()) 0112 { 0113 case CUSTOM: 0114 { 0115 setIfdList(getMetadataMap(), m_keysFilter, getTagsFilter()); 0116 break; 0117 } 0118 0119 case PHOTO: 0120 { 0121 setIfdList(getMetadataMap(), m_keysFilter, QStringList() << QLatin1String("FULL")); 0122 break; 0123 } 0124 0125 default: // NONE 0126 { 0127 setIfdList(getMetadataMap(), QStringList()); 0128 break; 0129 } 0130 } 0131 0132 MetadataWidget::buildView(); 0133 } 0134 0135 QString IptcWidget::getTagTitle(const QString& key) 0136 { 0137 QScopedPointer<DMetadata> metadataIface(new DMetadata); 0138 QString title = metadataIface->getIptcTagTitle(key.toLatin1().constData()); 0139 0140 if (title.isEmpty()) 0141 { 0142 return key.section(QLatin1Char('.'), -1); 0143 } 0144 0145 return title; 0146 } 0147 0148 QString IptcWidget::getTagDescription(const QString& key) 0149 { 0150 QScopedPointer<DMetadata> metadataIface(new DMetadata); 0151 QString desc = metadataIface->getIptcTagDescription(key.toLatin1().constData()); 0152 0153 if (desc.isEmpty()) 0154 { 0155 return i18n("No description available"); 0156 } 0157 0158 return desc; 0159 } 0160 0161 void IptcWidget::slotSaveMetadataToFile() 0162 { 0163 QUrl url = saveMetadataToFile(i18n("IPTC File to Save"), 0164 QString(QLatin1String("*.iptc|") + i18n("IPTC binary Files (*.iptc)"))); 0165 storeMetadataToFile(url, getMetadata()->getIptc()); 0166 } 0167 0168 } // namespace Digikam 0169 0170 #include "moc_iptcwidget.cpp"