From a4d30e30fdf9ae097ced2e92c9a5130126ff9b94 Mon Sep 17 00:00:00 2001 From: infirit Date: Sun, 17 Apr 2016 19:23:33 +0200 Subject: Replace deprecated UPower functions with ConsoleKit2 equivalents This requires ConsoleKit2 0.9.2. + some corrections for issues mentioned at https://github.com/mate-desktop/mate-power-manager/pull/209 --- src/egg-console-kit.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) (limited to 'src/egg-console-kit.c') diff --git a/src/egg-console-kit.c b/src/egg-console-kit.c index 0602d7c..df47210 100644 --- a/src/egg-console-kit.c +++ b/src/egg-console-kit.c @@ -107,6 +107,54 @@ egg_console_kit_stop (EggConsoleKit *console, GError **error) return ret; } +/** + * egg_console_kit_suspend: + **/ +gboolean +egg_console_kit_suspend (EggConsoleKit *console, GError **error) +{ + gboolean ret; + GError *error_local = NULL; + + g_return_val_if_fail (EGG_IS_CONSOLE_KIT (console), FALSE); + g_return_val_if_fail (console->priv->proxy_manager != NULL, FALSE); + + ret = dbus_g_proxy_call (console->priv->proxy_manager, "Suspend", &error_local, + G_TYPE_BOOLEAN, TRUE, + G_TYPE_INVALID, G_TYPE_INVALID); + if (!ret) { + egg_warning ("Couldn't suspend: %s", error_local->message); + if (error != NULL) + *error = g_error_new (1, 0, "%s", error_local->message); + g_error_free (error_local); + } + return ret; +} + +/** + * egg_console_kit_hibernate: + **/ +gboolean +egg_console_kit_hibernate (EggConsoleKit *console, GError **error) +{ + gboolean ret; + GError *error_local = NULL; + + g_return_val_if_fail (EGG_IS_CONSOLE_KIT (console), FALSE); + g_return_val_if_fail (console->priv->proxy_manager != NULL, FALSE); + + ret = dbus_g_proxy_call (console->priv->proxy_manager, "Hibernate", &error_local, + G_TYPE_BOOLEAN, TRUE, + G_TYPE_INVALID, G_TYPE_INVALID); + if (!ret) { + egg_warning ("Couldn't hibernate: %s", error_local->message); + if (error != NULL) + *error = g_error_new (1, 0, "%s", error_local->message); + g_error_free (error_local); + } + return ret; +} + /** * egg_console_kit_can_stop: **/ @@ -161,6 +209,65 @@ egg_console_kit_can_restart (EggConsoleKit *console, gboolean *can_restart, GErr return ret; } +/** + * egg_console_kit_can_suspend: + **/ +gboolean +egg_console_kit_can_suspend (EggConsoleKit *console, gboolean *can_suspend, GError **error) +{ + GError *error_local = NULL; + gboolean ret; + gchar *retval; + + g_return_val_if_fail (EGG_IS_CONSOLE_KIT (console), FALSE); + g_return_val_if_fail (console->priv->proxy_manager != NULL, FALSE); + + ret = dbus_g_proxy_call (console->priv->proxy_manager, "CanSuspend", &error_local, + G_TYPE_INVALID, + G_TYPE_STRING, &retval, G_TYPE_INVALID); + if (!ret) { + egg_warning ("Couldn't do CanSuspend: %s", error_local->message); + if (error != NULL) + *error = g_error_new (1, 0, "%s", error_local->message); + g_error_free (error_local); + } + + *can_suspend = g_strcmp0 (retval, "yes") == 0 || + g_strcmp0 (retval, "challenge") == 0; + + g_free (retval); + return ret; +} + +/** + * egg_console_kit_can_hibernate: + **/ + +gboolean +egg_console_kit_can_hibernate (EggConsoleKit *console, gboolean *can_hibernate, GError **error) +{ + GError *error_local = NULL; + gboolean ret; + gchar *retval; + + g_return_val_if_fail (EGG_IS_CONSOLE_KIT (console), FALSE); + g_return_val_if_fail (console->priv->proxy_manager != NULL, FALSE); + + ret = dbus_g_proxy_call (console->priv->proxy_manager, "CanHibernate", &error_local, + G_TYPE_INVALID, + G_TYPE_STRING, &retval, G_TYPE_INVALID); + if (!ret) { + egg_warning ("Couldn't do CanHibernate: %s", error_local->message); + if (error != NULL) + *error = g_error_new (1, 0, "%s", error_local->message); + g_error_free (error_local); + } + + *can_hibernate = g_strcmp0 (retval, "yes") == 0 || + g_strcmp0 (retval, "challenge") == 0; + return ret; +} + /** * egg_console_kit_is_local: * -- cgit v1.2.1