void TagsReadWriteTest::testReadFromDisabledNamespaces() { DMetadata dmeta; DMetadataSettingsContainer dmsettings; QStringList actual; 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.getReadMapping(QString::fromUtf8(DM_TAG_CONTAINER)).clear(); dmsettings.getReadMapping(QString::fromUtf8(DM_TAG_CONTAINER)) << tagNs2 << tagNs3; dmeta.setXmpTagStringBag("Xmp.MicrosoftPhoto.LastKeywordXMP", tagSet1); dmeta.setXmpTagStringBag("Xmp.lr.hierarchicalSubject", tagSet2); dmeta.getItemTagsPath(actual, dmsettings); QCOMPARE(actual, tagSet2); }
void TagsReadWriteTest::testTagReadAlternativeNameSpace() { DMetadata dmeta; DMetadataSettingsContainer dmsettings; QStringList toWrite; QStringList actual; QStringList reference; 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.getReadMapping(QString::fromUtf8(DM_TAG_CONTAINER)).clear(); dmsettings.getReadMapping(QString::fromUtf8(DM_TAG_CONTAINER)) << tagNs3; toWrite = tagSet1; toWrite = toWrite.replaceInStrings(QLatin1String("/"), QLatin1String("|")); dmeta.setXmpTagStringSeq("Xmp.lr.HierarchicalSubject", toWrite); // We write some data to alternative namespace reference = dmeta.getXmpTagStringSeq("Xmp.lr.HierarchicalSubject", false); QCOMPARE(reference, toWrite); dmeta.getItemTagsPath(actual, dmsettings); QCOMPARE(actual, tagSet1); }
void CommentReadWriteTest::testReadFromDisabledNamespaces() { DMetadata dmeta; dmeta.setFilePath(QLatin1String("random.org")); CaptionsMap rez; 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.getReadMapping(QString::fromUtf8(DM_COMMENT_CONTAINER)).clear(); dmsettings.getReadMapping(QString::fromUtf8(DM_COMMENT_CONTAINER)) << commNs1 << commNs2; dmeta.setXmpTagStringListLangAlt("Xmp.dc.description", commentSet1.toAltLangMap()); dmeta.setXmpTagStringLangAlt("Xmp.exif.UserComment", commentSet2.value(QLatin1String("x-default")).caption, QString()); rez = dmeta.getItemComments(dmsettings); QCOMPARE(rez.value(QLatin1String("x-default")).caption, commentSet2.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; }
int DMetadata::getItemRating(const DMetadataSettingsContainer& settings) const { if (getFilePath().isEmpty()) { return -1; } long rating = -1; bool xmpSupported = hasXmp(); bool iptcSupported = hasIptc(); bool exivSupported = hasExif(); for (NamespaceEntry entry : settings.getReadMapping(QString::fromUtf8(DM_RATING_CONTAINER))) { if (entry.isDisabled) continue; const std::string myStr = entry.namespaceName.toStdString(); const char* nameSpace = myStr.data(); QString value; switch(entry.subspace) { case NamespaceEntry::XMP: if (xmpSupported) value = getXmpTagString(nameSpace, false); break; case NamespaceEntry::IPTC: if (iptcSupported) value = QString::fromUtf8(getIptcTagData(nameSpace)); break; case NamespaceEntry::EXIF: if (exivSupported) getExifTagLong(nameSpace, rating); break; default: break; } if (!value.isEmpty()) { bool ok = false; rating = value.toLong(&ok); if (!ok) { return -1; } } int index = entry.convertRatio.indexOf(rating); // Exact value was not found,but rating is in range, // so we try to approximate it if ((index == -1) && (rating > entry.convertRatio.first()) && (rating < entry.convertRatio.last())) { for (int i = 0 ; i < entry.convertRatio.size() ; ++i) { if (rating > entry.convertRatio.at(i)) { index = i; } } } if (index != -1) { return index; } } return -1; }