File indexing completed on 2024-11-10 04:40:41
0001 /* 0002 SPDX-FileCopyrightText: 2007 Till Adam <adam@kde.org> 0003 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "itemserializerplugin.h" 0009 #include "itemserializer_p.h" 0010 0011 #include <QBuffer> 0012 0013 using namespace Akonadi; 0014 0015 ItemSerializerPlugin::~ItemSerializerPlugin() = default; 0016 0017 QSet<QByteArray> ItemSerializerPlugin::parts(const Item &item) const 0018 { 0019 if (!item.hasPayload()) { 0020 return {}; 0021 } 0022 0023 return {Item::FullPayload}; 0024 } 0025 0026 void ItemSerializerPlugin::overridePluginLookup(QObject *p) 0027 { 0028 ItemSerializer::overridePluginLookup(p); 0029 } 0030 0031 QSet<QByteArray> ItemSerializerPlugin::availableParts(const Item &item) const 0032 { 0033 if (!item.hasPayload()) { 0034 return {}; 0035 } 0036 0037 return {Item::FullPayload}; 0038 } 0039 0040 void ItemSerializerPlugin::apply(Item &item, const Item &other) 0041 { 0042 const auto loadedPayloadParts{other.loadedPayloadParts()}; 0043 for (const QByteArray &part : loadedPayloadParts) { 0044 QByteArray partData; 0045 QBuffer buffer; 0046 buffer.setBuffer(&partData); 0047 buffer.open(QIODevice::ReadWrite); 0048 buffer.seek(0); 0049 int version; 0050 // NOTE: we can't just pass other.payloadData() into deserialize(), 0051 // because that does not preserve payload version. 0052 serialize(other, part, buffer, version); 0053 buffer.seek(0); 0054 deserialize(item, part, buffer, version); 0055 } 0056 } 0057 0058 QSet<QByteArray> ItemSerializerPlugin::allowedForeignParts(const Item &item) const 0059 { 0060 if (!item.hasPayload()) { 0061 return {}; 0062 } 0063 0064 return {Item::FullPayload}; 0065 }