Merge lp:~cjcurran/indicator-sound/translation-app-name-bug into lp:indicator-sound/sound-menu-v2

Proposed by Conor Curran
Status: Merged
Approved by: Gord Allott
Approved revision: 149
Merged at revision: 146
Proposed branch: lp:~cjcurran/indicator-sound/translation-app-name-bug
Merge into: lp:indicator-sound/sound-menu-v2
Diff against target: 256 lines (+72/-94)
3 files modified
src/mpris2-controller.vala (+1/-4)
src/music-player-bridge.vala (+69/-88)
src/player-controller.vala (+2/-2)
To merge this branch: bzr merge lp:~cjcurran/indicator-sound/translation-app-name-bug
Reviewer Review Type Date Requested Status
Cody Russell (community) Approve
Review via email: mp+37839@code.launchpad.net

Description of the change

Fixes the bug attached.

To post a comment you must log in.
150. By Conor Curran

tidied silly logic

Revision history for this message
Cody Russell (bratsche) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/mpris2-controller.vala'
2--- src/mpris2-controller.vala 2010-09-15 11:30:06 +0000
3+++ src/mpris2-controller.vala 2010-10-07 13:23:40 +0000
4@@ -135,10 +135,7 @@
5 return changed_updates;
6 }
7
8- private TransportMenuitem.state determine_play_state(string status){
9- if(status == null)
10- return TransportMenuitem.state.PAUSED;
11-
12+ private TransportMenuitem.state determine_play_state(string status){
13 if(status != null && status == "Playing"){
14 return TransportMenuitem.state.PLAYING;
15 }
16
17=== modified file 'src/music-player-bridge.vala'
18--- src/music-player-bridge.vala 2010-09-10 11:28:57 +0000
19+++ src/music-player-bridge.vala 2010-10-07 13:23:40 +0000
20@@ -35,12 +35,8 @@
21 playersDB = new FamiliarPlayersDB();
22 registered_clients = new HashMap<string, PlayerController> ();
23 listener = Listener.ref_default();
24- listener.indicator_added += on_indicator_added;
25- listener.indicator_removed.connect(on_indicator_removed);
26- listener.indicator_modified.connect(on_indicator_modified);
27 listener.server_added.connect(on_server_added);
28 listener.server_removed.connect(on_server_removed);
29- listener.server_count_changed.connect(on_server_count_changed);
30 }
31
32 private void try_to_add_inactive_familiar_clients(){
33@@ -53,13 +49,13 @@
34 debug("attempting to make an app info from %s", app);
35
36 DesktopAppInfo info = new DesktopAppInfo.from_filename(app);
37- if(info == null){
38+
39+ if(info == null){
40 warning("Could not create a desktopappinfo instance from app: %s", app);
41 continue;
42 }
43+
44 GLib.AppInfo app_info = info as GLib.AppInfo;
45- // TODO refactor to remove need for further name refactoring in the player controller
46- // truncate should not do a down() on the name
47 PlayerController ctrl = new PlayerController(this.root_menu,
48 truncate_player_name(app_info.get_name()),
49 calculate_menu_position(),
50@@ -67,24 +63,10 @@
51 ctrl.app_info = app_info;
52 if(ctrl.app_info == null)
53 warning("for some reason the app info is null");
54-
55- this.registered_clients.set(truncate_player_name(app_info.get_name()), ctrl);
56+ this.registered_clients.set(determine_key(app), ctrl);
57 }
58 }
59-
60- private static string truncate_player_name(string app_info_name)
61- {
62- string result = app_info_name.down().strip();
63-
64- var tokens = result.split(" ");
65-
66- if(tokens.length > 1){
67- result = tokens[0];
68- }
69- debug("truncate player name %s", result);
70- return result;
71- }
72-
73+
74 private int calculate_menu_position()
75 {
76 if(this.registered_clients.size == 0){
77@@ -99,42 +81,52 @@
78 {
79 debug("MusicPlayerBridge -> on_server_added with value %s", type);
80 if(server_is_not_of_interest(type)) return;
81- string client_name = type.split(".")[1];
82- if (root_menu != null && client_name != null){
83- // If we have an instance already for this player, ensure it is switched to active
84- if(this.registered_clients.keys.contains(client_name)){
85- debug("It figured out that it already has an instance for this player already");
86- this.registered_clients[client_name].update_state(PlayerController.state.READY);
87- this.registered_clients[client_name].activate();
88- }
89- else{
90- //else init a new one
91- PlayerController ctrl = new PlayerController(root_menu,
92- client_name,
93- calculate_menu_position(),
94- PlayerController.state.READY);
95- registered_clients.set(client_name, ctrl);
96- debug("New Client of name %s has successfully registered with us", client_name);
97- }
98- // irregardless check that it has a desktop file if not kick off a request for it
99- if(this.registered_clients[client_name].app_info == null){
100- listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback;
101- this.listener.server_get_desktop(object, cb, this);
102- }
103+ if ( this.root_menu != null ){
104+ listener_get_server_property_cb cb = (listener_get_server_property_cb)desktop_info_callback;
105+ this.listener.server_get_desktop(object, cb, this);
106 }
107 }
108
109+ private void desktop_info_callback ( Indicate.ListenerServer server,
110+ owned string path,
111+ void* data )
112+ {
113+ MusicPlayerBridge bridge = data as MusicPlayerBridge;
114+ AppInfo? app_info = create_app_info(path);
115+ var name = truncate_player_name(app_info.get_name());
116+ if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){
117+ debug("About to store desktop file path: %s", path);
118+ bridge.playersDB.insert(path);
119+ PlayerController ctrl = new PlayerController(bridge.root_menu,
120+ name,
121+ bridge.calculate_menu_position(),
122+ PlayerController.state.READY);
123+ ctrl.set("app_info", app_info);
124+ bridge.registered_clients.set(determine_key(path), ctrl);
125+ debug("successfully created appinfo and instance from path and set it on the respective instance");
126+ }
127+ else{
128+ var key = determine_key(path);
129+ bridge.registered_clients[key].update_state(PlayerController.state.READY);
130+ bridge.registered_clients[key].activate();
131+ debug("Ignoring desktop file path callback because the db cache file has it already: %s", path);
132+ }
133+ }
134+
135 public void on_server_removed(Indicate.ListenerServer object, string type)
136 {
137 debug("MusicPlayerBridge -> on_server_removed with value %s", type);
138 if(server_is_not_of_interest(type)) return;
139- string client_name = type.split(".")[1];
140- if (root_menu != null && client_name != null){
141- registered_clients[client_name].hibernate();
142- debug("Successively offlined client %s", client_name);
143+ if (root_menu != null){
144+ var tmp = type.split(".");
145+ debug("attempt to remove %s", tmp[tmp.length-1]);
146+ if(tmp.length > 0){
147+ registered_clients[tmp[tmp.length - 1]].hibernate();
148+ debug("Successively offlined client %s", tmp[tmp.length - 1]);
149+ }
150 }
151 }
152-
153+
154 private bool server_is_not_of_interest(string type){
155 if (type == null) return true;
156 if (type.contains("music") == false) {
157@@ -144,50 +136,12 @@
158 return false;
159 }
160
161- private void desktop_info_callback(Indicate.ListenerServer server,
162- owned string path, void* data)
163- {
164- MusicPlayerBridge bridge = data as MusicPlayerBridge;
165- if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){
166- debug("About to store desktop file path: %s", path);
167- bridge.playersDB.insert(path);
168- AppInfo? app_info = create_app_info(path);
169- if(app_info != null){
170- PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()];
171- ctrl.set("app_info", app_info);
172- debug("successfully created appinfo from path and set it on the respective instance");
173- }
174- }
175- else{
176- debug("Ignoring desktop file path because its either invalid of the db cache file has it already: %s", path);
177- }
178- }
179-
180 public void set_root_menu_item(Dbusmenu.Menuitem menu)
181 {
182 this.root_menu = menu;
183 try_to_add_inactive_familiar_clients();
184 }
185
186- public void on_server_count_changed(Indicate.ListenerServer object, uint i)
187- {
188- debug("MusicPlayerBridge-> on_server_count_changed with value %u", i);
189- }
190- public void on_indicator_added(ListenerServer object, ListenerIndicator p0)
191- {
192- debug("MusicPlayerBridge-> on_indicator_added");
193- }
194-
195- public void on_indicator_removed(Indicate.ListenerServer object, Indicate.ListenerIndicator p0)
196- {
197- debug("MusicPlayerBridge -> on_indicator_removed");
198- }
199-
200- public void on_indicator_modified(Indicate.ListenerServer object, Indicate.ListenerIndicator p0, string s)
201- {
202- debug("MusicPlayerBridge -> indicator_modified with vale %s", s );
203- }
204-
205 public static AppInfo? create_app_info(string path)
206 {
207 DesktopAppInfo info = new DesktopAppInfo.from_filename(path);
208@@ -199,6 +153,33 @@
209 return app_info;
210 }
211
212+ private static string truncate_player_name(owned string app_info_name)
213+ {
214+ string result = app_info_name.down().strip();
215+
216+ var tokens = result.split(" ");
217+
218+ if(tokens.length > 1){
219+ result = tokens[0];
220+ }
221+ debug("truncate player name %s", result);
222+ return result;
223+ }
224+
225+ private static string? determine_key(owned string path)
226+ {
227+ var tokens = path.split("/");
228+ if ( tokens.length < 2) return null;
229+ var filename = tokens[tokens.length - 1];
230+ var result = filename.split(".")[0];
231+ var temp = result.split("-");
232+ if (temp.length > 1){
233+ result = temp[0];
234+ }
235+ debug("determine key result = %s", result);
236+ return result;
237+ }
238+
239 }
240
241
242
243=== modified file 'src/player-controller.vala'
244--- src/player-controller.vala 2010-09-02 22:21:00 +0000
245+++ src/player-controller.vala 2010-10-07 13:23:40 +0000
246@@ -160,8 +160,8 @@
247 private static string format_client_name(string client_name)
248 {
249 string formatted = client_name;
250- if(formatted.len() > 1){
251- formatted = client_name.up(1).concat(client_name.slice(1, client_name.len()));
252+ if(formatted.length > 1){
253+ formatted = client_name.up(1).concat(client_name.slice(1, client_name.length));
254 debug("PlayerController->format_client_name - : %s", formatted);
255 }
256 return formatted;

Subscribers

People subscribed via source and target branches

to all changes: