File indexing completed on 2025-01-19 03:56:17
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2004-11-17 0007 * Description : a tab to display item metadata information 0008 * 0009 * SPDX-FileCopyrightText: 2004-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 "itempropertiesmetadatatab.h" 0016 0017 // Qt includes 0018 0019 #include <QFile> 0020 #include <QLabel> 0021 #include <QPixmap> 0022 #include <QFileInfo> 0023 #include <QVBoxLayout> 0024 #include <QScopedPointer> 0025 #include <QElapsedTimer> 0026 0027 // KDE includes 0028 0029 #include <klocalizedstring.h> 0030 #include <ksharedconfig.h> 0031 #include <kconfiggroup.h> 0032 0033 // Local includes 0034 0035 #include "digikam_debug.h" 0036 #include "metadatapanel.h" 0037 #include "exifwidget.h" 0038 #include "makernotewidget.h" 0039 #include "iptcwidget.h" 0040 #include "xmpwidget.h" 0041 #include "exiftoolwidget.h" 0042 0043 namespace Digikam 0044 { 0045 0046 class Q_DECL_HIDDEN ItemPropertiesMetadataTab::Private 0047 { 0048 public: 0049 0050 enum MetadataTab 0051 { 0052 EXIF = 0, 0053 MAKERNOTE, 0054 IPTC, 0055 XMP, 0056 EXIFTOOL 0057 }; 0058 0059 explicit Private() 0060 : exifWidget (nullptr), 0061 makernoteWidget(nullptr), 0062 iptcWidget (nullptr), 0063 xmpWidget (nullptr), 0064 exifToolWidget (nullptr) 0065 { 0066 } 0067 0068 ExifWidget* exifWidget; 0069 MakerNoteWidget* makernoteWidget; 0070 IptcWidget* iptcWidget; 0071 XmpWidget* xmpWidget; 0072 ExifToolWidget* exifToolWidget; 0073 }; 0074 0075 ItemPropertiesMetadataTab::ItemPropertiesMetadataTab(QWidget* const parent) 0076 : QTabWidget(parent), 0077 d (new Private) 0078 { 0079 // Exif tab area --------------------------------------- 0080 0081 d->exifWidget = new ExifWidget(this); 0082 insertTab(Private::EXIF, d->exifWidget, i18n("EXIF")); 0083 0084 // Makernote tab area ---------------------------------- 0085 0086 d->makernoteWidget = new MakerNoteWidget(this); 0087 insertTab(Private::MAKERNOTE, d->makernoteWidget, i18n("Makernote")); 0088 0089 // IPTC tab area --------------------------------------- 0090 0091 d->iptcWidget = new IptcWidget(this); 0092 insertTab(Private::IPTC, d->iptcWidget, i18n("IPTC")); 0093 0094 // XMP tab area ---------------------------------------- 0095 0096 d->xmpWidget = new XmpWidget(this); 0097 0098 if (DMetadata::supportXmp()) 0099 { 0100 insertTab(Private::XMP, d->xmpWidget, i18n("XMP")); 0101 } 0102 else 0103 { 0104 d->xmpWidget->hide(); 0105 } 0106 0107 // ExifTool tab area ---------------------------------- 0108 0109 d->exifToolWidget = new ExifToolWidget(this); 0110 insertTab(Private::EXIFTOOL, d->exifToolWidget, QLatin1String("ExifTool")); // No i18n here. 0111 0112 connect(d->exifToolWidget, SIGNAL(signalSetupExifTool()), 0113 this, SIGNAL(signalSetupExifTool())); 0114 0115 // --- 0116 0117 connect(d->exifWidget, SIGNAL(signalSetupMetadataFilters()), 0118 this, SLOT(slotSetupMetadataFilters())); 0119 0120 connect(d->makernoteWidget, SIGNAL(signalSetupMetadataFilters()), 0121 this, SLOT(slotSetupMetadataFilters())); 0122 0123 connect(d->iptcWidget, SIGNAL(signalSetupMetadataFilters()), 0124 this, SLOT(slotSetupMetadataFilters())); 0125 0126 connect(d->xmpWidget, SIGNAL(signalSetupMetadataFilters()), 0127 this, SLOT(slotSetupMetadataFilters())); 0128 0129 connect(d->exifToolWidget, SIGNAL(signalSetupMetadataFilters()), 0130 this, SLOT(slotSetupMetadataFilters())); 0131 } 0132 0133 ItemPropertiesMetadataTab::~ItemPropertiesMetadataTab() 0134 { 0135 delete d; 0136 } 0137 0138 void ItemPropertiesMetadataTab::slotSetupMetadataFilters() 0139 { 0140 if (sender() == d->exifWidget) 0141 { 0142 Q_EMIT signalSetupMetadataFilters(Private::EXIF); 0143 } 0144 else if (sender() == d->makernoteWidget) 0145 { 0146 Q_EMIT signalSetupMetadataFilters(Private::MAKERNOTE); 0147 } 0148 else if (sender() == d->iptcWidget) 0149 { 0150 Q_EMIT signalSetupMetadataFilters(Private::IPTC); 0151 } 0152 else if (sender() == d->xmpWidget) 0153 { 0154 Q_EMIT signalSetupMetadataFilters(Private::XMP); 0155 } 0156 else if (sender() == d->exifToolWidget) 0157 { 0158 Q_EMIT signalSetupMetadataFilters(Private::EXIFTOOL); 0159 } 0160 } 0161 0162 void ItemPropertiesMetadataTab::readSettings(const KConfigGroup& group) 0163 { 0164 setCurrentIndex(group.readEntry("ImagePropertiesMetaData Tab", 0165 (int)Private::EXIF)); 0166 d->exifWidget->setMode(group.readEntry("EXIF Level", (int)ExifWidget::NONE)); 0167 d->makernoteWidget->setMode(group.readEntry("MAKERNOTE Level", (int)MakerNoteWidget::NONE)); 0168 d->iptcWidget->setMode(group.readEntry("IPTC Level", (int)IptcWidget::NONE)); 0169 d->xmpWidget->setMode(group.readEntry("XMP Level", (int)XmpWidget::NONE)); 0170 d->exifToolWidget->setMode(group.readEntry("EXIFTOOL Level", (int)ExifToolWidget::NONE)); 0171 d->exifWidget->setCurrentItemByKey(group.readEntry("Current EXIF Item", QString())); 0172 d->makernoteWidget->setCurrentItemByKey(group.readEntry("Current MAKERNOTE Item", QString())); 0173 d->iptcWidget->setCurrentItemByKey(group.readEntry("Current IPTC Item", QString())); 0174 d->xmpWidget->setCurrentItemByKey(group.readEntry("Current XMP Item", QString())); 0175 d->exifToolWidget->setCurrentItemByKey(group.readEntry("Current ExifTool Item", QString())); 0176 0177 loadFilters(); 0178 } 0179 0180 void ItemPropertiesMetadataTab::loadFilters() 0181 { 0182 KConfigGroup grp2 = KSharedConfig::openConfig()->group(QLatin1String("Image Properties SideBar")); 0183 d->exifWidget->setTagsFilter(grp2.readEntry("EXIF Tags Filter", QStringList())); 0184 d->makernoteWidget->setTagsFilter(grp2.readEntry("MAKERNOTE Tags Filter", QStringList())); 0185 d->iptcWidget->setTagsFilter(grp2.readEntry("IPTC Tags Filter", QStringList())); 0186 d->xmpWidget->setTagsFilter(grp2.readEntry("XMP Tags Filter", QStringList())); 0187 d->exifToolWidget->setTagsFilter(grp2.readEntry("EXIFTOOL Tags Filter", QStringList())); 0188 } 0189 0190 void ItemPropertiesMetadataTab::writeSettings(KConfigGroup& group) 0191 { 0192 group.writeEntry("ImagePropertiesMetaData Tab", currentIndex()); 0193 group.writeEntry("EXIF Level", d->exifWidget->getMode()); 0194 group.writeEntry("MAKERNOTE Level", d->makernoteWidget->getMode()); 0195 group.writeEntry("IPTC Level", d->iptcWidget->getMode()); 0196 group.writeEntry("XMP Level", d->xmpWidget->getMode()); 0197 group.writeEntry("EXIFTOOL Level", d->exifToolWidget->getMode()); 0198 group.writeEntry("Current EXIF Item", d->exifWidget->getCurrentItemKey()); 0199 group.writeEntry("Current MAKERNOTE Item", d->makernoteWidget->getCurrentItemKey()); 0200 group.writeEntry("Current IPTC Item", d->iptcWidget->getCurrentItemKey()); 0201 group.writeEntry("Current XMP Item", d->xmpWidget->getCurrentItemKey()); 0202 group.writeEntry("Current ExifTool Item", d->exifToolWidget->getCurrentItemKey()); 0203 } 0204 0205 void ItemPropertiesMetadataTab::setCurrentURL(const QUrl& url) 0206 { 0207 d->exifToolWidget->loadFromUrl(url); 0208 d->exifToolWidget->setEnabled(true); 0209 0210 if (url.isEmpty()) 0211 { 0212 d->exifWidget->loadFromURL(url); 0213 d->makernoteWidget->loadFromURL(url); 0214 d->iptcWidget->loadFromURL(url); 0215 d->xmpWidget->loadFromURL(url); 0216 d->exifToolWidget->loadFromUrl(url); 0217 d->exifWidget->setEnabled(false); 0218 d->makernoteWidget->setEnabled(false); 0219 d->iptcWidget->setEnabled(false); 0220 d->xmpWidget->setEnabled(false); 0221 return; 0222 } 0223 0224 d->exifWidget->setEnabled(true); 0225 d->makernoteWidget->setEnabled(true); 0226 d->iptcWidget->setEnabled(true); 0227 d->xmpWidget->setEnabled(true); 0228 0229 QScopedPointer<DMetadata> metadata(new DMetadata); 0230 0231 QElapsedTimer execTimer; 0232 execTimer.start(); 0233 0234 bool ret = metadata->load(url.toLocalFile()); 0235 0236 qCDebug(DIGIKAM_GENERAL_LOG) << "Metadata loading with Exiv2 took" 0237 << execTimer.elapsed() << "ms (" << ret << ")"; 0238 0239 d->exifWidget->loadFromData(url.fileName(), *metadata); 0240 d->makernoteWidget->loadFromData(url.fileName(), *metadata); 0241 d->iptcWidget->loadFromData(url.fileName(), *metadata); 0242 d->xmpWidget->loadFromData(url.fileName(), *metadata); 0243 } 0244 0245 void ItemPropertiesMetadataTab::setCurrentData(DMetadata* const metaData, const QUrl& url) 0246 { 0247 d->exifToolWidget->loadFromUrl(url); 0248 d->exifToolWidget->setEnabled(true); 0249 0250 QScopedPointer<DMetadata> data(new DMetadata(metaData->data())); 0251 0252 if (!data->hasExif() && !data->hasIptc() && !data->hasXmp()) 0253 { 0254 d->exifWidget->loadFromData(url.fileName(), *data); 0255 d->makernoteWidget->loadFromData(url.fileName(), *data); 0256 d->iptcWidget->loadFromData(url.fileName(), *data); 0257 d->xmpWidget->loadFromData(url.fileName(), *data); 0258 d->exifWidget->setEnabled(false); 0259 d->makernoteWidget->setEnabled(false); 0260 d->iptcWidget->setEnabled(false); 0261 d->xmpWidget->setEnabled(false); 0262 return; 0263 } 0264 0265 d->exifWidget->setEnabled(true); 0266 d->makernoteWidget->setEnabled(true); 0267 d->iptcWidget->setEnabled(true); 0268 d->xmpWidget->setEnabled(true); 0269 0270 d->exifWidget->loadFromData(url.fileName(), *data); 0271 d->makernoteWidget->loadFromData(url.fileName(), *data); 0272 d->iptcWidget->loadFromData(url.fileName(), *data); 0273 d->xmpWidget->loadFromData(url.fileName(), *data); 0274 } 0275 0276 } // namespace Digikam 0277 0278 #include "moc_itempropertiesmetadatatab.cpp"