Merge lp:~aacid/indicator-sound/kill_determine_key into lp:indicator-sound/12.10

Proposed by Albert Astals Cid
Status: Merged
Approved by: Conor Curran
Approved revision: 334
Merged at revision: 335
Proposed branch: lp:~aacid/indicator-sound/kill_determine_key
Merge into: lp:indicator-sound/12.10
Diff against target: 131 lines (+18/-40)
1 file modified
src/music-player-bridge.vala (+18/-40)
To merge this branch: bzr merge lp:~aacid/indicator-sound/kill_determine_key
Reviewer Review Type Date Requested Status
Conor Curran (community) Approve
jenkins (community) continuous-integration Approve
Review via email: mp+128650@code.launchpad.net

Commit message

Remove the determine_key function

As documented it did not work very well and it is not really needed since
they only time we need to map from dbus interface to desktop name is
when the program goes away that means we had previously seen it appearing
thus we can have a map with the dbus interface -> destkop name mapping

Description of the change

Remove the determine_key function

As documented it did not work very well and it is not really needed since
they only time we need to map from dbus interface to desktop name is
when the program goes away that means we had previously seen it appearing
thus we can have a map with the dbus interface -> destkop name mapping

To post a comment you must log in.
Revision history for this message
jenkins (martin-mrazik+qa) wrote :
review: Approve (continuous-integration)
Revision history for this message
Conor Curran (cjcurran) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/music-player-bridge.vala'
--- src/music-player-bridge.vala 2012-06-21 16:45:16 +0000
+++ src/music-player-bridge.vala 2012-10-09 09:09:25 +0000
@@ -29,6 +29,7 @@
29 private Dbusmenu.Menuitem root_menu;29 private Dbusmenu.Menuitem root_menu;
30 private HashMap<string, PlayerController> registered_clients;30 private HashMap<string, PlayerController> registered_clients;
31 private HashMap<string, string> file_monitors;31 private HashMap<string, string> file_monitors;
32 private HashMap<string, string> mpris_to_desktop;
32 private Mpris2Watcher watcher;33 private Mpris2Watcher watcher;
3334
34 public MusicPlayerBridge()35 public MusicPlayerBridge()
@@ -38,6 +39,7 @@
38 construct{39 construct{
39 this.registered_clients = new HashMap<string, PlayerController> ();40 this.registered_clients = new HashMap<string, PlayerController> ();
40 this.file_monitors = new HashMap<string, string> ();41 this.file_monitors = new HashMap<string, string> ();
42 this.mpris_to_desktop = new HashMap<string, string> ();
41 this.settings_manager = new SettingsManager();43 this.settings_manager = new SettingsManager();
42 this.settings_manager.blacklist_updates.connect ( this.on_blacklist_update );44 this.settings_manager.blacklist_updates.connect ( this.on_blacklist_update );
43 this.settings_manager.preferred_updates.connect ( this.on_preferred_update );45 this.settings_manager.preferred_updates.connect ( this.on_preferred_update );
@@ -47,8 +49,8 @@
47 {49 {
48 debug("some blacklist update");50 debug("some blacklist update");
4951
50 foreach(var s in blacklist){52 foreach(var desktop_id in blacklist){
51 string key = this.determine_key (s);53 string key = desktop_id;
52 if (this.registered_clients.has_key (key)){54 if (this.registered_clients.has_key (key)){
53 debug ("Apparently %s is now blacklisted - remove thy self", key);55 debug ("Apparently %s is now blacklisted - remove thy self", key);
54 this.registered_clients[key].remove_from_menu();56 this.registered_clients[key].remove_from_menu();
@@ -67,8 +69,8 @@
67 player_controller.set_as_preferred (false);69 player_controller.set_as_preferred (false);
68 }70 }
6971
70 foreach (var s in preferred) {72 foreach (var desktop_id in preferred) {
71 string key = this.determine_key (s);73 string key = desktop_id;
72 if (this.registered_clients.has_key (key)) {74 if (this.registered_clients.has_key (key)) {
73 debug ("Setting %s as preferred player", key);75 debug ("Setting %s as preferred player", key);
74 this.registered_clients[key].set_as_preferred (true);76 this.registered_clients[key].set_as_preferred (true);
@@ -96,7 +98,7 @@
96 null,98 null,
97 PlayerController.state.OFFLINE,99 PlayerController.state.OFFLINE,
98 is_preferred );100 is_preferred );
99 var mpris_key = determine_key ( desktop );101 var mpris_key = desktop;
100 this.registered_clients.set(mpris_key, ctrl); 102 this.registered_clients.set(mpris_key, ctrl);
101 this.establish_file_monitoring (app_info, mpris_key);103 this.establish_file_monitoring (app_info, mpris_key);
102 }104 }
@@ -183,9 +185,10 @@
183 return;185 return;
184 }186 }
185 187
186 var mpris_key = determine_key ( desktop );188 var mpris_key = desktop;
187 bool is_preferred = desktop in this.settings_manager.fetch_preferred (); 189 bool is_preferred = desktop in this.settings_manager.fetch_preferred ();
188 190
191 mpris_to_desktop.set (dbus_name, desktop);
189 if ( this.registered_clients.has_key (mpris_key) == false ){192 if ( this.registered_clients.has_key (mpris_key) == false ){
190 debug("New client has registered that we have not seen before: %s", dbus_name );193 debug("New client has registered that we have not seen before: %s", dbus_name );
191 PlayerController ctrl = new PlayerController ( this.root_menu,194 PlayerController ctrl = new PlayerController ( this.root_menu,
@@ -216,10 +219,13 @@
216 mpris_root_interface );219 mpris_root_interface );
217 if (root_menu != null){220 if (root_menu != null){
218 debug("\n attempt to remove %s", mpris_root_interface);221 debug("\n attempt to remove %s", mpris_root_interface);
219 var mpris_key = determine_key ( mpris_root_interface );222 if (mpris_to_desktop.has_key(mpris_root_interface)){
220 if ( mpris_key != null && this.registered_clients.has_key(mpris_key)){223 var mpris_key = mpris_to_desktop[mpris_root_interface];
221 registered_clients[mpris_key].hibernate();224 mpris_to_desktop.unset(mpris_root_interface);
222 debug("\n Successively offlined client %s", mpris_key); 225 if ( mpris_key != null && this.registered_clients.has_key(mpris_key)){
226 registered_clients[mpris_key].hibernate();
227 debug("\n Successively offlined client %s", mpris_key);
228 }
223 }229 }
224 }230 }
225 }231 }
@@ -236,7 +242,7 @@
236 public void enable_player_specific_items_for_client (string object_path,242 public void enable_player_specific_items_for_client (string object_path,
237 string desktop_id)243 string desktop_id)
238 {244 {
239 var mpris_key = determine_key ( desktop_id );245 var mpris_key = desktop_id;
240 if (this.registered_clients.has_key (mpris_key) == false){246 if (this.registered_clients.has_key (mpris_key) == false){
241 warning ("we don't have a client with desktop id %s registered", desktop_id);247 warning ("we don't have a client with desktop id %s registered", desktop_id);
242 return;248 return;
@@ -247,7 +253,7 @@
247 public void enable_track_specific_items_for_client (string object_path,253 public void enable_track_specific_items_for_client (string object_path,
248 string desktop_id)254 string desktop_id)
249 {255 {
250 var mpris_key = determine_key ( desktop_id );256 var mpris_key = desktop_id;
251 if (this.registered_clients.has_key (mpris_key) == false){257 if (this.registered_clients.has_key (mpris_key) == false){
252 warning ("we don't have a client with desktop id %s registered", desktop_id);258 warning ("we don't have a client with desktop id %s registered", desktop_id);
253 return;259 return;
@@ -292,34 +298,6 @@
292 return null;298 return null;
293 } 299 }
294 }300 }
295
296 /*
297 Messy but necessary method to consolidate desktop filesnames and mpris dbus
298 names into the one single word string (used as the key in the players hash).
299 So this means that we can determine the key for the players_hash from the
300 dbus interface name or the desktop file name, at startup offline/online and
301 shutdown.
302 */
303 private static string? determine_key(owned string desktop_or_interface)
304 {
305 // handle the special case of amarok, (kde4-amarok desktop file name)
306 if (desktop_or_interface.contains("amarok")){
307 return "amarok";
308 }
309
310 var result = desktop_or_interface;
311
312 var tokens = desktop_or_interface.split( "." );
313 if (tokens != null && tokens.length > 1){
314 result = tokens[tokens.length - 1];
315 }
316 var temp = result.split("-");
317 if (temp != null && temp.length > 1){
318 result = temp[0];
319 }
320 return result;
321 }
322
323}301}
324302
325303

Subscribers

People subscribed via source and target branches