[evolution] Calendar: Linkify URL and Location in import component preview



commit 74f4db1551b3577f152e797eea1f4473d30f21dc
Author: Milan Crha <mcrha redhat com>
Date:   Fri Nov 6 12:42:34 2020 +0100

    Calendar: Linkify URL and Location in import component preview
    
    Both the URL and Location can contain valid URL references, thus linkify
    them, if they look like URL, to make it easier to access the URL.

 src/calendar/importers/icalendar-importer.c | 23 +++++++++++++++++--
 src/e-util/e-web-view-preview.c             | 34 +++++++++++++++++++++++------
 src/e-util/e-web-view-preview.h             |  4 ++++
 3 files changed, 52 insertions(+), 9 deletions(-)
---
diff --git a/src/calendar/importers/icalendar-importer.c b/src/calendar/importers/icalendar-importer.c
index 91ddc704ed..97e26c9301 100644
--- a/src/calendar/importers/icalendar-importer.c
+++ b/src/calendar/importers/icalendar-importer.c
@@ -1234,6 +1234,25 @@ strip_mailto (const gchar *str)
        return str + 7;
 }
 
+static void
+add_url_section (EWebViewPreview *preview,
+                const gchar *section,
+                const gchar *raw_value)
+{
+       gchar *html;
+
+       g_return_if_fail (raw_value != NULL);
+
+       html = camel_text_to_html (raw_value, CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | 
CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0);
+
+       if (html) {
+               e_web_view_preview_add_section_html (preview, section, html);
+               g_free (html);
+       } else {
+               e_web_view_preview_add_section (preview, section, raw_value);
+       }
+}
+
 static void
 preview_comp (EWebViewPreview *preview,
               ECalComponent *comp)
@@ -1320,7 +1339,7 @@ preview_comp (EWebViewPreview *preview,
        tmp = e_cal_component_get_location (comp);
        if (tmp && *tmp)
                /* Translators: Appointment's location */
-               e_web_view_preview_add_section (preview, C_("iCalImp", "Location"), tmp);
+               add_url_section (preview, C_("iCalImp", "Location"), tmp);
        g_free (tmp);
 
        dt = e_cal_component_get_dtstart (comp);
@@ -1390,7 +1409,7 @@ preview_comp (EWebViewPreview *preview,
        tmp = e_cal_component_get_url (comp);
        if (tmp && *tmp)
                /* Translators: Appointment's URL */
-               e_web_view_preview_add_section (preview, C_("iCalImp", "URL"), tmp);
+               add_url_section (preview, C_("iCalImp", "URL"), tmp);
        g_free (tmp);
 
        if (e_cal_component_has_organizer (comp)) {
diff --git a/src/e-util/e-web-view-preview.c b/src/e-util/e-web-view-preview.c
index 9ddeba0d04..6d4d426909 100644
--- a/src/e-util/e-web-view-preview.c
+++ b/src/e-util/e-web-view-preview.c
@@ -462,24 +462,44 @@ e_web_view_preview_add_section (EWebViewPreview *preview,
                                 const gchar *section,
                                 const gchar *value)
 {
-       gchar *escaped_section = NULL, *escaped_value;
+       gchar *escaped_value;
 
        g_return_if_fail (E_IS_WEB_VIEW_PREVIEW (preview));
        g_return_if_fail (preview->priv->updating_content != NULL);
        g_return_if_fail (value != NULL);
 
+       escaped_value = web_view_preview_escape_text (preview, value);
+       if (escaped_value)
+               value = escaped_value;
+
+       e_web_view_preview_add_section_html (preview, section, value);
+
+       g_free (escaped_value);
+}
+
+/* section can be NULL, but html cannot */
+void
+e_web_view_preview_add_section_html (EWebViewPreview *preview,
+                                    const gchar *section,
+                                    const gchar *html)
+{
+       gchar *escaped_section = NULL;
+
+       g_return_if_fail (E_IS_WEB_VIEW_PREVIEW (preview));
+       g_return_if_fail (preview->priv->updating_content != NULL);
+       g_return_if_fail (html != NULL);
+
        if (section) {
                escaped_section = web_view_preview_escape_text (preview, section);
                if (escaped_section)
                        section = escaped_section;
        }
 
-       escaped_value = web_view_preview_escape_text (preview, value);
-       if (escaped_value)
-               value = escaped_value;
-
-       g_string_append_printf (preview->priv->updating_content, "<TR><TD width=\"10%%\" valign=\"top\" 
nowrap><FONT size=\"3\"><B>%s</B></FONT></TD><TD width=\"90%%\"><FONT size=\"3\">%s</FONT></TD></TR>", 
section ? section : "", value);
+       g_string_append_printf (preview->priv->updating_content,
+               "<TR>"
+                       "<TD width=\"10%%\" valign=\"top\" nowrap><FONT size=\"3\"><B>%s</B></FONT></TD>"
+                       "<TD width=\"90%%\"><FONT size=\"3\">%s</FONT></TD>"
+               "</TR>", section ? section : "", html);
 
        g_free (escaped_section);
-       g_free (escaped_value);
 }
diff --git a/src/e-util/e-web-view-preview.h b/src/e-util/e-web-view-preview.h
index 4e8c67b780..9d58df4947 100644
--- a/src/e-util/e-web-view-preview.h
+++ b/src/e-util/e-web-view-preview.h
@@ -108,6 +108,10 @@ void               e_web_view_preview_add_empty_line
 void           e_web_view_preview_add_section  (EWebViewPreview *preview,
                                                 const gchar *section,
                                                 const gchar *value);
+void           e_web_view_preview_add_section_html
+                                               (EWebViewPreview *preview,
+                                                const gchar *section,
+                                                const gchar *html);
 
 G_END_DECLS
 


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