[evolution] Bug #729084 - Use tel: URI instead of callto: for phone numbers



commit e0e498c644a485aee0029805532622f0a711ecfc
Author: Milan Crha <mcrha redhat com>
Date:   Wed Apr 30 16:05:31 2014 +0200

    Bug #729084 - Use tel: URI instead of callto: for phone numbers
    
    This change does a bit more, actually:
    - learn the code of "tel" URI, being handler similar to "sip", "callto", "h323"
    - generate tel: URIs for phone numbers, but only if the leading character of the
      phone number is a plus ("+") sign
    - always remove spaces in href part in the e_text_to_html() when
      E_TEXT_TO_HTML_URL_IS_WHOLE_TEXT flag is set

 addressbook/gui/widgets/eab-contact-formatter.c |   23 ++++++++++++++---------
 e-util/e-buffer-tagger.c                        |    2 +-
 e-util/e-html-utils.c                           |   15 ++++++++++++++-
 e-util/e-web-view-gtkhtml.c                     |    9 ++++-----
 e-util/e-web-view.c                             |    9 ++++-----
 5 files changed, 37 insertions(+), 21 deletions(-)
---
diff --git a/addressbook/gui/widgets/eab-contact-formatter.c b/addressbook/gui/widgets/eab-contact-formatter.c
index 5935145..7bfa468 100644
--- a/addressbook/gui/widgets/eab-contact-formatter.c
+++ b/addressbook/gui/widgets/eab-contact-formatter.c
@@ -64,7 +64,7 @@
 struct _EABContactFormatterPrivate {
        EABContactDisplayMode mode;
        gboolean render_maps;
-       gboolean supports_callto;
+       gboolean supports_tel;
        gboolean supports_sip;
 };
 
@@ -88,7 +88,7 @@ G_DEFINE_TYPE (
        eab_contact_formatter,
        G_TYPE_OBJECT);
 
-#define E_CREATE_CALLTO_URL    (E_TEXT_TO_HTML_LAST_FLAG << 0)
+#define E_CREATE_TEL_URL       (E_TEXT_TO_HTML_LAST_FLAG << 0)
 #define E_CREATE_SIP_URL       (E_TEXT_TO_HTML_LAST_FLAG << 1)
 
 static gboolean
@@ -303,8 +303,13 @@ maybe_create_url (const gchar *str,
 
        g_return_val_if_fail (str != NULL, NULL);
 
-       if ((html_flags & E_CREATE_CALLTO_URL) != 0) {
-               url = "callto:";
+       if ((html_flags & E_CREATE_TEL_URL) != 0) {
+               /* RFC 3966 requires either the phone number begins with '+',
+                  or the URL contains a 'phone-context' parameter, but that
+                  also requires changing phone number for some countries, thus
+                  rather mandate the '+' at the beginning. */
+               if (*str == '+')
+                       url = "tel:";
        } else if ((html_flags & E_CREATE_SIP_URL) != 0) {
                url = "sip:";
        }
@@ -798,11 +803,11 @@ render_work_column (EABContactFormatter *formatter,
        GString *accum = g_string_new ("");
        guint32 phone_flags = 0, sip_flags = 0;
 
-       if (formatter->priv->supports_callto)
+       if (formatter->priv->supports_tel)
                phone_flags = E_TEXT_TO_HTML_CONVERT_URLS |
                              E_TEXT_TO_HTML_HIDE_URL_SCHEME |
                              E_TEXT_TO_HTML_URL_IS_WHOLE_TEXT |
-                             E_CREATE_CALLTO_URL;
+                             E_CREATE_TEL_URL;
 
        if (formatter->priv->supports_sip)
                sip_flags = E_TEXT_TO_HTML_CONVERT_URLS |
@@ -847,11 +852,11 @@ render_personal_column (EABContactFormatter *formatter,
        GString *accum = g_string_new ("");
        guint32 phone_flags = 0, sip_flags = 0;
 
-       if (formatter->priv->supports_callto)
+       if (formatter->priv->supports_tel)
                phone_flags = E_TEXT_TO_HTML_CONVERT_URLS |
                              E_TEXT_TO_HTML_HIDE_URL_SCHEME |
                              E_TEXT_TO_HTML_URL_IS_WHOLE_TEXT |
-                             E_CREATE_CALLTO_URL;
+                             E_CREATE_TEL_URL;
 
        if (formatter->priv->supports_sip)
                sip_flags = E_TEXT_TO_HTML_CONVERT_URLS |
@@ -1307,7 +1312,7 @@ eab_contact_formatter_init (EABContactFormatter *formatter)
 
        formatter->priv->mode = EAB_CONTACT_DISPLAY_RENDER_NORMAL;
        formatter->priv->render_maps = FALSE;
-       formatter->priv->supports_callto = eab_contact_formatter_scheme_supported ("callto");
+       formatter->priv->supports_tel = eab_contact_formatter_scheme_supported ("tel");
        formatter->priv->supports_sip = eab_contact_formatter_scheme_supported ("sip");
 }
 
diff --git a/e-util/e-buffer-tagger.c b/e-util/e-buffer-tagger.c
index 7866c88..c3c923a 100644
--- a/e-util/e-buffer-tagger.c
+++ b/e-util/e-buffer-tagger.c
@@ -56,7 +56,7 @@ typedef struct _MagicInsertMatch MagicInsertMatch;
 static MagicInsertMatch mim[] = {
        /* prefixed expressions */
        { 
"(news|telnet|nntp|file|http|ftp|sftp|https|webcal)://([-a-z0-9]+(:[-a-z0-9]+)?@)?[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(([.])?/[-a-z0-9_$.+!*(),;:@%&=?/~#']*[^]'.}>\\)
 \n\r\t,?!;:\"]?)?", NULL, NULL },
-       { 
"(sip|h323|callto):([-_a-z0-9.'\\+]+(:[0-9]{1,5})?(/[-_a-z0-9.']+)?)(@([-_a-z0-9.%=?]+|([0-9]{1,3}.){3}[0-9]{1,3})?)?(:[0-9]{1,5})?",
 NULL, NULL },
+       { 
"(sip|h323|callto|tel):([-_a-z0-9.'\\+]+(:[0-9]{1,5})?(/[-_a-z0-9.']+)?)(@([-_a-z0-9.%=?]+|([0-9]{1,3}.){3}[0-9]{1,3})?)?(:[0-9]{1,5})?",
 NULL, NULL },
        { "mailto:[-_a-z0-9.'\\+]+ [-_a-z0-9 %=?]+", NULL, NULL },
        /* not prefixed expression */
        { "www\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(([.])?/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]'.}>\\) 
\n\r\t,?!;:\"]?)?", NULL, "http://"; },
diff --git a/e-util/e-html-utils.c b/e-util/e-html-utils.c
index 260e26b..9187b75 100644
--- a/e-util/e-html-utils.c
+++ b/e-util/e-html-utils.c
@@ -231,7 +231,7 @@ is_citation (const guchar *c,
  *     user will only see "www.example.com")
  *
  *   - E_TEXT_TO_HTML_URL_IS_WHOLE_TEXT: set when the whole @input text
- *     represents a URL
+ *     represents a URL; any spaces are removed in the href part.
  *
  * Returns: a newly-allocated string containing HTML
  **/
@@ -302,6 +302,7 @@ e_text_to_html_full (const gchar *input,
                            !g_ascii_strncasecmp ((gchar *) cur, "callto:", 7) ||
                            !g_ascii_strncasecmp ((gchar *) cur, "h323:", 5) ||
                            !g_ascii_strncasecmp ((gchar *) cur, "sip:", 4) ||
+                           !g_ascii_strncasecmp ((gchar *) cur, "tel:", 4) ||
                            !g_ascii_strncasecmp ((gchar *) cur, "webcal:", 7)) {
                                tmpurl = url_extract (&cur, TRUE, (flags & E_TEXT_TO_HTML_URL_IS_WHOLE_TEXT) 
!= 0);
                                if (tmpurl) {
@@ -335,6 +336,18 @@ e_text_to_html_full (const gchar *input,
                        }
 
                        if (tmpurl) {
+                               if ((flags & E_TEXT_TO_HTML_URL_IS_WHOLE_TEXT) != 0) {
+                                       /* also remove any spaces in refurl */
+                                       gchar *replaced, **split_url;
+
+                                       split_url = g_strsplit (refurl, " ", 0);
+                                       replaced = g_strjoinv ("", split_url);
+                                       g_strfreev (split_url);
+
+                                       g_free (refurl);
+                                       refurl = replaced;
+                               }
+
                                out = check_size (
                                        &buffer, &buffer_size, out,
                                        strlen (refurl) +
diff --git a/e-util/e-web-view-gtkhtml.c b/e-util/e-web-view-gtkhtml.c
index 5b6db0d..799240d 100644
--- a/e-util/e-web-view-gtkhtml.c
+++ b/e-util/e-web-view-gtkhtml.c
@@ -967,11 +967,10 @@ web_view_gtkhtml_hovering_over_link (EWebViewGtkHTML *web_view,
 
        if (g_str_has_prefix (uri, "mailto:";))
                format = _("Click to mail %s");
-       else if (g_str_has_prefix (uri, "callto:"))
-               format = _("Click to call %s");
-       else if (g_str_has_prefix (uri, "h323:"))
-               format = _("Click to call %s");
-       else if (g_str_has_prefix (uri, "sip:"))
+       else if (g_str_has_prefix (uri, "callto:") ||
+                g_str_has_prefix (uri, "h323:") ||
+                g_str_has_prefix (uri, "sip:") ||
+                g_str_has_prefix (uri, "tel:"))
                format = _("Click to call %s");
        else if (g_str_has_prefix (uri, "##"))
                message = g_strdup (_("Click to hide/unhide addresses"));
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
index ac238bc..47e31dc 100644
--- a/e-util/e-web-view.c
+++ b/e-util/e-web-view.c
@@ -994,11 +994,10 @@ web_view_hovering_over_link (EWebView *web_view,
 
        if (g_str_has_prefix (uri, "mailto:";))
                format = _("Click to mail %s");
-       else if (g_str_has_prefix (uri, "callto:"))
-               format = _("Click to call %s");
-       else if (g_str_has_prefix (uri, "h323:"))
-               format = _("Click to call %s");
-       else if (g_str_has_prefix (uri, "sip:"))
+       else if (g_str_has_prefix (uri, "callto:") ||
+                g_str_has_prefix (uri, "h323:") ||
+                g_str_has_prefix (uri, "sip:") ||
+                g_str_has_prefix (uri, "tel:"))
                format = _("Click to call %s");
        else if (g_str_has_prefix (uri, "##"))
                message = g_strdup (_("Click to hide/unhide addresses"));


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