[evolution] Bug 788904 - Show extra Google attendee info in Calendar and itip messages



commit 25fe8a4b8b4a0ae27b21e9c662dc40b5bca6f177
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jan 29 10:49:46 2018 +0100

    Bug 788904 - Show extra Google attendee info in Calendar and itip messages

 po/POTFILES.in                         |    1 +
 src/calendar/gui/comp-util.c           |  111 ++++++++++++++++++++++
 src/calendar/gui/comp-util.h           |    6 +-
 src/calendar/gui/e-calendar-view.c     |   11 ++
 src/calendar/gui/e-task-table.c        |   12 +++
 src/modules/itip-formatter/itip-view.c |  157 +++++++++++++++++++++++++++++++-
 6 files changed, 293 insertions(+), 5 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c2dbc29..6ac8212 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -66,6 +66,7 @@ src/calendar/alarm-notify/alarm-queue.c
 src/calendar/alarm-notify/util.c
 src/calendar/calendar.error.xml
 src/calendar/gui/caltypes.xml.in
+src/calendar/gui/comp-util.c
 src/calendar/gui/ea-cal-view.c
 src/calendar/gui/ea-cal-view-event.c
 src/calendar/gui/ea-day-view.c
diff --git a/src/calendar/gui/comp-util.c b/src/calendar/gui/comp-util.c
index 299364a..e66eaf3 100644
--- a/src/calendar/gui/comp-util.c
+++ b/src/calendar/gui/comp-util.c
@@ -23,12 +23,15 @@
 
 #include "evolution-config.h"
 
+#include <glib/gi18n-lib.h>
+
 #include <string.h>
 #include <time.h>
 
 #include "calendar-config.h"
 #include "comp-util.h"
 #include "e-calendar-view.h"
+#include "itip-utils.h"
 
 #include "shell/e-shell-window.h"
 #include "shell/e-shell-view.h"
@@ -1440,3 +1443,111 @@ cal_comp_util_set_added_attendees_mails (ECalComponent *comp,
 
        g_object_set_data_full (G_OBJECT (comp), "new-attendees", emails, free_slist_strs);
 }
+
+const gchar *
+cal_comp_util_find_parameter_xvalue (icalproperty *prop,
+                                    const gchar *name)
+{
+       icalparameter *param;
+
+       if (!prop || !name || !*name)
+               return NULL;
+
+       for (param = icalproperty_get_first_parameter (prop, ICAL_X_PARAMETER);
+            param;
+            param = icalproperty_get_next_parameter (prop, ICAL_X_PARAMETER)) {
+               const gchar *xname = icalparameter_get_xname (param);
+
+               if (xname && g_ascii_strcasecmp (xname, name) == 0)
+                       return icalparameter_get_xvalue (param);
+       }
+
+       return NULL;
+}
+
+gchar *
+cal_comp_util_get_attendee_comments (icalcomponent *icalcomp)
+{
+       GString *comments = NULL;
+       icalproperty *prop;
+
+       g_return_val_if_fail (icalcomp != NULL, NULL);
+
+       for (prop = icalcomponent_get_first_property (icalcomp, ICAL_ATTENDEE_PROPERTY);
+            prop != NULL;
+            prop = icalcomponent_get_next_property (icalcomp, ICAL_ATTENDEE_PROPERTY)) {
+               gchar *guests_str = NULL;
+               guint32 num_guests = 0;
+               const gchar *value;
+
+               value = cal_comp_util_find_parameter_xvalue (prop, "X-NUM-GUESTS");
+               if (value && *value)
+                       num_guests = atoi (value);
+
+               value = cal_comp_util_find_parameter_xvalue (prop, "X-RESPONSE-COMMENT");
+
+               if (num_guests)
+                       guests_str = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "with one guest", "with 
%d guests", num_guests), num_guests);
+
+               if (guests_str || (value && *value)) {
+                       const gchar *email = icalproperty_get_attendee (prop);
+                       const gchar *cn = NULL;
+                       icalparameter *cnparam;
+
+                       cnparam = icalproperty_get_first_parameter (prop, ICAL_CN_PARAMETER);
+                       if (cnparam) {
+                               cn = icalparameter_get_cn (cnparam);
+                               if (!cn || !*cn)
+                                       cn = NULL;
+                       }
+
+                       email = itip_strip_mailto (email);
+
+                       if ((email && *email) || (cn && *cn)) {
+                               if (!comments)
+                                       comments = g_string_new ("");
+                               else
+                                       g_string_append (comments, "\n    ");
+
+                               if (cn && *cn) {
+                                       g_string_append (comments, cn);
+
+                                       if (g_strcmp0 (email, cn) == 0)
+                                               email = NULL;
+                               }
+
+                               if (email && *email) {
+                                       if (cn && *cn)
+                                               g_string_append_printf (comments, " <%s>", email);
+                                       else
+                                               g_string_append (comments, email);
+                               }
+
+                               g_string_append (comments, ": ");
+
+                               if (guests_str) {
+                                       g_string_append (comments, guests_str);
+
+                                       if (value && *value)
+                                               g_string_append (comments, "; ");
+                               }
+
+                               if (value && *value)
+                                       g_string_append (comments, value);
+                       }
+               }
+
+               g_free (guests_str);
+       }
+
+       if (comments) {
+               gchar *str;
+
+               str = g_strdup_printf (_("Comments: %s"), comments->str);
+               g_string_free (comments, TRUE);
+
+               return str;
+       }
+
+       return NULL;
+}
diff --git a/src/calendar/gui/comp-util.h b/src/calendar/gui/comp-util.h
index 6871c72..a0cac72 100644
--- a/src/calendar/gui/comp-util.h
+++ b/src/calendar/gui/comp-util.h
@@ -139,5 +139,9 @@ void                cal_comp_util_copy_new_attendees
 void           cal_comp_util_set_added_attendees_mails
                                                (ECalComponent *comp,
                                                 GSList *emails);
-
+const gchar *  cal_comp_util_find_parameter_xvalue
+                                               (icalproperty *prop,
+                                                const gchar *name);
+gchar *                cal_comp_util_get_attendee_comments
+                                               (icalcomponent *icalcomp);
 #endif
diff --git a/src/calendar/gui/e-calendar-view.c b/src/calendar/gui/e-calendar-view.c
index 8b92a7c..00c90a2 100644
--- a/src/calendar/gui/e-calendar-view.c
+++ b/src/calendar/gui/e-calendar-view.c
@@ -1929,6 +1929,17 @@ e_calendar_view_get_tooltips (const ECalendarViewEventData *data)
                g_free (tmp);
        }
 
+       tmp = cal_comp_util_get_attendee_comments (e_cal_component_get_icalcomponent (newcomp));
+       if (tmp) {
+               hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+               gtk_box_pack_start ((GtkBox *) hbox, gtk_label_new (tmp), FALSE, FALSE, 0);
+               ebox = gtk_event_box_new ();
+               gtk_container_add ((GtkContainer *) ebox, hbox);
+               gtk_box_pack_start ((GtkBox *) box, ebox, FALSE, FALSE, 0);
+
+               g_free (tmp);
+       }
+
        pevent->tooltip = gtk_window_new (GTK_WINDOW_POPUP);
 
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (data->cal_view));
diff --git a/src/calendar/gui/e-task-table.c b/src/calendar/gui/e-task-table.c
index 0473840..c442f95 100644
--- a/src/calendar/gui/e-task-table.c
+++ b/src/calendar/gui/e-task-table.c
@@ -36,6 +36,7 @@
 #include <gdk/gdkkeysyms.h>
 
 #include "calendar-config.h"
+#include "comp-util.h"
 #include "e-cal-dialogs.h"
 #include "e-cal-model-tasks.h"
 #include "e-cal-ops.h"
@@ -912,6 +913,17 @@ task_table_query_tooltip (GtkWidget *widget,
                gtk_widget_override_color (l, GTK_STATE_FLAG_NORMAL, &norm_text);
        }
 
+       tmp = cal_comp_util_get_attendee_comments (e_cal_component_get_icalcomponent (new_comp));
+       if (tmp) {
+               l = gtk_label_new (tmp);
+               gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
+               gtk_box_pack_start (GTK_BOX (w), l, FALSE, FALSE, 0);
+               gtk_widget_override_color (l, GTK_STATE_FLAG_NORMAL, &norm_text);
+
+               g_free (tmp);
+               tmp = NULL;
+       }
+
        tmp2 = g_string_new ("");
        e_cal_component_get_description_list (new_comp, &desc);
        for (len = 0, p = desc; p != NULL; p = p->next) {
diff --git a/src/modules/itip-formatter/itip-view.c b/src/modules/itip-formatter/itip-view.c
index d18c545..e27af2e 100644
--- a/src/modules/itip-formatter/itip-view.c
+++ b/src/modules/itip-formatter/itip-view.c
@@ -28,6 +28,7 @@
 #include <shell/e-shell.h>
 #include <shell/e-shell-utils.h>
 
+#include <calendar/gui/comp-util.h>
 #include <calendar/gui/itip-utils.h>
 
 #include <mail/em-config.h>
@@ -1055,8 +1056,10 @@ append_text_table_row (GString *buffer,
 
                g_string_append_printf (
                        buffer,
-                       "<tr id=\"%s\" %s><th>%s</th><td>%s</td></tr>\n",
-                       id, (value && *value) ? "" : "hidden=\"\"", label, value ? value : "");
+                       "<tr id=\"%s\" %s><th%s>%s</th><td>%s</td></tr>\n",
+                       id, (value && *value) ? "" : "hidden=\"\"",
+                       g_strcmp0 (id, TABLE_ROW_COMMENT) == 0 ? " style=\"vertical-align: top;\"" : "",
+                       label, value ? value : "");
 
        } else {
 
@@ -1809,9 +1812,9 @@ itip_view_write_for_printing (ItipView *view,
                        "<div id=\"" TABLE_ROW_DESCRIPTION "\" "
                        "class=\"itip description\" %s>%s</div>\n",
                        view->priv->description ? "" : "hidden=\"\"", view->priv->description);
-
-               g_string_append (buffer, "</div>");
        }
+
+       g_string_append (buffer, "</div>");
 }
 
 static void
@@ -2306,6 +2309,150 @@ itip_view_get_comment (ItipView *view)
        return view->priv->comment;
 }
 
+static gchar *
+itip_plain_text_to_html (const gchar *plain)
+{
+       return camel_text_to_html (
+               plain,
+               CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
+               CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
+               CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES,
+               0);
+}
+
+static void
+itip_view_extract_attendee_info (ItipView *view)
+{
+       icalproperty *prop;
+       icalcomponent *ical_comp;
+       gint num_attendees;
+       const gchar *top_comment;
+       GString *new_comment = NULL;
+
+       g_return_if_fail (ITIP_IS_VIEW (view));
+
+       if (!view->priv->comp)
+               return;
+
+       ical_comp = e_cal_component_get_icalcomponent (view->priv->comp);
+       if (!ical_comp)
+               return;
+
+       num_attendees = icalcomponent_count_properties (ical_comp, ICAL_ATTENDEE_PROPERTY);
+       if (num_attendees <= 0)
+               return;
+
+       top_comment = icalcomponent_get_comment (ical_comp);
+
+       for (prop = icalcomponent_get_first_property (ical_comp, ICAL_ATTENDEE_PROPERTY);
+            prop != NULL;
+            prop = icalcomponent_get_next_property (ical_comp, ICAL_ATTENDEE_PROPERTY)) {
+               gchar *guests_str = NULL;
+               guint32 num_guests = 0;
+               const gchar *value;
+
+               value = cal_comp_util_find_parameter_xvalue (prop, "X-NUM-GUESTS");
+               if (value && *value)
+                       num_guests = atoi (value);
+
+               value = cal_comp_util_find_parameter_xvalue (prop, "X-RESPONSE-COMMENT");
+
+               if (value && *value && num_attendees == 1 &&
+                   g_strcmp0 (value, top_comment) == 0)
+                       value = NULL;
+
+               if (num_guests)
+                       guests_str = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "with one guest", "with 
%d guests", num_guests), num_guests);
+
+               if (num_attendees == 1) {
+                       if (!value)
+                               value = top_comment;
+
+                       if (value && *value) {
+                               gchar *html;
+
+                               if (num_guests) {
+                                       gchar *plain;
+
+                                       plain = g_strconcat (guests_str, "; ", value, NULL);
+                                       html = itip_plain_text_to_html (plain);
+                                       g_free (plain);
+                               } else {
+                                       html = itip_plain_text_to_html (value);
+                               }
+
+                               itip_view_set_comment (view, html);
+
+                               g_free (html);
+                       } else if (guests_str) {
+                               gchar *html;
+
+                               html = itip_plain_text_to_html (guests_str);
+                               itip_view_set_comment (view, html);
+                               g_free (html);
+                       }
+               } else if (guests_str || (value && *value)) {
+                       const gchar *email = icalproperty_get_attendee (prop);
+                       const gchar *cn = NULL;
+                       icalparameter *cnparam;
+
+                       cnparam = icalproperty_get_first_parameter (prop, ICAL_CN_PARAMETER);
+                       if (cnparam) {
+                               cn = icalparameter_get_cn (cnparam);
+                               if (!cn || !*cn)
+                                       cn = NULL;
+                       }
+
+                       email = itip_strip_mailto (email);
+
+                       if ((email && *email) || (cn && *cn)) {
+                               if (!new_comment)
+                                       new_comment = g_string_new ("");
+                               else
+                                       g_string_append_c (new_comment, '\n');
+
+                               if (cn && *cn) {
+                                       g_string_append (new_comment, cn);
+
+                                       if (g_strcmp0 (email, cn) == 0)
+                                               email = NULL;
+                               }
+
+                               if (email && *email) {
+                                       if (cn && *cn)
+                                               g_string_append_printf (new_comment, " <%s>", email);
+                                       else
+                                               g_string_append (new_comment, email);
+                               }
+
+                               g_string_append (new_comment, ": ");
+
+                               if (guests_str) {
+                                       g_string_append (new_comment, guests_str);
+
+                                       if (value && *value)
+                                               g_string_append (new_comment, "; ");
+                               }
+
+                               if (value && *value)
+                                       g_string_append (new_comment, value);
+                       }
+               }
+
+               g_free (guests_str);
+       }
+
+       if (new_comment) {
+               gchar *html;
+
+               html = itip_plain_text_to_html (new_comment->str);
+               itip_view_set_comment (view, html);
+               g_free (html);
+
+               g_string_free (new_comment, TRUE);
+       }
+}
+
 void
 itip_view_set_description (ItipView *view,
                            const gchar *description)
@@ -6184,6 +6331,8 @@ itip_view_init_view (ItipView *view)
                e_cal_component_free_text_list (list);
        }
 
+       itip_view_extract_attendee_info (view);
+
        e_cal_component_get_description_list (view->priv->comp, &list);
        for (l = list; l; l = l->next) {
                ECalComponentText *text = l->data;


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