Imported Upstream version 1.3.99.3~20130529~SE~b989f69~SYSYNC~3366831
[platform/upstream/syncevolution.git] / src / backends / akonadi / akonadisyncsource.h
1 /*
2     Copyright (c) 2009 Sascha Peilicke <sasch.pe@gmx.de>
3
4     This application 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 application 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 application; 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 AKONADISYNCSOURCE_H
21 #define AKONADISYNCSOURCE_H
22
23 #include "config.h"
24
25 #ifdef ENABLE_AKONADI
26
27 #include <Akonadi/Collection>
28 #include <Akonadi/Item>
29
30 #include <QtCore/QDateTime>
31 #include <QtCore/QStringList>
32
33 #include <syncevo/TrackingSyncSource.h>
34
35 SE_BEGIN_CXX
36
37 class TimeTrackingObserver;
38
39 /**
40  * General purpose Akonadi Sync Source. Choosing the type of data is
41  * done when instantiating it, using the Akonadi MIME subtypes.
42  * Payload is always using the native Akonadi format (no special "raw"
43  * and "engine" formats).
44  *
45  * Change tracking is done via the item uid/revision attributes.
46  *
47  * Databases (collections in Akonadi terminology) are selected via
48  * their int64 ID number.
49  */
50 class AkonadiSyncSource : public TrackingSyncSource
51 {
52 public:
53     /**
54      * @param submime     the MIME type string used by Akonadi
55      *                    to identify contacts, tasks, events, etc.
56      * @param params      the SyncEvolution source parameters
57      */
58     AkonadiSyncSource(const char *submime,
59                       const SyncSourceParams &params);
60     virtual ~AkonadiSyncSource();
61
62     /* methods that have to be implemented to complete TrackingSyncSource */
63     virtual Databases getDatabases();
64     virtual void open();
65     virtual void listAllItems(SyncSourceRevisions::RevisionMap_t &revisions);
66     virtual InsertItemResult insertItem(const std::string &luid, const std::string &item, bool raw);
67     virtual void readItem(const std::string &luid, std::string &item, bool raw);
68     virtual void removeItem(const string &luid);
69     virtual void close();
70     virtual bool isEmpty();
71 private:
72     void start();
73 protected:
74     Akonadi::Collection m_collection;
75     const std::string m_subMime;
76 };
77
78 class AkonadiContactSource : public AkonadiSyncSource
79 {
80 public:
81     AkonadiContactSource(const SyncSourceParams &params)
82         : AkonadiSyncSource("text/directory", params)
83     {
84     }
85
86     virtual std::string getMimeType() const {
87         return "text/vcard";
88     }
89     virtual std::string getMimeVersion() const {
90         return "3.0";
91     }
92
93     void getSynthesisInfo(SynthesisInfo &info,
94                           XMLConfigFragments &fragments)
95     {
96         TrackingSyncSource::getSynthesisInfo(info, fragments);
97
98         /** enable the KDE X- extensions in the Synthesis<->backend conversion */
99         info.m_backendRule = "KDE";
100
101         /*
102          * Disable the default VCARD_BEFOREWRITE_SCRIPT_EVOLUTION.
103          * If any KDE-specific transformations via such a script
104          * are needed, it can be named here and then defined by appending
105          * to the fragments.
106          */
107         info.m_beforeWriteScript = ""; // "$VCARD_BEFOREWRITE_SCRIPT_KDE;";
108         // fragments.m_datatypes["VCARD_BEFOREWRITE_SCRIPT_KDE"] = "<macro name=\"VCARD_BEFOREWRITE_SCRIPT_KDE\"><![DATA[ ... ]]></macro>";
109     }
110 };
111
112 class AkonadiCalendarSource : public AkonadiSyncSource
113 {
114 public:
115     AkonadiCalendarSource(const SyncSourceParams &params)
116         : AkonadiSyncSource("application/x-vnd.akonadi.calendar.event", params)
117     {
118     }
119
120     // TODO: the items are expected to be complete VCALENDAR with
121     // all necessary VTIMEZONEs and one VEVENT (here) resp. VTODO
122     // (AkonadiTodoSource). Not sure what we get from Akonadi.
123     virtual std::string getMimeType() const { return "text/calendar"; }
124     virtual std::string getMimeVersion() const { return "2.0"; }
125 };
126
127 class AkonadiTaskSource : public AkonadiSyncSource
128 {
129 public:
130     AkonadiTaskSource(const SyncSourceParams &params)
131         : AkonadiSyncSource("application/x-vnd.akonadi.calendar.todo", params)
132     {
133     }
134
135     virtual std::string getMimeType() const { return "text/calendar"; }
136     virtual std::string getMimeVersion() const { return "2.0"; }
137 };
138
139 class AkonadiMemoSource : public AkonadiSyncSource
140 {
141 private:
142     QString toKJots(QString data);
143     QString toSynthesis(QString data);
144
145 public:
146     AkonadiMemoSource(const SyncSourceParams &params)
147         : AkonadiSyncSource("text/x-vnd.akonadi.note", params)
148     {
149     }
150
151     // TODO: the AkonadiMemoSource is expected to import/export
152     // plain text with the summary in the first line; currently
153     // the AkonadiSyncSource will use VJOURNAL
154     // Also Currently there is no application which uses akonadi backend
155     // to display notes: probably work for knote??
156     virtual std::string getMimeType() const { return "text/plain"; }
157     virtual std::string getMimeVersion() const { return "1.0"; }
158     virtual InsertItemResult insertItem(const std::string &luid, const std::string &item, bool raw);
159     virtual void readItem(const std::string &luid, std::string &item, bool raw);
160 };
161
162 SE_END_CXX
163
164 #endif // ENABLE_AKONADI
165 #endif // AKONADISYNCSOURCE_H