aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/profile.vala15
-rw-r--r--src/service.vala50
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)