aboutsummaryrefslogtreecommitdiff
path: root/src/mpris2-watcher.vala
diff options
context:
space:
mode:
authorKen VanDine <ken.vandine@canonical.com>2011-01-11 16:44:38 -0600
committerKen VanDine <ken.vandine@canonical.com>2011-01-11 16:44:38 -0600
commit412bffad64182bfae1e2408b89f9488f0da38481 (patch)
tree1617f11e230dcd76678196fd1fde6b95a1742bcd /src/mpris2-watcher.vala
parent13d392dab3f0fcba861bd6607ce17d68990b9228 (diff)
parent714c7c49776e8a341254a3e4297b465d181206cd (diff)
downloadayatana-indicator-sound-412bffad64182bfae1e2408b89f9488f0da38481.tar.gz
ayatana-indicator-sound-412bffad64182bfae1e2408b89f9488f0da38481.tar.bz2
ayatana-indicator-sound-412bffad64182bfae1e2408b89f9488f0da38481.zip
Import upstream version 0.5.5
Diffstat (limited to 'src/mpris2-watcher.vala')
-rw-r--r--src/mpris2-watcher.vala125
1 files changed, 90 insertions, 35 deletions
diff --git a/src/mpris2-watcher.vala b/src/mpris2-watcher.vala
index 7814975..c20b04b 100644
--- a/src/mpris2-watcher.vala
+++ b/src/mpris2-watcher.vala
@@ -17,30 +17,21 @@ 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 async string[] list_names() throws IOError;
- public abstract signal void name_owner_changed ( string name,
- string old_owner,
- string new_owner );
-}
+using Xml;
public class Mpris2Watcher : GLib.Object
{
- private const string FREEDESKTOP_SERVICE = "org.freedesktop.DBus";
- private const string FREEDESKTOP_OBJECT = "/org/freedesktop/DBus";
- public 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_file_name, string dbus_name );
+ public signal void client_appeared ( string desktop_file_name,
+ string dbus_name,
+ bool use_playlists );
public signal void client_disappeared ( string dbus_name );
public Mpris2Watcher ()
{
}
-
+
construct
{
try {
@@ -57,6 +48,29 @@ public class Mpris2Watcher : GLib.Object
}
}
+ // 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;
+ bool use_playlists = this.supports_playlists ( address );
+ client_appeared (mpris2_root.DesktopEntry, address, use_playlists);
+ }
+ }
+ }
+
private void name_changes_detected ( FreeDesktopObject dbus_obj,
string name,
string previous_owner,
@@ -65,24 +79,25 @@ public class Mpris2Watcher : GLib.Object
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, name);
+ bool use_playlists = this.supports_playlists ( name );
+ client_appeared (mpris2_root.DesktopEntry, name, use_playlists);
}
}
- 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",
@@ -91,26 +106,66 @@ public class Mpris2Watcher : GLib.Object
}
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()
+
+ private bool supports_playlists ( string name )
{
- string[] interfaces;
- try{
- interfaces = yield this.fdesktop_obj.list_names();
+ FreeDesktopIntrospectable introspectable;
+
+ try {
+ /* The dbusproxy flag parameter is needed to ensure Banshee does not
+ blow up. I suspect the issue is that if you
+ try to instantiate a dbus object which does not have any properties
+ associated with it, gdbus will attempt to fetch the properties (this is
+ in the documentation) but the banshee mpris dbus object more than likely
+ causes a crash because it doesn't check for the presence of properties
+ before attempting to access them.
+ */
+ introspectable = Bus.get_proxy_sync ( BusType.SESSION,
+ name,
+ MPRIS_MEDIA_PLAYER_PATH,
+ GLib.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES);
+ var results = introspectable.Introspect();
+ return this.parse_interfaces (results);
}
- catch ( IOError e) {
- warning( "Mpris2watcher could fetch active interfaces at startup: %s",
+ catch (IOError e){
+ warning( "Could not create an introspectable object: %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, address);
+ return false;
+ }
+
+ private bool parse_interfaces( string interface_info )
+ {
+ //parse the document from path
+ bool result = false;
+ 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;
+ }
+ Xml.Attr* attributes = iter->properties; //get the node's name
+ string interface_name = attributes->children->content;
+ debug ( "this dbus object has interface %s ", interface_name );
+ if ( interface_name == MPRIS_PREFIX.concat("Playlists")){
+ result = true;
}
}
- }
+ delete xml_doc;
+ return result;
+ }
} \ No newline at end of file