summaryrefslogtreecommitdiff
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
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
-rw-r--r--src/egg-console-kit.c107
-rw-r--r--src/egg-console-kit.h10
-rw-r--r--src/gpm-control.c36
-rw-r--r--src/gpm-prefs-core.c9
4 files changed, 139 insertions, 23 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
diff --git a/src/egg-console-kit.h b/src/egg-console-kit.h
index c93ddce..6664131 100644
--- a/src/egg-console-kit.h
+++ b/src/egg-console-kit.h
@@ -58,12 +58,22 @@ gboolean egg_console_kit_stop (EggConsoleKit *console,
GError **error);
gboolean egg_console_kit_restart (EggConsoleKit *console,
GError **error);
+gboolean egg_console_kit_suspend (EggConsoleKit *console,
+ GError **error);
+gboolean egg_console_kit_hibernate (EggConsoleKit *console,
+ GError **error);
gboolean egg_console_kit_can_stop (EggConsoleKit *console,
gboolean *can_stop,
GError **error);
gboolean egg_console_kit_can_restart (EggConsoleKit *console,
gboolean *can_restart,
GError **error);
+gboolean egg_console_kit_can_suspend (EggConsoleKit *console,
+ gboolean *can_restart,
+ GError **error);
+gboolean egg_console_kit_can_hibernate (EggConsoleKit *console,
+ gboolean *can_restart,
+ GError **error);
G_END_DECLS
diff --git a/src/gpm-control.c b/src/gpm-control.c
index d9adb56..84a1171 100644
--- a/src/gpm-control.c
+++ b/src/gpm-control.c
@@ -36,9 +36,8 @@
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
+#include <gio/gio.h>
#include <glib/gi18n.h>
-#define UPOWER_ENABLE_DEPRECATED
-#include <libupower-glib/upower.h>
#ifdef WITH_KEYRING
#include <gnome-keyring.h>
@@ -57,7 +56,6 @@
struct GpmControlPrivate
{
GSettings *settings;
- UpClient *client;
};
enum {
@@ -210,6 +208,7 @@ gpm_control_suspend (GpmControl *control, GError **error)
gboolean ret = FALSE;
gboolean do_lock;
gboolean nm_sleep;
+ EggConsoleKit *console;
GpmScreensaver *screensaver;
guint32 throttle_cookie = 0;
#ifdef WITH_KEYRING
@@ -224,9 +223,10 @@ gpm_control_suspend (GpmControl *control, GError **error)
screensaver = gpm_screensaver_new ();
if (!LOGIND_RUNNING()) {
- g_object_get (control->priv->client,
- "can-suspend", &allowed,
- NULL);
+ console = egg_console_kit_new ();
+ egg_console_kit_can_suspend (console, &allowed, NULL);
+ g_object_unref (console);
+
if (!allowed) {
egg_debug ("cannot suspend as not allowed from policy");
g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend");
@@ -292,11 +292,12 @@ gpm_control_suspend (GpmControl *control, GError **error)
}
g_object_unref(proxy);
}
-#if !UP_CHECK_VERSION(0, 99, 0)
else {
- ret = up_client_suspend_sync (control->priv->client, NULL, error);
+ console = egg_console_kit_new ();
+ ret = egg_console_kit_suspend (console, error);
+ g_object_unref (console);
}
-#endif
+
egg_debug ("emitting resume");
g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_SUSPEND);
@@ -325,6 +326,7 @@ gpm_control_hibernate (GpmControl *control, GError **error)
gboolean ret = FALSE;
gboolean do_lock;
gboolean nm_sleep;
+ EggConsoleKit *console;
GpmScreensaver *screensaver;
guint32 throttle_cookie = 0;
#ifdef WITH_KEYRING
@@ -339,9 +341,10 @@ gpm_control_hibernate (GpmControl *control, GError **error)
screensaver = gpm_screensaver_new ();
if (!LOGIND_RUNNING()) {
- g_object_get (control->priv->client,
- "can-hibernate", &allowed,
- NULL);
+ console = egg_console_kit_new ();
+ egg_console_kit_can_hibernate (console, &allowed, NULL);
+ g_object_unref (console);
+
if (!allowed) {
egg_debug ("cannot hibernate as not allowed from policy");
g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot hibernate");
@@ -406,11 +409,12 @@ gpm_control_hibernate (GpmControl *control, GError **error)
ret = TRUE;
}
}
-#if !UP_CHECK_VERSION(0, 99, 0)
else {
- ret = up_client_hibernate_sync (control->priv->client, NULL, error);
+ console = egg_console_kit_new ();
+ ret = egg_console_kit_hibernate (console, error);
+ g_object_unref (console);
}
-#endif
+
egg_debug ("emitting resume");
g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_HIBERNATE);
@@ -442,7 +446,6 @@ gpm_control_finalize (GObject *object)
control = GPM_CONTROL (object);
g_object_unref (control->priv->settings);
- g_object_unref (control->priv->client);
g_return_if_fail (control->priv != NULL);
G_OBJECT_CLASS (gpm_control_parent_class)->finalize (object);
@@ -488,7 +491,6 @@ gpm_control_init (GpmControl *control)
{
control->priv = GPM_CONTROL_GET_PRIVATE (control);
- control->priv->client = up_client_new ();
control->priv->settings = g_settings_new (GPM_SETTINGS_SCHEMA);
}
diff --git a/src/gpm-prefs-core.c b/src/gpm-prefs-core.c
index f6847e0..5346ab9 100644
--- a/src/gpm-prefs-core.c
+++ b/src/gpm-prefs-core.c
@@ -755,13 +755,10 @@ gpm_prefs_init (GpmPrefs *prefs)
g_object_unref(proxy);
}
else {
- /* are we allowed to shutdown? */
+ /* Get values from ConsoleKit */
egg_console_kit_can_stop (prefs->priv->console, &prefs->priv->can_shutdown, NULL);
-#if !UP_CHECK_VERSION(0, 99, 0)
- /* get values from UpClient */
- prefs->priv->can_suspend = up_client_get_can_suspend (prefs->priv->client);
- prefs->priv->can_hibernate = up_client_get_can_hibernate (prefs->priv->client);
-#endif
+ egg_console_kit_can_suspend (prefs->priv->console, &prefs->priv->can_suspend, NULL);
+ egg_console_kit_can_hibernate (prefs->priv->console, &prefs->priv->can_hibernate, NULL);
}
if (LOGIND_RUNNING()) {