aboutsummaryrefslogtreecommitdiff
path: root/src/phone.vala
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-08-05 19:36:17 -0500
committerCharles Kerr <charles.kerr@canonical.com>2013-08-05 19:36:17 -0500
commit6492053ff654afbac9a078b7b67cca4a6dabecec (patch)
tree02ff781afaefd77bebfacbe4fcc54a6e312911fe /src/phone.vala
parent2d03420649eb330e7bae73929d98f0a8ea755ff7 (diff)
downloadayatana-indicator-bluetooth-6492053ff654afbac9a078b7b67cca4a6dabecec.tar.gz
ayatana-indicator-bluetooth-6492053ff654afbac9a078b7b67cca4a6dabecec.tar.bz2
ayatana-indicator-bluetooth-6492053ff654afbac9a078b7b67cca4a6dabecec.zip
promote shared functions up from Desktop to Profile so that Phone can use it too
Diffstat (limited to 'src/phone.vala')
-rw-r--r--src/phone.vala53
1 files changed, 25 insertions, 28 deletions
diff --git a/src/phone.vala b/src/phone.vala
index de5febe..05e6b9d 100644
--- a/src/phone.vala
+++ b/src/phone.vala
@@ -19,57 +19,54 @@
class Phone: Profile
{
- Bluetooth bluetooth;
SimpleActionGroup action_group;
public Phone (Bluetooth bluetooth, SimpleActionGroup action_group)
{
- base ("phone");
+ const string profile_name = "phone";
+ base (bluetooth, profile_name);
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 += get_root_action (profile_name);
+ actions += create_enabled_action (bluetooth);
actions += create_settings_action ();
foreach (var a in actions)
action_group.insert (a);
var section = new Menu ();
- section.append (_("Sound settingsā€¦"), "indicator.phone-settings");
+ section.append_item (create_enabled_menuitem ());
+ section.append (_("Bluetooth settingsā€¦"), "indicator.phone-show-settings::bluetooth");
menu.append_section (null, section);
+
+ // know when to show the indicator & when to hide it
+ bluetooth.notify.connect (() => update_visibility());
+ update_visibility ();
+
+ bluetooth.notify.connect (() => update_root_action_state());
}
- Action create_settings_action ()
+ void update_visibility ()
{
- var action = new SimpleAction ("phone-settings", null);
+ visible = bluetooth.powered && !bluetooth.blocked;
+ }
- action.activate.connect ((action, param) => {
- try {
- Process.spawn_command_line_async ("system-settings bluetooth");
- } catch (Error e) {
- warning (@"unable to launch settings: $(e.message)");
- }
- });
+ ///
+ /// Actions
+ ///
- return action;
+ void show_settings (string panel)
+ {
+ spawn_command_line_async ("system-settings " + panel);
}
- private Variant action_state_for_root ()
+ Action create_settings_action ()
{
- var label = "Hello World"; // FIXME
- var a11y = "Hello World"; // FIXME
- var visible = true; // FIXME
-
- string icon_name = "bluetooth"; // FIXME: enabled, disabled, connected, etc.
- 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 ();
+ var action = new SimpleAction ("phone-show-settings", VariantType.STRING);
+ action.activate.connect ((action, panel) => show_settings (panel.get_string()));
+ return action;
}
}