[evolution] Teach Evolution about Photo/Logo EContact fields stored as URIs



commit 02cbe55123aa9ee218ee6a33ffb19f7644110123
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Tue Nov 1 18:27:05 2011 -0400

    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 +
 addressbook/util/eab-book-util.c              |    1 +
 3 files changed, 36 insertions(+), 9 deletions(-)
---
diff --git a/addressbook/gui/widgets/eab-contact-display.c b/addressbook/gui/widgets/eab-contact-display.c
index da55835..d428f8e 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, "<img border=\"1\" src=\"internal-contact-photo:\">");
+	} else if (photo && photo->type == E_CONTACT_PHOTO_TYPE_URI && photo->data.uri && *photo->data.uri) {
+		g_string_append_printf (buffer, "<img border=\"1\" src=\"%s\">", 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,
-				"<img width=\"%d\" height=\"%d\" src=\"internal-contact-photo:\">",
-				calced_width, calced_height);
+			if (photo->type == E_CONTACT_PHOTO_TYPE_URI && photo->data.uri && *photo->data.uri)
+				g_string_append_printf (
+					buffer,
+					"<img width=\"%d\" height=\"%d\" src=\"%s\">",
+					calced_width, calced_height, photo->data.uri);
+			else
+				g_string_append_printf (
+					buffer,
+					"<img width=\"%d\" height=\"%d\" src=\"internal-contact-photo:\">",
+					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 eb98676..befc883 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 (
diff --git a/addressbook/util/eab-book-util.c b/addressbook/util/eab-book-util.c
index eff5fc1..30cd2ac 100644
--- a/addressbook/util/eab-book-util.c
+++ b/addressbook/util/eab-book-util.c
@@ -136,6 +136,7 @@ eab_contact_list_to_string (const GSList *contacts)
 		EContact *contact = l->data;
 		gchar *vcard_str;
 
+		e_contact_inline_local_photos (contact, NULL);
 		vcard_str = e_vcard_to_string (
 			E_VCARD (contact), EVC_FORMAT_VCARD_30);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]