[evolution-data-server] Miscellaneous changes for issues overlooked during port to libical-glib



commit 3cb5503368cc423ae20d9d9d137762852e6c4d02
Author: Milan Crha <mcrha redhat com>
Date:   Mon May 20 13:47:11 2019 +0200

    Miscellaneous changes for issues overlooked during port to libical-glib

 src/calendar/backends/file/e-cal-backend-file.c |   6 +-
 src/calendar/libecal/e-cal-check-timezones.c    | 128 +++++++++++++++++++++---
 src/calendar/libecal/e-cal-check-timezones.h    |  24 ++++-
 src/calendar/libecal/e-cal-recur.c              |   2 +-
 src/calendar/libecal/e-cal-recur.h              |   7 +-
 src/calendar/libecal/e-cal-util.c               |  12 +--
 6 files changed, 150 insertions(+), 29 deletions(-)
---
diff --git a/src/calendar/backends/file/e-cal-backend-file.c b/src/calendar/backends/file/e-cal-backend-file.c
index 8e86c25b3..1b8feacc0 100644
--- a/src/calendar/backends/file/e-cal-backend-file.c
+++ b/src/calendar/backends/file/e-cal-backend-file.c
@@ -3358,6 +3358,7 @@ e_cal_backend_file_receive_objects (ECalBackendSync *backend,
        ESourceRegistry *registry;
        ECalBackendFile *cbfile;
        ECalBackendFilePrivate *priv;
+       ECalClientTzlookupICalCompData *lookup_data = NULL;
        ICalComponent *toplevel_comp, *icomp = NULL;
        ICalComponentKind kind;
        ICalPropertyMethod toplevel_method, method;
@@ -3473,11 +3474,13 @@ e_cal_backend_file_receive_objects (ECalBackendSync *backend,
        g_slist_free_full (del_comps, g_object_unref);
        del_comps = NULL;
 
+       lookup_data = e_cal_client_tzlookup_icalcomp_data_new (priv->vcalendar);
+
         /* check and patch timezones */
        if (!e_cal_client_check_timezones_sync (toplevel_comp,
                               NULL,
                               e_cal_client_tzlookup_icalcomp_cb,
-                              priv->vcalendar,
+                              lookup_data,
                               NULL,
                               &err)) {
                /*
@@ -3649,6 +3652,7 @@ e_cal_backend_file_receive_objects (ECalBackendSync *backend,
 
        g_hash_table_destroy (tzdata.zones);
        g_rec_mutex_unlock (&priv->idle_save_rmutex);
+       e_cal_client_tzlookup_icalcomp_data_free (lookup_data);
 
        if (err)
                g_propagate_error (error, err);
diff --git a/src/calendar/libecal/e-cal-check-timezones.c b/src/calendar/libecal/e-cal-check-timezones.c
index 65db02acd..c3325599b 100644
--- a/src/calendar/libecal/e-cal-check-timezones.c
+++ b/src/calendar/libecal/e-cal-check-timezones.c
@@ -344,7 +344,6 @@ e_cal_client_check_timezones_sync (ICalComponent *vcalendar,
                                                zone_comp = i_cal_timezone_get_component (existing_zone);
                                                buffer = zone_comp ? i_cal_component_as_ical_string 
(zone_comp) : NULL;
                                                g_clear_object (&zone_comp);
-                                               g_clear_object (&existing_zone);
 
                                                if (!buffer)
                                                        continue;
@@ -469,10 +468,9 @@ e_cal_client_check_timezones_sync (ICalComponent *vcalendar,
  * An implementation of the #ECalRecurResolveTimezoneCb callback which clients
  * can use. Calls e_cal_client_get_timezone_sync().
  *
- * Free a non-NULL returned timezone object with g_object_unref(), when
- * no longer needed.
+ * The returned timezone object, if not %NULL, is owned by the @ecalclient.
  *
- * Returns: (transfer full) (nullable): A timezone object, or %NULL on failure
+ * Returns: (transfer none) (nullable): A timezone object, or %NULL on failure
  *    or when not found.
  *
  * Since: 3.34
@@ -506,34 +504,134 @@ e_cal_client_tzlookup_cb (const gchar *tzid,
        return NULL;
 }
 
+G_DEFINE_BOXED_TYPE (ECalClientTzlookupICalCompData, e_cal_client_tzlookup_icalcomp_data, 
e_cal_client_tzlookup_icalcomp_data_copy, e_cal_client_tzlookup_icalcomp_data_free)
+
+struct _ECalClientTzlookupICalCompData {
+       ICalComponent *icomp;
+       GHashTable *tzcache; /* gchar *tzid ~> ICalTimezone * */
+};
+
+/**
+ * e_cal_client_tzlookup_icalcomp_data_new:
+ * @icomp: an #ICalComponent
+ *
+ * Constructs a new #ECalClientTzlookupICalCompData, which can
+ * be used as a lookup_data argument of e_cal_client_tzlookup_icalcomp_cb().
+ * Free it with e_cal_client_tzlookup_icalcomp_data_free(), when no longer needed.
+ *
+ * Returns: (transfer full): a new #ECalClientTzlookupICalCompData
+ *
+ * Since: 3.34
+ **/
+ECalClientTzlookupICalCompData *
+e_cal_client_tzlookup_icalcomp_data_new (ICalComponent *icomp)
+{
+       ECalClientTzlookupICalCompData *lookup_data;
+
+       g_return_val_if_fail (I_CAL_IS_COMPONENT (icomp), NULL);
+
+       lookup_data = g_new0 (ECalClientTzlookupICalCompData, 1);
+       lookup_data->icomp = g_object_ref (icomp);
+       lookup_data->tzcache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+
+       return lookup_data;
+}
+
+/**
+ * e_cal_client_tzlookup_icalcomp_data_copy:
+ * @lookup_data: (nullable): source #ECalClientTzlookupICalCompData, or %NULL
+ *
+ * Copies given #ECalClientTzlookupICalCompData structure.
+ * When the @lookup_data is %NULL, simply returns %NULL as well.
+ *
+ * Returns: (transfer full) (nullable): copy of the @lookup_data. Free the returned structure
+ *    with e_cal_client_tzlookup_icalcomp_data_free(), when no longer needed.
+ *
+ * Since: 3.34
+ **/
+ECalClientTzlookupICalCompData *
+e_cal_client_tzlookup_icalcomp_data_copy (const ECalClientTzlookupICalCompData *lookup_data)
+{
+       if (!lookup_data)
+               return NULL;
+
+       return e_cal_client_tzlookup_icalcomp_data_new (
+               e_cal_client_tzlookup_icalcomp_data_get_icalcomponent (lookup_data));
+}
+
+/**
+ * e_cal_client_tzlookup_icalcomp_data_free:
+ * @lookup_data: (nullable): an #ECalClientTzlookupICalCompData, or %NULL
+ *
+ * Frees previously allocated #ECalClientTzlookupICalCompData structure
+ * with e_cal_client_tzlookup_icalcomp_data_new() or e_cal_client_tzlookup_icalcomp_data_copy().
+ * The function does nothing when @lookup_data is %NULL.
+ *
+ * Since: 3.34
+ **/
+void
+e_cal_client_tzlookup_icalcomp_data_free (ECalClientTzlookupICalCompData *lookup_data)
+{
+       if (lookup_data) {
+               g_clear_object (&lookup_data->icomp);
+               g_hash_table_destroy (lookup_data->tzcache);
+               g_free (lookup_data);
+       }
+}
+
+/**
+ * e_cal_client_tzlookup_icalcomp_data_get_icalcomponent:
+ * @lookup_data: an #ECalClientTzlookupICalCompData
+ *
+ * Returns: (transfer none): The #ICalComponent associated with the @lookup_data
+ *
+ * Since: 3.34
+ **/
+ICalComponent *
+e_cal_client_tzlookup_icalcomp_data_get_icalcomponent (const ECalClientTzlookupICalCompData *lookup_data)
+{
+       g_return_val_if_fail (lookup_data != NULL, NULL);
+
+       return lookup_data->icomp;
+}
+
 /**
  * e_cal_client_tzlookup_icalcomp_cb:
  * @tzid: ID of the timezone to lookup
- * @icalcomp: (type ICalComponent): an #ICalComponent pointer, which contains
- *    either a VCALENDAR with VTIMEZONEs or VTIMEZONES directly
+ * @lookup_data: (type ECalClientTzlookupICalCompData): an #ECalClientTzlookupICalCompData
+ *    strcture, created with e_cal_client_tzlookup_icalcomp_data_new()
  * @cancellable: an optional #GCancellable to use, or %NULL
  * @error: an error description in case of a failure
  *
  * An implementation of the #ECalRecurResolveTimezoneCb callback which
- * backends can use. Searches for the timezone in the @icalcomp.
+ * backends can use. Searches for the timezone in an %ICalComponent
+ * associated with the @lookup_data %ECalClientTzlookupICalCompData.
  *
- * Free a non-NULL returned timezone object with g_object_unref(), when
- * no longer needed.
+ * The returned timezone object is owned by the @lookup_data.
  *
- * Returns: (transfer full) (nullable): A timezone object, or %NULL, if
- *    not found inside @icalcomp.
+ * Returns: (transfer none) (nullable): A timezone object, or %NULL, if
+ *    not found inside @lookup_data 's #ICalComponent.
  *
  * Since: 3.34
  **/
 ICalTimezone *
 e_cal_client_tzlookup_icalcomp_cb (const gchar *tzid,
-                                  gpointer icalcomp,
+                                  gpointer lookup_data,
                                   GCancellable *cancellable,
                                   GError **error)
 {
-       ICalComponent *icomp = icalcomp;
+       ECalClientTzlookupICalCompData *ld = lookup_data;
+       ICalTimezone *zone;
 
-       g_return_val_if_fail (I_CAL_IS_COMPONENT (icalcomp), NULL);
+       g_return_val_if_fail (tzid != NULL, NULL);
+       g_return_val_if_fail (lookup_data != NULL, NULL);
+
+       zone = g_hash_table_lookup (ld->tzcache, tzid);
+       if (!zone) {
+               zone = i_cal_component_get_timezone (e_cal_client_tzlookup_icalcomp_data_get_icalcomponent 
(ld), tzid);
+               if (zone)
+                       g_hash_table_insert (ld->tzcache, g_strdup (tzid), zone);
+       }
 
-       return i_cal_component_get_timezone (icomp, tzid);
+       return zone;
 }
diff --git a/src/calendar/libecal/e-cal-check-timezones.h b/src/calendar/libecal/e-cal-check-timezones.h
index ec20f90f1..5614bb68c 100644
--- a/src/calendar/libecal/e-cal-check-timezones.h
+++ b/src/calendar/libecal/e-cal-check-timezones.h
@@ -44,9 +44,31 @@ ICalTimezone *       e_cal_client_tzlookup_cb        (const gchar *tzid,
                                                 GCancellable *cancellable,
                                                 GError **error);
 
+/**
+ * ECalClientTzlookupICalCompData:
+ *
+ * Contains data used as lookup_data of e_cal_client_tzlookup_icalcomp_cb().
+ *
+ * Since: 3.34
+ **/
+typedef struct _ECalClientTzlookupICalCompData ECalClientTzlookupICalCompData;
+
+GType          e_cal_client_tzlookup_icalcomp_data_get_type
+                                               (void) G_GNUC_CONST;
+ECalClientTzlookupICalCompData *
+               e_cal_client_tzlookup_icalcomp_data_new
+                                               (ICalComponent *icomp);
+ECalClientTzlookupICalCompData *
+               e_cal_client_tzlookup_icalcomp_data_copy
+                                               (const ECalClientTzlookupICalCompData *lookup_data);
+void           e_cal_client_tzlookup_icalcomp_data_free
+                                               (ECalClientTzlookupICalCompData *lookup_data);
+ICalComponent *        e_cal_client_tzlookup_icalcomp_data_get_icalcomponent
+                                               (const ECalClientTzlookupICalCompData *lookup_data);
+
 ICalTimezone * e_cal_client_tzlookup_icalcomp_cb
                                                (const gchar *tzid,
-                                                gpointer icalcomp, /* ICalComponent * */
+                                                gpointer lookup_data, /* ECalClientTzlookupICalCompData * */
                                                 GCancellable *cancellable,
                                                 GError **error);
 
diff --git a/src/calendar/libecal/e-cal-recur.c b/src/calendar/libecal/e-cal-recur.c
index 0f4251c32..c4587ce70 100644
--- a/src/calendar/libecal/e-cal-recur.c
+++ b/src/calendar/libecal/e-cal-recur.c
@@ -244,7 +244,7 @@ ensure_timezone (ICalComponent *comp,
        }
 
        if (get_tz_callback) {
-               ICalTimezone *zone = NULL;
+               zone = NULL;
 
                if (*pcached_zones)
                        zone = g_hash_table_lookup (*pcached_zones, tzid);
diff --git a/src/calendar/libecal/e-cal-recur.h b/src/calendar/libecal/e-cal-recur.h
index ccbb2ba40..f6d69370d 100644
--- a/src/calendar/libecal/e-cal-recur.h
+++ b/src/calendar/libecal/e-cal-recur.h
@@ -52,10 +52,11 @@ G_BEGIN_DECLS
  * @cancellable: optional #GCancellable object, or %NULL
  * @error: return location for a #GError, or %NULL
  *
- * Resolve timezone by its ID provided as @tzid. Free the returned object,
- * if not %NULL, with g_object_unref(), when no longer needed.
+ * Resolve timezone by its ID provided as @tzid. The returned object,
+ * if not %NULL, is owned by the callback implementation and should
+ * not be freed.
  *
- * Returns: (transfer full) (nullable): a new #ICalTimezone object for @tzid,
+ * Returns: (transfer none) (nullable): an #ICalTimezone object for @tzid,
  *    or %NULL, on error or if not found.
  *
  * Since: 3.34
diff --git a/src/calendar/libecal/e-cal-util.c b/src/calendar/libecal/e-cal-util.c
index 77c691376..4c2ea83c2 100644
--- a/src/calendar/libecal/e-cal-util.c
+++ b/src/calendar/libecal/e-cal-util.c
@@ -417,8 +417,8 @@ add_alarm_occurrences_cb (ICalComponent *icalcomp,
        GSList *link;
 
        aod = user_data;
-       start = i_cal_time_as_timet (instance_start);
-       end = i_cal_time_as_timet (instance_end);
+       start = i_cal_time_as_timet_with_zone (instance_start, i_cal_time_get_timezone (instance_start));
+       end = i_cal_time_as_timet_with_zone (instance_end, i_cal_time_get_timezone (instance_end));
 
        for (link = aod->alarm_uids; link; link = g_slist_next (link)) {
                const gchar *auid;
@@ -531,11 +531,9 @@ generate_absolute_triggers (ECalComponent *comp,
                if (tzid && !i_cal_time_is_date (e_cal_component_datetime_get_value (dtstart)))
                        zone = (* resolve_tzid) (tzid, user_data, NULL, NULL);
                else
-                       zone = default_timezone ? g_object_ref (default_timezone) : NULL;
+                       zone = default_timezone;
 
                occur_start = i_cal_time_as_timet_with_zone (e_cal_component_datetime_get_value (dtstart), 
zone);
-
-               g_clear_object (&zone);
        } else
                occur_start = -1;
 
@@ -546,11 +544,9 @@ generate_absolute_triggers (ECalComponent *comp,
                if (tzid && !i_cal_time_is_date (e_cal_component_datetime_get_value (dtend)))
                        zone = (* resolve_tzid) (tzid, user_data, NULL, NULL);
                else
-                       zone = default_timezone ? g_object_ref (default_timezone) : NULL;
+                       zone = default_timezone;
 
                occur_end = i_cal_time_as_timet_with_zone (e_cal_component_datetime_get_value (dtend), zone);
-
-               g_clear_object (&zone);
        } else
                occur_end = -1;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]