From 19fd5a77a5a820f320d71ffa364b978a69345317 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Feb 2014 16:46:33 -0600 Subject: Signalling some properties! --- src/media-player-user.vala | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/media-player-user.vala b/src/media-player-user.vala index c4d0e42..798c8c8 100644 --- a/src/media-player-user.vala +++ b/src/media-player-user.vala @@ -23,6 +23,9 @@ public class MediaPlayerUser : MediaPlayer { Act.User? actuser = null; AccountsServiceSoundSettings? proxy = null; + HashTable properties_queued = new HashTable(str_hash, str_equal); + uint properties_timeout = 0; + /* Grab the user from the Accounts service and, when it is loaded then set up a proxy to its sound settings */ public MediaPlayerUser(string user) { @@ -44,23 +47,53 @@ public class MediaPlayerUser : MediaPlayer { }); } + ~MediaPlayerUser () { + if (properties_timeout != 0) { + Source.remove(properties_timeout); + properties_timeout = 0; + } + } + + /* Ensure that we've collected all the changes so that we only signal + once for variables like 'track' */ + bool properties_idle () { + properties_timeout = 0; + + properties_queued.@foreach((key, value) => { + this.notify_property(key); + }); + + /* Remove source */ + return false; + } + + /* Turns the DBus names into the object properties */ void queue_property_notification (string dbus_property_name) { + if (properties_timeout == 0) { + properties_timeout = Idle.add(properties_idle); + } + switch (dbus_property_name) { case "Timestamp": + properties_queued.insert("name", true); + properties_queued.insert("icon", true); + properties_queued.insert("state", true); + properties_queued.insert("current-track", true); break; case "PlayerName": + properties_queued.insert("name", true); break; case "PlayerIcon": + properties_queued.insert("icon", true); break; case "State": + properties_queued.insert("state", true); break; case "Title": - break; case "Artist": - break; case "Album": - break; case "ArtUrl": + properties_queued.insert("current-track", true); break; } } @@ -84,7 +117,8 @@ public class MediaPlayerUser : MediaPlayer { } }); - /* TODO: Update settings */ + /* Update all of them -- we've got a proxy! */ + queue_property_notification("Timestamp"); } catch (Error e) { this.proxy = null; warning("Unable to get proxy to user '%s' sound settings: %s", username, e.message); -- cgit v1.2.3