changeset 2769:bf2d80abf76e trunk

[svn] Implemented CMD_IS_ADVANCE and CMD_TOGGLE_ADVANCE. Added partial MPRIS support. Root is complete, Player is partially implemented, and TrackList has not been started.
author magma
date Sun, 13 May 2007 18:38:53 -0700
parents 4a5cdf975bb3
children e21a9128e683
files ChangeLog src/audacious/Makefile src/audacious/build_stamp.c src/audacious/dbus-service.h src/audacious/dbus.c src/audacious/dbus.h src/audacious/mpris_player.xml src/audacious/objects.xml src/audacious/ui_main.c src/audacious/ui_main.h src/libaudclient/audctrl.c
diffstat 11 files changed, 237 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun May 13 11:57:18 2007 -0700
+++ b/ChangeLog	Sun May 13 18:38:53 2007 -0700
@@ -1,3 +1,13 @@
+2007-05-13 18:57:18 +0000  Ben Tucker <bnt@interchange.ubc.ca>
+  revision [4562]
+  Added a hook when building dependencies so that the dbus-bindings are created first without producing any error messages.
+  
+  trunk/mk/objective.mk        |    4 +++-
+  trunk/src/Makefile           |    3 +++
+  trunk/src/audacious/Makefile |    2 +-
+  3 files changed, 7 insertions(+), 2 deletions(-)
+
+
 2007-05-13 18:56:01 +0000  Ben Tucker <bnt@interchange.ubc.ca>
   revision [4560]
   Changed signedness and formatting.
--- a/src/audacious/Makefile	Sun May 13 11:57:18 2007 -0700
+++ b/src/audacious/Makefile	Sun May 13 18:38:53 2007 -0700
@@ -138,9 +138,9 @@
 
 dbus-server-bindings.h: $(DBUS_BINDINGS_SOURCES)
 	$(DBUS_BINDING_TOOL) --mode=glib-server --prefix=audacious_rc objects.xml > $@
-	# $(DBUS_BINDING_TOOL) --mode=glib-server --prefix=mpris_root mpris_root.xml >> $@
+	$(DBUS_BINDING_TOOL) --mode=glib-server --prefix=mpris_root mpris_root.xml >> $@
 	# $(DBUS_BINDING_TOOL) --mode=glib-server --prefix=mpris_tracklist mpris_tracklist.xml >> $@
-	# $(DBUS_BINDING_TOOL) --mode=glib-server --prefix=mpris_player mpris_player.xml >> $@
+	$(DBUS_BINDING_TOOL) --mode=glib-server --prefix=mpris_player mpris_player.xml >> $@
 	@printf "%10s     %-20s\n" DBUS-BIND $@
 
 dbus-client-bindings.h: $(DBUS_BINDINGS_SOURCES)
--- a/src/audacious/build_stamp.c	Sun May 13 11:57:18 2007 -0700
+++ b/src/audacious/build_stamp.c	Sun May 13 18:38:53 2007 -0700
@@ -1,2 +1,2 @@
 #include <glib.h>
-const gchar *svn_stamp = "20070513-4560";
+const gchar *svn_stamp = "20070513-4562";
--- a/src/audacious/dbus-service.h	Sun May 13 11:57:18 2007 -0700
+++ b/src/audacious/dbus-service.h	Sun May 13 18:38:53 2007 -0700
@@ -27,17 +27,39 @@
 
 typedef struct {
     GObject parent;
-    DBusGConnection *connection;
-} RemoteObject;
+} RemoteObject, MprisRoot, MprisPlayer;
 
 typedef struct {
     GObjectClass parent_class;
-} RemoteObjectClass;
+} RemoteObjectClass, MprisRootClass, MprisPlayerClass;
 
 void init_dbus();
 void free_dbus();
 DBusGProxy *audacious_get_dbus_proxy();
 
+///////////////////////////
+// MPRIS defined methods //
+///////////////////////////
+gboolean mpris_root_identity(MprisRoot *obj, gchar **identity,
+                             GError **error);
+gboolean mpris_player_next(MprisPlayer *obj, GError **error);
+gboolean mpris_player_prev(MprisPlayer *obj, GError **error);
+gboolean mpris_player_pause(MprisPlayer *obj, GError **error);
+gboolean mpris_player_stop(MprisPlayer *obj, GError **error);
+gboolean mpris_player_play(MprisPlayer *obj, GError **error);
+gboolean mpris_player_quit(MprisPlayer *obj, GError **error);
+gboolean mpris_player_repeat(MprisPlayer *obj, gboolean rpt, GError **error);
+gboolean mpris_player_get_status(MprisPlayer *obj, gint *status,
+                                 GError **error);
+gboolean mpris_player_get_caps(MprisPlayer *obj, gint *capabilities,
+                                 GError **error);
+gboolean mpris_player_volume_set(MprisPlayer *obj, gint vol, GError **error);
+gboolean mpris_player_volume_get(MprisPlayer *obj, gint *vol,
+                                 GError **error);
+gboolean mpris_player_position_set(MprisPlayer *obj, gint pos, GError **error);
+gboolean mpris_player_position_get(MprisPlayer *obj, gint *pos,
+                                   GError **error);
+
 // Audacious General Information
 gboolean audacious_rc_version(RemoteObject *obj, gchar **version,
                               GError **error);
@@ -102,10 +124,13 @@
                               GError **error);
 gboolean audacious_rc_delete(RemoteObject *obj, guint pos, GError **error);
 gboolean audacious_rc_clear(RemoteObject *obj, GError **error);
-gboolean audacious_rc_repeating(RemoteObject *obj, gboolean *is_repeating,
-                                GError **error);
-gboolean audacious_rc_repeat(RemoteObject *obj, GError **error);
-gboolean audacious_rc_shuffling(RemoteObject *obj, gboolean *is_shuffling,
-                                GError **error);
-gboolean audacious_rc_shuffle(RemoteObject *obj, GError **error);
+gboolean audacious_rc_auto_advance(RemoteObject *obj, gboolean *is_advance,
+                                   GError **error);
+gboolean audacious_rc_toggle_auto_advance(RemoteObject *obj, GError **error);
+gboolean audacious_rc_repeat(RemoteObject *obj, gboolean *is_repeat,
+                             GError **error);
+gboolean audacious_rc_toggle_repeat(RemoteObject *obj, GError **error);
+gboolean audacious_rc_shuffle(RemoteObject *obj, gboolean *is_shuffle,
+                              GError **error);
+gboolean audacious_rc_toggle_shuffle(RemoteObject *obj, GError **error);
 #endif // !_DBUS_SERVICE_H
--- a/src/audacious/dbus.c	Sun May 13 11:57:18 2007 -0700
+++ b/src/audacious/dbus.c	Sun May 13 18:38:53 2007 -0700
@@ -39,33 +39,34 @@
 #include "titlestring.h"
 #include "ui_jumptotrack.h"
 
+static DBusGConnection *dbus_conn = NULL;
+
 G_DEFINE_TYPE(RemoteObject, audacious_rc, G_TYPE_OBJECT);
+G_DEFINE_TYPE(MprisRoot, mpris_root, G_TYPE_OBJECT);
+G_DEFINE_TYPE(MprisPlayer, mpris_player, G_TYPE_OBJECT);
+// G_DEFINE_TYPE(MprisTracklist, mpris_tracklist, G_TYPE_OBJECT);
 
 void audacious_rc_class_init(RemoteObjectClass *klass) {}
+void mpris_root_class_init(MprisRootClass *klass) {}
+void mpris_player_class_init(MprisPlayerClass *klass) {}
+// void mpris_tracklist_class_init(MprisTracklistClass *klass) {}
 
 void audacious_rc_init(RemoteObject *object) {
     GError *error = NULL;
     DBusGProxy *driver_proxy;
     unsigned int request_ret;
 
-    // Initialize the DBus connection
-    object->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
-    if (object->connection == NULL) {
-        g_warning("Unable to connect to dbus: %s", error->message);
-        g_error_free(error);
-        return;
-    }
     
     dbus_g_object_type_install_info(audacious_rc_get_type(),
                                     &dbus_glib_audacious_rc_object_info);
     
     // Register DBUS path
-    dbus_g_connection_register_g_object(object->connection,
+    dbus_g_connection_register_g_object(dbus_conn,
                                         AUDACIOUS_DBUS_PATH, G_OBJECT(object));
 
     // Register the service name, the constants here are defined in
     // dbus-glib-bindings.h
-    driver_proxy = dbus_g_proxy_new_for_name(object->connection,
+    driver_proxy = dbus_g_proxy_new_for_name(dbus_conn,
                                              DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
                                              DBUS_INTERFACE_DBUS);
 
@@ -75,15 +76,109 @@
         g_error_free(error);
     }
 
+    if (!org_freedesktop_DBus_request_name(driver_proxy,
+        AUDACIOUS_DBUS_SERVICE_MPRIS, 0, &request_ret, &error)) {
+        g_warning("Unable to register service: %s", error->message);
+        g_error_free(error);
+    }
+
     g_object_unref(driver_proxy);
 }
 
+void mpris_root_init(MprisRoot *object) {
+    dbus_g_object_type_install_info(mpris_root_get_type(),
+                                    &dbus_glib_mpris_root_object_info);
+    
+    // Register DBUS path
+    dbus_g_connection_register_g_object(dbus_conn,
+                                        AUDACIOUS_DBUS_PATH_MPRIS_ROOT,
+                                        G_OBJECT(object));
+}
+
+void mpris_player_init(MprisPlayer *object) {
+    dbus_g_object_type_install_info(mpris_player_get_type(),
+                                    &dbus_glib_mpris_player_object_info);
+    
+    // Register DBUS path
+    dbus_g_connection_register_g_object(dbus_conn,
+                                        AUDACIOUS_DBUS_PATH_MPRIS_PLAYER,
+                                        G_OBJECT(object));
+}
+
 void init_dbus() {
+    GError *error = NULL;
+    // Initialize the DBus connection
+    dbus_conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+    if (dbus_conn == NULL) {
+        g_warning("Unable to connect to dbus: %s", error->message);
+        g_error_free(error);
+        return;
+    }
+
     g_type_init();
     g_object_new(audacious_rc_get_type(), NULL);
+    g_object_new(mpris_root_get_type(), NULL);
+    g_object_new(mpris_player_get_type(), NULL);
+    // g_object_new(mpris_tracklist_get_type(), NULL);
     g_message("D-Bus support has been activated");
 }
 
+///////////////////////////
+// MPRIS defined methods //
+///////////////////////////
+gboolean mpris_root_identity(MprisRoot *obj, gchar **identity,
+                             GError **error) {
+    *identity = g_strdup_printf("Audacious %s", VERSION);
+    return TRUE;
+}
+
+gboolean mpris_player_next(MprisPlayer *obj, GError **error) {
+    return audacious_rc_advance(obj, error);
+}
+gboolean mpris_player_prev(MprisPlayer *obj, GError **error) {
+    return audacious_rc_reverse(obj, error);
+}
+gboolean mpris_player_pause(MprisPlayer *obj, GError **error) {
+    return audacious_rc_pause(obj, error);
+}
+gboolean mpris_player_stop(MprisPlayer *obj, GError **error) {
+    return audacious_rc_stop(obj, error);
+}
+gboolean mpris_player_play(MprisPlayer *obj, GError **error) {
+    return audacious_rc_play(obj, error);
+}
+gboolean mpris_player_quit(MprisPlayer *obj, GError **error) {
+    return audacious_rc_quit(obj, error);
+}
+gboolean mpris_player_repeat(MprisPlayer *obj, gboolean rpt, GError **error) {
+    mainwin_repeat_pushed(rpt);
+    mainwin_set_noplaylistadvance(rpt);
+    return TRUE;
+}
+gboolean mpris_player_get_status(MprisPlayer *obj, gint *status,
+                                 GError **error) {
+    return TRUE;
+}
+gboolean mpris_player_get_caps(MprisPlayer *obj, gint *capabilities,
+                                 GError **error) {
+    return TRUE;
+}
+gboolean mpris_player_volume_set(MprisPlayer *obj, gint vol, GError **error) {
+    return TRUE;
+}
+gboolean mpris_player_volume_get(MprisPlayer *obj, gint *vol,
+                                 GError **error) {
+    return TRUE;
+}
+gboolean mpris_player_position_set(MprisPlayer *obj, gint pos,
+                                   GError **error) {
+    return TRUE;
+}
+gboolean mpris_player_position_get(MprisPlayer *obj, gint *pos,
+                                   GError **error) {
+    return TRUE;
+}
+
 // Audacious General Information
 gboolean audacious_rc_version(RemoteObject *obj, gchar **version,
                               GError **error) {
@@ -386,24 +481,35 @@
     return TRUE;
 }
 
-gboolean audacious_rc_repeating(RemoteObject *obj, gboolean *is_repeating,
+gboolean audacious_rc_auto_advance(RemoteObject *obj, gboolean *is_advance,
+                                   GError **error) {
+    *is_advance = cfg.no_playlist_advance;
+    return TRUE;
+}
+
+gboolean audacious_rc_toggle_auto_advance(RemoteObject *obj, GError **error) {
+    cfg.no_playlist_advance = !cfg.no_playlist_advance;
+    return TRUE;
+}
+
+gboolean audacious_rc_repeat(RemoteObject *obj, gboolean *is_repeating,
                                 GError **error) {
     *is_repeating = cfg.repeat;
     return TRUE;
 }
 
-gboolean audacious_rc_repeat(RemoteObject *obj, GError **error) {
+gboolean audacious_rc_toggle_repeat(RemoteObject *obj, GError **error) {
     mainwin_repeat_pushed(!cfg.repeat);
     return TRUE;
 }
 
-gboolean audacious_rc_shuffling(RemoteObject *obj, gboolean *is_shuffling,
+gboolean audacious_rc_shuffle(RemoteObject *obj, gboolean *is_shuffling,
                                 GError **error) {
     *is_shuffling = cfg.shuffle;
     return TRUE;
 }
 
-gboolean audacious_rc_shuffle(RemoteObject *obj, GError **error) {
+gboolean audacious_rc_toggle_shuffle(RemoteObject *obj, GError **error) {
     mainwin_shuffle_pushed(!cfg.shuffle);
     return TRUE;
 }
--- a/src/audacious/dbus.h	Sun May 13 11:57:18 2007 -0700
+++ b/src/audacious/dbus.h	Sun May 13 18:38:53 2007 -0700
@@ -23,5 +23,9 @@
 #define AUDACIOUS_DBUS_SERVICE      "org.atheme.audacious"
 #define AUDACIOUS_DBUS_PATH         "/org/atheme/audacious"
 #define AUDACIOUS_DBUS_INTERFACE    "org.atheme.audacious"
+#define AUDACIOUS_DBUS_SERVICE_MPRIS    "org.freedesktop.MediaPlayer"
+#define AUDACIOUS_DBUS_PATH_MPRIS_ROOT      "/"
+#define AUDACIOUS_DBUS_PATH_MPRIS_PLAYER    "/Player"
+#define AUDACIOUS_DBUS_PATH_MPRIS_TRACKLIST "/TrackList"
 
 #endif // !_AUDDBUS_H
--- a/src/audacious/mpris_player.xml	Sun May 13 11:57:18 2007 -0700
+++ b/src/audacious/mpris_player.xml	Sun May 13 18:38:53 2007 -0700
@@ -21,14 +21,27 @@
 
 <node name="/Player">
     <interface name="org.freedesktop.MediaPlayer">
-        <method name="Next" />
-        <method name="Prev" />
-        <method name="Pause" />
-        <method name="Stop" />
-        <method name="Play" />
-        <method name="Quit" />
+        <method name="Next">
+            <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
+        </method>
+        <method name="Prev">
+            <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
+        </method>
+        <method name="Pause">
+            <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
+        </method>
+        <method name="Stop">
+            <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
+        </method>
+        <method name="Play">
+            <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
+        </method>
+        <method name="Quit">
+            <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
+        </method>
 
         <method name="Repeat">
+            <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
             <arg type="b" direction="in" />
         </method>
 
@@ -41,6 +54,7 @@
         </method>
 
         <method name="VolumeSet">
+            <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
             <arg type="i" direction="in" />
         </method>
 
@@ -49,6 +63,7 @@
         </method>
 
         <method name="PositionSet">
+            <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
             <arg type="i" direction="in" />
         </method>
 
--- a/src/audacious/objects.xml	Sun May 13 11:57:18 2007 -0700
+++ b/src/audacious/objects.xml	Sun May 13 18:38:53 2007 -0700
@@ -56,6 +56,8 @@
     CMD_EJECT
     CMD_GET_INFO
     CMD_PLAYLIST_GET_TUPLE_DATA
+    CMD_IS_ADVANCE
+    CMD_TOGGLE_ADVANCE
 
 
     Remaining:
@@ -80,8 +82,6 @@
     CMD_PLAYQUEUE_ADD
     CMD_GET_PLAYQUEUE_LENGTH
     CMD_PLAYQUEUE_REMOVE
-    CMD_TOGGLE_ADVANCE
-    CMD_IS_ADVANCE
     CMD_ACTIVATE
     CMD_SHOW_JTF_BOX
     CMD_PLAYQUEUE_CLEAR
@@ -331,23 +331,33 @@
             <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
         </method>
 
+        <!-- Query auto-advance status -->
+        <method name="AutoAdvance">
+            <arg type="b" direction="out" name="is_advance"/>
+        </method>
+
+        <!-- Toggle auto-advance -->
+        <method name="ToggleAutoAdvance">
+            <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
+        </method>
+
         <!-- Query repeat status -->
-        <method name="Repeating">
-            <arg type="b" direction="out" name="is_repeating"/>
+        <method name="Repeat">
+            <arg type="b" direction="out" name="is_repeat"/>
         </method>
 
         <!-- Toggle repeat -->
-        <method name="Repeat">
+        <method name="ToggleRepeat">
             <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
         </method>
 
         <!-- Query shuffle status -->
-        <method name="Shuffling">
-            <arg type="b" direction="out" name="is_shuffling"/>
+        <method name="Shuffle">
+            <arg type="b" direction="out" name="is_shuffle"/>
         </method>
 
         <!-- Toggle shuffle -->
-        <method name="Shuffle">
+        <method name="ToggleShuffle">
             <annotation name="org.freedesktop.DBus.GLib.NoReply" value=""/>
         </method>
     </interface>
--- a/src/audacious/ui_main.c	Sun May 13 11:57:18 2007 -0700
+++ b/src/audacious/ui_main.c	Sun May 13 18:38:53 2007 -0700
@@ -2011,6 +2011,12 @@
     check_set(toggleaction_group_others, "stop after current song", cfg.stopaftersong);
 }
 
+void
+mainwin_set_noplaylistadvance(gboolean no_advance)
+{
+    cfg.no_playlist_advance = no_advance;
+    check_set(toggleaction_group_others, "playback no playlist advance", cfg.no_playlist_advance);
+}
 
 static void
 mainwin_set_doublesize(gboolean doublesize)
--- a/src/audacious/ui_main.h	Sun May 13 11:57:18 2007 -0700
+++ b/src/audacious/ui_main.h	Sun May 13 18:38:53 2007 -0700
@@ -148,6 +148,7 @@
 void mainwin_set_song_info(gint rate, gint freq, gint nch);
 void mainwin_clear_song_info(void);
 void mainwin_set_stopaftersong(gboolean stop);
+void mainwin_set_noplaylistadvance(gboolean no_advance);
 
 void mainwin_set_always_on_top(gboolean always);
 void mainwin_set_volume_diff(gint diff);
--- a/src/libaudclient/audctrl.c	Sun May 13 11:57:18 2007 -0700
+++ b/src/libaudclient/audctrl.c	Sun May 13 18:38:53 2007 -0700
@@ -332,6 +332,7 @@
  * Return value: A path to the currently selected skin.
  **/
 gchar *audacious_remote_get_skin(DBusGProxy *proxy) {
+    return NULL;
 }
 
 /**
@@ -558,6 +559,7 @@
  * Return value: TRUE if yes, otherwise FALSE.
  **/
 gboolean audacious_remote_is_running(DBusGProxy *proxy) {
+    return FALSE;
 }
 
 /**
@@ -587,6 +589,10 @@
  * Return value: TRUE if yes, otherwise FALSE.
  **/
 gboolean audacious_remote_is_repeat(DBusGProxy *proxy) {
+    gboolean is_repeat;
+    org_atheme_audacious_repeat(proxy, &is_repeat, &error);
+    g_clear_error(&error);
+    return is_repeat;
 }
 
 /**
@@ -598,6 +604,10 @@
  * Return value: TRUE if yes, otherwise FALSE.
  **/
 gboolean audacious_remote_is_shuffle(DBusGProxy *proxy) {
+    gboolean is_shuffle;
+    org_atheme_audacious_shuffle(proxy, &is_shuffle, &error);
+    g_clear_error(&error);
+    return is_shuffle;
 }
 
 /**
@@ -730,6 +740,11 @@
  * Return value: The number of entries in the playqueue.
  **/
 gint audacious_remote_get_playqueue_length(DBusGProxy *proxy) {
+    gint len = 0;
+    // this returns the lenght of the playlist, NOT the length of the playqueue
+    org_atheme_audacious_length(proxy, &len, &error);
+    g_clear_error(&error);
+    return len;
 }
 
 /**
@@ -739,6 +754,8 @@
  * Tells audacious to toggle the no-playlist-advance feature.
  **/
 void audacious_remote_toggle_advance(DBusGProxy *proxy) {
+    org_atheme_audacious_toggle_auto_advance(proxy, &error);
+    g_clear_error(&error);
 }
 
 /**
@@ -750,6 +767,10 @@
  * Return value: TRUE if yes, otherwise FALSE.
  **/
 gboolean audacious_remote_is_advance(DBusGProxy *proxy) {
+    gboolean is_advance;
+    org_atheme_audacious_auto_advance(proxy, &is_advance, &error);
+    g_clear_error(&error);
+    return is_advance;
 }
 
 /**