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
1=== modified file 'src/music-player-bridge.vala'
2--- src/music-player-bridge.vala 2012-06-21 16:45:16 +0000
3+++ src/music-player-bridge.vala 2012-10-09 09:09:25 +0000
4@@ -29,6 +29,7 @@
5 private Dbusmenu.Menuitem root_menu;
6 private HashMap<string, PlayerController> registered_clients;
7 private HashMap<string, string> file_monitors;
8+ private HashMap<string, string> mpris_to_desktop;
9 private Mpris2Watcher watcher;
10
11 public MusicPlayerBridge()
12@@ -38,6 +39,7 @@
13 construct{
14 this.registered_clients = new HashMap<string, PlayerController> ();
15 this.file_monitors = new HashMap<string, string> ();
16+ this.mpris_to_desktop = new HashMap<string, string> ();
17 this.settings_manager = new SettingsManager();
18 this.settings_manager.blacklist_updates.connect ( this.on_blacklist_update );
19 this.settings_manager.preferred_updates.connect ( this.on_preferred_update );
20@@ -47,8 +49,8 @@
21 {
22 debug("some blacklist update");
23
24- foreach(var s in blacklist){
25- string key = this.determine_key (s);
26+ foreach(var desktop_id in blacklist){
27+ string key = desktop_id;
28 if (this.registered_clients.has_key (key)){
29 debug ("Apparently %s is now blacklisted - remove thy self", key);
30 this.registered_clients[key].remove_from_menu();
31@@ -67,8 +69,8 @@
32 player_controller.set_as_preferred (false);
33 }
34
35- foreach (var s in preferred) {
36- string key = this.determine_key (s);
37+ foreach (var desktop_id in preferred) {
38+ string key = desktop_id;
39 if (this.registered_clients.has_key (key)) {
40 debug ("Setting %s as preferred player", key);
41 this.registered_clients[key].set_as_preferred (true);
42@@ -96,7 +98,7 @@
43 null,
44 PlayerController.state.OFFLINE,
45 is_preferred );
46- var mpris_key = determine_key ( desktop );
47+ var mpris_key = desktop;
48 this.registered_clients.set(mpris_key, ctrl);
49 this.establish_file_monitoring (app_info, mpris_key);
50 }
51@@ -183,9 +185,10 @@
52 return;
53 }
54
55- var mpris_key = determine_key ( desktop );
56+ var mpris_key = desktop;
57 bool is_preferred = desktop in this.settings_manager.fetch_preferred ();
58
59+ mpris_to_desktop.set (dbus_name, desktop);
60 if ( this.registered_clients.has_key (mpris_key) == false ){
61 debug("New client has registered that we have not seen before: %s", dbus_name );
62 PlayerController ctrl = new PlayerController ( this.root_menu,
63@@ -216,10 +219,13 @@
64 mpris_root_interface );
65 if (root_menu != null){
66 debug("\n attempt to remove %s", mpris_root_interface);
67- var mpris_key = determine_key ( mpris_root_interface );
68- if ( mpris_key != null && this.registered_clients.has_key(mpris_key)){
69- registered_clients[mpris_key].hibernate();
70- debug("\n Successively offlined client %s", mpris_key);
71+ if (mpris_to_desktop.has_key(mpris_root_interface)){
72+ var mpris_key = mpris_to_desktop[mpris_root_interface];
73+ mpris_to_desktop.unset(mpris_root_interface);
74+ if ( mpris_key != null && this.registered_clients.has_key(mpris_key)){
75+ registered_clients[mpris_key].hibernate();
76+ debug("\n Successively offlined client %s", mpris_key);
77+ }
78 }
79 }
80 }
81@@ -236,7 +242,7 @@
82 public void enable_player_specific_items_for_client (string object_path,
83 string desktop_id)
84 {
85- var mpris_key = determine_key ( desktop_id );
86+ var mpris_key = desktop_id;
87 if (this.registered_clients.has_key (mpris_key) == false){
88 warning ("we don't have a client with desktop id %s registered", desktop_id);
89 return;
90@@ -247,7 +253,7 @@
91 public void enable_track_specific_items_for_client (string object_path,
92 string desktop_id)
93 {
94- var mpris_key = determine_key ( desktop_id );
95+ var mpris_key = desktop_id;
96 if (this.registered_clients.has_key (mpris_key) == false){
97 warning ("we don't have a client with desktop id %s registered", desktop_id);
98 return;
99@@ -292,34 +298,6 @@
100 return null;
101 }
102 }
103-
104- /*
105- Messy but necessary method to consolidate desktop filesnames and mpris dbus
106- names into the one single word string (used as the key in the players hash).
107- So this means that we can determine the key for the players_hash from the
108- dbus interface name or the desktop file name, at startup offline/online and
109- shutdown.
110- */
111- private static string? determine_key(owned string desktop_or_interface)
112- {
113- // handle the special case of amarok, (kde4-amarok desktop file name)
114- if (desktop_or_interface.contains("amarok")){
115- return "amarok";
116- }
117-
118- var result = desktop_or_interface;
119-
120- var tokens = desktop_or_interface.split( "." );
121- if (tokens != null && tokens.length > 1){
122- result = tokens[tokens.length - 1];
123- }
124- var temp = result.split("-");
125- if (temp != null && temp.length > 1){
126- result = temp[0];
127- }
128- return result;
129- }
130-
131 }
132
133

Subscribers

People subscribed via source and target branches