[gnome-settings-daemon] rfkill: Add a new property to determine whether we can toggle airplane mode



commit 2c0979863e453edbadc18580676c1388232dc68f
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Aug 14 21:12:47 2013 -0400

    rfkill: Add a new property to determine whether we can toggle airplane mode
    
    On some systems like desktops or VMs, we have no rfkill switches to toggle,
    so we shouldn't show any switches in the control center.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706041

 plugins/rfkill/gsd-rfkill-manager.c |   49 +++++++++++++++++++++++++++-------
 1 files changed, 39 insertions(+), 10 deletions(-)
---
diff --git a/plugins/rfkill/gsd-rfkill-manager.c b/plugins/rfkill/gsd-rfkill-manager.c
index 8f36517..be630cb 100644
--- a/plugins/rfkill/gsd-rfkill-manager.c
+++ b/plugins/rfkill/gsd-rfkill-manager.c
@@ -51,6 +51,7 @@ static const gchar introspection_xml[] =
 "  <interface name='org.gnome.SettingsDaemon.Rfkill'>"
 "    <annotation name='org.freedesktop.DBus.GLib.CSymbol' value='gsd_rfkill_manager'/>"
 "      <property name='AirplaneMode' type='b' access='readwrite'/>"
+"      <property name='HasAirplaneMode' type='b' access='readonly'/>"
 "  </interface>"
 "</node>";
 
@@ -119,13 +120,43 @@ engine_get_airplane_mode (GsdRfkillManager *manager)
         return TRUE;
 }
 
+static gboolean
+engine_get_has_airplane_mode (GsdRfkillManager *manager)
+{
+        return (g_hash_table_size (manager->priv->killswitches) > 0);
+}
+
+static void
+engine_properties_changed (GsdRfkillManager *manager)
+{
+        GVariantBuilder props_builder;
+        GVariant *props_changed = NULL;
+
+        g_variant_builder_init (&props_builder, G_VARIANT_TYPE ("a{sv}"));
+
+        g_variant_builder_add (&props_builder, "{sv}", "AirplaneMode",
+                               engine_get_airplane_mode (manager));
+        g_variant_builder_add (&props_builder, "{sv}", "HasAirplaneMode",
+                               engine_get_has_airplane_mode (manager));
+
+        props_changed = g_variant_new ("(s a{sv}@as)", GSD_RFKILL_DBUS_NAME,
+                                       g_variant_builder_end (&props_builder),
+                                       g_variant_new_strv (NULL, 0));
+
+        g_dbus_connection_emit_signal (manager->priv->connection,
+                                       NULL,
+                                       GSD_RFKILL_DBUS_PATH,
+                                       "org.freedesktop.DBus.Properties",
+                                       "PropertiesChanged",
+                                       props_changed, NULL);
+}
+
 static void
 rfkill_changed (CcRfkillGlib     *rfkill,
                GList            *events,
                GsdRfkillManager  *manager)
 {
        GList *l;
-        GVariant *params;
 
        for (l = events; l != NULL; l = l->next) {
                struct rfkill_event *event = l->data;
@@ -148,15 +179,7 @@ rfkill_changed (CcRfkillGlib     *rfkill,
         if (manager->priv->connection == NULL)
                 return;
 
-        params = g_variant_new_parsed ("('" GSD_RFKILL_DBUS_NAME "', [{'AirplaneMode', %v}], @as [])",
-                                       g_variant_new_boolean (engine_get_airplane_mode (manager)));
-
-        g_dbus_connection_emit_signal (manager->priv->connection,
-                                       NULL,
-                                       GSD_RFKILL_DBUS_PATH,
-                                       "org.freedesktop.DBus.Properties",
-                                       "PropertiesChanged",
-                                       params, NULL);
+        engine_properties_changed (manager);
 }
 
 static void
@@ -233,6 +256,12 @@ handle_get_property (GDBusConnection *connection,
                 return g_variant_new_boolean (airplane_mode);
         }
 
+        if (g_strcmp0 (property_name, "HasAirplaneMode") == 0) {
+                gboolean has_airplane_mode;
+                has_airplane_mode = engine_get_has_airplane_mode (manager);
+                return g_variant_new_boolean (has_airplane_mode);
+        }
+
         return NULL;
 }
 


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