1 | /* |
2 | Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "akonadi_serializer_bookmark.h" |
21 | |
22 | #include <QtCore/qplugin.h> |
23 | #include <QDebug> |
24 | #include <QMimeData> |
25 | #include <kbookmark.h> |
26 | |
27 | #include <akonadi/item.h> |
28 | |
29 | |
30 | using namespace Akonadi; |
31 | |
32 | #ifndef KIO_KBOOKMARK_METATYPE_DEFINED |
33 | Q_DECLARE_METATYPE( KBookmark ) |
34 | #endif |
35 | |
36 | bool SerializerPluginBookmark::deserialize( Item& item, const QByteArray& label, QIODevice& data, int version ) |
37 | { |
38 | Q_UNUSED( version ); |
39 | |
40 | if ( label != Item::FullPayload ) |
41 | return false; |
42 | |
43 | KBookmark bk; |
44 | QMimeData *mimeData = new QMimeData(); |
45 | mimeData->setData( QString::fromLatin1( "application/x-xbel" ), data.readAll() ); |
46 | QDomDocument doc; |
47 | KBookmark::List bkl = KBookmark::List::fromMimeData( mimeData, doc ); |
48 | |
49 | if ( !bkl.isEmpty() ) |
50 | item.setPayload<KBookmark>( bkl[0] ); |
51 | return true; |
52 | } |
53 | |
54 | void SerializerPluginBookmark::serialize( const Item& item, const QByteArray& label, QIODevice& data, int &version ) |
55 | { |
56 | Q_UNUSED( version ); |
57 | |
58 | if ( label != Item::FullPayload ) |
59 | return; |
60 | |
61 | if ( item.mimeType() != QString::fromLatin1( "application/x-xbel" ) ) |
62 | return; |
63 | |
64 | KBookmark bk; |
65 | if ( item.hasPayload() ) |
66 | bk = item.payload<KBookmark>(); |
67 | |
68 | QMimeData *mimeData = new QMimeData(); |
69 | bk.populateMimeData( mimeData ); |
70 | |
71 | data.write( mimeData->data( QString::fromLatin1( "application/x-xbel" ) ) ); |
72 | |
73 | } |
74 | |
75 | Q_EXPORT_PLUGIN2( akonadi_serializer_bookmark, SerializerPluginBookmark ) |
76 | |
77 | |