[gnome-settings-daemon] power: Ignore battery devices that aren't present



commit 425b89210f71e042fff413e600e84633f2005e76
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Sep 4 14:21:41 2013 -0400

    power: Ignore battery devices that aren't present
    
    This fixes the battery menu showing on devices without batteries
    under gnome-shell.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=707493

 plugins/power/gsd-power-manager.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 1079366..4c36361 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -3570,10 +3570,10 @@ device_to_variant_blob (UpDevice *device)
         GVariant *value;
         UpDeviceKind kind;
         UpDeviceState state;
+        gboolean is_present;
 
-        icon = gpm_upower_get_device_icon (device, TRUE);
-        device_icon = g_icon_to_string (icon);
         g_object_get (device,
+                      "is-present", &is_present,
                       "kind", &kind,
                       "percentage", &percentage,
                       "state", &state,
@@ -3581,6 +3581,12 @@ device_to_variant_blob (UpDevice *device)
                       "time-to-full", &time_full,
                       NULL);
 
+        if (!is_present)
+                return NULL;
+
+        icon = gpm_upower_get_device_icon (device, TRUE);
+        device_icon = g_icon_to_string (icon);
+
         /* only return time for these simple states */
         if (state == UP_DEVICE_STATE_DISCHARGING)
                 time_state = time_empty;
@@ -3620,8 +3626,15 @@ handle_method_call_main (GsdPowerManager *manager,
         /* return object */
         if (g_strcmp0 (method_name, "GetPrimaryDevice") == 0) {
                 value = device_to_variant_blob (manager->priv->device_composite);
-                tuple = g_variant_new_tuple (&value, 1);
-                g_dbus_method_invocation_return_value (invocation, tuple);
+                if (value) {
+                        tuple = g_variant_new_tuple (&value, 1);
+                        g_dbus_method_invocation_return_value (invocation, tuple);
+                } else {
+                        g_dbus_method_invocation_return_error_literal (invocation,
+                                                                       GSD_POWER_MANAGER_ERROR,
+                                                                       GSD_POWER_MANAGER_ERROR_FAILED,
+                                                                       "Main battery device not available");
+                }
                 return;
         }
 
@@ -3637,6 +3650,8 @@ handle_method_call_main (GsdPowerManager *manager,
                 for (i=0; i<array->len; i++) {
                         device = g_ptr_array_index (array, i);
                         value = device_to_variant_blob (device);
+                        if (!value)
+                                continue;
                         g_variant_builder_add_value (builder, value);
                 }
 


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