[gnome-settings-daemon] power: Use logind to discover critical action availability



commit 0c5fd82a6ce25abca9a9d7018889bad8fc1c6057
Author: Jan Alexander Steffens (heftig) <jan steffens gmail com>
Date:   Mon Aug 5 18:15:00 2013 +0200

    power: Use logind to discover critical action availability
    
    The upower functionality is deprecated and will return an
    error unless upower is built with --enable-deprecated.
    
    Follows a similar patch to gnome-control-center.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705525

 plugins/power/gsd-power-manager.c |   36 +++++++++++++++++++++++++++---------
 1 files changed, 27 insertions(+), 9 deletions(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index fde90ef..346bd9f 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -27,7 +27,6 @@
 #include <string.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#define UPOWER_ENABLE_DEPRECATED 1
 #include <libupower-glib/upower.h>
 #include <libnotify/notify.h>
 #include <canberra-gtk.h>
@@ -1164,18 +1163,37 @@ static GsdPowerActionType
 manager_critical_action_get (GsdPowerManager *manager,
                              gboolean         is_ups)
 {
-        GsdPowerActionType policy;
+        GsdPowerActionType policy = GSD_POWER_ACTION_SHUTDOWN;
+        GVariant *result = NULL;
 
         policy = g_settings_get_enum (manager->priv->settings, "critical-battery-action");
+
         if (policy == GSD_POWER_ACTION_SUSPEND) {
-                if (is_ups == FALSE &&
-                    up_client_get_can_suspend (manager->priv->up_client))
-                        return policy;
-                return GSD_POWER_ACTION_SHUTDOWN;
+                if (is_ups == FALSE) {
+                        result = g_dbus_proxy_call_sync (manager->priv->logind_proxy,
+                                                         "CanSuspend",
+                                                         NULL,
+                                                         G_DBUS_CALL_FLAGS_NONE,
+                                                         -1, NULL, NULL);
+                }
         } else if (policy == GSD_POWER_ACTION_HIBERNATE) {
-                if (up_client_get_can_hibernate (manager->priv->up_client))
-                        return policy;
-                return GSD_POWER_ACTION_SHUTDOWN;
+                result = g_dbus_proxy_call_sync (manager->priv->logind_proxy,
+                                                 "CanHibernate",
+                                                 NULL,
+                                                 G_DBUS_CALL_FLAGS_NONE,
+                                                 -1, NULL, NULL);
+        } else {
+                /* Other actions need no check */
+                return policy;
+        }
+
+        if (result) {
+                const char *s;
+
+                g_variant_get (result, "(s)", &s);
+                if (g_strcmp0 (s, "yes") != 0)
+                        policy = GSD_POWER_ACTION_SHUTDOWN;
+                g_variant_unref (result);
         }
 
         return policy;


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