summaryrefslogtreecommitdiff
path: root/src/egg-console-kit.c
diff options
context:
space:
mode:
authorinfirit <[email protected]>2016-04-17 19:23:33 +0200
committermonsta <[email protected]>2017-03-07 22:17:52 +0300
commita4d30e30fdf9ae097ced2e92c9a5130126ff9b94 (patch)
treecb90eecd76a3e80f9dfc0092bc4f2644c78c0e07 /src/egg-console-kit.c
parenta11f72eee66b3dc244313a5cd0fc20fd7a1530ad (diff)
downloadmate-power-manager-a4d30e30fdf9ae097ced2e92c9a5130126ff9b94.tar.bz2
mate-power-manager-a4d30e30fdf9ae097ced2e92c9a5130126ff9b94.tar.xz
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
Diffstat (limited to 'src/egg-console-kit.c')
-rw-r--r--src/egg-console-kit.c107
1 files changed, 107 insertions, 0 deletions
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
@@ -108,6 +108,54 @@ egg_console_kit_stop (EggConsoleKit *console, GError **error)
}
/**
+ * 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:
**/
gboolean
@@ -162,6 +210,65 @@ egg_console_kit_can_restart (EggConsoleKit *console, gboolean *can_restart, GErr
}
/**
+ * 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:
*
* Return value: Returns whether the session is local