1 | /* |
2 | Copyright (c) 2007 Till Adam <adam@kde.org> |
3 | Copyright (c) 2007 Volker Krause <vkrause@kde.org> |
4 | |
5 | This library is free software; you can redistribute it and/or modify it |
6 | under the terms of the GNU Library General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or (at your |
8 | option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, but WITHOUT |
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
13 | License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to the |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | 02110-1301, USA. |
19 | */ |
20 | |
21 | #include "itemserializerplugin.h" |
22 | #include "item.h" |
23 | #include "itemserializer_p.h" |
24 | |
25 | #include <QtCore/QBuffer> |
26 | |
27 | using namespace Akonadi; |
28 | |
29 | ItemSerializerPlugin::~ItemSerializerPlugin() |
30 | { |
31 | } |
32 | |
33 | QSet<QByteArray> ItemSerializerPlugin::parts(const Item &item) const |
34 | { |
35 | QSet<QByteArray> set; |
36 | if (item.hasPayload()) { |
37 | set.insert(Item::FullPayload); |
38 | } |
39 | |
40 | return set; |
41 | } |
42 | |
43 | void ItemSerializerPlugin::overridePluginLookup(QObject *p) |
44 | { |
45 | ItemSerializer::overridePluginLookup(p); |
46 | } |
47 | |
48 | ItemSerializerPluginV2::~ItemSerializerPluginV2() |
49 | { |
50 | } |
51 | |
52 | QSet<QByteArray> ItemSerializerPluginV2::availableParts(const Item &item) const |
53 | { |
54 | if (item.hasPayload()) { |
55 | return QSet<QByteArray>(); |
56 | } |
57 | |
58 | return QSet<QByteArray>() << Item::FullPayload; |
59 | } |
60 | |
61 | void ItemSerializerPluginV2::apply(Item &item, const Item &other) |
62 | { |
63 | QBuffer buffer; |
64 | QByteArray data(other.payloadData()); |
65 | buffer.setBuffer(&data); |
66 | buffer.open(QIODevice::ReadOnly); |
67 | |
68 | foreach (const QByteArray &part, other.loadedPayloadParts()) { |
69 | buffer.seek(0); |
70 | deserialize(item, part, buffer, 0); |
71 | } |
72 | |
73 | buffer.close(); |
74 | } |
75 | |