aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2012-03-27 07:17:59 -0700
committerCharles Kerr <charles.kerr@canonical.com>2012-03-27 07:17:59 -0700
commitd4a652971f9a99ff244b0ec85a027753a3cf220e (patch)
tree866ee0d2ac1527cba30aee92bfd498b3205f27d3
parentcf5c77a39f7355e8a2a6ee719a36bcbe6dfc0d7f (diff)
parentafb59cd4a8fa5731b5f737a4ef58fe1f3ae2fbb8 (diff)
downloadayatana-indicator-sound-d4a652971f9a99ff244b0ec85a027753a3cf220e.tar.gz
ayatana-indicator-sound-d4a652971f9a99ff244b0ec85a027753a3cf220e.tar.bz2
ayatana-indicator-sound-d4a652971f9a99ff244b0ec85a027753a3cf220e.zip
merge lp:~charlesk/indicator-sound/remove-interested-client to fix a pair of indicator-sound-service crashes (bug #949837 and bug #965848) related to removing media clients
-rw-r--r--src/music-player-bridge.vala26
-rw-r--r--src/settings-manager.vala32
2 files changed, 33 insertions, 25 deletions
diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala
index c2d6623..18f1c40 100644
--- a/src/music-player-bridge.vala
+++ b/src/music-player-bridge.vala
@@ -85,19 +85,20 @@ public class MusicPlayerBridge : GLib.Object
DesktopAppInfo desktop_info = info as DesktopAppInfo;
var file_path = desktop_info.get_filename ();
File f = File.new_for_path (file_path);
- FileMonitor monitor;
try {
- monitor = f.monitor (FileMonitorFlags.SEND_MOVED, null);
+ FileMonitor monitor = f.monitor (FileMonitorFlags.SEND_MOVED, null);
+ unowned FileMonitor weak_monitor = monitor;
+ monitor.changed.connect ((desktop_file, other_file, event_type) => {
+ this.relevant_desktop_file_changed (desktop_file, other_file, event_type, weak_monitor);
+ });
+ monitor.ref(); // will be unref()ed by relevant_desktop_file_changed()
+ GLib.debug ("monitoring file '%s'", file_path);
+ this.file_monitors.set (file_path, mpris_key);
}
catch (Error e){
warning ("Unable to create a file monitor for %s", info.get_name());
return;
}
- this.file_monitors.set (file_path, mpris_key);
- // Finally watch for a change.
- monitor.changed.connect ((desktop_file, other_file, event_type) => {
- this.relevant_desktop_file_changed (desktop_file, other_file, event_type, monitor);
- });
}
private void relevant_desktop_file_changed (File desktop_file,
@@ -117,10 +118,13 @@ public class MusicPlayerBridge : GLib.Object
warning ("relevant_desktop_file_changed is returning a file which we know nothing about - %s",
path);
return;
- }
- this.registered_clients[this.file_monitors[path]].remove_from_menu();
- this.settings_manager.remove_interested (this.file_monitors[path]);
- this.registered_clients.unset (this.file_monitors[path]);
+ }
+
+ var mpris_key = this.file_monitors[path];
+ GLib.debug ("file \"%s\" was removed; stopping monitoring \"%s\"", path, mpris_key);
+ this.registered_clients[mpris_key].remove_from_menu();
+ this.settings_manager.remove_interested (mpris_key);
+ this.registered_clients.unset (mpris_key);
monitor.cancel ();
monitor.unref();
}
diff --git a/src/settings-manager.vala b/src/settings-manager.vala
index 034cd03..d57241e 100644
--- a/src/settings-manager.vala
+++ b/src/settings-manager.vala
@@ -58,27 +58,31 @@ public class SettingsManager : GLib.Object
public void remove_interested (string app_desktop_name)
{
- var already_interested = this.settings.get_strv ("interested-media-players");
- var list = new ArrayList<string>();
+ const string key = "interested-media-players";
+ var players = new GLib.VariantBuilder (new VariantType ("as")); // array of strings
- foreach (var s in already_interested){
- if (s == app_desktop_name) continue;
- list.add (s);
+ foreach (var player in this.settings.get_strv (key)) {
+ if (player != app_desktop_name)
+ players.add ("s", player);
}
- this.settings.set_strv("interested-media-players",
- list.to_array());
- this.settings.apply();
+
+ this.settings.set_value(key, players.end());
+ this.settings.apply();
}
public void add_interested (string app_desktop_name)
{
- var already_interested = this.settings.get_strv ("interested-media-players");
- foreach (var s in already_interested){
- if ( s == app_desktop_name ) return;
+ const string key = "interested-media-players";
+ var players = new GLib.VariantBuilder (new VariantType ("as")); // array of strings
+
+ foreach (var player in this.settings.get_strv (key)) {
+ if (player == app_desktop_name)
+ return;
+ players.add ("s", player);
}
- already_interested += (app_desktop_name);
- this.settings.set_strv( "interested-media-players",
- already_interested );
+
+ players.add ("s", app_desktop_name);
+ this.settings.set_value(key, players.end());
this.settings.apply();
}