diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-11-05 15:19:52 +0000 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-11-05 15:19:52 +0000 |
commit | 6c1c1d706fa7e8670ce3fb46329647e20a307911 (patch) | |
tree | ff91de689c5586b41e99db68d540cb7f328e74dd | |
parent | f6c1abd8b39794057044f2ad9a567624ae4e9cf3 (diff) | |
download | ayatana-indicator-sound-6c1c1d706fa7e8670ce3fb46329647e20a307911.tar.gz ayatana-indicator-sound-6c1c1d706fa7e8670ce3fb46329647e20a307911.tar.bz2 ayatana-indicator-sound-6c1c1d706fa7e8670ce3fb46329647e20a307911.zip |
refactored the constructor for the player controller enforcing app_info pattern
-rw-r--r-- | src/music-player-bridge.vala | 56 | ||||
-rw-r--r-- | src/player-controller.vala | 19 |
2 files changed, 39 insertions, 36 deletions
diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 57f5636..4bb0e6b 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -56,15 +56,13 @@ public class MusicPlayerBridge : GLib.Object } GLib.AppInfo app_info = info as GLib.AppInfo; + var mpris_key = determine_key(app); PlayerController ctrl = new PlayerController(this.root_menu, - truncate_player_name(app_info.get_name()), - determine_key(app), + app_info, + mpris_key, calculate_menu_position(), PlayerController.state.OFFLINE); - ctrl.app_info = app_info; - if(ctrl.app_info == null) - warning("for some reason the app info is null"); - this.registered_clients.set(determine_key(app), ctrl); + this.registered_clients.set(mpris_key, ctrl); } } @@ -94,24 +92,27 @@ public class MusicPlayerBridge : GLib.Object { 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); + if ( app_info == null ){ + warning ( "Could not create app_info for path %s \n Getting out of here ", path); + return; + } + + var mpris_key = determine_key(path); + + if(bridge.playersDB.already_familiar(path) == false){ + debug("New client has registered that we have seen before: %s", path); bridge.playersDB.insert(path); - PlayerController ctrl = new PlayerController(bridge.root_menu, - name, - determine_key(path), - 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"); + PlayerController ctrl = new PlayerController ( bridge.root_menu, + app_info, + mpris_key, + bridge.calculate_menu_position(), + PlayerController.state.READY ); + bridge.registered_clients.set(mpris_key, ctrl); } 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); + bridge.registered_clients[mpris_key].update_state(PlayerController.state.READY); + bridge.registered_clients[mpris_key].activate(); + debug("Ignoring desktop file path callback because the db cache file has it already: %s \n", path); } } @@ -155,19 +156,6 @@ 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("/"); diff --git a/src/player-controller.vala b/src/player-controller.vala index f9cbe71..cc2e4e1 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -51,13 +51,14 @@ public class PlayerController : GLib.Object public int menu_offset { get; set;} public PlayerController(Dbusmenu.Menuitem root, - string client_name, + GLib.AppInfo app, string mpris_name, int offset, state initial_state) { this.root_menu = root; - this.name = format_client_name(client_name.strip()); + this.app_info = app; + this.name = format_player_name(this.app_info.get_name()); this.mpris_name = mpris_name; this.custom_items = new ArrayList<PlayerItem>(); this.current_state = initial_state; @@ -170,6 +171,20 @@ public class PlayerController : GLib.Object return formatted; } + private static string format_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]; + } + if(result.length > 1){ + result = result.up(1).concat(result.slice(1, result.length)); + debug("PlayerController->format_player_name - : %s", result); + } + return result; + } + // Temporarily we will need to handle to different mpris implemenations // Do it for now - a couple of weeks should see this messy carry on out of // the codebase. |