Conor Curran has proposed merging lp:~cjcurran/indicator-sound/translation-app-name-bug into lp:indicator-sound.
Requested reviews: Indicator Applet Developers (indicator-applet-developers) Related bugs: #654140 Sound menu has two Rhythmbox elements when using translations https://bugs.launchpad.net/bugs/654140 Fixes the bug attached. -- https://code.launchpad.net/~cjcurran/indicator-sound/translation-app-name-bug/+merge/37839 Your team ayatana-commits is subscribed to branch lp:indicator-sound.
=== modified file 'src/music-player-bridge.vala' --- src/music-player-bridge.vala 2010-09-10 11:28:57 +0000 +++ src/music-player-bridge.vala 2010-10-07 11:12:52 +0000 @@ -35,12 +35,8 @@ 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 @@ 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 @@ 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 @@ { 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 @@ 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 @@ 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; + } + } === modified file 'src/player-controller.vala' --- src/player-controller.vala 2010-09-02 22:21:00 +0000 +++ src/player-controller.vala 2010-10-07 11:12:52 +0000 @@ -160,8 +160,8 @@ private static string format_client_name(string client_name) { string formatted = client_name; - if(formatted.len() > 1){ - formatted = client_name.up(1).concat(client_name.slice(1, client_name.len())); + if(formatted.length > 1){ + formatted = client_name.up(1).concat(client_name.slice(1, client_name.length)); debug("PlayerController->format_client_name - : %s", formatted); } return formatted;
_______________________________________________ Mailing list: https://launchpad.net/~ayatana-commits Post to : ayatana-commits@lists.launchpad.net Unsubscribe : https://launchpad.net/~ayatana-commits More help : https://help.launchpad.net/ListHelp