From 42b0656fdff84cd768d6b0b8461b85d8707ea700 Mon Sep 17 00:00:00 2001 From: Travis Reitter Date: Fri, 11 Jun 2010 13:24:00 -0700 Subject: [PATCH] Support avatars (generally, and for the Telepathy backend) --- .gitignore | 1 + backends/telepathy/tpf-persona.vala | 20 +++++++++++++++++-- configure.ac | 2 +- folks/Makefile.am | 1 + folks/avatar.vala | 26 +++++++++++++++++++++++++ folks/individual.vala | 38 +++++++++++++++++++++++++++++++------ folks/persona.vala | 11 ++++++----- 7 files changed, 85 insertions(+), 14 deletions(-) create mode 100644 folks/avatar.vala diff --git a/.gitignore b/.gitignore index 054eadf..f6d3361 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/backends/telepathy/tpf-persona.vala b/backends/telepathy/tpf-persona.vala index 46f290e..c0c834e 100644 --- a/backends/telepathy/tpf-persona.vala +++ b/backends/telepathy/tpf-persona.vala @@ -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 _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 (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; + } } diff --git a/configure.ac b/configure.ac index 5e2cda9..1d3a442 100644 --- a/configure.ac +++ b/configure.ac @@ -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' diff --git a/folks/Makefile.am b/folks/Makefile.am index 25fb23a..b303552 100644 --- a/folks/Makefile.am +++ b/folks/Makefile.am @@ -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 index 0000000..0e3522b --- /dev/null +++ b/folks/avatar.vala @@ -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 . + * + * Authors: + * Travis Reitter + */ + +using GLib; + +public interface Folks.Avatar : Object +{ + public abstract File avatar { get; set; } +} diff --git a/folks/individual.vala b/folks/individual.vala index 1d5dcba..afe753d 100644 --- a/folks/individual.vala +++ b/folks/individual.vala @@ -20,13 +20,10 @@ 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 _groups; private GLib.List _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; diff --git a/folks/persona.vala b/folks/persona.vala index 8a585d0..9d221cf 100644 --- a/folks/persona.vala +++ b/folks/persona.vala @@ -19,16 +19,17 @@ */ 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; } -- 2.7.4