From 9923739fe6f161a05078340593bf6a91db13d9be Mon Sep 17 00:00:00 2001 From: Sander Sweers Date: Sun, 17 Apr 2016 15:04:08 +0200 Subject: Replace deprecated upower functions with ConsoleKit2 equivalents This requires ConsoleKit2 version 0.9.2. + corrections for issues mentioned at https://github.com/mate-desktop/mate-session-manager/pull/133 --- mate-session/gsm-consolekit.c | 133 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) (limited to 'mate-session/gsm-consolekit.c') diff --git a/mate-session/gsm-consolekit.c b/mate-session/gsm-consolekit.c index dee78ab..5f39358 100644 --- a/mate-session/gsm-consolekit.c +++ b/mate-session/gsm-consolekit.c @@ -480,6 +480,65 @@ gsm_consolekit_attempt_stop (GsmConsolekit *manager) } } +void +gsm_consolekit_attempt_suspend (GsmConsolekit *manager) +{ + gboolean res; + GError *error; + + error = NULL; + + if (!gsm_consolekit_ensure_ck_connection (manager, &error)) { + g_warning ("Could not connect to ConsoleKit: %s", + error->message); + g_error_free (error); + return; + } + + res = dbus_g_proxy_call_with_timeout (manager->priv->ck_proxy, + "Suspend", + INT_MAX, + &error, + G_TYPE_BOOLEAN, TRUE, /* interactive */ + G_TYPE_INVALID, + G_TYPE_INVALID); + + if (!res) { + g_warning ("Unable to suspend system: %s", error->message); + g_error_free (error); + } +} + +void +gsm_consolekit_attempt_hibernate (GsmConsolekit *manager) +{ + gboolean res; + GError *error; + + error = NULL; + + if (!gsm_consolekit_ensure_ck_connection (manager, &error)) { + g_warning ("Could not connect to ConsoleKit: %s", + error->message); + g_error_free (error); + return; + } + + res = dbus_g_proxy_call_with_timeout (manager->priv->ck_proxy, + "Hibernate", + INT_MAX, + &error, + G_TYPE_BOOLEAN, TRUE, /* interactive */ + G_TYPE_INVALID, + G_TYPE_INVALID); + + + if (!res) { + g_warning ("Unable to hibernate system: %s", error->message); + g_error_free (error); + } +} + static gboolean get_current_session_id (DBusConnection *connection, char **session_id) @@ -836,6 +895,80 @@ gsm_consolekit_can_stop (GsmConsolekit *manager) return can_stop; } +gboolean +gsm_consolekit_can_suspend (GsmConsolekit *manager) +{ + gboolean res; + gboolean can_suspend; + gchar *retval; + GError *error = NULL; + + if (!gsm_consolekit_ensure_ck_connection (manager, &error)) { + g_warning ("Could not connect to ConsoleKit: %s", + error->message); + g_error_free (error); + return FALSE; + } + + res = dbus_g_proxy_call_with_timeout (manager->priv->ck_proxy, + "CanSuspend", + INT_MAX, + &error, + G_TYPE_INVALID, + G_TYPE_STRING, &retval, + G_TYPE_INVALID); + + if (res == FALSE) { + g_warning ("Could not make DBUS call: %s", + error->message); + g_error_free (error); + return FALSE; + } + + can_suspend = g_strcmp0 (retval, "yes") == 0 || + g_strcmp0 (retval, "challenge") == 0; + + g_free (retval); + return can_suspend; +} + +gboolean +gsm_consolekit_can_hibernate (GsmConsolekit *manager) +{ + gboolean res; + gboolean can_hibernate; + gchar *retval; + GError *error = NULL; + + if (!gsm_consolekit_ensure_ck_connection (manager, &error)) { + g_warning ("Could not connect to ConsoleKit: %s", + error->message); + g_error_free (error); + return FALSE; + } + + res = dbus_g_proxy_call_with_timeout (manager->priv->ck_proxy, + "CanHibernate", + INT_MAX, + &error, + G_TYPE_INVALID, + G_TYPE_STRING, &retval, + G_TYPE_INVALID); + + if (res == FALSE) { + g_warning ("Could not make DBUS call: %s", + error->message); + g_error_free (error); + return FALSE; + } + + can_hibernate = g_strcmp0 (retval, "yes") == 0 || + g_strcmp0 (retval, "challenge") == 0; + + g_free (retval); + return can_hibernate; +} + gchar * gsm_consolekit_get_current_session_type (GsmConsolekit *manager) { -- cgit v1.2.1