]> cgit.babelmonkeys.de Git - jubjub.git/blobdiff - src/gui/gtk/JubGtkRosterUI.m
Add User Avatar support
[jubjub.git] / src / gui / gtk / JubGtkRosterUI.m
index a805adf5129c80ae270688fbaa02271addac75d7..667760b0734cff566e6f9ed3a23791cc6340159b 100644 (file)
@@ -1,5 +1,6 @@
 #import <ObjXMPP/namespaces.h>
 #include <string.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 
 #import "JubGtkRosterUI.h"
 #import "JubGObjectMap.h"
@@ -78,6 +79,7 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
                _client = [client retain];
 
                [_client.contactManager addDelegate: self];
+               [_client.avatarManager setDelegate: self];
 
                builder = gtk_builder_new();
                gtk_builder_add_from_file(builder, "data/gtk/roster.ui", NULL);
@@ -121,6 +123,7 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
 
 - (void)dealloc
 {
+       [_client.avatarManager setDelegate: nil];
        [_client.contactManager removeDelegate: self];
        [_groupMap release];
        [_contactMap release];
@@ -364,6 +367,38 @@ static gboolean filter_roster_by_presence(GtkTreeModel *model,
        });
 }
 
+- (void)contact: (XMPPContact*)contact
+   didSetAvatar: (OFString*)avatarFile
+{
+       of_log(@"Got an avatar from %@", contact.rosterItem.JID);
+       g_idle_add_block(^{
+               GtkTreeIter iter;
+               GtkTreePath *path;
+               GtkTreeRowReference *ref;
+               OFString *bareJID = [contact.rosterItem.JID bareJID];
+               OFMapTable *contactRows = [_contactMap objectForKey: bareJID];
+               OFArray *groups = contact.rosterItem.groups;;
+
+               GdkPixbuf *avatar =
+                   gdk_pixbuf_new_from_file([avatarFile UTF8String], NULL);
+
+               if (groups == nil)
+                       groups = @[ @"General" ];
+
+               for (OFString *group in groups) {
+                       ref = [contactRows valueForKey: group];
+                       path = gtk_tree_row_reference_get_path(ref);
+                       gtk_tree_model_get_iter(GTK_TREE_MODEL(_roster_model),
+                           &iter, path);
+                       gtk_tree_path_free(path);
+
+                       gtk_tree_store_set(_roster_model, &iter,
+                           4, avatar, -1);
+               }
+               g_object_unref(G_OBJECT(avatar));
+       });
+}
+
 -      (void)client: (JubChatClient*)client_
   didChangePresence: (XMPPPresence*)presence
 {