aboutsummaryrefslogtreecommitdiff
path: root/src/music-player-bridge.vala
diff options
context:
space:
mode:
Diffstat (limited to 'src/music-player-bridge.vala')
-rw-r--r--src/music-player-bridge.vala47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala
index 18f1c40..606b129 100644
--- a/src/music-player-bridge.vala
+++ b/src/music-player-bridge.vala
@@ -40,6 +40,7 @@ public class MusicPlayerBridge : GLib.Object
this.file_monitors = new HashMap<string, string> ();
this.settings_manager = new SettingsManager();
this.settings_manager.blacklist_updates.connect ( this.on_blacklist_update );
+ this.settings_manager.preferred_updates.connect ( this.on_preferred_update );
}
private void on_blacklist_update ( string[] blacklist )
@@ -58,8 +59,26 @@ public class MusicPlayerBridge : GLib.Object
this.watcher.check_for_active_clients.begin();
}
+ private void on_preferred_update ( Gee.ArrayList<string> preferred )
+ {
+ debug ("Preferred players update. Clearing current preferred players...");
+
+ foreach (var player_controller in this.registered_clients.values) {
+ player_controller.set_as_preferred (false);
+ }
+
+ foreach (var s in preferred) {
+ string key = this.determine_key (s);
+ if (this.registered_clients.has_key (key)) {
+ debug ("Setting %s as preferred player", key);
+ this.registered_clients[key].set_as_preferred (true);
+ }
+ }
+ }
+
private void try_to_add_inactive_familiar_clients()
{
+ var preferred_players = this.settings_manager.fetch_preferred ();
foreach ( string desktop in this.settings_manager.fetch_interested()){
debug ( "interested client found : %s", desktop );
AppInfo? app_info = create_app_info ( desktop.concat( ".desktop" ) );
@@ -68,14 +87,16 @@ public class MusicPlayerBridge : GLib.Object
desktop );
continue;
}
- var mpris_key = determine_key ( desktop );
+ bool is_preferred = desktop in preferred_players;
PlayerController ctrl = new PlayerController ( this.root_menu,
app_info,
null,
this.fetch_icon_name(desktop),
calculate_menu_position(),
null,
- PlayerController.state.OFFLINE );
+ PlayerController.state.OFFLINE,
+ is_preferred );
+ var mpris_key = determine_key ( desktop );
this.registered_clients.set(mpris_key, ctrl);
this.establish_file_monitoring (app_info, mpris_key);
}
@@ -163,7 +184,8 @@ public class MusicPlayerBridge : GLib.Object
}
var mpris_key = determine_key ( desktop );
- // Are we sure clients will appear like this with the new registration method in place.
+ bool is_preferred = desktop in this.settings_manager.fetch_preferred ();
+
if ( this.registered_clients.has_key (mpris_key) == false ){
debug("New client has registered that we have not seen before: %s", dbus_name );
PlayerController ctrl = new PlayerController ( this.root_menu,
@@ -172,7 +194,8 @@ public class MusicPlayerBridge : GLib.Object
this.fetch_icon_name(desktop),
this.calculate_menu_position(),
use_playlists,
- PlayerController.state.READY );
+ PlayerController.state.READY,
+ is_preferred);
this.registered_clients.set ( mpris_key, ctrl );
debug ( "Have not seen this %s before, new controller created.", desktop );
this.settings_manager.add_interested ( desktop );
@@ -189,14 +212,14 @@ public class MusicPlayerBridge : GLib.Object
public void client_has_vanished ( string mpris_root_interface )
{
- debug("MusicPlayerBridge -> client with dbus interface %s has vanished",
+ debug("\n MusicPlayerBridge -> client with dbus interface %s has vanished",
mpris_root_interface );
if (root_menu != null){
- debug("attempt to remove %s", mpris_root_interface);
+ debug("\n attempt to remove %s", mpris_root_interface);
var mpris_key = determine_key ( mpris_root_interface );
if ( mpris_key != null && this.registered_clients.has_key(mpris_key)){
registered_clients[mpris_key].hibernate();
- debug("Successively offlined client %s", mpris_key);
+ debug("\n Successively offlined client %s", mpris_key);
}
}
}
@@ -279,15 +302,21 @@ public class MusicPlayerBridge : GLib.Object
*/
private static string? determine_key(owned string desktop_or_interface)
{
+ // handle the special case of amarok, (kde4-amarok desktop file name)
+ if (desktop_or_interface.contains("amarok")){
+ return "amarok";
+ }
+
var result = desktop_or_interface;
+
var tokens = desktop_or_interface.split( "." );
if (tokens != null && tokens.length > 1){
result = tokens[tokens.length - 1];
- }
+ }
var temp = result.split("-");
if (temp != null && temp.length > 1){
result = temp[0];
- }
+ }
return result;
}