From badc0e6156777c65885bad6858a6f44f7cbf037e Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 20 May 2013 13:41:57 -0400 Subject: Simplify EABContactFormatter. Simplify the EABContactFormatter API as follows: * Drop all constructor arguments from eab_contact_formatter_new() since get/set functions exist for all of them. * Remove eab_contact_formatter_format_contact_async() since EABContactFormatter does not block. * Replace eab_contact_formatter_format_contact_sync() with eab_contact_formatter_format_contact() which drops the CamelStream and GCancellable arguments and takes a GString as an output buffer. * Remove the "state" and "style" properties, and always use a white background when rendering the full contact. This is particularly important since render_normal() dereferenced the GtkStyle without checking for NULL, which would crash on mails with a vCard MIME part when "Show Full vCard" was clicked, because the "vcard-inline" module never set a GtkStyle. --- addressbook/gui/widgets/eab-contact-display.c | 56 ++++++--------------------- 1 file changed, 12 insertions(+), 44 deletions(-) (limited to 'addressbook/gui/widgets/eab-contact-display.c') diff --git a/addressbook/gui/widgets/eab-contact-display.c b/addressbook/gui/widgets/eab-contact-display.c index e71ea23b9f..c467e385e4 100644 --- a/addressbook/gui/widgets/eab-contact-display.c +++ b/addressbook/gui/widgets/eab-contact-display.c @@ -47,8 +47,6 @@ struct _EABContactDisplayPrivate { EABContactDisplayMode mode; gboolean show_maps; - - GCancellable *formatter_cancellable; }; enum { @@ -162,63 +160,33 @@ static GtkActionEntry internal_mailto_entries[] = { G_CALLBACK (action_contact_send_message_cb) } }; -static void -contact_formatting_finished (GObject *object, - GSimpleAsyncResult *result, - gpointer user_data) -{ - EABContactDisplay *display = user_data; - CamelStreamMem *stream; - gchar *html; - GByteArray *ba; - - stream = g_simple_async_result_get_op_res_gpointer (result); - /* The operation was probably cancelled */ - if (!stream) - return; - - ba = camel_stream_mem_get_byte_array (stream); - - html = g_strndup ((gchar *) ba->data, ba->len); - e_web_view_load_string (E_WEB_VIEW (display), html); - - g_free (html); - g_object_unref (stream); - g_object_unref (object); - g_clear_object (&display->priv->formatter_cancellable); -} - static void load_contact (EABContactDisplay *display) { EABContactFormatter *formatter; - - if (display->priv->formatter_cancellable) { - g_cancellable_cancel (display->priv->formatter_cancellable); - g_clear_object (&display->priv->formatter_cancellable); - } + GString *buffer; if (!display->priv->contact) { e_web_view_clear (E_WEB_VIEW (display)); return; } - formatter = eab_contact_formatter_new ( - display->priv->mode, - display->priv->show_maps); + formatter = eab_contact_formatter_new (); g_object_set ( G_OBJECT (formatter), - "style", gtk_widget_get_style (GTK_WIDGET (display)), - "state", gtk_widget_get_state (GTK_WIDGET (display)), + "display-mode", display->priv->mode, + "render-maps", display->priv->show_maps, NULL); - display->priv->formatter_cancellable = g_cancellable_new (); + buffer = g_string_sized_new (1024); + + eab_contact_formatter_format_contact ( + formatter, display->priv->contact, buffer); + e_web_view_load_string (E_WEB_VIEW (display), buffer->str); + + g_string_free (buffer, TRUE); - eab_contact_formatter_format_contact_async ( - formatter, display->priv->contact, - display->priv->formatter_cancellable, - (GAsyncReadyCallback) contact_formatting_finished, - display); + g_object_unref (formatter); } static void -- cgit v1.2.3