[gnome-settings-daemon] rfkill: expose in the API if the rfkill is blocked in hardware



commit bc474312f67d577458af69aec3e46b2857c73344
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Tue Oct 8 23:10:31 2013 +0200

    rfkill: expose in the API if the rfkill is blocked in hardware
    
    Hardware-blocked rfkills can't be toggled, so they should cause
    a different "Airplane mode" UI in the shell and control center
    (one that cannot be toggled)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=709684

 plugins/rfkill/gsd-rfkill-manager.c |   56 ++++++++++++++++++++++++++++++----
 1 files changed, 49 insertions(+), 7 deletions(-)
---
diff --git a/plugins/rfkill/gsd-rfkill-manager.c b/plugins/rfkill/gsd-rfkill-manager.c
index b0bc027..3813f08 100644
--- a/plugins/rfkill/gsd-rfkill-manager.c
+++ b/plugins/rfkill/gsd-rfkill-manager.c
@@ -65,6 +65,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='HardwareAirplaneMode' type='b' access='read'/>"
 "      <property name='HasAirplaneMode' type='b' access='read'/>"
 "  </interface>"
 "</node>";
@@ -106,14 +107,13 @@ engine_get_airplane_mode (GsdRfkillManager *manager)
 
        g_hash_table_iter_init (&iter, manager->priv->killswitches);
        while (g_hash_table_iter_next (&iter, &key, &value)) {
-               gboolean state;
+               int state;
 
                state = GPOINTER_TO_INT (value);
 
-               /* A single rfkill switch that's disabled? Airplane mode is off */
-               if (!state) {
+               /* A single rfkill switch that's unblocked? Airplane mode is off */
+               if (state == RFKILL_STATE_UNBLOCKED)
                         return FALSE;
-                }
        }
 
         /* wwan enabled? then airplane mode is off (because an USB modem
@@ -125,6 +125,32 @@ engine_get_airplane_mode (GsdRfkillManager *manager)
 }
 
 static gboolean
+engine_get_hardware_airplane_mode (GsdRfkillManager *manager)
+{
+       GHashTableIter iter;
+       gpointer key, value;
+
+        /* If we have no killswitches, hw airplane mode is off. */
+        if (g_hash_table_size (manager->priv->killswitches) == 0) {
+                return FALSE;
+        }
+
+       g_hash_table_iter_init (&iter, manager->priv->killswitches);
+       while (g_hash_table_iter_next (&iter, &key, &value)) {
+               int state;
+
+               state = GPOINTER_TO_INT (value);
+
+               /* A single rfkill switch that's not hw blocked? Hw airplane mode is off */
+               if (state != RFKILL_STATE_HARD_BLOCKED) {
+                        return FALSE;
+                }
+       }
+
+        return TRUE;
+}
+
+static gboolean
 engine_get_has_airplane_mode (GsdRfkillManager *manager)
 {
         return (g_hash_table_size (manager->priv->killswitches) > 0) ||
@@ -141,6 +167,8 @@ engine_properties_changed (GsdRfkillManager *manager)
 
         g_variant_builder_add (&props_builder, "{sv}", "AirplaneMode",
                                g_variant_new_boolean (engine_get_airplane_mode (manager)));
+        g_variant_builder_add (&props_builder, "{sv}", "HardwareAirplaneMode",
+                               g_variant_new_boolean (engine_get_hardware_airplane_mode (manager)));
         g_variant_builder_add (&props_builder, "{sv}", "HasAirplaneMode",
                                g_variant_new_boolean (engine_get_has_airplane_mode (manager)));
 
@@ -162,6 +190,7 @@ rfkill_changed (CcRfkillGlib     *rfkill,
                GsdRfkillManager  *manager)
 {
        GList *l;
+        int value;
 
        for (l = events; l != NULL; l = l->next) {
                struct rfkill_event *event = l->data;
@@ -169,9 +198,16 @@ rfkill_changed (CcRfkillGlib     *rfkill,
                 switch (event->op) {
                 case RFKILL_OP_ADD:
                 case RFKILL_OP_CHANGE:
-                       g_hash_table_insert (manager->priv->killswitches,
-                                            GINT_TO_POINTER (event->idx),
-                                            GINT_TO_POINTER (event->soft || event->hard));
+                        if (event->hard)
+                                value = RFKILL_STATE_HARD_BLOCKED;
+                        else if (event->soft)
+                                value = RFKILL_STATE_SOFT_BLOCKED;
+                        else
+                                value = RFKILL_STATE_UNBLOCKED;
+
+                        g_hash_table_insert (manager->priv->killswitches,
+                                             GINT_TO_POINTER (event->idx),
+                                             GINT_TO_POINTER (value));
                         break;
                 case RFKILL_OP_DEL:
                        g_hash_table_remove (manager->priv->killswitches,
@@ -297,6 +333,12 @@ handle_get_property (GDBusConnection *connection,
                 return g_variant_new_boolean (airplane_mode);
         }
 
+        if (g_strcmp0 (property_name, "HardwareAirplaneMode") == 0) {
+                gboolean hw_airplane_mode;
+                hw_airplane_mode = engine_get_hardware_airplane_mode (manager);
+                return g_variant_new_boolean (hw_airplane_mode);
+        }
+
         if (g_strcmp0 (property_name, "HasAirplaneMode") == 0) {
                 gboolean has_airplane_mode;
                 has_airplane_mode = engine_get_has_airplane_mode (manager);


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