diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2009-11-20 01:21:27 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-11-20 02:55:06 +0800 |
commit | fe0c708bf00e5509336d559797bc34dd641cf511 (patch) | |
tree | a524621b95b045fb5ec243dcb01b19695580787a | |
parent | aa813bd7cadffa0110ddeeecd2b8df9d367db6e1 (diff) | |
download | gsoc2013-evolution-fe0c708bf00e5509336d559797bc34dd641cf511.tar.gz gsoc2013-evolution-fe0c708bf00e5509336d559797bc34dd641cf511.tar.zst gsoc2013-evolution-fe0c708bf00e5509336d559797bc34dd641cf511.zip |
Assemble HTML code in a GString instead of a GtkHTMLStream.
This helps further isolate direct GtkHTML API usage to EWebView.
-rw-r--r-- | addressbook/gui/widgets/eab-contact-display.c | 410 | ||||
-rw-r--r-- | calendar/gui/e-cal-component-preview.c | 109 | ||||
-rw-r--r-- | calendar/gui/e-itip-control.c | 258 | ||||
-rw-r--r-- | mail/e-mail-reader.c | 2 |
4 files changed, 430 insertions, 349 deletions
diff --git a/addressbook/gui/widgets/eab-contact-display.c b/addressbook/gui/widgets/eab-contact-display.c index 692b6f003e..84f7cba538 100644 --- a/addressbook/gui/widgets/eab-contact-display.c +++ b/addressbook/gui/widgets/eab-contact-display.c @@ -41,7 +41,8 @@ (G_TYPE_INSTANCE_GET_PRIVATE \ ((obj), EAB_TYPE_CONTACT_DISPLAY, EABContactDisplayPrivate)) -#define HANDLE_MAILTO_INTERNALLY 1 +#define TEXT_IS_RIGHT_TO_LEFT \ + (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) struct _EABContactDisplayPrivate { EContact *contact; @@ -184,60 +185,84 @@ static GtkActionEntry internal_mailto_entries[] = { }; static void -render_name_value (GtkHTMLStream *html_stream, const gchar *label, const gchar *str, const gchar *icon, guint html_flags) +render_name_value (GString *buffer, + const gchar *label, + const gchar *str, + const gchar *icon, + guint html_flags) { gchar *value = e_text_to_html (str, html_flags); - if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) { - gtk_html_stream_printf (html_stream, "<tr><td align=\"right\" valign=\"top\">%s</td> <td align=\"right\" valign=\"top\" width=\"100\" nowrap><font color=" HEADER_COLOR ">%s:</font></td>", value, label); - gtk_html_stream_printf (html_stream, "<td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); - if (icon) - gtk_html_stream_printf (html_stream, "<img width=\"16\" height=\"16\" src=\"evo-icon:%s\"></td></tr>", icon); - else - gtk_html_stream_printf (html_stream, "</td></tr>"); + if (TEXT_IS_RIGHT_TO_LEFT) { + g_string_append_printf ( + buffer, "<tr>" + "<td align=\"right\" valign=\"top\">%s</td> " + "<td align=\"right\" valign=\"top\" width=\"100\" nowrap>" + "<font color=" HEADER_COLOR ">%s:</font></td>", + value, label); + g_string_append ( + buffer, "<td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); + if (icon != NULL) + g_string_append_printf ( + buffer, "<img width=\"16\" height=\"16\" " + "src=\"evo-icon:%s\">", icon); + g_string_append (buffer, "</td></tr>"); } else { - gtk_html_stream_printf (html_stream, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); - if (icon) - gtk_html_stream_printf (html_stream, "<img width=\"16\" height=\"16\" src=\"evo-icon:%s\">", icon); - gtk_html_stream_printf (html_stream, "</td><td valign=\"top\" width=\"100\" nowrap><font color=" HEADER_COLOR ">%s:</font></td> <td valign=\"top\">%s</td></tr>", label, value); + g_string_append ( + buffer, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); + if (icon != NULL) + g_string_append_printf ( + buffer, "<img width=\"16\" height=\"16\" " + "src=\"evo-icon:%s\">", icon); + g_string_append_printf ( + buffer, "</td><td valign=\"top\" width=\"100\" nowrap>" + "<font color=" HEADER_COLOR ">%s:</font></td> " + "<td valign=\"top\">%s</td></tr>", label, value); } g_free (value); } static void -render_attribute (GtkHTMLStream *html_stream, EContact *contact, const gchar *html_label, EContactField field, const gchar *icon, guint html_flags) +render_attribute (GString *buffer, + EContact *contact, + const gchar *html_label, + EContactField field, + const gchar *icon, + guint html_flags) { const gchar *str; str = e_contact_get_const (contact, field); - if (str && *str) { - render_name_value (html_stream, html_label, str, icon, html_flags); - } + if (str != NULL && *str != '\0') + render_name_value (buffer, html_label, str, icon, html_flags); } static void -accum_address (GString *gstr, EContact *contact, const gchar *html_label, EContactField adr_field, EContactField label_field) +accum_address (GString *buffer, + EContact *contact, + const gchar *html_label, + EContactField adr_field, + EContactField label_field) { EContactAddress *adr; const gchar *label; - gboolean is_rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL); label = e_contact_get_const (contact, label_field); if (label) { gchar *html = e_text_to_html (label, E_TEXT_TO_HTML_CONVERT_NL); #ifdef mapping_works - if (is_rtl) - g_string_append_printf (gstr, "<tr><td align=\"right\" valign=\"top\">%s</td><td valign=\"top\" width=\"100\" align=\"right\"><font color=" HEADER_COLOR ">%s:</font><br><a href=\"http://www.mapquest.com/\">%s</a></td><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td></tr>", html, html_label, _("(map)")); + if (TEXT_IS_RIGHT_TO_LEFT) + g_string_append_printf (buffer, "<tr><td align=\"right\" valign=\"top\">%s</td><td valign=\"top\" width=\"100\" align=\"right\"><font color=" HEADER_COLOR ">%s:</font><br><a href=\"http://www.mapquest.com/\">%s</a></td><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td></tr>", html, html_label, _("(map)")); else - g_string_append_printf (gstr, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td><td valign=\"top\" width=\"100\"><font color=" HEADER_COLOR ">%s:</font><br><a href=\"http://www.mapquest.com/\">%s</a></td><td valign=\"top\">%s</td></tr>", html_label, _("(map)"), html); + g_string_append_printf (buffer, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td><td valign=\"top\" width=\"100\"><font color=" HEADER_COLOR ">%s:</font><br><a href=\"http://www.mapquest.com/\">%s</a></td><td valign=\"top\">%s</td></tr>", html_label, _("(map)"), html); #else - if (is_rtl) - g_string_append_printf (gstr, "<tr><td align=\"right\" valign=\"top\">%s</td><td valign=\"top\" width=\"100\" align=\"right\"><font color=" HEADER_COLOR ">%s:</font></td><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td></tr>", html, html_label); + if (TEXT_IS_RIGHT_TO_LEFT) + g_string_append_printf (buffer, "<tr><td align=\"right\" valign=\"top\">%s</td><td valign=\"top\" width=\"100\" align=\"right\"><font color=" HEADER_COLOR ">%s:</font></td><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td></tr>", html, html_label); else - g_string_append_printf (gstr, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td><td valign=\"top\" width=\"100\"><font color=" HEADER_COLOR ">%s:</font></td><td valign=\"top\">%s</td></tr>", html_label, html); + g_string_append_printf (buffer, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td><td valign=\"top\" width=\"100\"><font color=" HEADER_COLOR ">%s:</font></td><td valign=\"top\">%s</td></tr>", html_label, html); #endif g_free (html); @@ -247,64 +272,92 @@ accum_address (GString *gstr, EContact *contact, const gchar *html_label, EConta adr = e_contact_get (contact, adr_field); if (adr && (adr->po || adr->ext || adr->street || adr->locality || adr->region || adr->code || adr->country)) { - if (is_rtl) - g_string_append_printf (gstr, "<tr><td align=\"right\" valign=\"top\">"); + if (TEXT_IS_RIGHT_TO_LEFT) + g_string_append_printf (buffer, "<tr><td align=\"right\" valign=\"top\">"); else - g_string_append_printf (gstr, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td><td valign=\"top\" width=\"100\"><font color=" HEADER_COLOR ">%s:</font><br><a href=\"http://www.mapquest.com/\">%s</a></td><td valign=\"top\">", html_label, _("map")); - - if (adr->po && *adr->po) g_string_append_printf (gstr, "%s<br>", adr->po); - if (adr->ext && *adr->ext) g_string_append_printf (gstr, "%s<br>", adr->ext); - if (adr->street && *adr->street) g_string_append_printf (gstr, "%s<br>", adr->street); - if (adr->locality && *adr->locality) g_string_append_printf (gstr, "%s<br>", adr->locality); - if (adr->region && *adr->region) g_string_append_printf (gstr, "%s<br>", adr->region); - if (adr->code && *adr->code) g_string_append_printf (gstr, "%s<br>", adr->code); - if (adr->country && *adr->country) g_string_append_printf (gstr, "%s<br>", adr->country); - - if (is_rtl) - g_string_append_printf (gstr, "</td><td valign=\"top\" width=\"100\" align=\"right\"><font color=" HEADER_COLOR ">%s:</font><br><a href=\"http://www.mapquest.com/\">%s</a></td><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td></tr>", html_label, _("map")); + g_string_append_printf (buffer, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td><td valign=\"top\" width=\"100\"><font color=" HEADER_COLOR ">%s:</font><br><a href=\"http://www.mapquest.com/\">%s</a></td><td valign=\"top\">", html_label, _("map")); + + if (adr->po && *adr->po) g_string_append_printf (buffer, "%s<br>", adr->po); + if (adr->ext && *adr->ext) g_string_append_printf (buffer, "%s<br>", adr->ext); + if (adr->street && *adr->street) g_string_append_printf (buffer, "%s<br>", adr->street); + if (adr->locality && *adr->locality) g_string_append_printf (buffer, "%s<br>", adr->locality); + if (adr->region && *adr->region) g_string_append_printf (buffer, "%s<br>", adr->region); + if (adr->code && *adr->code) g_string_append_printf (buffer, "%s<br>", adr->code); + if (adr->country && *adr->country) g_string_append_printf (buffer, "%s<br>", adr->country); + + if (TEXT_IS_RIGHT_TO_LEFT) + g_string_append_printf (buffer, "</td><td valign=\"top\" width=\"100\" align=\"right\"><font color=" HEADER_COLOR ">%s:</font><br><a href=\"http://www.mapquest.com/\">%s</a></td><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td></tr>", html_label, _("map")); else - g_string_append_printf (gstr, "</td></tr>"); + g_string_append_printf (buffer, "</td></tr>"); } if (adr) e_contact_address_free (adr); } static void -accum_name_value (GString *gstr, const gchar *label, const gchar *str, const gchar *icon, guint html_flags) +accum_name_value (GString *buffer, + const gchar *label, + const gchar *str, + const gchar *icon, + guint html_flags) { gchar *value = e_text_to_html (str, html_flags); - if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL) { - g_string_append_printf (gstr, "<tr><td valign=\"top\" align=\"right\">%s</td> <td align=\"right\" valign=\"top\" width=\"100\" nowrap><font color=" HEADER_COLOR ">%s:</font></td>", value, label); - g_string_append_printf (gstr, "<td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); - if (icon) - g_string_append_printf (gstr, "<img width=\"16\" height=\"16\" src=\"evo-icon:%s\"></td></tr>", icon); + if (TEXT_IS_RIGHT_TO_LEFT) { + g_string_append_printf ( + buffer, "<tr>" + "<td valign=\"top\" align=\"right\">%s</td> " + "<td align=\"right\" valign=\"top\" width=\"100\" nowrap>" + "<font color=" HEADER_COLOR ">%s:</font></td>", + value, label); + g_string_append_printf ( + buffer, "<td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); + if (icon != NULL) + g_string_append_printf ( + buffer, "<img width=\"16\" height=\"16\" " + "src=\"evo-icon:%s\"></td></tr>", icon); else - g_string_append_printf (gstr, "</td></tr>"); + g_string_append_printf (buffer, "</td></tr>"); } else { - g_string_append_printf (gstr, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); - if (icon) - g_string_append_printf (gstr, "<img width=\"16\" height=\"16\" src=\"evo-icon:%s\">", icon); - g_string_append_printf (gstr, "</td><td valign=\"top\" width=\"100\" nowrap><font color=" HEADER_COLOR ">%s:</font></td> <td valign=\"top\">%s</td></tr>", label, value); + g_string_append_printf ( + buffer, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); + if (icon != NULL) + g_string_append_printf ( + buffer, "<img width=\"16\" height=\"16\" " + "src=\"evo-icon:%s\">", icon); + g_string_append_printf ( + buffer, "</td><td valign=\"top\" width=\"100\" nowrap>" + "<font color=" HEADER_COLOR ">%s:</font>" + "</td> <td valign=\"top\">%s</td></tr>", + label, value); } g_free (value); } static void -accum_attribute (GString *gstr, EContact *contact, const gchar *html_label, EContactField field, const gchar *icon, guint html_flags) +accum_attribute (GString *buffer, + EContact *contact, + const gchar *html_label, + EContactField field, + const gchar *icon, + guint html_flags) { const gchar *str; str = e_contact_get_const (contact, field); - if (str && *str) { - accum_name_value (gstr, html_label, str, icon, html_flags); - } + if (str != NULL && *str != '\0') + accum_name_value (buffer, html_label, str, icon, html_flags); } static void -accum_time_attribute (GString *gstr, EContact *contact, const gchar *html_label, EContactField field, const gchar *icon, guint html_flags) +accum_time_attribute (GString *buffer, + EContact *contact, + const gchar *html_label, + EContactField field, + const gchar *icon, + guint html_flags) { EContactDate *date; GDate *gdate = NULL; @@ -317,35 +370,49 @@ accum_time_attribute (GString *gstr, EContact *contact, const gchar *html_label, date->year ); g_date_strftime (sdate, 100, "%x", gdate); g_date_free (gdate); - accum_name_value (gstr, html_label, sdate, icon, html_flags); + accum_name_value (buffer, html_label, sdate, icon, html_flags); e_contact_date_free (date); } } static void -accum_multival_attribute (GString *gstr, EContact *contact, const gchar *html_label, EContactField field, const gchar *icon, guint html_flags) +accum_multival_attribute (GString *buffer, + EContact *contact, + const gchar *html_label, + EContactField field, + const gchar *icon, + guint html_flags) { GList *val_list, *l; val_list = e_contact_get (contact, field); for (l = val_list; l; l = l->next) { const gchar *str = (const gchar *) l->data; - accum_name_value (gstr, html_label, str, icon, html_flags); + accum_name_value (buffer, html_label, str, icon, html_flags); } g_list_foreach (val_list, (GFunc) g_free, NULL); g_list_free (val_list); } static void -render_contact_list (GtkHTMLStream *html_stream, EContact *contact) +render_contact_list (GString *buffer, + EContact *contact) { GList *email_list; GList *l; - gtk_html_stream_printf (html_stream, "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>"); - gtk_html_stream_printf (html_stream, "<td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); - gtk_html_stream_printf (html_stream, "<img width=\"16\" height=\"16\" src=\"evo-icon:" CONTACT_LIST_ICON "\">"); - gtk_html_stream_printf (html_stream, "</td><td valign=\"top\" width=\"100\" nowrap><font color=" HEADER_COLOR ">%s:</font></td> <td valign=\"top\">", _("List Members")); + g_string_append ( + buffer, "<table border=\"0\" cellspacing=\"0\" " + "cellpadding=\"0\"><tr>"); + g_string_append ( + buffer, "<td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); + g_string_append ( + buffer, "<img width=\"16\" height=\"16\" " + "src=\"evo-icon:" CONTACT_LIST_ICON "\">"); + g_string_append_printf ( + buffer, "</td><td valign=\"top\" width=\"100\" nowrap>" + "<font color=" HEADER_COLOR ">%s:</font></td> " + "<td valign=\"top\">", _("List Members")); email_list = e_contact_get (contact, E_CONTACT_EMAIL); for (l = email_list; l; l = l->next) { @@ -356,24 +423,28 @@ render_contact_list (GtkHTMLStream *html_stream, EContact *contact) if (!value) value = e_text_to_html (l->data, E_TEXT_TO_HTML_CONVERT_ADDRESSES); - gtk_html_stream_printf (html_stream, "%s<br>", value); + g_string_append_printf (buffer, "%s<br>", value); g_free (value); } - gtk_html_stream_printf (html_stream, "</td></tr></table>"); + g_string_append (buffer, "</td></tr></table>"); } static void -start_block (GtkHTMLStream *html_stream, const gchar *label) +start_block (GString *buffer, + const gchar *label) { - gtk_html_stream_printf (html_stream, "<tr><td height=\"20\" colspan=\"3\"><font color=" HEADER_COLOR "><b>%s</b></font></td></tr>", label); + g_string_append_printf ( + buffer, "<tr><td height=\"20\" colspan=\"3\">" + "<font color=" HEADER_COLOR "><b>%s</b>" + "</font></td></tr>", label); } static void -end_block (GtkHTMLStream *html_stream) +end_block (GString *buffer) { - gtk_html_stream_printf (html_stream, "<tr><td height=\"20\"> </td></tr>"); + g_string_append (buffer, "<tr><td height=\"20\"> </td></tr>"); } static const gchar * @@ -390,23 +461,21 @@ get_email_location (EVCardAttribute *attr) } static void -render_contact (GtkHTMLStream *html_stream, EContact *contact) +render_contact (GString *buffer, + EContact *contact) { GString *accum; GList *email_list, *l, *email_attr_list, *al; - gboolean is_rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL); -#ifdef HANDLE_MAILTO_INTERNALLY gint email_num = 0; -#endif const gchar *nl; gchar *nick=NULL; - gtk_html_stream_printf (html_stream, "<table border=\"0\">"); + g_string_append (buffer, "<table border=\"0\">"); accum = g_string_new (""); nl = ""; - start_block (html_stream, ""); + start_block (buffer, ""); email_list = e_contact_get (contact, E_CONTACT_EMAIL); email_attr_list = e_contact_get_attributes (contact, E_CONTACT_EMAIL); @@ -415,7 +484,6 @@ render_contact (GtkHTMLStream *html_stream, EContact *contact) gchar *html = NULL, *name = NULL, *mail = NULL; gchar *attr_str = (gchar *)get_email_location ((EVCardAttribute *) al->data); -#ifdef HANDLE_MAILTO_INTERNALLY if (!eab_parse_qp_email (l->data, &name, &mail)) mail = e_text_to_html (l->data, 0); @@ -428,14 +496,6 @@ render_contact (GtkHTMLStream *html_stream, EContact *contact) name ? ">" : "", attr_str ? attr_str : ""); email_num ++; -#else - html = eab_parse_qp_email_to_html (l->data); - - if (!html) - html = e_text_to_html (l->data, E_TEXT_TO_HTML_CONVERT_ADDRESSES); - - g_string_append_printf (accum, "%s%s <font color=" HEADER_COLOR ">(%s)</font>", nl, html, attr_str ? attr_str : ""); -#endif nl = "<br>"; g_free (html); @@ -447,21 +507,23 @@ render_contact (GtkHTMLStream *html_stream, EContact *contact) if (accum->len) { -#ifdef HANDLE_MAILTO_INTERNALLY - if (is_rtl) { - gtk_html_stream_printf (html_stream, - "<tr><td valign=\"top\" align=\"right\">%s</td> <td valign=\"top\" align=\"right\" width=\"100\" nowrap><font color=" HEADER_COLOR ">%s:</font></td><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\"></td></tr>", - accum->str, _("Email")); + if (TEXT_IS_RIGHT_TO_LEFT) { + g_string_append_printf ( + buffer, "<tr>" + "<td valign=\"top\" align=\"right\">%s</td> " + "<td valign=\"top\" align=\"right\" width=\"100\" nowrap>" + "<font color=" HEADER_COLOR ">%s:</font>" + "</td><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">" + "</td></tr>", accum->str, _("Email")); } else { - gtk_html_stream_printf (html_stream, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); - gtk_html_stream_printf (html_stream, - "</td><td valign=\"top\" width=\"100\" nowrap><font color=" HEADER_COLOR ">%s:</font></td> <td valign=\"top\">%s</td></tr>", - _("Email"), accum->str); + g_string_append ( + buffer, "<tr><td valign=\"top\" width=\"" IMAGE_COL_WIDTH "\">"); + g_string_append_printf ( + buffer, "</td><td valign=\"top\" width=\"100\" nowrap>" + "<font color=" HEADER_COLOR ">%s:</font></td> " + "<td valign=\"top\">%s</td></tr>", + _("Email"), accum->str); } -#else - render_name_value (html_stream, _("Email"), accum->str, NULL, - E_TEXT_TO_HTML_CONVERT_ADDRESSES | E_TEXT_TO_HTML_CONVERT_NL); -#endif } g_string_assign (accum, ""); @@ -469,7 +531,8 @@ render_contact (GtkHTMLStream *html_stream, EContact *contact) if (nick && *nick) { accum_name_value (accum, _("Nickname"), nick, NULL, 0); if (accum->len > 0) - gtk_html_stream_printf (html_stream, "%s", accum->str); + g_string_append_printf ( + buffer, "%s", accum->str); } g_string_assign (accum, ""); @@ -483,9 +546,9 @@ render_contact (GtkHTMLStream *html_stream, EContact *contact) accum_multival_attribute (accum, contact, _("Skype"), E_CONTACT_IM_SKYPE, SKYPE_ICON, 0); if (accum->len > 0) - gtk_html_stream_printf (html_stream, "%s", accum->str); + g_string_append_printf (buffer, "%s", accum->str); - end_block (html_stream); + end_block (buffer); g_string_assign (accum, ""); @@ -503,9 +566,9 @@ render_contact (GtkHTMLStream *html_stream, EContact *contact) 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, "%s", accum->str); - end_block (html_stream); + start_block (buffer, _("Work")); + g_string_append_printf (buffer, "%s", accum->str); + end_block (buffer); } g_string_assign (accum, ""); @@ -520,46 +583,58 @@ render_contact (GtkHTMLStream *html_stream, EContact *contact) accum_time_attribute (accum, contact, _("Anniversary"), E_CONTACT_ANNIVERSARY, NULL, 0); accum_attribute (accum, contact, _("Spouse"), E_CONTACT_SPOUSE, NULL, 0); if (accum->len > 0) { - start_block (html_stream, _("Personal")); - gtk_html_stream_printf (html_stream, "%s", accum->str); - end_block (html_stream); + start_block (buffer, _("Personal")); + g_string_append_printf (buffer, "%s", accum->str); + end_block (buffer); } - start_block (html_stream, ""); + start_block (buffer, ""); - 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); + render_attribute ( + buffer, 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 (buffer); - gtk_html_stream_printf (html_stream, "</table>"); + g_string_append (buffer, "</table>"); } static void -eab_contact_display_render_normal (EABContactDisplay *display, EContact *contact) +eab_contact_display_render_normal (EABContactDisplay *display, + EContact *contact) { - GtkHTMLStream *html_stream; - gboolean is_rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL); + GString *buffer; + + /* XXX The initial buffer size is arbitrary. Tune it. */ - html_stream = gtk_html_begin (GTK_HTML (display)); - gtk_html_stream_write (html_stream, HTML_HEADER, sizeof (HTML_HEADER) - 1); - gtk_html_stream_printf (html_stream, "<body><table width=\"100%%\"><tr><td %s>\n", is_rtl ? " align=\"right\" " : ""); + buffer = g_string_sized_new (4096); + g_string_append (buffer, HTML_HEADER); + g_string_append_printf ( + buffer, "<body><table width=\"100%%\"><tr>" + "<td %s>\n", TEXT_IS_RIGHT_TO_LEFT ? "align=\"right\"" : ""); if (contact) { const gchar *str; gchar *html; EContactPhoto *photo; - gtk_html_stream_printf (html_stream, "<table cellspacing=\"20\" border=\"0\"><td %s valign=\"top\">", is_rtl ? " align=\"right\" " : ""); + g_string_append_printf ( + buffer, "<table cellspacing=\"20\" border=\"0\">" + "<td %s valign=\"top\">", TEXT_IS_RIGHT_TO_LEFT ? + "align=\"right\"" : ""); photo = e_contact_get (contact, E_CONTACT_PHOTO); if (!photo) photo = e_contact_get (contact, E_CONTACT_LOGO); /* Only handle inlined photos for now */ if (photo && photo->type == E_CONTACT_PHOTO_TYPE_INLINED) { - gtk_html_stream_printf (html_stream, "<img border=\"1\" src=\"internal-contact-photo:\">"); + g_string_append (buffer, "<img border=\"1\" src=\"internal-contact-photo:\">"); e_contact_photo_free (photo); } - gtk_html_stream_printf (html_stream, "</td><td %s valign=\"top\">\n", is_rtl ? " align=\"right\" " : ""); + g_string_append_printf ( + buffer, "</td><td %s valign=\"top\">\n", + TEXT_IS_RIGHT_TO_LEFT ? "align=\"right\"" : ""); str = e_contact_get_const (contact, E_CONTACT_FILE_AS); if (!str) @@ -567,36 +642,39 @@ eab_contact_display_render_normal (EABContactDisplay *display, EContact *contact if (str) { html = e_text_to_html (str, 0); -#ifdef HANDLE_MAILTO_INTERNALLY if (e_contact_get (contact, E_CONTACT_IS_LIST)) - gtk_html_stream_printf (html_stream, "<h2><a href=\"internal-mailto:0\">%s</a></h2>", html); + g_string_append_printf (buffer, "<h2><a href=\"internal-mailto:0\">%s</a></h2>", html); else -#endif - gtk_html_stream_printf (html_stream, "<h2>%s</h2>", html); + g_string_append_printf (buffer, "<h2>%s</h2>", html); g_free (html); } if (e_contact_get (contact, E_CONTACT_IS_LIST)) - render_contact_list (html_stream, contact); + render_contact_list (buffer, contact); else - render_contact (html_stream, contact); + render_contact (buffer, contact); - gtk_html_stream_printf (html_stream, "</td></tr></table>\n"); + g_string_append (buffer, "</td></tr></table>\n"); } - gtk_html_stream_printf (html_stream, "</td></tr></table></body></html>\n"); - gtk_html_end (GTK_HTML (display), html_stream, GTK_HTML_STREAM_OK); + g_string_append (buffer, "</td></tr></table></body></html>\n"); + + e_web_view_load_string (E_WEB_VIEW (display), buffer->str); + + g_string_free (buffer, TRUE); } static void eab_contact_display_render_compact (EABContactDisplay *display, EContact *contact) { - GtkHTMLStream *html_stream; + GString *buffer; + + /* XXX The initial buffer size is arbitrary. Tune it. */ - html_stream = gtk_html_begin (GTK_HTML (display)); - gtk_html_stream_write (html_stream, HTML_HEADER, sizeof (HTML_HEADER) - 1); - gtk_html_stream_write (html_stream, "<body>\n", 7); + buffer = g_string_sized_new (4096); + g_string_append (buffer, HTML_HEADER); + g_string_append (buffer, "<body>\n"); if (contact) { const gchar *str; @@ -622,13 +700,14 @@ eab_contact_display_render_compact (EABContactDisplay *display, #undef DARKER } - gtk_html_stream_printf (html_stream, - "<table width=\"100%%\" cellpadding=1 cellspacing=0 bgcolor=\"#%06X\">" - "<tr><td valign=\"top\">" - "<table width=\"100%%\" cellpadding=0 cellspacing=0 bgcolor=\"#%06X\">" - "<tr><td valign=\"top\">" - "<table>" - "<tr><td valign=\"top\">", bg_frame, bg_body); + g_string_append_printf ( + buffer, + "<table width=\"100%%\" cellpadding=1 cellspacing=0 bgcolor=\"#%06X\">" + "<tr><td valign=\"top\">" + "<table width=\"100%%\" cellpadding=0 cellspacing=0 bgcolor=\"#%06X\">" + "<tr><td valign=\"top\">" + "<table>" + "<tr><td valign=\"top\">", bg_frame, bg_body); photo = e_contact_get (contact, E_CONTACT_PHOTO); if (!photo) @@ -665,54 +744,56 @@ eab_contact_display_render_compact (EABContactDisplay *display, } g_object_unref (pixbuf); - gtk_html_stream_printf (html_stream, "<img width=\"%d\" height=\"%d\" src=\"internal-contact-photo:\">", - calced_width, calced_height); + g_string_append_printf ( + buffer, + "<img width=\"%d\" height=\"%d\" src=\"internal-contact-photo:\">", + calced_width, calced_height); e_contact_photo_free (photo); } - gtk_html_stream_printf (html_stream, "</td><td valign=\"top\">\n"); + g_string_append (buffer, "</td><td valign=\"top\">\n"); str = e_contact_get_const (contact, E_CONTACT_FILE_AS); if (str) { html = e_text_to_html (str, 0); - gtk_html_stream_printf (html_stream, "<b>%s</b>", html); + g_string_append_printf (buffer, "<b>%s</b>", html); g_free (html); } else { str = e_contact_get_const (contact, E_CONTACT_FULL_NAME); if (str) { html = e_text_to_html (str, 0); - gtk_html_stream_printf (html_stream, "<b>%s</b>", html); + g_string_append_printf (buffer, "<b>%s</b>", html); g_free (html); } } - gtk_html_stream_write (html_stream, "<hr>", 4); + g_string_append (buffer, "<hr>"); if (e_contact_get (contact, E_CONTACT_IS_LIST)) { GList *email_list; GList *l; - gtk_html_stream_printf (html_stream, "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td valign=\"top\">"); - gtk_html_stream_printf (html_stream, "<b>%s:</b> <td>", _("List Members")); + g_string_append (buffer, "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td valign=\"top\">"); + g_string_append_printf (buffer, "<b>%s:</b> <td>", _("List Members")); email_list = e_contact_get (contact, E_CONTACT_EMAIL); for (l = email_list; l; l = l->next) { if (l->data) { html = e_text_to_html (l->data, 0); - gtk_html_stream_printf (html_stream, "%s, ", html); + g_string_append_printf (buffer, "%s, ", html); g_free (html); } } - gtk_html_stream_printf (html_stream, "</td></tr></table>"); + g_string_append (buffer, "</td></tr></table>"); } else { gboolean comma = FALSE; str = e_contact_get_const (contact, E_CONTACT_TITLE); if (str) { html = e_text_to_html (str, 0); - gtk_html_stream_printf (html_stream, "<b>%s:</b> %s<br>", _("Job Title"), str); + g_string_append_printf (buffer, "<b>%s:</b> %s<br>", _("Job Title"), str); g_free (html); } @@ -722,12 +803,12 @@ eab_contact_display_render_compact (EABContactDisplay *display, if (!html) \ html = e_text_to_html (str, 0); \ \ - gtk_html_stream_printf (html_stream, "%s%s", comma ? ", " : "", html); \ + g_string_append_printf (buffer, "%s%s", comma ? ", " : "", html); \ g_free (html); \ comma = TRUE; \ } - gtk_html_stream_printf (html_stream, "<b>%s:</b> ", _("Email")); + g_string_append_printf (buffer, "<b>%s:</b> ", _("Email")); str = e_contact_get_const (contact, E_CONTACT_EMAIL_1); if (str) print_email (); @@ -740,31 +821,36 @@ eab_contact_display_render_compact (EABContactDisplay *display, if (str) print_email (); - gtk_html_stream_write (html_stream, "<br>", 4); + g_string_append (buffer, "<br>"); #undef print_email str = e_contact_get_const (contact, E_CONTACT_HOMEPAGE_URL); if (str) { html = e_text_to_html (str, E_TEXT_TO_HTML_CONVERT_URLS); - gtk_html_stream_printf (html_stream, "<b>%s:</b> %s<br>", - _("Home page"), html); + g_string_append_printf ( + buffer, "<b>%s:</b> %s<br>", + _("Home page"), html); g_free (html); } str = e_contact_get_const (contact, E_CONTACT_BLOG_URL); if (str) { html = e_text_to_html (str, E_TEXT_TO_HTML_CONVERT_URLS); - gtk_html_stream_printf (html_stream, "<b>%s:</b> %s<br>", - _("Blog"), html); + g_string_append_printf ( + buffer, "<b>%s:</b> %s<br>", + _("Blog"), html); } } - gtk_html_stream_printf (html_stream, "</td></tr></table></td></tr></table></td></tr></table>\n"); + g_string_append (buffer, "</td></tr></table></td></tr></table></td></tr></table>\n"); } - gtk_html_stream_write (html_stream, "</body></html>\n", 15); - gtk_html_end (GTK_HTML (display), html_stream, GTK_HTML_STREAM_OK); + g_string_append (buffer, "</body></html>\n"); + + e_web_view_load_string (E_WEB_VIEW (display), buffer->str); + + g_string_free (buffer, TRUE); } static void diff --git a/calendar/gui/e-cal-component-preview.c b/calendar/gui/e-cal-component-preview.c index b0ba329286..014ce2c7d3 100644 --- a/calendar/gui/e-cal-component-preview.c +++ b/calendar/gui/e-cal-component-preview.c @@ -29,7 +29,6 @@ #include <glib/gi18n.h> #include <libecal/e-cal-time-util.h> #include <libedataserver/e-categories.h> -#include <gtkhtml/gtkhtml-stream.h> #include <libedataserver/e-time-utils.h> #include <e-util/e-util.h> #include <e-util/e-categories-config.h> @@ -79,7 +78,7 @@ timet_to_str_with_zone (ECalComponentDateTime *dt, } static void -cal_component_preview_write_html (GtkHTMLStream *stream, +cal_component_preview_write_html (GString *buffer, ECal *ecal, ECalComponent *comp, icaltimezone *default_zone) @@ -101,19 +100,19 @@ cal_component_preview_write_html (GtkHTMLStream *stream, e_cal_component_get_summary (comp, &text); if (text.value) - gtk_html_stream_printf (stream, - "<HTML><BODY><H1>%s</H1>", - text.value); + g_string_append_printf ( + buffer, "<HTML><BODY><H1>%s</H1>", + text.value); else - gtk_html_stream_printf (stream, - "<HTML><BODY><H1><I>%s</I></H1>", - _("Untitled")); + g_string_append_printf ( + buffer, "<HTML><BODY><H1><I>%s</I></H1>", + _("Untitled")); /* write icons for the categories */ string = g_string_new (NULL); e_cal_component_get_categories_list (comp, &list); if (list != NULL) - gtk_html_stream_printf (stream, "<H3>%s ", _("Categories:")); + g_string_append_printf (buffer, "<H3>%s ", _("Categories:")); for (iter = list; iter != NULL; iter = iter->next) { const gchar *category = iter->data; const gchar *icon_file; @@ -123,8 +122,8 @@ cal_component_preview_write_html (GtkHTMLStream *stream, gchar *uri; uri = g_filename_to_uri (icon_file, NULL, NULL); - gtk_html_stream_printf ( - stream, "<IMG ALT=\"%s\" SRC=\"%s\">", + g_string_append_printf ( + buffer, "<IMG ALT=\"%s\" SRC=\"%s\">", category, uri); g_free (uri); } else { @@ -134,28 +133,34 @@ cal_component_preview_write_html (GtkHTMLStream *stream, } } if (string->len > 0) - gtk_html_stream_printf (stream, "%s", string->str); + g_string_append_printf (buffer, "%s", string->str); if (list != NULL) - gtk_html_stream_printf (stream, "</H3>"); + g_string_append (buffer, "</H3>"); e_cal_component_free_categories_list (list); g_string_free (string, TRUE); /* Start table */ - gtk_html_stream_printf (stream, "<TABLE BORDER=\"0\" WIDTH=\"80%%\">" - "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\" WIDTH=\"15%%\"></TD></TR>"); + g_string_append ( + buffer, "<TABLE BORDER=\"0\" WIDTH=\"80%%\">" + "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\" WIDTH=\"15%%\">" + "</TD></TR>"); /* write location */ e_cal_component_get_location (comp, &location); if (location) - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\" WIDTH=\"15%%\"><B>%s</B></TD><TD>%s</TD></TR>", - _("Summary:"), text.value); + g_string_append_printf ( + buffer, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\" " + "WIDTH=\"15%%\"><B>%s</B></TD><TD>%s</TD></TR>", + _("Summary:"), text.value); /* write start date */ e_cal_component_get_dtstart (comp, &dt); if (dt.value != NULL) { str = timet_to_str_with_zone (&dt, ecal, default_zone); - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>", - _("Start Date:"), str); + g_string_append_printf ( + buffer, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\">" + "<B>%s</B></TD><TD>%s</TD></TR>", + _("Start Date:"), str); g_free (str); } @@ -165,8 +170,10 @@ cal_component_preview_write_html (GtkHTMLStream *stream, e_cal_component_get_dtend (comp, &dt); if (dt.value != NULL) { str = timet_to_str_with_zone (&dt, ecal, default_zone); - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>", - _("Start Date:"), str); + g_string_append_printf ( + buffer, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\">" + "<B>%s</B></TD><TD>%s</TD></TR>", + _("Start Date:"), str); g_free (str); } @@ -176,8 +183,10 @@ cal_component_preview_write_html (GtkHTMLStream *stream, e_cal_component_get_due (comp, &dt); if (dt.value != NULL) { str = timet_to_str_with_zone (&dt, ecal, default_zone); - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD><TD>%s</TD></TR>", - _("Due Date:"), str); + g_string_append_printf ( + buffer, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\">" + "<B>%s</B></TD><TD>%s</TD></TR>", + _("Due Date:"), str); g_free (str); } @@ -188,7 +197,9 @@ cal_component_preview_write_html (GtkHTMLStream *stream, icalprop = icalcomponent_get_first_property ( icalcomp, ICAL_STATUS_PROPERTY); if (icalprop != NULL) { - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Status:")); + g_string_append_printf ( + buffer, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\">" + "<B>%s</B></TD>", _("Status:")); e_cal_component_get_status (comp, &status); switch (status) { case ICAL_STATUS_INPROCESS : @@ -206,14 +217,16 @@ cal_component_preview_write_html (GtkHTMLStream *stream, break; } - gtk_html_stream_printf (stream, "<TD>%s</TD></TR>", str); + g_string_append_printf (buffer, "<TD>%s</TD></TR>", str); g_free (str); } /* write priority */ e_cal_component_get_priority (comp, &priority_value); if (priority_value && *priority_value != 0) { - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Priority:")); + g_string_append_printf ( + buffer, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\">" + "<B>%s</B></TD>", _("Priority:")); if (*priority_value <= 4) str = g_strdup (_("High")); else if (*priority_value == 5) @@ -221,7 +234,7 @@ cal_component_preview_write_html (GtkHTMLStream *stream, else str = g_strdup (_("Low")); - gtk_html_stream_printf (stream, "<TD>%s</TD></TR>", str); + g_string_append_printf (buffer, "<TD>%s</TD></TR>", str); g_free (str); } @@ -230,29 +243,36 @@ cal_component_preview_write_html (GtkHTMLStream *stream, e_cal_component_free_priority (priority_value); /* write description and URL */ - gtk_html_stream_printf (stream, "<TR><TD COLSPAN=\"2\"><HR></TD></TR>"); + g_string_append (buffer, "<TR><TD COLSPAN=\"2\"><HR></TD></TR>"); e_cal_component_get_description_list (comp, &list); if (list) { GSList *node; - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Description:")); + g_string_append_printf ( + buffer, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\">" + "<B>%s</B></TD>", _("Description:")); - gtk_html_stream_printf (stream, "<TD><TT>"); + g_string_append (buffer, "<TD><TT>"); for (node = list; node != NULL; node = node->next) { gchar *html; text = * (ECalComponentText *) node->data; - html = camel_text_to_html (text.value ? text.value : "", CAMEL_MIME_FILTER_TOHTML_CONVERT_NL | CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES | CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0); + html = camel_text_to_html ( + text.value ? text.value : "", + CAMEL_MIME_FILTER_TOHTML_CONVERT_NL | + CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES | + CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | + CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES, 0); if (html) - gtk_html_stream_printf (stream, "%s", html); + g_string_append_printf (buffer, "%s", html); g_free (html); } - gtk_html_stream_printf (stream, "</TT></TD></TR>"); + g_string_append (buffer, "</TT></TD></TR>"); e_cal_component_free_text_list (list); } @@ -260,14 +280,18 @@ cal_component_preview_write_html (GtkHTMLStream *stream, /* URL */ e_cal_component_get_url (comp, (const gchar **) &str); if (str) { - gtk_html_stream_printf (stream, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\"><B>%s</B></TD>", _("Web Page:")); - gtk_html_stream_printf (stream, "<TD><A HREF=\"%s\">%s</A></TD></TR>", str, str); + g_string_append_printf ( + buffer, "<TR><TD VALIGN=\"TOP\" ALIGN=\"RIGHT\">" + "<B>%s</B></TD>", _("Web Page:")); + g_string_append_printf ( + buffer, "<TD><A HREF=\"%s\">%s</A></TD></TR>", + str, str); } - gtk_html_stream_printf (stream, "</TABLE>"); + g_string_append (buffer, "</TABLE>"); /* close document */ - gtk_html_stream_printf (stream, "</BODY></HTML>"); + g_string_append (buffer, "</BODY></HTML>"); } static void @@ -347,13 +371,16 @@ e_cal_component_preview_display (ECalComponentPreview *preview, ECal *ecal, ECalComponent *comp) { - GtkHTMLStream *stream; + GString *buffer; g_return_if_fail (E_IS_CAL_COMPONENT_PREVIEW (preview)); g_return_if_fail (E_IS_CAL_COMPONENT (comp)); - stream = gtk_html_begin (GTK_HTML (preview)); + /* XXX The initial buffer size is arbitrary. Tune it. */ + + buffer = g_string_sized_new (4096); cal_component_preview_write_html ( - stream, ecal, comp, preview->priv->zone); - gtk_html_stream_close (stream, GTK_HTML_STREAM_OK); + buffer, ecal, comp, preview->priv->zone); + e_web_view_load_string (E_WEB_VIEW (preview), buffer->str); + g_string_free (buffer, TRUE); } diff --git a/calendar/gui/e-itip-control.c b/calendar/gui/e-itip-control.c index dd231548e1..5b995d60a0 100644 --- a/calendar/gui/e-itip-control.c +++ b/calendar/gui/e-itip-control.c @@ -33,7 +33,6 @@ #include <glib/gstdio.h> #include <gtkhtml/gtkhtml.h> #include <gtkhtml/gtkhtml-embedded.h> -#include <gtkhtml/gtkhtml-stream.h> #include <libedataserver/e-source-list.h> #include <libedataserverui/e-source-combo-box.h> #include <libical/ical.h> @@ -50,10 +49,11 @@ #include "itip-utils.h" #include "e-itip-control.h" #include "common/authentication.h" +#include "widgets/misc/e-web-view.h" #include <shell/e-shell.h> struct _EItipControlPrivate { - GtkWidget *html; + GtkWidget *web_view; ESourceList *source_lists[E_CAL_SOURCE_TYPE_LAST]; GHashTable *ecals[E_CAL_SOURCE_TYPE_LAST]; @@ -109,7 +109,6 @@ struct _EItipControlPrivate { static void e_itip_control_destroy (GtkObject *obj); static void find_my_address (EItipControl *itip, icalcomponent *ical_comp, icalparameter_partstat *status); -static void url_requested_cb (GtkHTML *html, const gchar *url, GtkHTMLStream *handle, gpointer data); static gboolean object_requested_cb (GtkHTML *html, GtkHTMLEmbedded *eb, gpointer data); static void ok_clicked_cb (GtkWidget *widget, gpointer data); @@ -386,7 +385,7 @@ html_destroyed (gpointer data) priv = itip->priv; - priv->html = NULL; + priv->web_view = NULL; } static void @@ -423,11 +422,8 @@ e_itip_control_init (EItipControl *itip) priv->view_only = 0; /* Html Widget */ - priv->html = gtk_html_new (); - gtk_html_set_default_content_type (GTK_HTML (priv->html), - "text/html; charset=utf-8"); - gtk_html_load_from_string (GTK_HTML (priv->html), " ", 1); - gtk_widget_show (priv->html); + priv->web_view = e_web_view_new (); + gtk_widget_show (priv->web_view); scrolled_window = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), @@ -435,14 +431,17 @@ e_itip_control_init (EItipControl *itip) GTK_POLICY_AUTOMATIC); gtk_widget_show (scrolled_window); - gtk_container_add (GTK_CONTAINER (scrolled_window), priv->html); - g_object_weak_ref (G_OBJECT (priv->html), (GWeakNotify)html_destroyed, itip); + gtk_container_add (GTK_CONTAINER (scrolled_window), priv->web_view); + g_object_weak_ref (G_OBJECT (priv->web_view), (GWeakNotify)html_destroyed, itip); gtk_widget_set_size_request (scrolled_window, 600, 400); gtk_box_pack_start (GTK_BOX (itip), scrolled_window, FALSE, FALSE, 6); - g_signal_connect (priv->html, "url_requested", G_CALLBACK (url_requested_cb), itip); - g_signal_connect (priv->html, "object_requested", G_CALLBACK (object_requested_cb), itip); - g_signal_connect (priv->html, "submit", G_CALLBACK (ok_clicked_cb), itip); + g_signal_connect ( + priv->web_view, "object-requested", + G_CALLBACK (object_requested_cb), itip); + g_signal_connect ( + priv->web_view, "submit", + G_CALLBACK (ok_clicked_cb), itip); } static void @@ -511,9 +510,9 @@ e_itip_control_destroy (GtkObject *obj) } } - if (priv->html) { - g_signal_handlers_disconnect_matched (priv->html, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, itip); - g_object_weak_unref (G_OBJECT (priv->html), (GWeakNotify)html_destroyed, itip); + if (priv->web_view) { + g_signal_handlers_disconnect_matched (priv->web_view, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, itip); + g_object_weak_unref (G_OBJECT (priv->web_view), (GWeakNotify)html_destroyed, itip); } g_free (priv); @@ -891,16 +890,15 @@ write_recurrence_piece (EItipControl *itip, ECalComponent *comp, } static void -set_date_label (EItipControl *itip, GtkHTML *html, GtkHTMLStream *html_stream, - ECalComponent *comp) +set_date_label (EItipControl *itip, + GString *buffer, + ECalComponent *comp) { ECalComponentDateTime datetime; - GString *buffer; gchar *str; gboolean wrote = FALSE, task_completed = FALSE; ECalComponentVType type; - buffer = g_string_sized_new (1024); type = e_cal_component_get_vtype (comp); e_cal_component_get_dtstart (comp, &datetime); @@ -908,38 +906,26 @@ set_date_label (EItipControl *itip, GtkHTML *html, GtkHTMLStream *html_stream, /* For Translators : 'Starts' is part of "Starts: date", showing when the event starts */ str = g_strdup_printf ("<b>%s:</b>", _("Starts")); write_label_piece (itip, &datetime, buffer, str, "<br>", FALSE); - gtk_html_write (html, html_stream, buffer->str, buffer->len); wrote = TRUE; g_free (str); } e_cal_component_free_datetime (&datetime); - /* Reset the buffer. */ - g_string_truncate (buffer, 0); - e_cal_component_get_dtend (comp, &datetime); if (datetime.value) { /* For Translators : 'Ends' is part of "Ends: date", showing when the event ends */ str = g_strdup_printf ("<b>%s:</b>", _("Ends")); write_label_piece (itip, &datetime, buffer, str, "<br>", FALSE); - gtk_html_write (html, html_stream, buffer->str, buffer->len); wrote = TRUE; g_free (str); } e_cal_component_free_datetime (&datetime); - /* Reset the buffer. */ - g_string_truncate (buffer, 0); - if (e_cal_component_has_recurrences (comp)) { write_recurrence_piece (itip, comp, buffer); - gtk_html_write (html, html_stream, buffer->str, buffer->len); wrote = TRUE; } - /* Reset the buffer. */ - g_string_truncate (buffer, 0); - datetime.tzid = NULL; e_cal_component_get_completed (comp, &datetime.value); if (type == E_CAL_COMPONENT_TODO && datetime.value) { @@ -948,21 +934,16 @@ set_date_label (EItipControl *itip, GtkHTML *html, GtkHTMLStream *html_stream, str = g_strdup_printf ("<b>%s:</b>", _("Completed")); datetime.value->is_utc = TRUE; write_label_piece (itip, &datetime, buffer, str, "<br>", FALSE); - gtk_html_write (html, html_stream, buffer->str, buffer->len); wrote = TRUE; task_completed = TRUE; g_free (str); } e_cal_component_free_datetime (&datetime); - /* Reset the buffer. */ - g_string_truncate (buffer, 0); - e_cal_component_get_due (comp, &datetime); if (type == E_CAL_COMPONENT_TODO && !task_completed && datetime.value) { str = g_strdup_printf ("<b>%s:</b>", _("Due")); write_label_piece (itip, &datetime, buffer, str, "<br>", FALSE); - gtk_html_write (html, html_stream, buffer->str, buffer->len); wrote = TRUE; g_free (str); } @@ -970,21 +951,24 @@ set_date_label (EItipControl *itip, GtkHTML *html, GtkHTMLStream *html_stream, e_cal_component_free_datetime (&datetime); if (wrote) - gtk_html_stream_printf (html_stream, "<br>"); - - g_string_free (buffer, TRUE); + g_string_append (buffer, "<br>"); } static void -set_message (GtkHTML *html, GtkHTMLStream *html_stream, const gchar *message, gboolean err) +set_message (GString *buffer, + const gchar *message, + gboolean err) { if (message == NULL) return; if (err) { - gtk_html_stream_printf (html_stream, "<b><font color=\"#ff0000\">%s</font></b><br><br>", message); + g_string_append_printf ( + buffer, "<b><font color=\"#ff0000\">%s</font></b>" + "<br><br>", message); } else { - gtk_html_stream_printf (html_stream, "<b>%s</b><br><br>", message); + g_string_append_printf ( + buffer, "<b>%s</b><br><br>", message); } } @@ -992,91 +976,96 @@ static void write_error_html (EItipControl *itip, const gchar *itip_err) { EItipControlPrivate *priv; - GtkHTMLStream *html_stream; + GString *buffer; gchar *filename; priv = itip->priv; - /* Html widget */ - html_stream = gtk_html_begin (GTK_HTML (priv->html)); - gtk_html_stream_printf (html_stream, - "<html><head><title>%s</title></head>", - _("iCalendar Information")); + buffer = g_string_sized_new (1024); + + g_string_append_printf ( + buffer, "<html><head><title>%s</title></head>", + _("iCalendar Information")); - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_BODY_START, strlen(HTML_BODY_START)); + g_string_append (buffer, HTML_BODY_START); /* The table */ - gtk_html_stream_printf (html_stream, "<table width=450 cellspacing=\"0\" cellpadding=\"4\" border=\"0\">"); + g_string_append ( + buffer, "<table width=450 cellspacing=\"0\" " + "cellpadding=\"4\" border=\"0\">"); /* The column for the image */ - gtk_html_stream_printf (html_stream, "<tr><td width=48 align=\"center\" valign=\"top\" rowspan=\"8\">"); + g_string_append ( + buffer, "<tr><td width=48 align=\"center\" " + "valign=\"top\" rowspan=\"8\">"); /* The image */ - filename = e_icon_factory_get_icon_filename ("stock_new-meeting", GTK_ICON_SIZE_DIALOG); - gtk_html_stream_printf (html_stream, "<img src=\"%s\"></td>", filename); + filename = e_icon_factory_get_icon_filename ( + "stock_new-meeting", GTK_ICON_SIZE_DIALOG); + g_string_append_printf ( + buffer, "<img src=\"%s\"></td>", filename); g_free (filename); - gtk_html_stream_printf (html_stream, "<td align=\"left\" valign=\"top\">"); + g_string_append (buffer, "<td align=\"left\" valign=\"top\">"); /* Title */ - set_message (GTK_HTML (priv->html), html_stream, _("iCalendar Error"), TRUE); + set_message (buffer, _("iCalendar Error"), TRUE); /* Error */ - gtk_html_write (GTK_HTML (priv->html), html_stream, itip_err, strlen(itip_err)); + g_string_append_printf (buffer, "%s", itip_err); /* Clean up */ - gtk_html_stream_printf (html_stream, "</td></tr></table>"); + g_string_append (buffer, "</td></tr></table>"); - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_BODY_END, strlen(HTML_BODY_END)); - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_FOOTER, strlen(HTML_FOOTER)); + g_string_append (buffer, HTML_BODY_END); + g_string_append (buffer, HTML_FOOTER); - gtk_html_end (GTK_HTML (priv->html), html_stream, GTK_HTML_STREAM_OK); + e_web_view_load_string (E_WEB_VIEW (priv->web_view), buffer->str); + + g_string_free (buffer, TRUE); } static void write_html (EItipControl *itip, const gchar *itip_desc, const gchar *itip_title, const gchar *options) { EItipControlPrivate *priv; - GtkHTMLStream *html_stream; ECalComponentText text; ECalComponentOrganizer organizer; ECalComponentAttendee *attendee; GSList *attendees, *l = NULL; + GString *buffer; const gchar *string; gchar *html; - const gchar *const_html; gchar *filename; gchar *str; priv = itip->priv; - if (priv->html == NULL) + if (priv->web_view == NULL) return; - /* Html widget */ - html_stream = gtk_html_begin (GTK_HTML (priv->html)); - gtk_html_stream_printf (html_stream, - "<html><head><title>%s</title></head>", - _("iCalendar Information")); - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_BODY_START, strlen(HTML_BODY_START)); + buffer = g_string_sized_new (4096); + + g_string_append_printf ( + buffer, "<html><head><title>%s</title></head>", + _("iCalendar Information")); + g_string_append (buffer, HTML_BODY_START); /* The table */ - const_html = "<table width=450 cellspacing=\"0\" cellpadding=\"4\" border=\"0\">"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); + g_string_append ( + buffer, "<table width=450 cellspacing=\"0\" " + "cellpadding=\"4\" border=\"0\">"); /* The column for the image */ - const_html = "<tr><td width=48 align=\"center\" valign=\"top\" rowspan=\"8\">"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); + g_string_append ( + buffer, "<tr><td width=48 align=\"center\" " + "valign=\"top\" rowspan=\"8\">"); /* The image */ - filename = e_icon_factory_get_icon_filename ("stock_new-meeting", GTK_ICON_SIZE_DIALOG); - gtk_html_stream_printf (html_stream, "<img src=\"%s\"></td>", filename); + filename = e_icon_factory_get_icon_filename ( + "stock_new-meeting", GTK_ICON_SIZE_DIALOG); + g_string_append_printf (buffer, "<img src=\"%s\"></td>", filename); g_free (filename); - const_html = "<td align=\"left\" valign=\"top\">"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); + g_string_append (buffer, "<td align=\"left\" valign=\"top\">"); switch (priv->method) { case ICAL_METHOD_REFRESH: @@ -1137,30 +1126,30 @@ write_html (EItipControl *itip, const gchar *itip_desc, const gchar *itip_title, html = g_strdup_printf (itip_desc, _("An unknown person")); break; } - gtk_html_write (GTK_HTML (priv->html), html_stream, html, strlen(html)); + g_string_append_printf (buffer, "%s", html); g_free (html); /* Describe what the user can do */ - const_html = _("<br> Please review the following information, " - "and then select an action from the menu below."); - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); + g_string_append ( + buffer, _("<br> Please review the following information, " + "and then select an action from the menu below.")); /* Separator */ - gtk_html_write (GTK_HTML (priv->html), html_stream, HTML_SEP, strlen (HTML_SEP)); + g_string_append (buffer, HTML_SEP); /* Title */ - set_message (GTK_HTML (priv->html), html_stream, itip_title, FALSE); + set_message (buffer, itip_title, FALSE); /* Date information */ - set_date_label (itip, GTK_HTML (priv->html), html_stream, priv->comp); + set_date_label (itip, buffer, priv->comp); /* Summary */ e_cal_component_get_summary (priv->comp, &text); str = g_strdup_printf ("<i>%s:</i>", _("None")); html = text.value ? e_text_to_html_full (text.value, E_TEXT_TO_HTML_CONVERT_NL, 0) : str; - gtk_html_stream_printf (html_stream, "<b>%s</b><br>%s<br><br>", - _("Summary:"), html); + g_string_append_printf ( + buffer, "<b>%s</b><br>%s<br><br>", _("Summary:"), html); g_free (str); if (text.value) g_free (html); @@ -1169,8 +1158,9 @@ write_html (EItipControl *itip, const gchar *itip_desc, const gchar *itip_title, e_cal_component_get_location (priv->comp, &string); if (string != NULL) { html = e_text_to_html_full (string, E_TEXT_TO_HTML_CONVERT_NL, 0); - gtk_html_stream_printf (html_stream, "<b>%s</b><br>%s<br><br>", - _("Location:"), html); + g_string_append_printf ( + buffer, "<b>%s</b><br>%s<br><br>", + _("Location:"), html); g_free (html); } @@ -1183,25 +1173,29 @@ write_html (EItipControl *itip, const gchar *itip_desc, const gchar *itip_title, if (alist != NULL) { ECalComponentAttendee *a = alist->data; - gtk_html_stream_printf (html_stream, "<b>%s</b><br>", - _("Status:")); + g_string_append_printf ( + buffer, "<b>%s</b><br>", _("Status:")); switch (a->status) { case ICAL_PARTSTAT_ACCEPTED: - gtk_html_stream_printf (html_stream, "%s<br><br>", - _("Accepted")); + g_string_append_printf ( + buffer, "%s<br><br>", + _("Accepted")); break; case ICAL_PARTSTAT_TENTATIVE: - gtk_html_stream_printf (html_stream, "%s<br><br>", - _("Tentatively Accepted")); + g_string_append_printf ( + buffer, "%s<br><br>", + _("Tentatively Accepted")); break; case ICAL_PARTSTAT_DECLINED: - gtk_html_stream_printf (html_stream, "%s<br><br>", - _("Declined")); + g_string_append_printf ( + buffer, "%s<br><br>", + _("Declined")); break; default: - gtk_html_stream_printf (html_stream, "%s<br><br>", - _("Unknown")); + g_string_append_printf ( + buffer, "%s<br><br>", + _("Unknown")); } } @@ -1214,34 +1208,35 @@ write_html (EItipControl *itip, const gchar *itip_desc, const gchar *itip_title, text = *((ECalComponentText *)l->data); if (l && text.value) { - html = e_text_to_html_full (text.value, E_TEXT_TO_HTML_CONVERT_NL, 0); - gtk_html_stream_printf (html_stream, "<b>%s</b><br>%s", - _("Description:"), html); + html = e_text_to_html_full ( + text.value, E_TEXT_TO_HTML_CONVERT_NL, 0); + g_string_append_printf ( + buffer, "<b>%s</b><br>%s", + _("Description:"), html); g_free (html); } e_cal_component_free_text_list (l); /* Separator */ - gtk_html_write (GTK_HTML (priv->html), html_stream, HTML_SEP, strlen (HTML_SEP)); + g_string_append (buffer, HTML_SEP); /* Options */ if (!e_itip_control_get_view_only (itip)) { if (options != NULL) { - const_html = "</td></tr><tr><td valign=\"center\">"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen (const_html)); - gtk_html_write (GTK_HTML (priv->html), html_stream, options, strlen (options)); + g_string_append ( + buffer, "</td></tr><tr><td valign=\"center\">"); + g_string_append_printf (buffer, "%s", options); } } - const_html = "</td></tr></table>"; - gtk_html_write (GTK_HTML (priv->html), html_stream, const_html, strlen(const_html)); + g_string_append (buffer, "</td></tr></table>"); + + g_string_append (buffer, HTML_BODY_END); + g_string_append (buffer, HTML_FOOTER); - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_BODY_END, strlen(HTML_BODY_END)); - gtk_html_write (GTK_HTML (priv->html), html_stream, - HTML_FOOTER, strlen(HTML_FOOTER)); + e_web_view_load_string (E_WEB_VIEW (priv->web_view), buffer->str); - gtk_html_end (GTK_HTML (priv->html), html_stream, GTK_HTML_STREAM_OK); + g_string_free (buffer, TRUE); } static gchar * @@ -1684,7 +1679,7 @@ e_itip_control_set_data (EItipControl *itip, const gchar *text) clean_up (itip); if (text == NULL || *text == '\0') { - gtk_html_load_from_string (GTK_HTML (priv->html), " ", 1); + e_web_view_clear (E_WEB_VIEW (priv->web_view)); return; } @@ -2175,31 +2170,6 @@ send_freebusy (EItipControl *itip) gtk_widget_destroy (dialog); } -static void -url_requested_cb (GtkHTML *html, const gchar *url, GtkHTMLStream *handle, gpointer data) -{ guchar buffer[4096]; - gint len, fd; - - if ((fd = g_open (url, O_RDONLY|O_BINARY, 0)) == -1) { - g_warning ("%s", g_strerror (errno)); - return; - } - - while ((len = read (fd, buffer, 4096)) > 0) { - gtk_html_write (html, handle, (gchar *)buffer, len); - } - - if (len < 0) { - /* check to see if we stopped because of an error */ - gtk_html_end (html, handle, GTK_HTML_STREAM_ERROR); - g_warning ("%s", g_strerror (errno)); - return; - } - /* done with no errors */ - gtk_html_end (html, handle, GTK_HTML_STREAM_OK); - close (fd); -} - static GtkWidget * create_combo_box (void) { diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c index 3bfa077b24..73e2621a26 100644 --- a/mail/e-mail-reader.c +++ b/mail/e-mail-reader.c @@ -23,8 +23,6 @@ #include <glib/gi18n.h> #include <gdk/gdkkeysyms.h> -#include <gtkhtml/gtkhtml.h> -#include <gtkhtml/gtkhtml-stream.h> #ifdef HAVE_XFREE #include <X11/XF86keysym.h> |