From 781447c5a0d82c625ddd8e6fb2ab01eae720d330 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 29 Oct 2013 17:16:45 -0700 Subject: Rename MediaPlayer.launch() ot activate() --- src/media-player.vala | 8 ++++---- src/service.vala | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/media-player.vala b/src/media-player.vala index 7326708..7e0d2a7 100644 --- a/src/media-player.vala +++ b/src/media-player.vala @@ -118,17 +118,17 @@ public class MediaPlayer: Object { } /** - * Launch the associated media player. + * Activate the associated media player. * * Note: this will _not_ call attach(), because it doesn't know on which dbus-name the player will appear. * Use attach() to attach this object to a running instance of the player. */ - public void launch () { + public void activate () { try { this.appinfo.launch (null, null); } catch (Error e) { - warning ("unable to launch %s: %s", appinfo.get_name (), e.message); + warning ("unable to activate %s: %s", appinfo.get_name (), e.message); } if (this.proxy == null) @@ -144,7 +144,7 @@ public class MediaPlayer: Object { } else if (this.state != "Launching") { this.play_when_attached = true; - this.launch (); + this.activate (); } } diff --git a/src/service.vala b/src/service.vala index 7dc6824..9a82e8b 100644 --- a/src/service.vala +++ b/src/service.vala @@ -290,7 +290,7 @@ public class IndicatorSound.Service { this.menus.@foreach ( (profile, menu) => menu.add_player (player)); SimpleAction action = new SimpleAction.stateful (player.id, null, this.action_state_for_player (player)); - action.activate.connect ( () => { player.launch (); }); + action.activate.connect ( () => { player.activate (); }); this.actions.add_action (action); var play_action = new SimpleAction.stateful ("play." + player.id, null, player.state); -- cgit v1.2.3 From aaa6d3919ad7cfd3eebe24f387b52da2526edf7f Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 29 Oct 2013 18:33:46 -0700 Subject: Call Raise() when activating a player menu item --- src/CMakeLists.txt | 2 ++ src/media-player-list.vala | 2 +- src/media-player.vala | 15 ++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 572befd..c11ec51 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,6 +32,7 @@ vala_add(indicator-sound-service volume-control media-player media-player-list + mpris2-interfaces ) vala_add(indicator-sound-service main.vala @@ -62,6 +63,7 @@ vala_add(indicator-sound-service sound-menu.vala DEPENDS media-player + mpris2-interfaces ) vala_finish(indicator-sound-service diff --git a/src/media-player-list.vala b/src/media-player-list.vala index 62badc2..75c7bb4 100644 --- a/src/media-player-list.vala +++ b/src/media-player-list.vala @@ -118,7 +118,7 @@ public class MediaPlayerList { var player = this.insert (mpris2_root.DesktopEntry); if (player != null) - player.attach (name); + player.attach (mpris2_root, name); } catch (Error e) { warning ("unable to create mpris proxy for '%s': %s", name, e.message); diff --git a/src/media-player.vala b/src/media-player.vala index 7e0d2a7..49fe387 100644 --- a/src/media-player.vala +++ b/src/media-player.vala @@ -94,9 +94,10 @@ public class MediaPlayer: Object { * * This method does not block. If it is successful, "is-running" will be set to %TRUE. */ - public void attach (string dbus_name) { + public void attach (MprisRoot root, string dbus_name) { return_if_fail (this._dbus_name == null && this.proxy == null); + this.root = root; this._dbus_name = dbus_name; Bus.get_proxy.begin (BusType.SESSION, dbus_name, "/org/mpris/MediaPlayer2", DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, got_proxy); @@ -125,14 +126,17 @@ public class MediaPlayer: Object { */ public void activate () { try { - this.appinfo.launch (null, null); + if (this.proxy == null) { + this.appinfo.launch (null, null); + this.state = "Launching"; + } + else if (this.root != null && this.root.CanRaise) { + this.root.Raise (); + } } catch (Error e) { warning ("unable to activate %s: %s", appinfo.get_name (), e.message); } - - if (this.proxy == null) - this.state = "Launching"; } /** @@ -188,6 +192,7 @@ public class MediaPlayer: Object { MprisPlaylists ?playlists_proxy; string _dbus_name; bool play_when_attached = false; + MprisRoot root; PlaylistDetails[] playlists = null; void got_proxy (Object? obj, AsyncResult res) { -- cgit v1.2.3 From 9fb9f5077869c6e30d305ec7cb21d0129567e10e Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 30 Oct 2013 07:48:46 -0700 Subject: Make player menu item insensitive when player can't be raised --- src/media-player.vala | 10 ++++++++++ src/service.vala | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/media-player.vala b/src/media-player.vala index 49fe387..bdcea35 100644 --- a/src/media-player.vala +++ b/src/media-player.vala @@ -84,6 +84,12 @@ public class MediaPlayer: Object { get; set; } + public bool can_raise { + get { + return this.root != null ? this.root.CanRaise : true; + } + } + public signal void playlists_changed (); /** @@ -98,6 +104,8 @@ public class MediaPlayer: Object { return_if_fail (this._dbus_name == null && this.proxy == null); this.root = root; + this.notify_property ("can-raise"); + this._dbus_name = dbus_name; Bus.get_proxy.begin (BusType.SESSION, dbus_name, "/org/mpris/MediaPlayer2", DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, got_proxy); @@ -111,9 +119,11 @@ public class MediaPlayer: Object { * See also: attach() */ public void detach () { + this.root = null; this.proxy = null; this._dbus_name = null; this.notify_property ("is-running"); + this.notify_property ("can-raise"); this.state = "Paused"; this.current_track = null; } diff --git a/src/service.vala b/src/service.vala index 9a82e8b..14d4893 100644 --- a/src/service.vala +++ b/src/service.vala @@ -266,8 +266,10 @@ public class IndicatorSound.Service { bool update_player_actions () { foreach (var player in this.players) { SimpleAction? action = this.actions.lookup_action (player.id) as SimpleAction; - if (action != null) + if (action != null) { action.set_state (this.action_state_for_player (player)); + action.set_enabled (player.can_raise); + } } this.player_action_update_id = 0; -- cgit v1.2.3