Support avatars (generally, and for the Telepathy backend)
authorTravis Reitter <travis.reitter@collabora.co.uk>
Fri, 11 Jun 2010 20:24:00 +0000 (13:24 -0700)
committerTravis Reitter <travis.reitter@collabora.co.uk>
Fri, 11 Jun 2010 20:27:36 +0000 (13:27 -0700)
.gitignore
backends/telepathy/tpf-persona.vala
configure.ac
folks/Makefile.am
folks/avatar.vala [new file with mode: 0644]
folks/individual.vala
folks/persona.vala

index 054eadf..f6d3361 100644 (file)
@@ -61,6 +61,7 @@ Makefile.in
 /backends/telepathy/tpf-persona.c
 /backends/telepathy/tpf-persona-store.c
 /folks/alias.c
+/folks/avatar.c
 /folks/backend.c
 /folks/backend-store.c
 /folks/capabilities.c
index 46f290e..c0c834e 100644 (file)
@@ -23,14 +23,17 @@ using GLib;
 using Tp;
 using Folks;
 
-public class Tpf.Persona : Folks.Persona, Alias, Folks.Capabilities, Groups,
-       Presence
+public class Tpf.Persona : Folks.Persona, Alias, Avatar, Folks.Capabilities,
+       Groups, Presence
 {
   private HashTable<string, bool> _groups;
 
   /* interface Alias */
   public override string alias { get; set; }
 
+  /* interface Avatar */
+  public override File avatar { get; set; }
+
   /* interface Capabilities */
   public override CapabilitiesFlags capabilities { get; private set; }
 
@@ -120,6 +123,12 @@ public class Tpf.Persona : Folks.Persona, Alias, Folks.Capabilities, Groups,
 
       this._groups = new HashTable<string, bool> (str_hash, str_equal);
 
+      contact.notify["avatar-file"].connect ((s, p) =>
+        {
+          this.set_avatar_from_contact ();
+        });
+      this.set_avatar_from_contact ();
+
       contact.notify["presence-message"].connect ((s, p) =>
         {
           this.contact_notify_presence_message ((Tp.Contact) s);
@@ -206,4 +215,11 @@ public class Tpf.Persona : Folks.Persona, Alias, Folks.Capabilities, Groups,
             return PresenceType.UNKNOWN;
         }
     }
+
+  private void set_avatar_from_contact ()
+    {
+      var file = this.contact.get_avatar_file ();
+      if (this.avatar != file)
+        this.avatar = file;
+    }
 }
index 5e2cda9..1d3a442 100644 (file)
@@ -3,7 +3,7 @@ m4_define(folks_released, 0)
 
 m4_define([folks_major_version], [0])
 m4_define([folks_minor_version], [1])
-m4_define([folks_micro_version], [1])
+m4_define([folks_micro_version], [2])
 m4_define([folks_nano_version], [0])
 
 dnl Display the nano_version only if it's not '0'
index 25fb23a..b303552 100644 (file)
@@ -25,6 +25,7 @@ lib_LTLIBRARIES = \
 
 libfolks_la_VALASOURCES = \
        alias.vala \
+       avatar.vala \
        backend.vala \
        backend-store.vala \
        capabilities.vala \
diff --git a/folks/avatar.vala b/folks/avatar.vala
new file mode 100644 (file)
index 0000000..0e3522b
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 Collabora Ltd.
+ *
+ * This library is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ *       Travis Reitter <travis.reitter@collabora.co.uk>
+ */
+
+using GLib;
+
+public interface Folks.Avatar : Object
+{
+  public abstract File avatar { get; set; }
+}
index 1d5dcba..afe753d 100644 (file)
 
 using Gee;
 using GLib;
-using Folks.Alias;
-using Folks.Capabilities;
-using Folks.Groups;
-using Folks.PersonaStore;
-using Folks.Presence;
+using Folks;
 
-public class Folks.Individual : Object, Alias, Capabilities, Groups, Presence
+public class Folks.Individual : Object, Alias, Avatar, Capabilities, Groups,
+       Presence
 {
   private HashTable<string, bool> _groups;
   private GLib.List<Persona> _personas;
@@ -35,6 +32,7 @@ public class Folks.Individual : Object, Alias, Capabilities, Groups, Presence
   /* XXX: should setting this push it down into the Persona (to foward along to
    * the actual store if possible?) */
   public string alias { get; set; }
+  public File avatar { get; set; }
   public CapabilitiesFlags capabilities { get; private set; }
   public string id { get; private set; }
   public Folks.PresenceType presence_type { get; private set; }
@@ -68,6 +66,7 @@ public class Folks.Individual : Object, Alias, Capabilities, Groups, Presence
               var persona = (Persona) p;
               var groups = (p is Groups) ? (Groups) p : null;
 
+              persona.notify["avatar"].disconnect (this.notify_avatar_cb);
               persona.notify["presence-message"].disconnect (
                   this.notify_presence_cb);
               persona.notify["presence-type"].disconnect (
@@ -87,6 +86,7 @@ public class Folks.Individual : Object, Alias, Capabilities, Groups, Presence
               var persona = (Persona) p;
               var groups = (p is Groups) ? (Groups) p : null;
 
+              persona.notify["avatar"].connect (this.notify_avatar_cb);
               persona.notify["presence-message"].connect (
                   this.notify_presence_cb);
               persona.notify["presence-type"].connect (this.notify_presence_cb);
@@ -97,6 +97,11 @@ public class Folks.Individual : Object, Alias, Capabilities, Groups, Presence
         }
     }
 
+  private void notify_avatar_cb (Object obj, ParamSpec ps)
+    {
+      this.update_avatar ();
+    }
+
   private void persona_group_changed_cb (string group, bool is_member)
     {
       this.change_group (group, is_member);
@@ -208,6 +213,7 @@ public class Folks.Individual : Object, Alias, Capabilities, Groups, Presence
 
       this.update_groups ();
       this.update_presence ();
+      this.update_avatar ();
     }
 
   private void update_groups ()
@@ -297,6 +303,26 @@ public class Folks.Individual : Object, Alias, Capabilities, Groups, Presence
         this.presence_type = presence_type;
     }
 
+  private void update_avatar ()
+    {
+      File avatar = null;
+
+      this._personas.foreach ((p) =>
+        {
+          var persona = (Persona) p;
+
+          if (avatar == null)
+            {
+              avatar = persona.avatar;
+              return;
+            }
+        });
+
+      /* only notify if the value has changed */
+      if (this.avatar != avatar)
+        this.avatar = avatar;
+    }
+
   public CapabilitiesFlags get_capabilities ()
     {
       return this.capabilities;
index 8a585d0..9d221cf 100644 (file)
  */
 
 using GLib;
-using Folks.Alias;
-using Folks.Capabilities;
-using Folks.PersonaStore;
-using Folks.Presence;
+using Folks;
 
-public abstract class Folks.Persona : Object, Alias, Capabilities, Presence
+public abstract class Folks.Persona : Object, Alias, Avatar, Capabilities,
+       Presence
 {
   /* interface Alias */
   public abstract string alias { get; set; }
 
+  /* interface Avatar */
+  public abstract File avatar { get; set; }
+
   /* interface Capabilities */
   public abstract CapabilitiesFlags capabilities { get; set; }