[vino] Add the avatar's contact in vino notification



commit 0dc639d2ecb5f4fb7f9842bc291061a3e6a31634
Author: Arnaud Maillet <arnaud maillet collabora co uk>
Date:   Fri Jun 12 12:31:04 2009 +0200

    Add the avatar's contact in vino notification

 server/vino-status-icon.c |   23 ++++++++++--
 server/vino-tube-server.c |   89 +++++++++++++++++++++++++++++++++++++++++++--
 server/vino-tube-server.h |    2 +-
 3 files changed, 106 insertions(+), 8 deletions(-)
---
diff --git a/server/vino-status-icon.c b/server/vino-status-icon.c
index acb50ba..6969735 100644
--- a/server/vino-status-icon.c
+++ b/server/vino-status-icon.c
@@ -612,6 +612,10 @@ vino_status_icon_show_new_client_notification (gpointer user_data)
   VinoStatusIcon *icon    = a->icon;
   VinoClient     *client  = a->client;
 
+#ifdef HAVE_TELEPATHY_GLIB
+  const gchar *filename = NULL;
+#endif
+
   if (vino_server_get_prompt_enabled (icon->priv->server))
   {
     g_free (user_data);
@@ -647,6 +651,17 @@ vino_status_icon_show_new_client_notification (gpointer user_data)
           (_("'%s' is remotely controlling your desktop."),
           vino_tube_server_get_alias (VINO_TUBE_SERVER
           (icon->priv->server)));
+      filename = vino_tube_server_get_avatar_filename (VINO_TUBE_SERVER
+          (icon->priv->server));
+
+      if (filename == NULL)
+        filename = "stock_person";
+
+      icon->priv->new_client_notification =
+          notify_notification_new_with_status_icon (summary,
+                                                    body,
+                                                    filename,
+                                                    GTK_STATUS_ICON (icon));
     }
   else
     {
@@ -669,16 +684,16 @@ vino_status_icon_show_new_client_notification (gpointer user_data)
           "your desktop."), vino_client_get_hostname (client));
     }
 
-#ifdef HAVE_TELEPATHY_GLIB
-    }
-#endif
-
   icon->priv->new_client_notification =
     notify_notification_new_with_status_icon (summary,
                                               body,
                                               "preferences-desktop-remote-desktop",
                                               GTK_STATUS_ICON (icon));
 
+#ifdef HAVE_TELEPATHY_GLIB
+    }
+#endif
+
   g_free (body);
 
   g_signal_connect_swapped (icon->priv->new_client_notification, "closed",
diff --git a/server/vino-tube-server.c b/server/vino-tube-server.c
index 0f8a7ea..ddbb1cc 100644
--- a/server/vino-tube-server.c
+++ b/server/vino-tube-server.c
@@ -31,6 +31,9 @@
 #include "vino-tube-server.h"
 #include "vino-dbus-error.h"
 
+#define MC_DBUS_SERVICE "org.freedesktop.Telepathy.MissionControl"
+#define MC_DBUS_SERVICE_PATH "/org/freedesktop/Telepathy/MissionControl"
+
 G_DEFINE_TYPE (VinoTubeServer, vino_tube_server, VINO_TYPE_SERVER);
 
 #define VINO_TUBE_SERVER_GET_PRIVATE(obj)\
@@ -44,6 +47,7 @@ struct _VinoTubeServerPrivate
   gchar *connection_path;
   gchar *tube_path;
   GHashTable *channel_properties;
+  gchar *filename;
 };
 
 enum
@@ -88,6 +92,12 @@ vino_tube_server_finalize (GObject *object)
       server->priv->alias = NULL;
     }
 
+  if (server->priv->filename != NULL)
+    {
+      g_free (server->priv->filename);
+      server->priv->filename = NULL;
+    }
+
   if (server->priv->connection_path != NULL)
     {
       g_free (server->priv->connection_path);
@@ -279,6 +289,59 @@ vino_tube_server_offer_cb (TpChannel *proxy,
     }
 }
 
+static gchar *
+vino_tube_server_contact_get_avatar_filename (TpContact *contact,
+    const gchar *token,
+    VinoTubeServer *self)
+{
+  TpConnection *connection;
+  gchar *avatar_path;
+  gchar *avatar_file;
+  gchar *token_escaped;
+  gchar *contact_escaped;
+  gchar *mc_account_unique_name;
+  GError *error = NULL;
+  DBusGProxy *proxy;
+
+  connection = tp_contact_get_connection (contact);
+
+  proxy = dbus_g_proxy_new_for_name (tp_get_bus (), MC_DBUS_SERVICE,
+      MC_DBUS_SERVICE_PATH, MC_DBUS_SERVICE);
+
+  /* Have to do that while waiting for mission control 5 because
+  there is no mc API in telepathy-glib */
+  if (!dbus_g_proxy_call (proxy, "GetAccountForConnection", &error,
+      G_TYPE_STRING, tp_proxy_get_object_path (connection),
+      G_TYPE_INVALID,
+      G_TYPE_STRING, &mc_account_unique_name,
+      G_TYPE_INVALID))
+    {
+      g_printerr ("Failed to request name: %s",
+          error ? error->message : "No error given");
+      g_clear_error (&error);
+      return NULL;
+    }
+
+  contact_escaped = tp_escape_as_identifier (tp_contact_get_identifier
+      (contact));
+
+  token_escaped = tp_escape_as_identifier (token);
+  connection = tp_contact_get_connection (contact);
+
+  avatar_path = g_build_filename (g_get_user_cache_dir (),
+      "Empathy", "avatars", mc_account_unique_name,
+      contact_escaped, NULL);
+
+  avatar_file = g_build_filename (avatar_path, token_escaped, NULL);
+
+  g_free (contact_escaped);
+  g_free (token_escaped);
+  g_free (avatar_path);
+  g_object_unref (proxy);
+
+  return avatar_file;
+}
+
 static void
 vino_tube_server_factory_handle_cb (TpConnection *connection,
     guint n_contacts,
@@ -291,6 +354,7 @@ vino_tube_server_factory_handle_cb (TpConnection *connection,
 {
   VinoTubeServer *server = VINO_TUBE_SERVER (self);
   TpContact *contact;
+  const gchar *token;
 
   if (error != NULL)
     {
@@ -300,6 +364,17 @@ vino_tube_server_factory_handle_cb (TpConnection *connection,
 
   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);
+    }
 }
 
 static void
@@ -310,7 +385,8 @@ vino_tube_server_channel_ready (TpChannel *channel,
   VinoTubeServer *server = VINO_TUBE_SERVER (object);
   TpConnection *connection;
   TpHandle handle;
-  TpContactFeature features[] = { TP_CONTACT_FEATURE_ALIAS };
+  TpContactFeature features[] = { TP_CONTACT_FEATURE_ALIAS,
+      TP_CONTACT_FEATURE_AVATAR_TOKEN };
   GHashTable *parameters;
   GValue address = {0,};
   gint port;
@@ -328,8 +404,8 @@ vino_tube_server_channel_ready (TpChannel *channel,
 
   handle = tp_channel_get_handle (server->priv->tp_channel, NULL);
 
-  tp_connection_get_contacts_by_handle (connection, 1, &handle, 1,
-      features, vino_tube_server_factory_handle_cb,
+  tp_connection_get_contacts_by_handle (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));
@@ -433,3 +509,10 @@ vino_tube_server_get_alias (VinoTubeServer *self)
   VinoTubeServer *server = VINO_TUBE_SERVER (self);
   return (const gchar*)server->priv->alias;
 }
+
+const gchar*
+vino_tube_server_get_avatar_filename (VinoTubeServer *self)
+{
+  VinoTubeServer *server = VINO_TUBE_SERVER (self);
+  return (const gchar*)server->priv->filename;
+}
diff --git a/server/vino-tube-server.h b/server/vino-tube-server.h
index 84b86e4..7b54f4a 100644
--- a/server/vino-tube-server.h
+++ b/server/vino-tube-server.h
@@ -24,7 +24,6 @@
 #define __VINO_TUBE_SERVER_H__
 
 #include <glib-object.h>
-
 #include "vino-server.h"
 
 G_BEGIN_DECLS
@@ -63,6 +62,7 @@ GType vino_tube_server_get_type (void) G_GNUC_CONST;
 gboolean vino_tube_server_share_with_tube (VinoTubeServer *server,
      GError **error);
 const gchar* vino_tube_server_get_alias (VinoTubeServer *self);
+const gchar* vino_tube_server_get_avatar_filename (VinoTubeServer *self);
 
 G_END_DECLS
 



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