[rhythmbox] queue: add dbus interface
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] queue: add dbus interface
- Date: Sun, 6 Mar 2011 22:28:55 +0000 (UTC)
commit 875d19a81877d16e62b2fde4ddc8a873d66e5f19
Author: Jonathan Matthew <jonathan d14n org>
Date: Mon Mar 7 08:28:06 2011 +1000
queue: add dbus interface
This replaces the addToQueue, removeFromQueue and clearQueue methods
on the shell dbus interface.
sources/rb-play-queue-source.c | 141 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 141 insertions(+), 0 deletions(-)
---
diff --git a/sources/rb-play-queue-source.c b/sources/rb-play-queue-source.c
index 726943a..813e8a2 100644
--- a/sources/rb-play-queue-source.c
+++ b/sources/rb-play-queue-source.c
@@ -30,6 +30,7 @@
#include <libxml/tree.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <gtk/gtk.h>
#include "rb-play-queue-source.h"
@@ -52,6 +53,21 @@
* the usual horizontal space allowed for the side bar.
*/
+static const char *RB_PLAY_QUEUE_DBUS_PATH = "/org/gnome/Rhythmbox/PlayQueue";
+static const char *RB_PLAY_QUEUE_IFACE_NAME = "org.gnome.Rhythmbox.PlayQueue";
+
+static const char *rb_play_queue_dbus_spec =
+"<node>"
+" <interface name='org.gnome.Rhythmbox.PlayQueue'>"
+" <method name='AddToQueue'>"
+" <arg type='s' name='uri'/>"
+" </method>"
+" <method name='RemoveFromQueue'>"
+" <arg type='s' name='uri'/>"
+" </method>"
+" <method name='ClearQueue'/>"
+" </interface>"
+"</node>";
static void rb_play_queue_source_constructed (GObject *object);
static void rb_play_queue_source_get_property (GObject *object,
@@ -85,6 +101,15 @@ static void rb_play_queue_source_cmd_shuffle (GtkAction *action,
static GList *impl_get_ui_actions (RBDisplayPage *page);
static gboolean impl_show_popup (RBDisplayPage *page);
+static void rb_play_queue_dbus_method_call (GDBusConnection *connection,
+ const char *sender,
+ const char *object_path,
+ const char *interface_name,
+ const char *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ RBPlayQueueSource *source);
+
#define PLAY_QUEUE_SOURCE_SONGS_POPUP_PATH "/QueuePlaylistViewPopup"
#define PLAY_QUEUE_SOURCE_SIDEBAR_POPUP_PATH "/QueueSidebarViewPopup"
#define PLAY_QUEUE_SOURCE_POPUP_PATH "/QueueSourcePopup"
@@ -97,6 +122,9 @@ struct _RBPlayQueueSourcePrivate
GtkTreeViewColumn *sidebar_column;
GtkActionGroup *action_group;
RBPlayOrder *queue_play_order;
+
+ guint dbus_object_id;
+ GDBusConnection *bus;
};
enum
@@ -119,6 +147,12 @@ static GtkActionEntry rb_play_queue_source_actions [] =
G_CALLBACK (rb_play_queue_source_cmd_shuffle) }
};
+static const GDBusInterfaceVTable play_queue_vtable = {
+ (GDBusInterfaceMethodCallFunc) rb_play_queue_dbus_method_call,
+ NULL,
+ NULL
+};
+
static void
rb_play_queue_sync_playing_state (GObject *entry_view,
GParamSpec *pspec,
@@ -145,6 +179,14 @@ rb_play_queue_source_dispose (GObject *object)
priv->queue_play_order = NULL;
}
+ if (priv->bus != NULL) {
+ if (priv->dbus_object_id) {
+ g_dbus_connection_unregister_object (priv->bus, priv->dbus_object_id);
+ priv->dbus_object_id = 0;
+ }
+ g_object_unref (priv->bus);
+ }
+
G_OBJECT_CLASS (rb_play_queue_source_parent_class)->dispose (object);
}
@@ -280,6 +322,32 @@ rb_play_queue_source_constructed (GObject *object)
source, 0);
rb_play_queue_source_update_count (source, GTK_TREE_MODEL (model), 0);
+
+ /* register dbus interface */
+ priv->bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ if (priv->bus) {
+ GDBusNodeInfo *node_info;
+ GError *error = NULL;
+
+ node_info = g_dbus_node_info_new_for_xml (rb_play_queue_dbus_spec, &error);
+ if (error != NULL) {
+ g_warning ("Unable to parse playlist manager dbus spec: %s", error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ priv->dbus_object_id = g_dbus_connection_register_object (priv->bus,
+ RB_PLAY_QUEUE_DBUS_PATH,
+ g_dbus_node_info_lookup_interface (node_info, RB_PLAY_QUEUE_IFACE_NAME),
+ &play_queue_vtable,
+ source,
+ NULL,
+ &error);
+ if (error != NULL) {
+ g_warning ("Unable to register play queue dbus object: %s", error->message);
+ g_clear_error (&error);
+ }
+ }
}
static void
@@ -520,3 +588,76 @@ impl_get_ui_actions (RBDisplayPage *page)
return actions;
}
+static void
+rb_play_queue_dbus_method_call (GDBusConnection *connection,
+ const char *sender,
+ const char *object_path,
+ const char *interface_name,
+ const char *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ RBPlayQueueSource *source)
+{
+ RhythmDBEntry *entry;
+ RhythmDB *db;
+ const char *uri;
+
+ if (g_strcmp0 (interface_name, RB_PLAY_QUEUE_IFACE_NAME) != 0) {
+ rb_debug ("method call on unexpected interface %s", interface_name);
+ g_dbus_method_invocation_return_error (invocation,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_NOT_SUPPORTED,
+ "Method %s.%s not supported",
+ interface_name,
+ method_name);
+ return;
+ }
+
+ if (g_strcmp0 (method_name, "AddToQueue") == 0) {
+ g_variant_get (parameters, "(&s)", &uri);
+
+ db = rb_playlist_source_get_db (RB_PLAYLIST_SOURCE (source));
+ entry = rhythmdb_entry_lookup_by_location (db, uri);
+ if (entry == NULL) {
+ RBSource *urisource;
+ RBShell *shell;
+
+ g_object_get (source, "shell", &shell, NULL);
+ urisource = rb_shell_guess_source_for_uri (shell, uri);
+ g_object_unref (shell);
+
+ if (urisource != NULL) {
+ rb_source_add_uri (urisource, uri, NULL, NULL, NULL, NULL, NULL);
+ } else {
+ g_dbus_method_invocation_return_error (invocation,
+ RB_SHELL_ERROR,
+ RB_SHELL_ERROR_NO_SOURCE_FOR_URI,
+ _("No registered source can handle URI %s"),
+ uri);
+ return;
+ }
+ }
+ rb_static_playlist_source_add_location (RB_STATIC_PLAYLIST_SOURCE (source),
+ uri, -1);
+
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ } else if (g_strcmp0 (method_name, "RemoveFromQueue") == 0) {
+ g_variant_get (parameters, "(&s)", &uri);
+
+ if (rb_playlist_source_location_in_map (RB_PLAYLIST_SOURCE (source), uri)) {
+ rb_static_playlist_source_remove_location (RB_STATIC_PLAYLIST_SOURCE (source), uri);
+ }
+
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ } else if (g_strcmp0 (method_name, "ClearQueue") == 0) {
+ rb_play_queue_source_clear_queue (RB_PLAY_QUEUE_SOURCE (source));
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ } else {
+ g_dbus_method_invocation_return_error (invocation,
+ G_DBUS_ERROR,
+ G_DBUS_ERROR_NOT_SUPPORTED,
+ "Method %s.%s not supported",
+ interface_name,
+ method_name);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]