diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2013-08-09 18:18:59 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2013-08-09 18:18:59 -0500 |
commit | c1d8ca09d39ba3070d22529bd40f564e7647bfb3 (patch) | |
tree | 92662297f6c919d14d04c169e314db313f0a776f /src | |
parent | 654ce426eb9de761f1adec4643eb76a0fcf64fb1 (diff) | |
download | ayatana-indicator-bluetooth-c1d8ca09d39ba3070d22529bd40f564e7647bfb3.tar.gz ayatana-indicator-bluetooth-c1d8ca09d39ba3070d22529bd40f564e7647bfb3.tar.bz2 ayatana-indicator-bluetooth-c1d8ca09d39ba3070d22529bd40f564e7647bfb3.zip |
on shutdown, unexport the menus and unown the bus name
Diffstat (limited to 'src')
-rw-r--r-- | src/profile.vala | 15 | ||||
-rw-r--r-- | src/service.vala | 50 |
2 files changed, 49 insertions, 16 deletions
diff --git a/src/profile.vala b/src/profile.vala index 96d1b5c..f89490b 100644 --- a/src/profile.vala +++ b/src/profile.vala @@ -23,6 +23,7 @@ class Profile: Object protected string profile_name; protected Menu root; protected Menu menu; + private uint menu_export_id; protected bool visible { get; set; default = true; } @@ -44,8 +45,8 @@ class Profile: Object { try { - debug (@"exporting '$profile_name' on $object_path"); - connection.export_menu_model (object_path, root); + debug (@"exporting menu '$profile_name'"); + menu_export_id = connection.export_menu_model (object_path, root); } catch (Error e) { @@ -53,6 +54,16 @@ class Profile: Object } } + public void unexport_menu (DBusConnection connection) + { + if (menu_export_id != 0) + { + debug (@"unexporting menu '$profile_name'"); + connection.unexport_menu_model (menu_export_id); + menu_export_id = 0; + } + } + protected void spawn_command_line_async (string command) { try { diff --git a/src/service.vala b/src/service.vala index 0c18b36..20fdd1e 100644 --- a/src/service.vala +++ b/src/service.vala @@ -27,6 +27,25 @@ public class Service: Object private MainLoop loop; private SimpleActionGroup actions; private HashTable<string,Profile> profiles; + private DBusConnection connection; + private uint exported_action_id; + private const string OBJECT_PATH = "/com/canonical/indicator/bluetooth"; + + private void unexport () + { + if (connection != null) + { + profiles.for_each ((name, profile) + => profile.unexport_menu (connection)); + + if (exported_action_id != 0) + { + debug (@"unexporting action group '$(OBJECT_PATH)'"); + connection.unexport_action_group (exported_action_id); + exported_action_id = 0; + } + } + } public Service (Bluetooth bluetooth) { @@ -45,37 +64,40 @@ public class Service: Object return Posix.EXIT_FAILURE; } - Bus.own_name (BusType.SESSION, - "com.canonical.indicator.bluetooth", - BusNameOwnerFlags.NONE, - on_bus_acquired, - null, - on_name_lost); + var own_name_id = Bus.own_name (BusType.SESSION, + "com.canonical.indicator.bluetooth", + BusNameOwnerFlags.NONE, + on_bus_acquired, + null, + on_name_lost); loop = new MainLoop (null, false); loop.run (); + + // cleanup + unexport (); + Bus.unown_name (own_name_id); return Posix.EXIT_SUCCESS; } void on_bus_acquired (DBusConnection connection, string name) { debug (@"bus acquired: $name"); + this.connection = connection; - var object_path = "/com/canonical/indicator/bluetooth"; try { - connection.export_action_group (object_path, actions); + debug (@"exporting action group '$(OBJECT_PATH)'"); + exported_action_id = connection.export_action_group (OBJECT_PATH, + actions); } catch (Error e) { - critical (@"Unable to export actions on $object_path: $(e.message)"); + critical (@"Unable to export actions on $OBJECT_PATH: $(e.message)"); } - profiles.for_each ((name, profile) => { - var path = @"$object_path/$name"; - debug (@"exporting menu '$path'"); - profile.export_menu (connection, path); - }); + profiles.for_each ((name, profile) + => profile.export_menu (connection, @"$OBJECT_PATH/$name")); } void on_name_lost (DBusConnection connection, string name) |