diff options
author | Ken VanDine <ken.vandine@canonical.com> | 2010-10-07 06:08:19 -0400 |
---|---|---|
committer | Bazaar Package Importer <james.westby@ubuntu.com> | 2010-10-07 06:08:19 -0400 |
commit | 3954f25cb99c9e6042d0f036fda0f2636d76ef93 (patch) | |
tree | 9231dd0bf3208d66db8ea3092d2bb7384efd5d12 /src/music-player-bridge.vala | |
parent | 4b79b2105c0c547667b3be12cbd65b84c1cab19d (diff) | |
parent | 4d97b660ec5a21fb3fa48bdca75dbf77f9288b87 (diff) | |
download | ayatana-indicator-sound-3954f25cb99c9e6042d0f036fda0f2636d76ef93.tar.gz ayatana-indicator-sound-3954f25cb99c9e6042d0f036fda0f2636d76ef93.tar.bz2 ayatana-indicator-sound-3954f25cb99c9e6042d0f036fda0f2636d76ef93.zip |
* New upstream release.
- indicator-sound-service eating CPU on second user login (LP: #581173)
- Right border of transport control is different colour while using
Ambiance (LP: #632774)
- Incorrect ellipsing (LP: #637580)
- always show unmuted at startup (LP: #648238)
- click or enter on metadata widget does not copy contents to
clipboard (LP: #651246)
- Sound menu has two Rhythmbox elements when using
translations (LP: #654140)
Diffstat (limited to 'src/music-player-bridge.vala')
-rw-r--r-- | src/music-player-bridge.vala | 157 |
1 files changed, 69 insertions, 88 deletions
diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 61dfa2e..9ba4ef6 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -35,12 +35,8 @@ public class MusicPlayerBridge : GLib.Object playersDB = new FamiliarPlayersDB(); registered_clients = new HashMap<string, PlayerController> (); listener = Listener.ref_default(); - listener.indicator_added += on_indicator_added; - listener.indicator_removed.connect(on_indicator_removed); - listener.indicator_modified.connect(on_indicator_modified); listener.server_added.connect(on_server_added); listener.server_removed.connect(on_server_removed); - listener.server_count_changed.connect(on_server_count_changed); } private void try_to_add_inactive_familiar_clients(){ @@ -53,13 +49,13 @@ public class MusicPlayerBridge : GLib.Object debug("attempting to make an app info from %s", app); DesktopAppInfo info = new DesktopAppInfo.from_filename(app); - if(info == null){ + + if(info == null){ warning("Could not create a desktopappinfo instance from app: %s", app); continue; } + GLib.AppInfo app_info = info as GLib.AppInfo; - // TODO refactor to remove need for further name refactoring in the player controller - // truncate should not do a down() on the name PlayerController ctrl = new PlayerController(this.root_menu, truncate_player_name(app_info.get_name()), calculate_menu_position(), @@ -67,24 +63,10 @@ public class MusicPlayerBridge : GLib.Object ctrl.app_info = app_info; if(ctrl.app_info == null) warning("for some reason the app info is null"); - - this.registered_clients.set(truncate_player_name(app_info.get_name()), ctrl); + this.registered_clients.set(determine_key(app), ctrl); } } - - private static string truncate_player_name(string app_info_name) - { - string result = app_info_name.down().strip(); - - var tokens = result.split(" "); - - if(tokens.length > 1){ - result = tokens[0]; - } - debug("truncate player name %s", result); - return result; - } - + private int calculate_menu_position() { if(this.registered_clients.size == 0){ @@ -99,42 +81,52 @@ public class MusicPlayerBridge : GLib.Object { debug("MusicPlayerBridge -> on_server_added with value %s", type); if(server_is_not_of_interest(type)) return; - string client_name = type.split(".")[1]; - if (root_menu != null && client_name != null){ - // If we have an instance already for this player, ensure it is switched to active - if(this.registered_clients.keys.contains(client_name)){ - debug("It figured out that it already has an instance for this player already"); - this.registered_clients[client_name].update_state(PlayerController.state.READY); - this.registered_clients[client_name].activate(); - } - else{ - //else init a new one - PlayerController ctrl = new PlayerController(root_menu, - client_name, - calculate_menu_position(), - PlayerController.state.READY); - registered_clients.set(client_name, ctrl); - debug("New Client of name %s has successfully registered with us", client_name); - } - // irregardless check that it has a desktop file if not kick off a request for it - if(this.registered_clients[client_name].app_info == null){ - listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback; - this.listener.server_get_desktop(object, cb, this); - } + if ( this.root_menu != null ){ + listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback; + this.listener.server_get_desktop(object, cb, this); } } + private void desktop_info_callback ( Indicate.ListenerServer server, + owned string path, + void* data ) + { + MusicPlayerBridge bridge = data as MusicPlayerBridge; + AppInfo? app_info = create_app_info(path); + var name = truncate_player_name(app_info.get_name()); + if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){ + debug("About to store desktop file path: %s", path); + bridge.playersDB.insert(path); + PlayerController ctrl = new PlayerController(bridge.root_menu, + name, + bridge.calculate_menu_position(), + PlayerController.state.READY); + ctrl.set("app_info", app_info); + bridge.registered_clients.set(determine_key(path), ctrl); + debug("successfully created appinfo and instance from path and set it on the respective instance"); + } + else{ + var key = determine_key(path); + bridge.registered_clients[key].update_state(PlayerController.state.READY); + bridge.registered_clients[key].activate(); + debug("Ignoring desktop file path callback because the db cache file has it already: %s", path); + } + } + public void on_server_removed(Indicate.ListenerServer object, string type) { debug("MusicPlayerBridge -> on_server_removed with value %s", type); if(server_is_not_of_interest(type)) return; - string client_name = type.split(".")[1]; - if (root_menu != null && client_name != null){ - registered_clients[client_name].hibernate(); - debug("Successively offlined client %s", client_name); + if (root_menu != null){ + var tmp = type.split("."); + debug("attempt to remove %s", tmp[tmp.length-1]); + if(tmp.length > 0){ + registered_clients[tmp[tmp.length - 1]].hibernate(); + debug("Successively offlined client %s", tmp[tmp.length - 1]); + } } } - + private bool server_is_not_of_interest(string type){ if (type == null) return true; if (type.contains("music") == false) { @@ -144,50 +136,12 @@ public class MusicPlayerBridge : GLib.Object return false; } - private void desktop_info_callback(Indicate.ListenerServer server, - owned string path, void* data) - { - MusicPlayerBridge bridge = data as MusicPlayerBridge; - if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){ - debug("About to store desktop file path: %s", path); - bridge.playersDB.insert(path); - AppInfo? app_info = create_app_info(path); - if(app_info != null){ - PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()]; - ctrl.set("app_info", app_info); - debug("successfully created appinfo from path and set it on the respective instance"); - } - } - else{ - debug("Ignoring desktop file path because its either invalid of the db cache file has it already: %s", path); - } - } - public void set_root_menu_item(Dbusmenu.Menuitem menu) { this.root_menu = menu; try_to_add_inactive_familiar_clients(); } - public void on_server_count_changed(Indicate.ListenerServer object, uint i) - { - debug("MusicPlayerBridge-> on_server_count_changed with value %u", i); - } - public void on_indicator_added(ListenerServer object, ListenerIndicator p0) - { - debug("MusicPlayerBridge-> on_indicator_added"); - } - - public void on_indicator_removed(Indicate.ListenerServer object, Indicate.ListenerIndicator p0) - { - debug("MusicPlayerBridge -> on_indicator_removed"); - } - - public void on_indicator_modified(Indicate.ListenerServer object, Indicate.ListenerIndicator p0, string s) - { - debug("MusicPlayerBridge -> indicator_modified with vale %s", s ); - } - public static AppInfo? create_app_info(string path) { DesktopAppInfo info = new DesktopAppInfo.from_filename(path); @@ -199,6 +153,33 @@ public class MusicPlayerBridge : GLib.Object return app_info; } + private static string truncate_player_name(owned string app_info_name) + { + string result = app_info_name.down().strip(); + + var tokens = result.split(" "); + + if(tokens.length > 1){ + result = tokens[0]; + } + debug("truncate player name %s", result); + return result; + } + + private static string? determine_key(owned string path) + { + var tokens = path.split("/"); + if ( tokens.length < 2) return null; + var filename = tokens[tokens.length - 1]; + var result = filename.split(".")[0]; + var temp = result.split("-"); + if (temp.length > 1){ + result = temp[0]; + } + debug("determine key result = %s", result); + return result; + } + } |