From 6492053ff654afbac9a078b7b67cca4a6dabecec Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 5 Aug 2013 19:36:17 -0500 Subject: promote shared functions up from Desktop to Profile so that Phone can use it too --- src/phone.vala | 53 +++++++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) (limited to 'src/phone.vala') 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; } } -- cgit v1.2.3