[goobox] ported to GDBus



commit 262eaa0a20e0696b039d0a7744be712c1b9464bb
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Jun 2 19:17:37 2011 +0200

    ported to GDBus

 configure.ac                 |   12 +---
 src/Makefile.am              |    2 -
 src/goo-volume-tool-button.c |   59 ++++++++--------
 src/goo-window.c             |  156 ++++++++++++++++++++----------------------
 4 files changed, 107 insertions(+), 122 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 4c7c101..472a3f8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,19 +91,9 @@ AM_CONDITIONAL(ENABLE_MEDIA_KEYS, test "x$enable_media_keys" = xyes)
 DBUS_LIBS=""
 DBUS_CFLAGS=""
 if test x"$enable_media_keys" = xyes; then
-   AC_MSG_CHECKING(for media keys support)
-
-   if pkg-config dbus-glib-1; then
-      DBUS_LIBS=`pkg-config --libs dbus-glib-1`
-      DBUS_CFLAGS=`pkg-config --cflags dbus-glib-1`
-      AC_DEFINE(ENABLE_MEDIA_KEYS, 1, [enable media keys support])
-   else
-      enable_media_keys=no
-   fi
+   AC_DEFINE(ENABLE_MEDIA_KEYS, 1, [enable media keys support])
 fi
 AC_MSG_RESULT($enable_media_keys)
-AC_SUBST(DBUS_LIBS)
-AC_SUBST(DBUS_CFLAGS)
 
 dnl ===========================================================================
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 9feb4b9..1084aa9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,7 +18,6 @@ INCLUDES =						\
         -DGOO_LIBDIR=\"$(libdir)\"  	         	\
 	-DGOO_UIDIR=\""$(uidir)"\"     			\
 	$(DISABLE_DEPRECATED)				\
-	$(DBUS_CFLAGS)					\
 	$(GOO_CFLAGS)					\
 	$(LIBNOTIFY_CFLAGS)
 
@@ -88,7 +87,6 @@ goo-marshal.c: goo-marshal.list $(GLIB_GENMARSHAL)
 
 goobox_LDADD = 				\
 	$(top_builddir)/copy-n-paste/libeggsmclient.la  \
-	$(DBUS_LIBS)			\
 	$(GOO_LIBS) 			\
 	$(LIBNOTIFY_LIBS)		\
 	$(SYSTEM_LIBS)
diff --git a/src/goo-volume-tool-button.c b/src/goo-volume-tool-button.c
index 369b76d..25126d9 100644
--- a/src/goo-volume-tool-button.c
+++ b/src/goo-volume-tool-button.c
@@ -293,29 +293,30 @@ arrow_button_press_cb (GtkToggleButton     *toggle_button,
 	v = gtk_range_get_value (GTK_RANGE (button->priv->volume_scale)) / (gtk_adjustment_get_upper (adj) - gtk_adjustment_get_lower (adj));
 	gtk_widget_get_allocation (widget, &allocation);
 	gtk_widget_get_allocation (button->priv->popup_win, &allocation2);
-  	x += (allocation.width - allocation2.width) / 2;
-  	y -= ystartoff;
-  	y -= gtk_range_get_min_slider_size (GTK_RANGE (button->priv->volume_scale)) / 2;
-  	gtk_widget_get_allocation (button->priv->volume_scale, &allocation);
-  	m = allocation.height - gtk_range_get_min_slider_size (GTK_RANGE (button->priv->volume_scale));
-  	y -= m * (1.0 - v);
-  	y += mouse_y;
-  	gtk_window_move (GTK_WINDOW (button->priv->popup_win), x, y);
-  	gdk_window_get_origin (gtk_widget_get_window (button->priv->volume_scale), &sx, &sy);
-
-	gdk_pointer_grab (gtk_widget_get_window (button->priv->popup_win),
-			  TRUE,
-			  (GDK_POINTER_MOTION_MASK
-			   | GDK_BUTTON_PRESS_MASK
-			   | GDK_BUTTON_RELEASE_MASK),
-			  NULL,
-			  NULL,
-			  GDK_CURRENT_TIME);
-	gdk_keyboard_grab (gtk_widget_get_window (button->priv->popup_win), TRUE, GDK_CURRENT_TIME);
+	x += (allocation.width - allocation2.width) / 2;
+	y -= ystartoff;
+	y -= gtk_range_get_min_slider_size (GTK_RANGE (button->priv->volume_scale)) / 2;
+	gtk_widget_get_allocation (button->priv->volume_scale, &allocation);
+	m = allocation.height - gtk_range_get_min_slider_size (GTK_RANGE (button->priv->volume_scale));
+	y -= m * (1.0 - v);
+	y += mouse_y;
+	gtk_window_move (GTK_WINDOW (button->priv->popup_win), x, y);
+	gdk_window_get_origin (gtk_widget_get_window (button->priv->volume_scale), &sx, &sy);
+
+	gdk_device_grab (gdk_event_get_device ((GdkEvent *) event),
+			 gtk_widget_get_window (button->priv->popup_win),
+			 GDK_OWNERSHIP_NONE,
+			 TRUE,
+			 (GDK_POINTER_MOTION_MASK
+			  | GDK_BUTTON_PRESS_MASK
+			  | GDK_BUTTON_RELEASE_MASK),
+			 NULL,
+			 gdk_event_get_time ((GdkEvent *) event));
 	gtk_widget_grab_focus (button->priv->volume_scale);
 	gtk_grab_add (button->priv->popup_win);
 
 	/* forward event to the slider */
+
 	e = (GdkEventButton *) gdk_event_copy ((GdkEvent *) event);
 	e->window = gtk_widget_get_window (button->priv->volume_scale);
 	gtk_widget_get_allocation (button->priv->volume_scale, &allocation);
@@ -333,10 +334,10 @@ arrow_button_press_cb (GtkToggleButton     *toggle_button,
 
 
 static void
-ungrab (GooVolumeToolButton *button)
+ungrab (GooVolumeToolButton *button,
+	GdkEvent            *event)
 {
-	gdk_pointer_ungrab (GDK_CURRENT_TIME);
-	gdk_keyboard_ungrab (GDK_CURRENT_TIME);
+	gdk_device_ungrab (gdk_event_get_device (event), gdk_event_get_time (event));
 	gtk_grab_remove (button->priv->popup_win);
 	gtk_widget_hide (button->priv->popup_win);
 
@@ -367,7 +368,7 @@ scale_button_release_cb (GtkToggleButton     *toggle_button,
 	if (button->priv->timeout) {
 		/* if we did a quick click, leave the window open; else, hide it */
 		if (event->time > button->priv->pop_time + CLICK_TIMEOUT) {
-			ungrab (button);
+			ungrab (button, (GdkEvent *) event);
 			return FALSE;
 		}
 		button->priv->timeout = FALSE;
@@ -389,8 +390,9 @@ popup_win_event_cb (GtkWidget           *widget,
 		event_widget = gtk_get_event_widget ((GdkEvent *)event);
 
 		if ((event_widget == button->priv->button)
-		    || (event_widget == button->priv->arrow_button)) {
-			ungrab (button);
+		    || (event_widget == button->priv->arrow_button))
+		{
+			ungrab (button, event);
 			return TRUE;
 		}
 		else {
@@ -402,8 +404,9 @@ popup_win_event_cb (GtkWidget           *widget,
 			if ((event->button.x < 0)
 			    || (event->button.x > w)
 			    || (event->button.y < 0)
-			    || (event->button.y > h)) {
-				ungrab (button);
+			    || (event->button.y > h))
+			{
+				ungrab (button, event);
 				return TRUE;
 			}
 		}
@@ -412,7 +415,7 @@ popup_win_event_cb (GtkWidget           *widget,
 	case GDK_KEY_PRESS:
 		switch (event->key.keyval) {
 		case GDK_KEY_Escape:
-			ungrab (button);
+			ungrab (button, event);
 			return TRUE;
 		default:
 			break;
diff --git a/src/goo-window.c b/src/goo-window.c
index cfcd5cd..e89c1e8 100644
--- a/src/goo-window.c
+++ b/src/goo-window.c
@@ -27,9 +27,6 @@
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtk.h>
 #include <gst/gst.h>
-#ifdef ENABLE_MEDIA_KEYS
-#include <dbus/dbus-glib.h>
-#endif /* ENABLE_MEDIA_KEYS */
 #include "actions.h"
 #include "gio-utils.h"
 #include "dlg-cover-chooser.h"
@@ -114,10 +111,9 @@ struct _GooWindowPrivate {
 	gboolean           hibernate;
 	gboolean           notify_action;
 
-#ifdef ENABLE_MEDIA_KEYS
-	DBusGProxy        *media_keys_proxy;
+	GDBusProxy        *media_keys_proxy;
 	gulong             focus_in_event;
-#endif /* ENABLE_MEDIA_KEYS */
+	gulong             media_key_event;
 };
 
 enum {
@@ -445,17 +441,16 @@ goo_window_finalize (GObject *object)
 	debug (DEBUG_INFO, "[FINALIZE]\n");
 
 	if (window->priv != NULL) {
-#ifdef ENABLE_MEDIA_KEYS
 		if (window->priv->media_keys_proxy != NULL) {
-			dbus_g_proxy_call (window->priv->media_keys_proxy,
-					   "ReleaseMediaPlayerKeys",
-					   NULL,
-					   G_TYPE_STRING, "goobox",
-					   G_TYPE_INVALID,
-					   G_TYPE_INVALID);
+			g_dbus_proxy_call_sync (window->priv->media_keys_proxy,
+						"ReleaseMediaPlayerKeys",
+						g_variant_new ("(s)", g_get_application_name ()),
+						G_DBUS_CALL_FLAGS_NONE,
+						-1,
+						NULL,
+						NULL);
 			g_object_unref (window->priv->media_keys_proxy);
 		}
-#endif /* ENABLE_MEDIA_KEYS */
 
 		/* Save preferences */
 
@@ -969,7 +964,7 @@ first_time_idle (gpointer callback_data)
 	GooWindow *window = callback_data;
 
 	g_source_remove (window->priv->first_time_event);
-	/*goo_player_update (window->priv->player); FIXME */
+	/* goo_player_update (window->priv->player); FIXME */
 
 	return FALSE;
 }
@@ -2116,25 +2111,35 @@ goo_window_init (GooWindow *window)
 }
 
 
-#ifdef ENABLE_MEDIA_KEYS
+static void
+media_player_key_pressed_cb (GDBusProxy *proxy,
+			     char       *sender_name,
+			     char       *signal_name,
+			     GVariant   *parameters,
+			     gpointer    user_data)
+{
+	GooWindow *window = user_data;
+	char      *application;
+	char      *key;
 
+	if (g_strcmp0 (signal_name, "MediaPlayerKeyPressed") != 0)
+		return;
 
-static void
-media_player_key_pressed_cb (DBusGProxy *proxy,
-			     const char *application,
-			     const char *key,
-			     GooWindow  *window)
-{
-        if (strcmp ("goobox", application) == 0) {
-                if (strcmp ("Play", key) == 0)
-                	goo_window_toggle_play (window);
-                else if (strcmp ("Previous", key) == 0)
-                	goo_window_prev (window);
-                else if (strcmp ("Next", key) == 0)
-                	goo_window_next (window);
-                else if (strcmp ("Stop", key) == 0)
-                	goo_window_stop (window);
-        }
+	g_variant_get (parameters, "(ss)", &application, &key);
+
+	if (g_strcmp0 (application, PACKAGE_NAME) == 0) {
+		if (g_strcmp0 (key, "Play") == 0)
+			goo_window_toggle_play (window);
+		else if (g_strcmp0 (key, "Previous") == 0)
+			goo_window_prev (window);
+		else if (g_strcmp0 (key, "Next") == 0)
+			goo_window_next (window);
+		else if (g_strcmp0 (key, "Stop") == 0)
+			goo_window_stop (window);
+	}
+
+	g_free (application);
+	g_free (key);
 }
 
 
@@ -2145,13 +2150,13 @@ window_focus_in_event_cb (GtkWidget     *widget,
 {
 	GooWindow *window = user_data;
 
-	dbus_g_proxy_call (window->priv->media_keys_proxy,
-			   "GrabMediaPlayerKeys",
-			   NULL,
-			   G_TYPE_STRING, "goobox",
-			   G_TYPE_UINT, 0,
-			   G_TYPE_INVALID,
-			   G_TYPE_INVALID);
+	g_dbus_proxy_call_sync (window->priv->media_keys_proxy,
+				"GrabMediaPlayerKeys",
+				g_variant_new ("(su)", PACKAGE_NAME, 0),
+				G_DBUS_CALL_FLAGS_NONE,
+				-1,
+				NULL,
+				NULL);
 
 	return FALSE;
 }
@@ -2160,52 +2165,46 @@ window_focus_in_event_cb (GtkWidget     *widget,
 static void
 _goo_window_enable_media_keys (GooWindow *window)
 {
-	DBusGConnection *connection;
+	GDBusConnection *connection;
 
-	connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+	connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
 	if (connection == NULL)
 		return;
 
-	window->priv->media_keys_proxy = dbus_g_proxy_new_for_name_owner (connection,
-									  "org.gnome.SettingsDaemon",
-									  "/org/gnome/SettingsDaemon/MediaKeys",
-									  "org.gnome.SettingsDaemon.MediaKeys",
-									  NULL);
+	window->priv->media_keys_proxy = g_dbus_proxy_new_sync (connection,
+								G_DBUS_PROXY_FLAGS_NONE,
+								NULL,
+								"org.gnome.SettingsDaemon",
+								"/org/gnome/SettingsDaemon/MediaKeys",
+								"org.gnome.SettingsDaemon.MediaKeys",
+								NULL,
+								NULL);
 	if (window->priv->media_keys_proxy == NULL)
-		window->priv->media_keys_proxy = dbus_g_proxy_new_for_name_owner (connection,
-		                                                                  "org.gnome.SettingsDaemon",
-		                                                                  "/org/gnome/SettingsDaemon",
-		                                                                  "org.gnome.SettingsDaemon",
-		                                                                  NULL);
-	dbus_g_connection_unref (connection);
+		window->priv->media_keys_proxy = g_dbus_proxy_new_sync (connection,
+									G_DBUS_PROXY_FLAGS_NONE,
+									NULL,
+									"org.gnome.SettingsDaemon",
+									"/org/gnome/SettingsDaemon",
+									"org.gnome.SettingsDaemon",
+									NULL,
+									NULL);
+	g_object_unref (connection);
 
 	if (window->priv->media_keys_proxy == NULL)
 		return;
 
-	dbus_g_proxy_call (window->priv->media_keys_proxy,
-			   "GrabMediaPlayerKeys",
-			   NULL,
-			   G_TYPE_STRING, "goobox",
-			   G_TYPE_UINT, 0,
-			   G_TYPE_INVALID,
-			   G_TYPE_INVALID);
-
-        dbus_g_object_register_marshaller (goo_marshal_VOID__STRING_STRING,
-					   G_TYPE_NONE,
-					   G_TYPE_STRING,
-					   G_TYPE_STRING,
-					   G_TYPE_INVALID);
-        dbus_g_proxy_add_signal (window->priv->media_keys_proxy,
-				 "MediaPlayerKeyPressed",
-				 G_TYPE_STRING,
-				 G_TYPE_STRING,
-				 G_TYPE_INVALID);
-	dbus_g_proxy_connect_signal (window->priv->media_keys_proxy,
-				     "MediaPlayerKeyPressed",
-				     G_CALLBACK (media_player_key_pressed_cb),
-				     window,
-				     NULL);
-
+	g_dbus_proxy_call_sync (window->priv->media_keys_proxy,
+				"GrabMediaPlayerKeys",
+				g_variant_new ("(su)", PACKAGE_NAME, 0),
+				G_DBUS_CALL_FLAGS_NONE,
+				-1,
+				NULL,
+				NULL);
+
+	window->priv->media_key_event = g_signal_connect (window->priv->media_keys_proxy,
+							  "g-signal",
+							  G_CALLBACK (media_player_key_pressed_cb),
+							  window);
 	window->priv->focus_in_event = g_signal_connect (window,
 							 "focus-in-event",
 							 G_CALLBACK (window_focus_in_event_cb),
@@ -2213,9 +2212,6 @@ _goo_window_enable_media_keys (GooWindow *window)
 }
 
 
-#endif /* ENABLE_MEDIA_KEYS */
-
-
 static void
 goo_window_construct (GooWindow    *window,
 		      BraseroDrive *drive)
@@ -2554,9 +2550,7 @@ goo_window_construct (GooWindow    *window,
 
 	/* Media keys*/
 
-#ifdef ENABLE_MEDIA_KEYS
 	_goo_window_enable_media_keys (window);
-#endif /* ENABLE_MEDIA_KEYS */
 }
 
 



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