aboutsummaryrefslogtreecommitdiff
path: root/src/desktop.vala
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-08-01 18:21:05 -0500
committerCharles Kerr <charles.kerr@canonical.com>2013-08-01 18:21:05 -0500
commitcf894302767d5ec483b5f8002bb796a284895bbf (patch)
treedb2db117dd355db27e72efa9087b8e18a43d38ae /src/desktop.vala
parent3cc732f558737acd0004efb013993515845e67d7 (diff)
downloadayatana-indicator-bluetooth-cf894302767d5ec483b5f8002bb796a284895bbf.tar.gz
ayatana-indicator-bluetooth-cf894302767d5ec483b5f8002bb796a284895bbf.tar.bz2
ayatana-indicator-bluetooth-cf894302767d5ec483b5f8002bb796a284895bbf.zip
add a bluetooth backend to track bluetooth being enabled, being hard/soft blocked, and its devices.
Diffstat (limited to 'src/desktop.vala')
-rw-r--r--src/desktop.vala121
1 files changed, 87 insertions, 34 deletions
diff --git a/src/desktop.vala b/src/desktop.vala
index bd005f5..351770a 100644
--- a/src/desktop.vala
+++ b/src/desktop.vala
@@ -20,80 +20,133 @@
class DesktopMenu: BluetoothMenu
{
private Settings settings;
+ private Bluetooth bluetooth;
- private Action[] actions;
+ private SimpleAction root_action;
+ private Action[] all_actions;
public override void add_actions_to_group (SimpleActionGroup group)
{
base.add_actions_to_group (group);
- for (var i=0; i<this.actions.length; i++)
- group.insert (actions[i]);
+ for (var i=0; i<this.all_actions.length; i++)
+ group.insert (all_actions[i]);
}
- public DesktopMenu ()
+ public DesktopMenu (Bluetooth bluetooth)
{
base ("desktop");
+ this.bluetooth = bluetooth;
+
this.settings = new Settings ("com.canonical.indicator.bluetooth");
- this.settings.changed["visible"].connect (()=> { message("visible toggled"); });
- this.actions = {};
- this.actions += new SimpleAction.stateful ("root-desktop", null, action_state_for_root());
- this.actions += create_settings_action ();
- this.actions += create_wizard_action ();
+ this.root_action = new SimpleAction.stateful ("root-desktop", null, action_state_for_root());
+
+ this.all_actions = {};
+ this.all_actions += this.root_action;
+ this.all_actions += create_enabled_action (bluetooth);
+ this.all_actions += create_discoverable_action (bluetooth);
+ this.all_actions += create_settings_action ();
+ this.all_actions += create_wizard_action ();
+
+ bluetooth.notify.connect (() => this.update_root_action_state());
+ settings.changed["visible"].connect (()=> this.update_root_action_state());
+
+ Menu section;
+ MenuItem item;
- var section = new Menu ();
+ section = new Menu ();
+ item = new MenuItem ("Bluetooth", "indicator.desktop-enabled");
+ item.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.switch");
+ section.append_item (item);
+ item = new MenuItem ("Visible", "indicator.desktop-discoverable");
+ item.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.switch");
+ section.append_item (item);
+ this.menu.append_section (null, section);
+
+ section = new Menu ();
section.append (_("Set Up New Deviceā€¦"), "indicator.desktop-wizard");
section.append (_("Bluetooth Settingsā€¦"), "indicator.desktop-settings");
this.menu.append_section (null, section);
}
- Action create_wizard_action ()
+ Action create_enabled_action (Bluetooth bluetooth)
{
- var action = new SimpleAction ("desktop-wizard", null);
+ var action = new SimpleAction.stateful ("desktop-enabled", null, !bluetooth.blocked);
+ action.activate.connect (() => action.set_state (!action.get_state().get_boolean()));
+ action.notify["state"].connect (() => bluetooth.try_set_blocked (!action.get_state().get_boolean()));
+ bluetooth.notify["blocked"].connect (() => action.set_state (!bluetooth.blocked));
+ return action;
+ }
- action.activate.connect ((action, param) => {
- try {
- Process.spawn_command_line_async ("bluetooth-wizard");
- } catch (Error e) {
- warning ("unable to launch settings: %s", e.message);
- }
- });
+ Action create_discoverable_action (Bluetooth bluetooth)
+ {
+ var action = new SimpleAction.stateful ("desktop-discoverable", null, bluetooth.discoverable);
+ action.set_enabled (bluetooth.powered);
+ action.activate.connect (() => action.set_state (!action.get_state().get_boolean()));
+ action.notify["state"].connect (() => bluetooth.try_set_discoverable (action.get_state().get_boolean()));
+ bluetooth.notify["discoverable"].connect (() => action.set_state (bluetooth.discoverable));
+ bluetooth.notify["powered"].connect (() => action.set_enabled (bluetooth.powered));
+ return action;
+ }
+ void spawn_command_line_async (string command)
+ {
+ try {
+ Process.spawn_command_line_async (command);
+ } catch (Error e) {
+ warning ("unable to launch '%s': %s", command, e.message);
+ }
+ }
+
+ Action create_wizard_action ()
+ {
+ var action = new SimpleAction ("desktop-wizard", null);
+ action.activate.connect (() => spawn_command_line_async ("bluetooth-wizard"));
return action;
}
Action create_settings_action ()
{
var action = new SimpleAction ("desktop-settings", null);
-
- action.activate.connect ((action, param) => {
- try {
- Process.spawn_command_line_async ("gnome-control-center bluetooth");
- } catch (Error e) {
- warning ("unable to launch settings: %s", e.message);
- }
- });
-
+ action.activate.connect (() => spawn_command_line_async ("gnome-control-center bluetooth"));
return action;
}
protected Variant action_state_for_root ()
{
- var label = "Hello"; // FIXME
- var a11y = "Hello"; // FIXME
- var visible = true; // FIXME
+ bool blocked = bluetooth.blocked;
+ bool powered = bluetooth.powered;
+
+ settings.changed["visible"].connect (()=> this.update_root_action_state());
+
+ bool visible = powered && settings.get_boolean("visible");
+
+ string a11y;
+ string icon_name;
+ if (powered && !blocked)
+ {
+ a11y = "Bluetooth (on)";
+ icon_name = "bluetooth-active";
+ }
+ else
+ {
+ a11y = "Bluetooth (off)";
+ icon_name = "bluetooth-disabled";
+ }
- string icon_name = "bluetooth-active"; // FIXME: enabled, disabled, connected, etc.
-//indicator-bluetooth-service.vala: bluetooth_service._icon_name = enabled ? "bluetooth-active" : "bluetooth-disabled";
var icon = new ThemedIcon.with_default_fallbacks (icon_name);
var builder = new VariantBuilder (new VariantType ("a{sv}"));
builder.add ("{sv}", "visible", new Variant ("b", visible));
- builder.add ("{sv}", "label", new Variant ("s", label));
builder.add ("{sv}", "accessible-desc", new Variant ("s", a11y));
builder.add ("{sv}", "icon", icon.serialize());
return builder.end ();
}
+
+ void update_root_action_state ()
+ {
+ root_action.set_state (action_state_for_root ());
+ }
}