1 /* ============================================================ 2 * 3 * This file is a part of digiKam project 4 * https://www.digikam.org 5 * 6 * Date : 2012-10-23 7 * Description : a command line tool to test DMetadata image loader 8 * 9 * Copyright (C) 2012-2021 by Gilles Caulier, <caulier dot gilles at gmail dot com> 10 * 11 * This program is free software; you can redistribute it 12 * and/or modify it under the terms of the GNU General 13 * Public License as published by the Free Software Foundation; 14 * either version 2, or (at your option) 15 * any later version. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * ============================================================ */ 23 24 // Qt includes 25 26 #include <QFileInfo> 27 #include <QString> 28 #include <QTextStream> 29 #include <QApplication> 30 31 // Local includes 32 33 #include "dmetadata.h" 34 #include "digikam_debug.h" 35 36 using namespace Digikam; 37 s_printMetadataMap(const DMetadata::MetaDataMap & map)38void s_printMetadataMap(const DMetadata::MetaDataMap& map) 39 { 40 QString output; 41 QTextStream stream(&output); 42 stream << endl; 43 44 qCDebug(DIGIKAM_TESTS_LOG) << "Found" << map.size() << "tags:" << endl; 45 46 for (DMetadata::MetaDataMap::const_iterator it = map.constBegin() ; 47 it != map.constEnd() ; ++it) 48 { 49 QString key = it.key(); 50 QString value = it.value(); 51 52 QString tagName = key.simplified(); 53 tagName.append(QString().fill(QLatin1Char(' '), 48 - tagName.length())); 54 55 QString tagVal = value.simplified(); 56 57 if (tagVal.length() > 48) 58 { 59 tagVal.truncate(48); 60 tagVal.append(QString::fromLatin1("... (%1 bytes)").arg(value.length())); 61 } 62 63 stream << tagName << " : " << tagVal << endl; 64 } 65 66 qCDebug(DIGIKAM_TESTS_LOG).noquote() << output; 67 } 68 main(int argc,char ** argv)69int main(int argc, char** argv) 70 { 71 QApplication app(argc, argv); 72 73 if (argc != 2) 74 { 75 qCDebug(DIGIKAM_TESTS_LOG) << "dmetadataloader_cli - CLI tool to check DMetadata image loader"; 76 qCDebug(DIGIKAM_TESTS_LOG) << "Usage: <image>"; 77 return -1; 78 } 79 80 MetaEngine::initializeExiv2(); 81 82 QFileInfo input(QString::fromUtf8(argv[1])); 83 84 DMetadata meta; 85 bool ret = meta.load(input.filePath()); 86 87 if (!ret) 88 { 89 qCWarning(DIGIKAM_TESTS_LOG) << "Cannot load" << meta.getFilePath(); 90 return -1; 91 } 92 93 qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- Exif metadata from %1 --").arg(meta.getFilePath()); 94 95 DMetadata::MetaDataMap map = meta.getExifTagsDataList(); 96 s_printMetadataMap(map); 97 98 qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- Iptc metadata from %1 --").arg(meta.getFilePath()); 99 100 map = meta.getIptcTagsDataList(); 101 s_printMetadataMap(map); 102 103 if (meta.supportXmp()) 104 { 105 qCDebug(DIGIKAM_TESTS_LOG) << QString::fromUtf8("-- Xmp metadata from %1 --").arg(meta.getFilePath()); 106 map = meta.getXmpTagsDataList(); 107 s_printMetadataMap(map); 108 } 109 else 110 { 111 qCWarning(DIGIKAM_TESTS_LOG) << "Exiv2 has no XMP support..."; 112 } 113 114 return 0; 115 } 116 117