From ffbc3a026bd3377a78b39c7af490c99a04eeb638 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 23 Oct 2008 12:48:44 +0100 Subject: feature: add in CanSuspend and CanHibernate into API --- src/dkp-daemon.c | 42 ++++++++++++++++++++---------- src/dkp-daemon.h | 6 +++++ src/org.freedesktop.DeviceKit.Power.xml | 46 +++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 14 deletions(-) diff --git a/src/dkp-daemon.c b/src/dkp-daemon.c index d1f1baf..c3a2b83 100644 --- a/src/dkp-daemon.c +++ b/src/dkp-daemon.c @@ -825,6 +825,32 @@ dkp_daemon_get_low_battery (DkpDaemon *daemon, DBusGMethodInvocation *context) return TRUE; } +/** + * dkp_daemon_can_suspend: + * + * TODO: Ask PolicyKit and check in DeviceKit.conf + **/ +gboolean +dkp_daemon_can_suspend (DkpDaemon *daemon, gboolean interactive, DBusGMethodInvocation *context) +{ + /* for now, assume we can suspend under all circumstances */ + dbus_g_method_return (context, TRUE); + return TRUE; +} + +/** + * dkp_daemon_can_hibernate: + * + * TODO: Ask PolicyKit and check in DeviceKit.conf + **/ +gboolean +dkp_daemon_can_hibernate (DkpDaemon *daemon, gboolean interactive, DBusGMethodInvocation *context) +{ + /* for now, assume we can hibernate under all circumstances */ + dbus_g_method_return (context, TRUE); + return TRUE; +} + /** * dkp_daemon_suspend: **/ @@ -834,8 +860,6 @@ dkp_daemon_suspend (DkpDaemon *daemon, DBusGMethodInvocation *context) gboolean ret; GError *error; GError *error_local = NULL; - gchar *argv; - const gchar *quirks; PolKitCaller *pk_caller; pk_caller = dkp_daemon_local_get_caller_for_context (daemon, context); @@ -845,11 +869,7 @@ dkp_daemon_suspend (DkpDaemon *daemon, DBusGMethodInvocation *context) if (!dkp_daemon_local_check_auth (daemon, pk_caller, "org.freedesktop.devicekit.power.suspend", context)) goto out; - /* TODO: where from? */ - quirks = "--quirk-s3-bios --quirk-s3-mode"; - - argv = g_strdup_printf ("/usr/sbin/pm-suspend %s", quirks); - ret = g_spawn_command_line_async (argv, &error_local); + ret = g_spawn_command_line_async ("/usr/sbin/pm-suspend", &error_local); if (!ret) { error = g_error_new (DKP_DAEMON_ERROR, DKP_DAEMON_ERROR_GENERAL, @@ -874,8 +894,6 @@ dkp_daemon_hibernate (DkpDaemon *daemon, DBusGMethodInvocation *context) gboolean ret; GError *error; GError *error_local = NULL; - gchar *argv; - const gchar *quirks; PolKitCaller *pk_caller; pk_caller = dkp_daemon_local_get_caller_for_context (daemon, context); @@ -885,11 +903,7 @@ dkp_daemon_hibernate (DkpDaemon *daemon, DBusGMethodInvocation *context) if (!dkp_daemon_local_check_auth (daemon, pk_caller, "org.freedesktop.devicekit.power.hibernate", context)) goto out; - /* TODO: where from? */ - quirks = "--quirk-s3-bios --quirk-s3-mode"; - - argv = g_strdup_printf ("/usr/sbin/pm-hibernate %s", quirks); - ret = g_spawn_command_line_async (argv, &error_local); + ret = g_spawn_command_line_async ("/usr/sbin/pm-hibernate", &error_local); if (!ret) { error = g_error_new (DKP_DAEMON_ERROR, DKP_DAEMON_ERROR_GENERAL, diff --git a/src/dkp-daemon.h b/src/dkp-daemon.h index d779086..80b2cc1 100644 --- a/src/dkp-daemon.h +++ b/src/dkp-daemon.h @@ -85,6 +85,12 @@ gboolean dkp_daemon_suspend (DkpDaemon *daemon, DBusGMethodInvocation *context); gboolean dkp_daemon_hibernate (DkpDaemon *daemon, DBusGMethodInvocation *context); +gboolean dkp_daemon_can_suspend (DkpDaemon *daemon, + gboolean interactive, + DBusGMethodInvocation *context); +gboolean dkp_daemon_can_hibernate (DkpDaemon *daemon, + gboolean interactive, + DBusGMethodInvocation *context); G_END_DECLS diff --git a/src/org.freedesktop.DeviceKit.Power.xml b/src/org.freedesktop.DeviceKit.Power.xml index 8f9fa25..28d872e 100644 --- a/src/org.freedesktop.DeviceKit.Power.xml +++ b/src/org.freedesktop.DeviceKit.Power.xml @@ -135,6 +135,52 @@ + + + + + + If we are allowed to be interactive, and ask the user to authorise + the action. + + + + + + + Returns if the computer is able to suspend. + This function should be used to decide whether to show the + Supend menu item or button in GUI programs. + + + + + + + + + + + + + If we are allowed to be interactive, and ask the user to authorise + the action. + + + + + + + Returns if the computer is able to hibernate. + This function should be used to decide whether to show the + Hibernate menu item or button in GUI programs. + + + + + + + -- cgit v1.2.3