aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/desktop.vala34
-rw-r--r--src/phone.vala19
-rw-r--r--src/profile.vala2
-rw-r--r--src/service.vala12
4 files changed, 32 insertions, 35 deletions
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<uint,SimpleAction> connect_actions;
- public override void add_actions_to_group (SimpleActionGroup group)
- {
- for (var i=0; i<all_actions.length; i++)
- group.insert (all_actions[i]);
- }
-
protected override void dispose ()
{
if (idle_rebuild_id != 0)
@@ -45,11 +39,12 @@ class Desktop: Profile
base.dispose ();
}
- public Desktop (Bluetooth bluetooth)
+ public Desktop (Bluetooth bluetooth, SimpleActionGroup action_group)
{
base ("desktop");
this.bluetooth = bluetooth;
+ this.action_group = action_group;
connect_actions = new HashTable<uint,SimpleAction>(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<actions.length; i++)
- group.insert (actions[i]);
- }
-
- public Phone (Bluetooth bluetooth)
+ public Phone (Bluetooth bluetooth, SimpleActionGroup action_group)
{
base ("phone");
- actions = {};
+ this.bluetooth = bluetooth;
+ this.action_group = action_group;
+
+ // build the static actions
+ Action[] actions = {};
actions += new SimpleAction.stateful ("root-phone", null, action_state_for_root());
actions += create_settings_action ();
+ foreach (var a in actions)
+ action_group.insert (a);
var section = new Menu ();
section.append (_("Sound settingsā€¦"), "indicator.phone-settings");
diff --git a/src/profile.vala b/src/profile.vala
index 360722d..d839121 100644
--- a/src/profile.vala
+++ b/src/profile.vala
@@ -23,8 +23,6 @@ class Profile: Object
protected Menu root;
protected Menu menu;
- public virtual void add_actions_to_group (SimpleActionGroup group) {}
-
public Profile (string name)
{
this.name = name;
diff --git a/src/service.vala b/src/service.vala
index 0cece83..69f57a6 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -16,13 +16,11 @@ public class Service: Object
public Service (Bluetooth bluetooth)
{
- profiles = new HashTable<string,Profile> (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<string,Profile> (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);
});
}