void TagsReadWriteTest::testTagSeparatorWrite() { DMetadata dmeta; DMetadataSettingsContainer dmsettings; QStringList readResult; QStringList expected; NamespaceEntry tagNs3; tagNs3.namespaceName = QLatin1String("Xmp.lr.hierarchicalSubject"); tagNs3.tagPaths = NamespaceEntry::TAGPATH; tagNs3.separator = QLatin1Char('|'); tagNs3.nsType = NamespaceEntry::TAGS; tagNs3.index = 2; tagNs3.specialOpts = NamespaceEntry::TAG_XMPBAG; tagNs3.subspace = NamespaceEntry::XMP; tagNs3.alternativeName = QLatin1String("Xmp.lr.HierarchicalSubject"); tagNs3.secondNameOpts = NamespaceEntry::TAG_XMPSEQ; dmsettings.getWriteMapping(QString::fromUtf8(DM_TAG_CONTAINER)).clear(); dmsettings.getWriteMapping(QString::fromUtf8(DM_TAG_CONTAINER)) << tagNs3; dmeta.setItemTagsPath(tagSet1, dmsettings); readResult = dmeta.getXmpTagStringBag("Xmp.lr.hierarchicalSubject", false); expected = tagSet1; expected = expected.replaceInStrings(QLatin1String("/"), QLatin1String("|")); QCOMPARE(readResult, expected); }
void TagsReadWriteTest::testWriteToDisabledNamespaces() { DMetadata dmeta; DMetadataSettingsContainer dmsettings; QStringList empty; QStringList secondNamespace; NamespaceEntry tagNs2; tagNs2.namespaceName = QLatin1String("Xmp.MicrosoftPhoto.LastKeywordXMP"); tagNs2.tagPaths = NamespaceEntry::TAGPATH; tagNs2.separator = QLatin1Char('/'); tagNs2.nsType = NamespaceEntry::TAGS; tagNs2.index = 1; tagNs2.specialOpts = NamespaceEntry::TAG_XMPBAG; tagNs2.subspace = NamespaceEntry::XMP; tagNs2.isDisabled = true; NamespaceEntry tagNs3; tagNs3.namespaceName = QLatin1String("Xmp.lr.hierarchicalSubject"); tagNs3.tagPaths = NamespaceEntry::TAGPATH; tagNs3.separator = QLatin1Char('|'); tagNs3.nsType = NamespaceEntry::TAGS; tagNs3.index = 2; tagNs3.specialOpts = NamespaceEntry::TAG_XMPBAG; tagNs3.subspace = NamespaceEntry::XMP; tagNs3.alternativeName = QLatin1String("Xmp.lr.HierarchicalSubject"); tagNs3.secondNameOpts = NamespaceEntry::TAG_XMPSEQ; dmsettings.getWriteMapping(QString::fromUtf8(DM_TAG_CONTAINER)).clear(); dmsettings.getWriteMapping(QString::fromUtf8(DM_TAG_CONTAINER)) << tagNs2 << tagNs3; dmeta.setItemTagsPath(tagSet1, dmsettings); empty = dmeta.getXmpTagStringBag("Xmp.MicrosoftPhoto.LastKeywordXMP", false); QCOMPARE(empty, QStringList()); secondNamespace = dmeta.getXmpTagStringBag("Xmp.lr.hierarchicalSubject", false); secondNamespace = secondNamespace.replaceInStrings(QLatin1String("|"), QLatin1String("/")); QCOMPARE(secondNamespace, tagSet1); }
void CommentReadWriteTest::testWriteToDisabledNamespaces() { DMetadata dmeta; dmeta.setFilePath(QLatin1String("random.org")); MetaEngine::AltLangMap commentsMap; QString commentString; DMetadataSettingsContainer dmsettings; NamespaceEntry commNs1; commNs1.namespaceName = QLatin1String("Xmp.dc.description"); commNs1.nsType = NamespaceEntry::COMMENT; commNs1.specialOpts = NamespaceEntry::COMMENT_ATLLANGLIST; commNs1.index = 0; commNs1.subspace = NamespaceEntry::XMP; commNs1.isDisabled = true; NamespaceEntry commNs2; commNs2.namespaceName = QLatin1String("Xmp.exif.UserComment"); commNs2.nsType = NamespaceEntry::COMMENT; commNs2.specialOpts = NamespaceEntry::COMMENT_ALTLANG; commNs2.index = 1; commNs2.subspace = NamespaceEntry::XMP; dmsettings.setUnifyReadWrite(false); dmsettings.getWriteMapping(QString::fromUtf8(DM_COMMENT_CONTAINER)).clear(); dmsettings.getWriteMapping(QString::fromUtf8(DM_COMMENT_CONTAINER)) << commNs1 << commNs2; bool rez = dmeta.setItemComments(commentSet1, dmsettings); QVERIFY(rez); commentsMap = dmeta.getXmpTagStringListLangAlt("Xmp.dc.description", false); QCOMPARE(commentsMap.value(QLatin1String("x-default")), QString()); commentString = dmeta.getXmpTagStringLangAlt("Xmp.exif.UserComment", QString(), false); QCOMPARE(commentString, commentSet1.value(QLatin1String("x-default")).caption); }
bool DMetadata::setItemRating(int rating, const DMetadataSettingsContainer& settings) const { // NOTE : with digiKam 0.9.x, we have used IPTC Urgency to store Rating. // Now this way is obsolete, and we use standard XMP rating tag instead. if (rating < RatingMin || rating > RatingMax) { qCDebug(DIGIKAM_METAENGINE_LOG) << "Rating value to write is out of range!"; return false; } //qCDebug(DIGIKAM_METAENGINE_LOG) << getFilePath() << " ==> Rating:" << rating; QList<NamespaceEntry> toWrite = settings.getReadMapping(QString::fromUtf8(DM_RATING_CONTAINER)); if (!settings.unifyReadWrite()) toWrite = settings.getWriteMapping(QString::fromUtf8(DM_RATING_CONTAINER)); for (NamespaceEntry entry : toWrite) { if (entry.isDisabled) continue; const std::string myStr = entry.namespaceName.toStdString(); const char* nameSpace = myStr.data(); switch(entry.subspace) { case NamespaceEntry::XMP: if (!setXmpTagString(nameSpace, QString::number(entry.convertRatio.at(rating)))) { qCDebug(DIGIKAM_METAENGINE_LOG) << "Setting rating failed" << nameSpace; return false; } break; case NamespaceEntry::EXIF: if (QLatin1String(nameSpace) == QLatin1String("Exif.Image.0x4749")) { // Wrapper around rating percents managed by Windows Vista. int ratePercents = 0; switch (rating) { case 0: ratePercents = 0; break; case 1: ratePercents = 1; break; case 2: ratePercents = 25; break; case 3: ratePercents = 50; break; case 4: ratePercents = 75; break; case 5: ratePercents = 99; break; } if (!setExifTagLong(nameSpace, ratePercents)) { qCDebug(DIGIKAM_METAENGINE_LOG) << "Setting rating failed" << nameSpace; return false; } } else { if (!setExifTagLong(nameSpace, rating)) { qCDebug(DIGIKAM_METAENGINE_LOG) << "Setting rating failed" << nameSpace; return false; } } break; case NamespaceEntry::IPTC: // IPTC rating deprecated default: break; } } return true; }