[evolution] I#1042 - Show recurrence information with user-specified date format



commit 87732546bcfc8857cae337d3b793c858ebf5c36d
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jul 30 12:33:55 2020 +0200

    I#1042 - Show recurrence information with user-specified date format
    
    Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/1042

 src/calendar/gui/comp-util.c               | 17 +++++++
 src/calendar/gui/comp-util.h               |  4 ++
 src/calendar/gui/e-cal-component-preview.c |  5 +-
 src/calendar/gui/e-date-time-list.c        | 11 ++---
 src/e-util/e-datetime-format.c             | 79 +++++++++++++++++++++++-------
 src/e-util/e-datetime-format.h             | 13 +++++
 src/modules/alarm-notify/alarm-notify.c    | 12 +----
 src/modules/itip-formatter/itip-view.c     |  5 +-
 8 files changed, 105 insertions(+), 41 deletions(-)
---
diff --git a/src/calendar/gui/comp-util.c b/src/calendar/gui/comp-util.c
index 2ad465480e..815b151002 100644
--- a/src/calendar/gui/comp-util.c
+++ b/src/calendar/gui/comp-util.c
@@ -1829,3 +1829,20 @@ cal_comp_util_maybe_ensure_allday_timezone_properties (ECalClient *client,
        ensure_allday_timezone_property (icomp, zone, I_CAL_DTSTART_PROPERTY, i_cal_component_get_dtstart, 
i_cal_component_set_dtstart);
        ensure_allday_timezone_property (icomp, zone, I_CAL_DTEND_PROPERTY, i_cal_component_get_dtend, 
i_cal_component_set_dtend);
 }
+
+void
+cal_comp_util_format_itt (ICalTime *itt,
+                         gchar *buffer,
+                         gint buffer_size)
+{
+       struct tm tm;
+
+       g_return_if_fail (itt != NULL);
+       g_return_if_fail (buffer != NULL);
+       g_return_if_fail (buffer_size > 0);
+
+       buffer[0] = '\0';
+
+       tm = e_cal_util_icaltime_to_tm (itt);
+       e_datetime_format_format_tm_inline ("calendar", "table", i_cal_time_is_date (itt) ? DTFormatKindDate 
: DTFormatKindDateTime, &tm, buffer, buffer_size);
+}
diff --git a/src/calendar/gui/comp-util.h b/src/calendar/gui/comp-util.h
index 1c9702deea..97902e4d51 100644
--- a/src/calendar/gui/comp-util.h
+++ b/src/calendar/gui/comp-util.h
@@ -172,4 +172,8 @@ void                cal_comp_util_maybe_ensure_allday_timezone_properties
                                                (ECalClient *client,
                                                 ICalComponent *icomp,
                                                 ICalTimezone *zone);
+void           cal_comp_util_format_itt        (ICalTime *itt,
+                                                gchar *buffer,
+                                                gint buffer_size);
+
 #endif
diff --git a/src/calendar/gui/e-cal-component-preview.c b/src/calendar/gui/e-cal-component-preview.c
index 3f8a1a6aec..712a5cd00a 100644
--- a/src/calendar/gui/e-cal-component-preview.c
+++ b/src/calendar/gui/e-cal-component-preview.c
@@ -318,9 +318,10 @@ cal_component_preview_write_html (ECalComponentPreview *preview,
        icomp = e_cal_component_get_icalcomponent (comp);
 
        if (e_cal_util_component_has_recurrences (icomp)) {
-               str = e_cal_recur_describe_recurrence (icomp,
+               str = e_cal_recur_describe_recurrence_ex (icomp,
                        calendar_config_get_week_start_day (),
-                       E_CAL_RECUR_DESCRIBE_RECURRENCE_FLAG_NONE);
+                       E_CAL_RECUR_DESCRIBE_RECURRENCE_FLAG_NONE,
+                       cal_comp_util_format_itt);
 
                if (str) {
                        cal_component_preview_add_table_line (buffer, _("Recurs:"), str);
diff --git a/src/calendar/gui/e-date-time-list.c b/src/calendar/gui/e-date-time-list.c
index 06143fe1c5..05c684e33d 100644
--- a/src/calendar/gui/e-date-time-list.c
+++ b/src/calendar/gui/e-date-time-list.c
@@ -23,6 +23,8 @@
 
 #include "evolution-config.h"
 
+#include "comp-util.h"
+
 #include "e-date-time-list.h"
 
 #include <string.h>
@@ -141,12 +143,9 @@ get_exception_string (EDateTimeList *date_time_list,
                      ICalTime *itt)
 {
        static gchar buf[256];
-       struct tm tmp_tm;
        ICalTime *tt;
        ICalTimezone *zone;
-       gboolean use_24_hour_format;
 
-       use_24_hour_format = e_date_time_list_get_use_24_hour_format (date_time_list);
        zone = e_date_time_list_get_timezone (date_time_list);
 
        if (zone)
@@ -154,11 +153,7 @@ get_exception_string (EDateTimeList *date_time_list,
        else
                tt = g_object_ref (itt);
 
-       tmp_tm = e_cal_util_icaltime_to_tm (tt);
-
-       e_time_format_date_and_time (
-               &tmp_tm, use_24_hour_format,
-               FALSE, FALSE, buf, sizeof (buf));
+       cal_comp_util_format_itt (tt, buf, sizeof (buf));
 
        g_clear_object (&tt);
 
diff --git a/src/e-util/e-datetime-format.c b/src/e-util/e-datetime-format.c
index 9f8a06d6f1..df45850fbd 100644
--- a/src/e-util/e-datetime-format.c
+++ b/src/e-util/e-datetime-format.c
@@ -276,14 +276,15 @@ format_relative_date (time_t tvalue,
        return res;
 }
 
-static gchar *
+static void
 format_internal (const gchar *key,
-                 DTFormatKind kind,
-                 time_t tvalue,
-                 struct tm *tm_value)
+                DTFormatKind kind,
+                time_t tvalue,
+                struct tm *tm_value,
+                gchar *buffer,
+                gint buffer_size)
 {
        const gchar *fmt;
-       gchar buff[129];
        GString *use_fmt = NULL;
        gint i, last = 0;
        struct tm today, value;
@@ -350,12 +351,12 @@ format_internal (const gchar *key,
                g_string_append_len (use_fmt, fmt + last, i - last);
        }
 
-       e_utf8_strftime_fix_am_pm (buff, sizeof (buff) - 1, use_fmt ? use_fmt->str : fmt, tm_value);
+       e_utf8_strftime_fix_am_pm (buffer, buffer_size, use_fmt ? use_fmt->str : fmt, tm_value);
 
        if (use_fmt)
                g_string_free (use_fmt, TRUE);
 
-       return g_strstrip (g_strdup (buff));
+       g_strstrip (buffer);
 }
 
 static void
@@ -477,7 +478,7 @@ update_preview_widget (GtkWidget *combo)
 {
        GtkWidget *preview;
        const gchar *key;
-       gchar *value;
+       gchar buffer[129];
        time_t now;
 
        g_return_if_fail (GTK_IS_COMBO_BOX (combo));
@@ -491,9 +492,8 @@ update_preview_widget (GtkWidget *combo)
 
        time (&now);
 
-       value = format_internal (key, GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "format-kind")), 
now, NULL);
-       gtk_label_set_text (GTK_LABEL (preview), value ? value : "");
-       g_free (value);
+       format_internal (key, GPOINTER_TO_INT (g_object_get_data (G_OBJECT (combo), "format-kind")), now, 
NULL, buffer, sizeof (buffer));
+       gtk_label_set_text (GTK_LABEL (preview), buffer);
 }
 
 static void
@@ -664,19 +664,39 @@ e_datetime_format_format (const gchar *component,
                           DTFormatKind kind,
                           time_t value)
 {
-       gchar *key, *res;
+       gchar buffer[129];
 
        g_return_val_if_fail (component != NULL, NULL);
        g_return_val_if_fail (*component != 0, NULL);
 
+       e_datetime_format_format_inline (component, part, kind, value, buffer, sizeof (buffer));
+
+       return g_strdup (buffer);
+}
+
+void
+e_datetime_format_format_inline (const gchar *component,
+                                const gchar *part,
+                                DTFormatKind kind,
+                                time_t value,
+                                gchar *buffer,
+                                gint buffer_size)
+{
+       gchar *key;
+
+       g_return_if_fail (component != NULL);
+       g_return_if_fail (*component != 0);
+       g_return_if_fail (buffer != NULL);
+       g_return_if_fail (buffer_size > 0);
+
        key = gen_key (component, part, kind);
-       g_return_val_if_fail (key != NULL, NULL);
+       g_return_if_fail (key != NULL);
 
-       res = format_internal (key, kind, value, NULL);
+       format_internal (key, kind, value, NULL, buffer, buffer_size - 1);
 
        g_free (key);
 
-       return res;
+       buffer[buffer_size - 1] = '\0';
 }
 
 gchar *
@@ -685,20 +705,41 @@ e_datetime_format_format_tm (const gchar *component,
                              DTFormatKind kind,
                              struct tm *tm_time)
 {
-       gchar *key, *res;
+       gchar buffer[129];
 
        g_return_val_if_fail (component != NULL, NULL);
        g_return_val_if_fail (*component != 0, NULL);
        g_return_val_if_fail (tm_time != NULL, NULL);
 
+       e_datetime_format_format_tm_inline (component, part, kind, tm_time, buffer, sizeof (buffer));
+
+       return g_strdup (buffer);
+}
+
+void
+e_datetime_format_format_tm_inline (const gchar *component,
+                                   const gchar *part,
+                                   DTFormatKind kind,
+                                   struct tm *tm_time,
+                                   gchar *buffer,
+                                   gint buffer_size)
+{
+       gchar *key;
+
+       g_return_if_fail (component != NULL);
+       g_return_if_fail (*component != 0);
+       g_return_if_fail (tm_time != NULL);
+       g_return_if_fail (buffer != NULL);
+       g_return_if_fail (buffer_size > 0);
+
        key = gen_key (component, part, kind);
-       g_return_val_if_fail (key != NULL, NULL);
+       g_return_if_fail (key != NULL);
 
-       res = format_internal (key, kind, 0, tm_time);
+       format_internal (key, kind, 0, tm_time, buffer, buffer_size - 1);
 
        g_free (key);
 
-       return res;
+       buffer[buffer_size - 1] = '\0';
 }
 
 gboolean
diff --git a/src/e-util/e-datetime-format.h b/src/e-util/e-datetime-format.h
index 2b9309fd99..ec8e79ba0b 100644
--- a/src/e-util/e-datetime-format.h
+++ b/src/e-util/e-datetime-format.h
@@ -49,10 +49,23 @@ gchar *             e_datetime_format_format        (const gchar *component,
                                                 const gchar *part,
                                                 DTFormatKind kind,
                                                 time_t value);
+void           e_datetime_format_format_inline (const gchar *component,
+                                                const gchar *part,
+                                                DTFormatKind kind,
+                                                time_t value,
+                                                gchar *buffer,
+                                                gint buffer_size);
 gchar *                e_datetime_format_format_tm     (const gchar *component,
                                                 const gchar *part,
                                                 DTFormatKind kind,
                                                 struct tm *tm_time);
+void           e_datetime_format_format_tm_inline
+                                               (const gchar *component,
+                                                const gchar *part,
+                                                DTFormatKind kind,
+                                                struct tm *tm_time,
+                                                gchar *buffer,
+                                                gint buffer_size);
 gboolean       e_datetime_format_includes_day_name
                                                (const gchar *component,
                                                 const gchar *part,
diff --git a/src/modules/alarm-notify/alarm-notify.c b/src/modules/alarm-notify/alarm-notify.c
index 1df835f629..2137eb0f76 100644
--- a/src/modules/alarm-notify/alarm-notify.c
+++ b/src/modules/alarm-notify/alarm-notify.c
@@ -23,6 +23,7 @@
 
 #include <libedataserverui/libedataserverui.h>
 
+#include "calendar/gui/comp-util.h"
 #include "e-util/e-util.h"
 
 /* Standard GObject macros */
@@ -95,22 +96,13 @@ alarm_notify_module_format_time_cb (EReminderWatcher *watcher,
                                    gchar **inout_buffer,
                                    gint buffer_size)
 {
-       struct tm tm;
-       gchar *text;
-
        g_return_if_fail (rd != NULL);
        g_return_if_fail (itt != NULL);
        g_return_if_fail (inout_buffer != NULL);
        g_return_if_fail (*inout_buffer != NULL);
        g_return_if_fail (buffer_size > 0);
 
-       tm = e_cal_util_icaltime_to_tm (itt);
-       text = e_datetime_format_format_tm ("calendar", "table", i_cal_time_is_date (itt) ? DTFormatKindDate 
: DTFormatKindDateTime, &tm);
-
-       if (text) {
-               g_snprintf (*inout_buffer, buffer_size, "%s", text);
-               g_free (text);
-       }
+       cal_comp_util_format_itt (itt, *inout_buffer, buffer_size);
 }
 
 static gboolean
diff --git a/src/modules/itip-formatter/itip-view.c b/src/modules/itip-formatter/itip-view.c
index 2ff7a172cb..72c3138e33 100644
--- a/src/modules/itip-formatter/itip-view.c
+++ b/src/modules/itip-formatter/itip-view.c
@@ -6280,9 +6280,10 @@ itip_view_add_recurring_info (ItipView *view)
 {
        gchar *description;
 
-       description = e_cal_recur_describe_recurrence (e_cal_component_get_icalcomponent (view->priv->comp),
+       description = e_cal_recur_describe_recurrence_ex (e_cal_component_get_icalcomponent 
(view->priv->comp),
                calendar_config_get_week_start_day (),
-               E_CAL_RECUR_DESCRIBE_RECURRENCE_FLAG_PREFIXED | 
E_CAL_RECUR_DESCRIBE_RECURRENCE_FLAG_FALLBACK);
+               E_CAL_RECUR_DESCRIBE_RECURRENCE_FLAG_PREFIXED | E_CAL_RECUR_DESCRIBE_RECURRENCE_FLAG_FALLBACK,
+               cal_comp_util_format_itt);
 
        if (description) {
                itip_view_add_upper_info_item (view, ITIP_VIEW_INFO_ITEM_TYPE_INFO, description);


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