From 8fe114430be64bd64d04fd14803b22c24e4904ad Mon Sep 17 00:00:00 2001 From: Sander Sweers Date: Sat, 16 Apr 2016 23:28:58 +0200 Subject: [PATCH] Replace deprecated upower functions with ConsoleKit2 equivalents This requires ConsoleKit2 version 0.9.2. --- configure.ac | 27 -------- mate-session/Makefile.am | 2 - mate-session/gsm-consolekit.c | 130 +++++++++++++++++++++++++++++++++++++++ mate-session/gsm-consolekit.h | 8 +++ mate-session/gsm-logout-dialog.c | 32 ++-------- mate-session/gsm-manager.c | 75 +++++----------------- 6 files changed, 158 insertions(+), 116 deletions(-) diff --git a/configure.ac b/configure.ac index 4714e29..58b7f79 100644 --- a/configure.ac +++ b/configure.ac @@ -45,7 +45,6 @@ GLIB_REQUIRED=2.36.0 GIO_REQUIRED=2.25.0 GTK_REQUIRED=3.14.0 DBUS_GLIB_REQUIRED=0.76 -UPOWER_REQUIRED=0.9.0 dnl ==================================================================== dnl Dependency Checks @@ -117,32 +116,6 @@ AM_CONDITIONAL(HAVE_SYSTEMD, test "x$use_systemd" = "xyes") AC_SUBST(HAVE_SYSTEMD) dnl ==================================================================== -dnl UPOWER -dnl ==================================================================== - -AC_ARG_ENABLE(upower, - AS_HELP_STRING([--enable-upower], - [Use upower to suspend/hibernate]), - enable_upower=$enableval, - enable_upower=no) -if test "x$enable_upower" = "xyes"; then - PKG_CHECK_MODULES([UPOWER], [upower-glib >= $UPOWER_REQUIRED], has_upower=yes, has_upower=no) - - if test "x$has_upower" = "xyes"; then - AC_DEFINE(HAVE_UPOWER, 1, [upower support]) - AC_SUBST(UPOWER_CFLAGS) - AC_SUBST(UPOWER_LIBS) - fi - PKG_CHECK_MODULES([UPOWER_HIBERNATE], [upower-glib < 0.99], has_upower_hibernate_suspend=yes, has_upower_hibernate_suspend=no) - if test "x$has_upower_hibernate_suspend" = "xyes"; then - AC_DEFINE(HAVE_UPOWER_HIBERNATE_SUSPEND, 1, [upower based support for hibernate and suspend (< 0.99)]) - fi - -fi -AM_CONDITIONAL(HAVE_UPOWER, test "x$has_upower" = "xyes") -AC_SUBST(HAVE_UPOWER) - -dnl ==================================================================== dnl Check for XSync extension dnl ==================================================================== diff --git a/mate-session/Makefile.am b/mate-session/Makefile.am index c6e8d37..4b2e3f1 100644 --- a/mate-session/Makefile.am +++ b/mate-session/Makefile.am @@ -7,7 +7,6 @@ noinst_PROGRAMS = \ AM_CPPFLAGS = \ $(MATE_SESSION_CFLAGS) \ $(SYSTEMD_CFLAGS) \ - $(UPOWER_CFLAGS) \ $(DISABLE_DEPRECATED_CFLAGS) AM_CFLAGS = $(WARN_CFLAGS) @@ -81,7 +80,6 @@ mate_session_LDADD = \ $(XEXT_LIBS) \ $(MATE_SESSION_LIBS) \ $(SYSTEMD_LIBS) \ - $(UPOWER_LIBS) \ $(EXECINFO_LIBS) libgsmutil_la_SOURCES = \ diff --git a/mate-session/gsm-consolekit.c b/mate-session/gsm-consolekit.c index a008c4c..5a790b2 100644 --- a/mate-session/gsm-consolekit.c +++ b/mate-session/gsm-consolekit.c @@ -480,6 +480,64 @@ 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_INVALID, + G_TYPE_BOOLEAN, TRUE, /* interactive */ + 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_INVALID, + G_TYPE_BOOLEAN, TRUE, /* interactive */ + 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 +894,78 @@ gsm_consolekit_can_stop (GsmConsolekit *manager) return can_stop; } +gboolean +gsm_consolekit_can_suspend (GsmConsolekit *manager) +{ + gboolean res; + char *can_suspend; + 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, &can_suspend, + G_TYPE_INVALID); + + if (res == FALSE) { + g_warning ("Could not make DBUS call: %s", + error->message); + g_error_free (error); + return FALSE; + } + + if (g_strcmp0 (can_suspend, "yes") == 0) { + return TRUE; + } else { + return FALSE; + } +} + +gboolean +gsm_consolekit_can_hibernate (GsmConsolekit *manager) +{ + gboolean res; + char *can_hibernate; + 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, &can_hibernate, + G_TYPE_INVALID); + + if (res == FALSE) { + g_warning ("Could not make DBUS call: %s", + error->message); + g_error_free (error); + return FALSE; + } + + if (g_strcmp0 (can_hibernate, "yes") == 0) { + return TRUE; + } else { + return FALSE; + } +} + gchar * gsm_consolekit_get_current_session_type (GsmConsolekit *manager) { diff --git a/mate-session/gsm-consolekit.h b/mate-session/gsm-consolekit.h index 741bde9..3dbb4f8 100644 --- a/mate-session/gsm-consolekit.h +++ b/mate-session/gsm-consolekit.h @@ -87,10 +87,18 @@ gboolean gsm_consolekit_can_stop (GsmConsolekit *manager); gboolean gsm_consolekit_can_restart (GsmConsolekit *manager); +gboolean gsm_consolekit_can_suspend (GsmConsolekit *manager); + +gboolean gsm_consolekit_can_hibernate (GsmConsolekit *manager); + void gsm_consolekit_attempt_stop (GsmConsolekit *manager); void gsm_consolekit_attempt_restart (GsmConsolekit *manager); +void gsm_consolekit_attempt_suspend (GsmConsolekit *manager); + +void gsm_consolekit_attempt_hibernate (GsmConsolekit *manager); + void gsm_consolekit_set_session_idle (GsmConsolekit *manager, gboolean is_idle); diff --git a/mate-session/gsm-logout-dialog.c b/mate-session/gsm-logout-dialog.c index 9eb9366..76e0167 100644 --- a/mate-session/gsm-logout-dialog.c +++ b/mate-session/gsm-logout-dialog.c @@ -27,10 +27,6 @@ #include #include -#ifdef HAVE_UPOWER -#include -#endif - #include "gsm-logout-dialog.h" #ifdef HAVE_SYSTEMD #include "gsm-systemd.h" @@ -58,9 +54,6 @@ typedef enum { struct _GsmLogoutDialogPrivate { GsmDialogLogoutType type; -#ifdef HAVE_UPOWER - UpClient *up_client; -#endif #ifdef HAVE_SYSTEMD GsmSystemd *systemd; #endif @@ -156,9 +149,6 @@ gsm_logout_dialog_init (GsmLogoutDialog *logout_dialog) gtk_window_set_skip_taskbar_hint (GTK_WINDOW (logout_dialog), TRUE); gtk_window_set_keep_above (GTK_WINDOW (logout_dialog), TRUE); gtk_window_stick (GTK_WINDOW (logout_dialog)); -#ifdef HAVE_UPOWER - logout_dialog->priv->up_client = up_client_new (); -#endif #ifdef HAVE_SYSTEMD if (LOGIND_RUNNING()) logout_dialog->priv->systemd = gsm_get_systemd (); @@ -185,12 +175,6 @@ gsm_logout_dialog_destroy (GsmLogoutDialog *logout_dialog, g_source_remove (logout_dialog->priv->timeout_id); logout_dialog->priv->timeout_id = 0; } -#ifdef HAVE_UPOWER - if (logout_dialog->priv->up_client) { - g_object_unref (logout_dialog->priv->up_client); - logout_dialog->priv->up_client = NULL; - } -#endif #ifdef HAVE_SYSTEMD if (logout_dialog->priv->systemd) { g_object_unref (logout_dialog->priv->systemd); @@ -214,12 +198,8 @@ gsm_logout_supports_system_suspend (GsmLogoutDialog *logout_dialog) #ifdef HAVE_SYSTEMD if (LOGIND_RUNNING()) ret = gsm_systemd_can_suspend (logout_dialog->priv->systemd); -#endif -#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND) - else -#endif -#ifdef HAVE_UPOWER_HIBERNATE_SUSPEND - ret = up_client_get_can_suspend (logout_dialog->priv->up_client); +#else + ret = gsm_consolekit_can_suspend (logout_dialog->priv->consolekit); #endif return ret; } @@ -232,12 +212,8 @@ gsm_logout_supports_system_hibernate (GsmLogoutDialog *logout_dialog) #ifdef HAVE_SYSTEMD if (LOGIND_RUNNING()) ret = gsm_systemd_can_hibernate (logout_dialog->priv->systemd); -#endif -#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND) - else -#endif -#ifdef HAVE_UPOWER_HIBERNATE_SUSPEND - ret = up_client_get_can_hibernate (logout_dialog->priv->up_client); +#else + ret = gsm_consolekit_can_hibernate (logout_dialog->priv->consolekit); #endif return ret; } diff --git a/mate-session/gsm-manager.c b/mate-session/gsm-manager.c index 153e937..07aeaa2 100644 --- a/mate-session/gsm-manager.c +++ b/mate-session/gsm-manager.c @@ -38,10 +38,6 @@ #include #include -#ifdef HAVE_UPOWER -#include -#endif - #include /* for logout dialog */ #include /* for gsettings */ @@ -150,10 +146,6 @@ struct GsmManagerPrivate DBusGProxy *bus_proxy; DBusGConnection *connection; -#ifdef HAVE_UPOWER - /* Interface with other parts of the system */ - UpClient *up_client; -#endif }; enum { @@ -1178,26 +1170,17 @@ manager_attempt_hibernate (GsmManager *manager) gsm_systemd_attempt_hibernate (systemd); } -#endif -#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND) - else { -#endif -#ifdef HAVE_UPOWER_HIBERNATE_SUSPEND - gboolean can_hibernate = up_client_get_can_hibernate (manager->priv->up_client); + +#else + GsmConsolekit *consolekit; + consolekit = gsm_get_consolekit (); + + gboolean can_hibernate = gsm_consolekit_can_hibernate (consolekit); if (can_hibernate) { /* lock the screen before we suspend */ manager_perhaps_lock (manager); - GError *error = NULL; - gboolean ret = up_client_hibernate_sync (manager->priv->up_client, NULL, &error); - if (!ret) { - g_warning ("Unexpected hibernate failure: %s", - error->message); - g_error_free (error); - } - } -#endif -#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND) + gsm_consolekit_attempt_hibernate (consolekit); } #endif } @@ -1217,27 +1200,18 @@ manager_attempt_suspend (GsmManager *manager) gsm_systemd_attempt_suspend (systemd); } -#endif -#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND) - else { -#endif -#ifdef HAVE_UPOWER_HIBERNATE_SUSPEND - gboolean can_suspend = up_client_get_can_suspend (manager->priv->up_client); +#else + GsmConsolekit *consolekit; + consolekit = gsm_get_consolekit (); + + gboolean can_suspend = gsm_consolekit_can_suspend (consolekit); if (can_suspend) { /* lock the screen before we suspend */ manager_perhaps_lock (manager); - GError *error = NULL; - gboolean ret = up_client_suspend_sync (manager->priv->up_client, NULL, &error); - if (!ret) { - g_warning ("Unexpected suspend failure: %s", - error->message); - g_error_free (error); - } - } -#endif -#if defined(HAVE_SYSTEMD) && defined(HAVE_UPOWER_HIBERNATE_SUSPEND) + gsm_consolekit_attempt_suspend (consolekit); } + #endif } @@ -2452,12 +2426,6 @@ gsm_manager_dispose (GObject *object) g_object_unref (manager->priv->settings_screensaver); manager->priv->settings_screensaver = NULL; } -#ifdef HAVE_UPOWER - if (manager->priv->up_client != NULL) { - g_object_unref (manager->priv->up_client); - manager->priv->up_client = NULL; - } -#endif G_OBJECT_CLASS (gsm_manager_parent_class)->dispose (object); } @@ -2664,9 +2632,6 @@ gsm_manager_init (GsmManager *manager) "status-changed", G_CALLBACK (on_presence_status_changed), manager); -#ifdef HAVE_UPOWER - manager->priv->up_client = up_client_new (); -#endif g_signal_connect (manager->priv->settings_session, "changed", G_CALLBACK (on_gsettings_key_changed), @@ -3376,14 +3341,6 @@ gsm_manager_can_shutdown (GsmManager *manager, #ifdef HAVE_SYSTEMD GsmSystemd *systemd; #endif - gboolean can_suspend = FALSE; - gboolean can_hibernate = FALSE; -#ifdef HAVE_UPOWER - g_object_get (manager->priv->up_client, - "can-suspend", &can_suspend, - "can-hibernate", &can_hibernate, - NULL); -#endif g_debug ("GsmManager: CanShutdown called"); g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE); @@ -3403,8 +3360,8 @@ gsm_manager_can_shutdown (GsmManager *manager, *shutdown_available = !_log_out_is_locked_down (manager) && (gsm_consolekit_can_stop (consolekit) || gsm_consolekit_can_restart (consolekit) - || can_suspend - || can_hibernate); + || gsm_consolekit_can_suspend (consolekit) + || gsm_consolekit_can_hibernate (consolekit)); g_object_unref (consolekit); #ifdef HAVE_SYSTEMD } -- 2.11.0