From 28ef20a9ad4b4b5e931b6eb4833accf44c65951f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 15 Mar 2010 17:15:16 -0500 Subject: Use the upower allowed interface to check to see if PK is blocking suspend and hibernate --- src/session-service.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/session-service.c b/src/session-service.c index a915884..9dd50bf 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -47,6 +47,7 @@ with this program. If not, see . #include "session-dbus.h" #include "users-service-dbus.h" #include "lock-helper.h" +#include "upower-client.h" #define UP_ADDRESS "org.freedesktop.UPower" #define UP_OBJECT "/org/freedesktop/UPower" @@ -254,6 +255,20 @@ up_changed_cb (DBusGProxy * proxy, gpointer user_data) return; } +/* Handle the callback from the allow functions to check and + see if we're changing the value, and if so, rebuilding the + menus based on that info. */ +static void +allowed_cb (DBusGProxy *proxy, gboolean OUT_allowed, GError *error, gpointer userdata) +{ + gboolean * can_do = (gboolean *)userdata; + + if (OUT_allowed != *can_do) { + *can_do = OUT_allowed; + rebuild_items (root_menuitem, dbus_interface); + } +} + /* This function goes through and sets up what we need for DKp checking. We're even setting up the calls for the props we need */ @@ -292,6 +307,14 @@ setup_up (void) { /* Force an original "changed" event */ up_changed_cb(up_main_proxy, NULL); + /* Check to see if these are getting blocked by PolicyKit */ + org_freedesktop_UPower_suspend_allowed_async(up_main_proxy, + allowed_cb, + &allow_suspend); + org_freedesktop_UPower_hibernate_allowed_async(up_main_proxy, + allowed_cb, + &allow_hibernate); + return; } -- cgit v1.2.3