// ***************************************************************************** // Main int main(int argc, char* const argv[]) try { if (argc != 2) { std::cout << "Usage: " << argv[0] << " file\n"; return 1; } Exiv2::IptcData iptcData; int rc = iptcData.read(argv[1]); if (rc) { std::string error = Exiv2::IptcData::strError(rc, argv[1]); throw Exiv2::Error(error); } Exiv2::IptcData::iterator end = iptcData.end(); for (Exiv2::IptcData::iterator i = iptcData.begin(); i != end; ++i) { std::cout << std::setw(40) << std::setfill(' ') << std::left << i->key() << " " << "0x" << std::setw(4) << std::setfill('0') << std::right << std::hex << i->tag() << " " << std::dec << i->value() << "\n"; } return rc; } catch (Exiv2::Error& e) { std::cout << "Caught Exiv2 exception '" << e << "'\n"; return -1; }
bool getIptcKeywords(Exiv2::IptcData &iptcData, bool isIptcUtf8, QStringList &keywords) { bool anyAdded = false; try { QString keywordsTagName = QString::fromLatin1(IPTC_KEYWORDS); for (Exiv2::IptcData::iterator it = iptcData.begin(); it != iptcData.end(); ++it) { QString key = QString::fromLocal8Bit(it->key().c_str()); if (key == keywordsTagName) { QString tag; if (isIptcUtf8) { tag = QString::fromUtf8(it->toString().c_str()); } else { tag = QString::fromLocal8Bit(it->toString().c_str()); } keywords.append(tag); anyAdded = true; } } if (keywords.length() == 1 && keywords[0].contains(',')) { LOG_DEBUG << "processing legacy saved keywords"; QString composite = keywords[0]; keywords.clear(); keywords += decomposeKeyword(composite); } } catch (Exiv2::Error &e) { LOG_WARNING << "Exiv2 error:" << e.what(); anyAdded = false; } catch (...) { LOG_WARNING << "Exception"; anyAdded = false; #ifdef QT_DEBUG throw; #endif } return anyAdded; }
KExiv2::MetaDataMap KExiv2::getIptcTagsDataList(const QStringList& iptcKeysFilter, bool invertSelection) const { if (d->iptcMetadata().empty()) return MetaDataMap(); try { Exiv2::IptcData iptcData = d->iptcMetadata(); iptcData.sortByKey(); QString ifDItemName; MetaDataMap metaDataMap; for (Exiv2::IptcData::iterator md = iptcData.begin(); md != iptcData.end(); ++md) { QString key = QString::fromLocal8Bit(md->key().c_str()); // Decode the tag value with a user friendly output. std::ostringstream os; os << *md; QString value = QString(os.str().c_str()); // To make a string just on one line. value.replace('\n', ' '); // Some Iptc key are redondancy. check if already one exist... MetaDataMap::iterator it = metaDataMap.find(key); // We apply a filter to get only the Iptc tags that we need. if (!invertSelection) { if (iptcKeysFilter.contains(key.section('.', 1, 1))) { if (it == metaDataMap.end()) metaDataMap.insert(key, value); else { QString v = *it; v.append(", "); v.append(value); metaDataMap.insert(key, v); } } } else { if (!iptcKeysFilter.contains(key.section('.', 1, 1))) { if (it == metaDataMap.end()) metaDataMap.insert(key, value); else { QString v = *it; v.append(", "); v.append(value); metaDataMap.insert(key, v); } } } } return metaDataMap; } catch (Exiv2::Error& e) { d->printExiv2ExceptionError("Cannot parse Iptc metadata using Exiv2 ", e); } return MetaDataMap(); }