[evolution/gnome-3-4] Bug #674381 - Show contact photo from address book doesn't work
- From: Dan VrÃtil <dvratil src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution/gnome-3-4] Bug #674381 - Show contact photo from address book doesn't work
- Date: Fri, 27 Apr 2012 18:35:28 +0000 (UTC)
commit c219cb1dec286cea39c0a7d8455319c3677d3600
Author: Dan VrÃtil <dvratil redhat com>
Date: Fri Apr 27 20:29:02 2012 +0200
Bug #674381 - Show contact photo from address book doesn't work
libemail-engine/e-mail-utils.c | 53 ++++++++++++++++++++++++----------------
mail/em-format-html.c | 13 ++++++++-
2 files changed, 43 insertions(+), 23 deletions(-)
---
diff --git a/libemail-engine/e-mail-utils.c b/libemail-engine/e-mail-utils.c
index 58fdcc3..b79d6a1 100644
--- a/libemail-engine/e-mail-utils.c
+++ b/libemail-engine/e-mail-utils.c
@@ -693,8 +693,8 @@ em_utils_contact_photo (CamelInternetAddress *cia,
const gchar *addr = NULL;
CamelMimePart *part = NULL;
EContactPhoto *photo = NULL;
- GSList *p, *first_not_null = NULL;
- gint count_not_null = 0;
+ GSList *p, *last = NULL;
+ gint cache_len;
if (cia == NULL || !camel_internet_address_get (cia, 0, NULL, &addr) || !addr) {
return NULL;
@@ -703,22 +703,21 @@ em_utils_contact_photo (CamelInternetAddress *cia,
G_LOCK (photos_cache);
/* search a cache first */
+ cache_len = 0;
+ last = NULL;
for (p = photos_cache; p; p = p->next) {
PhotoInfo *pi = p->data;
if (!pi)
continue;
- if (pi->photo) {
- if (!first_not_null)
- first_not_null = p;
- count_not_null++;
- }
-
if (g_ascii_strcasecmp (addr, pi->address) == 0) {
photo = pi->photo;
break;
}
+
+ cache_len++;
+ last = p;
}
/* !p means the address had not been found in the cache */
@@ -726,34 +725,46 @@ em_utils_contact_photo (CamelInternetAddress *cia,
addr, local_only, extract_photo_data, &photo)) {
PhotoInfo *pi;
- if (photo && photo->type != E_CONTACT_PHOTO_TYPE_INLINED) {
- e_contact_photo_free (photo);
- photo = NULL;
- }
-
/* keep only up to 10 photos in memory */
- if (photo && count_not_null >= 10 && first_not_null) {
- pi = first_not_null->data;
-
+ if (last && (cache_len >= 10)) {
+ pi = last->data;
photos_cache = g_slist_remove (photos_cache, pi);
- emu_free_photo_info (pi);
+ if (pi)
+ emu_free_photo_info (pi);
}
pi = g_new0 (PhotoInfo, 1);
pi->address = g_strdup (addr);
pi->photo = photo;
- photos_cache = g_slist_append (photos_cache, pi);
+ photos_cache = g_slist_prepend (photos_cache, pi);
}
/* some photo found, use it */
if (photo) {
/* Form a mime part out of the photo */
part = camel_mime_part_new ();
- camel_mime_part_set_content (part,
- (const gchar *) photo->data.inlined.data,
- photo->data.inlined.length, "image/jpeg");
+
+ if (photo->type == E_CONTACT_PHOTO_TYPE_INLINED) {
+ camel_mime_part_set_content (part,
+ (const gchar *) photo->data.inlined.data,
+ photo->data.inlined.length, "image/jpeg");
+ } else {
+ gchar *filename = g_filename_from_uri (photo->data.uri, NULL, NULL);
+ gchar *data;
+ gsize len;
+
+ if (g_file_get_contents (filename, &data, &len, NULL)) {
+ camel_mime_part_set_content (part, data, len, "image/jpeg");
+ g_free (data);
+ } else {
+ g_object_unref (part);
+ part = NULL;
+ }
+
+ g_free (filename);
+ }
}
G_UNLOCK (photos_cache);
diff --git a/mail/em-format-html.c b/mail/em-format-html.c
index 6c4c2d7..6bf6769 100644
--- a/mail/em-format-html.c
+++ b/mail/em-format-html.c
@@ -861,6 +861,7 @@ efh_busy (EMFormat *emf)
return (priv->format_id != -1);
}
+
static void
efh_base_init (EMFormatHTMLClass *class)
{
@@ -868,6 +869,15 @@ efh_base_init (EMFormatHTMLClass *class)
}
static void
+efh_constructed (GObject *object)
+{
+ /* Chain up to parent's constructed() method. */
+ G_OBJECT_CLASS (parent_class)->constructed (object);
+
+ e_extensible_load_extensions (E_EXTENSIBLE (object));
+}
+
+static void
efh_class_init (EMFormatHTMLClass *class)
{
GObjectClass *object_class;
@@ -878,6 +888,7 @@ efh_class_init (EMFormatHTMLClass *class)
g_type_class_add_private (class, sizeof (EMFormatHTMLPrivate));
object_class = G_OBJECT_CLASS (class);
+ object_class->constructed = efh_constructed;
object_class->set_property = efh_set_property;
object_class->get_property = efh_get_property;
object_class->finalize = efh_finalize;
@@ -1104,8 +1115,6 @@ efh_init (EMFormatHTML *efh,
CAMEL_MIME_FILTER_TOHTML_MARK_CITATION;
efh->show_icon = TRUE;
efh->state = EM_FORMAT_HTML_STATE_NONE;
-
- e_extensible_load_extensions (E_EXTENSIBLE (efh));
}
GType
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]