[evolution/wip/webkit2] Bug 765665 - Notification doesn't use user selected date/time format



commit 1a1bfc775c1c506bf7ca036f38ace924e501f938
Author: Milan Crha <mcrha redhat com>
Date:   Thu Apr 28 09:52:39 2016 +0200

    Bug 765665 - Notification doesn't use user selected date/time format

 calendar/alarm-notify/alarm-notify-dialog.c |   14 +++++----
 calendar/alarm-notify/alarm-notify-dialog.h |    2 +-
 calendar/alarm-notify/alarm-queue.c         |   18 ++++-------
 calendar/alarm-notify/util.c                |   42 +++++++++++++++++++++++----
 calendar/alarm-notify/util.h                |    6 +++-
 5 files changed, 57 insertions(+), 25 deletions(-)
---
diff --git a/calendar/alarm-notify/alarm-notify-dialog.c b/calendar/alarm-notify/alarm-notify-dialog.c
index d094ce6..84df985 100644
--- a/calendar/alarm-notify/alarm-notify-dialog.c
+++ b/calendar/alarm-notify/alarm-notify-dialog.c
@@ -436,7 +436,7 @@ notified_alarms_dialog_new (void)
  * @trigger: Trigger time for the alarm.
  * @occur_start: Start of occurrence time for the event.
  * @occur_end: End of occurrence time for the event.
- * @vtype: Type of the component which corresponds to the alarm.
+ * @comp: The #ECalComponent which corresponds to the alarm.
  * @summary: Short summary of the appointment
  * @description: Long description of the appointment
  * @location: Location of the appointment
@@ -454,7 +454,7 @@ add_alarm_to_notified_alarms_dialog (AlarmNotificationsDialog *na,
                                      time_t trigger,
                                      time_t occur_start,
                                      time_t occur_end,
-                                     ECalComponentVType vtype,
+                                     ECalComponent *comp,
                                      const gchar *summary,
                                      const gchar *description,
                                      const gchar *location,
@@ -464,11 +464,15 @@ add_alarm_to_notified_alarms_dialog (AlarmNotificationsDialog *na,
        GtkTreeIter iter = { 0 };
        GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (na->treeview));
        AlarmFuncInfo *funcinfo = NULL;
-       gchar *to_display = NULL, *start, *end, *str_time;
+       ECalComponentVType vtype;
+       gchar *to_display = NULL, *start, *str_time;
        icaltimezone *current_zone;
 
        /* Iter is not yet defined but still we return it in all the g_return_val_if_fail() calls? */
        g_return_val_if_fail (trigger != -1, iter);
+       g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), iter);
+
+       vtype = e_cal_component_get_vtype (comp);
 
        /* Only VEVENTs or VTODOs can have alarms */
        g_return_val_if_fail (vtype == E_CAL_COMPONENT_EVENT || vtype == E_CAL_COMPONENT_TODO, iter);
@@ -484,14 +488,12 @@ add_alarm_to_notified_alarms_dialog (AlarmNotificationsDialog *na,
        gtk_list_store_append (GTK_LIST_STORE (model), &iter);
 
        current_zone = config_data_get_timezone ();
-       start = timet_to_str_with_zone (occur_start, current_zone);
-       end = timet_to_str_with_zone (occur_end, current_zone);
+       start = timet_to_str_with_zone (occur_start, current_zone, datetime_is_date_only (comp, 
DATETIME_CHECK_DTSTART));
        str_time = calculate_time (occur_start, occur_end);
        to_display = g_markup_printf_escaped (
                "<big><b>%s</b></big>\n%s %s",
                summary, start, str_time);
        g_free (start);
-       g_free (end);
        gtk_list_store_set (
                GTK_LIST_STORE (model), &iter,
                ALARM_DISPLAY_COLUMN, to_display, -1);
diff --git a/calendar/alarm-notify/alarm-notify-dialog.h b/calendar/alarm-notify/alarm-notify-dialog.h
index 04d56a9..42fafce 100644
--- a/calendar/alarm-notify/alarm-notify-dialog.h
+++ b/calendar/alarm-notify/alarm-notify-dialog.h
@@ -52,7 +52,7 @@ GtkTreeIter   add_alarm_to_notified_alarms_dialog
                                                 time_t trigger,
                                                 time_t occur_start,
                                                 time_t occur_end,
-                                                ECalComponentVType vtype,
+                                                ECalComponent *comp,
                                                 const gchar *summary,
                                                 const gchar *description,
                                                 const gchar *location,
diff --git a/calendar/alarm-notify/alarm-queue.c b/calendar/alarm-notify/alarm-queue.c
index b465035..abe732d 100644
--- a/calendar/alarm-notify/alarm-queue.c
+++ b/calendar/alarm-notify/alarm-queue.c
@@ -1508,7 +1508,7 @@ open_alarm_dialog (TrayIconData *tray_data)
                                tray_data->trigger,
                                qa->instance->occur_start,
                                qa->instance->occur_end,
-                               e_cal_component_get_vtype (tray_data->comp),
+                               tray_data->comp,
                                tray_data->summary,
                                tray_data->description,
                                tray_data->location,
@@ -1693,7 +1693,7 @@ display_notification (time_t trigger,
        TrayIconData *tray_data;
        ECalComponentText text;
        GSList *text_list;
-       gchar *str, *start_str, *end_str, *alarm_str, *time_str;
+       gchar *str, *start_str, *alarm_str, *time_str;
        icaltimezone *current_zone;
        ECalComponentOrganizer organiser;
 
@@ -1747,9 +1747,8 @@ display_notification (time_t trigger,
        }
 
        current_zone = config_data_get_timezone ();
-       alarm_str = timet_to_str_with_zone (trigger, current_zone);
-       start_str = timet_to_str_with_zone (qa->instance->occur_start, current_zone);
-       end_str = timet_to_str_with_zone (qa->instance->occur_end, current_zone);
+       alarm_str = timet_to_str_with_zone (trigger, current_zone, FALSE);
+       start_str = timet_to_str_with_zone (qa->instance->occur_start, current_zone, datetime_is_date_only 
(comp, DATETIME_CHECK_DTSTART));
        time_str = calculate_time (qa->instance->occur_start, qa->instance->occur_end);
 
        str = g_strdup_printf (
@@ -1790,7 +1789,6 @@ display_notification (time_t trigger,
 
        g_free (alarm_summary);
        g_free (start_str);
-       g_free (end_str);
        g_free (alarm_str);
        g_free (time_str);
        g_free (str);
@@ -1871,7 +1869,7 @@ popup_notification (time_t trigger,
        ECalComponent *comp;
        const gchar *summary, *location;
        gchar *alarm_summary;
-       gchar *str, *start_str, *end_str, *alarm_str, *time_str;
+       gchar *str, *start_str, *alarm_str, *time_str;
        icaltimezone *current_zone;
        ECalComponentOrganizer organiser;
        gchar *body;
@@ -1900,9 +1898,8 @@ popup_notification (time_t trigger,
        /* create the tray icon */
 
        current_zone = config_data_get_timezone ();
-       alarm_str = timet_to_str_with_zone (trigger, current_zone);
-       start_str = timet_to_str_with_zone (qa->instance->occur_start, current_zone);
-       end_str = timet_to_str_with_zone (qa->instance->occur_end, current_zone);
+       alarm_str = timet_to_str_with_zone (trigger, current_zone, FALSE);
+       start_str = timet_to_str_with_zone (qa->instance->occur_start, current_zone, datetime_is_date_only 
(comp, DATETIME_CHECK_DTSTART));
        time_str = calculate_time (qa->instance->occur_start, qa->instance->occur_end);
 
        str = g_strdup_printf (
@@ -1956,7 +1953,6 @@ popup_notification (time_t trigger,
        g_clear_error (&error);
        g_free (alarm_summary);
        g_free (start_str);
-       g_free (end_str);
        g_free (alarm_str);
        g_free (time_str);
        g_free (str);
diff --git a/calendar/alarm-notify/util.c b/calendar/alarm-notify/util.c
index 0565bf7..a50b5b3 100644
--- a/calendar/alarm-notify/util.c
+++ b/calendar/alarm-notify/util.c
@@ -26,18 +26,42 @@
 #endif
 
 #include <glib/gi18n.h>
+#include "e-util/e-util.h"
 
 #include "config-data.h"
 #include "util.h"
 
+gboolean
+datetime_is_date_only (ECalComponent *comp,
+                      gboolean datetime_check)
+{
+       ECalComponentDateTime dt;
+       gboolean is_date_only;
+
+       g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
+
+       dt.value = NULL;
+
+       if (datetime_check == DATETIME_CHECK_DTSTART)
+               e_cal_component_get_dtstart (comp, &dt);
+       else
+               e_cal_component_get_dtend (comp, &dt);
+
+       is_date_only = dt.value && dt.value->is_date;
+
+       e_cal_component_free_datetime (&dt);
+
+       return is_date_only;
+}
+
 /* Converts a time_t to a string, relative to the specified timezone */
 gchar *
 timet_to_str_with_zone (time_t t,
-                        icaltimezone *zone)
+                        icaltimezone *zone,
+                       gboolean date_only)
 {
        struct icaltimetype itt;
        struct tm tm;
-       gchar buf[256];
 
        if (t == -1)
                return g_strdup (_("invalid time"));
@@ -45,9 +69,7 @@ timet_to_str_with_zone (time_t t,
        itt = icaltime_from_timet_with_zone (t, FALSE, zone);
        tm = icaltimetype_to_tm (&itt);
 
-       e_time_format_date_and_time (&tm, config_data_get_24_hour_format (),
-                                    FALSE, FALSE, buf, sizeof (buf));
-       return g_strdup (buf);
+       return e_datetime_format_format_tm ("calendar", "table", date_only ? DTFormatKindDate : 
DTFormatKindDateTime, &tm);
 }
 
 gchar *
@@ -57,11 +79,19 @@ calculate_time (time_t start,
        time_t difference = end - start;
        gchar *str;
        gint   hours, minutes;
-       gchar *times[4];
+       gchar *times[5];
        gchar *joined;
        gint   i;
 
        i = 0;
+       if (difference >= 24 * 3600) {
+               gint days;
+
+               days = difference / (24 * 3600);
+               difference %= (24 * 3600);
+
+               times[i++] = g_strdup_printf (ngettext ("%d day", "%d days", days), days);
+       }
        if (difference >= 3600) {
                hours = difference / 3600;
                difference %= 3600;
diff --git a/calendar/alarm-notify/util.h b/calendar/alarm-notify/util.h
index 56d2b78..4bcde09 100644
--- a/calendar/alarm-notify/util.h
+++ b/calendar/alarm-notify/util.h
@@ -27,6 +27,10 @@
 
 #include <libecal/libecal.h>
 
-gchar *timet_to_str_with_zone (time_t t, icaltimezone *zone);
+#define DATETIME_CHECK_DTSTART TRUE
+#define DATETIME_CHECK_DTEND FALSE
+
+gboolean datetime_is_date_only (ECalComponent *comp, gboolean datetime_check);
+gchar *timet_to_str_with_zone (time_t t, icaltimezone *zone, gboolean date_only);
 gchar *calculate_time (time_t start, time_t end);
 #endif


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