[Telepathy-commits] [telepathy-gabble/master] olpc-view: add gabble_olpc_view_get_buddy_activities

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Fri Sep 26 10:02:22 PDT 2008


20080627104815-7fe3f-6ffd4bf0b2dd5451bb996bf544c38e7f9beba2f0.gz
---
 src/olpc-view.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 src/olpc-view.h |    3 +++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/src/olpc-view.c b/src/olpc-view.c
index fbce366..a1308b2 100644
--- a/src/olpc-view.c
+++ b/src/olpc-view.c
@@ -662,6 +662,49 @@ gabble_olpc_view_remove_activities (GabbleOlpcView *self,
   g_array_free (array, TRUE);
 }
 
+GPtrArray *
+gabble_olpc_view_get_buddy_activities (GabbleOlpcView *self,
+                                       TpHandle buddy)
+{
+  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GPtrArray *activities;
+  TpHandleSet *rooms_set;
+  GArray *rooms;
+  guint i;
+
+  activities = g_ptr_array_new ();
+
+  rooms_set = g_hash_table_lookup (priv->buddy_rooms, GUINT_TO_POINTER (buddy));
+  if (rooms_set == NULL || tp_handle_set_size (rooms_set) == 0)
+    return activities;
+
+  /* Convert to an array for easier iteration */
+  rooms = tp_handle_set_to_array (rooms_set);
+  for (i = 0; i < rooms->len; i++)
+    {
+      TpHandle room;
+      GabbleOlpcActivity *activity;
+
+      room = g_array_index (rooms, TpHandle, i);
+
+      activity = g_hash_table_lookup (priv->activities,
+          GUINT_TO_POINTER (room));
+      if (activity == NULL)
+        {
+          /* FIXME: When this could happen ? */
+          DEBUG ("Buddy %d is supposed to be in activity %d but view doesn't"
+              " contain its info", buddy, room);
+          continue;
+        }
+
+      g_ptr_array_add (activities, activity);
+    }
+
+  g_array_free (rooms, TRUE);
+
+  return activities;
+}
+
 static void
 view_iface_init (gpointer g_iface,
                  gpointer iface_data)
diff --git a/src/olpc-view.h b/src/olpc-view.h
index fcda7fd..ae68910 100644
--- a/src/olpc-view.h
+++ b/src/olpc-view.h
@@ -88,6 +88,9 @@ void gabble_olpc_view_add_activities (GabbleOlpcView *self,
 void gabble_olpc_view_remove_activities (GabbleOlpcView *self,
     TpHandleSet *rooms);
 
+GPtrArray * gabble_olpc_view_get_buddy_activities (GabbleOlpcView *self,
+    TpHandle buddy);
+
 G_END_DECLS
 
 #endif /* #ifndef __GABBLE_OLPC_VIEW_H__ */
-- 
1.5.6.5




More information about the Telepathy-commits mailing list