Akonadi

itemserializerplugin.cpp
1/*
2 SPDX-FileCopyrightText: 2007 Till Adam <adam@kde.org>
3 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "itemserializerplugin.h"
9#include "itemserializer_p.h"
10
11#include <QBuffer>
12
13using namespace Akonadi;
14
16
18{
19 if (!item.hasPayload()) {
20 return {};
21 }
22
23 return {Item::FullPayload};
24}
25
27{
28 ItemSerializer::overridePluginLookup(p);
29}
30
32{
33 if (!item.hasPayload()) {
34 return {};
35 }
36
37 return {Item::FullPayload};
38}
39
40void ItemSerializerPlugin::apply(Item &item, const Item &other)
41{
42 const auto loadedPayloadParts{other.loadedPayloadParts()};
43 for (const QByteArray &part : loadedPayloadParts) {
44 QByteArray partData;
45 QBuffer buffer;
46 buffer.setBuffer(&partData);
48 buffer.seek(0);
49 int version;
50 // NOTE: we can't just pass other.payloadData() into deserialize(),
51 // because that does not preserve payload version.
52 serialize(other, part, buffer, version);
53 buffer.seek(0);
54 deserialize(item, part, buffer, version);
55 }
56}
57
59{
60 if (!item.hasPayload()) {
61 return {};
62 }
63
64 return {Item::FullPayload};
65}
66
67#include "moc_itemserializerplugin.cpp"
virtual void apply(Item &item, const Item &other)
Merges the payload parts in other into item.
virtual bool deserialize(Item &item, const QByteArray &label, QIODevice &data, int version)=0
Converts serialized item data provided in data into payload for item.
virtual QSet< QByteArray > parts(const Item &item) const
Returns a list of available parts for the given item payload.
static void overridePluginLookup(QObject *plugin)
Override the plugin-lookup with plugin.
virtual void serialize(const Item &item, const QByteArray &label, QIODevice &data, int &version)=0
Convert the payload object provided in item into its serialzed form into data.
virtual QSet< QByteArray > availableParts(const Item &item) const
Returns the parts available in the item item.
virtual ~ItemSerializerPlugin()
Destroys the item serializer plugin.
virtual QSet< QByteArray > allowedForeignParts(const Item &item) const
Returns the parts available in the item item that can be stored using foreign payload mechanism.
Represents a PIM item stored in Akonadi storage.
Definition item.h:100
bool hasPayload() const
Returns whether the item has a payload object.
static const char FullPayload[]
Describes the part name that is used to fetch the full payload of an item.
Definition item.h:126
QSet< QByteArray > loadedPayloadParts() const
Returns the list of loaded payload parts.
Definition item.cpp:283
Helper integration between Akonadi and Qt.
virtual bool open(OpenMode flags) override
virtual bool seek(qint64 pos) override
void setBuffer(QByteArray *byteArray)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.