Commit 6dc80098 authored by Volker Krause's avatar Volker Krause

Store parsed result, not the raw JSON-LD

We'll need the parsed result also for interactions, which will be
simplified by this.
parent 4a9f8d85
......@@ -97,9 +97,10 @@ static QVariant createInstance(const QJsonObject &obj)
#undef MAKE_FACTORY
QVariantList JsonLdDocument::fromJson(const QJsonArray &array)
QVector<QVariant> JsonLdDocument::fromJson(const QJsonArray &array)
{
QVariantList l;
QVector<QVariant> l;
l.reserve(array.size());
for (const auto &obj : array) {
const auto v = createInstance(obj.toObject());
if (!v.isNull())
......
......@@ -21,13 +21,14 @@
#define JSONLDDOCUMENT_H
#include <QVariant>
#include <QVector>
class QJsonArray;
/** Serialization/deserialization code for JSON-LD data. */
namespace JsonLdDocument
{
QVariantList fromJson(const QJsonArray &array);
QVector<QVariant> fromJson(const QJsonArray &array);
}
#endif // JSONLDDOCUMENT_H
......@@ -30,12 +30,12 @@ bool SemanticMemento::isEmpty() const
return m_data.isEmpty();
}
QJsonArray SemanticMemento::data() const
QVector<QVariant> SemanticMemento::data() const
{
return m_data;
}
void SemanticMemento::setData(const QJsonArray &data)
void SemanticMemento::setData(const QVector<QVariant> &data)
{
m_data = data;
}
......@@ -22,7 +22,8 @@
#include <MimeTreeParser/BodyPart>
#include <QJsonArray>
#include <QVariant>
#include <QVector>
/** Memento holding the semantic information extracted for an email. */
class SemanticMemento : public MimeTreeParser::Interface::BodyPartMemento
......@@ -32,11 +33,11 @@ public:
void detach() override;
bool isEmpty() const;
QJsonArray data() const;
void setData(const QJsonArray &data);
QVector<QVariant> data() const;
void setData(const QVector<QVariant> &data);
private:
QJsonArray m_data;
QVector<QVariant> m_data;
};
#endif // SEMANTICMEMENTO_H
......@@ -18,11 +18,13 @@
*/
#include "semanticprocessor.h"
#include "jsonlddocument.h"
#include "structureddataextractor.h"
#include "semanticmemento.h"
#include "semantic_debug.h"
#include <QDebug>
#include <QJsonDocument>
MimeTreeParser::MessagePart::Ptr SemanticProcessor::process(MimeTreeParser::Interface::BodyPart &part) const
{
......@@ -38,7 +40,13 @@ MimeTreeParser::MessagePart::Ptr SemanticProcessor::process(MimeTreeParser::Inte
extractor.parse(part.content()->decodedText());
memento = new SemanticMemento;
nodeHelper->setBodyPartMemento(part.topLevelContent(), "org.kde.messageviewer.semanticData", memento);
memento->setData(extractor.data());
const auto data = extractor.data();
const auto decodedData = JsonLdDocument::fromJson(data);
if (data.size() != decodedData.size()) {
qCDebug(SEMANTIC_LOG) << "Unhandled content:" << QJsonDocument(data).toJson();
}
memento->setData(decodedData);
qCDebug(SEMANTIC_LOG) << "-------------------------------------------- END SEMANTIC PARSING";
return {};
}
......@@ -19,7 +19,6 @@
#include "semanticrenderer.h"
#include "datatypes.h"
#include "jsonlddocument.h"
#include "semanticmemento.h"
#include "semantic_debug.h"
......@@ -31,7 +30,6 @@
#include <QDebug>
#include <QGuiApplication>
#include <QJsonDocument>
#include <QMetaProperty>
#include <QPalette>
......@@ -81,14 +79,8 @@ bool SemanticRenderer::render(const MimeTreeParser::MessagePartPtr &msgPart, Mim
if (!memento || memento->isEmpty())
return false;
const auto decodedData = JsonLdDocument::fromJson(memento->data());
if (decodedData.isEmpty()) {
qCDebug(SEMANTIC_LOG) << "Unhandled content:" << QJsonDocument(memento->data()).toJson();
return false;
}
auto c = MessageViewer::MessagePartRendererManager::self()->createContext();
c.insert(QStringLiteral("data"), decodedData);
c.insert(QStringLiteral("data"), QVariant::fromValue(memento->data()));
const auto pal = qGuiApp->palette();
QVariantMap style;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment