summaryrefslogtreecommitdiff
path: root/extra/gnome-settings-daemon/0001-power-Use-logind-to-discover-critical-action-availab.patch
blob: 7e678f936c8cfad9f03da9dd8c359aa4406f7c93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
From 1271864ddfc053a1567d046b5fcdf8351da3f438 Mon Sep 17 00:00:00 2001
From: "Jan Alexander Steffens (heftig)" <jan.steffens@gmail.com>
Date: Mon, 5 Aug 2013 18:15:00 +0200
Subject: [PATCH] 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.
---
 plugins/power/gsd-power-manager.c | 42 ++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 12 deletions(-)

diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index fde90ef..8bd124f 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;
+        GsdPowerActionType setpolicy;
+        GVariant *result = NULL;
+        gchar *s;
 
-        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;
-        } else if (policy == GSD_POWER_ACTION_HIBERNATE) {
-                if (up_client_get_can_hibernate (manager->priv->up_client))
-                        return policy;
-                return GSD_POWER_ACTION_SHUTDOWN;
+        setpolicy = g_settings_get_enum (manager->priv->settings, "critical-battery-action");
+
+        if (setpolicy == GSD_POWER_ACTION_SUSPEND) {
+                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 (setpolicy == GSD_POWER_ACTION_HIBERNATE) {
+                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 setpolicy;
+        }
+
+        if (result) {
+                g_variant_get (result, "(s)", &s);
+                if (g_strcmp0 (s, "yes") == 0)
+                        policy = setpolicy;
+                g_variant_unref (result);
         }
 
         return policy;
-- 
1.8.3.4