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 "itemserializer_p.h"
10 
11 #include <QBuffer>
12 
13 using 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 
40 void 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);
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 bool open(QIODevice::OpenMode flags) override
static const char FullPayload[]
Describes the part name that is used to fetch the full payload of an item.
Definition: item.h:131
virtual void apply(Item &item, const Item &other)
Merges the payload parts in other into item.
virtual QSet< QByteArray > allowedForeignParts(const Item &item) const
Returns the parts available in the item item that can be stored using foreign payload mechanism.
bool hasPayload() const
Returns whether the item has a payload object.
Definition: item.cpp:372
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.
void setBuffer(QByteArray *byteArray)
virtual bool seek(qint64 pos) override
virtual QSet< QByteArray > availableParts(const Item &item) const
Returns the parts available in the item 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.
unsigned int version()
static void overridePluginLookup(QObject *plugin)
Override the plugin-lookup with plugin.
virtual ~ItemSerializerPlugin()
Destroys the item serializer plugin.
QSet< QByteArray > loadedPayloadParts() const
Returns the list of loaded payload parts.
Definition: item.cpp:288
Represents a PIM item stored in Akonadi storage.
Definition: item.h:104
Helper integration between Akonadi and Qt.
virtual QSet< QByteArray > parts(const Item &item) const
Returns a list of available parts for the given item payload.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.