示例#1
0
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       = QLatin1String("|");
    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(QLatin1String(DM_TAG_CONTAINER)).clear();
    dmsettings.getWriteMapping(QLatin1String(DM_TAG_CONTAINER))
             << tagNs3;

    dmeta.setImageTagsPath(tagSet1, dmsettings);

    readResult = dmeta.getXmpTagStringBag("Xmp.lr.hierarchicalSubject", false);

    expected   = tagSet1;
    expected   = expected.replaceInStrings(QLatin1String("/"),QLatin1String("|"));

    QCOMPARE(readResult, expected);
}
示例#2
0
void TagsReadWriteTest::testSimpleReadAfterWrite()
{
    DMetadata dmeta;
    QStringList tagPaths2;

    dmeta.setImageTagsPath(this->tagSet1);
    dmeta.getImageTagsPath(tagPaths2);

    QCOMPARE(tagSet1, tagPaths2);
}
示例#3
0
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     = QLatin1String("/");
    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       = QLatin1String("|");
    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(QLatin1String(DM_TAG_CONTAINER)).clear();
    dmsettings.getWriteMapping(QLatin1String(DM_TAG_CONTAINER))
             << tagNs2
             << tagNs3;

    dmeta.setImageTagsPath(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);
}
示例#4
0
bool MetadataHub::writeTags(DMetadata& metadata, bool saveTags)
{
    qCDebug(DIGIKAM_GENERAL_LOG) << "Writting tags";
    bool dirty = false;

    if (saveTags)
    {
        // Store tag paths as Iptc keywords tags.

        // DatabaseMode == ManagedTags is assumed.
        // To fix this constraint (not needed currently), an oldKeywords parameter is needed

        // create list of keywords to be added and to be removed
        QStringList tagsPathList, newKeywords;

        QList<int> keys = d->tags.keys();

        foreach (int tagId, keys)
        {
            if (!TagsCache::instance()->canBeWrittenToMetadata(tagId))
            {
                continue;
            }

            // WARNING: Do not use write(QFilePath ...) when multiple image info are loaded
            // otherwise disjoint tags will not be used, use writeToMetadata(ImageInfo...)
            if (d->tags.value(tagId) == MetadataAvailable)
            {
                // This works for single and multiple selection.
                // In both situations, tags which had originally been loaded
                // have explicitly been removed with setTag.
                QString tagName = TagsCache::instance()->tagName(tagId);
                QString tagPath = TagsCache::instance()->tagPath(tagId, TagsCache::NoLeadingSlash);

                if (!tagsPathList.contains(tagPath))
                {
                    tagsPathList << tagPath;
                }

                if (!tagName.isEmpty())
                {
                    newKeywords << tagName;
                }
            }
        }

        tagsPathList = cleanupTags(tagsPathList);
        newKeywords = cleanupTags(newKeywords);

        if (!newKeywords.isEmpty())
        {
            qCDebug(DIGIKAM_GENERAL_LOG) << "-------------------------- New Keywords" << newKeywords;
            // NOTE: See bug #175321 : we remove all old keyword from IPTC and XMP before to
            // synchronize metadata, else contents is not coherent.

            // We set Iptc keywords using tags name.
            // dirty |= metadata.setIptcKeywords(metadata.getIptcKeywords(), newKeywords);

            // We add Xmp keywords using tags name.
            // dirty |= metadata.removeXmpKeywords(metadata.getXmpKeywords());
            // dirty |= metadata.setXmpKeywords(newKeywords);

            // We set Tags Path list in digiKam Xmp private namespace using tags path.
            dirty |= metadata.setImageTagsPath(tagsPathList);
        }
        else
        {
            qCDebug(DIGIKAM_GENERAL_LOG) << "Delete all keywords";
            // Delete all IPTC and XMP keywords
            // dirty |= metadata.setIptcKeywords(metadata.getIptcKeywords(), QStringList());
            // dirty |= metadata.removeXmpKeywords(metadata.getXmpKeywords());
            dirty |= metadata.setImageTagsPath(QStringList());
        }
    }

    return dirty;
}