[vino] Rely on the factory to prepare the TpContact



commit 1e4cf3ad8892fb80b353c944c666d606a72ad1b8
Author: Guillaume Desmottes <guillaume desmottes collabora co uk>
Date:   Tue Apr 24 14:17:29 2012 +0200

    Rely on the factory to prepare the TpContact
    
    See bug 674707.

 server/vino-tube-server.c          |  100 ++++++++++++++++--------------------
 server/vino-tube-servers-manager.c |    9 +++
 2 files changed, 54 insertions(+), 55 deletions(-)
---
diff --git a/server/vino-tube-server.c b/server/vino-tube-server.c
index c91778d..edbd366 100644
--- a/server/vino-tube-server.c
+++ b/server/vino-tube-server.c
@@ -44,7 +44,6 @@ G_DEFINE_TYPE (VinoTubeServer, vino_tube_server, VINO_TYPE_SERVER);
 struct _VinoTubeServerPrivate
 {
   TpChannel *tp_channel;
-  gchar *alias;
   TpConnection *connection;
   gchar *filename;
   gulong signal_invalidated_id;
@@ -67,6 +66,38 @@ enum
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
+static gchar * vino_tube_server_contact_get_avatar_filename (TpContact *contact,
+    const gchar *token,
+    VinoTubeServer *self);
+
+static void
+vino_tube_server_constructed (GObject *object)
+{
+  VinoTubeServer *self = VINO_TUBE_SERVER (object);
+  TpContact *contact;
+  const gchar *token;
+
+  if (G_OBJECT_CLASS (vino_tube_server_parent_class)->constructed)
+    G_OBJECT_CLASS (vino_tube_server_parent_class)->constructed (object);
+
+  g_assert (self->priv->tp_channel != NULL);
+
+  contact = tp_channel_get_target_contact (self->priv->tp_channel);
+  g_assert (contact != NULL);
+
+  token = tp_contact_get_avatar_token (contact);
+
+  if (!tp_str_empty (token))
+    {
+      self->priv->filename = NULL;
+    }
+  else
+    {
+      self->priv->filename = vino_tube_server_contact_get_avatar_filename
+          (contact, token, self);
+    }
+}
+
 static void
 vino_tube_server_dispose (GObject *object)
 {
@@ -96,12 +127,6 @@ vino_tube_server_finalize (GObject *object)
 {
   VinoTubeServer *server = VINO_TUBE_SERVER (object);
 
-  if (server->priv->alias != NULL)
-    {
-      g_free (server->priv->alias);
-      server->priv->alias = NULL;
-    }
-
   if (server->priv->filename != NULL)
     {
       g_free (server->priv->filename);
@@ -198,6 +223,7 @@ vino_tube_server_class_init (VinoTubeServerClass *klass)
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
   gobject_class->dispose = vino_tube_server_dispose;
+  gobject_class->constructed = vino_tube_server_constructed;
   gobject_class->finalize = vino_tube_server_finalize;
   gobject_class->set_property = vino_tube_server_set_property;
   gobject_class->get_property = vino_tube_server_get_property;
@@ -376,48 +402,10 @@ vino_tube_server_contact_get_avatar_filename (TpContact *contact,
   return avatar_file;
 }
 
-static void
-vino_tube_server_factory_handle_cb (TpConnection *connection,
-    guint n_contacts,
-    TpContact * const *contacts,
-    guint n_failed,
-    const TpHandle *failed,
-    const GError *error,
-    gpointer self,
-    GObject *weak_object)
-{
-  VinoTubeServer *server = VINO_TUBE_SERVER (self);
-  TpContact *contact;
-  const gchar *token;
-
-  if (error != NULL)
-    {
-      dprintf (TUBE, "Impossible to get the contact name: %s\n", error->message);
-      return;
-    }
-
-  contact = contacts[0];
-  server->priv->alias = g_strdup (tp_contact_get_alias (contact));
-  token = tp_contact_get_avatar_token (contact);
-
-  if (!tp_strdiff (token, ""))
-    {
-      server->priv->filename = NULL;
-    }
-  else
-    {
-      server->priv->filename = vino_tube_server_contact_get_avatar_filename
-          (contact, token, self);
-    }
-}
-
 gboolean
 vino_tube_server_share_with_tube (VinoTubeServer *server,
     GError **error)
 {
-  TpHandle handle;
-  TpContactFeature features[] = { TP_CONTACT_FEATURE_ALIAS,
-      TP_CONTACT_FEATURE_AVATAR_TOKEN };
   GHashTable *parameters;
   GValue address = {0,};
   gint port;
@@ -442,12 +430,6 @@ vino_tube_server_share_with_tube (VinoTubeServer *server,
       return FALSE;
     }
 
-  handle = tp_channel_get_handle (server->priv->tp_channel, NULL);
-
-  tp_connection_get_contacts_by_handle (server->priv->connection, 1, &handle,
-      G_N_ELEMENTS(features), features, vino_tube_server_factory_handle_cb,
-      server, NULL, NULL);
-
   port = vino_server_get_port (VINO_SERVER (server));
 
   dprintf (TUBE, "Creation of a VinoTubeServer, port : %d\n", port);
@@ -475,13 +457,21 @@ vino_tube_server_share_with_tube (VinoTubeServer *server,
 const gchar*
 vino_tube_server_get_alias (VinoTubeServer *self)
 {
-  VinoTubeServer *server = VINO_TUBE_SERVER (self);
-  return (const gchar*)server->priv->alias;
+  TpContact *contact;
+
+  contact = tp_channel_get_target_contact (self->priv->tp_channel);
+  g_return_val_if_fail (contact != NULL, NULL);
+
+  return tp_contact_get_alias (contact);
 }
 
 const gchar*
 vino_tube_server_get_avatar_filename (VinoTubeServer *self)
 {
-  VinoTubeServer *server = VINO_TUBE_SERVER (self);
-  return (const gchar*)server->priv->filename;
+  TpContact *contact;
+
+  contact = tp_channel_get_target_contact (self->priv->tp_channel);
+  g_return_val_if_fail (contact != NULL, NULL);
+
+  return tp_contact_get_alias (contact);
 }
diff --git a/server/vino-tube-servers-manager.c b/server/vino-tube-servers-manager.c
index 263d720..70be03e 100644
--- a/server/vino-tube-servers-manager.c
+++ b/server/vino-tube-servers-manager.c
@@ -117,6 +117,15 @@ vino_tube_servers_manager_init (VinoTubeServersManager *self)
   factory = TP_SIMPLE_CLIENT_FACTORY (tp_automatic_client_factory_new (dbus));
   g_object_unref (dbus);
 
+  tp_simple_client_factory_add_contact_features_varargs (factory,
+      TP_CONTACT_FEATURE_ALIAS,
+      TP_CONTACT_FEATURE_AVATAR_TOKEN,
+      TP_CONTACT_FEATURE_INVALID);
+
+  tp_simple_client_factory_add_channel_features_varargs (factory,
+      TP_CHANNEL_FEATURE_CONTACTS,
+      0);
+
   self->priv->handler = tp_simple_handler_new_with_factory (factory, FALSE,
       FALSE, "Vino", FALSE, handle_channels_cb, self, NULL);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]