From 02cbe55123aa9ee218ee6a33ffb19f7644110123 Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Tue, 1 Nov 2011 18:27:05 -0400 Subject: Teach Evolution about Photo/Logo EContact fields stored as URIs Committing Milan Crha's patch here at his request (bug 652178). --- addressbook/gui/widgets/eab-contact-display.c | 43 +++++++++++++++++++++------ addressbook/gui/widgets/eab-gui-util.c | 1 + 2 files changed, 35 insertions(+), 9 deletions(-) (limited to 'addressbook/gui') diff --git a/addressbook/gui/widgets/eab-contact-display.c b/addressbook/gui/widgets/eab-contact-display.c index da558352bb..d428f8ed77 100644 --- a/addressbook/gui/widgets/eab-contact-display.c +++ b/addressbook/gui/widgets/eab-contact-display.c @@ -427,6 +427,8 @@ render_title_block (GString *buffer, /* Only handle inlined photos for now */ if (photo && photo->type == E_CONTACT_PHOTO_TYPE_INLINED) { g_string_append (buffer, ""); + } else if (photo && photo->type == E_CONTACT_PHOTO_TYPE_URI && photo->data.uri && *photo->data.uri) { + g_string_append_printf (buffer, "", photo->data.uri); } if (photo) e_contact_photo_free (photo); @@ -929,7 +931,22 @@ eab_contact_display_render_compact (EABContactDisplay *display, * image here. we don't scale the pixbuf * itself, just insert width/height tags in * the html */ - gdk_pixbuf_loader_write (loader, photo->data.inlined.data, photo->data.inlined.length, NULL); + if (photo->type == E_CONTACT_PHOTO_TYPE_INLINED) { + gdk_pixbuf_loader_write (loader, photo->data.inlined.data, photo->data.inlined.length, NULL); + } else if (photo->type == E_CONTACT_PHOTO_TYPE_URI && photo->data.uri && + g_ascii_strncasecmp (photo->data.uri, "file://", 7) == 0) { + gchar *filename, *contents = NULL; + gsize length; + + filename = g_filename_from_uri (photo->data.uri, NULL, NULL); + if (filename) { + if (g_file_get_contents (filename, &contents, &length, NULL)) { + gdk_pixbuf_loader_write (loader, (const guchar *) contents, length, NULL); + g_free (contents); + } + g_free (filename); + } + } gdk_pixbuf_loader_close (loader, NULL); pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf) @@ -949,13 +966,20 @@ eab_contact_display_render_compact (EABContactDisplay *display, calced_width *= ((gfloat) MAX_COMPACT_IMAGE_DIMENSION / max_dimension); calced_height *= ((gfloat) MAX_COMPACT_IMAGE_DIMENSION / max_dimension); } + g_object_unref (pixbuf); } - g_object_unref (pixbuf); - g_string_append_printf ( - buffer, - "", - calced_width, calced_height); + if (photo->type == E_CONTACT_PHOTO_TYPE_URI && photo->data.uri && *photo->data.uri) + g_string_append_printf ( + buffer, + "", + calced_width, calced_height, photo->data.uri); + else + g_string_append_printf ( + buffer, + "", + calced_width, calced_height); + e_contact_photo_free (photo); } @@ -1174,9 +1198,10 @@ contact_display_url_requested (GtkHTML *html, if (photo == NULL) photo = e_contact_get (contact, E_CONTACT_LOGO); - gtk_html_stream_write ( - handle, (gchar *) photo->data.inlined.data, - photo->data.inlined.length); + if (photo->type == E_CONTACT_PHOTO_TYPE_INLINED) + gtk_html_stream_write ( + handle, (gchar *) photo->data.inlined.data, + photo->data.inlined.length); gtk_html_end (html, handle, GTK_HTML_STREAM_OK); diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c index eb98676169..befc8836ca 100644 --- a/addressbook/gui/widgets/eab-gui-util.c +++ b/addressbook/gui/widgets/eab-gui-util.c @@ -495,6 +495,7 @@ do_copy (gpointer data, contact = data; book_client = process->destination; + e_contact_inline_local_photos (contact, NULL); process->count++; eab_merging_book_add_contact ( -- cgit v1.2.3