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 non standard Exif metadata 0008 * used by camera makers 0009 * 0010 * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "makernotewidget.h" 0017 0018 // Qt includes 0019 0020 #include <QMap> 0021 #include <QFile> 0022 #include <QScopedPointer> 0023 0024 // KDE includes 0025 0026 #include <klocalizedstring.h> 0027 0028 // Local includes 0029 0030 #include "dmetadata.h" 0031 0032 namespace Digikam 0033 { 0034 0035 namespace 0036 { 0037 0038 static const char* ExifEntryListToIgnore[] = 0039 { 0040 "GPSInfo", 0041 "Iop", 0042 "Thumbnail", 0043 "SubImage1", 0044 "SubImage2", 0045 "Image", 0046 "Photo", 0047 "-1" 0048 }; 0049 0050 } // namespace 0051 0052 MakerNoteWidget::MakerNoteWidget(QWidget* const parent, const QString& name) 0053 : MetadataWidget(parent, name) 0054 { 0055 setup(); 0056 0057 for (int i = 0 ; QLatin1String(ExifEntryListToIgnore[i]) != QLatin1String("-1") ; ++i) 0058 { 0059 m_keysFilter << QLatin1String(ExifEntryListToIgnore[i]); 0060 } 0061 } 0062 0063 MakerNoteWidget::~MakerNoteWidget() 0064 { 0065 } 0066 0067 QString MakerNoteWidget::getMetadataTitle() const 0068 { 0069 return i18n("MakerNote Exif Tags"); 0070 } 0071 0072 bool MakerNoteWidget::loadFromURL(const QUrl& url) 0073 { 0074 setFileName(url.toLocalFile()); 0075 0076 if (url.isEmpty()) 0077 { 0078 setMetadata(); 0079 return false; 0080 } 0081 else 0082 { 0083 QScopedPointer<DMetadata> metadata(new DMetadata(url.toLocalFile())); 0084 0085 if (!metadata->hasExif()) 0086 { 0087 setMetadata(); 0088 return false; 0089 } 0090 else 0091 { 0092 setMetadata(*metadata); 0093 } 0094 } 0095 0096 return true; 0097 } 0098 0099 bool MakerNoteWidget::decodeMetadata() 0100 { 0101 QScopedPointer<DMetadata> data(new DMetadata(getMetadata()->data())); 0102 0103 if (!data->hasExif()) 0104 { 0105 return false; 0106 } 0107 0108 // Update all metadata contents. 0109 0110 setMetadataMap(data->getExifTagsDataList(m_keysFilter, 0111 true, 0112 false)); // Do not extract binary data which can introduce time latency in GUI. 0113 0114 return true; 0115 } 0116 0117 void MakerNoteWidget::buildView() 0118 { 0119 switch (getMode()) 0120 { 0121 case CUSTOM: 0122 { 0123 setIfdList(getMetadataMap(), getTagsFilter()); 0124 break; 0125 } 0126 0127 case PHOTO: 0128 { 0129 setIfdList(getMetadataMap(), QStringList() << QLatin1String("FULL")); 0130 break; 0131 } 0132 0133 default: // NONE 0134 { 0135 setIfdList(getMetadataMap(), QStringList()); 0136 break; 0137 } 0138 } 0139 0140 MetadataWidget::buildView(); 0141 } 0142 0143 QString MakerNoteWidget::getTagTitle(const QString& key) 0144 { 0145 QScopedPointer<DMetadata> metadataIface(new DMetadata); 0146 QString title = metadataIface->getExifTagTitle(key.toLatin1().constData()); 0147 0148 if (title.isEmpty()) 0149 { 0150 return key.section(QLatin1Char('.'), -1); 0151 } 0152 0153 return title; 0154 } 0155 0156 QString MakerNoteWidget::getTagDescription(const QString& key) 0157 { 0158 QScopedPointer<DMetadata> metadataIface(new DMetadata); 0159 QString desc = metadataIface->getExifTagDescription(key.toLatin1().constData()); 0160 0161 if (desc.isEmpty()) 0162 { 0163 return i18n("No description available"); 0164 } 0165 0166 return desc; 0167 } 0168 0169 void MakerNoteWidget::slotSaveMetadataToFile() 0170 { 0171 QUrl url = saveMetadataToFile(i18n("EXIF File to Save"), 0172 QString(QLatin1String("*.exif|") + i18n("EXIF binary Files (*.exif)"))); 0173 0174 storeMetadataToFile(url, getMetadata()->getExifEncoded()); 0175 } 0176 0177 } // namespace Digikam 0178 0179 #include "moc_makernotewidget.cpp"