Commit 8679c54e authored by Milan Crha's avatar Milan Crha

I#323 - Show non-Work/Home TEL in the contacts preview

Closes #323
parent dc18cba6
......@@ -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);
......
......@@ -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 &lt;a href="..."&gt; &lt;/a&gt;
* 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, "&nbsp;");
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment