[telepathy-mission-control/master] McdClientProxy: pre-load unique name if known

Simon McVittie simon.mcvittie at collabora.co.uk
Mon May 25 09:35:49 PDT 2009


---
 src/mcd-client-priv.h |    3 +-
 src/mcd-client.c      |   60 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/mcd-dispatcher.c  |   16 +++++++-----
 3 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/src/mcd-client-priv.h b/src/mcd-client-priv.h
index 40f8699..4604727 100644
--- a/src/mcd-client-priv.h
+++ b/src/mcd-client-priv.h
@@ -67,7 +67,8 @@ G_GNUC_INTERNAL GType _mcd_client_proxy_get_type (void);
                               McdClientProxyClass))
 
 G_GNUC_INTERNAL McdClientProxy *_mcd_client_proxy_new (
-    TpDBusDaemon *dbus_daemon, const gchar *name_suffix);
+    TpDBusDaemon *dbus_daemon, const gchar *name_suffix,
+    const gchar *unique_name_if_known);
 
 G_GNUC_INTERNAL gboolean _mcd_client_check_valid_name (
     const gchar *name_suffix, GError **error);
diff --git a/src/mcd-client.c b/src/mcd-client.c
index 262c77c..6369005 100644
--- a/src/mcd-client.c
+++ b/src/mcd-client.c
@@ -37,6 +37,12 @@ G_DEFINE_TYPE (McdClientProxy, _mcd_client_proxy, TP_TYPE_PROXY);
 
 enum
 {
+    PROP_0,
+    PROP_UNIQUE_NAME,
+};
+
+enum
+{
     S_READY,
     N_SIGNALS
 };
@@ -139,6 +145,45 @@ mcd_client_proxy_constructed (GObject *object)
 }
 
 static void
+mcd_client_proxy_get_property (GObject *object,
+                               guint property,
+                               GValue *value,
+                               GParamSpec *param_spec)
+{
+    McdClientProxy *self = MCD_CLIENT_PROXY (object);
+
+    switch (property)
+    {
+        case PROP_UNIQUE_NAME:
+            g_value_set_string (value, self->priv->unique_name);
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property, param_spec);
+    }
+}
+
+static void
+mcd_client_proxy_set_property (GObject *object,
+                               guint property,
+                               const GValue *value,
+                               GParamSpec *param_spec)
+{
+    McdClientProxy *self = MCD_CLIENT_PROXY (object);
+
+    switch (property)
+    {
+        case PROP_UNIQUE_NAME:
+            g_assert (self->priv->unique_name == NULL);
+            self->priv->unique_name = g_value_dup_string (value);
+            break;
+
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property, param_spec);
+    }
+}
+
+static void
 _mcd_client_proxy_class_init (McdClientProxyClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -146,12 +191,23 @@ _mcd_client_proxy_class_init (McdClientProxyClass *klass)
     g_type_class_add_private (object_class, sizeof (McdClientProxyPrivate));
 
     object_class->constructed = mcd_client_proxy_constructed;
+    object_class->get_property = mcd_client_proxy_get_property;
+    object_class->set_property = mcd_client_proxy_set_property;
 
     signals[S_READY] = g_signal_new ("ready", G_OBJECT_CLASS_TYPE (klass),
                                      G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
                                      0, NULL, NULL,
                                      g_cclosure_marshal_VOID__VOID,
                                      G_TYPE_NONE, 0);
+
+    g_object_class_install_property (object_class, PROP_UNIQUE_NAME,
+        g_param_spec_string ("unique-name", "Unique name",
+            "The D-Bus unique name of this client, \"\" if not running or "
+            "NULL if unknown",
+            NULL,
+            G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+            G_PARAM_STATIC_STRINGS));
+
 }
 
 gboolean
@@ -210,7 +266,8 @@ _mcd_client_check_valid_name (const gchar *name_suffix,
 
 McdClientProxy *
 _mcd_client_proxy_new (TpDBusDaemon *dbus_daemon,
-                       const gchar *name_suffix)
+                       const gchar *name_suffix,
+                       const gchar *unique_name_if_known)
 {
     McdClientProxy *self;
     gchar *bus_name, *object_path;
@@ -231,6 +288,7 @@ _mcd_client_proxy_new (TpDBusDaemon *dbus_daemon,
                          "dbus-daemon", dbus_daemon,
                          "object-path", object_path,
                          "bus-name", bus_name,
+                         "unique-name", unique_name_if_known,
                          NULL);
 
     g_free (object_path);
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 0714fa9..2a9484d 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -2240,7 +2240,8 @@ finish:
 static McdClient *
 create_mcd_client (McdDispatcher *self,
                    const gchar *name,
-                   gboolean activatable)
+                   gboolean activatable,
+                   const gchar *owner)
 {
     /* McdDispatcherPrivate *priv = MCD_DISPATCHER_PRIV (self); */
     McdClient *client;
@@ -2254,7 +2255,7 @@ create_mcd_client (McdDispatcher *self,
         client->active = TRUE;
 
     client->proxy = _mcd_client_proxy_new (self->priv->dbus_daemon,
-                                           client->name);
+                                           client->name, owner);
 
     DEBUG ("McdClient created for %s", name);
 
@@ -2350,7 +2351,8 @@ finally:
 static void
 mcd_dispatcher_add_client (McdDispatcher *self,
                            const gchar *name,
-                           gboolean activatable)
+                           gboolean activatable,
+                           const gchar *owner)
 {
     McdDispatcherPrivate *priv = MCD_DISPATCHER_PRIV (self);
     McdClient *client;
@@ -2395,7 +2397,7 @@ mcd_dispatcher_add_client (McdDispatcher *self,
     if (!self->priv->startup_completed)
         self->priv->startup_lock++;
 
-    client = create_mcd_client (self, name, activatable);
+    client = create_mcd_client (self, name, activatable, owner);
 
     g_hash_table_insert (priv->clients, g_strdup (name), client);
 
@@ -2426,7 +2428,7 @@ list_activatable_names_cb (TpDBusDaemon *proxy,
 
         while (*iter != NULL)
         {
-            mcd_dispatcher_add_client (self, *iter, TRUE);
+            mcd_dispatcher_add_client (self, *iter, TRUE, NULL);
             iter++;
         }
     }
@@ -2457,7 +2459,7 @@ list_names_cb (TpDBusDaemon *proxy,
 
         while (*iter != NULL)
         {
-            mcd_dispatcher_add_client (self, *iter, FALSE);
+            mcd_dispatcher_add_client (self, *iter, FALSE, NULL);
             iter++;
         }
     }
@@ -2488,7 +2490,7 @@ name_owner_changed_cb (TpDBusDaemon *proxy,
 
     if (old_owner[0] == '\0' && new_owner[0] != '\0')
     {
-        mcd_dispatcher_add_client (self, name, FALSE);
+        mcd_dispatcher_add_client (self, name, FALSE, new_owner);
     }
     else if (old_owner[0] != '\0' && new_owner[0] == '\0')
     {
-- 
1.5.6.5




More information about the telepathy-commits mailing list