static void import_items(ICalImporterData *icidata) { ESource *source; g_return_if_fail (icidata != NULL); source = e_source_selector_peek_primary_selection ((ESourceSelector *)icidata->selector); g_return_if_fail ( source != NULL); icidata->client = auth_new_cal_from_source (source, icidata->source_type); e_cal_open (icidata->client, FALSE, NULL); switch (icidata->source_type) { case E_CAL_SOURCE_TYPE_EVENT: prepare_events (icidata->icalcomp, NULL); if (!update_objects (icidata->client, icidata->icalcomp)) /* FIXME: e_error ... */; break; case E_CAL_SOURCE_TYPE_TODO: prepare_tasks (icidata->icalcomp, NULL); if (!update_objects (icidata->client, icidata->icalcomp)) /* FIXME: e_error ... */; break; default: g_assert_not_reached (); } ical_import_done (icidata); }
static gchar * test_e_cal_new (ECal **cal, const gchar *uri) { GError *error = NULL; gchar *cal_uri, *cal_file; gboolean created = 0; cal_uri = g_strconcat ("file://", uri, NULL); *cal = e_cal_new_from_uri (cal_uri, E_CAL_SOURCE_TYPE_EVENT); if (!*cal) { g_message (G_STRLOC ": could not create the client"); g_free (cal_uri); return "Test Creation of new calendar : Failed"; } g_object_weak_ref (G_OBJECT (*cal), client_destroy_cb, NULL); cl_printf (*cal, "Calendar loading `%s'...\n", uri); if (!e_cal_open (*cal, FALSE, &error)) { cl_printf (*cal, "Load/create %s\n", error->message); g_free (cal_uri); return "Test creation of new calendar : Failed"; } cal_file = g_strconcat (uri, "/calendar.ics", NULL); created = g_file_test (cal_file, G_FILE_TEST_EXISTS); g_free (cal_uri); g_free (cal_file); mu_assert ("Test creation of new calendar : Failed", created); return NULL; }
ECal * evo_cal_source_open_new_with_absolute_uri(const char *name, const char *uri, ECalSourceType type) { ESource *source = NULL; ECal *cal = NULL; GError *gerror = NULL; g_debug("Opening new calendar source uri: %s\n", uri); source = e_source_new_with_absolute_uri(name, uri); if (!source) { g_warning("Unable to open source for calendar (type %u)", type); return NULL; } cal = e_cal_new(source, type); if(!cal) { g_warning("Failed to create new calendar (type %u)", type); return NULL; } if(!e_cal_open(cal, FALSE, &gerror)) { g_warning("Failed to open calendar (type %u): %s", type, gerror && gerror->message ? gerror->message : "None"); g_object_unref(cal); g_clear_error(&gerror); return NULL; } return cal; }
static int start_calendar_server (EMemoConduitContext *ctxt) { g_return_val_if_fail (ctxt != NULL, -2); if (ctxt->cfg->source) { ctxt->client = e_cal_new (ctxt->cfg->source, E_CAL_SOURCE_TYPE_JOURNAL); if (!e_cal_open (ctxt->client, TRUE, NULL)) return -1; } else if (!e_cal_open_default (&ctxt->client, E_CAL_SOURCE_TYPE_JOURNAL, NULL, NULL, NULL)) { return -1; } return 0; }
ECal * evo_cal_source_open_source(const char *uri, ECalSourceType type) { ESourceList *sources = NULL; ESource *source = NULL; ECal *cal = NULL; GError *gerror = NULL; g_debug("Opening calendar source uri: %s\n", uri); if (strcmp(uri, "default")) { if (!e_cal_get_sources(&sources, type, &gerror)) { g_warning("Unable to get sources for calendar (type %u): %s", type, gerror && gerror->message ? gerror->message : "None"); g_clear_error(&gerror); return NULL; } source = evo_environment_find_source(sources, uri); if (!source) { g_warning("Unable to find source for calendar (type %u)", type); return NULL; } cal = e_cal_new(source, type); if(!cal) { g_warning("Failed to create new calendar (type %u)", type); return NULL; } if(!e_cal_open(cal, FALSE, &gerror)) { g_warning("Failed to open calendar (type %u): %s", type, gerror && gerror->message? gerror->message : "None"); g_object_unref(cal); g_clear_error(&gerror); return NULL; } } else { if (!e_cal_open_default (&cal, type, NULL, NULL, &gerror)) { g_warning("Failed to open default calendar: %s", gerror && gerror->message ? gerror->message : "None"); g_clear_error(&gerror); return NULL; } } return cal; }
gint main (gint argc, gchar **argv) { ECal *ecal; GList *l, *objects; g_type_init (); if (argc < 3) { printf ("usage: test-search <uid> <query>\n"); exit (0); } /* FIXME We don't build ECals from URIs anymore. */ /* ecal = e_cal_new_from_uri (argv[1], E_CAL_SOURCE_TYPE_EVENT); */ ecal = NULL; if (!e_cal_open (ecal, TRUE, NULL)) { printf ("failed to open calendar\n"); exit (0); } if (!e_cal_get_object_list_as_comp (ecal, argv[2], &objects, NULL)) { printf ("failed to get objects\n"); exit (0); } printf ("Received %d objects\n", g_list_length (objects)); for (l = objects; l; l = l->next) { ECalComponent *comp = E_CAL_COMPONENT (l->data); gchar *str; str = e_cal_component_get_as_string (comp); printf ("%s\n", str); g_free (str); g_object_unref (comp); } g_list_free (objects); g_object_unref (ecal); return 0; }
void open_calendar(const char *uri, ECalSourceType source_type) { ECal *cal = NULL; GError *gerror = NULL; cal = e_cal_new_from_uri(uri, source_type); if (!cal) { printf("Failed to allocate calendar\n"); return; } if (!e_cal_open(cal, TRUE, &gerror)) { printf("Failed to open calendar:\n%s\n", gerror->message); g_clear_error(&gerror); return; } printf("Successfully opened %s\n", uri); g_object_unref(cal); }
static gboolean write_calendar (gchar *uid, ESourceList *source_list, GOutputStream *stream) { ESource *source; ECal *client = NULL; GError *error = NULL; GList *objects; icaltimezone *utc; time_t start = time(NULL), end; icalcomponent *top_level; char *email = NULL; GList *users = NULL; gboolean res = FALSE; utc = icaltimezone_get_utc_timezone (); start = time_day_begin_with_zone (start, utc); end = time_add_week_with_zone (start, 6, utc); source = e_source_list_peek_source_by_uid (source_list, uid); if (source) client = auth_new_cal_from_source (source, E_CAL_SOURCE_TYPE_EVENT); if (!client) { g_warning (G_STRLOC ": Could not publish calendar: Calendar backend no longer exists"); return FALSE; } if (!e_cal_open (client, TRUE, &error)) { if (error) { g_warning ("%s", error->message); g_error_free (error); } g_object_unref (client); return FALSE; } if (e_cal_get_cal_address (client, &email, &error)) { if (email && *email) users = g_list_append (users, email); } top_level = e_cal_util_new_top_level (); error = NULL; if (e_cal_get_free_busy (client, users, start, end, &objects, &error)) { char *ical_string; while (objects) { ECalComponent *comp = objects->data; icalcomponent *icalcomp = e_cal_component_get_icalcomponent (comp); icalcomponent_add_component (top_level, icalcomp); objects = g_list_remove (objects, comp); } ical_string = icalcomponent_as_ical_string (top_level); res = g_output_stream_write_all (stream, ical_string, strlen (ical_string), NULL, NULL, &error); g_free (ical_string); } if (users) g_list_free (users); g_free (email); g_object_unref (client); if (error) { g_warning ("%s", error->message); g_error_free (error); } return res; }
/* The following function taken from gnome clock-applet * (gnome-panel/applets/clock/calendar-sources.c) */ ECal * dates_load_esource (ESource *esource, ECalSourceType source_type, GSList *existing_clients, DatesData *d) { ECal *retval; GError *error; if (existing_clients) { GSList *l; for (l = existing_clients; l; l = l->next) { ECal *client = E_CAL (l->data); if (e_source_equal (esource, e_cal_get_source (client))) { #ifdef DEBUG if (d->debug & DATES_DEBUG_CALENDAR) g_debug ("load_esource: found existing source, returning that"); #endif return g_object_ref (client); } } } retval = e_cal_new (esource, source_type); if (!retval) { g_warning ("Could not load source '%s' from '%s'\n", e_source_peek_name (esource), e_source_get_uri (esource)); return NULL; } error = NULL; if (!e_cal_open (retval, FALSE, &error)) { g_assert (error != NULL); g_warning ("Cannot open calendar from uri '%s': %s\n", e_cal_get_uri (retval), error->message); g_error_free (error); g_object_unref (retval); return NULL; } #ifdef DEBUG if (d->debug & DATES_DEBUG_CALENDAR) g_debug ("Loaded calendar from uri '%s'", e_cal_get_uri (retval)); #endif /* * Set the calendar mode to CAL_MODE_REMOTE. This is necessary to get the * remote (webcal) calendars to work. It doesn't seem to have any effect * on the file backend. */ e_cal_set_mode (retval, CAL_MODE_REMOTE); return retval; }
/* Creates a calendar client and tries to load the specified URI into it */ static void create_client (ECal **client, const gchar *uri, ECalSourceType type, gboolean only_if_exists) { const gchar *results; ECalView *query; gchar *cal_uri; GError *error = NULL; cal_uri = g_strconcat ("file://", uri, NULL); /* FIXME We don't build ECals from URIs anymore. */ /* *client = e_cal_new_from_uri (cal_uri, type); */ *client = NULL; if (!*client) { g_message (G_STRLOC ": could not create the client"); exit (1); } g_object_weak_ref (G_OBJECT (*client), client_destroy_cb, NULL); cl_printf (*client, "Calendar loading `%s'...\n", uri); if (!e_cal_open (*client, only_if_exists, &error)) { cl_printf (*client, "Load/create %s\n", error->message); exit (1); } g_clear_error (&error); if (!e_cal_get_query (*client, "(contains? \"any\" \"Event\")", &query, NULL)) { cl_printf (*client, G_STRLOC ": Unable to obtain query"); exit (1); } g_signal_connect ( G_OBJECT (query), "objects_added", G_CALLBACK (objects_added_cb), client); g_signal_connect ( G_OBJECT (query), "objects_modified", G_CALLBACK (objects_modified_cb), client); g_signal_connect ( G_OBJECT (query), "objects_removed", G_CALLBACK (objects_removed_cb), client); g_signal_connect ( G_OBJECT (query), "view_complete", G_CALLBACK (view_complete_cb), client); e_cal_view_start (query); results = all_tests (*client, uri); cl_printf (*client, "\n\n\n*************Tests run: %d****************\n\n", tests_run); cl_printf (*client, "*************Tests passed: %d*************\n\n\n", tests_passed); if (results != NULL) cl_printf (*client, "***Failures********%s\n", results); cl_printf (*client, "dump of the test calendar data"); list_uids (*client); g_free (cal_uri); }