[balsa/wip/gtk4: 318/351] Display time stamps of date-only iCalendar events



commit 5ed5d82b71e87839645f3fa5fae7d9114ffe178d
Author: Albrecht Dreß <albrecht dress arcor de>
Date:   Tue May 1 15:59:48 2018 -0400

    Display time stamps of date-only iCalendar events
    
    Display time stamps of date-only RFC 5545 iCalendar events
    
    Signed-off-by: Peter Bloomfield <PeterBloomfield bellsouth net>

 ChangeLog                         |   14 +++++++++++++
 libbalsa/rfc2445.c                |   40 +++++++++++++++++++++++++++++++-----
 libbalsa/rfc2445.h                |    4 ++-
 src/balsa-mime-widget-vcalendar.c |   15 ++++++++++---
 4 files changed, 62 insertions(+), 11 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ddcba9f..402d8ca 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2018-05-01  Albrecht Dreß <albrecht dress arcor de>
+
+       Display time stamps of date-only RFC 5545 iCalendar events
+
+I noticed that “VALUE=DATE” time stamps (date only, without time) in RFC 5545 iCalendar parts (MIME type 
text/calendar) are not displayed.
+
+The attached trivial patch add parsing, displaying and printing such values  As to simplify life, the 
date-only values are printed using the “%x” conversion specification, instead of extracting the date part 
from balsa_app.date_string.
+
+       * libbalsa/rfc2445.c (libbalsa_vcal_new_from_body),
+       (date_time_2445_to_time_t):
+       * libbalsa/rfc2445.h:
+       * src/balsa-mime-widget-vcalendar.c (balsa_vevent_widget):
+       * src/balsa-print-object-text.c (balsa_print_object_text_calendar):
+
 2018-04-11  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Fix the "scroll on click" issue
diff --git a/libbalsa/rfc2445.c b/libbalsa/rfc2445.c
index e278e8b..9810581 100644
--- a/libbalsa/rfc2445.c
+++ b/libbalsa/rfc2445.c
@@ -62,7 +62,7 @@ static LibBalsaAddress *cal_address_2445_to_lbaddress(const gchar * uri,
                                                      is_organizer);
 
 /* conversion helpers */
-static time_t date_time_2445_to_time_t(const gchar * date_time);
+static time_t date_time_2445_to_time_t(const gchar *date_time, const gchar *modifier, gboolean *date_only);
 static gchar *time_t_to_date_time_2445(time_t ttime);
 static gchar *text_2445_unescape(const gchar * text);
 static gchar *text_2445_escape(const gchar * text);
@@ -150,7 +150,9 @@ struct _LibBalsaVEvent {
     GList *attendee;
     time_t stamp;
     time_t start;
+    gboolean start_date_only;
     time_t end;
+    gboolean end_date_only;
     gchar *uid;
     gchar *summary;
     gchar *location;
@@ -342,11 +344,11 @@ libbalsa_vcal_new_from_body(LibBalsaMessageBody * body)
                 in_embedded = TRUE;
             else if (!in_embedded) {
                 if (!g_ascii_strcasecmp(entry[0], "DTSTART"))
-                    event->start = date_time_2445_to_time_t(value);
+                    event->start = date_time_2445_to_time_t(value, entry[1], &event->start_date_only);
                 else if (!g_ascii_strcasecmp(entry[0], "DTEND"))
-                    event->end = date_time_2445_to_time_t(value);
+                    event->end = date_time_2445_to_time_t(value, entry[1], &event->end_date_only);
                 else if (!g_ascii_strcasecmp(entry[0], "DTSTAMP"))
-                    event->stamp = date_time_2445_to_time_t(value);
+                    event->stamp = date_time_2445_to_time_t(value, entry[1], NULL);
                 else if (!g_ascii_strcasecmp(entry[0], "UID"))
                     STR_REPL_2445_TXT(event->uid, value);
                 else if (!g_ascii_strcasecmp(entry[0], "SUMMARY"))
@@ -504,10 +506,10 @@ libbalsa_vevent_reply(const LibBalsaVEvent * event, const gchar * sender,
 /* convert a rfc 2445 time string into a time_t value */
 // FIXME - what about entries containing a TZID?
 static time_t
-date_time_2445_to_time_t(const gchar *date_time)
+date_time_2445_to_time_t(const gchar *date_time, const gchar *modifier, gboolean *date_only)
 {
     gint len;
-    time_t the_time = (time_t) (-1);;
+    time_t the_time = (time_t) (-1);
 
     g_return_val_if_fail(date_time != NULL, (time_t) (-1));
     len = strlen(date_time);
@@ -520,7 +522,21 @@ date_time_2445_to_time_t(const gchar *date_time)
         /* the rfc2445 date-time is a special case of an iso8901 date/time value... */
         if (g_time_val_from_iso8601(date_time, &timeval)) {
                the_time = timeval.tv_sec;
+               if (date_only != NULL) {
+                       *date_only = FALSE;
+               }
         }
+    } else if ((modifier!= NULL) && (g_ascii_strcasecmp(modifier, "VALUE=DATE") == 0) && (len == 8)) {
+       struct tm tm;
+
+       /* date only (yyyymmdd) */
+       memset(&tm, 0, sizeof(tm));
+       if (strptime(date_time, "%Y%m%d", &tm) != NULL) {
+               the_time = mktime(&tm);
+               if (date_only != NULL) {
+                       *date_only = TRUE;
+               }
+       }
     }
 
     return the_time;
@@ -790,12 +806,24 @@ libbalsa_vevent_get_start(LibBalsaVEvent *vevent)
     return vevent->start;
 }
 
+gboolean
+libbalsa_vevent_get_start_date_only(LibBalsaVEvent *vevent)
+{
+    return vevent->start_date_only;
+}
+
 time_t
 libbalsa_vevent_get_end(LibBalsaVEvent *vevent)
 {
     return vevent->end;
 }
 
+gboolean
+libbalsa_vevent_get_end_date_only(LibBalsaVEvent *vevent)
+{
+    return vevent->end_date_only;
+}
+
 const gchar *
 libbalsa_vevent_get_location(LibBalsaVEvent *vevent)
 {
diff --git a/libbalsa/rfc2445.h b/libbalsa/rfc2445.h
index a3aa726..dd1242e 100644
--- a/libbalsa/rfc2445.h
+++ b/libbalsa/rfc2445.h
@@ -1,7 +1,7 @@
 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
 /*
  * VCalendar (RFC 2445) stuff
- * Copyright (C) 2009 Albrecht Dre� <albrecht dress arcor de>
+ * Copyright (C) 2009 Albrecht Dreß <albrecht dress arcor de>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -95,7 +95,9 @@ GList             *libbalsa_vcal_get_vevent(LibBalsaVCal *vcal);
 const gchar       *libbalsa_vevent_get_summary(LibBalsaVEvent *vevent);
 LibBalsaAddress   *libbalsa_vevent_get_organizer(LibBalsaVEvent *vevent);
 time_t             libbalsa_vevent_get_start(LibBalsaVEvent *vevent);
+gboolean           libbalsa_vevent_get_start_date_only(LibBalsaVEvent *vevent);
 time_t             libbalsa_vevent_get_end(LibBalsaVEvent *vevent);
+gboolean           libbalsa_vevent_get_end_date_only(LibBalsaVEvent *vevent);
 const gchar       *libbalsa_vevent_get_location(LibBalsaVEvent *vevent);
 GList             *libbalsa_vevent_get_attendee(LibBalsaVEvent *vevent);
 const gchar       *libbalsa_vevent_get_description(LibBalsaVEvent *vevent);
diff --git a/src/balsa-mime-widget-vcalendar.c b/src/balsa-mime-widget-vcalendar.c
index 287aada..946f3d6 100644
--- a/src/balsa-mime-widget-vcalendar.c
+++ b/src/balsa-mime-widget-vcalendar.c
@@ -121,11 +121,12 @@ balsa_mime_widget_new_vcalendar(BalsaMessage * bm,
         }                                                               \
     } while (0)
 
-#define GRID_ATTACH_DATE(g,date,label)                                  \
+#define GRID_ATTACH_DATE(g,date,date_only,label)                        \
     do {                                                                \
         if (date != (time_t) -1) {                                      \
             gchar * _dstr =                                             \
-                libbalsa_date_to_utf8(date, balsa_app.date_string);     \
+                libbalsa_date_to_utf8(date,                                                    \
+                       date_only ? "%x" : balsa_app.date_string);              \
             GRID_ATTACH(g, _dstr, label);                               \
             g_free(_dstr);                                              \
         }                                                               \
@@ -173,8 +174,14 @@ balsa_vevent_widget(LibBalsaVEvent * event, gboolean may_reply,
     gtk_grid_set_column_spacing(grid, 12);
     GRID_ATTACH(grid, libbalsa_vevent_get_summary(event), _("Summary:"));
     GRID_ATTACH_ADDRESS(grid, libbalsa_vevent_get_organizer(event), _("Organizer:"));
-    GRID_ATTACH_DATE(grid, libbalsa_vevent_get_start(event), _("Start:"));
-    GRID_ATTACH_DATE(grid, libbalsa_vevent_get_end(event), _("End:"));
+    GRID_ATTACH_DATE(grid,
+                     libbalsa_vevent_get_start(event),
+                     libbalsa_vevent_get_start_date_only(event),
+                     _("Start:"));
+    GRID_ATTACH_DATE(grid,
+                     libbalsa_vevent_get_end(event),
+                     libbalsa_vevent_get_end_date_only(event),
+                     _("End:"));
     GRID_ATTACH(grid, libbalsa_vevent_get_location(event), _("Location:"));
     if (libbalsa_vevent_get_attendee(event)) {
        GList *att;


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