Merge lp:~charlesk/indicator-sound/remove-interested-client into lp:indicator-sound/fifth

Proposed by Charles Kerr
Status: Merged
Approved by: Charles Kerr
Approved revision: 318
Merge reported by: Charles Kerr
Merged at revision: not available
Proposed branch: lp:~charlesk/indicator-sound/remove-interested-client
Merge into: lp:indicator-sound/fifth
Diff against target: 98 lines (+33/-25)
2 files modified
src/music-player-bridge.vala (+15/-11)
src/settings-manager.vala (+18/-14)
To merge this branch: bzr merge lp:~charlesk/indicator-sound/remove-interested-client
Reviewer Review Type Date Requested Status
Conor Curran (community) Approve
Review via email: mp+99458@code.launchpad.net
To post a comment you must log in.
Conor Curran (cjcurran) :
review: Approve
Conor Curran (cjcurran) wrote :

Nice catch Charles.

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-02-27 19:08:57 +0000
3+++ src/music-player-bridge.vala 2012-03-27 01:38:19 +0000
4@@ -85,19 +85,20 @@
5 DesktopAppInfo desktop_info = info as DesktopAppInfo;
6 var file_path = desktop_info.get_filename ();
7 File f = File.new_for_path (file_path);
8- FileMonitor monitor;
9 try {
10- monitor = f.monitor (FileMonitorFlags.SEND_MOVED, null);
11+ FileMonitor monitor = f.monitor (FileMonitorFlags.SEND_MOVED, null);
12+ unowned FileMonitor weak_monitor = monitor;
13+ monitor.changed.connect ((desktop_file, other_file, event_type) => {
14+ this.relevant_desktop_file_changed (desktop_file, other_file, event_type, weak_monitor);
15+ });
16+ monitor.ref(); // will be unref()ed by relevant_desktop_file_changed()
17+ GLib.debug ("monitoring file '%s'", file_path);
18+ this.file_monitors.set (file_path, mpris_key);
19 }
20 catch (Error e){
21 warning ("Unable to create a file monitor for %s", info.get_name());
22 return;
23 }
24- this.file_monitors.set (file_path, mpris_key);
25- // Finally watch for a change.
26- monitor.changed.connect ((desktop_file, other_file, event_type) => {
27- this.relevant_desktop_file_changed (desktop_file, other_file, event_type, monitor);
28- });
29 }
30
31 private void relevant_desktop_file_changed (File desktop_file,
32@@ -117,10 +118,13 @@
33 warning ("relevant_desktop_file_changed is returning a file which we know nothing about - %s",
34 path);
35 return;
36- }
37- this.registered_clients[this.file_monitors[path]].remove_from_menu();
38- this.settings_manager.remove_interested (this.file_monitors[path]);
39- this.registered_clients.unset (this.file_monitors[path]);
40+ }
41+
42+ var mpris_key = this.file_monitors[path];
43+ GLib.debug ("file \"%s\" was removed; stopping monitoring \"%s\"", path, mpris_key);
44+ this.registered_clients[mpris_key].remove_from_menu();
45+ this.settings_manager.remove_interested (mpris_key);
46+ this.registered_clients.unset (mpris_key);
47 monitor.cancel ();
48 monitor.unref();
49 }
50
51=== modified file 'src/settings-manager.vala'
52--- src/settings-manager.vala 2012-02-27 19:08:57 +0000
53+++ src/settings-manager.vala 2012-03-27 01:38:19 +0000
54@@ -58,27 +58,31 @@
55
56 public void remove_interested (string app_desktop_name)
57 {
58- var already_interested = this.settings.get_strv ("interested-media-players");
59- var list = new ArrayList<string>();
60+ const string key = "interested-media-players";
61+ var players = new GLib.VariantBuilder (new VariantType ("as")); // array of strings
62
63- foreach (var s in already_interested){
64- if (s == app_desktop_name) continue;
65- list.add (s);
66+ foreach (var player in this.settings.get_strv (key)) {
67+ if (player != app_desktop_name)
68+ players.add ("s", player);
69 }
70- this.settings.set_strv("interested-media-players",
71- list.to_array());
72- this.settings.apply();
73+
74+ this.settings.set_value(key, players.end());
75+ this.settings.apply();
76 }
77
78 public void add_interested (string app_desktop_name)
79 {
80- var already_interested = this.settings.get_strv ("interested-media-players");
81- foreach (var s in already_interested){
82- if ( s == app_desktop_name ) return;
83+ const string key = "interested-media-players";
84+ var players = new GLib.VariantBuilder (new VariantType ("as")); // array of strings
85+
86+ foreach (var player in this.settings.get_strv (key)) {
87+ if (player == app_desktop_name)
88+ return;
89+ players.add ("s", player);
90 }
91- already_interested += (app_desktop_name);
92- this.settings.set_strv( "interested-media-players",
93- already_interested );
94+
95+ players.add ("s", app_desktop_name);
96+ this.settings.set_value(key, players.end());
97 this.settings.apply();
98 }
99

Subscribers

People subscribed via source and target branches