diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-12-07 10:32:32 +0000 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-12-07 10:32:32 +0000 |
commit | 4280f27f7b3f42a73c971664f0cd322780c2bff6 (patch) | |
tree | 2faba8113b99ae3d23e3d9cf02879b6eb0a70d53 /src/mpris2-watcher.vala | |
parent | 0d5c60e9161f4b1b4315bbfac7862ef662f577ee (diff) | |
parent | 4061f2bed3ed22262305c19e534f1007f7febbe9 (diff) | |
download | ayatana-indicator-sound-4280f27f7b3f42a73c971664f0cd322780c2bff6.tar.gz ayatana-indicator-sound-4280f27f7b3f42a73c971664f0cd322780c2bff6.tar.bz2 ayatana-indicator-sound-4280f27f7b3f42a73c971664f0cd322780c2bff6.zip |
merged the first large part of the gdbus port
Diffstat (limited to 'src/mpris2-watcher.vala')
-rw-r--r-- | src/mpris2-watcher.vala | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala new file mode 100644 index 0000000..1cf8baa --- /dev/null +++ b/src/mpris2-watcher.vala @@ -0,0 +1,84 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran <conor.curran@canonical.com> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +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, + string old_owner, + string new_owner); +} + +public class Mpris2Watcher : GLib.Object +{ + private const string FREEDESKTOP_SERVICE = "org.freedesktop.DBus"; + private const string FREEDESKTOP_OBJECT = "/org/freedesktop/DBus"; + private const string MPRIS_PREFIX = "org.mpris.MediaPlayer2."; + private const string MPRIS_MEDIA_PLAYER_PATH = "/org/mpris/MediaPlayer2"; + + FreeDesktopObject fdesktop_obj; + + public signal void client_appeared ( string desktop_name ); + public signal void client_disappeared ( string mpris_root_interface ); + + public Mpris2Watcher () + { + } + + construct + { + try { + this.fdesktop_obj = Bus.get_proxy_sync ( BusType.SESSION, + FREEDESKTOP_SERVICE, + FREEDESKTOP_OBJECT, + DBusProxyFlags.DO_NOT_LOAD_PROPERTIES ); + this.fdesktop_obj.name_owner_changed.connect (this.name_changes_detected); + } + catch ( IOError e ){ + warning( "Mpris2watcher could not set up a watch for mpris clients appearing on the bus: %s", + e.message ); + } + } + + private void name_changes_detected ( FreeDesktopObject dbus_obj, + string name, + string previous_owner, + string current_owner ) { + MprisRoot mpris2_root; + if ( name.has_prefix (MPRIS_PREFIX) ){ + try { + mpris2_root = Bus.get_proxy_sync ( BusType.SESSION, + name, + MPRIS_MEDIA_PLAYER_PATH ); + } + 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); + } + } + } +}
\ No newline at end of file |