From aa132a553b871a19a8d23fe8e9d93f736f2a4faf Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 28 Sep 2009 09:14:33 +0100 Subject: [PATCH] Convert gdm from using gnome-power-manager to DeviceKit-power --- configure.ac | 7 ++ gui/simple-greeter/Makefile.am | 4 + gui/simple-greeter/gdm-greeter-login-window.c | 84 ++++++------------------- 3 files changed, 31 insertions(+), 64 deletions(-) diff --git a/configure.ac b/configure.ac index 756890a..2cae1cf 100644 --- a/configure.ac +++ b/configure.ac @@ -51,6 +51,7 @@ LIBXKLAVIER_REQUIRED_VERSION=4.0 LIBCANBERRA_GTK_REQUIRED_VERSION=0.4 #FONTCONFIG_REQUIRED_VERSION=2.6.0 FONTCONFIG_REQUIRED_VERSION=2.5.0 +DEVKIT_POWER_REQUIRED_VERSION=008 EXTRA_COMPILE_WARNINGS(yes) @@ -103,6 +104,12 @@ PKG_CHECK_MODULES(GCONF, AC_SUBST(GCONF_CFLAGS) AC_SUBST(GCONF_LIBS) +PKG_CHECK_MODULES(DEVKIT_POWER, + devkit-power-gobject >= $DEVKIT_POWER_REQUIRED_VERSION +) +AC_SUBST(DEVKIT_POWER_CFLAGS) +AC_SUBST(DEVKIT_POWER_LIBS) + PKG_CHECK_MODULES(SIMPLE_GREETER, dbus-glib-1 >= $DBUS_GLIB_REQUIRED_VERSION gtk+-2.0 >= $GTK_REQUIRED_VERSION diff --git a/gui/simple-greeter/Makefile.am b/gui/simple-greeter/Makefile.am index 8c9ae46..4c06bc3 100644 --- a/gui/simple-greeter/Makefile.am +++ b/gui/simple-greeter/Makefile.am @@ -18,6 +18,8 @@ AM_CPPFLAGS = \ -DSBINDIR=\""$(sbindir)"\" \ -DGDM_CACHE_DIR=\""$(localstatedir)/cache/gdm"\" \ -DAT_SPI_REGISTRYD_DIR="\"$(AT_SPI_REGISTRYD_DIR)\"" \ + $(DEVKIT_POWER_CFLAGS) \ + -DI_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE \ $(DISABLE_DEPRECATED_CFLAGS) \ $(GTK_CFLAGS) \ $(SIMPLE_GREETER_CFLAGS) \ @@ -90,6 +92,7 @@ test_greeter_login_window_LDADD = \ libgdmuser.la \ $(COMMON_LIBS) \ $(SIMPLE_GREETER_LIBS) \ + $(DEVKIT_POWER_LIBS) \ $(RBAC_LIBS) \ $(NULL) @@ -324,6 +327,7 @@ gdm_simple_greeter_LDADD = \ $(SIMPLE_GREETER_LIBS) \ $(RBAC_LIBS) \ $(LIBXKLAVIER_LIBS) \ + $(DEVKIT_POWER_LIBS) \ $(NULL) gladedir = $(pkgdatadir) diff --git a/gui/simple-greeter/gdm-greeter-login-window.c b/gui/simple-greeter/gdm-greeter-login-window.c index c7ea5d6..7d4ef83 100644 --- a/gui/simple-greeter/gdm-greeter-login-window.c +++ b/gui/simple-greeter/gdm-greeter-login-window.c @@ -56,6 +56,8 @@ #include #include +#include + #include "gdm-settings-client.h" #include "gdm-settings-keys.h" #include "gdm-profile.h" @@ -79,10 +81,6 @@ #define CK_SEAT_INTERFACE "org.freedesktop.ConsoleKit.Seat" #define CK_SESSION_INTERFACE "org.freedesktop.ConsoleKit.Session" -#define GPM_DBUS_NAME "org.freedesktop.PowerManagement" -#define GPM_DBUS_PATH "/org/freedesktop/PowerManagement" -#define GPM_DBUS_INTERFACE "org.freedesktop.PowerManagement" - #define GLADE_XML_FILE "gdm-greeter-login-window.glade" #define KEY_GREETER_DIR "/apps/gdm/simple-greeter" @@ -480,40 +478,15 @@ adjust_other_login_visibility(GdmGreeterLoginWindow *login_window) static gboolean can_suspend (GdmGreeterLoginWindow *login_window) { - DBusGConnection *connection; - DBusGProxy *proxy; - GError *error; - gboolean ret; - gboolean res; - - error = NULL; - connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (error != NULL) { - g_warning ("Couldn't connect to power manager: %s", error->message); - g_error_free (error); - return FALSE; - } - proxy = dbus_g_proxy_new_for_name (connection, - GPM_DBUS_NAME, - GPM_DBUS_PATH, - GPM_DBUS_INTERFACE); - ret = FALSE; - - res = dbus_g_proxy_call (proxy, "CanSuspend", - &error, - G_TYPE_INVALID, - G_TYPE_BOOLEAN, - &ret, - G_TYPE_INVALID); - if (! res) { - if (error != NULL) { - g_warning ("Could not ask power manager if user can suspend: %s", - error->message); - g_error_free (error); - } - ret = FALSE; - } + gboolean ret; + DkpClient *dkp_client; + /* use DeviceKit-power to get data */ + dkp_client = dkp_client_new (); + g_object_get (dkp_client, + "can-suspend", &ret, + NULL); + g_object_unref (dkp_client); return ret; } @@ -655,36 +628,19 @@ do_disconnect (GdmGreeterLoginWindow *login_window) static void do_suspend (GdmGreeterLoginWindow *login_window) { - GError *error; - DBusGConnection *connection; - DBusGProxy *proxy; + gboolean ret; + DkpClient *dkp_client; + GError *error = NULL; - g_debug ("GdmGreeterLoginWindow: Suspend button clicked"); - - error = NULL; - connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (error != NULL) { + /* use DeviceKit-power to get data */ + dkp_client = dkp_client_new (); + ret = dkp_client_suspend (dkp_client, &error); + if (!ret) { g_warning ("Couldn't suspend: %s", error->message); g_error_free (error); return; } - proxy = dbus_g_proxy_new_for_name (connection, - GPM_DBUS_NAME, - GPM_DBUS_PATH, - GPM_DBUS_INTERFACE); - error = NULL; - dbus_g_proxy_call (proxy, - "Suspend", - &error, - G_TYPE_INVALID, - G_TYPE_INVALID); - if (error != NULL) { - g_warning ("Couldn't suspend: %s", error->message); - g_error_free (error); - return; - } - - g_object_unref (proxy); + g_object_unref (dkp_client); } static void -- 1.6.4.4