[Telepathy-commits] [telepathy-gabble/master] Turn view object into a channel. Move BuddyView code from conn-olpc to olpc-buddy-view

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Thu Oct 16 03:18:51 PDT 2008


---
 src/conn-olpc.c       |  312 ++--------------------
 src/conn-olpc.h       |    5 +
 src/olpc-buddy-view.c |  705 ++++++++++++++++++++++++++++++++++++++-----------
 src/olpc-buddy-view.h |   20 +-
 src/types.h           |    3 +
 5 files changed, 584 insertions(+), 461 deletions(-)

diff --git a/src/conn-olpc.c b/src/conn-olpc.c
index bbe1667..63efffb 100644
--- a/src/conn-olpc.c
+++ b/src/conn-olpc.c
@@ -455,9 +455,7 @@ olpc_buddy_info_get_properties (GabbleSvcOLPCBuddyInfo *iface,
   GabbleConnection *conn = GABBLE_CONNECTION (iface);
   TpBaseConnection *base = (TpBaseConnection *) conn;
   const gchar *jid;
-#if 0
   GHashTable *properties;
-#endif
 
   DEBUG ("called");
 
@@ -468,15 +466,14 @@ olpc_buddy_info_get_properties (GabbleSvcOLPCBuddyInfo *iface,
   /* First check if we can find properties in a buddy view */
   /* FIXME: Maybe we should first try the PEP node as we do for buddy
    * activities ? */
-#if 0
-  properties = find_buddy_properties_from_views (conn, contact);
+  properties = gabble_olpc_gadget_manager_find_buddy_properties_from_views (
+      conn->olpc_gadget_manager, contact);
   if (properties != NULL)
     {
       gabble_svc_olpc_buddy_info_return_from_get_properties (context,
           properties);
       return;
     }
-#endif
 
   /* Then try to query the PEP node */
   jid = inspect_contact (base, context, contact);
@@ -2919,7 +2916,6 @@ connection_presence_do_update (GabblePresenceCache *cache,
     }
 }
 
-#if 0
 static void
 buddy_changed (GabbleConnection *conn,
                LmMessageNode *change)
@@ -2947,7 +2943,7 @@ buddy_changed (GabbleConnection *conn,
     }
 
   id = strtoul (id_str, NULL, 10);
-  view = g_hash_table_lookup (conn->olpc_views, GUINT_TO_POINTER (id));
+  view = gabble_olpc_gadget_manager_get_view (conn->olpc_gadget_manager, id);
   if (view == NULL)
     {
       DEBUG ("No active view with ID %u", id);
@@ -3003,6 +2999,7 @@ buddy_changed (GabbleConnection *conn,
     }
 }
 
+#if 0
 static void
 activity_changed (GabbleConnection *conn,
                   LmMessageNode *change)
@@ -3026,6 +3023,7 @@ activity_changed (GabbleConnection *conn,
         }
     }
 }
+#endif
 
 static gboolean
 populate_buddies_from_nodes (GabbleConnection *conn,
@@ -3088,6 +3086,7 @@ populate_buddies_from_nodes (GabbleConnection *conn,
   return TRUE;
 }
 
+#if 0
 static gboolean
 add_activities_to_view_from_node (GabbleConnection *conn,
                                   GabbleOlpcView *view,
@@ -3254,10 +3253,11 @@ activity_added (GabbleConnection *conn,
 
   add_activities_to_view_from_node (conn, view, added);
 }
+#endif
 
 /* if activity is not zero, buddies are associated with the given
  * activity room */
-static gboolean
+gboolean
 add_buddies_to_view_from_node (GabbleConnection *conn,
                                GabbleOlpcView *view,
                                LmMessageNode *node,
@@ -3325,7 +3325,8 @@ buddy_added (GabbleConnection *conn,
     return;
 
   id = strtoul (id_str, NULL, 10);
-  view = g_hash_table_lookup (conn->olpc_views, GUINT_TO_POINTER (id));
+  view = gabble_olpc_gadget_manager_get_view (
+      conn->olpc_gadget_manager, id);
   if (view == NULL)
     {
       DEBUG ("no view with ID %u", id);
@@ -3389,7 +3390,9 @@ buddy_removed (GabbleConnection *conn,
     return;
 
   id = strtoul (id_str, NULL, 10);
-  view = g_hash_table_lookup (conn->olpc_views, GUINT_TO_POINTER (id));
+
+  view = gabble_olpc_gadget_manager_get_view (
+      conn->olpc_gadget_manager, id);
   if (view == NULL)
     {
       DEBUG ("no view with ID %u", id);
@@ -3399,6 +3402,7 @@ buddy_removed (GabbleConnection *conn,
   remove_buddies_from_view_from_node (conn, view, removed);
 }
 
+#if 0
 static gboolean
 remove_activities_from_view_from_node (GabbleConnection *conn,
                                        GabbleOlpcView *view,
@@ -3556,9 +3560,7 @@ conn_olpc_msg_cb (LmMessageHandler *handler,
 {
   GabbleConnection *conn = GABBLE_CONNECTION (user_data);
   const gchar *from;
-#if 0
   LmMessageNode *node;
-#endif
 
   from = lm_message_node_get_attribute (message->node, "from");
   if (from == NULL)
@@ -3571,7 +3573,6 @@ conn_olpc_msg_cb (LmMessageHandler *handler,
       tp_strdiff (from, conn->olpc_gadget_activity))
       return LM_HANDLER_RESULT_ALLOW_MORE_HANDLERS;
 
-#if 0
   for (node = message->node->children; node != NULL; node = node->next)
     {
       const gchar *ns;
@@ -3583,11 +3584,13 @@ conn_olpc_msg_cb (LmMessageHandler *handler,
         {
           buddy_changed (conn, node);
         }
+#if 0
       else if (!tp_strdiff (node->name, "change") &&
           !tp_strdiff (ns, NS_OLPC_ACTIVITY))
         {
           activity_changed (conn, node);
         }
+#endif
       else if (!tp_strdiff (node->name, "added") &&
           !tp_strdiff (ns, NS_OLPC_BUDDY))
         {
@@ -3598,6 +3601,7 @@ conn_olpc_msg_cb (LmMessageHandler *handler,
         {
           buddy_removed (conn, node);
         }
+#if 0
       else if (!tp_strdiff (node->name, "added") &&
           !tp_strdiff (ns, NS_OLPC_ACTIVITY))
         {
@@ -3613,8 +3617,8 @@ conn_olpc_msg_cb (LmMessageHandler *handler,
         {
           activity_membership_change (conn, node);
         }
-    }
 #endif
+    }
 
   return LM_HANDLER_RESULT_REMOVE_MESSAGE;
 }
@@ -3769,15 +3773,11 @@ olpc_activity_properties_iface_init (gpointer g_iface,
 }
 
 #if 0
-static void
-view_closed_cb (GabbleOlpcView *view,
-                GabbleConnection *conn)
-{
-  guint id;
 
-  g_object_get (view, "id", &id, NULL);
-  g_hash_table_remove (conn->olpc_views, GUINT_TO_POINTER (id));
-}
+/* FIXME: connect this
+  g_signal_connect (view, "buddy-activities-changed",
+      G_CALLBACK (buddy_activities_changed_cb), conn);
+*/
 
 static void
 buddy_activities_changed_cb (GabbleOlpcView *view,
@@ -3796,273 +3796,6 @@ buddy_activities_changed_cb (GabbleOlpcView *view,
   free_activities (activities);
 }
 
-static GabbleOlpcView *
-create_view (GabbleConnection *conn,
-             GabbleOlpcViewType type)
-{
-  guint id;
-  GabbleOlpcView *view;
-
-  /* Look for a free ID */
-  for (id = 0; id < G_MAXUINT &&
-      g_hash_table_lookup (conn->olpc_views, GUINT_TO_POINTER (id))
-      != NULL; id++);
-
-  if (id == G_MAXUINT)
-    {
-      /* All the ID's are allocated */
-      DEBUG ("All the view ID's are already used!");
-      return NULL;
-    }
-
-  view = gabble_olpc_view_new (conn, type, id);
-  g_hash_table_insert (conn->olpc_views, GUINT_TO_POINTER (id), view);
-
-  g_signal_connect (view, "closed_", G_CALLBACK (view_closed_cb), conn);
-
-  g_signal_connect (view, "buddy-activities-changed",
-      G_CALLBACK (buddy_activities_changed_cb), conn);
-
-  return view;
-}
-
-static LmHandlerResult
-buddy_view_query_result_cb (GabbleConnection *conn,
-                            LmMessage *sent_msg,
-                            LmMessage *reply_msg,
-                            GObject *_view,
-                            gpointer user_data)
-{
-  LmMessageNode *view_node;
-  GabbleOlpcView *view = GABBLE_OLPC_VIEW (_view);
-
-  view_node = lm_message_node_get_child_with_namespace (reply_msg->node,
-      "view", NS_OLPC_BUDDY);
-  if (view_node == NULL)
-    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
-
-  add_buddies_to_view_from_node (conn, view, view_node, "buddy", 0);
-
-  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
-}
-
-static void
-olpc_gadget_request_random_buddies (GabbleSvcOLPCGadget *iface,
-                                    guint max,
-                                    DBusGMethodInvocation *context)
-{
-  GabbleConnection *conn = GABBLE_CONNECTION (iface);
-  LmMessage *query;
-  gchar *max_str, *id_str;
-  gchar *object_path;
-  guint id;
-  GabbleOlpcView *view;
-
-  if (!check_gadget_buddy (conn, context))
-    return;
-
-  if (max == 0)
-    {
-      GError error = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
-        "max have to be greater than 0" };
-
-      DEBUG ("%s", error.message);
-      dbus_g_method_return_error (context, &error);
-      return;
-    }
-
-  view = create_view (conn, GABBLE_OLPC_VIEW_TYPE_BUDDY);
-  if (view == NULL)
-    {
-      GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
-        "can't create view" };
-
-      DEBUG ("%s", error.message);
-      dbus_g_method_return_error (context, &error);
-      return;
-    }
-
-  g_object_get (view,
-      "id", &id,
-      "object-path", &object_path,
-      NULL);
-
-  max_str = g_strdup_printf ("%u", max);
-  id_str = g_strdup_printf ("%u", id);
-
-  query = lm_message_build_with_sub_type (conn->olpc_gadget_buddy,
-      LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
-      '(', "view", "",
-          '@', "xmlns", NS_OLPC_BUDDY,
-          '@', "id", id_str,
-          '(', "random", "",
-            '@', "max", max_str,
-          ')',
-      ')',
-      NULL);
-
-  g_free (max_str);
-  g_free (id_str);
-
-  if (!_gabble_connection_send_with_reply (conn, query,
-        buddy_view_query_result_cb, G_OBJECT (view), NULL, NULL))
-    {
-      GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
-        "Failed to send buddy search query to server" };
-
-      DEBUG ("%s", error.message);
-      dbus_g_method_return_error (context, &error);
-      lm_message_unref (query);
-      g_free (object_path);
-      return;
-    }
-
-  gabble_svc_olpc_gadget_return_from_request_random_buddies (context,
-      object_path);
-
-  g_free (object_path);
-  lm_message_unref (query);
-}
-
-static void
-olpc_gadget_search_buddies_by_properties (GabbleSvcOLPCGadget *iface,
-                                          GHashTable *properties,
-                                          DBusGMethodInvocation *context)
-{
-  GabbleConnection *conn = GABBLE_CONNECTION (iface);
-  LmMessage *query;
-  LmMessageNode *properties_node;
-  gchar *id_str;
-  gchar *object_path;
-  guint id;
-  GabbleOlpcView *view;
-
-  if (!check_gadget_buddy (conn, context))
-    return;
-
-  view = create_view (conn, GABBLE_OLPC_VIEW_TYPE_BUDDY);
-  if (view == NULL)
-    {
-      GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
-        "can't create view" };
-
-      DEBUG ("%s", error.message);
-      dbus_g_method_return_error (context, &error);
-      return;
-    }
-
-  g_object_get (view,
-      "id", &id,
-      "object-path", &object_path,
-      NULL);
-
-  id_str = g_strdup_printf ("%u", id);
-
-  query = lm_message_build_with_sub_type (conn->olpc_gadget_buddy,
-      LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
-      '(', "view", "",
-          '@', "xmlns", NS_OLPC_BUDDY,
-          '@', "id", id_str,
-          '(', "buddy", "",
-            '(', "properties", "",
-              '*', &properties_node,
-              '@', "xmlns", NS_OLPC_BUDDY_PROPS,
-            ')',
-          ')',
-      ')',
-      NULL);
-
-  g_free (id_str);
-
-  lm_message_node_add_children_from_properties (properties_node, properties,
-      "property");
-
-  if (!_gabble_connection_send_with_reply (conn, query,
-        buddy_view_query_result_cb, G_OBJECT (view), NULL, NULL))
-    {
-      GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
-        "Failed to send buddy search query to server" };
-
-      DEBUG ("%s", error.message);
-      dbus_g_method_return_error (context, &error);
-      lm_message_unref (query);
-      g_free (object_path);
-      return;
-    }
-
-  gabble_svc_olpc_gadget_return_from_search_buddies_by_properties (context,
-      object_path);
-
-  g_free (object_path);
-  lm_message_unref (query);
-}
-
-static void
-olpc_gadget_search_buddies_by_alias (GabbleSvcOLPCGadget *iface,
-                                     const gchar *alias,
-                                     DBusGMethodInvocation *context)
-{
-  GabbleConnection *conn = GABBLE_CONNECTION (iface);
-  LmMessage *query;
-  gchar *id_str;
-  gchar *object_path;
-  guint id;
-  GabbleOlpcView *view;
-
-  if (!check_gadget_buddy (conn, context))
-    return;
-
-  view = create_view (conn, GABBLE_OLPC_VIEW_TYPE_BUDDY);
-  if (view == NULL)
-    {
-      GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
-        "can't create view" };
-
-      DEBUG ("%s", error.message);
-      dbus_g_method_return_error (context, &error);
-      return;
-    }
-
-  g_object_get (view,
-      "id", &id,
-      "object-path", &object_path,
-      NULL);
-
-  id_str = g_strdup_printf ("%u", id);
-
-  query = lm_message_build_with_sub_type (conn->olpc_gadget_buddy,
-      LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
-      '(', "view", "",
-          '@', "xmlns", NS_OLPC_BUDDY,
-          '@', "id", id_str,
-          '(', "buddy", "",
-            '@', "alias", alias,
-          ')',
-      ')',
-      NULL);
-
-  g_free (id_str);
-
-  if (!_gabble_connection_send_with_reply (conn, query,
-        buddy_view_query_result_cb, G_OBJECT (view), NULL, NULL))
-    {
-      GError error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR,
-        "Failed to send buddy search query to server" };
-
-      DEBUG ("%s", error.message);
-      dbus_g_method_return_error (context, &error);
-      lm_message_unref (query);
-      g_free (object_path);
-      return;
-    }
-
-  gabble_svc_olpc_gadget_return_from_search_buddies_by_alias (context,
-      object_path);
-
-  g_free (object_path);
-  lm_message_unref (query);
-}
-
 static LmHandlerResult
 activity_view_query_result_cb (GabbleConnection *conn,
                                LmMessage *sent_msg,
@@ -4464,6 +4197,7 @@ conn_olpc_presence_cb (LmMessageHandler *handler,
       sub_type == LM_MESSAGE_SUB_TYPE_AVAILABLE)
     {
       DEBUG ("Got presence from Gadget. Close open views if any");
+      /* FIXME: gabble_olpc_gadget_manager_close_all_views (); */
       close_all_views (conn);
     }
 #endif
diff --git a/src/conn-olpc.h b/src/conn-olpc.h
index 1a020b1..24f53c4 100644
--- a/src/conn-olpc.h
+++ b/src/conn-olpc.h
@@ -23,6 +23,7 @@
 #include <extensions/extensions.h>
 
 #include "connection.h"
+#include "olpc-buddy-view.h"
 
 void
 olpc_buddy_info_iface_init (gpointer g_iface, gpointer iface_data);
@@ -67,6 +68,10 @@ LmHandlerResult conn_olpc_presence_cb (LmMessageHandler *handler,
 void conn_olpc_gadget_propeties_getter (GObject *object, GQuark interface,
     GQuark name, GValue *value, gpointer getter_data);
 
+gboolean add_buddies_to_view_from_node (GabbleConnection *conn,
+    GabbleOlpcView *view, LmMessageNode *node, const gchar *node_name,
+    TpHandle activity);
+
 void olpc_gadget_iface_init (gpointer g_iface, gpointer iface_data);
 
 #endif /* __CONN_OLPC_H__ */
diff --git a/src/olpc-buddy-view.c b/src/olpc-buddy-view.c
index e89c38f..80726d1 100644
--- a/src/olpc-buddy-view.c
+++ b/src/olpc-buddy-view.c
@@ -25,10 +25,16 @@
 #include <glib.h>
 
 #include <loudmouth/loudmouth.h>
+#include <telepathy-glib/channel-iface.h>
 #include <telepathy-glib/dbus.h>
+#include <telepathy-glib/gtypes.h>
+#include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/svc-channel.h>
+#include <telepathy-glib/svc-generic.h>
 
 #define DEBUG_FLAG GABBLE_DEBUG_OLPC
 
+#include "conn-olpc.h"
 #include "debug.h"
 #include "extensions/extensions.h"
 #include "gabble-signals-marshal.h"
@@ -36,10 +42,12 @@
 #include "namespaces.h"
 #include "util.h"
 
+#define GABBLE_ARRAY_TYPE_HANDLE (dbus_g_type_get_collection ("GArray", \
+    G_TYPE_UINT))
+
 /* signals */
 enum
 {
-  CLOSED,
   BUDDY_ACTIVITIES_CHANGED,
   LAST_SIGNAL
 };
@@ -49,9 +57,32 @@ static guint signals[LAST_SIGNAL] = {0};
 /* properties */
 enum
 {
-  PROP_CONNECTION = 1,
-  PROP_TYPE,
-  PROP_OBJECT_PATH,
+  PROP_OBJECT_PATH = 1,
+  /* org.freedesktop.Telepathy.Channel D-Bus properties */
+  PROP_CHANNEL_TYPE,
+  PROP_INTERFACES,
+  PROP_HANDLE,
+  PROP_TARGET_ID,
+  PROP_HANDLE_TYPE,
+
+  /* org.freedesktop.Telepathy.Channel.FUTURE D-Bus properties */
+  PROP_REQUESTED,
+  PROP_INITIATOR_HANDLE,
+  PROP_INITIATOR_ID,
+
+  PROP_CHANNEL_DESTROYED,
+  PROP_CHANNEL_PROPERTIES,
+
+  /* org.laptop.Telepathy.Channel.Type.View D-Bus properties */
+  PROP_MAX_SIZE,
+  PROP_BUDDIES,
+  PROP_ACTIVITIES,
+
+  /* org.laptop.Telepathy.Channel.Type.BuddyView D-Bus properties */
+  PROP_VIEW_PROPERTIES,
+  PROP_ALIAS,
+
+  PROP_CONNECTION,
   PROP_ID,
   LAST_PROPERTY
 };
@@ -60,10 +91,13 @@ typedef struct _GabbleOlpcViewPrivate GabbleOlpcViewPrivate;
 struct _GabbleOlpcViewPrivate
 {
   GabbleConnection *conn;
-  /* FIXME: subclass instead of using a type attribute ? */
-  GabbleOlpcViewType type;
   char *object_path;
   guint id;
+  gboolean closed;
+  guint max_size;
+
+  GHashTable *properties;
+  gchar *alias;
 
   TpHandleSet *buddies;
   /* TpHandle => GabbleOlpcActivity * */
@@ -77,12 +111,26 @@ struct _GabbleOlpcViewPrivate
   gboolean dispose_has_run;
 };
 
-static void view_iface_init (gpointer, gpointer);
+static void channel_iface_init (gpointer, gpointer);
 
 G_DEFINE_TYPE_WITH_CODE (
     GabbleOlpcView, gabble_olpc_view, G_TYPE_OBJECT,
     G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_OLPC_CHANNEL_TYPE_BUDDYVIEW,
-      view_iface_init));
+      NULL);
+    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_DBUS_PROPERTIES,
+      tp_dbus_properties_mixin_iface_init);
+    G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL, channel_iface_init);
+    G_IMPLEMENT_INTERFACE (TP_TYPE_EXPORTABLE_CHANNEL, NULL);
+    G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_CHANNEL_FUTURE, NULL);
+    G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_OLPC_CHANNEL_INTERFACE_VIEW, NULL);
+    G_IMPLEMENT_INTERFACE (TP_TYPE_CHANNEL_IFACE, NULL);
+    );
+
+static const gchar *gabble_olpc_buddy_view_interfaces[] = {
+    GABBLE_IFACE_CHANNEL_FUTURE,
+    GABBLE_IFACE_OLPC_CHANNEL_INTERFACE_VIEW,
+    NULL
+};
 
 #define GABBLE_OLPC_VIEW_GET_PRIVATE(obj) \
     ((GabbleOlpcViewPrivate *) obj->priv)
@@ -96,6 +144,8 @@ gabble_olpc_view_init (GabbleOlpcView *self)
 
   self->priv = priv;
 
+  priv->closed = FALSE;
+
   priv->dispose_has_run = FALSE;
 }
 
@@ -150,6 +200,38 @@ gabble_olpc_view_finalize (GObject *object)
 }
 
 static void
+add_activity_to_array (TpHandle handle,
+                       GabbleOlpcActivity *activity,
+                       GPtrArray *array)
+{
+  GValue gvalue = { 0 };
+
+  g_value_init (&gvalue, GABBLE_STRUCT_TYPE_ACTIVITY);
+  g_value_take_boxed (&gvalue, dbus_g_type_specialized_construct
+      (GABBLE_STRUCT_TYPE_ACTIVITY));
+  dbus_g_type_struct_set (&gvalue,
+      0, activity->id,
+      1, activity->room,
+      G_MAXUINT);
+
+  g_ptr_array_add (array, g_value_get_boxed (&gvalue));
+}
+
+static GPtrArray *
+create_activities_array (GabbleOlpcView *self)
+{
+  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GPtrArray *activities;
+
+  activities = g_ptr_array_new ();
+
+  g_hash_table_foreach (priv->activities, (GHFunc) add_activity_to_array,
+      activities);
+
+  return activities;
+}
+
+static void
 gabble_olpc_view_get_property (GObject *object,
                                guint property_id,
                                GValue *value,
@@ -157,21 +239,88 @@ gabble_olpc_view_get_property (GObject *object,
 {
   GabbleOlpcView *self = GABBLE_OLPC_VIEW (object);
   GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  TpBaseConnection *base_conn = (TpBaseConnection *) priv->conn;
 
   switch (property_id)
     {
-      case PROP_CONNECTION:
-        g_value_set_object (value, priv->conn);
-        break;
-      case PROP_TYPE:
-        g_value_set_uint (value, priv->type);
-        break;
       case PROP_OBJECT_PATH:
         g_value_set_string (value, priv->object_path);
         break;
+      case PROP_CHANNEL_TYPE:
+        g_value_set_static_string (value,
+            GABBLE_IFACE_OLPC_CHANNEL_TYPE_BUDDYVIEW);
+        break;
+      case PROP_HANDLE_TYPE:
+        g_value_set_uint (value, TP_HANDLE_TYPE_NONE);
+        break;
+      case PROP_HANDLE:
+        g_value_set_uint (value, 0);
+        break;
+      case PROP_INITIATOR_HANDLE:
+        g_value_set_uint (value, base_conn->self_handle);
+        break;
+      case PROP_INITIATOR_ID:
+          {
+            TpHandleRepoIface *repo = tp_base_connection_get_handles (
+                base_conn, TP_HANDLE_TYPE_CONTACT);
+
+            g_value_set_string (value,
+                tp_handle_inspect (repo, base_conn->self_handle));
+          }
+        break;
+      case PROP_TARGET_ID:
+          {
+            g_value_set_string (value, NULL);
+        }
+        break;
+      case PROP_REQUESTED:
+        g_value_set_boolean (value, TRUE);
+        break;
+     case PROP_INTERFACES:
+        g_value_set_boxed (value, gabble_olpc_buddy_view_interfaces);
+        break;
+      case PROP_CHANNEL_DESTROYED:
+        g_value_set_boolean (value, priv->closed);
+        break;
+      case PROP_CHANNEL_PROPERTIES:
+        g_value_take_boxed (value,
+            tp_dbus_properties_mixin_make_properties_hash (object,
+                TP_IFACE_CHANNEL, "TargetHandle",
+                TP_IFACE_CHANNEL, "TargetHandleType",
+                TP_IFACE_CHANNEL, "ChannelType",
+                TP_IFACE_CHANNEL, "TargetID",
+                GABBLE_IFACE_CHANNEL_FUTURE, "InitiatorHandle",
+                GABBLE_IFACE_CHANNEL_FUTURE, "InitiatorID",
+                GABBLE_IFACE_CHANNEL_FUTURE, "Requested",
+                GABBLE_IFACE_OLPC_CHANNEL_INTERFACE_VIEW, "MaxSize",
+                GABBLE_IFACE_OLPC_CHANNEL_INTERFACE_VIEW, "Buddies",
+                GABBLE_IFACE_OLPC_CHANNEL_INTERFACE_VIEW, "Activities",
+                GABBLE_IFACE_OLPC_CHANNEL_TYPE_BUDDYVIEW, "Properties",
+                GABBLE_IFACE_OLPC_CHANNEL_TYPE_BUDDYVIEW, "Alias",
+                NULL));
+        break;
+      case PROP_CONNECTION:
+        g_value_set_object (value, priv->conn);
+        break;
       case PROP_ID:
         g_value_set_uint (value, priv->id);
         break;
+      case PROP_MAX_SIZE:
+        g_value_set_uint (value, priv->max_size);
+        break;
+      case PROP_BUDDIES:
+        g_value_take_boxed (value, tp_handle_set_to_array (priv->buddies));
+        break;
+      case PROP_ACTIVITIES:
+        /* TODO: is that leak free ? */
+        g_value_take_boxed (value, create_activities_array (self));
+        break;
+      case PROP_VIEW_PROPERTIES:
+        g_value_set_boxed (value, priv->properties);
+        break;
+      case PROP_ALIAS:
+        g_value_set_string (value, priv->alias);
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -189,15 +338,32 @@ gabble_olpc_view_set_property (GObject *object,
 
   switch (property_id)
     {
+      case PROP_OBJECT_PATH:
+        g_free (priv->object_path);
+        priv->object_path = g_value_dup_string (value);
+        break;
+      case PROP_HANDLE:
+      case PROP_INITIATOR_HANDLE:
+      case PROP_HANDLE_TYPE:
+      case PROP_CHANNEL_TYPE:
+        /* these properties are writable in the interface, but not actually
+         * meaningfully changeable on this channel, so we do nothing */
+        break;
       case PROP_CONNECTION:
         priv->conn = g_value_get_object (value);
         break;
-      case PROP_TYPE:
-        priv->type = g_value_get_uint (value);
-        break;
       case PROP_ID:
         priv->id = g_value_get_uint (value);
         break;
+      case PROP_MAX_SIZE:
+        priv->max_size = g_value_get_uint (value);
+        break;
+      case PROP_VIEW_PROPERTIES:
+        priv->properties = g_value_dup_boxed (value);
+        break;
+      case PROP_ALIAS:
+        priv->alias = g_value_dup_string (value);
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -238,6 +404,11 @@ gabble_olpc_view_constructor (GType type,
   priv->buddy_rooms = g_hash_table_new_full (g_direct_hash, g_direct_equal,
       NULL, (GDestroyNotify) tp_handle_set_destroy);
 
+  if (priv->properties == NULL)
+    {
+      priv->properties = g_hash_table_new (g_direct_hash, g_direct_equal);
+    }
+
   return obj;
 }
 
@@ -246,6 +417,55 @@ gabble_olpc_view_class_init (GabbleOlpcViewClass *gabble_olpc_view_class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (gabble_olpc_view_class);
   GParamSpec *param_spec;
+   static TpDBusPropertiesMixinPropImpl channel_props[] = {
+      { "TargetHandleType", "handle-type", NULL },
+      { "TargetHandle", "handle", NULL },
+      { "TargetID", "target-id", NULL },
+      { "ChannelType", "channel-type", NULL },
+      { "Interfaces", "interfaces", NULL },
+      { NULL }
+  };
+  static TpDBusPropertiesMixinPropImpl future_props[] = {
+      { "Requested", "requested", NULL },
+      { "InitiatorHandle", "initiator-handle", NULL },
+      { "InitiatorID", "initiator-id", NULL },
+      { NULL }
+  };
+  static TpDBusPropertiesMixinPropImpl view_props[] = {
+      { "MaxSize", "max-size", NULL },
+      { "Buddies", "buddies", NULL },
+      { "Activities", "activities", NULL },
+      { NULL }
+  };
+  static TpDBusPropertiesMixinPropImpl buddy_view_props[] = {
+      { "Properties", "view-properties", NULL },
+      { "Alias", "alias", NULL },
+      { NULL }
+  };
+  /* Add view properties */
+  static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
+      { TP_IFACE_CHANNEL,
+        tp_dbus_properties_mixin_getter_gobject_properties,
+        NULL,
+        channel_props,
+      },
+      { GABBLE_IFACE_CHANNEL_FUTURE,
+        tp_dbus_properties_mixin_getter_gobject_properties,
+        NULL,
+        future_props,
+      },
+      { GABBLE_IFACE_OLPC_CHANNEL_INTERFACE_VIEW,
+        tp_dbus_properties_mixin_getter_gobject_properties,
+        NULL,
+        view_props,
+      },
+      { GABBLE_IFACE_OLPC_CHANNEL_TYPE_BUDDYVIEW,
+        tp_dbus_properties_mixin_getter_gobject_properties,
+        NULL,
+        buddy_view_props,
+      },
+      { NULL }
+  };
 
   object_class->get_property = gabble_olpc_view_get_property;
   object_class->set_property = gabble_olpc_view_set_property;
@@ -257,6 +477,96 @@ gabble_olpc_view_class_init (GabbleOlpcViewClass *gabble_olpc_view_class)
   object_class->dispose = gabble_olpc_view_dispose;
   object_class->finalize = gabble_olpc_view_finalize;
 
+  g_object_class_override_property (object_class, PROP_OBJECT_PATH,
+      "object-path");
+  g_object_class_override_property (object_class, PROP_CHANNEL_TYPE,
+      "channel-type");
+  g_object_class_override_property (object_class, PROP_HANDLE_TYPE,
+      "handle-type");
+  g_object_class_override_property (object_class, PROP_HANDLE, "handle");
+  g_object_class_override_property (object_class, PROP_CHANNEL_DESTROYED,
+      "channel-destroyed");
+  g_object_class_override_property (object_class, PROP_CHANNEL_PROPERTIES,
+      "channel-properties");
+
+  param_spec = g_param_spec_boxed ("interfaces", "Extra D-Bus interfaces",
+      "Additional Channel.Interface.* interfaces",
+      G_TYPE_STRV,
+      G_PARAM_READABLE |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_INTERFACES, param_spec);
+
+  param_spec = g_param_spec_string ("target-id", "Peer's bare JID",
+      "The string obtained by inspecting the peer handle (never the full JID)",
+      NULL,
+      G_PARAM_READABLE |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_TARGET_ID, param_spec);
+
+  param_spec = g_param_spec_boolean ("requested", "Requested?",
+      "True if this channel was requested by the local user",
+      FALSE,
+      G_PARAM_READABLE |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_REQUESTED, param_spec);
+
+  param_spec = g_param_spec_uint ("initiator-handle", "Initiator's handle",
+      "The contact who initiated the channel",
+      0, G_MAXUINT32, 0,
+      G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_INITIATOR_HANDLE,
+      param_spec);
+
+  param_spec = g_param_spec_string ("initiator-id", "Initiator's bare JID",
+      "The string obtained by inspecting the initiator-handle",
+      NULL,
+      G_PARAM_READABLE |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_INITIATOR_ID,
+      param_spec);
+
+  param_spec = g_param_spec_uint ("max-size", "View's max size",
+      "The maximum number of elements that Gadget has to return to the "
+      "search request.",
+      0, G_MAXUINT32, 0,
+      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_MAX_SIZE,
+      param_spec);
+
+  param_spec = g_param_spec_boxed ("buddies", "View's buddies",
+      "The contact handles of the buddies who are in this view channel",
+      GABBLE_ARRAY_TYPE_HANDLE,
+      G_PARAM_READABLE |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_BUDDIES,
+      param_spec);
+
+  param_spec = g_param_spec_boxed ("activities", "View's activities",
+      "The activities which are in this view channel",
+      GABBLE_ARRAY_TYPE_ACTIVITY_LIST,
+      G_PARAM_READABLE |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_ACTIVITIES,
+      param_spec);
+
+  param_spec = g_param_spec_boxed ("view-properties", "View's search properties",
+      "The buddy properties Gadget should look for",
+      TP_HASH_TYPE_STRING_VARIANT_MAP,
+      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_VIEW_PROPERTIES,
+      param_spec);
+
+  param_spec = g_param_spec_string ("alias", "View's search alias",
+      "The buddy alias Gadget should look for",
+      NULL,
+      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+      G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NAME);
+  g_object_class_install_property (object_class, PROP_ALIAS,
+      param_spec);
+
    param_spec = g_param_spec_object (
       "connection",
       "GabbleConnection object",
@@ -270,30 +580,6 @@ gabble_olpc_view_class_init (GabbleOlpcViewClass *gabble_olpc_view_class)
   g_object_class_install_property (object_class, PROP_CONNECTION, param_spec);
 
   param_spec = g_param_spec_uint (
-      "type",
-      "view type",
-      "the type of query who creates this view object. A GabbleOlpcViewType",
-      GABBLE_OLPC_VIEW_TYPE_BUDDY, NUM_GABBLE_OLPC_VIEW_TYPE -1,
-      GABBLE_OLPC_VIEW_TYPE_BUDDY,
-      G_PARAM_CONSTRUCT_ONLY |
-      G_PARAM_READWRITE |
-      G_PARAM_STATIC_NAME |
-      G_PARAM_STATIC_NICK |
-      G_PARAM_STATIC_BLURB);
-  g_object_class_install_property (object_class, PROP_TYPE, param_spec);
-
-  param_spec = g_param_spec_string (
-      "object-path",
-      "D-Bus object path",
-      "The D-Bus object path of this view object",
-      NULL,
-      G_PARAM_READABLE |
-      G_PARAM_STATIC_NAME |
-      G_PARAM_STATIC_NICK |
-      G_PARAM_STATIC_BLURB);
-  g_object_class_install_property (object_class, PROP_OBJECT_PATH, param_spec);
-
-  param_spec = g_param_spec_uint (
       "id",
       "query ID",
       "The ID of the query associated with this view",
@@ -305,16 +591,6 @@ gabble_olpc_view_class_init (GabbleOlpcViewClass *gabble_olpc_view_class)
       G_PARAM_STATIC_BLURB);
   g_object_class_install_property (object_class, PROP_ID, param_spec);
 
-  /* We can't use "closed" as it's already use for the D-Bus signal... */
-  signals[CLOSED] =
-    g_signal_new ("closed_",
-        G_OBJECT_CLASS_TYPE (gabble_olpc_view_class),
-        G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
-        0,
-        NULL, NULL,
-        gabble_marshal_VOID__VOID,
-        G_TYPE_NONE, 0);
-
   signals[BUDDY_ACTIVITIES_CHANGED] =
     g_signal_new ("buddy-activities-changed",
         G_OBJECT_CLASS_TYPE (gabble_olpc_view_class),
@@ -323,55 +599,31 @@ gabble_olpc_view_class_init (GabbleOlpcViewClass *gabble_olpc_view_class)
         NULL, NULL,
         gabble_marshal_VOID__UINT,
         G_TYPE_NONE, 1, G_TYPE_UINT);
+
+  gabble_olpc_view_class->dbus_props_class.interfaces = prop_interfaces;
+  tp_dbus_properties_mixin_class_init (object_class,
+      G_STRUCT_OFFSET (GabbleOlpcViewClass, dbus_props_class));
 }
 
 GabbleOlpcView *
-gabble_olpc_view_new (GabbleConnection *conn,
-                      GabbleOlpcViewType type,
-                      guint id)
+gabble_olpc_buddy_view_new (GabbleConnection *conn,
+                            const gchar *object_path,
+                            guint id,
+                            guint max_size,
+                            GHashTable *properties,
+                            const gchar *alias)
+
 {
   return g_object_new (GABBLE_TYPE_OLPC_VIEW,
+      "object-path", object_path,
       "connection", conn,
-      "type", type,
       "id", id,
+      "max-size", max_size,
+      "view-properties", properties,
+      "alias", alias,
       NULL);
 }
 
-#if 0
-static void
-olpc_view_get_buddies (GabbleSvcOLPCView *iface,
-                       DBusGMethodInvocation *context)
-{
-  GabbleOlpcView *self = GABBLE_OLPC_VIEW (iface);
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
-  GArray *buddies;
-
-  buddies = tp_handle_set_to_array (priv->buddies);
-
-  gabble_svc_olpc_view_return_from_get_buddies (context, buddies);
-
-  g_array_free (buddies, TRUE);
-}
-#endif
-
-static void
-add_activity_to_array (TpHandle handle,
-                       GabbleOlpcActivity *activity,
-                       GPtrArray *array)
-{
-  GValue gvalue = { 0 };
-
-  g_value_init (&gvalue, GABBLE_STRUCT_TYPE_ACTIVITY);
-  g_value_take_boxed (&gvalue, dbus_g_type_specialized_construct
-      (GABBLE_STRUCT_TYPE_ACTIVITY));
-  dbus_g_type_struct_set (&gvalue,
-      0, activity->id,
-      1, activity->room,
-      G_MAXUINT);
-
-  g_ptr_array_add (array, g_value_get_boxed (&gvalue));
-}
-
 static void
 free_activities_array (GPtrArray *activities)
 {
@@ -383,26 +635,6 @@ free_activities_array (GPtrArray *activities)
   g_ptr_array_free (activities, TRUE);
 }
 
-#if 0
-static void
-olpc_view_get_activities (GabbleSvcOLPCView *iface,
-                          DBusGMethodInvocation *context)
-{
-  GabbleOlpcView *self = GABBLE_OLPC_VIEW (iface);
-  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
-  GPtrArray *activities;
-
-  activities = g_ptr_array_new ();
-
-  g_hash_table_foreach (priv->activities, (GHFunc) add_activity_to_array,
-      activities);
-
-  gabble_svc_olpc_view_return_from_get_activities (context, activities);
-
-  free_activities_array (activities);
-}
-#endif
-
 static void
 buddy_left_activities_foreach (TpHandleSet *set,
                                TpHandle buddy,
@@ -418,27 +650,9 @@ buddy_left_activities_foreach (TpHandleSet *set,
       0, buddy);
 }
 
-#if 0
-static void
-olpc_view_close (GabbleSvcOLPCView *iface,
-                 DBusGMethodInvocation *context)
-{
-  GabbleOlpcView *self = GABBLE_OLPC_VIEW (iface);
-  GError *error = NULL;
-
-  if (!gabble_olpc_view_close (self, &error))
-    {
-      dbus_g_method_return_error (context, error);
-      g_error_free (error);
-    }
-
-  gabble_svc_olpc_view_return_from_close (context);
-}
-#endif
-
-gboolean
-gabble_olpc_view_close (GabbleOlpcView *self,
-                        GError **error)
+static gboolean
+do_close (GabbleOlpcView *self,
+          GError **error)
 {
   GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
   LmMessage *msg;
@@ -446,15 +660,14 @@ gabble_olpc_view_close (GabbleOlpcView *self,
 
   id_str = g_strdup_printf ("%u", priv->id);
 
-  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);
-    }
+  msg = lm_message_build (priv->conn->olpc_gadget_buddy,
+      LM_MESSAGE_TYPE_MESSAGE,
+      '(', "close", "",
+        '@', "xmlns", NS_OLPC_BUDDY,
+        '@', "id", id_str,
+      ')', NULL);
+
+#if 0
   else if (priv->type == GABBLE_OLPC_VIEW_TYPE_ACTIVITY)
     {
       msg = lm_message_build (priv->conn->olpc_gadget_activity,
@@ -463,11 +676,7 @@ gabble_olpc_view_close (GabbleOlpcView *self,
             '@', "xmlns", NS_OLPC_ACTIVITY,
             '@', "id", id_str,
           ')', NULL);
-    }
-  else
-    {
-      g_assert_not_reached ();
-    }
+#endif
 
   g_free (id_str);
 
@@ -483,13 +692,85 @@ gabble_olpc_view_close (GabbleOlpcView *self,
   tp_handle_set_foreach (priv->buddies,
       (TpHandleSetMemberFunc) buddy_left_activities_foreach, self);
 
-  g_signal_emit (G_OBJECT (self), signals[CLOSED], 0);
+  priv->closed = TRUE;
 
-  //gabble_svc_olpc_view_emit_closed (self);
+  tp_svc_channel_emit_closed (self);
 
   return TRUE;
 }
 
+/**
+ * gabble_olpc_buddy_view_close
+ *
+ * Implements D-Bus method Close
+ * on interface org.freedesktop.Telepathy.Channel
+ */
+static void
+gabble_olpc_buddy_view_close (TpSvcChannel *iface,
+                              DBusGMethodInvocation *context)
+{
+  GabbleOlpcView *self = GABBLE_OLPC_VIEW (iface);
+  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  GError *error = NULL;
+
+  if (priv->closed)
+    {
+      DEBUG ("Already closed. Doing nothing");
+    }
+  else
+    {
+      /* FIXME: set closed */
+      if (!do_close (self, &error))
+        {
+          dbus_g_method_return_error (context, error);
+          g_error_free (error);
+        }
+    }
+
+  tp_svc_channel_return_from_close (context);
+}
+
+/**
+ * gabble_olpc_buddy_view_get_channel_type
+ *
+ * Implements D-Bus method GetChannelType
+ * on interface org.freedesktop.Telepathy.Channel
+ */
+static void
+gabble_olpc_buddy_view_get_channel_type (TpSvcChannel *iface,
+                                         DBusGMethodInvocation *context)
+{
+  tp_svc_channel_return_from_get_channel_type (context,
+      GABBLE_IFACE_OLPC_CHANNEL_TYPE_BUDDYVIEW);
+}
+
+/**
+ * gabble_olpc_buddy_view_get_handle
+ *
+ * Implements D-Bus method GetHandle
+ * on interface org.freedesktop.Telepathy.Channel
+ */
+static void
+gabble_olpc_buddy_view_get_handle (TpSvcChannel *iface,
+                                   DBusGMethodInvocation *context)
+{
+  tp_svc_channel_return_from_get_handle (context, TP_HANDLE_TYPE_NONE, 0);
+}
+
+/**
+ * gabble_olpc_buddy_view_get_interfaces
+ *
+ * Implements D-Bus method GetInterfaces
+ * on interface org.freedesktop.Telepathy.Channel
+ */
+static void
+gabble_olpc_buddy_view_get_interfaces (TpSvcChannel *iface,
+                                       DBusGMethodInvocation *context)
+{
+  tp_svc_channel_return_from_get_interfaces (context,
+      gabble_olpc_buddy_view_interfaces);
+}
+
 /* If room is not zero, these buddies are associated with the activity
  * of this room. They'll leave the view if the activity is removed.
  */
@@ -557,7 +838,8 @@ gabble_olpc_view_add_buddies (GabbleOlpcView *self,
         }
     }
 
-  //gabble_svc_olpc_view_emit_buddies_changed (self, buddies, empty);
+  gabble_svc_olpc_channel_interface_view_emit_buddies_changed (self, buddies,
+      empty);
 
   for (i = 0; i < buddies_changed->len; i++)
     {
@@ -599,7 +881,8 @@ gabble_olpc_view_remove_buddies (GabbleOlpcView *self,
   empty = g_array_new (FALSE, FALSE, sizeof (TpHandle));
   removed = tp_handle_set_to_array (buddies);
 
-  //gabble_svc_olpc_view_emit_buddies_changed (self, empty, removed);
+  gabble_svc_olpc_channel_interface_view_emit_buddies_changed (self, empty,
+      removed);
 
   g_array_free (empty, TRUE);
   g_array_free (removed, TRUE);
@@ -653,7 +936,8 @@ gabble_olpc_view_add_activities (GabbleOlpcView *self,
 
   empty = g_ptr_array_new ();
 
-  //gabble_svc_olpc_view_emit_activities_changed (self, added, empty);
+  gabble_svc_olpc_channel_interface_view_emit_activities_changed (self, added,
+      empty);
 
   free_activities_array (added);
   g_ptr_array_free (empty, TRUE);
@@ -739,7 +1023,8 @@ gabble_olpc_view_remove_activities (GabbleOlpcView *self,
       tp_handle_set_destroy (ctx.removed);
     }
 
-  //gabble_svc_olpc_view_emit_activities_changed (self, empty, removed);
+  gabble_svc_olpc_channel_interface_view_emit_activities_changed (self, empty,
+      removed);
 
   free_activities_array (removed);
   g_ptr_array_free (empty, TRUE);
@@ -840,18 +1125,118 @@ gabble_olpc_view_buddies_left_activity (GabbleOlpcView *self,
   tp_handle_set_destroy (removed);
 }
 
+static LmHandlerResult
+buddy_view_query_result_cb (GabbleConnection *conn,
+                            LmMessage *sent_msg,
+                            LmMessage *reply_msg,
+                            GObject *_view,
+                            gpointer user_data)
+{
+  LmMessageNode *view_node;
+  GabbleOlpcView *self = GABBLE_OLPC_VIEW (_view);
+
+  view_node = lm_message_node_get_child_with_namespace (reply_msg->node,
+      "view", NS_OLPC_BUDDY);
+  if (view_node == NULL)
+    return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+
+  /* FIXME: make sense to call this conn-olpc function ? */
+  add_buddies_to_view_from_node (conn, self, view_node, "buddy", 0);
+
+  return LM_HANDLER_RESULT_REMOVE_MESSAGE;
+}
+
+gboolean
+gabble_olpc_buddy_view_send_request (GabbleOlpcView *self,
+                                     GError **error)
+
+{
+  GabbleOlpcViewPrivate *priv = GABBLE_OLPC_VIEW_GET_PRIVATE (self);
+  LmMessage *query;
+  gchar *max_str, *id_str;
+
+  max_str = g_strdup_printf ("%u", priv->max_size);
+  id_str = g_strdup_printf ("%u", priv->id);
+
+  /* TODO: Implement multi criterias properties */
+  /* TODO: Always use the max_size argument */
+  if (g_hash_table_size (priv->properties) != 0)
+    {
+      LmMessageNode *properties_node;
+
+      query = lm_message_build_with_sub_type (priv->conn->olpc_gadget_buddy,
+        LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
+        '(', "view", "",
+            '@', "xmlns", NS_OLPC_BUDDY,
+            '@', "id", id_str,
+            '(', "buddy", "",
+              '(', "properties", "",
+                '*', &properties_node,
+                '@', "xmlns", NS_OLPC_BUDDY_PROPS,
+              ')',
+            ')',
+        ')',
+        NULL);
+
+      lm_message_node_add_children_from_properties (properties_node,
+          priv->properties, "property");
+    }
+  else if (priv->alias != NULL)
+    {
+      query = lm_message_build_with_sub_type (priv->conn->olpc_gadget_buddy,
+        LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
+        '(', "view", "",
+            '@', "xmlns", NS_OLPC_BUDDY,
+            '@', "id", id_str,
+            '(', "buddy", "",
+              '@', "alias", priv->alias,
+            ')',
+        ')',
+        NULL);
+    }
+  else
+    {
+      query = lm_message_build_with_sub_type (priv->conn->olpc_gadget_buddy,
+          LM_MESSAGE_TYPE_IQ, LM_MESSAGE_SUB_TYPE_GET,
+          '(', "view", "",
+              '@', "xmlns", NS_OLPC_BUDDY,
+              '@', "id", id_str,
+              '(', "random", "",
+                '@', "max", max_str,
+              ')',
+          ')',
+          NULL);
+    }
+
+  g_free (max_str);
+  g_free (id_str);
+
+  if (!_gabble_connection_send_with_reply (priv->conn, query,
+        buddy_view_query_result_cb, G_OBJECT (self), NULL, NULL))
+    {
+      g_set_error (error, TP_ERRORS, TP_ERROR_NETWORK_ERROR,
+        "Failed to send buddy search query to server");
+
+      DEBUG ("Failed to send buddy search query to server");
+      lm_message_unref (query);
+      return FALSE;
+    }
+
+  lm_message_unref (query);
+
+  return TRUE;
+}
+
 static void
-view_iface_init (gpointer g_iface,
-                 gpointer iface_data)
+channel_iface_init (gpointer g_iface, gpointer iface_data)
 {
-#if 0
-  GabbleSvcOLPCViewClass *klass = g_iface;
+  TpSvcChannelClass *klass = (TpSvcChannelClass *) g_iface;
 
-#define IMPLEMENT(x) gabble_svc_olpc_view_implement_##x (\
-    klass, olpc_view_##x)
-  IMPLEMENT(get_buddies);
-  IMPLEMENT(get_activities);
+#define IMPLEMENT(x) tp_svc_channel_implement_##x (\
+    klass, gabble_olpc_buddy_view_##x)
   IMPLEMENT(close);
+  IMPLEMENT(get_channel_type);
+  IMPLEMENT(get_handle);
+  IMPLEMENT(get_interfaces);
 #undef IMPLEMENT
-#endif
 }
diff --git a/src/olpc-buddy-view.h b/src/olpc-buddy-view.h
index 28de0e5..5b4c023 100644
--- a/src/olpc-buddy-view.h
+++ b/src/olpc-buddy-view.h
@@ -29,18 +29,12 @@
 
 G_BEGIN_DECLS
 
-typedef enum
-{
-  GABBLE_OLPC_VIEW_TYPE_BUDDY,
-  GABBLE_OLPC_VIEW_TYPE_ACTIVITY,
-  NUM_GABBLE_OLPC_VIEW_TYPE
-} GabbleOlpcViewType;
-
-typedef struct _GabbleOlpcView GabbleOlpcView;
 typedef struct _GabbleOlpcViewClass GabbleOlpcViewClass;
 
 struct _GabbleOlpcViewClass {
   GObjectClass parent_class;
+
+  TpDBusPropertiesMixinClass dbus_props_class;
 };
 
 struct _GabbleOlpcView {
@@ -67,8 +61,12 @@ GType gabble_olpc_view_get_type (void);
   (G_TYPE_INSTANCE_GET_CLASS ((obj), GABBLE_TYPE_OLPC_VIEW,\
                               GabbleOlpcViewClass))
 
-GabbleOlpcView * gabble_olpc_view_new (GabbleConnection *conn,
-    GabbleOlpcViewType type, guint id);
+GabbleOlpcView * gabble_olpc_buddy_view_new (GabbleConnection *conn,
+    const gchar *object_path, guint id, guint max_size, GHashTable *properties,
+    const gchar *alias);
+
+gboolean gabble_olpc_buddy_view_send_request (GabbleOlpcView *view,
+    GError **error);
 
 /* FIXME: fix method names */
 /* FIXME: most of this should be moved to an abstract class */
@@ -96,8 +94,6 @@ GPtrArray * gabble_olpc_view_get_buddy_activities (GabbleOlpcView *self,
 void gabble_olpc_view_buddies_left_activity (GabbleOlpcView *self,
     GArray *buddies, TpHandle room);
 
-gboolean gabble_olpc_view_close (GabbleOlpcView *self, GError **error);
-
 G_END_DECLS
 
 #endif /* #ifndef __GABBLE_OLPC_VIEW_H__ */
diff --git a/src/types.h b/src/types.h
index 5a00309..23d8f24 100644
--- a/src/types.h
+++ b/src/types.h
@@ -39,6 +39,9 @@ typedef struct _GabbleVCardManager GabbleVCardManager;
 typedef struct _GabbleBytestreamFactory GabbleBytestreamFactory;
 typedef struct _GabblePrivateTubesFactory GabblePrivateTubesFactory;
 typedef struct _GabbleRequestPipeline GabbleRequestPipeline;
+typedef struct _GabbleOlpcView GabbleOlpcView;
+typedef struct _GabbleOlpcGadgetManager GabbleOlpcGadgetManager;
+
 
 typedef enum {
     INITIATOR_INVALID = -1,
-- 
1.5.6.5




More information about the Telepathy-commits mailing list