[gnome-shell/gnome-3-20] calendar-server: Use the actual recurrence ID of events
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/gnome-3-20] calendar-server: Use the actual recurrence ID of events
- Date: Fri, 8 Jul 2016 16:10:39 +0000 (UTC)
commit b21e4d1deef0f40ffc5e900245027d880be1651a
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Jul 7 18:50:49 2016 +0200
calendar-server: Use the actual recurrence ID of events
Instead of querying the client for a list of objects and using
e_cal_recur_generate_instances() to get occurrences for each of
them, we can use e_cal_client_generate_instances_sync() which
combines the functionality of both functions. This doesn't only
save us some lines of code (yay!), but also gives us access to
the real recurrence ID of an event, so we can get rid of the hack
of faking one.
https://bugzilla.gnome.org/show_bug.cgi?id=748226
src/calendar-server/gnome-shell-calendar-server.c | 136 +++++++--------------
1 files changed, 45 insertions(+), 91 deletions(-)
---
diff --git a/src/calendar-server/gnome-shell-calendar-server.c
b/src/calendar-server/gnome-shell-calendar-server.c
index 83da779..5ff12f2 100644
--- a/src/calendar-server/gnome-shell-calendar-server.c
+++ b/src/calendar-server/gnome-shell-calendar-server.c
@@ -95,6 +95,12 @@ typedef struct
GSList *occurrences;
} CalendarAppointment;
+typedef struct
+{
+ ECalClient *client;
+ GHashTable *appointments;
+} CollectAppointmentsData;
+
static time_t
get_time_from_property (icalcomponent *ical,
icalproperty_kind prop_kind,
@@ -396,78 +402,49 @@ resolve_timezone_id (const char *tzid,
return retval;
}
-static gboolean
-calendar_appointment_collect_occurrence (ECalComponent *component,
- time_t occurrence_start,
- time_t occurrence_end,
- gpointer data)
+static CalendarAppointment *
+calendar_appointment_new (icalcomponent *ical,
+ ECalClient *cal)
{
- CalendarOccurrence *occurrence;
- GSList **collect_loc = data;
- char *rid;
-
- /* HACK: component is the primary event, so we don't have access
- * to the actual recur ID; fake one if the event has any
- * recurrences
- */
- if (e_cal_component_has_recurrences (component))
- rid = ctime (&occurrence_start);
- else
- rid = "";
-
- occurrence = g_new0 (CalendarOccurrence, 1);
- occurrence->start_time = occurrence_start;
- occurrence->end_time = occurrence_end;
- occurrence->rid = g_strdup (rid);
+ CalendarAppointment *appointment;
- *collect_loc = g_slist_prepend (*collect_loc, occurrence);
+ appointment = g_new0 (CalendarAppointment, 1);
- return TRUE;
+ calendar_appointment_init (appointment, ical, cal);
+ return appointment;
}
-static void
-calendar_appointment_generate_occurrences (CalendarAppointment *appointment,
- icalcomponent *ical,
- ECalClient *cal,
- time_t start,
- time_t end)
+static gboolean
+generate_instances_cb (ECalComponent *comp,
+ time_t start,
+ time_t end,
+ gpointer data)
{
- ECalComponent *ecal;
- icaltimezone *default_zone;
-
- g_assert (appointment->occurrences == NULL);
+ ECalClient *cal = ((CollectAppointmentsData *)data)->client;
+ GHashTable *appointments = ((CollectAppointmentsData *)data)->appointments;
+ CalendarAppointment *appointment;
+ CalendarOccurrence *occurrence;
+ const char *uid;
- default_zone = e_cal_client_get_default_timezone (cal);
+ e_cal_component_get_uid (comp, &uid);
+ appointment = g_hash_table_lookup (appointments, uid);
- ecal = e_cal_component_new ();
- e_cal_component_set_icalcomponent (ecal,
- icalcomponent_new_clone (ical));
+ if (appointment == NULL)
+ {
+ icalcomponent *ical = e_cal_component_get_icalcomponent (comp);
- e_cal_recur_generate_instances (ecal,
- start,
- end,
- calendar_appointment_collect_occurrence,
- &appointment->occurrences,
- (ECalRecurResolveTimezoneFn) resolve_timezone_id,
- cal,
- default_zone);
+ appointment = calendar_appointment_new (ical, cal);
+ g_hash_table_insert (appointments, g_strdup (uid), appointment);
+ }
- g_object_unref (ecal);
+ occurrence = g_new0 (CalendarOccurrence, 1);
+ occurrence->start_time = start;
+ occurrence->end_time = end;
+ occurrence->rid = e_cal_component_get_recurid_as_string (comp);
- appointment->occurrences = g_slist_reverse (appointment->occurrences);
+ appointment->occurrences = g_slist_append (appointment->occurrences, occurrence);
}
-static CalendarAppointment *
-calendar_appointment_new (icalcomponent *ical,
- ECalClient *cal)
-{
- CalendarAppointment *appointment;
-
- appointment = g_new0 (CalendarAppointment, 1);
-
- calendar_appointment_init (appointment, ical, cal);
- return appointment;
-}
/* ---------------------------------------------------------------------------------------------------- */
@@ -647,6 +624,7 @@ app_load_events (App *app)
GError *error;
GSList *objects, *j;
ECalClientView *view;
+ CollectAppointmentsData data;
e_cal_client_set_default_timezone (cal, app->zone);
@@ -660,37 +638,13 @@ app_load_events (App *app)
continue;
}
- error = NULL;
- objects = NULL;
- if (!e_cal_client_get_object_list_sync (cal,
- query,
- &objects,
- NULL, /* cancellable */
- &error))
- {
- ESource *source = e_client_get_source (E_CLIENT (cal));
- g_warning ("Error querying calendar %s: %s\n",
- e_source_get_uid (source), error->message);
- g_error_free (error);
- g_free (query);
- continue;
- }
-
- for (j = objects; j != NULL; j = j->next)
- {
- icalcomponent *ical = j->data;
- CalendarAppointment *appointment;
-
- appointment = calendar_appointment_new (ical, cal);
- calendar_appointment_generate_occurrences (appointment,
- ical,
- cal,
- app->since,
- app->until);
- g_hash_table_insert (app->appointments, g_strdup (appointment->uid), appointment);
- }
-
- e_cal_client_free_icalcomp_slist (objects);
+ data.client = cal;
+ data.appointments = app->appointments;
+ e_cal_client_generate_instances_sync (cal,
+ app->since,
+ app->until,
+ generate_instances_cb,
+ &data);
error = NULL;
if (!e_cal_client_get_view_sync (cal,
@@ -922,7 +876,7 @@ handle_method_call (GDBusConnection *connection,
char *id = g_strdup_printf ("%s\n%s\n%s",
a->source_id,
a->uid,
- o->rid);
+ o->rid ? o->rid : "");
g_variant_builder_init (&extras_builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&builder,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]