[evolution] I#323 - Show non-Work/Home TEL in the contacts preview
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] I#323 - Show non-Work/Home TEL in the contacts preview
- Date: Mon, 11 Mar 2019 10:52:25 +0000 (UTC)
commit 8679c54e002349acf0558cd1902bfee2dabd9f2d
Author: Milan Crha <mcrha redhat com>
Date: Mon Mar 11 11:53:06 2019 +0100
I#323 - Show non-Work/Home TEL in the contacts preview
Closes https://gitlab.gnome.org/GNOME/evolution/issues/323
.../gui/widgets/eab-contact-formatter.c | 112 ++++++++++++++++++++-
src/e-util/e-html-utils.c | 8 +-
src/e-util/e-html-utils.h | 23 +++--
3 files changed, 128 insertions(+), 15 deletions(-)
---
diff --git a/src/addressbook/gui/widgets/eab-contact-formatter.c
b/src/addressbook/gui/widgets/eab-contact-formatter.c
index b1581e564c..998b0f7fb5 100644
--- a/src/addressbook/gui/widgets/eab-contact-formatter.c
+++ b/src/addressbook/gui/widgets/eab-contact-formatter.c
@@ -704,16 +704,88 @@ render_contact_list (EABContactFormatter *formatter,
g_object_unref (destination);
}
+static const gchar *
+get_phone_location (EVCardAttribute *attr)
+{
+ struct _locations {
+ EContactField field_id;
+ const gchar *attr_type;
+ } locations[] = {
+ { E_CONTACT_PHONE_ASSISTANT, EVC_X_ASSISTANT },
+ { E_CONTACT_PHONE_CALLBACK, EVC_X_CALLBACK },
+ { E_CONTACT_PHONE_CAR, "CAR" },
+ { E_CONTACT_PHONE_COMPANY, EVC_X_COMPANY },
+ { E_CONTACT_PHONE_ISDN, "ISDN" },
+ { E_CONTACT_PHONE_MOBILE, "CELL" },
+ { E_CONTACT_PHONE_OTHER_FAX, "FAX" },
+ { E_CONTACT_PHONE_PAGER, "PAGER" },
+ { E_CONTACT_PHONE_PRIMARY, "PREF" },
+ { E_CONTACT_PHONE_RADIO, EVC_X_RADIO },
+ { E_CONTACT_PHONE_TELEX, EVC_X_TELEX },
+ { E_CONTACT_PHONE_TTYTDD, EVC_X_TTYTDD }
+ };
+ GList *params, *plink;
+ GList *values = NULL, *vlink;
+ gboolean done = FALSE;
+ const gchar *location = NULL;
+ gint ii;
+
+ params = e_vcard_attribute_get_params (attr);
+
+ for (plink = params; plink; plink = g_list_next (plink)) {
+ EVCardAttributeParam *param = plink->data;
+
+ if (!g_ascii_strcasecmp (e_vcard_attribute_param_get_name (param), EVC_TYPE)) {
+ values = e_vcard_attribute_param_get_values (param);
+ break;
+ }
+ }
+
+ for (vlink = values; vlink && !done; vlink = g_list_next (vlink)) {
+ const gchar *value = vlink->data;
+
+ if (!value)
+ continue;
+
+ for (ii = 0; ii < G_N_ELEMENTS (locations); ii++) {
+ if (!g_ascii_strcasecmp (value, locations[ii].attr_type)) {
+ if (location) {
+ /* if more than one is set, then fallback to the "Other Phone" */
+ location = NULL;
+ done = TRUE;
+ break;
+ }
+
+ location = e_contact_pretty_name (locations[ii].field_id);
+ }
+ }
+ }
+
+ if (!location)
+ location = e_contact_pretty_name (E_CONTACT_PHONE_OTHER);
+
+ if (!location)
+ location = _("Phone");
+
+ return location;
+}
+
static void
render_contact_column (EABContactFormatter *formatter,
EContact *contact,
GString *buffer)
{
GString *accum, *email;
- GList *email_list, *l, *email_attr_list, *al;
+ GList *email_list, *l, *email_attr_list, *al, *phone_attr_list;
gint email_num = 0;
const gchar *nl;
- guint32 sip_flags = 0;
+ guint32 phone_flags = 0, sip_flags = 0;
+
+ 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_TEL_URL;
if (formatter->priv->supports_sip)
sip_flags = E_TEXT_TO_HTML_CONVERT_URLS |
@@ -761,6 +833,42 @@ render_contact_column (EABContactFormatter *formatter,
if (email->len)
render_table_row (accum, _("Email"), email->str, NULL, 0);
+ phone_attr_list = e_contact_get_attributes (contact, E_CONTACT_TEL);
+
+ for (l = phone_attr_list; l; l = g_list_next (l)) {
+ EVCardAttribute *attr = l->data;
+
+ if (!e_vcard_attribute_has_type (attr, "WORK") &&
+ !e_vcard_attribute_has_type (attr, "HOME")) {
+ guint32 html_flags = phone_flags;
+ const gchar *attr_str, *str;
+ gchar *phone, *tmp_value, *label;
+
+ phone = e_vcard_attribute_get_value (attr);
+ if (!phone || !*phone) {
+ g_free (phone);
+ continue;
+ }
+
+ attr_str = get_phone_location (attr);
+ label = e_text_to_html (attr_str, E_TEXT_TO_HTML_CONVERT_ALL_SPACES);
+
+ tmp_value = maybe_create_url (phone, html_flags);
+ if (tmp_value)
+ str = tmp_value;
+ else
+ str = phone;
+
+ render_table_row (accum, label, str, NULL, html_flags);
+
+ g_free (tmp_value);
+ g_free (phone);
+ g_free (label);
+ }
+ }
+
+ g_list_free_full (phone_attr_list, (GDestroyNotify) e_vcard_attribute_free);
+
accum_sip (accum, contact, EAB_CONTACT_FORMATTER_SIP_TYPE_OTHER, NULL, sip_flags);
accum_attribute (accum, contact, _("Nickname"), E_CONTACT_NICKNAME, NULL, 0);
diff --git a/src/e-util/e-html-utils.c b/src/e-util/e-html-utils.c
index 99ead9f7c4..65737a004d 100644
--- a/src/e-util/e-html-utils.c
+++ b/src/e-util/e-html-utils.c
@@ -210,6 +210,9 @@ is_citation (const guchar *c,
* If E_TEXT_TO_HTML_CONVERT_NL and E_TEXT_TO_HTML_CONVERT_SPACES
* are both defined, then TABs will also be converted to spaces.
*
+ * - E_TEXT_TO_HTML_CONVERT_ALL_SPACES: similar to E_TEXT_TO_HTML_CONVERT_SPACES,
+ * but converts all spaces to non-breaking spaces.
+ *
* - E_TEXT_TO_HTML_CONVERT_URLS: wrap <a href="..."> </a>
* around strings that look like URLs.
*
@@ -447,8 +450,9 @@ e_text_to_html_full (const gchar *input,
/* falls through */
case ' ':
- if (flags & E_TEXT_TO_HTML_CONVERT_SPACES) {
- if (cur == (const guchar *) input ||
+ if ((flags & (E_TEXT_TO_HTML_CONVERT_SPACES | E_TEXT_TO_HTML_CONVERT_ALL_SPACES)) !=
0) {
+ if ((flags & E_TEXT_TO_HTML_CONVERT_ALL_SPACES) != 0 ||
+ cur == (const guchar *) input ||
*(cur + 1) == ' ' || *(cur + 1) == '\t' ||
*(cur - 1) == '\n') {
strcpy (out, " ");
diff --git a/src/e-util/e-html-utils.h b/src/e-util/e-html-utils.h
index ea48fbd890..bff1a0dd83 100644
--- a/src/e-util/e-html-utils.h
+++ b/src/e-util/e-html-utils.h
@@ -28,17 +28,18 @@
#include <glib.h>
-#define E_TEXT_TO_HTML_PRE (1 << 0)
-#define E_TEXT_TO_HTML_CONVERT_NL (1 << 1)
-#define E_TEXT_TO_HTML_CONVERT_SPACES (1 << 2)
-#define E_TEXT_TO_HTML_CONVERT_URLS (1 << 3)
-#define E_TEXT_TO_HTML_MARK_CITATION (1 << 4)
-#define E_TEXT_TO_HTML_CONVERT_ADDRESSES (1 << 5)
-#define E_TEXT_TO_HTML_ESCAPE_8BIT (1 << 6)
-#define E_TEXT_TO_HTML_CITE (1 << 7)
-#define E_TEXT_TO_HTML_HIDE_URL_SCHEME (1 << 8)
-#define E_TEXT_TO_HTML_URL_IS_WHOLE_TEXT (1 << 9)
-#define E_TEXT_TO_HTML_LAST_FLAG (1 << 10)
+#define E_TEXT_TO_HTML_PRE (1 << 0)
+#define E_TEXT_TO_HTML_CONVERT_NL (1 << 1)
+#define E_TEXT_TO_HTML_CONVERT_SPACES (1 << 2)
+#define E_TEXT_TO_HTML_CONVERT_URLS (1 << 3)
+#define E_TEXT_TO_HTML_MARK_CITATION (1 << 4)
+#define E_TEXT_TO_HTML_CONVERT_ADDRESSES (1 << 5)
+#define E_TEXT_TO_HTML_ESCAPE_8BIT (1 << 6)
+#define E_TEXT_TO_HTML_CITE (1 << 7)
+#define E_TEXT_TO_HTML_HIDE_URL_SCHEME (1 << 8)
+#define E_TEXT_TO_HTML_URL_IS_WHOLE_TEXT (1 << 9)
+#define E_TEXT_TO_HTML_CONVERT_ALL_SPACES (1 << 10)
+#define E_TEXT_TO_HTML_LAST_FLAG (1 << 11)
gchar *e_text_to_html_full (const gchar *input, guint flags, guint32 color);
gchar *e_text_to_html (const gchar *input, guint flags);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]