aboutsummaryrefslogtreecommitdiff
path: root/src/session-service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/session-service.c')
-rw-r--r--src/session-service.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/session-service.c b/src/session-service.c
index 020aad3..fb20f3b 100644
--- a/src/session-service.c
+++ b/src/session-service.c
@@ -47,6 +47,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#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"
@@ -91,6 +92,8 @@ static DbusmenuMenuitem * shutdown_mi = NULL;
static gboolean can_hibernate = TRUE;
static gboolean can_suspend = TRUE;
+static gboolean allow_hibernate = TRUE;
+static gboolean allow_suspend = TRUE;
static GConfClient * gconf_client = NULL;
@@ -142,7 +145,6 @@ lock_if_possible (void) {
return;
}
-
/* A return from the command to sleep the system. Make sure
that we unthrottle the screensaver. */
static void
@@ -266,6 +268,25 @@ 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)
+{
+ if (error != NULL) {
+ g_warning("Unable to get information on what is allowed from UPower: %s", error->message);
+ return;
+ }
+
+ 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 */
@@ -304,6 +325,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;
}
@@ -585,17 +614,18 @@ rebuild_items (DbusmenuMenuitem *root,
} else {
dbusmenu_menuitem_property_set(logout_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Log Out..."));
}
+ dbusmenu_menuitem_property_set_bool(logout_mi, DBUSMENU_MENUITEM_PROP_VISIBLE, show_logout());
dbusmenu_menuitem_child_append(root, logout_mi);
g_signal_connect(G_OBJECT(logout_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_dialog), "logout");
- if (can_suspend) {
+ if (can_suspend && allow_suspend) {
suspend_mi = dbusmenu_menuitem_new();
dbusmenu_menuitem_property_set(suspend_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sleep"));
dbusmenu_menuitem_child_append(root, suspend_mi);
g_signal_connect(G_OBJECT(suspend_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(machine_sleep), "Suspend");
}
- if (can_hibernate) {
+ if (can_hibernate && allow_hibernate) {
hibernate_mi = dbusmenu_menuitem_new();
dbusmenu_menuitem_property_set(hibernate_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Hibernate"));
dbusmenu_menuitem_child_append(root, hibernate_mi);
@@ -626,7 +656,7 @@ rebuild_items (DbusmenuMenuitem *root,
restart_shutdown_logout_mi->restart_mi = restart_mi;
restart_shutdown_logout_mi->shutdown_mi = shutdown_mi;
- update_menu_entries(restart_shutdown_logout_mi);
+ update_menu_entries(restart_shutdown_logout_mi, logout_mi);
if (g_file_test(DESKTOP_FILE, G_FILE_TEST_EXISTS)) {
GAppInfo * appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(DESKTOP_FILE));