2
* evolution2_sync - A plugin for the opensync framework
3
* Copyright (C) 2004-2005 Armin Bauer <armin.bauer@opensync.org>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include "evolution2_sync.h"
23
osync_bool evo2_todo_open(evo_environment *env, OSyncError **error)
25
osync_trace(TRACE_ENTRY, "%s(%p)", __func__, env);
26
ESourceList *sources = NULL;
27
ESource *source = NULL;
28
GError *gerror = NULL;
30
if (strcmp(env->tasks_path, "default")) {
31
if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_TODO, &gerror)) {
32
osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to get sources for tasks: %s", gerror ? gerror->message : "None");
33
osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
34
g_clear_error(&gerror);
38
source = evo2_find_source(sources, env->tasks_path);
40
osync_error_set(error, OSYNC_ERROR_GENERIC, "Unable to find source for tasks");
41
osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
45
env->tasks = e_cal_new(source, E_CAL_SOURCE_TYPE_TODO);
47
osync_error_set(error, OSYNC_ERROR_GENERIC, "Failed to create new tasks");
48
osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
52
if(!e_cal_open(env->tasks, FALSE, &gerror)) {
53
osync_error_set(error, OSYNC_ERROR_GENERIC, "Failed to open tasks: %s", gerror ? gerror->message : "None");
54
g_object_unref(env->tasks);
56
osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
57
g_clear_error(&gerror);
61
if (!e_cal_open_default (&env->tasks, E_CAL_SOURCE_TYPE_TODO, NULL, NULL, &gerror)) {
62
osync_error_set(error, OSYNC_ERROR_GENERIC, "Failed to open default tasks: %s", gerror ? gerror->message : "None");
64
osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
65
g_clear_error(&gerror);
70
if (!osync_anchor_compare(env->member, "todo", env->tasks_path))
71
osync_member_set_slow_sync(env->member, "todo", TRUE);
73
osync_trace(TRACE_EXIT, "%s", __func__);
77
void evo2_todo_get_changes(OSyncContext *ctx)
79
osync_trace(TRACE_ENTRY, "%s(%p)", __func__, ctx);
80
evo_environment *env = (evo_environment *)osync_context_get_plugin_data(ctx);
82
GList *changes = NULL;
85
const char *uid = NULL;
87
GError *gerror = NULL;
89
if (osync_member_get_slow_sync(env->member, "todo") == FALSE) {
90
osync_debug("EVO2-SYNC", 4, "No slow_sync for todo");
91
if (!e_cal_get_changes(env->tasks, env->change_id, &changes, &gerror)) {
92
osync_context_send_log(ctx, "Unable to open changed tasks entries");
93
osync_trace(TRACE_EXIT_ERROR, "%s: Unable to open changed tasks entries: %s", __func__, gerror ? gerror->message : "None");
94
g_clear_error(&gerror);
98
for (l = changes; l; l = l->next) {
99
ECalChange *ecc = (ECalChange *)l->data;
100
e_cal_component_get_uid(ecc->comp, &uid);
101
e_cal_component_commit_sequence (ecc->comp);
102
e_cal_component_strip_errors(ecc->comp);
104
case E_CAL_CHANGE_ADDED:
105
data = e_cal_get_component_as_string(env->calendar, e_cal_component_get_icalcomponent(ecc->comp));
106
datasize = strlen(data) + 1;
107
evo2_report_change(ctx, "todo", "vtodo20", data, datasize, uid, CHANGE_ADDED);
109
case E_CAL_CHANGE_MODIFIED:
110
data = e_cal_get_component_as_string(env->calendar, e_cal_component_get_icalcomponent(ecc->comp));
111
datasize = strlen(data) + 1;
112
evo2_report_change(ctx, "todo", "vtodo20", data, datasize, uid, CHANGE_MODIFIED);
114
case E_CAL_CHANGE_DELETED:
115
evo2_report_change(ctx, "todo", "vtodo20", NULL, 0, uid, CHANGE_DELETED);
120
osync_debug("EVO2-SYNC", 4, "slow_sync for todo");
121
if (!e_cal_get_object_list_as_comp (env->tasks, "(contains? \"any\" \"\")", &changes, &gerror)) {
122
osync_context_send_log(ctx, "Unable to get all todos");
123
osync_trace(TRACE_EXIT_ERROR, "%s: Unable to get all todos: %s", __func__, gerror ? gerror->message : "None");
124
g_clear_error(&gerror);
127
for (l = changes; l; l = l->next) {
128
ECalComponent *comp = E_CAL_COMPONENT (l->data);
129
char *data = e_cal_get_component_as_string(env->tasks, e_cal_component_get_icalcomponent(comp));
130
const char *uid = NULL;
131
e_cal_component_get_uid(comp, &uid);
132
int datasize = strlen(data) + 1;
133
evo2_report_change(ctx, "todo", "vtodo20", data, datasize, uid, CHANGE_ADDED);
134
g_object_unref (comp);
137
osync_trace(TRACE_EXIT, "%s", __func__);
141
static osync_bool evo2_todo_modify(OSyncContext *ctx, OSyncChange *change)
143
osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, ctx, change);
144
evo_environment *env = (evo_environment *)osync_context_get_plugin_data(ctx);
146
const char *uid = osync_change_get_uid(change);
147
char *data = osync_change_get_data(change);
148
icalcomponent *icomp = NULL;
149
char *returnuid = NULL;
150
GError *gerror = NULL;
152
switch (osync_change_get_changetype(change)) {
154
if (!e_cal_remove_object(env->tasks, uid, &gerror)) {
155
osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to delete todo: %s", gerror ? gerror->message : "None");
156
osync_trace(TRACE_EXIT_ERROR, "%s: Unable to delete todo: %s", __func__, gerror ? gerror->message : "None");
157
g_clear_error(&gerror);
162
icomp = icalcomponent_new_from_string(data);
164
osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to convert todo");
165
osync_trace(TRACE_EXIT_ERROR, "%s: Unable to convert todo", __func__);
169
icomp = icalcomponent_get_first_component (icomp, ICAL_VTODO_COMPONENT);
171
osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to get todo");
172
osync_trace(TRACE_EXIT_ERROR, "%s: Unable to get todo", __func__);
176
if (!e_cal_create_object(env->tasks, icomp, &returnuid, &gerror)) {
177
osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to create todo: %s", gerror ? gerror->message : "None");
178
osync_trace(TRACE_EXIT_ERROR, "%s: Unable to create todo: %s", __func__, gerror ? gerror->message : "None");
179
g_clear_error(&gerror);
182
osync_change_set_uid(change, returnuid);
184
case CHANGE_MODIFIED:
185
icomp = icalcomponent_new_from_string(data);
187
osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to convert todo2");
188
osync_trace(TRACE_EXIT_ERROR, "%s: Unable to convert todo2", __func__);
192
icomp = icalcomponent_get_first_component (icomp, ICAL_VTODO_COMPONENT);
194
osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to get todo2");
195
osync_trace(TRACE_EXIT_ERROR, "%s: Unable to get todo2", __func__);
199
icalcomponent_set_uid (icomp, uid);
200
if (!e_cal_modify_object(env->tasks, icomp, CALOBJ_MOD_ALL, &gerror)) {
201
osync_context_report_error(ctx, OSYNC_ERROR_GENERIC, "Unable to modify todo: %s", gerror ? gerror->message : "None");
202
osync_trace(TRACE_EXIT_ERROR, "%s: Unable to modify todo: %s", __func__, gerror ? gerror->message : "None");
203
g_clear_error(&gerror);
211
osync_context_report_success(ctx);
212
osync_trace(TRACE_EXIT, "%s", __func__);
216
void evo2_tasks_setup(OSyncPluginInfo *info)
218
osync_plugin_accept_objtype(info, "todo");
219
osync_plugin_accept_objformat(info, "todo", "vtodo20", NULL);
220
osync_plugin_set_commit_objformat(info, "todo", "vtodo20", evo2_todo_modify);
221
osync_plugin_set_access_objformat(info, "todo", "vtodo20", evo2_todo_modify);