mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-26 13:44:23 +08:00
tools/mpris-player: Add support for MPRIS TrackList.TrackAdded signal
This commit is contained in:
parent
a73ff5d4a8
commit
51e021de62
@ -1690,6 +1690,12 @@ static const GDBusMethodTable tracklist_methods[] = {
|
||||
{ },
|
||||
};
|
||||
|
||||
static const GDBusSignalTable tracklist_signals[] = {
|
||||
{ GDBUS_SIGNAL("TrackAdded", GDBUS_ARGS({"metadata", "a{sv}"},
|
||||
{"after", "o"})) },
|
||||
{ }
|
||||
};
|
||||
|
||||
static void append_path(gpointer data, gpointer user_data)
|
||||
{
|
||||
GDBusProxy *proxy = data;
|
||||
@ -1813,7 +1819,7 @@ static void register_tracklist(struct player *player, const char *playlist)
|
||||
if (!g_dbus_register_interface(player->conn, MPRIS_PLAYER_PATH,
|
||||
MPRIS_TRACKLIST_INTERFACE,
|
||||
tracklist_methods,
|
||||
NULL,
|
||||
tracklist_signals,
|
||||
tracklist_properties,
|
||||
player, NULL)) {
|
||||
fprintf(stderr, "Could not register interface %s",
|
||||
@ -1973,6 +1979,10 @@ static void register_item(struct player *player, GDBusProxy *proxy)
|
||||
{
|
||||
struct tracklist *tracklist;
|
||||
const char *path;
|
||||
DBusMessage *signal;
|
||||
DBusMessageIter iter, args, metadata;
|
||||
GSList *l;
|
||||
GDBusProxy *after;
|
||||
|
||||
tracklist = player->tracklist;
|
||||
if (tracklist == NULL)
|
||||
@ -1983,11 +1993,46 @@ static void register_item(struct player *player, GDBusProxy *proxy)
|
||||
!g_str_has_prefix(path, tracklist->playlist))
|
||||
return;
|
||||
|
||||
l = g_slist_last(tracklist->items);
|
||||
tracklist->items = g_slist_append(tracklist->items, proxy);
|
||||
|
||||
g_dbus_emit_property_changed(player->conn, MPRIS_PLAYER_PATH,
|
||||
MPRIS_TRACKLIST_INTERFACE,
|
||||
"Tracks");
|
||||
|
||||
if (l == NULL)
|
||||
return;
|
||||
|
||||
signal = dbus_message_new_signal(MPRIS_PLAYER_PATH,
|
||||
MPRIS_TRACKLIST_INTERFACE,
|
||||
"TrackAdded");
|
||||
if (!signal) {
|
||||
fprintf(stderr, "Unable to allocate new %s.TrackAdded signal",
|
||||
MPRIS_TRACKLIST_INTERFACE);
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_iter_init_append(signal, &args);
|
||||
|
||||
if (!g_dbus_proxy_get_property(proxy, "Metadata", &iter)) {
|
||||
dbus_message_unref(signal);
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY,
|
||||
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
|
||||
DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
|
||||
DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &metadata);
|
||||
|
||||
parse_metadata(&iter, &metadata, parse_track_entry);
|
||||
|
||||
dbus_message_iter_close_container(&args, &metadata);
|
||||
|
||||
after = l->data;
|
||||
path = g_dbus_proxy_get_path(after);
|
||||
dbus_message_iter_append_basic(&args, DBUS_TYPE_OBJECT_PATH, &path);
|
||||
|
||||
g_dbus_send_message(player->conn, signal);
|
||||
}
|
||||
|
||||
static void proxy_added(GDBusProxy *proxy, void *user_data)
|
||||
|
Loading…
Reference in New Issue
Block a user