コード例 #1
0
ファイル: kis_kra_load_visitor.cpp プロジェクト: KDE/krita
bool KisKraLoadVisitor::loadMetaData(KisNode* node)
{
    dbgFile << "Load metadata for " << node->name();
    KisLayer* layer = qobject_cast<KisLayer*>(node);
    if (!layer) return true;

    bool result = true;

    KisMetaData::IOBackend* backend = KisMetaData::IOBackendRegistry::instance()->get("xmp");

    if (!backend || !backend->supportLoading()) {
        if (backend)
            dbgFile << "Backend " << backend->id() << " does not support loading.";
        else
            dbgFile << "Could not load the XMP backenda t all";
        return true;
    }

    QString location = getLocation(node, QString(".") + backend->id() +  DOT_METADATA);
    dbgFile << "going to load " << backend->id() << ", " << backend->name() << " from " << location;

    if (m_store->hasFile(location)) {
        QByteArray data;
        m_store->open(location);
        data = m_store->read(m_store->size());
        m_store->close();
        QBuffer buffer(&data);
        if (!backend->loadFrom(layer->metaData(), &buffer)) {
            m_errorMessages << i18n("Could not load metadata for layer %1.", layer->name());
            result = false;
        }

    }
    return result;
}
コード例 #2
0
bool KisKraSaveVisitor::saveMetaData(KisNode* node)
{
    if (!node->inherits("KisLayer")) return true;

    KisMetaData::Store* metadata = (static_cast<KisLayer*>(node))->metaData();
    if (metadata->isEmpty()) return true;

    // Serialize all the types of metadata there are
    KisMetaData::IOBackend* backend = KisMetaData::IOBackendRegistry::instance()->get("xmp");
    if (!backend->supportSaving()) {
        dbgFile << "Backend " << backend->id() << " does not support saving.";
        return false;
    }

    QString location = getLocation(node, QString(".") + backend->id() +  DOT_METADATA);
    dbgFile << "going to save " << backend->id() << ", " << backend->name() << " to " << location;

    QBuffer buffer;
    // not that the metadata backends every return anything but true...
    bool retval = backend->saveTo(metadata, &buffer);

    if (!retval) {
        m_errorMessages << i18n("The metadata backend failed to save the metadata for %1", node->name());
    }
    else {
        QByteArray data = buffer.data();
        dbgFile << "\t information size is" << data.size();

        if (data.size() > 0 && m_store->open(location)) {
            retval = m_store->write(data,  data.size());
            m_store->close();
        }
        if (!retval) {
            m_errorMessages << i18n("Could not write for %1 metadata to the file.", node->name());
        }
    }
    return retval;
}