From ecda7da11e893ff29258388c7b594b5ef4fa902a Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Thu, 11 Mar 2004 01:12:40 +0000 Subject: #if 0 this, since nothing uses it anymore. (accum_address): new function, 2004-03-10 Chris Toshok * gui/widgets/eab-contact-display.c (render_address): #if 0 this, since nothing uses it anymore. (accum_address): new function, build up a GString. (accum_name_value): same. (accum_attribute): same. (render_contact): don't just blindly render the work/personal blocks, since if they're empty it looks stupid. instead, accumulate each block into a GString and only output the entire block if the string is non-empty. svn path=/trunk/; revision=25018 --- addressbook/gui/widgets/eab-contact-display.c | 153 +++++++++++++++++++------- 1 file changed, 113 insertions(+), 40 deletions(-) (limited to 'addressbook/gui') diff --git a/addressbook/gui/widgets/eab-contact-display.c b/addressbook/gui/widgets/eab-contact-display.c index 87c8502147..b27fed110b 100644 --- a/addressbook/gui/widgets/eab-contact-display.c +++ b/addressbook/gui/widgets/eab-contact-display.c @@ -104,6 +104,7 @@ on_link_clicked (GtkHTML *html, const char *url, EABContactDisplay *display) } } +#if 0 static void render_address (GtkHTMLStream *html_stream, EContact *contact, const char *html_label, EContactField adr_field, EContactField label_field) { @@ -139,6 +140,7 @@ render_address (GtkHTMLStream *html_stream, EContact *contact, const char *html_ if (adr) e_contact_address_free (adr); } +#endif static void render_name_value (GtkHTMLStream *html_stream, const char *label, const char *str, const char *icon, unsigned int html_flags) @@ -165,6 +167,69 @@ render_attribute (GtkHTMLStream *html_stream, EContact *contact, const char *htm } } +static void +accum_address (GString *gstr, EContact *contact, const char *html_label, EContactField adr_field, EContactField label_field) +{ + EContactAddress *adr; + const char *label; + + label = e_contact_get_const (contact, label_field); + if (label) { + char *html = e_text_to_html (label, E_TEXT_TO_HTML_CONVERT_NL); + + g_string_append_printf (gstr, "%s:
%s%s", html_label, _("(map)"), html); + + g_free (html); + return; + } + + adr = e_contact_get (contact, adr_field); + if (adr && + (adr->po || adr->ext || adr->street || adr->locality || adr->region || adr->code || adr->country)) { + + g_string_append_printf (gstr, "%s:
%s", html_label, _("map")); + + if (adr->po && *adr->po) g_string_append_printf (gstr, "%s
", adr->po); + if (adr->ext && *adr->ext) g_string_append_printf (gstr, "%s
", adr->ext); + if (adr->street && *adr->street) g_string_append_printf (gstr, "%s
", adr->street); + if (adr->locality && *adr->locality) g_string_append_printf (gstr, "%s
", adr->locality); + if (adr->region && *adr->region) g_string_append_printf (gstr, "%s
", adr->region); + if (adr->code && *adr->code) g_string_append_printf (gstr, "%s
", adr->code); + if (adr->country && *adr->country) g_string_append_printf (gstr, "%s
", adr->country); + + g_string_append_printf (gstr, ""); + } + if (adr) + e_contact_address_free (adr); +} + +static void +accum_name_value (GString *gstr, const char *label, const char *str, const char *icon, unsigned int html_flags) +{ + char *value = e_text_to_html (str, html_flags); + + g_string_append_printf (gstr, ""); + if (icon) + g_string_append_printf (gstr, "", icon); + g_string_append_printf (gstr, "%s: %s", label, value); + + g_free (value); +} + + +static void +accum_attribute (GString *gstr, EContact *contact, const char *html_label, EContactField field, const char *icon, unsigned int html_flags) +{ + const char *str; + + str = e_contact_get_const (contact, field); + + if (str && *str) { + accum_name_value (gstr, html_label, str, icon, html_flags); + } +} + + static void render_contact_list (GtkHTMLStream *html_stream, EContact *contact) { @@ -205,72 +270,80 @@ end_block (GtkHTMLStream *html_stream) static void render_contact (GtkHTMLStream *html_stream, EContact *contact) { - GString *emails; + GString *accum; const char *e; char *nl; gtk_html_stream_printf (html_stream, ""); - start_block (html_stream, ""); - - emails = g_string_new (""); + accum = g_string_new (""); nl = ""; e = e_contact_get_const (contact, E_CONTACT_EMAIL_1); if (e) { - g_string_append_printf (emails, "%s", e); + g_string_append_printf (accum, "%s", e); nl = "\n"; } e = e_contact_get_const (contact, E_CONTACT_EMAIL_2); if (e) { - g_string_append_printf (emails, "%s%s", nl, e); + g_string_append_printf (accum, "%s%s", nl, e); nl = "\n"; } e = e_contact_get_const (contact, E_CONTACT_EMAIL_3); if (e) { - g_string_append_printf (emails, "%s%s", nl, e); + g_string_append_printf (accum, "%s%s", nl, e); } - render_name_value (html_stream, _("E-mail"), emails->str, NULL, E_TEXT_TO_HTML_CONVERT_ADDRESSES | E_TEXT_TO_HTML_CONVERT_NL); - g_string_free (emails, TRUE); - - end_block (html_stream); - - start_block (html_stream, _("work")); - - render_attribute (html_stream, contact, _("Organization"), E_CONTACT_ORG, NULL, 0); - render_attribute (html_stream, contact, _("Position"), E_CONTACT_TITLE, NULL, 0); - render_attribute (html_stream, contact, _("AIM"), E_CONTACT_IM_AIM_WORK_1, AIM_ICON, 0); - render_attribute (html_stream, contact, _("Groupwise"), E_CONTACT_IM_GROUPWISE_WORK_1, GROUPWISE_ICON, 0); - render_attribute (html_stream, contact, _("ICQ"), E_CONTACT_IM_ICQ_WORK_1, ICQ_ICON, 0); - render_attribute (html_stream, contact, _("Jabber"), E_CONTACT_IM_JABBER_WORK_1, JABBER_ICON, 0); - render_attribute (html_stream, contact, _("MSN"), E_CONTACT_IM_MSN_WORK_1, MSN_ICON, 0); - render_attribute (html_stream, contact, _("Yahoo"), E_CONTACT_IM_YAHOO_WORK_1, YAHOO_ICON, 0); - render_attribute (html_stream, contact, _("Video Conferencing"), E_CONTACT_VIDEO_URL, VIDEOCONF_ICON, E_TEXT_TO_HTML_CONVERT_URLS); - render_attribute (html_stream, contact, _("Phone"), E_CONTACT_PHONE_BUSINESS, NULL, 0); - render_attribute (html_stream, contact, _("Fax"), E_CONTACT_PHONE_BUSINESS_FAX, NULL, 0); - render_address (html_stream, contact, _("Address"), E_CONTACT_ADDRESS_WORK, E_CONTACT_ADDRESS_LABEL_WORK); - - end_block (html_stream); + if (accum->len) { + start_block (html_stream, ""); + render_name_value (html_stream, _("E-mail"), accum->str, NULL, + E_TEXT_TO_HTML_CONVERT_ADDRESSES | E_TEXT_TO_HTML_CONVERT_NL); + end_block (html_stream); + } - start_block (html_stream, _("personal")); + g_string_assign (accum, ""); + + accum_attribute (accum, contact, _("Organization"), E_CONTACT_ORG, NULL, 0); + accum_attribute (accum, contact, _("Position"), E_CONTACT_TITLE, NULL, 0); + accum_attribute (accum, contact, _("AIM"), E_CONTACT_IM_AIM_WORK_1, AIM_ICON, 0); + accum_attribute (accum, contact, _("Groupwise"), E_CONTACT_IM_GROUPWISE_WORK_1, GROUPWISE_ICON, 0); + accum_attribute (accum, contact, _("ICQ"), E_CONTACT_IM_ICQ_WORK_1, ICQ_ICON, 0); + accum_attribute (accum, contact, _("Jabber"), E_CONTACT_IM_JABBER_WORK_1, JABBER_ICON, 0); + accum_attribute (accum, contact, _("MSN"), E_CONTACT_IM_MSN_WORK_1, MSN_ICON, 0); + accum_attribute (accum, contact, _("Yahoo"), E_CONTACT_IM_YAHOO_WORK_1, YAHOO_ICON, 0); + accum_attribute (accum, contact, _("Video Conferencing"), E_CONTACT_VIDEO_URL, VIDEOCONF_ICON, E_TEXT_TO_HTML_CONVERT_URLS); + accum_attribute (accum, contact, _("Phone"), E_CONTACT_PHONE_BUSINESS, NULL, 0); + accum_attribute (accum, contact, _("Fax"), E_CONTACT_PHONE_BUSINESS_FAX, NULL, 0); + accum_address (accum, contact, _("Address"), E_CONTACT_ADDRESS_WORK, E_CONTACT_ADDRESS_LABEL_WORK); + + if (accum->len > 0) { + start_block (html_stream, _("work")); + gtk_html_stream_printf (html_stream, accum->str); + end_block (html_stream); + } - render_attribute (html_stream, contact, _("AIM"), E_CONTACT_IM_AIM_HOME_1, AIM_ICON, 0); - render_attribute (html_stream, contact, _("Groupwise"), E_CONTACT_IM_GROUPWISE_HOME_1, GROUPWISE_ICON, 0); - render_attribute (html_stream, contact, _("ICQ"), E_CONTACT_IM_ICQ_HOME_1, ICQ_ICON, 0); - render_attribute (html_stream, contact, _("Jabber"), E_CONTACT_IM_JABBER_HOME_1, JABBER_ICON, 0); - render_attribute (html_stream, contact, _("MSN"), E_CONTACT_IM_MSN_HOME_1, MSN_ICON, 0); - render_attribute (html_stream, contact, _("Yahoo"), E_CONTACT_IM_YAHOO_HOME_1, YAHOO_ICON, 0); + g_string_assign (accum, ""); - render_attribute (html_stream, contact, _("WWW"), E_CONTACT_HOMEPAGE_URL, NULL, E_TEXT_TO_HTML_CONVERT_URLS); - render_attribute (html_stream, contact, _("Blog"), E_CONTACT_BLOG_URL, NULL, E_TEXT_TO_HTML_CONVERT_URLS); + accum_attribute (accum, contact, _("AIM"), E_CONTACT_IM_AIM_HOME_1, AIM_ICON, 0); + accum_attribute (accum, contact, _("Groupwise"), E_CONTACT_IM_GROUPWISE_HOME_1, GROUPWISE_ICON, 0); + accum_attribute (accum, contact, _("ICQ"), E_CONTACT_IM_ICQ_HOME_1, ICQ_ICON, 0); + accum_attribute (accum, contact, _("Jabber"), E_CONTACT_IM_JABBER_HOME_1, JABBER_ICON, 0); + accum_attribute (accum, contact, _("MSN"), E_CONTACT_IM_MSN_HOME_1, MSN_ICON, 0); + accum_attribute (accum, contact, _("Yahoo"), E_CONTACT_IM_YAHOO_HOME_1, YAHOO_ICON, 0); + accum_attribute (accum, contact, _("WWW"), E_CONTACT_HOMEPAGE_URL, NULL, E_TEXT_TO_HTML_CONVERT_URLS); + accum_attribute (accum, contact, _("Blog"), E_CONTACT_BLOG_URL, NULL, E_TEXT_TO_HTML_CONVERT_URLS); - render_address (html_stream, contact, _("Address"), E_CONTACT_ADDRESS_HOME, E_CONTACT_ADDRESS_LABEL_HOME); + accum_address (accum, contact, _("Address"), E_CONTACT_ADDRESS_HOME, E_CONTACT_ADDRESS_LABEL_HOME); - end_block (html_stream); + if (accum->len > 0) { + start_block (html_stream, _("personal")); + gtk_html_stream_printf (html_stream, accum->str); + end_block (html_stream); + } start_block (html_stream, ""); - render_attribute (html_stream, contact, _("Note"), E_CONTACT_NOTE, NULL, E_TEXT_TO_HTML_CONVERT_ADDRESSES | E_TEXT_TO_HTML_CONVERT_URLS | E_TEXT_TO_HTML_CONVERT_NL); + render_attribute (html_stream, contact, _("Note"), E_CONTACT_NOTE, NULL, + E_TEXT_TO_HTML_CONVERT_ADDRESSES | E_TEXT_TO_HTML_CONVERT_URLS | E_TEXT_TO_HTML_CONVERT_NL); end_block (html_stream); gtk_html_stream_printf (html_stream, "
"); -- cgit