177
206
position = E_GW_CURSOR_POSITION_CURRENT;
179
208
e_gw_connection_destroy_cursor (priv->cnc, priv->container_id, cursor);
209
e_cal_backend_notify_view_done (E_CAL_BACKEND (cbgw), GNOME_Evolution_Calendar_Success);
181
211
g_mutex_unlock (mutex);
183
213
return E_GW_CONNECTION_STATUS_OK;
216
compare_prefix (gconstpointer a, gconstpointer b)
218
return !(g_str_has_prefix ((const char *)a, (const char *)b));
187
222
get_deltas (gpointer handle)
189
ECalBackendGroupwise *cbgw;
224
ECalBackendGroupwise *cbgw;
190
225
ECalBackendGroupwisePrivate *priv;
191
226
EGwConnection *cnc;
192
ECalBackendCache *cache;
193
EGwConnectionStatus status;
227
ECalBackendCache *cache;
228
EGwConnectionStatus status;
194
229
icalcomponent_kind kind;
195
GSList *item_list, *cache_keys, *l;
230
GList *item_list, *total_list = NULL, *l;
231
GSList *cache_keys = NULL;
232
GPtrArray *uid_array = g_ptr_array_new ();
197
233
char *time_string = NULL;
198
234
char t_str [100];
235
const char *serv_time;
236
static GStaticMutex connecting = G_STATIC_MUTEX_INIT;
237
const char *time_interval_string;
238
const char *key = "attempts";
239
const char *attempts;
240
const char *position ;
246
gboolean done = FALSE;
250
gboolean needs_to_get = FALSE;
203
254
cbgw = (ECalBackendGroupwise *) handle;
204
255
priv= cbgw->priv;
205
256
kind = e_cal_backend_get_kind (E_CAL_BACKEND (cbgw));
208
259
item_list = NULL;
210
261
if (priv->mode == CAL_MODE_LOCAL)
213
g_strlcpy (t_str, e_cal_backend_cache_get_server_utc_time (cache), 100);
214
if (!*t_str || !strcmp (t_str, "")) {
219
g_warning (" Could not get the correct time stamp for using in getQuick Messages\n");
264
attempts = e_cal_backend_cache_get_key_value (cache, key);
266
g_static_mutex_lock (&connecting);
268
serv_time = e_cal_backend_cache_get_server_utc_time (cache);
270
g_strlcpy (t_str, e_cal_backend_cache_get_server_utc_time (cache), 100);
271
if (!*t_str || !strcmp (t_str, "")) {
272
/* FIXME: When time-stamp is crashed, getting changes from current time */
273
g_warning ("\n\a Could not get the correct time stamp. \n\a");
274
temp = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
275
current_time = icaltime_as_timet_with_zone (temp, icaltimezone_get_utc_timezone ());
276
tm = gmtime (¤t_time);
277
strftime (t_str, 100, "%Y-%m-%dT%H:%M:%SZ", tm);
280
/* FIXME: When time-stamp is crashed, getting changes from current time */
281
g_warning ("\n\a Could not get the correct time stamp. \n\a");
220
282
temp = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
221
283
current_time = icaltime_as_timet_with_zone (temp, icaltimezone_get_utc_timezone ());
222
284
tm = gmtime (¤t_time);
223
285
strftime (t_str, 100, "%Y-%m-%dT%H:%M:%SZ", tm);
226
time_string = g_strdup (t_str);
227
status = e_gw_connection_get_quick_messages (cnc, cbgw->priv->container_id, "attachments recipients message recipientStatus default peek", &time_string, "New", "CalendarItem", NULL, -1, &item_list);
229
if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
230
status = e_gw_connection_get_quick_messages (cnc, cbgw->priv->container_id, "attachments recipients message recipientStatus default peek", &time_string, "New", "CalendarItem", NULL, -1, &item_list);
232
if (status != E_GW_CONNECTION_STATUS_OK) {
234
if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE)
237
e_cal_backend_groupwise_notify_error_code (cbgw, status);
240
/* store the timestamp in the cache */
241
e_cal_backend_cache_put_server_utc_time (cache, time_string);
242
g_free (time_string), time_string = NULL;
244
e_file_cache_freeze_changes (E_FILE_CACHE (cache));
245
for (; item_list != NULL; item_list = g_slist_next(item_list)) {
246
EGwItem *item = E_GW_ITEM(item_list->data);
247
ECalComponent *comp = e_gw_item_to_cal_component (item, cbgw);
249
e_cal_component_commit_sequence (comp);
252
if (!e_cal_backend_cache_put_component (cache, comp))
253
g_message ("Could not add the component");
255
if (kind == icalcomponent_isa (e_cal_component_get_icalcomponent (comp))) {
256
comp_str = e_cal_component_get_as_string (comp);
257
e_cal_backend_notify_object_created (E_CAL_BACKEND (cbgw), comp_str);
263
g_message ("Invalid component returned");
265
g_object_unref (comp);
266
g_object_unref (item);
269
g_slist_free (item_list);
272
e_file_cache_thaw_changes (E_FILE_CACHE (cache));
274
/* We must use the same timestamp used for getQm call with message list New */
275
time_string = g_strdup (t_str);
277
status = e_gw_connection_get_quick_messages (cnc, cbgw->priv->container_id,"attachments recipients message recipientStatus default", &time_string, "Modified", "CalendarItem", NULL, -1, &item_list);
279
if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
280
status = e_gw_connection_get_quick_messages (cnc, cbgw->priv->container_id,"recipients message recipientStatus default", &time_string, "Modified", "CalendarItem", NULL, -1, &item_list);
283
g_free (time_string);
284
if (status != E_GW_CONNECTION_STATUS_OK) {
285
if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE)
288
e_cal_backend_groupwise_notify_error_code (cbgw, status);
293
e_file_cache_freeze_changes (E_FILE_CACHE (cache));
295
for (; item_list != NULL; item_list = g_slist_next(item_list)) {
296
EGwItem *item = E_GW_ITEM(item_list->data);
297
ECalComponent *modified_comp, *cache_comp;
298
char *cache_comp_str;
287
time_string = g_strdup (t_str);
289
filter = e_gw_filter_new ();
290
/* Items modified after the time-stamp */
291
e_gw_filter_add_filter_component (filter, E_GW_FILTER_OP_GREATERTHAN, "modified", time_string);
293
status = e_gw_connection_get_items (cnc, cbgw->priv->container_id, "attachments recipients message recipientStatus default peek", filter, &item_list);
294
if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
295
status = e_gw_connection_get_items (cnc, cbgw->priv->container_id, "attachments recipients message recipientStatus default peek", filter, &item_list);
296
g_object_unref (filter);
298
if (status != E_GW_CONNECTION_STATUS_OK) {
300
const char *msg = NULL;
303
e_cal_backend_cache_put_key_value (cache, key, "2");
306
failures = g_ascii_strtod(attempts, NULL) + 1;
307
e_cal_backend_cache_put_key_value (cache, key, GINT_TO_POINTER (failures));
310
if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) {
311
g_static_mutex_unlock (&connecting);
315
msg = e_gw_connection_get_error_message (status);
317
g_static_mutex_unlock (&connecting);
321
e_file_cache_freeze_changes (E_FILE_CACHE (cache));
323
for (; item_list != NULL; item_list = g_list_next(item_list)) {
324
EGwItem *item = NULL;
325
item = E_GW_ITEM(item_list->data);
326
ECalComponent *modified_comp = NULL, *cache_comp = NULL;
327
char *cache_comp_str = NULL;
328
const char *uid, *rid = NULL;
300
331
modified_comp = e_gw_item_to_cal_component (item, cbgw);
301
332
if (!modified_comp) {
302
333
g_message ("Invalid component returned in update");
305
cache_comp = e_cal_backend_cache_get_component (cache, e_gw_item_get_icalid (item), NULL);
336
if ((r_key = e_gw_item_get_recurrence_key (item)) != 0)
337
rid = e_cal_component_get_recurid_as_string (modified_comp);
339
e_cal_component_get_uid (modified_comp, &uid);
340
cache_comp = e_cal_backend_cache_get_component (cache, uid, rid);
306
341
e_cal_component_commit_sequence (modified_comp);
307
342
e_cal_component_commit_sequence (cache_comp);
310
345
cache_comp_str = e_cal_component_get_as_string (cache_comp);
311
346
e_cal_backend_notify_object_modified (E_CAL_BACKEND (cbgw), cache_comp_str, e_cal_component_get_as_string (modified_comp));
312
347
g_free (cache_comp_str);
348
cache_comp_str = NULL;
314
350
e_cal_backend_cache_put_component (cache, modified_comp);
315
352
g_object_unref (item);
316
353
g_object_unref (modified_comp);
318
355
e_file_cache_thaw_changes (E_FILE_CACHE (cache));
357
temp = icaltime_from_string (time_string);
358
current_time = icaltime_as_timet_with_zone (temp, icaltimezone_get_utc_timezone ());
359
tm = gmtime (¤t_time);
361
time_interval = (CACHE_REFRESH_INTERVAL / 60000);
362
time_interval_string = g_getenv ("GETQM_TIME_INTERVAL");
363
if (time_interval_string) {
364
time_interval = g_ascii_strtod (time_interval_string, NULL);
367
tm->tm_min += (time_interval * g_ascii_strtod (attempts, NULL));
368
e_cal_backend_cache_put_key_value (cache, key, NULL);
370
tm->tm_min += time_interval;
372
strftime (t_str, 100, "%Y-%m-%dT%H:%M:%SZ", tm);
373
time_string = g_strdup (t_str);
375
e_cal_backend_cache_put_server_utc_time (cache, time_string);
377
g_free (time_string);
321
g_slist_free (item_list);
381
g_list_free (item_list);
322
382
item_list = NULL;
325
status = e_gw_connection_get_quick_messages (cnc, cbgw->priv->container_id, "iCalId", NULL, "All", "CalendarItem", NULL, -1, &item_list);
327
if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
328
status = e_gw_connection_get_quick_messages (cnc, cbgw->priv->container_id, "iCalId", NULL, "All", "CalendarItem", NULL, -1, &item_list);
330
if (status != E_GW_CONNECTION_STATUS_OK) {
331
if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE)
334
e_cal_backend_groupwise_notify_error_code (cbgw, status);
385
/* TODO currently the read cursors response does not give us the recurrencKey, uncomment
386
this once the response gives the recurrenceKey */
338
387
/* handle deleted items here by going over the entire cache and
339
388
* checking for deleted items.*/
389
position = E_GW_CURSOR_POSITION_END;
391
status = e_gw_connection_create_cursor (cnc, cbgw->priv->container_id, "id iCalId recurrenceKey", NULL, &cursor);
393
if (status != E_GW_CONNECTION_STATUS_OK) {
394
if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) {
395
g_static_mutex_unlock (&connecting);
399
e_cal_backend_groupwise_notify_error_code (cbgw, status);
400
g_static_mutex_unlock (&connecting);
341
404
cache_keys = e_cal_backend_cache_get_keys (cache);
342
for (l = item_list; l; l = g_slist_next (l)) {
343
/* this works assuming rid is null*/
344
cache_keys = g_slist_delete_link (cache_keys,
345
g_slist_find_custom (cache_keys, l->data, (GCompareFunc) strcmp));
408
status = e_gw_connection_read_cal_ids (cnc, cbgw->priv->container_id, cursor, FALSE, CURSOR_ICALID_LIMIT, position, &item_list);
409
if (status != E_GW_CONNECTION_STATUS_OK) {
410
if (status == E_GW_CONNECTION_STATUS_NO_RESPONSE) {
411
g_static_mutex_unlock (&connecting);
414
e_cal_backend_groupwise_notify_error_code (cbgw, status);
415
g_static_mutex_unlock (&connecting);
419
/* FIXME handle deleted items here by going over the entire cache and
420
* checking for deleted items.*/
422
for (l1 = item_list; l1; l1 = g_list_next (l1)) {
424
icalid = (char *)(l1->data);
425
cache_keys = g_slist_delete_link (cache_keys,
426
g_slist_find_custom (cache_keys, icalid, (GCompareFunc) strcmp));
431
if (!item_list || g_list_length (item_list) == 0)
435
total_list = item_list;
437
total_list = g_list_concat (total_list, item_list);
442
position = E_GW_CURSOR_POSITION_CURRENT;
445
e_gw_connection_destroy_cursor (cnc, cbgw->priv->container_id, cursor);
349
446
e_file_cache_freeze_changes (E_FILE_CACHE (cache));
350
449
for (l = cache_keys; l ; l = g_slist_next (l)) {
351
450
/* assumes rid is null - which works for now */
352
451
ECalComponent *comp = NULL;
452
GSList *comp_list = NULL;
353
453
ECalComponentVType vtype;
355
455
comp = e_cal_backend_cache_get_component (cache, (const char *) l->data, NULL);
362
462
(vtype == E_CAL_COMPONENT_TODO)) {
363
463
comp_str = e_cal_component_get_as_string (comp);
364
464
e_cal_backend_notify_object_removed (E_CAL_BACKEND (cbgw),
365
(char *) l->data, comp_str, NULL);
465
(char *) l->data, comp_str, NULL);
366
466
e_cal_backend_cache_remove_component (cache, (const char *) l->data, NULL);
367
467
g_free (comp_str);
369
469
g_object_unref (comp);
473
for (l = total_list; l != NULL; l = l->next) {
474
EGwItemCalId *calid = (EGwItemCalId *) l->data;
475
GCompareFunc func = NULL;
476
GSList *remove = NULL;
479
func = (GCompareFunc) strcmp;
481
func = (GCompareFunc) compare_prefix;
483
if (!(remove = g_slist_find_custom (cache_keys, calid->ical_id ? calid->ical_id :
484
calid->recur_key, func))) {
485
g_ptr_array_add (uid_array, g_strdup (calid->item_id));
488
cache_keys = g_slist_delete_link (cache_keys, remove);
495
e_gw_connection_get_items_from_ids (priv->cnc,
497
"attachments recipients message recipientStatus default peek",
498
uid_array, &item_list);
500
for (l = item_list; l != NULL; l = l->next) {
501
ECalComponent *comp = NULL;
502
EGwItem *item = NULL;
505
item = (EGwItem *) l->data;
506
comp = e_gw_item_to_cal_component (item, cbgw);
508
e_cal_component_commit_sequence (comp);
509
sanitize_component (E_CAL_BACKEND_SYNC (cbgw), comp, (char *) e_gw_item_get_id (item));
510
e_cal_backend_cache_put_component (priv->cache, comp);
513
if (kind == icalcomponent_isa (e_cal_component_get_icalcomponent (comp))) {
514
temp = e_cal_component_get_as_string (comp);
515
e_cal_backend_notify_object_created (E_CAL_BACKEND (cbgw), temp);
518
g_object_unref (comp);
521
g_object_unref (item);
371
525
e_file_cache_thaw_changes (E_FILE_CACHE (cache));
527
g_ptr_array_free (uid_array, TRUE);
374
g_slist_free (item_list);
530
g_list_free (item_list);
375
531
item_list = NULL;
535
g_list_foreach (total_list, (GFunc) e_gw_item_free_cal_id, NULL);
536
g_list_free (total_list);
377
539
if (cache_keys) {
378
540
g_slist_free (cache_keys);
543
g_static_mutex_unlock (&connecting);
549
get_deltas_timeout (gpointer cbgw)
552
GError *error = NULL;
557
thread = g_thread_create ((GThreadFunc) get_deltas, cbgw, FALSE, &error);
559
g_warning (G_STRLOC ": %s", error->message);
560
g_error_free (error);
386
568
form_uri (ESource *source)
510
692
static ECalBackendSyncStatus
693
set_container_id_with_count (ECalBackendGroupwise *cbgw)
695
ECalBackendGroupwisePrivate *priv;
696
GList *container_list = NULL, *l;
697
EGwConnectionStatus status;
698
icalcomponent_kind kind;
699
ECalBackendSyncStatus res;
703
kind = e_cal_backend_get_kind (E_CAL_BACKEND (cbgw));
706
case ICAL_VEVENT_COMPONENT:
707
case ICAL_VTODO_COMPONENT:
708
e_source_set_name (e_cal_backend_get_source (E_CAL_BACKEND (cbgw)), _("Calendar"));
711
priv->container_id = NULL;
712
return GNOME_Evolution_Calendar_UnsupportedMethod;
715
status = e_gw_connection_get_container_list (priv->cnc, "folders", &container_list);
717
if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
718
status = e_gw_connection_get_container_list (priv->cnc, "folders", &container_list);
720
if (status != E_GW_CONNECTION_STATUS_OK)
721
return GNOME_Evolution_Calendar_OtherError;
723
res = GNOME_Evolution_Calendar_ObjectNotFound;
724
for (l = container_list; l != NULL; l = l->next) {
725
EGwContainer *container = E_GW_CONTAINER (l->data);
726
const char *name = e_gw_container_get_name (container);
728
if (name && strcmp (name, "Calendar") == 0) {
729
priv->container_id = g_strdup (e_gw_container_get_id (container));
730
priv->total_count = e_gw_container_get_total_count (container);
731
res = GNOME_Evolution_Calendar_Success;
736
e_gw_connection_free_container_list (container_list);
741
static ECalBackendSyncStatus
511
742
connect_to_server (ECalBackendGroupwise *cbgw)
525
760
real_uri = form_uri (source);
526
761
use_ssl = e_source_get_property (source, "use_ssl");
529
764
e_cal_backend_notify_error (E_CAL_BACKEND (cbgw), _("Invalid server URI"));
530
765
return GNOME_Evolution_Calendar_NoSuchCal;
767
parent_user = (char *) e_source_get_property (source, "parent_id_name");
532
768
/* create connection to server */
533
priv->cnc = e_gw_connection_new (
538
if (!E_IS_GW_CONNECTION(priv->cnc) && use_ssl && g_str_equal (use_ssl, "when-possible")) {
539
http_uri = g_strconcat ("http://", real_uri + 8, NULL);
540
priv->cnc = e_gw_connection_new (http_uri, priv->username, priv->password);
771
/* create connection to server */
772
cnc = e_gw_connection_new (real_uri, parent_user, priv->password);
773
if (!E_IS_GW_CONNECTION(cnc) && use_ssl && g_str_equal (use_ssl, "when-possible")) {
774
http_uri = g_strconcat ("http://", real_uri + 8, NULL);
775
cnc = e_gw_connection_new (http_uri, parent_user, priv->password);
780
e_cal_backend_notify_error (E_CAL_BACKEND (cbgw), _("Authentication failed"));
781
return GNOME_Evolution_Calendar_AuthenticationFailed;
784
priv->cnc = e_gw_connection_get_proxy_connection (cnc, parent_user, priv->password, priv->username, &permissions);
789
e_cal_backend_notify_error (E_CAL_BACKEND (cbgw), _("Authentication failed"));
790
return GNOME_Evolution_Calendar_AuthenticationFailed;
793
kind = e_cal_backend_get_kind (E_CAL_BACKEND (cbgw));
795
cbgw->priv->read_only = TRUE;
797
if (kind == ICAL_VEVENT_COMPONENT && (permissions & E_GW_PROXY_APPOINTMENT_WRITE) )
798
cbgw->priv->read_only = FALSE;
799
else if (kind == ICAL_VTODO_COMPONENT && (permissions & E_GW_PROXY_TASK_WRITE))
800
cbgw->priv->read_only = FALSE;
804
priv->cnc = e_gw_connection_new (
809
if (!E_IS_GW_CONNECTION(priv->cnc) && use_ssl && g_str_equal (use_ssl, "when-possible")) {
810
http_uri = g_strconcat ("http://", real_uri + 8, NULL);
811
priv->cnc = e_gw_connection_new (http_uri, priv->username, priv->password);
814
cbgw->priv->read_only = FALSE;
543
816
g_free (real_uri);
545
/* As of now we are assuming that logged in user has write rights to calender */
546
/* we need to read actual rights from server when we implement proxy user access */
547
cbgw->priv->read_only = FALSE;
549
if (priv->cnc && priv->cache) {
818
if (priv->cnc && priv->cache && priv->container_id) {
550
820
priv->mode = CAL_MODE_REMOTE;
551
821
if (priv->mode_changed && !priv->timeout_id && (e_cal_backend_get_kind (E_CAL_BACKEND (cbgw)) == ICAL_VEVENT_COMPONENT)) {
552
822
GThread *thread1;
560
830
e_cal_backend_notify_error (E_CAL_BACKEND (cbgw), _("Could not create thread for getting deltas"));
561
831
return GNOME_Evolution_Calendar_OtherError;
563
priv->timeout_id = g_timeout_add (CACHE_REFRESH_INTERVAL, (GSourceFunc) get_deltas, (gpointer) cbgw);
833
priv->timeout_id = g_timeout_add (CACHE_REFRESH_INTERVAL, (GSourceFunc) get_deltas_timeout, (gpointer)cbgw);
835
utc_str = (char *) e_gw_connection_get_server_time (priv->cnc);
836
e_cal_backend_cache_put_server_utc_time (priv->cache, utc_str);
567
838
return GNOME_Evolution_Calendar_Success;
569
840
priv->mode_changed = FALSE;
571
842
if (E_IS_GW_CONNECTION (priv->cnc)) {
572
icalcomponent_kind kind;
843
ECalBackendSyncStatus status;
574
844
/* get the ID for the container */
575
845
if (priv->container_id)
576
846
g_free (priv->container_id);
578
kind = e_cal_backend_get_kind (E_CAL_BACKEND (cbgw));
580
if (kind == ICAL_VEVENT_COMPONENT) {
581
priv->container_id = g_strdup (e_gw_connection_get_container_id (priv->cnc, "Calendar"));
582
e_source_set_name (e_cal_backend_get_source (E_CAL_BACKEND (cbgw)), _("Calendar"));
583
} else if (kind == ICAL_VTODO_COMPONENT) {
584
priv->container_id = g_strdup (e_gw_connection_get_container_id (priv->cnc, "Calendar"));
585
e_source_set_name (e_cal_backend_get_source (E_CAL_BACKEND (cbgw)), _("Calendar"));
587
priv->container_id = NULL;
848
if ((status = set_container_id_with_count (cbgw)) != GNOME_Evolution_Calendar_Success) {
589
852
priv->cache = e_cal_backend_cache_new (e_cal_backend_get_uri (E_CAL_BACKEND (cbgw)));
590
853
if (!priv->cache) {
591
854
g_mutex_unlock (priv->mutex);
756
1019
static ECalBackendSyncStatus
757
1020
e_cal_backend_groupwise_get_static_capabilities (ECalBackendSync *backend, EDataCal *cal, char **capabilities)
759
*capabilities = g_strdup (CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS "," \
760
CAL_STATIC_CAPABILITY_ONE_ALARM_ONLY "," \
761
CAL_STATIC_CAPABILITY_REMOVE_ALARMS "," \
762
CAL_STATIC_CAPABILITY_NO_THISANDPRIOR "," \
763
CAL_STATIC_CAPABILITY_NO_THISANDFUTURE "," \
764
CAL_STATIC_CAPABILITY_NO_CONV_TO_ASSIGN_TASK "," \
765
CAL_STATIC_CAPABILITY_NO_CONV_TO_RECUR "," \
766
CAL_STATIC_CAPABILITY_REQ_SEND_OPTIONS "," \
1022
*capabilities = g_strdup (CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS ","
1023
CAL_STATIC_CAPABILITY_ONE_ALARM_ONLY ","
1024
CAL_STATIC_CAPABILITY_REMOVE_ALARMS ","
1025
CAL_STATIC_CAPABILITY_NO_THISANDPRIOR ","
1026
CAL_STATIC_CAPABILITY_NO_THISANDFUTURE ","
1027
CAL_STATIC_CAPABILITY_NO_CONV_TO_ASSIGN_TASK ","
1028
CAL_STATIC_CAPABILITY_NO_CONV_TO_RECUR ","
1029
CAL_STATIC_CAPABILITY_REQ_SEND_OPTIONS ","
1030
CAL_STATIC_CAPABILITY_SAVE_SCHEDULES ","
1031
CAL_STATIC_CAPABILITY_ORGANIZER_MUST_ACCEPT ","
1032
CAL_STATIC_CAPABILITY_DELEGATE_SUPPORTED ","
1033
CAL_STATIC_CAPABILITY_DELEGATE_TO_MANY ","
1034
CAL_STATIC_CAPABILITY_NO_ORGANIZER ","
1035
CAL_STATIC_CAPABILITY_RECURRENCES_NO_MASTER ","
1036
CAL_STATIC_CAPABILITY_HAS_UNACCEPTED_MEETING ","
767
1037
CAL_STATIC_CAPABILITY_SAVE_SCHEDULES);
769
1039
return GNOME_Evolution_Calendar_Success;
1518
1805
comp = e_cal_component_new ();
1519
1806
e_cal_component_set_icalcomponent (comp, icalcomp);
1520
item = e_gw_item_new_from_cal_component (priv->container_id, cbgw, comp);
1807
e_cal_component_get_uid (comp, &uid);
1522
1809
/* check if the object exists */
1523
1810
switch (priv->mode) {
1524
1811
case CAL_MODE_ANY :
1525
1812
case CAL_MODE_REMOTE :
1526
1813
/* when online, send the item to the server */
1527
cache_comp = e_cal_backend_cache_get_component (priv->cache, e_gw_item_get_icalid (item), NULL);
1814
cache_comp = e_cal_backend_cache_get_component (priv->cache, uid, NULL);
1528
1815
if (!cache_comp) {
1529
1816
g_message ("CRITICAL : Could not find the object in cache");
1530
1817
return GNOME_Evolution_Calendar_ObjectNotFound;
1820
if (e_cal_component_has_attendees (comp) &&
1821
e_cal_backend_groupwise_utils_check_delegate (comp, e_gw_connection_get_user_email (priv->cnc))) {
1822
const char *id = NULL, *recur_key = NULL;
1824
item = e_gw_item_new_for_delegate_from_cal (cbgw, comp);
1826
if (mod == CALOBJ_MOD_ALL && e_cal_component_is_instance (comp)) {
1829
id = e_gw_item_get_id (item);
1832
status = e_gw_connection_delegate_request (priv->cnc, item, id, NULL, NULL, recur_key);
1834
if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
1835
status = e_gw_connection_delegate_request (priv->cnc, item, id, NULL, NULL, recur_key);
1837
if (status != E_GW_CONNECTION_STATUS_OK) {
1838
g_object_unref (comp);
1839
g_object_unref (cache_comp);
1840
return GNOME_Evolution_Calendar_OtherError;
1844
e_cal_backend_cache_put_component (priv->cache, comp);
1845
*new_object = e_cal_component_get_as_string (comp);
1849
item = e_gw_item_new_from_cal_component (priv->container_id, cbgw, comp);
1533
1850
cache_item = e_gw_item_new_from_cal_component (priv->container_id, cbgw, cache_comp);
1534
1851
if ( e_gw_item_get_item_type (item) == E_GW_ITEM_TYPE_TASK) {
1535
1852
gboolean completed, cache_completed;
1602
1941
if (priv->mode == CAL_MODE_REMOTE) {
1603
1942
ECalBackendSyncStatus status;
1604
1943
const char *id_to_remove = NULL;
1605
icalproperty *icalprop;
1606
1944
icalcomponent *icalcomp;
1608
status = e_cal_backend_groupwise_get_object (backend, cal, uid, rid, &calobj);
1609
if (status != GNOME_Evolution_Calendar_Success)
1612
*old_object = strdup (calobj);
1614
icalcomp = icalparser_parse_string (calobj);
1617
return GNOME_Evolution_Calendar_InvalidObject;
1620
/* search the component for the X-GWRECORDID property */
1621
icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);
1623
const char *x_name, *x_val;
1625
x_name = icalproperty_get_x_name (icalprop);
1626
x_val = icalproperty_get_x (icalprop);
1627
if (!strcmp (x_name, "X-GWRECORDID")) {
1628
id_to_remove = x_val;
1632
icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
1635
if (!id_to_remove) {
1636
/* use the iCalId to remove the object */
1640
/* remove the object */
1641
status = e_gw_connection_remove_item (priv->cnc, priv->container_id, id_to_remove);
1643
if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
1946
if (mod == CALOBJ_MOD_THIS) {
1948
status = e_cal_backend_groupwise_get_object (backend, cal, uid, rid, &calobj);
1949
if (status != GNOME_Evolution_Calendar_Success)
1952
*old_object = strdup (calobj);
1954
icalcomp = icalparser_parse_string (calobj);
1957
return GNOME_Evolution_Calendar_InvalidObject;
1960
id_to_remove = get_gw_item_id (icalcomp);
1961
if (!id_to_remove) {
1962
/* use the iCalId to remove the object */
1966
/* remove the object */
1644
1967
status = e_gw_connection_remove_item (priv->cnc, priv->container_id, id_to_remove);
1646
icalcomponent_free (icalcomp);
1647
if (status == E_GW_CONNECTION_STATUS_OK) {
1648
/* remove the component from the cache */
1649
if (!e_cal_backend_cache_remove_component (priv->cache, uid, rid)) {
1651
return GNOME_Evolution_Calendar_ObjectNotFound;
1655
return GNOME_Evolution_Calendar_Success;
1658
return GNOME_Evolution_Calendar_OtherError;
1969
if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
1970
status = e_gw_connection_remove_item (priv->cnc, priv->container_id, id_to_remove);
1972
icalcomponent_free (icalcomp);
1973
if (status == E_GW_CONNECTION_STATUS_OK) {
1974
/* remove the component from the cache */
1975
if (!e_cal_backend_cache_remove_component (priv->cache, uid, rid)) {
1977
return GNOME_Evolution_Calendar_ObjectNotFound;
1981
return GNOME_Evolution_Calendar_Success;
1984
return GNOME_Evolution_Calendar_OtherError;
1986
} else if (mod == CALOBJ_MOD_ALL) {
1987
GSList *l, *comp_list = e_cal_backend_cache_get_components_by_uid (priv->cache, uid);
1989
if (e_cal_component_has_attendees (E_CAL_COMPONENT (comp_list->data))) {
1990
/* get recurrence key and send it to
1991
* e_gw_connection_remove_recurrence_item */
1993
id_to_remove = get_gw_item_id (e_cal_component_get_icalcomponent (comp_list->data));
1994
status = e_gw_connection_decline_request (priv->cnc, id_to_remove, NULL, uid);
1995
if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
1996
status = e_gw_connection_decline_request (priv->cnc, id_to_remove, NULL, uid);
1998
GList *item_ids = NULL;
1999
for (l = comp_list; l; l = l->next) {
2000
ECalComponent *comp = E_CAL_COMPONENT (l->data);
2002
id_to_remove = get_gw_item_id (e_cal_component_get_icalcomponent (comp));
2003
item_ids = g_list_append (item_ids, (char *) id_to_remove);
2005
status = e_gw_connection_remove_items (priv->cnc, priv->container_id, item_ids);
2007
if (status == E_GW_CONNECTION_STATUS_INVALID_CONNECTION)
2008
status = e_gw_connection_remove_items (priv->cnc, priv->container_id, item_ids);
2011
if (status == E_GW_CONNECTION_STATUS_OK) {
2013
for (l = comp_list; l; l = l->next) {
2014
ECalComponent *comp = E_CAL_COMPONENT (l->data);
2015
e_cal_backend_cache_remove_component (priv->cache, uid,
2016
e_cal_component_get_recurid_as_string (comp));
2017
e_cal_backend_notify_object_removed (E_CAL_BACKEND (cbgw),
2018
uid, e_cal_component_get_as_string (comp), NULL);
2019
g_object_unref (comp);
2022
/* Setting NULL would trigger another signal.
2023
* We do not set the *object to NULL */
2024
g_slist_free (comp_list);
2025
return GNOME_Evolution_Calendar_Success;
2027
return GNOME_Evolution_Calendar_OtherError;
2030
return GNOME_Evolution_Calendar_UnsupportedMethod;
1660
2031
} else if (priv->mode == CAL_MODE_LOCAL) {
1661
2032
in_offline (cbgw);
1662
2033
return GNOME_Evolution_Calendar_RepositoryOffline;
1665
/* remove the component from the cache */
1666
if (!e_cal_backend_cache_remove_component (priv->cache, uid, rid)) {
1668
return GNOME_Evolution_Calendar_ObjectNotFound;
1672
return GNOME_Evolution_Calendar_Success;
2035
return GNOME_Evolution_Calendar_CalListener_MODE_NOT_SUPPORTED;