diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-12-10 19:08:00 +0000 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-12-10 19:08:00 +0000 |
commit | f800967fcabf6a9d7e6223ff8d6591f042496588 (patch) | |
tree | 2ac7f8bc6a9fabd09601f55500dd3f01272db6c5 /src | |
parent | 0649b09ccf86ea2a158fb24061fc3a142e02f462 (diff) | |
parent | ee3cc0d34b7f64412a9298fc7f9160641d887a83 (diff) | |
download | ayatana-indicator-sound-f800967fcabf6a9d7e6223ff8d6591f042496588.tar.gz ayatana-indicator-sound-f800967fcabf6a9d7e6223ff8d6591f042496588.tar.bz2 ayatana-indicator-sound-f800967fcabf6a9d7e6223ff8d6591f042496588.zip |
merged appropriate mpris2 watcher startup behaviour
Diffstat (limited to 'src')
-rw-r--r-- | src/mpris2-watcher.vala | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala index 1cf8baa..d154fcb 100644 --- a/src/mpris2-watcher.vala +++ b/src/mpris2-watcher.vala @@ -19,7 +19,8 @@ with this program. If not, see <http://www.gnu.org/licenses/>. [DBus (name = "org.freedesktop.DBus")] public interface FreeDesktopObject: Object { - public abstract signal void name_owner_changed (string name, + public abstract async string[] list_names() throws IOError; + public abstract signal void name_owner_changed (string name, string old_owner, string new_owner); } @@ -48,6 +49,7 @@ public class Mpris2Watcher : GLib.Object FREEDESKTOP_OBJECT, DBusProxyFlags.DO_NOT_LOAD_PROPERTIES ); this.fdesktop_obj.name_owner_changed.connect (this.name_changes_detected); + this.check_for_active_clients.begin(); } catch ( IOError e ){ warning( "Mpris2watcher could not set up a watch for mpris clients appearing on the bus: %s", @@ -58,8 +60,24 @@ public class Mpris2Watcher : GLib.Object private void name_changes_detected ( FreeDesktopObject dbus_obj, string name, string previous_owner, - string current_owner ) { - MprisRoot mpris2_root; + string current_owner ) + { + MprisRoot? mpris2_root = this.create_mpris_root(name); + + if (mpris2_root == null) return; + + if (previous_owner != "" && current_owner == "") { + debug ("Client '%s' gone down", name); + client_disappeared (name); + } + else if (previous_owner == "" && current_owner != "") { + debug ("Client '%s' has appeared", name); + client_appeared (mpris2_root.DesktopEntry); + } + } + + private MprisRoot? create_mpris_root(string name){ + MprisRoot mpris2_root = null; if ( name.has_prefix (MPRIS_PREFIX) ){ try { mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, @@ -69,16 +87,30 @@ public class Mpris2Watcher : GLib.Object catch (IOError e){ warning( "Mpris2watcher could not create a root interface: %s", e.message ); - return; - } - if (previous_owner != "" && current_owner == "") { - debug ("Client '%s' gone down", name); - client_disappeared (name); - } - else if (previous_owner == "" && current_owner != "") { - debug ("Client '%s' has appeared", name); - client_appeared (mpris2_root.DesktopEntry); } } + return mpris2_root; } + + // At startup check to see if there are clients up that we are interested in + // More relevant for development and daemon's like mpd. + private async void check_for_active_clients() + { + string[] interfaces; + try{ + interfaces = yield this.fdesktop_obj.list_names(); + } + catch ( IOError e) { + warning( "Mpris2watcher could fetch active interfaces at startup: %s", + e.message ); + return; + } + foreach (var address in interfaces) { + if (address.has_prefix (MPRIS_PREFIX)){ + MprisRoot? mpris2_root = this.create_mpris_root(address); + if (mpris2_root == null) return; + client_appeared (mpris2_root.DesktopEntry); + } + } + } }
\ No newline at end of file |