From 21743ac2cfa2d2ddcd539e9b7695cc8dd720ef36 Mon Sep 17 00:00:00 2001 From: Ettore Perazzoli Date: Tue, 21 Oct 2003 18:51:30 +0000 Subject: Merge new-ui-branch into the trunk. svn path=/trunk/; revision=22966 --- calendar/importers/icalendar-importer.c | 102 ++++++++++++++++++++++++++------ 1 file changed, 84 insertions(+), 18 deletions(-) (limited to 'calendar/importers') diff --git a/calendar/importers/icalendar-importer.c b/calendar/importers/icalendar-importer.c index 28068c11df..f2dcbd7097 100644 --- a/calendar/importers/icalendar-importer.c +++ b/calendar/importers/icalendar-importer.c @@ -179,6 +179,60 @@ prepare_tasks (icalcomponent *icalcomp, GList *vtodos) g_list_free (vtodos); } +static CalClientResult +update_single_object (CalClient *client, icalcomponent *icalcomp) +{ + char *uid; + icalcomponent *tmp_icalcomp; + + uid = (char *) icalcomponent_get_uid (icalcomp); + + if (cal_client_get_object (client, uid, NULL, &tmp_icalcomp, NULL)) + return cal_client_modify_object (client, icalcomp, CALOBJ_MOD_ALL, NULL) + ? CAL_CLIENT_RESULT_SUCCESS : CAL_CLIENT_RESULT_CORBA_ERROR; + + return cal_client_create_object (client, icalcomp, &uid, NULL) + ? CAL_CLIENT_RESULT_SUCCESS : CAL_CLIENT_RESULT_CORBA_ERROR; +} + +static CalClientResult +update_objects (CalClient *client, icalcomponent *icalcomp) +{ + icalcomponent *subcomp; + icalcomponent_kind kind; + CalClientResult result; + + kind = icalcomponent_isa (icalcomp); + if (kind == ICAL_VTODO_COMPONENT || kind == ICAL_VEVENT_COMPONENT) + return update_single_object (client, icalcomp); + else if (kind != ICAL_VCALENDAR_COMPONENT) + return CAL_CLIENT_RESULT_INVALID_OBJECT; + + subcomp = icalcomponent_get_first_component (icalcomp, ICAL_ANY_COMPONENT); + while (subcomp) { + kind = icalcomponent_isa (subcomp); + if (kind == ICAL_VTIMEZONE_COMPONENT) { + icaltimezone *zone; + + zone = icaltimezone_new (); + icaltimezone_set_component (zone, subcomp); + + result = cal_client_add_timezone (client, zone, NULL); + icaltimezone_free (zone, 1); + if (result != CAL_CLIENT_RESULT_SUCCESS) + return result; + } else if (kind == ICAL_VTODO_COMPONENT || + kind == ICAL_VEVENT_COMPONENT) { + result = update_single_object (client, subcomp); + if (result != CAL_CLIENT_RESULT_SUCCESS) + return result; + } + + subcomp = icalcomponent_get_next_component (icalcomp, ICAL_ANY_COMPONENT); + } + + return CAL_CLIENT_RESULT_SUCCESS; +} static void process_item_fn (EvolutionImporter *importer, @@ -220,20 +274,20 @@ process_item_fn (EvolutionImporter *importer, contains just tasks, we strip out the VEVENTs, which do not get imported at all. */ if (ici->folder_contains_events && ici->folder_contains_tasks) { - if (cal_client_update_objects (ici->client, ici->icalcomp) != CAL_CLIENT_RESULT_SUCCESS) + if (update_objects (ici->client, ici->icalcomp) != CAL_CLIENT_RESULT_SUCCESS) result = GNOME_Evolution_ImporterListener_BAD_DATA; } else if (ici->folder_contains_events) { GList *vtodos = prepare_events (ici->icalcomp); - if (cal_client_update_objects (ici->client, ici->icalcomp) != CAL_CLIENT_RESULT_SUCCESS) + if (update_objects (ici->client, ici->icalcomp) != CAL_CLIENT_RESULT_SUCCESS) result = GNOME_Evolution_ImporterListener_BAD_DATA; prepare_tasks (ici->icalcomp, vtodos); - if (cal_client_update_objects (ici->tasks_client, + if (update_objects (ici->tasks_client, ici->icalcomp) != CAL_CLIENT_RESULT_SUCCESS) result = GNOME_Evolution_ImporterListener_BAD_DATA; } else { prepare_tasks (ici->icalcomp, NULL); - if (cal_client_update_objects (ici->client, ici->icalcomp) != CAL_CLIENT_RESULT_SUCCESS) + if (update_objects (ici->client, ici->icalcomp) != CAL_CLIENT_RESULT_SUCCESS) result = GNOME_Evolution_ImporterListener_BAD_DATA; } @@ -312,8 +366,14 @@ load_file_fn (EvolutionImporter *importer, } else real_uri = g_strdup (physical_uri); - if (cal_client_open_calendar (ici->client, real_uri, TRUE) - && cal_client_open_default_tasks (ici->tasks_client, FALSE)) { + /* create CalClient's */ + if (!ici->client) + ici->client = cal_client_new (real_uri, CALOBJ_TYPE_EVENT); + if (!ici->tasks_client) + ici->tasks_client = cal_client_new ("", CALOBJ_TYPE_TODO); /* FIXME */ + + if (cal_client_open (ici->client, TRUE, NULL) + && cal_client_open (ici->tasks_client, FALSE, NULL)) { ici->icalcomp = icalcomp; ret = TRUE; } @@ -334,8 +394,8 @@ ical_importer_new (void) ICalImporter *ici; ici = g_new0 (ICalImporter, 1); - ici->client = cal_client_new (); - ici->tasks_client = cal_client_new (); + ici->client = NULL; + ici->tasks_client = NULL; ici->icalcomp = NULL; ici->importer = evolution_importer_new (support_format_fn, load_file_fn, @@ -458,8 +518,14 @@ vcal_load_file_fn (EvolutionImporter *importer, } else real_uri = g_strdup (physical_uri); - if (cal_client_open_calendar (ici->client, real_uri, TRUE) - && cal_client_open_default_tasks (ici->tasks_client, FALSE)) { + /* create CalClient's */ + if (!ici->client) + ici->client = cal_client_new (real_uri, CALOBJ_TYPE_EVENT); + if (!ici->tasks_client) + ici->tasks_client = cal_client_new ("", CALOBJ_TYPE_TODO); + + if (cal_client_open (ici->client, TRUE, NULL) + && cal_client_open (ici->tasks_client, FALSE, NULL)) { ici->icalcomp = icalcomp; ret = TRUE; } @@ -478,8 +544,8 @@ vcal_importer_new (void) ICalImporter *ici; ici = g_new0 (ICalImporter, 1); - ici->client = cal_client_new (); - ici->tasks_client = cal_client_new (); + ici->client = NULL; + ici->tasks_client = NULL; ici->icalcomp = NULL; ici->importer = evolution_importer_new (vcal_support_format_fn, vcal_load_file_fn, @@ -542,14 +608,14 @@ gnome_calendar_import_data_fn (EvolutionIntelligentImporter *ii, /* Try to open the default calendar & tasks folders. */ if (ici->do_calendar) { - calendar_client = cal_client_new (); - if (!cal_client_open_default_calendar (calendar_client, FALSE)) + calendar_client = cal_client_new ("", CALOBJ_TYPE_EVENT); /* FIXME: use default folder */ + if (!cal_client_open (calendar_client, FALSE, NULL)) goto out; } if (ici->do_tasks) { - tasks_client = cal_client_new (); - if (!cal_client_open_default_tasks (tasks_client, FALSE)) + tasks_client = cal_client_new ("", CALOBJ_TYPE_TODO); /* FIXME: use default folder */ + if (!cal_client_open (tasks_client, FALSE, NULL)) goto out; } @@ -598,7 +664,7 @@ gnome_calendar_import_data_fn (EvolutionIntelligentImporter *ii, /* Import the calendar events. */ /* FIXME: What do intelligent importers do about errors? */ if (ici->do_calendar) - cal_client_update_objects (calendar_client, icalcomp); + update_objects (calendar_client, icalcomp); /* @@ -606,7 +672,7 @@ gnome_calendar_import_data_fn (EvolutionIntelligentImporter *ii, */ prepare_tasks (icalcomp, vtodos); if (ici->do_tasks) - cal_client_update_objects (tasks_client, icalcomp); + update_objects (tasks_client, icalcomp); out: if (icalcomp) -- cgit v1.2.3