changeset 3346:71d8d93f1bad trunk

Implemented TrackChange, StatusChange signals, with a stub for CapsChange.
author Ben Tucker <ben.tucker@gmail.com>
date Sun, 12 Aug 2007 16:10:45 -0700
parents 67951f8f9d83
children d3e667797310 0afbafec6cd8
files src/audacious/dbus-service.h src/audacious/dbus.c src/audacious/main.c src/audacious/main.h src/audacious/playback.c src/audacious/playlist.c
diffstat 6 files changed, 103 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/dbus-service.h	Sun Aug 12 13:28:09 2007 -0700
+++ b/src/audacious/dbus-service.h	Sun Aug 12 16:10:45 2007 -0700
@@ -52,6 +52,13 @@
     MPRIS_CAPS_PROVIDES_TIMING          = 1 << 6,
 };
 
+// Status
+typedef enum {
+	MPRIS_STATUS_PLAY = 0,
+	MPRIS_STATUS_PAUSE,
+	MPRIS_STATUS_STOP
+} PlaybackStatus;
+
 // MPRIS /
 gboolean mpris_root_identity(MprisRoot *obj, gchar **identity,
                              GError **error);
@@ -81,9 +88,10 @@
     CAPS_CHANGE_SIG,
     LAST_SIG
 };
-gboolean mpris_player_emit_track_change(MprisPlayer *obj, GError **error);
-gboolean mpris_player_emit_status_change(MprisPlayer *obj, GError **error);
-gboolean mpris_player_emit_caps_change(MprisPlayer *obj, GError **error);
+
+gboolean mpris_emit_track_change(MprisPlayer *obj);
+gboolean mpris_emit_status_change(MprisPlayer *obj, PlaybackStatus status);
+gboolean mpris_emit_caps_change(MprisPlayer *obj);
 
 // MPRIS /TrackList
 gboolean mpris_tracklist_get_metadata(MprisTrackList *obj, gint pos,
--- a/src/audacious/dbus.c	Sun Aug 12 13:28:09 2007 -0700
+++ b/src/audacious/dbus.c	Sun Aug 12 16:10:45 2007 -0700
@@ -136,6 +136,15 @@
     dbus_g_connection_register_g_object(dbus_conn,
                                         AUDACIOUS_DBUS_PATH_MPRIS_PLAYER,
                                         G_OBJECT(object));
+
+	// Add signals
+	DBusGProxy *proxy = object->proxy;
+	dbus_g_proxy_add_signal(proxy, "StatusChange",
+			G_TYPE_INT, G_TYPE_INVALID);
+	dbus_g_proxy_add_signal(proxy, "CapsChange",
+			G_TYPE_INT, G_TYPE_INVALID);
+	dbus_g_proxy_add_signal(proxy, "TrackChange",
+			DBUS_TYPE_G_STRING_VALUE_HASHTABLE, G_TYPE_INVALID);
 }
 
 void mpris_tracklist_init(MprisTrackList *object) {
@@ -161,7 +170,7 @@
     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);
+    mpris = g_object_new(mpris_player_get_type(), NULL);
     g_object_new(mpris_tracklist_get_type(), NULL);
     g_message("D-Bus support has been activated");
 }
@@ -272,11 +281,11 @@
     // check paused before playing because playback_get_playing() is true when
     // paused as well as when playing
     if (playback_get_paused())
-        *status = 1;
+        *status = MPRIS_STATUS_PAUSE;
     else if (playback_get_playing())
-        *status = 0;
+        *status = MPRIS_STATUS_PLAY;
     else
-        *status = 2;
+        *status = MPRIS_STATUS_STOP;
     return TRUE;
 }
 gboolean mpris_player_get_metadata(MprisPlayer *obj, GHashTable **metadata,
@@ -364,21 +373,38 @@
     return TRUE;
 }
 // MPRIS /Player signals
-gboolean mpris_player_emit_caps_change(MprisPlayer *obj, GError **error) {
-    static GQuark quark;
-    if (!quark)
-        quark = g_quark_from_static_string("CapsChange");
-    g_signal_emit(obj, signals[CAPS_CHANGE_SIG], quark, "capabilities changed");
+gboolean mpris_emit_caps_change(MprisPlayer *obj) {
+    g_signal_emit(obj, signals[CAPS_CHANGE_SIG], 0, 0);
     return TRUE;
 }
 
-gboolean mpris_player_emit_track_change(MprisPlayer *obj, GError **error) {
-    g_signal_emit(obj, signals[TRACK_CHANGE_SIG], 0, "track changed");
+gboolean mpris_emit_track_change(MprisPlayer *obj) {
+	GHashTable *metadata;
+    Tuple *tuple = NULL;
+    GValue *value;
+    Playlist *active;
+
+    active = playlist_get_active();
+    gint pos = playlist_get_position(active);
+    tuple = playlist_get_tuple(active, pos);
+
+    metadata = mpris_metadata_from_tuple(tuple);
+
+    if (metadata != NULL) {
+		// Song URI
+		value = g_new0(GValue, 1);
+		g_value_init(value, G_TYPE_STRING);
+		g_value_set_string(value, playlist_get_filename(active, pos));
+
+		g_hash_table_insert(metadata, "URI", value);
+	}
+
+    g_signal_emit(obj, signals[TRACK_CHANGE_SIG], 0, metadata);
     return TRUE;
 }
 
-gboolean mpris_player_emit_status_change(MprisPlayer *obj, GError **error) {
-    g_signal_emit(obj, signals[STATUS_CHANGE_SIG], 0, "status changed");
+gboolean mpris_emit_status_change(MprisPlayer *obj, PlaybackStatus status) {
+    g_signal_emit(obj, signals[STATUS_CHANGE_SIG], 0, status);
     return TRUE;
 }
 
--- a/src/audacious/main.c	Sun Aug 12 13:28:09 2007 -0700
+++ b/src/audacious/main.c	Sun Aug 12 16:10:45 2007 -0700
@@ -414,6 +414,9 @@
 
 GCond *cond_scan;
 GMutex *mutex_scan;
+#ifdef USE_DBUS
+MprisPlayer *mpris;
+#endif
 
 static GSList *
 get_feature_list(void)
--- a/src/audacious/main.h	Sun Aug 12 13:28:09 2007 -0700
+++ b/src/audacious/main.h	Sun Aug 12 16:10:45 2007 -0700
@@ -30,6 +30,10 @@
 # include "ui_main.h"
 #endif
 
+#ifdef USE_DBUS
+#include "dbus-service.h"
+#endif
+
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -174,6 +178,9 @@
 
 extern GCond *cond_scan;
 extern GMutex *mutex_scan;
+#ifdef USE_DBUS
+extern MprisPlayer *mpris;
+#endif
 
 G_END_DECLS
 
--- a/src/audacious/playback.c	Sun Aug 12 13:28:09 2007 -0700
+++ b/src/audacious/playback.c	Sun Aug 12 16:10:45 2007 -0700
@@ -108,7 +108,7 @@
     if (playback->error)
         return -2;
     if (!playback->playing || 
-	(playback->eof && !playback->output->buffer_playing()))
+    (playback->eof && !playback->output->buffer_playing()))
         return -1;
     return playback->output->output_time();
 }
@@ -191,10 +191,17 @@
 
     g_return_if_fail(mainwin_playstatus != NULL);
 
-    if (ip_data.paused)
+    if (ip_data.paused) {
         ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PAUSE);
-    else
+#ifdef USE_DBUS
+        mpris_emit_status_change(mpris, MPRIS_STATUS_PAUSE);
+#endif
+    } else {
         ui_skinned_playstatus_set_status(mainwin_playstatus, STATUS_PLAY);
+#ifdef USE_DBUS
+        mpris_emit_status_change(mpris, MPRIS_STATUS_PLAY);
+#endif
+    }
 }
 
 void
@@ -240,6 +247,9 @@
         g_free(playback->filename);
         g_free(playback);
         set_current_input_playback(NULL);
+#ifdef USE_DBUS
+        mpris_emit_status_change(mpris, MPRIS_STATUS_STOP);
+#endif
     }
 
     ip_data.buffering = FALSE;
@@ -345,6 +355,9 @@
     set_current_input_playback(playback);
 
     playback->thread = g_thread_create(playback_monitor_thread, playback, TRUE, NULL);
+#ifdef USE_DBUS
+    mpris_emit_status_change(mpris, MPRIS_STATUS_PLAY);
+#endif
 
     return TRUE;
 }
--- a/src/audacious/playlist.c	Sun Aug 12 13:28:09 2007 -0700
+++ b/src/audacious/playlist.c	Sun Aug 12 16:10:45 2007 -0700
@@ -521,6 +521,9 @@
     playlistwin_update_list(playlist);
     if (restart_playing) {
         if (playlist->position) {
+#ifdef USE_DBUS
+            mpris_emit_track_change(mpris);
+#endif
             playback_initiate();
         }
         else {
@@ -560,6 +563,9 @@
 
     if (restart_playing) {
         if (playlist->position) {
+#ifdef USE_DBUS
+            mpris_emit_track_change(mpris);
+#endif
             playback_initiate();
         }
         else {
@@ -601,6 +607,9 @@
 
     if (restart_playing) {
         if (playlist->position) {
+#ifdef USE_DBUS
+            mpris_emit_track_change(mpris);
+#endif
             playback_initiate();
         }
         else {
@@ -1168,8 +1177,12 @@
     PLAYLIST_UNLOCK(playlist->mutex);
     playlist_check_pos_current(playlist);
 
-    if (restart_playing)
+    if (restart_playing) {
+#ifdef USE_DBUS
+        mpris_emit_track_change(mpris);
+#endif
         playback_initiate();
+    }
 
     playlistwin_update_list(playlist);
 }
@@ -1228,9 +1241,12 @@
 
     playlist_check_pos_current(playlist);
 
-    if (restart_playing)
+    if (restart_playing) {
+#ifdef USE_DBUS
+        mpris_emit_track_change(mpris);
+#endif
         playback_initiate();
-    else {
+    } else {
         playlistwin_update_list(playlist);
     }
 }
@@ -1410,9 +1426,12 @@
     PLAYLIST_UNLOCK(playlist->mutex);
     playlist_check_pos_current(playlist);
 
-    if (restart_playing)
+    if (restart_playing) {
+#ifdef USE_DBUS
+        mpris_emit_track_change(mpris);
+#endif
         playback_initiate();
-    else {
+    } else {
         playlistwin_update_list(playlist);
     }
 }
@@ -1479,6 +1498,9 @@
     PLAYLIST_UNLOCK(playlist->mutex);
 
     playlist_check_pos_current(playlist);
+#ifdef USE_DBUS
+    mpris_emit_track_change(mpris);
+#endif
     playback_initiate();
     playlistwin_update_list(playlist);
 }