[vino] Export whether the server is connected to through D-Bus



commit 97bcaa72c3bae8f6f30a64de2ca806e41deb15ce
Author: Bastien Nocera <hadess hadess net>
Date:   Sat Jan 26 01:36:15 2013 +0100

    Export whether the server is connected to through D-Bus
    
    Using the "Connected" property. This allows gnome-settings-daemon
    to know whether to disable-animations in the desktop to make
    things faster.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=690337

 common/vino-dbus.c          |    5 +++++
 server/vino-dbus-listener.c |   31 +++++++++++++++++++++++++++++++
 server/vino-server.c        |   35 ++++++++++++++++++++++++++++++++++-
 server/vino-server.h        |    1 +
 4 files changed, 71 insertions(+), 1 deletions(-)
---
diff --git a/common/vino-dbus.c b/common/vino-dbus.c
index 735d815..6807ae5 100644
--- a/common/vino-dbus.c
+++ b/common/vino-dbus.c
@@ -41,12 +41,17 @@ static const GDBusPropertyInfo org_gnome_VinoScreen_AvahiHost = {
   -1, "AvahiHost", "s", G_DBUS_PROPERTY_INFO_FLAGS_READABLE
 };
 
+static const GDBusPropertyInfo org_gnome_VinoScreen_Connected = {
+  -1, "Connected", "b", G_DBUS_PROPERTY_INFO_FLAGS_READABLE
+};
+
 static const GDBusPropertyInfo* const org_gnome_VinoScreen_properties[] = {
   &org_gnome_VinoScreen_ExternalHost,
   &org_gnome_VinoScreen_ExternalPort,
   &org_gnome_VinoScreen_AvahiHost,
   &org_gnome_VinoScreen_Host,
   &org_gnome_VinoScreen_Port,
+  &org_gnome_VinoScreen_Connected,
   NULL
 };
 
diff --git a/server/vino-dbus-listener.c b/server/vino-dbus-listener.c
index 0d17798..97b72f2 100644
--- a/server/vino-dbus-listener.c
+++ b/server/vino-dbus-listener.c
@@ -210,10 +210,38 @@ vino_dbus_listener_get_property (GDBusConnection  *connection,
   else if (strcmp (property_name, "AvahiHost") == 0)
     return g_variant_new_string (vino_mdns_get_hostname());
 
+  else if (strcmp (property_name, "Connected") == 0)
+    return g_variant_new_boolean (vino_server_get_has_clients (listener->server));
+
   else
     g_assert_not_reached ();
 }
 
+static void
+server_connected_changed_cb (GObject    *gobject,
+                             GParamSpec *pspec,
+                             gpointer    user_data)
+{
+  GVariantBuilder *builder;
+  VinoDBusListener *listener = (VinoDBusListener *) user_data;
+
+  builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY);
+  g_variant_builder_add (builder,
+                         "{sv}",
+                         "Connected",
+                         g_variant_new_boolean (vino_server_get_has_clients (listener->server)));
+  g_dbus_connection_emit_signal (listener->connection,
+                                 NULL,
+                                 listener->path,
+                                 "org.freedesktop.DBus.Properties",
+                                 "PropertiesChanged",
+                                 g_variant_new ("(sa{sv}as)",
+                                                ORG_GNOME_VINO_SCREEN_INTERFACE_NAME,
+                                                builder,
+                                                NULL),
+                                 NULL);
+}
+
 void
 vino_dbus_listener_set_server (VinoDBusListener *listener,
                                VinoServer       *server)
@@ -229,6 +257,9 @@ vino_dbus_listener_set_server (VinoDBusListener *listener,
    * nobody will have checked properties before now (see large comment
    * above in get_property()).
    */
+
+  g_signal_connect (listener->server, "notify::connected",
+                    G_CALLBACK (server_connected_changed_cb), listener);
 }
 
 VinoDBusListener *
diff --git a/server/vino-server.c b/server/vino-server.c
index b61b3b9..7d2d088 100644
--- a/server/vino-server.c
+++ b/server/vino-server.c
@@ -66,6 +66,7 @@ struct _VinoServerPrivate
   guint             io_watch[RFB_MAX_SOCKETLISTEN];
 
   GSList           *clients;
+  guint             num_clients;
 
   VinoAuthMethod    auth_methods;
   char             *vnc_password;
@@ -125,7 +126,8 @@ enum
   PROP_USE_UPNP,
   PROP_DISABLE_XDAMAGE,
   PROP_NOTIFY_ON_CONNECT,
-  PROP_REJECT_INCOMING
+  PROP_REJECT_INCOMING,
+  PROP_CONNECTED
 };
 
 static enum rfbNewClientAction vino_server_auth_client (VinoServer *server,
@@ -308,10 +310,16 @@ vino_server_client_accepted (VinoServer *server,
   if (server->priv->display_status_icon)
     vino_status_icon_add_client (server->priv->icon, client);
 
+  server->priv->num_clients++;
+
   vino_server_unlock_screen ();
 
   if (vino_server_get_disable_background (server))
     vino_background_draw (FALSE);
+
+  /* First client? */
+  if (server->priv->num_clients == 1)
+    g_object_notify (G_OBJECT (server), "connected");
 }
 
 
@@ -329,6 +337,10 @@ vino_server_client_disconnected (VinoServer *server,
             vino_background_draw (TRUE);
         }
     }
+
+  server->priv->num_clients--;
+  if (server->priv->num_clients == 0)
+    g_object_notify (G_OBJECT (server), "connected");
 }
 
 static void
@@ -1261,6 +1273,9 @@ vino_server_get_property (GObject    *object,
     case PROP_REJECT_INCOMING:
       g_value_set_boolean (value, server->priv->reject_incoming);
       break;
+    case PROP_CONNECTED:
+      g_value_set_boolean (value, server->priv->num_clients > 0);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1512,6 +1527,16 @@ vino_server_class_init (VinoServerClass *klass)
                                                          G_PARAM_READWRITE   |
                                                          G_PARAM_CONSTRUCT_ONLY |
                                                          G_PARAM_STATIC_STRINGS));
+  g_object_class_install_property (gobject_class,
+				   PROP_CONNECTED,
+				   g_param_spec_boolean ("connected",
+							 "Connected",
+							 "Whether at least one client is connected",
+							 FALSE,
+                                                         G_PARAM_READABLE   |
+                                                         G_PARAM_STATIC_NAME |
+                                                         G_PARAM_STATIC_NICK |
+                                                         G_PARAM_STATIC_BLURB));
 }
 
 VinoServer *
@@ -1732,6 +1757,14 @@ vino_server_set_prompt_enabled (VinoServer *server,
     }
 }
 
+gboolean
+vino_server_get_has_clients (VinoServer *server)
+{
+  g_return_val_if_fail (VINO_IS_SERVER (server), FALSE);
+
+  return server->priv->num_clients > 0;
+}
+
 static void
 vino_server_update_security_types (VinoServer *server)
 {
diff --git a/server/vino-server.h b/server/vino-server.h
index 01fa19e..0e98880 100644
--- a/server/vino-server.h
+++ b/server/vino-server.h
@@ -70,6 +70,7 @@ GType                vino_server_get_type                 (void) G_GNUC_CONST;
 VinoServer          *vino_server_new                      (GdkScreen      *screen,
 							   gboolean        view_only);
 GdkScreen           *vino_server_get_screen               (VinoServer     *server);
+gboolean             vino_server_get_has_clients          (VinoServer     *server);
 void                 vino_server_set_on_hold              (VinoServer     *server,
 							   gboolean        on_hold);
 gboolean             vino_server_get_on_hold              (VinoServer     *server);



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