From 1271864ddfc053a1567d046b5fcdf8351da3f438 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" 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 #include #include -#define UPOWER_ENABLE_DEPRECATED 1 #include #include #include @@ -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