calendar-server: update to ECalClient

ECal is deprecated and replaced by ECalClient. This has the
advantage of using e_utils to handle authentication, and should
fix NotOpened errors (that affect in particular webcal calendars
prior to evolution running)

https://bugzilla.gnome.org/show_bug.cgi?id=671177
This commit is contained in:
Giovanni Campagna 2012-03-02 01:22:46 +01:00
parent f1f2bc28a2
commit d68ff69c7a
2 changed files with 73 additions and 91 deletions

View File

@ -31,9 +31,9 @@
#include <string.h> #include <string.h>
#include <gconf/gconf-client.h> #include <gconf/gconf-client.h>
#define HANDLE_LIBICAL_MEMORY #define HANDLE_LIBICAL_MEMORY
#include <libecal/e-cal.h> #include <libecal/e-cal-client.h>
#include <libedataserver/e-source-list.h> #include <libedataserver/e-source-list.h>
#include <libedataserverui/e-passwords.h> #include <libedataserverui/e-client-utils.h>
#undef CALENDAR_ENABLE_DEBUG #undef CALENDAR_ENABLE_DEBUG
#include "calendar-debug.h" #include "calendar-debug.h"
@ -60,7 +60,7 @@ typedef struct _CalendarSourceData CalendarSourceData;
struct _CalendarSourceData struct _CalendarSourceData
{ {
ECalSourceType source_type; ECalClientSourceType source_type;
CalendarSources *sources; CalendarSources *sources;
guint changed_signal; guint changed_signal;
@ -88,7 +88,7 @@ static void calendar_sources_class_init (CalendarSourcesClass *klass);
static void calendar_sources_init (CalendarSources *sources); static void calendar_sources_init (CalendarSources *sources);
static void calendar_sources_finalize (GObject *object); static void calendar_sources_finalize (GObject *object);
static void backend_died_cb (ECal *client, CalendarSourceData *source_data); static void backend_died_cb (EClient *client, CalendarSourceData *source_data);
static void calendar_sources_esource_list_changed (ESourceList *source_list, static void calendar_sources_esource_list_changed (ESourceList *source_list,
CalendarSourceData *source_data); CalendarSourceData *source_data);
@ -172,12 +172,12 @@ calendar_sources_init (CalendarSources *sources)
{ {
sources->priv = CALENDAR_SOURCES_GET_PRIVATE (sources); sources->priv = CALENDAR_SOURCES_GET_PRIVATE (sources);
sources->priv->appointment_sources.source_type = E_CAL_SOURCE_TYPE_EVENT; sources->priv->appointment_sources.source_type = E_CAL_CLIENT_SOURCE_TYPE_EVENTS;
sources->priv->appointment_sources.sources = sources; sources->priv->appointment_sources.sources = sources;
sources->priv->appointment_sources.changed_signal = signals [APPOINTMENT_SOURCES_CHANGED]; sources->priv->appointment_sources.changed_signal = signals [APPOINTMENT_SOURCES_CHANGED];
sources->priv->appointment_sources.timeout_id = 0; sources->priv->appointment_sources.timeout_id = 0;
sources->priv->task_sources.source_type = E_CAL_SOURCE_TYPE_TODO; sources->priv->task_sources.source_type = E_CAL_CLIENT_SOURCE_TYPE_TASKS;
sources->priv->task_sources.sources = sources; sources->priv->task_sources.sources = sources;
sources->priv->task_sources.changed_signal = signals [TASK_SOURCES_CHANGED]; sources->priv->task_sources.changed_signal = signals [TASK_SOURCES_CHANGED];
sources->priv->task_sources.timeout_id = 0; sources->priv->task_sources.timeout_id = 0;
@ -295,30 +295,14 @@ is_source_selected (ESource *esource,
return FALSE; return FALSE;
} }
static char *
auth_func_cb (ECal *ecal,
const char *prompt,
const char *key,
gpointer user_data)
{
ESource *source;
const gchar *auth_domain;
const gchar *component_name;
source = e_cal_get_source (ecal);
auth_domain = e_source_get_property (source, "auth-domain");
component_name = auth_domain ? auth_domain : "Calendar";
return e_passwords_get_password (component_name, key);
}
/* The clients are just created here but not loaded */ /* The clients are just created here but not loaded */
static ECal * static ECalClient *
get_ecal_from_source (ESource *esource, get_ecal_from_source (ESource *esource,
ECalSourceType source_type, ECalClientSourceType source_type,
GSList *existing_clients) GSList *existing_clients)
{ {
ECal *retval; ECalClient *retval;
GError *error = NULL;
if (existing_clients) if (existing_clients)
{ {
@ -326,9 +310,9 @@ get_ecal_from_source (ESource *esource,
for (l = existing_clients; l; l = l->next) for (l = existing_clients; l; l = l->next)
{ {
ECal *client = E_CAL (l->data); EClient *client = E_CLIENT (l->data);
if (e_source_equal (esource, e_cal_get_source (client))) if (e_source_equal (esource, e_client_get_source (client)))
{ {
dprintf (" load_esource: found existing source ... returning that\n"); dprintf (" load_esource: found existing source ... returning that\n");
@ -337,16 +321,19 @@ get_ecal_from_source (ESource *esource,
} }
} }
retval = e_cal_new (esource, source_type); retval = e_cal_client_new (esource, source_type, &error);
if (!retval) if (!retval)
{ {
g_warning ("Could not load source '%s' from '%s'\n", g_warning ("Could not load source '%s' from '%s': %s",
e_source_peek_name (esource), e_source_peek_name (esource),
e_source_peek_relative_uri (esource)); e_source_peek_relative_uri (esource),
error->message);
g_clear_error(&error);
return NULL; return NULL;
} }
e_cal_set_auth_func (retval, auth_func_cb, NULL); g_signal_connect (retval, "authenticate",
G_CALLBACK (e_client_utils_authenticate_handler), NULL);
return retval; return retval;
} }
@ -399,13 +386,13 @@ debug_dump_ecal_list (GSList *ecal_list)
dprintf ("Loaded clients:\n"); dprintf ("Loaded clients:\n");
for (l = ecal_list; l; l = l->next) for (l = ecal_list; l; l = l->next)
{ {
ECal *client = l->data; EClient *client = l->data;
ESource *source = e_cal_get_source (client); ESource *source = e_client_get_source (client);
dprintf (" %s %s %s\n", dprintf (" %s %s %s\n",
e_source_peek_uid (source), e_source_peek_uid (source),
e_source_peek_name (source), e_source_peek_name (source),
e_cal_get_uri (client)); e_client_get_uri (client));
} }
#endif #endif
} }
@ -426,7 +413,7 @@ backend_restart (gpointer data)
} }
static void static void
backend_died_cb (ECal *client, CalendarSourceData *source_data) backend_died_cb (EClient *client, CalendarSourceData *source_data)
{ {
const char *uristr; const char *uristr;
@ -436,7 +423,7 @@ backend_died_cb (ECal *client, CalendarSourceData *source_data)
g_slist_free (source_data->clients); g_slist_free (source_data->clients);
source_data->clients = NULL; source_data->clients = NULL;
} }
uristr = e_cal_get_uri (client); uristr = e_client_get_uri (client);
g_warning ("The calendar backend for %s has crashed.", uristr); g_warning ("The calendar backend for %s has crashed.", uristr);
if (source_data->timeout_id != 0) if (source_data->timeout_id != 0)
@ -472,8 +459,8 @@ calendar_sources_load_esource_list (CalendarSourceData *source_data)
esources = e_source_group_peek_sources (l->data); esources = e_source_group_peek_sources (l->data);
for (s = esources; s; s = s->next) for (s = esources; s; s = s->next)
{ {
ESource *esource = E_SOURCE (s->data); ESource *esource = E_SOURCE (s->data);
ECal *client; ECalClient *client;
dprintf (" type = '%s' uid = '%s', name = '%s', relative uri = '%s': \n", dprintf (" type = '%s' uid = '%s', name = '%s', relative uri = '%s': \n",
source_data->source_type == E_CAL_SOURCE_TYPE_EVENT ? "appointment" : "task", source_data->source_type == E_CAL_SOURCE_TYPE_EVENT ? "appointment" : "task",
@ -510,7 +497,7 @@ calendar_sources_load_esource_list (CalendarSourceData *source_data)
* were already there before) */ * were already there before) */
for (l = source_data->clients; l; l = l->next) for (l = source_data->clients; l; l = l->next)
{ {
g_signal_connect (G_OBJECT (l->data), "backend_died", g_signal_connect (G_OBJECT (l->data), "backend-died",
G_CALLBACK (backend_died_cb), source_data); G_CALLBACK (backend_died_cb), source_data);
} }

View File

@ -36,7 +36,7 @@
#include <gio/gio.h> #include <gio/gio.h>
#define HANDLE_LIBICAL_MEMORY #define HANDLE_LIBICAL_MEMORY
#include <libecal/e-cal.h> #include <libecal/e-cal-client.h>
#include <libecal/e-cal-time-util.h> #include <libecal/e-cal-time-util.h>
#include <libecal/e-cal-recur.h> #include <libecal/e-cal-recur.h>
#include <libecal/e-cal-system-timezone.h> #include <libecal/e-cal-system-timezone.h>
@ -250,27 +250,27 @@ get_ical_completed_time (icalcomponent *ical,
} }
static char * static char *
get_source_color (ECal *esource) get_source_color (ECalClient *esource)
{ {
ESource *source; ESource *source;
g_return_val_if_fail (E_IS_CAL (esource), NULL); g_return_val_if_fail (E_IS_CAL_CLIENT (esource), NULL);
source = e_cal_get_source (esource); source = e_client_get_source (E_CLIENT (esource));
return g_strdup (e_source_peek_color_spec (source)); return g_strdup (e_source_peek_color_spec (source));
} }
static gchar * static gchar *
get_source_uri (ECal *esource) get_source_uri (ECalClient *esource)
{ {
ESource *source; ESource *source;
gchar *string; gchar *string;
gchar **list; gchar **list;
g_return_val_if_fail (E_IS_CAL (esource), NULL); g_return_val_if_fail (E_IS_CAL_CLIENT (esource), NULL);
source = e_cal_get_source (esource); source = e_client_get_source (E_CLIENT (esource));
string = g_strdup (e_source_get_uri (source)); string = g_strdup (e_source_get_uri (source));
if (string) { if (string) {
list = g_strsplit (string, ":", 2); list = g_strsplit (string, ":", 2);
@ -358,7 +358,7 @@ calendar_appointment_free (CalendarAppointment *appointment)
static void static void
calendar_appointment_init (CalendarAppointment *appointment, calendar_appointment_init (CalendarAppointment *appointment,
icalcomponent *ical, icalcomponent *ical,
ECal *cal, ECalClient *cal,
icaltimezone *default_zone) icaltimezone *default_zone)
{ {
appointment->uid = get_ical_uid (ical); appointment->uid = get_ical_uid (ical);
@ -376,14 +376,14 @@ calendar_appointment_init (CalendarAppointment *appointment,
static icaltimezone * static icaltimezone *
resolve_timezone_id (const char *tzid, resolve_timezone_id (const char *tzid,
ECal *source) ECalClient *source)
{ {
icaltimezone *retval; icaltimezone *retval;
retval = icaltimezone_get_builtin_timezone_from_tzid (tzid); retval = icaltimezone_get_builtin_timezone_from_tzid (tzid);
if (!retval) if (!retval)
{ {
e_cal_get_timezone (source, tzid, &retval, NULL); e_cal_client_get_timezone_sync (source, tzid, &retval, NULL, NULL);
} }
return retval; return retval;
@ -410,7 +410,7 @@ calendar_appointment_collect_occurrence (ECalComponent *component,
static void static void
calendar_appointment_generate_occurrences (CalendarAppointment *appointment, calendar_appointment_generate_occurrences (CalendarAppointment *appointment,
icalcomponent *ical, icalcomponent *ical,
ECal *cal, ECalClient *cal,
time_t start, time_t start,
time_t end, time_t end,
icaltimezone *default_zone) icaltimezone *default_zone)
@ -439,7 +439,7 @@ calendar_appointment_generate_occurrences (CalendarAppointment *appointment,
static CalendarAppointment * static CalendarAppointment *
calendar_appointment_new (icalcomponent *ical, calendar_appointment_new (icalcomponent *ical,
ECal *cal, ECalClient *cal,
icaltimezone *default_zone) icaltimezone *default_zone)
{ {
CalendarAppointment *appointment; CalendarAppointment *appointment;
@ -535,12 +535,12 @@ invalidate_cache (App *app)
} }
static void static void
on_objects_added (ECalView *view, on_objects_added (ECalClientView *view,
GList *objects, GSList *objects,
gpointer user_data) gpointer user_data)
{ {
App *app = user_data; App *app = user_data;
GList *l; GSList *l;
print_debug ("%s for calendar", G_STRFUNC); print_debug ("%s for calendar", G_STRFUNC);
@ -561,9 +561,9 @@ on_objects_added (ECalView *view,
} }
static void static void
on_objects_modified (ECalView *view, on_objects_modified (ECalClientView *view,
GList *objects, GSList *objects,
gpointer user_data) gpointer user_data)
{ {
App *app = user_data; App *app = user_data;
print_debug ("%s for calendar", G_STRFUNC); print_debug ("%s for calendar", G_STRFUNC);
@ -572,9 +572,9 @@ on_objects_modified (ECalView *view,
} }
static void static void
on_objects_removed (ECalView *view, on_objects_removed (ECalClientView *view,
GList *uids, GSList *uids,
gpointer user_data) gpointer user_data)
{ {
App *app = user_data; App *app = user_data;
print_debug ("%s for calendar", G_STRFUNC); print_debug ("%s for calendar", G_STRFUNC);
@ -596,11 +596,11 @@ app_load_events (App *app)
/* nuke existing views */ /* nuke existing views */
for (ll = app->live_views; ll != NULL; ll = ll->next) for (ll = app->live_views; ll != NULL; ll = ll->next)
{ {
ECalView *view = E_CAL_VIEW (ll->data); ECalClientView *view = E_CAL_CLIENT_VIEW (ll->data);
g_signal_handlers_disconnect_by_func (view, on_objects_added, app); g_signal_handlers_disconnect_by_func (view, on_objects_added, app);
g_signal_handlers_disconnect_by_func (view, on_objects_modified, app); g_signal_handlers_disconnect_by_func (view, on_objects_modified, app);
g_signal_handlers_disconnect_by_func (view, on_objects_removed, app); g_signal_handlers_disconnect_by_func (view, on_objects_removed, app);
e_cal_view_stop (view); e_cal_client_view_stop (view, NULL);
g_object_unref (view); g_object_unref (view);
} }
g_list_free (app->live_views); g_list_free (app->live_views);
@ -619,23 +619,16 @@ app_load_events (App *app)
sources = calendar_sources_get_appointment_sources (app->sources); sources = calendar_sources_get_appointment_sources (app->sources);
for (l = sources; l != NULL; l = l->next) for (l = sources; l != NULL; l = l->next)
{ {
ECal *cal = E_CAL (l->data); ECalClient *cal = E_CAL_CLIENT (l->data);
GError *error; GError *error;
gchar *query; gchar *query;
GList *objects; GSList *objects, *j;
GList *j; ECalClientView *view;
ECalView *view;
e_cal_client_set_default_timezone (cal, app->zone);
error = NULL; error = NULL;
if (!e_cal_set_default_timezone (cal, app->zone, &error)) if (!e_client_open_sync (E_CLIENT (cal), TRUE, NULL, &error))
{
g_printerr ("Error setting timezone on calendar: %s\n", error->message);
g_error_free (error);
continue;
}
error = NULL;
if (!e_cal_open (cal, TRUE, &error))
{ {
g_printerr ("Error opening calendar: %s\n", error->message); g_printerr ("Error opening calendar: %s\n", error->message);
g_error_free (error); g_error_free (error);
@ -648,10 +641,11 @@ app_load_events (App *app)
until_iso8601); until_iso8601);
error = NULL; error = NULL;
objects = NULL; objects = NULL;
if (!e_cal_get_object_list (cal, if (!e_cal_client_get_object_list_sync (cal,
query, query,
&objects, &objects,
&error)) NULL, /* cancellable */
&error))
{ {
g_printerr ("Error querying calendar: %s\n", error->message); g_printerr ("Error querying calendar: %s\n", error->message);
g_error_free (error); g_error_free (error);
@ -677,13 +671,14 @@ app_load_events (App *app)
g_hash_table_insert (app->appointments, g_strdup (appointment->uid), appointment); g_hash_table_insert (app->appointments, g_strdup (appointment->uid), appointment);
} }
e_cal_free_object_list (objects); e_cal_client_free_icalcomp_slist (objects);
error = NULL; error = NULL;
if (!e_cal_get_query (cal, if (!e_cal_client_get_view_sync (cal,
query, query,
&view, &view,
&error)) NULL, /* cancellable */
&error))
{ {
g_printerr ("Error setting up live-query on calendar: %s\n", error->message); g_printerr ("Error setting up live-query on calendar: %s\n", error->message);
g_error_free (error); g_error_free (error);
@ -702,7 +697,7 @@ app_load_events (App *app)
"objects-removed", "objects-removed",
G_CALLBACK (on_objects_removed), G_CALLBACK (on_objects_removed),
app); app);
e_cal_view_start (view); e_cal_client_view_start (view, NULL);
app->live_views = g_list_prepend (app->live_views, view); app->live_views = g_list_prepend (app->live_views, view);
} }
@ -752,11 +747,11 @@ app_free (App *app)
GList *ll; GList *ll;
for (ll = app->live_views; ll != NULL; ll = ll->next) for (ll = app->live_views; ll != NULL; ll = ll->next)
{ {
ECalView *view = E_CAL_VIEW (ll->data); ECalClientView *view = E_CAL_CLIENT_VIEW (ll->data);
g_signal_handlers_disconnect_by_func (view, on_objects_added, app); g_signal_handlers_disconnect_by_func (view, on_objects_added, app);
g_signal_handlers_disconnect_by_func (view, on_objects_modified, app); g_signal_handlers_disconnect_by_func (view, on_objects_modified, app);
g_signal_handlers_disconnect_by_func (view, on_objects_removed, app); g_signal_handlers_disconnect_by_func (view, on_objects_removed, app);
e_cal_view_stop (view); e_cal_client_view_stop (view, NULL);
g_object_unref (view); g_object_unref (view);
} }
g_list_free (app->live_views); g_list_free (app->live_views);