diff options
Diffstat (limited to 'src/mpris2-watcher.vala')
-rw-r--r-- | src/mpris2-watcher.vala | 70 |
1 files changed, 65 insertions, 5 deletions
diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala index 7814975..f572ab7 100644 --- a/src/mpris2-watcher.vala +++ b/src/mpris2-watcher.vala @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ +using Xml; + [DBus (name = "org.freedesktop.DBus")] public interface FreeDesktopObject: Object { public abstract async string[] list_names() throws IOError; @@ -25,6 +27,16 @@ public interface FreeDesktopObject: Object { string new_owner ); } +[DBus (name = "org.freedesktop.DBus.Introspectable")] +public interface FreeDesktopIntrospectable: Object { + public abstract string introspect() throws IOError; +} + +public errordomain XmlError { + FILE_NOT_FOUND, + XML_DOCUMENT_EMPTY +} + public class Mpris2Watcher : GLib.Object { private const string FREEDESKTOP_SERVICE = "org.freedesktop.DBus"; @@ -33,14 +45,14 @@ public class Mpris2Watcher : GLib.Object private const string MPRIS_MEDIA_PLAYER_PATH = "/org/mpris/MediaPlayer2"; FreeDesktopObject fdesktop_obj; - + public signal void client_appeared ( string desktop_file_name, string dbus_name ); public signal void client_disappeared ( string dbus_name ); public Mpris2Watcher () { } - + construct { try { @@ -76,21 +88,69 @@ public class Mpris2Watcher : GLib.Object } } - private MprisRoot? create_mpris_root(string name){ + 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, - name, - MPRIS_MEDIA_PLAYER_PATH ); + name, + MPRIS_MEDIA_PLAYER_PATH ); } catch (IOError e){ warning( "Mpris2watcher could not create a root interface: %s", e.message ); } } + this.supports_playlists(name); return mpris2_root; } + + private bool supports_playlists ( string name ) + { + FreeDesktopIntrospectable introspectable; + try { + introspectable = Bus.get_proxy_sync ( BusType.SESSION, + name, + MPRIS_MEDIA_PLAYER_PATH ); + var results = introspectable.introspect(); + return this.parse_interfaces (results); + } + catch (IOError e){ + warning( "Could not create an introspectable object: %s", + e.message ); + } + return false; + } + + private bool parse_interfaces( string interface_info ) + { + //parse the document from path + debug ("attempting to parse %s", interface_info); + Xml.Doc* xml_doc = Parser.parse_doc (interface_info); + if (xml_doc == null) { + warning ("Mpris2Watcher - parse-interfaces - failed to instantiate xml doc"); + return false; + } + //get the root node. notice the dereferencing operator -> instead of . + Xml.Node* root_node = xml_doc->get_root_element (); + if (root_node == null) { + //free the document manually before throwing because the garbage collector can't work on pointers + delete xml_doc; + warning ("Mpris2Watcher - the interface info xml is empty"); + return false; + } + + //let's parse those nodes + for (Xml.Node* iter = root_node->children; iter != null; iter = iter->next) { + //spaces btw. tags are also nodes, discard them + if (iter->type != ElementType.ELEMENT_NODE) + continue; + string node_name = iter->name; //get the node's name + debug ( "this dbus object has interface %s ", node_name ); + } + delete xml_doc; + return false; + } // At startup check to see if there are clients up that we are interested in // More relevant for development and daemon's like mpd. |