[Telepathy-commits] [telepathy-gabble/master] move view-activity features to view

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


20080606084535-7fe3f-1e368eac686f3027f0185e7ecc175aabe97f1028.gz
---
 src/conn-olpc.c                            |   34 ++++++------
 src/olpc-view.c                            |   82 +++++++++++++++++++++++++---
 src/olpc-view.h                            |    5 ++
 tests/twisted/olpc/olpc-activity-search.py |   30 +++++++++-
 4 files changed, 123 insertions(+), 28 deletions(-)

diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index 31a90a6..4e9128d 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -3412,7 +3412,6 @@ olpc_gadget_search_buddies_by_properties (GabbleSvcOLPCGadget *iface,
   lm_message_unref (query);
 }
 
-#if 0
 static LmHandlerResult
 activity_query_result_cb (GabbleConnection *conn,
                           LmMessage *sent_msg,
@@ -3424,7 +3423,7 @@ activity_query_result_cb (GabbleConnection *conn,
   TpHandleSet *activities;
   TpHandleRepoIface *room_repo = tp_base_connection_get_handles (
       (TpBaseConnection*) conn, TP_HANDLE_TYPE_ROOM);
-  GabbleOlpcActivityView *view = GABBLE_OLPC_ACTIVITY_VIEW (_view);
+  GabbleOlpcView *view = GABBLE_OLPC_VIEW (_view);
 
   view_node = lm_message_node_get_child_with_namespace (reply_msg->node, "view",
       NS_OLPC_ACTIVITY);
@@ -3478,38 +3477,38 @@ activity_query_result_cb (GabbleConnection *conn,
     }
 
   /* TODO: remove activities when needed and unref ActivityInfo */
-  gabble_olpc_activity_view_add_activities (view, activities);
+  gabble_olpc_view_add_activities (view, activities);
 
   tp_handle_set_destroy (activities);
   return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 }
 
 static void
-activity_view_closed_cb (GabbleOlpcActivityView *view,
+activity_view_closed_cb (GabbleOlpcView *view,
                          GabbleConnection *conn)
 {
   guint id;
   TpHandleSet *activities;
 
   /* decrement ActivityInfo */
-  activities = gabble_olpc_activity_view_get_activities (view);
+  activities = gabble_olpc_view_get_activities (view);
 
   tp_handle_set_foreach (activities,
       decrement_contacts_activities_set_foreach, conn);
 
   g_object_get (view, "id", &id, NULL);
-  g_hash_table_remove (conn->olpc_activity_views, GUINT_TO_POINTER (id));
+  g_hash_table_remove (conn->olpc_views, GUINT_TO_POINTER (id));
 }
 
-static GabbleOlpcActivityView *
+static GabbleOlpcView *
 create_activity_view (GabbleConnection *conn)
 {
   guint id;
-  GabbleOlpcActivityView *view;
+  GabbleOlpcView *view;
 
   /* Look for a free ID */
   for (id = 0; id < G_MAXUINT &&
-      g_hash_table_lookup (conn->olpc_activity_views, GUINT_TO_POINTER (id))
+      g_hash_table_lookup (conn->olpc_views, GUINT_TO_POINTER (id))
       != NULL; id++);
 
   if (id == G_MAXUINT)
@@ -3518,8 +3517,8 @@ create_activity_view (GabbleConnection *conn)
       return NULL;
     }
 
-  view = gabble_olpc_activity_view_new (conn, id);
-  g_hash_table_insert (conn->olpc_activity_views, GUINT_TO_POINTER (id), view);
+  view = gabble_olpc_view_new (conn, GABBLE_OLPC_VIEW_TYPE_ACTIVITY, id);
+  g_hash_table_insert (conn->olpc_views, GUINT_TO_POINTER (id), view);
 
   g_signal_connect (view, "closed", G_CALLBACK (activity_view_closed_cb), conn);
 
@@ -3536,7 +3535,7 @@ olpc_gadget_request_random_activities (GabbleSvcOLPCGadget *iface,
   gchar *max_str, *id_str;
   gchar *object_path;
   guint id;
-  GabbleOlpcActivityView *view;
+  GabbleOlpcView *view;
 
   if (!check_gadget_activity (conn, context))
     return;
@@ -3615,7 +3614,7 @@ olpc_gadget_search_activities_by_properties (GabbleSvcOLPCGadget *iface,
   gchar *id_str;
   gchar *object_path;
   guint id;
-  GabbleOlpcActivityView *view;
+  GabbleOlpcView *view;
 
   if (!check_gadget_activity (conn, context))
     return;
@@ -3688,7 +3687,7 @@ olpc_gadget_search_activities_by_participants (GabbleSvcOLPCGadget *iface,
   gchar *id_str;
   gchar *object_path;
   guint id, i;
-  GabbleOlpcActivityView *view;
+  GabbleOlpcView *view;
   TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (
       (TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
 
@@ -3757,7 +3756,6 @@ olpc_gadget_search_activities_by_participants (GabbleSvcOLPCGadget *iface,
   g_free (object_path);
   lm_message_unref (query);
 }
-#endif
 
 static gboolean
 send_presence_to_gadget (GabbleConnection *conn,
@@ -3831,9 +3829,9 @@ olpc_gadget_iface_init (gpointer g_iface,
     klass, olpc_gadget_##x)
   IMPLEMENT(request_random_buddies);
   IMPLEMENT(search_buddies_by_properties);
-  //IMPLEMENT(request_random_activities);
-  //IMPLEMENT(search_activities_by_properties);
-  //IMPLEMENT(search_activities_by_participants);
+  IMPLEMENT(request_random_activities);
+  IMPLEMENT(search_activities_by_properties);
+  IMPLEMENT(search_activities_by_participants);
   IMPLEMENT(publish);
 #undef IMPLEMENT
 }
diff --git a/src/olpc-view.c b/src/olpc-view.c
index b02ddbf..185eb92 100644
--- a/src/olpc-view.c
+++ b/src/olpc-view.c
@@ -65,6 +65,7 @@ struct _GabbleOlpcViewPrivate
   guint id;
 
   TpHandleSet *buddies;
+  TpHandleSet *activities;
 
   /* TpHandle (owned in priv->buddies) => GHashTable * */
   GHashTable *buddy_properties;
@@ -112,6 +113,11 @@ gabble_olpc_view_dispose (GObject *object)
       priv->buddies = NULL;
     }
 
+  if (priv->activities != NULL)
+    {
+      tp_handle_set_destroy (priv->activities);
+      priv->activities = NULL;
+    }
   if (priv->buddy_properties != NULL)
     {
       g_hash_table_destroy (priv->buddy_properties);
@@ -199,7 +205,7 @@ gabble_olpc_view_constructor (GType type,
   GabbleOlpcViewPrivate *priv;
   DBusGConnection *bus;
   TpBaseConnection *conn;
-  TpHandleRepoIface *contact_handles;
+  TpHandleRepoIface *contact_handles, *room_handles;
 
   obj = G_OBJECT_CLASS (gabble_olpc_view_parent_class)->
            constructor (type, n_props, props);
@@ -214,8 +220,11 @@ gabble_olpc_view_constructor (GType type,
 
   contact_handles = tp_base_connection_get_handles (conn,
       TP_HANDLE_TYPE_CONTACT);
+  room_handles = tp_base_connection_get_handles (conn,
+      TP_HANDLE_TYPE_ROOM);
 
   priv->buddies = tp_handle_set_new (contact_handles);
+  priv->activities = tp_handle_set_new (room_handles);
 
   return obj;
 }
@@ -322,6 +331,21 @@ olpc_view_get_buddies (GabbleSvcOLPCView *iface,
 }
 
 static void
+olpc_view_get_activities (GabbleSvcOLPCView *iface,
+                          DBusGMethodInvocation *context)
+{
+  GabbleOlpcView *self = GABBLE_OLPC_VIEW (iface);
+  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GArray *activities;
+
+  activities = tp_handle_set_to_array (priv->activities);
+
+  gabble_svc_olpc_view_return_from_get_activities (context, activities);
+
+  g_array_free (activities, TRUE);
+}
+
+static void
 olpc_view_close (GabbleSvcOLPCView *iface,
                  DBusGMethodInvocation *context)
 {
@@ -333,12 +357,29 @@ olpc_view_close (GabbleSvcOLPCView *iface,
 
   id_str = g_strdup_printf ("%u", priv->id);
 
-  msg = lm_message_build (priv->conn->olpc_gadget_buddy,
-      LM_MESSAGE_TYPE_MESSAGE,
-      '(', "close", "",
-        '@', "xmlns", NS_OLPC_BUDDY,
-        '@', "id", id_str,
-      ')', NULL);
+  if (priv->type == GABBLE_OLPC_VIEW_TYPE_BUDDY)
+    {
+      msg = lm_message_build (priv->conn->olpc_gadget_buddy,
+          LM_MESSAGE_TYPE_MESSAGE,
+          '(', "close", "",
+            '@', "xmlns", NS_OLPC_BUDDY,
+            '@', "id", id_str,
+          ')', NULL);
+    }
+  else if (priv->type == GABBLE_OLPC_VIEW_TYPE_ACTIVITY)
+    {
+      msg = lm_message_build (priv->conn->olpc_gadget_activity,
+          LM_MESSAGE_TYPE_MESSAGE,
+          '(', "close", "",
+            '@', "xmlns", NS_OLPC_ACTIVITY,
+            '@', "id", id_str,
+          ')', NULL);
+    }
+  else
+    {
+      g_assert_not_reached ();
+    }
+
   g_free (id_str);
 
   if (!_gabble_connection_send (priv->conn, msg, &error))
@@ -448,6 +489,32 @@ gabble_olpc_view_get_buddy_properties (GabbleOlpcView *self,
   return g_hash_table_lookup (priv->buddy_properties, GUINT_TO_POINTER (buddy));
 }
 
+void
+gabble_olpc_view_add_activities (GabbleOlpcView *self,
+                                 TpHandleSet *activities)
+{
+  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GArray *added, *empty;
+
+  tp_handle_set_update (priv->activities, tp_handle_set_peek (activities));
+
+  added = tp_handle_set_to_array (activities);
+  empty = g_array_new (FALSE, FALSE, sizeof (TpHandle));
+
+  gabble_svc_olpc_view_emit_activities_changed (self, added, empty);
+
+  g_array_free (added, TRUE);
+  g_array_free (empty, TRUE);
+}
+
+TpHandleSet *
+gabble_olpc_view_get_activities (GabbleOlpcView *self)
+{
+  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+
+  return priv->activities;
+}
+
 static void
 view_iface_init (gpointer g_iface,
                  gpointer iface_data)
@@ -457,6 +524,7 @@ view_iface_init (gpointer g_iface,
 #define IMPLEMENT(x) gabble_svc_olpc_view_implement_##x (\
     klass, olpc_view_##x)
   IMPLEMENT(get_buddies);
+  IMPLEMENT(get_activities);
   IMPLEMENT(close);
 #undef IMPLEMENT
 }
diff --git a/src/olpc-view.h b/src/olpc-view.h
index ccdc127..5b9bdbf 100644
--- a/src/olpc-view.h
+++ b/src/olpc-view.h
@@ -82,6 +82,11 @@ gboolean gabble_olpc_view_set_buddy_properties (GabbleOlpcView *self,
 GHashTable * gabble_olpc_view_get_buddy_properties (GabbleOlpcView *self,
     TpHandle buddy);
 
+void gabble_olpc_view_add_activities (GabbleOlpcView *self,
+    TpHandleSet *activities);
+
+TpHandleSet * gabble_olpc_view_get_activities (GabbleOlpcView *self);
+
 G_END_DECLS
 
 #endif /* #ifndef __GABBLE_OLPC_VIEW_H__ */
diff --git a/tests/twisted/olpc/olpc-activity-search.py b/tests/twisted/olpc/olpc-activity-search.py
index fbc64f2..8f57615 100644
--- a/tests/twisted/olpc/olpc-activity-search.py
+++ b/tests/twisted/olpc/olpc-activity-search.py
@@ -91,13 +91,21 @@ def test(q, bus, conn, stream):
 
     view_path = return_event.value[0]
     view0 = bus.get_object(conn.bus_name, view_path)
-    view0_iface = dbus.Interface(view0, 'org.laptop.Telepathy.ActivityView')
+    view0_iface = dbus.Interface(view0, 'org.laptop.Telepathy.View')
 
     event = q.expect('dbus-signal', signal='ActivityPropertiesChanged')
     handle, props = event.args
     assert conn.InspectHandles(2, [handle])[0] == 'room1 at conference.localhost'
     assert props == {'color': '#005FE4,#00A0FF'}
 
+    event = q.expect('dbus-signal', signal='ActivitiesChanged')
+    added, removed = event.args
+    assert removed == []
+    assert sorted(conn.InspectHandles(2, added)) == ['room1 at conference.localhost']
+
+    act = view0_iface.GetActivities()
+    assert sorted(act) == sorted(added)
+
     # we can now get these properties
     props = activity_prop_iface.GetProperties(handle)
     assert props == {'color': '#005FE4,#00A0FF'}
@@ -136,13 +144,21 @@ def test(q, bus, conn, stream):
 
     view_path = return_event.value[0]
     view1 = bus.get_object(conn.bus_name, view_path)
-    view1_iface = dbus.Interface(view1, 'org.laptop.Telepathy.ActivityView')
+    view1_iface = dbus.Interface(view1, 'org.laptop.Telepathy.View')
 
     event = q.expect('dbus-signal', signal='ActivityPropertiesChanged')
     handle, props = event.args
     assert conn.InspectHandles(2, [handle])[0] == 'room2 at conference.localhost'
     assert props == {'color': '#AABBCC,#001122'}
 
+    event = q.expect('dbus-signal', signal='ActivitiesChanged')
+    added, removed = event.args
+    assert removed == []
+    assert sorted(conn.InspectHandles(2, added)) == ['room2 at conference.localhost']
+
+    act = view1.GetActivities()
+    assert sorted(act) == sorted(added)
+
     # activity search by participants
     participants = conn.RequestHandles(1, ["alice at localhost", "bob at localhost"])
     call_async(q, gadget_iface, 'SearchActivitiesByParticipants', participants)
@@ -174,13 +190,21 @@ def test(q, bus, conn, stream):
 
     view_path = return_event.value[0]
     view2 = bus.get_object(conn.bus_name, view_path)
-    view2_iface = dbus.Interface(view2, 'org.laptop.Telepathy.ActivityView')
+    view2_iface = dbus.Interface(view2, 'org.laptop.Telepathy.View')
 
     event = q.expect('dbus-signal', signal='ActivityPropertiesChanged')
     handle, props = event.args
     assert conn.InspectHandles(2, [handle])[0] == 'room2 at conference.localhost'
     assert props == {'color': '#AABBCC,#001122'}
 
+    event = q.expect('dbus-signal', signal='ActivitiesChanged')
+    added, removed = event.args
+    assert removed == []
+    assert sorted(conn.InspectHandles(2, added)) == ['room2 at conference.localhost']
+
+    act = view2.GetActivities()
+    assert sorted(act) == sorted(added)
+
     # close view 0
     call_async(q, view0_iface, 'Close')
     event, _ = q.expect_many(
-- 
1.5.6.5




More information about the Telepathy-commits mailing list