rhythmbox r6160 - in trunk: . plugins/daap



Author: jmatthew
Date: Tue Feb 24 09:57:28 2009
New Revision: 6160
URL: http://svn.gnome.org/viewvc/rhythmbox?rev=6160&view=rev

Log:
2009-02-24  Jonathan Matthew  <jonathan d14n org>

	patch by:  Alban Crequy  <alban crequy collabora co uk>

	* plugins/daap/rb-daap.xml:
	* plugins/daap/Makefile.am:
	* plugins/daap/rb-daap-plugin.c: (impl_activate),
	(new_daap_share_resolve_cb), (new_daap_share_location_added_cb),
	(rb_daap_add_source), (rb_daap_remove_source):
	Add a D-Bus interface for adding and removing DAAP shares.
	Fixes #570115.


Added:
   trunk/plugins/daap/rb-daap.xml
Modified:
   trunk/ChangeLog
   trunk/plugins/daap/Makefile.am
   trunk/plugins/daap/rb-daap-plugin.c

Modified: trunk/plugins/daap/Makefile.am
==============================================================================
--- trunk/plugins/daap/Makefile.am	(original)
+++ trunk/plugins/daap/Makefile.am	Tue Feb 24 09:57:28 2009
@@ -32,6 +32,7 @@
 
 libdaap_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
 libdaap_la_LIBADD = 					\
+	$(DBUS_LIBS)					\
 	$(MDNS_LIBS)
 
 INCLUDES = 						\
@@ -57,6 +58,7 @@
 	-DDATADIR=\""$(datadir)"\"			\
 	$(MDNS_CFLAGS)					\
 	$(RHYTHMBOX_CFLAGS)				\
+	$(DBUS_CFLAGS)					\
 	-D_XOPEN_SOURCE -D_BSD_SOURCE
 
 if USE_GNOME_KEYRING
@@ -96,3 +98,11 @@
 	$(BUILT_SOURCES)	\
 	$(NULL)
 
+rb-daap-glue.h: rb-daap.xml Makefile
+	$(LIBTOOL) --mode=execute $(DBUS_GLIB_BIN)/dbus-binding-tool --prefix=rb_daap --mode=glib-server --output=$@ $<
+
+BUILT_SOURCES += rb-daap-glue.h
+EXTRA_DIST += rb-daap.xml
+
+libdaap_la_LIBADD += $(DBUS_LIBS)
+

Modified: trunk/plugins/daap/rb-daap-plugin.c
==============================================================================
--- trunk/plugins/daap/rb-daap-plugin.c	(original)
+++ trunk/plugins/daap/rb-daap-plugin.c	Tue Feb 24 09:57:28 2009
@@ -2,6 +2,7 @@
  * rb-daap-plugin.c
  *
  * Copyright (C) 2006 James Livingston <doclivingston gmail com>
+ * Copyright (C) 2008 Alban Crequy <alban crequy collabora co uk>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -36,6 +37,7 @@
 #include <gtk/gtk.h>
 #include <glib.h>
 #include <glib-object.h>
+#include <dbus/dbus-glib.h>
 
 #include <libsoup/soup.h>
 
@@ -57,6 +59,8 @@
 #define CONF_DAAP_PREFIX  	CONF_PREFIX "/plugins/daap"
 #define CONF_ENABLE_BROWSING 	CONF_DAAP_PREFIX "/enable_browsing"
 
+#define DAAP_DBUS_PATH	"/org/gnome/Rhythmbox/DAAP"
+
 struct RBDaapPluginPrivate
 {
 	RBShell *shell;
@@ -65,6 +69,7 @@
 	GtkWidget *preferences;
 	gboolean sharing;
 	gboolean shutdown;
+	gboolean dbus_intf_added;
 
 	GtkActionGroup *daap_action_group;
 	guint daap_ui_merge_id;
@@ -109,6 +114,10 @@
 					GConfEntry *entry,
 					RBDaapPlugin *plugin);
 
+gboolean rb_daap_add_source (RBDaapPlugin *plugin, gchar *service_name, gchar *host, unsigned int port, GError **error);
+gboolean rb_daap_remove_source (RBDaapPlugin *plugin, gchar *service_name, GError **error);
+#include "rb-daap-glue.h"
+
 RB_PLUGIN_REGISTER(RBDaapPlugin, rb_daap_plugin)
 
 static GtkActionEntry rb_daap_source_actions [] =
@@ -197,7 +206,10 @@
 	GConfClient *client = eel_gconf_client_get_global ();
 	GtkUIManager *uimanager = NULL;
 	char *uifile;
+	DBusGConnection *conn;
+	GError *error = NULL;
 
+	plugin->priv->shutdown = FALSE;
 	plugin->priv->shell = g_object_ref (shell);
 
 	value = gconf_client_get_without_default (client,
@@ -255,6 +267,22 @@
 	plugin->priv->sharing = !no_registration;
 	if (plugin->priv->sharing)
 		rb_daap_sharing_init (shell);
+
+	/*
+	 * Add dbus interface
+	 */
+	if (plugin->priv->dbus_intf_added == FALSE) {
+		conn = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+		if (conn != NULL) {
+			dbus_g_object_type_install_info (RB_TYPE_DAAP_PLUGIN,
+							 &dbus_glib_rb_daap_object_info);
+			dbus_g_connection_register_g_object (conn, DAAP_DBUS_PATH,
+							     G_OBJECT (bplugin));
+			plugin->priv->dbus_intf_added = TRUE;
+		}
+		else
+			rb_debug ("No session D-Bus. DAAP interface on D-Bus disabled.");
+	}
 }
 
 static void
@@ -593,6 +621,7 @@
 
 typedef struct {
 	RBDaapPlugin *plugin;
+	char *service_name;
 	char *location;
 } RBDaapShareResolveData;
 
@@ -606,7 +635,7 @@
 	if (status == SOUP_STATUS_OK) {
 		rb_debug ("adding manually specified DAAP share at %s", data->location);
 		mdns_service_added (NULL,
-				    data->location,
+				    data->service_name,
 				    data->location,
 				    soup_address_get_physical (addr),
 				    soup_address_get_port (addr),
@@ -621,6 +650,7 @@
 	}
 
 	g_object_unref (data->plugin);
+	g_free (data->service_name);
 	g_free (data->location);
 	g_free (data);
 	g_object_unref (addr);
@@ -641,6 +671,7 @@
 
 	data = g_new0 (RBDaapShareResolveData, 1);
 	data->plugin = g_object_ref (plugin);
+	data->service_name = g_strdup (location);
 	data->location = g_strdup (location);
 
 	host = g_strdup (location);
@@ -910,3 +941,39 @@
 	return plugin->priv->preferences;
 }
 
+gboolean
+rb_daap_add_source (RBDaapPlugin *plugin, gchar *service_name, gchar *host, unsigned int port, GError **error)
+{
+	SoupAddress *addr;
+	RBDaapShareResolveData *data;
+
+	if (plugin->priv->shutdown)
+		return FALSE;
+
+	rb_debug ("Add DAAP source %s (%s:%d)", service_name, host, port);
+
+	data = g_new0 (RBDaapShareResolveData, 1);
+	data->plugin = g_object_ref (plugin);
+	data->service_name = g_strdup (service_name);
+	data->location = g_strdup (service_name);
+
+	addr = soup_address_new (host, port);
+
+	soup_address_resolve_async (addr,
+				    NULL, NULL,
+				    (SoupAddressCallback) new_daap_share_resolve_cb,
+				    data);
+
+	return TRUE;
+}
+
+gboolean
+rb_daap_remove_source (RBDaapPlugin *plugin, gchar *service_name, GError **error)
+{
+	if (plugin->priv->shutdown)
+		return FALSE;
+	rb_debug ("Remove DAAP source %s", service_name);
+	mdns_service_removed (plugin->priv->mdns_browser, service_name, plugin);
+	return TRUE;
+}
+

Added: trunk/plugins/daap/rb-daap.xml
==============================================================================
--- (empty file)
+++ trunk/plugins/daap/rb-daap.xml	Tue Feb 24 09:57:28 2009
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/">
+  <interface name="org.gnome.Rhythmbox.DAAP">
+
+    <method name="AddDAAPSource">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="rb_daap_add_source"/>
+      <arg type="s" name="service_name"/>
+      <arg type="s" name="host"/>
+      <arg type="u" name="port"/>
+    </method>
+
+    <method name="RemoveDAAPSource">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="rb_daap_remove_source"/>
+      <arg type="s" name="service_name"/>
+    </method>
+
+  </interface>
+</node>
+



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