[vino] Add TpContact Alias in the status notification



commit bacdce6772e1c4ee7c4805888f3a2eed2bd8890a
Author: Arnaud Maillet <arnaud maillet collabora co uk>
Date:   Wed Jun 10 11:16:59 2009 +0200

    Add TpContact Alias in the status notification

 server/vino-status-icon.c |   83 +++++++++++++++++++++++++++++++++++++++------
 server/vino-tube-server.c |   56 +++++++++++++++++++++++++++---
 server/vino-tube-server.h |    2 +
 3 files changed, 125 insertions(+), 16 deletions(-)
---
diff --git a/server/vino-status-icon.c b/server/vino-status-icon.c
index 2b2b48d..acb50ba 100644
--- a/server/vino-status-icon.c
+++ b/server/vino-status-icon.c
@@ -33,6 +33,10 @@
 #include "vino-enums.h"
 #include "vino-util.h"
 
+#ifdef HAVE_TELEPATHY_GLIB
+#include "vino-tube-server.h"
+#endif
+
 struct _VinoStatusIconPrivate
 {
   GtkMenu    *menu;
@@ -332,19 +336,44 @@ vino_status_icon_disconnect_confirm (VinoStatusIconNotify *a)
     return;
   }
 
+#ifdef HAVE_TELEPATHY_GLIB
+  if (VINO_IS_TUBE_SERVER (icon->priv->server))
+    {
+      /* Translators: %s is the alias of the telepathy contact */
+      primary_msg   = g_strdup_printf
+          (_("Are you sure you want to disconnect '%s'?"),
+          vino_tube_server_get_alias (VINO_TUBE_SERVER
+          (icon->priv->server)));
+      secondary_msg = g_strdup_printf
+          (_("The remote user '%s' will be disconnected. Are you sure?"),
+          vino_tube_server_get_alias (VINO_TUBE_SERVER
+          (icon->priv->server)));
+    }
+  else
+    {
+#endif
+
   if (client != NULL)
     {
       /* Translators: %s is a hostname */
-      primary_msg   = g_strdup_printf (_("Are you sure you want to disconnect '%s'?"),
-                                       vino_client_get_hostname (client));
-      secondary_msg = g_strdup_printf (_("The remote user from '%s' will be disconnected. Are you sure?"),
-                                       vino_client_get_hostname (client));
+      primary_msg   = g_strdup_printf
+          (_("Are you sure you want to disconnect '%s'?"),
+          vino_client_get_hostname (client));
+      secondary_msg = g_strdup_printf
+          (_("The remote user from '%s' will be disconnected. Are you sure?"),
+          vino_client_get_hostname (client));
     }
   else
     {
-      primary_msg   = g_strdup (_("Are you sure you want to disconnect all clients?"));
-      secondary_msg = g_strdup (_("All remote users will be disconnected. Are you sure?"));
+      primary_msg   = g_strdup
+          (_("Are you sure you want to disconnect all clients?"));
+      secondary_msg = g_strdup
+          (_("All remote users will be disconnected. Are you sure?"));
+    }
+
+#ifdef HAVE_TELEPATHY_GLIB
     }
+#endif
 
   icon->priv->disconnect_dialog = gtk_message_dialog_new (NULL,
                                                           GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -419,8 +448,18 @@ vino_status_icon_popup_menu (GtkStatusIcon *status_icon,
       a->icon   = icon;
       a->client = client;
 
+#ifdef HAVE_TELEPATHY_GLIB
+      if (VINO_IS_TUBE_SERVER (icon->priv->server))
+        /* Translators: %s is the alias of the telepathy contact */
+        str = g_strdup_printf (_("Disconnect %s"),
+            vino_tube_server_get_alias (VINO_TUBE_SERVER
+            (icon->priv->server)));
+      else
+#endif
+
       /* Translators: %s is a hostname */
-      str = g_strdup_printf (_("Disconnect %s"), vino_client_get_hostname (client));
+      str = g_strdup_printf (_("Disconnect %s"),
+          vino_client_get_hostname (client));
 
       item  = gtk_image_menu_item_new_with_label (str);
       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
@@ -599,19 +638,41 @@ vino_status_icon_show_new_client_notification (gpointer user_data)
       icon->priv->new_client_notification = NULL;
     }
 
+#ifdef HAVE_TELEPATHY_GLIB
+  if (VINO_IS_TUBE_SERVER (icon->priv->server))
+    {
+       /* Translators: %s is the alias of the telepathy contact */
+      summary = _("Another user is controlling your desktop");
+      body = g_strdup_printf
+          (_("'%s' is remotely controlling your desktop."),
+          vino_tube_server_get_alias (VINO_TUBE_SERVER
+          (icon->priv->server)));
+    }
+  else
+    {
+#endif
+
   if (vino_server_get_view_only (icon->priv->server))
     {
+      /* Translators: %s is a hostname */
       summary = _("Another user is viewing your desktop");
-      body = g_strdup_printf (_("A user on the computer '%s' is remotely viewing your desktop."),
-                              vino_client_get_hostname (client));
+      body = g_strdup_printf
+          (_("A user on the computer '%s' is remotely viewing your desktop."),
+          vino_client_get_hostname (client));
     }
   else
     {
+      /* Translators: %s is a hostname */
       summary = _("Another user is controlling your desktop");
-      body = g_strdup_printf (_("A user on the computer '%s' is remotely controlling your desktop."),
-                              vino_client_get_hostname (client));
+      body = g_strdup_printf
+          (_("A user on the computer '%s' is remotely controlling "
+          "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,
diff --git a/server/vino-tube-server.c b/server/vino-tube-server.c
index 437f032..0f8a7ea 100644
--- a/server/vino-tube-server.c
+++ b/server/vino-tube-server.c
@@ -25,6 +25,7 @@
 #include <telepathy-glib/connection.h>
 #include <telepathy-glib/dbus.h>
 #include <telepathy-glib/util.h>
+#include <telepathy-glib/contact.h>
 
 
 #include "vino-tube-server.h"
@@ -39,6 +40,7 @@ G_DEFINE_TYPE (VinoTubeServer, vino_tube_server, VINO_TYPE_SERVER);
 struct _VinoTubeServerPrivate
 {
   TpChannel *tp_channel;
+  gchar *alias;
   gchar *connection_path;
   gchar *tube_path;
   GHashTable *channel_properties;
@@ -80,6 +82,12 @@ 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->connection_path != NULL)
     {
       g_free (server->priv->connection_path);
@@ -272,11 +280,37 @@ vino_tube_server_offer_cb (TpChannel *proxy,
 }
 
 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;
+
+  if (error != NULL)
+    {
+      g_printerr ("Impossible to get the contact name: %s\n", error->message);
+      return;
+    }
+
+  contact = contacts[0];
+  server->priv->alias = g_strdup (tp_contact_get_alias (contact));
+}
+
+static void
 vino_tube_server_channel_ready (TpChannel *channel,
     const GError *error,
-    gpointer server)
+    gpointer object)
 {
-  TpConnection *tp_connection;
+  VinoTubeServer *server = VINO_TUBE_SERVER (object);
+  TpConnection *connection;
+  TpHandle handle;
+  TpContactFeature features[] = { TP_CONTACT_FEATURE_ALIAS };
   GHashTable *parameters;
   GValue address = {0,};
   gint port;
@@ -290,7 +324,13 @@ vino_tube_server_channel_ready (TpChannel *channel,
       return;
     }
 
-  g_object_get (channel, "connection", &tp_connection, NULL);
+  connection = tp_channel_borrow_connection (server->priv->tp_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,
+      server, NULL, NULL);
 
   port = vino_server_get_port (VINO_SERVER (server));
 
@@ -311,7 +351,6 @@ vino_tube_server_channel_ready (TpChannel *channel,
 
   g_value_unset (&address);
   g_hash_table_destroy (parameters);
-  g_object_unref (tp_connection);
 }
 
 static void
@@ -386,4 +425,11 @@ vino_tube_server_share_with_tube (VinoTubeServer *server,
   g_object_unref (tp_dbus_daemon);
 
   return TRUE;
-}
\ No newline at end of file
+}
+
+const gchar*
+vino_tube_server_get_alias (VinoTubeServer *self)
+{
+  VinoTubeServer *server = VINO_TUBE_SERVER (self);
+  return (const gchar*)server->priv->alias;
+}
diff --git a/server/vino-tube-server.h b/server/vino-tube-server.h
index 85d7340..84b86e4 100644
--- a/server/vino-tube-server.h
+++ b/server/vino-tube-server.h
@@ -62,6 +62,8 @@ struct _VinoTubeServerClass
 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);
+
 G_END_DECLS
 
 #endif /* __VINO_TUBE_SERVER_H__ */
\ No newline at end of file



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