aboutsummaryrefslogtreecommitdiff
path: root/src/mpris2-controller.vala
diff options
context:
space:
mode:
authorKen VanDine <ken.vandine@canonical.com>2011-01-11 14:38:35 -0600
committerKen VanDine <ken.vandine@canonical.com>2011-01-11 14:38:35 -0600
commit13d392dab3f0fcba861bd6607ce17d68990b9228 (patch)
treede176e8a94de984549564aa60a5aa1a20d06cad6 /src/mpris2-controller.vala
parent2565fc2f86a1c81780ca8bcdb1f568b56031fa5a (diff)
downloadayatana-indicator-sound-13d392dab3f0fcba861bd6607ce17d68990b9228.tar.gz
ayatana-indicator-sound-13d392dab3f0fcba861bd6607ce17d68990b9228.tar.bz2
ayatana-indicator-sound-13d392dab3f0fcba861bd6607ce17d68990b9228.zip
Import upstream version 0.5.4
Diffstat (limited to 'src/mpris2-controller.vala')
-rw-r--r--src/mpris2-controller.vala72
1 files changed, 65 insertions, 7 deletions
diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala
index 7f14efe..5f98541 100644
--- a/src/mpris2-controller.vala
+++ b/src/mpris2-controller.vala
@@ -18,11 +18,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using Dbusmenu;
-
[DBus (name = "org.freedesktop.DBus.Properties")]
- public interface FreeDesktopProperties : Object{
- public signal void PropertiesChanged(string source, HashTable<string, Variant?> changed_properties,
- string[] invalid);
+public interface FreeDesktopProperties : Object{
+ public signal void PropertiesChanged (string source, HashTable<string, Variant?> changed_properties,
+ string[] invalid );
}
/*
@@ -33,13 +32,14 @@ public class Mpris2Controller : GLib.Object
{
public MprisRoot mpris2_root {get; construct;}
public MprisPlayer player {get; construct;}
+ public MprisPlaylists playlists {get; construct;}
public FreeDesktopProperties properties_interface {get; construct;}
public PlayerController owner {get; construct;}
-
+
public Mpris2Controller(PlayerController ctrl)
{
- GLib.Object(owner: ctrl);
+ GLib.Object(owner: ctrl);
}
construct{
@@ -50,10 +50,13 @@ public class Mpris2Controller : GLib.Object
this.player = Bus.get_proxy_sync ( BusType.SESSION,
this.owner.dbus_name,
"/org/mpris/MediaPlayer2" );
+ this.playlists = Bus.get_proxy_sync ( BusType.SESSION,
+ this.owner.dbus_name,
+ "/org/mpris/MediaPlayer2" );
this.properties_interface = Bus.get_proxy_sync ( BusType.SESSION,
"org.freedesktop.Properties.PropertiesChanged",
- "/org/mpris/MediaPlayer2" );
+ "/org/mpris/MediaPlayer2" );
this.properties_interface.PropertiesChanged.connect ( property_changed_cb );
}
catch (IOError e) {
@@ -91,8 +94,21 @@ public class Mpris2Controller : GLib.Object
metadata.property_set_bool ( MENUITEM_PROP_VISIBLE,
metadata.populated(MetadataMenuitem.attributes_format()));
}
+ Variant? playlist_v = changed_properties.lookup("ActivePlaylist");
+ if ( playlist_v != null ){
+ this.fetch_active_playlist();
+ //Timeout.add ( 200, fetch_active_playlist );
+ }
}
+ public bool playlists_support_exist()
+ {
+ if (this.playlists == null) return false;
+ uint32? count = this.playlists.PlaylistCount;
+ if ( count == null || count <= 0 ) return false;
+ return true;
+ }
+
private bool ensure_correct_playback_status(){
debug("TEST playback status = %s", this.player.PlaybackStatus);
TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(this.player.PlaybackStatus);
@@ -138,6 +154,8 @@ public class Mpris2Controller : GLib.Object
GLib.HashTable<string, Value?>? cleaned_metadata = this.clean_metadata();
this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata,
MetadataMenuitem.attributes_format());
+ this.fetch_playlists();
+ this.fetch_active_playlist();
}
public void transport_update(TransportMenuitem.action command)
@@ -154,6 +172,32 @@ public class Mpris2Controller : GLib.Object
}
}
+ public void fetch_playlists()
+ {
+ if (this.playlists == null) return;
+
+ PlaylistDetails[] current_playlists = this.playlists.GetPlaylists(0,
+ 10,
+ "Alphabetical",
+ false);
+ if( current_playlists != null ){
+ debug( "Size of the playlist array = %i", current_playlists.length );
+ PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem;
+ playlists_item.update(current_playlists);
+ }
+ return;
+ }
+
+ private void fetch_active_playlist()
+ {
+ if (this.playlists == null && this.playlists.ActivePlaylist.valid == false){
+ warning("Playlists object is null or we don't have an active playlist");
+ }
+ PlaylistsMenuitem playlists_item = this.owner.custom_items[PlayerController.widget_order.PLAYLISTS] as PlaylistsMenuitem;
+ playlists_item.update_active_playlist ( this.playlists.ActivePlaylist.details );
+ }
+
+
public bool connected()
{
return (this.player != null && this.mpris2_root != null);
@@ -165,4 +209,18 @@ public class Mpris2Controller : GLib.Object
this.mpris2_root.Raise.begin();
}
}
+
+ public void activate_playlist (ObjectPath path)
+ {
+ if(this.playlists == null){
+ warning("playlists mpris instance is null !");
+ return;
+ }
+ try{
+ this.playlists.ActivatePlaylist.begin(path);
+ }
+ catch(IOError e){
+ debug("Could not activate playlist %s because %s", (string)path, e.message);
+ }
+ }
} \ No newline at end of file