[folks] Don't manipulate the Avatar Cache before e-d-s acks changes



commit 19ae7a8f60aa04dc0548a41e6c976c3654709c22
Author: Raul Gutierrez Segales <rgs collabora co uk>
Date:   Thu Aug 4 15:44:28 2011 +0100

    Don't manipulate the Avatar Cache before e-d-s acks changes
    
    Also, lets set EContactPhotos as INLINED because it doesn't
    make sense to use URIs for local files. In the future, when
    we support gravatars, we'll have to handle the case of
    setting ContactPhotos as URIs for those.
    
    Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=655374

 backends/eds/lib/edsf-persona-store.vala |   51 +++++++++++++++++-------------
 1 files changed, 29 insertions(+), 22 deletions(-)
---
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index cdfb7bb..e9db1e4 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -841,38 +841,45 @@ public class Edsf.PersonaStore : Folks.PersonaStore
   private async void _set_contact_avatar (E.Contact contact,
       LoadableIcon? avatar)
     {
-      var uid = Folks.Persona.build_uid (BACKEND_NAME, this.id,
-          (string) Edsf.Persona._get_property_from_contact (contact, "id"));
-
-      var cache = AvatarCache.dup ();
-      if (avatar != null)
+      if (avatar == null)
+        {
+          unowned VCardAttribute attr = contact.get_attribute ("PHOTO");
+          if (attr != null)
+            {
+              contact.remove_attribute (attr);
+            }
+        }
+      else
         {
           try
             {
-              // Cache the avatar so that it has a URI
-              var uri = yield cache.store_avatar (uid, avatar);
-
-              // Set the avatar on the contact
+              /* Set the avatar on the contact */
               var cp = new ContactPhoto ();
-              cp.type = ContactPhotoType.URI;
-              cp.set_uri (uri);
+              cp.type = ContactPhotoType.INLINED;
+              var input_s = yield avatar.load_async (-1, null, null);
 
+              uint8[] image_data = new uint8[0];
+              uint8[] buffer = new uint8[4096];
+              while (true)
+                {
+                  var size_read = yield input_s.read_async (buffer);
+                  if (size_read <= 0)
+                    {
+                      break;
+                    }
+                  var read_cur = image_data.length;
+                  image_data.resize (read_cur + (int)size_read);
+                  Memory.copy (&image_data[read_cur], buffer, size_read);
+                }
+
+              cp.set_inlined (image_data);
               contact.set (ContactField.PHOTO, cp);
             }
           catch (GLib.Error e1)
             {
-              warning ("Couldn't cache avatar for Edsf.Persona '%s': %s",
-                  uid, e1.message);
-            }
-        }
-      else
-        {
-          // Delete any old avatar from the cache, ignoring errors
-          try
-            {
-              yield cache.remove_avatar (uid);
+              warning ("Couldn't set avatar on the EContact : %s",
+                  e1.message);
             }
-          catch (GLib.Error e2) {}
         }
     }
 



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