[gnome-panel/wip/3.0-freeze-break: 29/32] panel: Port to GDBus



commit 762d13f85f3fa87817b6d6024c1df2498e580f73
Author: Vincent Untz <vuntz gnome org>
Date:   Thu Mar 24 14:10:19 2011 +0100

    panel: Port to GDBus
    
    We can remove our PanelDBusService helper class now.

 configure.ac                                      |    2 +-
 gnome-panel/libpanel-util/Makefile.am             |    2 -
 gnome-panel/libpanel-util/panel-dbus-service.c    |  307 ---------------------
 gnome-panel/libpanel-util/panel-dbus-service.h    |   74 -----
 gnome-panel/libpanel-util/panel-screensaver.c     |  123 ++++-----
 gnome-panel/libpanel-util/panel-screensaver.h     |   10 +-
 gnome-panel/libpanel-util/panel-session-manager.c |  156 +++++------
 gnome-panel/libpanel-util/panel-session-manager.h |   10 +-
 8 files changed, 144 insertions(+), 540 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index e80f9fe..6817677 100644
--- a/configure.ac
+++ b/configure.ac
@@ -81,7 +81,7 @@ dnl pkg-config dependency checks
 
 PKG_CHECK_MODULES(EGG_SMCLIENT, ice sm gtk+-3.0)
 
-PKG_CHECK_MODULES(PANEL, gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED pango >= $PANGO_REQUIRED gtk+-3.0 >= $GTK_REQUIRED cairo-xlib glib-2.0 >= $GLIB_REQUIRED gio-2.0 >= $GLIB_REQUIRED gio-unix-2.0 >= $GLIB_REQUIRED gnome-desktop-3.0 >= $LIBGNOME_DESKTOP_REQUIRED gconf-2.0 >= $GCONF_REQUIRED libgnome-menu >= $LIBGNOME_MENU_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED)
+PKG_CHECK_MODULES(PANEL, gdk-pixbuf-2.0 >= $GDK_PIXBUF_REQUIRED pango >= $PANGO_REQUIRED gtk+-3.0 >= $GTK_REQUIRED cairo-xlib glib-2.0 >= $GLIB_REQUIRED gio-2.0 >= $GLIB_REQUIRED gio-unix-2.0 >= $GLIB_REQUIRED gnome-desktop-3.0 >= $LIBGNOME_DESKTOP_REQUIRED gconf-2.0 >= $GCONF_REQUIRED libgnome-menu >= $LIBGNOME_MENU_REQUIRED)
 AC_SUBST(PANEL_CFLAGS)
 AC_SUBST(PANEL_LIBS)
 
diff --git a/gnome-panel/libpanel-util/Makefile.am b/gnome-panel/libpanel-util/Makefile.am
index ec9dd03..e8937e3 100644
--- a/gnome-panel/libpanel-util/Makefile.am
+++ b/gnome-panel/libpanel-util/Makefile.am
@@ -13,8 +13,6 @@ AM_CFLAGS = $(WARN_CFLAGS)
 libpanel_util_la_SOURCES =		\
 	panel-cleanup.c			\
 	panel-cleanup.h			\
-	panel-dbus-service.c		\
-	panel-dbus-service.h		\
 	panel-error.c			\
 	panel-error.h			\
 	panel-glib.c			\
diff --git a/gnome-panel/libpanel-util/panel-screensaver.c b/gnome-panel/libpanel-util/panel-screensaver.c
index cfaf773..202ab7a 100644
--- a/gnome-panel/libpanel-util/panel-screensaver.c
+++ b/gnome-panel/libpanel-util/panel-screensaver.c
@@ -22,88 +22,77 @@
  *	Vincent Untz <vuntz gnome org>
  */
 
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
 
 #include "panel-cleanup.h"
-#include "panel-dbus-service.h"
 
 #include "panel-screensaver.h"
 
-static GObject *panel_screensaver_constructor (GType                  type,
-					       guint                  n_construct_properties,
-					       GObjectConstructParam *construct_properties);
+struct _PanelScreensaverPrivate {
+	GDBusProxy *proxy;
+};
 
-G_DEFINE_TYPE (PanelScreensaver, panel_screensaver, PANEL_TYPE_DBUS_SERVICE);
+G_DEFINE_TYPE (PanelScreensaver, panel_screensaver, G_TYPE_OBJECT);
 
 static void
 panel_screensaver_class_init (PanelScreensaverClass *klass)
 {
-	GObjectClass *object_class;
-
-	object_class = G_OBJECT_CLASS (klass);
-
-	object_class->constructor = panel_screensaver_constructor;
+	g_type_class_add_private (klass,
+				  sizeof (PanelScreensaverPrivate));
 }
 
 static void
-panel_screensaver_init (PanelScreensaver *manager)
+panel_screensaver_init (PanelScreensaver *screensaver)
 {
-}
-
-static GObject *
-panel_screensaver_constructor (GType                  type,
-				   guint                  n_construct_properties,
-				   GObjectConstructParam *construct_properties)
-{
-	GObject *obj;
-	GError  *error;
-
-	obj = G_OBJECT_CLASS (panel_screensaver_parent_class)->constructor (
-							type,
-							n_construct_properties,
-							construct_properties);
-
+	GError *error;
 
-	panel_dbus_service_define_service (PANEL_DBUS_SERVICE (obj),
-					   "org.gnome.ScreenSaver",
-					   "/org/gnome/ScreenSaver",
-					   "org.gnome.ScreenSaver");
+	screensaver->priv = G_TYPE_INSTANCE_GET_PRIVATE (screensaver,
+							 PANEL_TYPE_SCREENSAVER,
+							 PanelScreensaverPrivate);
 
 	error = NULL;
-	if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (obj),
-						   &error)) {
-		g_message ("Could not connect to screensaver: %s",
+	screensaver->priv->proxy = g_dbus_proxy_new_for_bus_sync (
+						G_BUS_TYPE_SESSION,
+						G_DBUS_PROXY_FLAGS_NONE,
+						NULL,
+						"org.gnome.ScreenSaver",
+						"/org/gnome/ScreenSaver",
+						"org.gnome.ScreenSaver",
+						NULL, &error);
+
+	if (error) {
+		g_warning ("Could not connect to screensaver: %s",
 			   error->message);
 		g_error_free (error);
 	}
-
-	return obj;
 }
 
 void
 panel_screensaver_lock (PanelScreensaver *screensaver)
 {
-	GError *error;
-	DBusGProxy *proxy;
+	GVariant *ret;
+	GError   *error;
 
 	g_return_if_fail (PANEL_IS_SCREENSAVER (screensaver));
 
-	error = NULL;
-
-	if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (screensaver),
-						   &error)) {
-		g_warning ("Could not connect to screensaver: %s",
-			   error->message);
-		g_error_free (error);
+	if (!screensaver->priv->proxy) {
+		g_warning ("Screensaver service not available.");
 		return;
 	}
 
-	proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (screensaver));
-
-	if (!dbus_g_proxy_call (proxy, "Lock", &error,
-				G_TYPE_INVALID,
-				G_TYPE_INVALID) &&
-	    error != NULL) {
+	error = NULL;
+	ret = g_dbus_proxy_call_sync (screensaver->priv->proxy,
+				      "Lock",
+				      NULL,
+				      G_DBUS_CALL_FLAGS_NONE,
+				      -1,
+				      NULL,
+				      &error);
+
+	if (ret)
+		g_variant_unref (ret);
+
+	if (error) {
 		g_warning ("Could not ask screensaver to lock: %s",
 			   error->message);
 		g_error_free (error);
@@ -113,27 +102,29 @@ panel_screensaver_lock (PanelScreensaver *screensaver)
 void
 panel_screensaver_activate (PanelScreensaver *screensaver)
 {
-	GError *error;
-	DBusGProxy *proxy;
+	GVariant *ret;
+	GError   *error;
 
 	g_return_if_fail (PANEL_IS_SCREENSAVER (screensaver));
 
-	error = NULL;
-
-	if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (screensaver),
-						   &error)) {
-		g_warning ("Could not connect to screensaver: %s",
-			   error->message);
-		g_error_free (error);
+	if (!screensaver->priv->proxy) {
+		g_warning ("Screensaver service not available.");
 		return;
 	}
 
-	proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (screensaver));
-
-	if (!dbus_g_proxy_call (proxy, "SetActive", &error,
-				G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID,
-				G_TYPE_INVALID) &&
-	    error != NULL) {
+	error = NULL;
+	ret = g_dbus_proxy_call_sync (screensaver->priv->proxy,
+				      "SetActive",
+				      g_variant_new ("(b)", TRUE),
+				      G_DBUS_CALL_FLAGS_NONE,
+				      -1,
+				      NULL,
+				      &error);
+
+	if (ret)
+		g_variant_unref (ret);
+
+	if (error) {
 		g_warning ("Could not ask screensaver to activate: %s",
 			   error->message);
 		g_error_free (error);
diff --git a/gnome-panel/libpanel-util/panel-screensaver.h b/gnome-panel/libpanel-util/panel-screensaver.h
index 82de9da..00297d1 100644
--- a/gnome-panel/libpanel-util/panel-screensaver.h
+++ b/gnome-panel/libpanel-util/panel-screensaver.h
@@ -27,8 +27,6 @@
 
 #include <glib-object.h>
 
-#include "panel-dbus-service.h"
-
 G_BEGIN_DECLS
 
 #define PANEL_TYPE_SCREENSAVER			(panel_screensaver_get_type ())
@@ -40,13 +38,17 @@ G_BEGIN_DECLS
 
 typedef struct _PanelScreensaver		PanelScreensaver;
 typedef struct _PanelScreensaverClass		PanelScreensaverClass;
+typedef struct _PanelScreensaverPrivate		PanelScreensaverPrivate;
 
 struct _PanelScreensaver {
-	PanelDBusService parent;
+	GObject parent;
+
+	/*< private > */
+	PanelScreensaverPrivate *priv;
 };
 
 struct _PanelScreensaverClass {
-	PanelDBusServiceClass parent_class;
+	GObjectClass parent_class;
 };
 
 GType panel_screensaver_get_type (void);
diff --git a/gnome-panel/libpanel-util/panel-session-manager.c b/gnome-panel/libpanel-util/panel-session-manager.c
index 36f72aa..0a2e6ff 100644
--- a/gnome-panel/libpanel-util/panel-session-manager.c
+++ b/gnome-panel/libpanel-util/panel-session-manager.c
@@ -22,89 +22,78 @@
  *	Vincent Untz <vuntz gnome org>
  */
 
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
 
 #include "panel-cleanup.h"
-#include "panel-dbus-service.h"
 
 #include "panel-session-manager.h"
 
-static GObject *panel_session_manager_constructor (GType                  type,
-						   guint                  n_construct_properties,
-						   GObjectConstructParam *construct_properties);
+struct _PanelSessionManagerPrivate {
+	GDBusProxy *proxy;
+};
 
-G_DEFINE_TYPE (PanelSessionManager, panel_session_manager, PANEL_TYPE_DBUS_SERVICE);
+G_DEFINE_TYPE (PanelSessionManager, panel_session_manager, G_TYPE_OBJECT);
 
 static void
 panel_session_manager_class_init (PanelSessionManagerClass *klass)
 {
-	GObjectClass *object_class;
-
-	object_class = G_OBJECT_CLASS (klass);
-
-	object_class->constructor = panel_session_manager_constructor;
+	g_type_class_add_private (klass,
+				  sizeof (PanelSessionManagerPrivate));
 }
 
 static void
 panel_session_manager_init (PanelSessionManager *manager)
 {
-}
-
-static GObject *
-panel_session_manager_constructor (GType                  type,
-				   guint                  n_construct_properties,
-				   GObjectConstructParam *construct_properties)
-{
-	GObject *obj;
-	GError  *error;
-
-	obj = G_OBJECT_CLASS (panel_session_manager_parent_class)->constructor (
-							type,
-							n_construct_properties,
-							construct_properties);
-
+	GError *error;
 
-	panel_dbus_service_define_service (PANEL_DBUS_SERVICE (obj),
-					   "org.gnome.SessionManager",
-					   "/org/gnome/SessionManager",
-					   "org.gnome.SessionManager");
+	manager->priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
+						     PANEL_TYPE_SESSION_MANAGER,
+						     PanelSessionManagerPrivate);
 
 	error = NULL;
-	if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (obj),
-						   &error)) {
-		g_message ("Could not connect to session manager: %s",
+	manager->priv->proxy = g_dbus_proxy_new_for_bus_sync (
+						G_BUS_TYPE_SESSION,
+						G_DBUS_PROXY_FLAGS_NONE,
+						NULL,
+						"org.gnome.SessionManager",
+						"/org/gnome/SessionManager",
+						"org.gnome.SessionManager",
+						NULL, &error);
+
+	if (error) {
+		g_warning ("Could not connect to session manager: %s",
 			   error->message);
 		g_error_free (error);
 	}
-
-	return obj;
 }
 
 void
 panel_session_manager_request_logout (PanelSessionManager           *manager,
 				      PanelSessionManagerLogoutType  mode)
 {
-	GError *error;
-	DBusGProxy *proxy;
+	GVariant *ret;
+	GError   *error;
 
 	g_return_if_fail (PANEL_IS_SESSION_MANAGER (manager));
 
-	error = NULL;
-
-	if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (manager),
-						   &error)) {
-		g_warning ("Could not connect to session manager: %s",
-			   error->message);
-		g_error_free (error);
+	if (!manager->priv->proxy) {
+		g_warning ("Session manager service not available.");
 		return;
 	}
 
-	proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (manager));
-
-	if (!dbus_g_proxy_call (proxy, "Logout", &error,
-				G_TYPE_UINT, mode, G_TYPE_INVALID,
-				G_TYPE_INVALID) &&
-	    error != NULL) {
+	error = NULL;
+	ret = g_dbus_proxy_call_sync (manager->priv->proxy,
+				      "Logout",
+				      g_variant_new ("(u)", mode),
+				      G_DBUS_CALL_FLAGS_NONE,
+				      -1,
+				      NULL,
+				      &error);
+
+	if (ret)
+		g_variant_unref (ret);
+
+	if (error) {
 		g_warning ("Could not ask session manager to log out: %s",
 			   error->message);
 		g_error_free (error);
@@ -114,27 +103,29 @@ panel_session_manager_request_logout (PanelSessionManager           *manager,
 void
 panel_session_manager_request_shutdown (PanelSessionManager *manager)
 {
-	GError *error;
-	DBusGProxy *proxy;
+	GVariant *ret;
+	GError   *error;
 
 	g_return_if_fail (PANEL_IS_SESSION_MANAGER (manager));
 
-	error = NULL;
-
-	if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (manager),
-						   &error)) {
-		g_warning ("Could not connect to session manager: %s",
-			   error->message);
-		g_error_free (error);
+	if (!manager->priv->proxy) {
+		g_warning ("Session manager service not available.");
 		return;
 	}
 
-	proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (manager));
-
-	if (!dbus_g_proxy_call (proxy, "Shutdown", &error,
-				G_TYPE_INVALID,
-				G_TYPE_INVALID) &&
-	    error != NULL) {
+	error = NULL;
+	ret = g_dbus_proxy_call_sync (manager->priv->proxy,
+				      "Shutdown",
+				      NULL,
+				      G_DBUS_CALL_FLAGS_NONE,
+				      -1,
+				      NULL,
+				      &error);
+
+	if (ret)
+		g_variant_unref (ret);
+
+	if (error) {
 		g_warning ("Could not ask session manager to shut down: %s",
 			   error->message);
 		g_error_free (error);
@@ -144,34 +135,35 @@ panel_session_manager_request_shutdown (PanelSessionManager *manager)
 gboolean
 panel_session_manager_is_shutdown_available (PanelSessionManager *manager)
 {
-	GError *error;
-	DBusGProxy *proxy;
-	gboolean is_shutdown_available;
+	GVariant *ret;
+	GError   *error;
+	gboolean  is_shutdown_available = FALSE;
 
 	g_return_val_if_fail (PANEL_IS_SESSION_MANAGER (manager), FALSE);
 
-	error = NULL;
-
-	if (!panel_dbus_service_ensure_connection (PANEL_DBUS_SERVICE (manager),
-						   &error)) {
-		g_warning ("Could not connect to session manager: %s",
-			   error->message);
-		g_error_free (error);
-
+	if (!manager->priv->proxy) {
+		g_warning ("Session manager service not available.");
 		return FALSE;
 	}
 
-	proxy = panel_dbus_service_get_proxy (PANEL_DBUS_SERVICE (manager));
-
-	if (!dbus_g_proxy_call (proxy, "CanShutdown", &error,
-				G_TYPE_INVALID, G_TYPE_BOOLEAN,
-				&is_shutdown_available, G_TYPE_INVALID) &&
-	    error != NULL) {
+	error = NULL;
+	ret = g_dbus_proxy_call_sync (manager->priv->proxy,
+				      "CanShutdown",
+				      NULL,
+				      G_DBUS_CALL_FLAGS_NONE,
+				      -1,
+				      NULL,
+				      &error);
+
+	if (error) {
 		g_warning ("Could not ask session manager if shut down is available: %s",
 			   error->message);
 		g_error_free (error);
 
 		return FALSE;
+	} else {
+		g_variant_get (ret, "(b)", &is_shutdown_available);
+		g_variant_unref (ret);
 	}
 
 	return is_shutdown_available;
diff --git a/gnome-panel/libpanel-util/panel-session-manager.h b/gnome-panel/libpanel-util/panel-session-manager.h
index 3a82306..0561b52 100644
--- a/gnome-panel/libpanel-util/panel-session-manager.h
+++ b/gnome-panel/libpanel-util/panel-session-manager.h
@@ -27,8 +27,6 @@
 
 #include <glib-object.h>
 
-#include "panel-dbus-service.h"
-
 G_BEGIN_DECLS
 
 #define PANEL_TYPE_SESSION_MANAGER		(panel_session_manager_get_type ())
@@ -40,13 +38,17 @@ G_BEGIN_DECLS
 
 typedef struct _PanelSessionManager		PanelSessionManager;
 typedef struct _PanelSessionManagerClass	PanelSessionManagerClass;
+typedef struct _PanelSessionManagerPrivate	PanelSessionManagerPrivate;
 
 struct _PanelSessionManager {
-	PanelDBusService parent;
+	GObject parent;
+
+	/*< private > */
+	PanelSessionManagerPrivate *priv;
 };
 
 struct _PanelSessionManagerClass {
-	PanelDBusServiceClass parent_class;
+	GObjectClass parent_class;
 };
 
 GType panel_session_manager_get_type (void);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]