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