Akonadi

itemserializerplugin.cpp
1 /*
2  SPDX-FileCopyrightText: 2007 Till Adam <[email protected]>
3  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "itemserializerplugin.h"
9 #include "item.h"
10 #include "itemserializer_p.h"
11 
12 #include <QBuffer>
13 
14 using namespace Akonadi;
15 
17 
19 {
20  if (!item.hasPayload()) {
21  return {};
22  }
23 
24  return { Item::FullPayload };
25 }
26 
28 {
29  ItemSerializer::overridePluginLookup(p);
30 }
31 
33 {
34  if (!item.hasPayload()) {
35  return {};
36  }
37 
38  return { Item::FullPayload };
39 }
40 
41 void ItemSerializerPlugin::apply(Item &item, const Item &other)
42 {
43  Q_FOREACH (const QByteArray &part, other.loadedPayloadParts()) {
44  QByteArray partData;
45  QBuffer buffer;
46  buffer.setBuffer(&partData);
47  buffer.open(QIODevice::ReadWrite);
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 }
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 ~ItemSerializerPlugin()
Destroys the item serializer plugin.
virtual QSet< QByteArray > parts(const Item &item) const
Returns a list of available parts for the given item payload.
virtual bool open(QIODevice::OpenMode flags) override
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.
Helper integration between Akonadi and Qt.
void setBuffer(QByteArray *byteArray)
virtual QSet< QByteArray > allowedForeignParts(const Item &item) const
Returns the parts available in the item item that can be stored using foreign payload mechanism...
virtual bool seek(qint64 pos) override
virtual QSet< QByteArray > availableParts(const Item &item) const
Returns the parts available in the item item.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 12 2020 23:16:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.