Warning: That file was not part of the compilation database. It may have many parsing errors.

1/*
2 Copyright (c) 2008 Volker Krause <vkrause@kde.org>
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#ifndef DATASINK_H
21#define DATASINK_H
22
23#include "sinkbase.h"
24
25#include <akonadi/collection.h>
26#include <akonadi/itemfetchjob.h>
27#include <akonadi/itemcreatejob.h>
28#include <akonadi/itemmodifyjob.h>
29#include <akonadi/itemfetchscope.h>
30
31#include <opensync/opensync.h>
32#include <opensync/opensync-plugin.h>
33#include <opensync/opensync-data.h>
34#include <opensync/opensync-format.h>
35
36#include <boost/shared_ptr.hpp>
37
38using namespace Akonadi;
39
40/**
41 * Base class for data sink classes, dealing with the type-independent stuff.
42 */
43class DataSink : public SinkBase
44{
45 Q_OBJECT
46
47 public:
48 enum Type { Calendar = 0, Contacts, Notes };
49
50 DataSink( int type );
51 ~DataSink();
52
53 bool initialize( OSyncPlugin *plugin, OSyncPluginInfo *info, OSyncObjTypeSink *sink, OSyncError **error );
54
55 void getChanges();
56 void commit( OSyncChange *change );
57 void syncDone();
58
59 public slots:
60 void slotGetChangesFinished( KJob * );
61 void slotItemsReceived( const Akonadi::Item::List & );
62
63 protected:
64 /**
65 * Returns the collection we are supposed to sync with.
66 */
67 Akonadi::Collection collection() const;
68
69 /**
70 * This reports the change back to opensync
71 */
72 void reportChange( const Item& item, const QString& format );
73
74 /**
75 * Reimplement in subclass to provide data about changes to opensync. Note, that you must call DataSink::reportChange( Item, QString, int ) after you have organized data to be send to opensync.
76 */
77 void reportChange( const Item & item );
78
79 /**
80 * Creates a new item based on the data given by opensync.
81 */
82 const Item createItem( OSyncChange *change );
83 /**
84 * Modified an item based on the data given by opensync.
85 */
86 const Item modifyItem( OSyncChange *change );
87 /**
88 * Deletes an item based on the data given by opensync.
89 */
90 void deleteItem( OSyncChange *change );
91
92 private:
93 const Item createAkonadiItem( OSyncChange *change );
94 const Item fetchItem( const QString& id );
95 const QString formatName();
96 bool setPayload( Item *item, const QString &str );
97
98 private:
99 OSyncHashTable *m_hashtable;
100 int m_type;
101};
102
103#endif
104

Warning: That file was not part of the compilation database. It may have many parsing errors.