diff options
author | Sander Sweers <[email protected]> | 2016-04-17 15:04:08 +0200 |
---|---|---|
committer | monsta <[email protected]> | 2017-03-05 14:12:12 +0300 |
commit | 9923739fe6f161a05078340593bf6a91db13d9be (patch) | |
tree | 04206ce1a4d88c8236229d2f1adfc325d8dcd641 /mate-session/gsm-consolekit.c | |
parent | 54d119718d8c2c109e089669aacdb66ffeb38a3e (diff) | |
download | mate-session-manager-9923739fe6f161a05078340593bf6a91db13d9be.tar.bz2 mate-session-manager-9923739fe6f161a05078340593bf6a91db13d9be.tar.xz |
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
Diffstat (limited to 'mate-session/gsm-consolekit.c')
-rw-r--r-- | mate-session/gsm-consolekit.c | 133 |
1 files changed, 133 insertions, 0 deletions
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) { |