From 77e298f113541feacb27c1deca14ec953b6559b0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 5 Aug 2013 17:47:31 -0500 Subject: pass the SimpleActionGroup handle into the profile object so that dynamically-added actions can get added/exported --- src/desktop.vala | 34 +++++++++++++++++----------------- src/phone.vala | 19 ++++++++++--------- src/profile.vala | 2 -- src/service.vala | 12 +++++------- 4 files changed, 32 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/desktop.vala b/src/desktop.vala index 31fe9ac..4432a3f 100644 --- a/src/desktop.vala +++ b/src/desktop.vala @@ -22,18 +22,12 @@ class Desktop: Profile private uint idle_rebuild_id = 0; private Settings settings; private Bluetooth bluetooth; + private SimpleActionGroup action_group; private SimpleAction root_action; - private Action[] all_actions; private Menu device_section; private HashTable connect_actions; - public override void add_actions_to_group (SimpleActionGroup group) - { - for (var i=0; i(direct_hash, direct_equal); @@ -57,19 +52,24 @@ class Desktop: Profile root_action = create_root_action (); - all_actions = {}; - all_actions += root_action; - all_actions += create_enabled_action (bluetooth); - all_actions += create_discoverable_action (bluetooth); - all_actions += create_wizard_action (); - all_actions += create_browse_files_action (); - all_actions += create_send_file_action (); - all_actions += create_show_settings_action (); + // build the static actions + Action[] actions = {}; + actions += root_action; + actions += create_enabled_action (bluetooth); + actions += create_discoverable_action (bluetooth); + actions += create_wizard_action (); + actions += create_browse_files_action (); + actions += create_send_file_action (); + actions += create_show_settings_action (); + foreach (var a in actions) + action_group.insert (a); build_menu (); settings.changed["visible"].connect (()=> update_root_action_state()); bluetooth.notify.connect (() => update_root_action_state()); + + // when devices change, rebuild our device section bluetooth.devices_changed.connect (()=> { if (idle_rebuild_id == 0) idle_rebuild_id = Idle.add (() => { @@ -99,7 +99,7 @@ class Desktop: Profile action.activate.connect (() => action.set_state (!action.get_state().get_boolean())); action.notify["state"].connect (() => bluetooth.set_device_connected (device.id, action.get_state().get_boolean())); connect_actions.insert (device.id, action); - all_actions += action; + action_group.insert (action); } else { diff --git a/src/phone.vala b/src/phone.vala index 34c10ab..4eaff4d 100644 --- a/src/phone.vala +++ b/src/phone.vala @@ -19,21 +19,22 @@ class Phone: Profile { - private Action[] actions; + Bluetooth bluetooth; + SimpleActionGroup action_group; - public override void add_actions_to_group (SimpleActionGroup group) - { - for (var i=0; i (str_hash, str_equal); - profiles.insert ("phone", new Phone (bluetooth)); - profiles.insert ("desktop", new Desktop (bluetooth)); - actions = new SimpleActionGroup (); - foreach (Profile profile in profiles.get_values()) - profile.add_actions_to_group (actions); + + profiles = new HashTable (str_hash, str_equal); + profiles.insert ("phone", new Phone (bluetooth, actions)); + profiles.insert ("desktop", new Desktop (bluetooth, actions)); } public int run () @@ -61,7 +59,7 @@ public class Service: Object this.profiles.for_each ((name,profile) => { var path = @"/com/canonical/indicator/bluetooth/$name"; - message (@"exporting menu '$path'"); + debug (@"exporting menu '$path'"); profile.export_menu (connection, path); }); } -- cgit v1.2.3