diff options
Diffstat (limited to 'calendar/conduits/calendar/calendar-conduit.c')
-rw-r--r-- | calendar/conduits/calendar/calendar-conduit.c | 104 |
1 files changed, 52 insertions, 52 deletions
diff --git a/calendar/conduits/calendar/calendar-conduit.c b/calendar/conduits/calendar/calendar-conduit.c index 1893e6b34c..39d341cfb5 100644 --- a/calendar/conduits/calendar/calendar-conduit.c +++ b/calendar/conduits/calendar/calendar-conduit.c @@ -253,7 +253,7 @@ struct _ECalConduitContext { icaltimezone *timezone; CalComponent *default_comp; - GList *uids; + GList *comps; GList *changed; GHashTable *changed_hash; GList *locals; @@ -276,7 +276,7 @@ e_calendar_context_new (guint32 pilot_id) ctxt->client = NULL; ctxt->timezone = NULL; ctxt->default_comp = NULL; - ctxt->uids = NULL; + ctxt->comps = NULL; ctxt->changed = NULL; ctxt->changed_hash = NULL; ctxt->locals = NULL; @@ -311,8 +311,11 @@ e_calendar_context_destroy (ECalConduitContext *ctxt) g_object_unref (ctxt->client); if (ctxt->default_comp != NULL) g_object_unref (ctxt->default_comp); - if (ctxt->uids != NULL) - cal_obj_uid_list_free (ctxt->uids); + if (ctxt->comps != NULL) { + for (l = ctxt->comps; l; l = l->next) + g_object_unref (l->data); + g_list_free (ctxt->comps); + } if (ctxt->changed != NULL) cal_client_change_list_free (ctxt->changed); @@ -433,8 +436,8 @@ get_timezone (CalClient *client, const char *tzid) icaltimezone *timezone = NULL; timezone = icaltimezone_get_builtin_timezone_from_tzid (tzid); - if (timezone == NULL) - cal_client_get_timezone (client, tzid, &timezone); + if (timezone == NULL) + cal_client_get_timezone (client, tzid, &timezone, NULL); return timezone; } @@ -550,7 +553,7 @@ is_all_day (CalClient *client, CalComponentDateTime *dt_start, CalComponentDateT } static gboolean -process_multi_day (ECalConduitContext *ctxt, CalClientChange *ccc, GList **multi_uid, GList **multi_ccc) +process_multi_day (ECalConduitContext *ctxt, CalClientChange *ccc, GList **multi_comp, GList **multi_ccc) { CalComponentDateTime dt_start, dt_end; icaltimezone *tz_start, *tz_end; @@ -562,7 +565,7 @@ process_multi_day (ECalConduitContext *ctxt, CalClientChange *ccc, GList **multi gboolean ret = TRUE; *multi_ccc = NULL; - *multi_uid = NULL; + *multi_comp = NULL; if (ccc->type == CAL_CLIENT_CHANGE_DELETED) return FALSE; @@ -617,13 +620,14 @@ process_multi_day (ECalConduitContext *ctxt, CalClientChange *ccc, GList **multi dt_end.value = &end_value; cal_component_set_dtend (clone, &dt_end); - cal_client_update_object (ctxt->client, clone); + /* FIXME Error handling */ + cal_client_create_object (ctxt->client, cal_component_get_icalcomponent (clone), NULL, NULL); c->comp = clone; c->type = CAL_CLIENT_CHANGE_ADDED; *multi_ccc = g_list_prepend (*multi_ccc, c); - *multi_uid = g_list_prepend (*multi_uid, new_uid); + *multi_comp = g_list_prepend (*multi_comp, g_object_ref (c->comp)); event_start = day_end; day_end = time_day_end_with_zone (event_start, ctxt->timezone); @@ -632,7 +636,8 @@ process_multi_day (ECalConduitContext *ctxt, CalClientChange *ccc, GList **multi dt_end.value = old_end_value; cal_component_get_uid (ccc->comp, &uid); - cal_client_remove_object (ctxt->client, uid); + /* FIXME Error handling */ + cal_client_remove_object (ctxt->client, uid, NULL); ccc->type = CAL_CLIENT_CHANGE_DELETED; cleanup: @@ -1007,13 +1012,11 @@ local_record_from_uid (ECalLocalRecord *local, { CalComponent *comp; icalcomponent *icalcomp; - CalClientGetStatus status; + GError *error = NULL; g_assert(local!=NULL); - status = cal_client_get_object (ctxt->client, uid, &icalcomp); - - if (status == CAL_CLIENT_GET_SUCCESS) { + if (cal_client_get_object (ctxt->client, uid, NULL, &icalcomp, &error)) { comp = cal_component_new (); if (!cal_component_set_icalcomponent (comp, icalcomp)) { g_object_unref (comp); @@ -1023,7 +1026,7 @@ local_record_from_uid (ECalLocalRecord *local, local_record_from_comp (local, comp, ctxt); g_object_unref (comp); - } else if (status == CAL_CLIENT_GET_NOT_FOUND) { + } else if (error->code == E_CALENDAR_STATUS_OBJECT_NOT_FOUND) { comp = cal_component_new (); cal_component_set_new_vtype (comp, CAL_COMPONENT_EVENT); cal_component_set_uid (comp, uid); @@ -1031,7 +1034,9 @@ local_record_from_uid (ECalLocalRecord *local, g_object_unref (comp); } else { INFO ("Object did not exist"); - } + } + + g_clear_error (&error); } static CalComponent * @@ -1283,21 +1288,6 @@ comp_from_remote_record (GnomePilotConduitSyncAbs *conduit, } static void -update_comp (GnomePilotConduitSyncAbs *conduit, CalComponent *comp, - ECalConduitContext *ctxt) -{ - CalClientResult success; - - g_return_if_fail (conduit != NULL); - g_return_if_fail (comp != NULL); - - success = cal_client_update_object (ctxt->client, comp); - - if (success != CAL_CLIENT_RESULT_SUCCESS) - WARN (_("Error while communicating with calendar server")); -} - -static void check_for_slow_setting (GnomePilotConduit *c, ECalConduitContext *ctxt) { GnomePilotConduitStandard *conduit = GNOME_PILOT_CONDUIT_STANDARD (c); @@ -1360,11 +1350,13 @@ pre_sync (GnomePilotConduit *conduit, LOG (g_message ( " Using timezone: %s", icaltimezone_get_tzid (ctxt->timezone) )); /* Set the default timezone on the backend. */ - if (ctxt->timezone) - cal_client_set_default_timezone (ctxt->client, ctxt->timezone); + if (ctxt->timezone) { + if (!cal_client_set_default_timezone (ctxt->client, ctxt->timezone, NULL)) + return -1; + } /* Get the default component */ - if (cal_client_get_default_object (ctxt->client, CALOBJ_TYPE_EVENT, &icalcomp) != CAL_CLIENT_GET_SUCCESS) + if (!cal_client_get_default_object (ctxt->client, CALOBJ_TYPE_EVENT, &icalcomp, NULL)) return -1; ctxt->default_comp = cal_component_new (); @@ -1380,21 +1372,23 @@ pre_sync (GnomePilotConduit *conduit, g_free (filename); /* Get the local database */ - ctxt->uids = cal_client_get_uids (ctxt->client, CALOBJ_TYPE_EVENT); + if (!cal_client_get_object_list_as_comp (ctxt->client, "(#t)", &ctxt->comps, NULL)) + return -1; /* Find the added, modified and deleted items */ change_id = g_strdup_printf ("pilot-sync-evolution-calendar-%d", ctxt->cfg->pilot_id); - ctxt->changed = cal_client_get_changes (ctxt->client, CALOBJ_TYPE_EVENT, change_id); + if (!cal_client_get_changes (ctxt->client, CALOBJ_TYPE_EVENT, change_id, &ctxt->changed, NULL)) + return -1; ctxt->changed_hash = g_hash_table_new (g_str_hash, g_str_equal); g_free (change_id); /* See if we need to split up any events */ for (l = ctxt->changed; l != NULL; l = l->next) { CalClientChange *ccc = l->data; - GList *multi_uid = NULL, *multi_ccc = NULL; + GList *multi_comp = NULL, *multi_ccc = NULL; - if (process_multi_day (ctxt, ccc, &multi_uid, &multi_ccc)) { - ctxt->uids = g_list_concat (ctxt->uids, multi_uid); + if (process_multi_day (ctxt, ccc, &multi_comp, &multi_ccc)) { + ctxt->comps = g_list_concat (ctxt->comps, multi_comp); added = g_list_concat (added, multi_ccc); removed = g_list_prepend (removed, ccc); @@ -1442,7 +1436,7 @@ pre_sync (GnomePilotConduit *conduit, } /* Set the count information */ - num_records = cal_client_get_n_objects (ctxt->client, CALOBJ_TYPE_EVENT); + num_records = g_list_length (ctxt->comps); gnome_pilot_conduit_sync_abs_set_num_local_records(abs_conduit, num_records); gnome_pilot_conduit_sync_abs_set_num_new_local_records (abs_conduit, add_records); gnome_pilot_conduit_sync_abs_set_num_updated_local_records (abs_conduit, mod_records); @@ -1492,8 +1486,8 @@ post_sync (GnomePilotConduit *conduit, * a race condition if anyone changes a record elsewhere during sycnc */ change_id = g_strdup_printf ("pilot-sync-evolution-calendar-%d", ctxt->cfg->pilot_id); - changed = cal_client_get_changes (ctxt->client, CALOBJ_TYPE_EVENT, change_id); - cal_client_change_list_free (changed); + if (cal_client_get_changes (ctxt->client, CALOBJ_TYPE_EVENT, change_id, &changed, NULL)) + cal_client_change_list_free (changed); g_free (change_id); LOG (g_message ( "---------------------------------------------------------\n" )); @@ -1537,7 +1531,7 @@ for_each (GnomePilotConduitSyncAbs *conduit, ECalLocalRecord **local, ECalConduitContext *ctxt) { - static GList *uids, *iterator; + static GList *comps, *iterator; static int count; g_return_val_if_fail (local != NULL, -1); @@ -1545,17 +1539,17 @@ for_each (GnomePilotConduitSyncAbs *conduit, if (*local == NULL) { LOG (g_message ( "beginning for_each" )); - uids = ctxt->uids; + comps = ctxt->comps; count = 0; - if (uids != NULL) { - LOG (g_message ( "iterating over %d records", g_list_length (uids) )); + if (comps != NULL) { + LOG (g_message ( "iterating over %d records", g_list_length (comps))); *local = g_new0 (ECalLocalRecord, 1); - local_record_from_uid (*local, uids->data, ctxt); + local_record_from_comp (*local, comps->data, ctxt); g_list_prepend (ctxt->locals, *local); - iterator = uids; + iterator = comps; } else { LOG (g_message ( "no events" )); (*local) = NULL; @@ -1681,8 +1675,10 @@ add_record (GnomePilotConduitSyncAbs *conduit, /* Give it a new UID otherwise it will be the uid of the default comp */ uid = cal_component_gen_uid (); cal_component_set_uid (comp, uid); + + if (!cal_client_create_object (ctxt->client, cal_component_get_icalcomponent (comp), NULL, NULL)) + return -1; - update_comp (conduit, comp, ctxt); e_pilot_map_insert (ctxt->map, remote->ID, uid, FALSE); g_free (uid); @@ -1709,7 +1705,10 @@ replace_record (GnomePilotConduitSyncAbs *conduit, new_comp = comp_from_remote_record (conduit, remote, local->comp, ctxt->client, ctxt->timezone); g_object_unref (local->comp); local->comp = new_comp; - update_comp (conduit, local->comp, ctxt); + + if (!cal_client_modify_object (ctxt->client, cal_component_get_icalcomponent (new_comp), + CALOBJ_MOD_ALL, NULL)) + return -1; return retval; } @@ -1729,7 +1728,8 @@ delete_record (GnomePilotConduitSyncAbs *conduit, LOG (g_message ( "delete_record: deleting %s\n", uid )); e_pilot_map_remove_by_uid (ctxt->map, uid); - cal_client_remove_object (ctxt->client, uid); + /* FIXME Error handling */ + cal_client_remove_object (ctxt->client, uid, NULL); return 0; } |