aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2012-06-21 17:45:16 +0100
committerConor Curran <conor.curran@canonical.com>2012-06-21 17:45:16 +0100
commitdcde0e28f8cd4d674ba744fad1779f6e9f91eb6e (patch)
tree4619435c7c550a397401751e60503dab36bef8ea
parent5f9a9b8b0ba50dcb5f47233df9e7123ed37501ad (diff)
downloadayatana-indicator-sound-dcde0e28f8cd4d674ba744fad1779f6e9f91eb6e.tar.gz
ayatana-indicator-sound-dcde0e28f8cd4d674ba744fad1779f6e9f91eb6e.tar.bz2
ayatana-indicator-sound-dcde0e28f8cd4d674ba744fad1779f6e9f91eb6e.zip
manually merge of lp:~victored/indicator-sound/lp-1014955
-rw-r--r--data/com.canonical.indicator.sound.gschema.xml7
-rw-r--r--src/music-player-bridge.vala30
-rw-r--r--src/player-controller.vala23
-rw-r--r--src/settings-manager.vala26
4 files changed, 75 insertions, 11 deletions
diff --git a/data/com.canonical.indicator.sound.gschema.xml b/data/com.canonical.indicator.sound.gschema.xml
index a3ec770..86de36a 100644
--- a/data/com.canonical.indicator.sound.gschema.xml
+++ b/data/com.canonical.indicator.sound.gschema.xml
@@ -18,6 +18,13 @@
have at some point appeared in the menU. This allows the menu remember and display offlined applications.
</description>
</key>
+ <key name="preferred-media-players" type="as">
+ <summary>A list of applications that will have player controls visible all the time</summary>
+ <default>[ 'rhythmbox' ]</default>
+ <description>
+ A list of applications that will have player controls visible all the time
+ </description>
+ </key>
<key name="global-mute" type="b">
<default>false</default>
<summary>Initial setting for global mute (mute all) on the menu </summary>
diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala
index 5b9afea..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,6 +184,8 @@ public class MusicPlayerBridge : GLib.Object
}
var mpris_key = determine_key ( desktop );
+ 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,
@@ -171,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 );
diff --git a/src/player-controller.vala b/src/player-controller.vala
index 80a48c3..fd66a8a 100644
--- a/src/player-controller.vala
+++ b/src/player-controller.vala
@@ -40,7 +40,7 @@ public class PlayerController : GLib.Object
}
public int current_state = state.OFFLINE;
-
+
public Dbusmenu.Menuitem root_menu;
public string dbus_name { get; set;}
public ArrayList<PlayerItem> custom_items;
@@ -49,6 +49,7 @@ public class PlayerController : GLib.Object
public int menu_offset { get; set;}
public string icon_name { get; set; }
public bool? use_playlists;
+ public bool is_preferred { get; private set; }
private SpecificItemsManager track_specific_mgr;
private SpecificItemsManager player_specific_mgr;
@@ -58,7 +59,8 @@ public class PlayerController : GLib.Object
string icon_name,
int offset,
bool? use_playlists,
- state initial_state)
+ state initial_state,
+ bool is_preferred)
{
this.use_playlists = use_playlists;
this.root_menu = root;
@@ -68,6 +70,8 @@ public class PlayerController : GLib.Object
this.custom_items = new ArrayList<PlayerItem>();
this.current_state = initial_state;
this.menu_offset = offset;
+ this.is_preferred = is_preferred;
+
this.construct_widgets();
this.establish_mpris_connection();
this.update_layout();
@@ -156,6 +160,11 @@ public class PlayerController : GLib.Object
}
}
+ public void set_as_preferred (bool val) {
+ this.is_preferred = val;
+ this.update_layout();
+ }
+
public void hibernate()
{
update_state(PlayerController.state.OFFLINE);
@@ -175,12 +184,14 @@ public class PlayerController : GLib.Object
metadata_menuitem.should_collapse (true);
playlists_menuitem.root_item.property_set_bool (MENUITEM_PROP_VISIBLE,
false);
- this.custom_items[widget_order.TRANSPORT].property_set_bool (MENUITEM_PROP_VISIBLE,
- this.app_info.get_id() == "rhythmbox.desktop");
+ this.custom_items[widget_order.TRANSPORT].property_set_bool (MENUITEM_PROP_VISIBLE, is_preferred);
return;
}
- metadata_menuitem.should_collapse (!this.custom_items[widget_order.METADATA].populated (MetadataMenuitem.relevant_attributes_for_ui()) );
- if (this.app_info.get_id() == "rhythmbox.desktop"){
+
+ bool should_collapse = !this.custom_items[widget_order.METADATA].populated (MetadataMenuitem.relevant_attributes_for_ui());
+ metadata_menuitem.should_collapse (should_collapse);
+
+ if (is_preferred){
TransportMenuitem transport = this.custom_items[widget_order.TRANSPORT] as TransportMenuitem;
transport.handle_cached_action();
}
diff --git a/src/settings-manager.vala b/src/settings-manager.vala
index d57241e..458ac21 100644
--- a/src/settings-manager.vala
+++ b/src/settings-manager.vala
@@ -22,12 +22,14 @@ public class SettingsManager : GLib.Object
{
private Settings settings;
public signal void blacklist_updates ( string[] new_blacklist );
+ public signal void preferred_updates (Gee.ArrayList<string> new_preferred);
public SettingsManager ( ){
}
construct{
this.settings = new Settings ("com.canonical.indicator.sound");
- this.settings.changed["blacklisted-media-players"].connect (on_blacklist_event);
+ this.settings.changed["blacklisted-media-players"].connect (on_blacklist_event);
+ this.settings.changed["preferred-media-players"].connect (on_preferred_event);
}
public string[] fetch_blacklist()
@@ -35,9 +37,24 @@ public class SettingsManager : GLib.Object
return this.settings.get_strv ("blacklisted-media-players");
}
+ public ArrayList<string> fetch_preferred()
+ {
+ var list = new ArrayList<string>();
+
+ var preferred = this.settings.get_strv ("preferred-media-players");
+ var interested = fetch_interested ();
+
+ foreach (var s in preferred) {
+ if (!(s in list) && interested.contains (s))
+ list.add (s);
+ }
+
+ return list;
+ }
+
public ArrayList<string> fetch_interested()
{
- var blacklisted = this.settings.get_strv ("blacklisted-media-players");
+ var blacklisted = fetch_blacklist ();
var interested = this.settings.get_strv ("interested-media-players");
var list = new ArrayList<string>();
foreach(var s in interested){
@@ -91,6 +108,11 @@ public class SettingsManager : GLib.Object
this.blacklist_updates(this.settings.get_strv ("blacklisted-media-players"));
}
+ private void on_preferred_event()
+ {
+ this.preferred_updates (this.fetch_preferred());
+ }
+
// Convenient debug method inorder to provide visability over
// the contents of both interested and blacklisted containers in its gsettings
/**