diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2013-08-03 10:47:23 -0500 |
---|---|---|
committer | Charles Kerr <charles.kerr@canonical.com> | 2013-08-03 10:47:23 -0500 |
commit | 43059ed45ac41e1bf6172b3eec236ea086d81cda (patch) | |
tree | 729f113dabd2c0f8079a8479a99f4f9355cfba5a | |
parent | dfd38e506145b8569611e5fb0eb8cb49eef1b7b2 (diff) | |
download | ayatana-indicator-bluetooth-43059ed45ac41e1bf6172b3eec236ea086d81cda.tar.gz ayatana-indicator-bluetooth-43059ed45ac41e1bf6172b3eec236ea086d81cda.tar.bz2 ayatana-indicator-bluetooth-43059ed45ac41e1bf6172b3eec236ea086d81cda.zip |
change the 'BluetoothMenu' superclass to 'Profile'
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/desktop.vala | 34 | ||||
-rw-r--r-- | src/phone.vala | 14 | ||||
-rw-r--r-- | src/profile.vala (renamed from src/menu.vala) | 25 | ||||
-rw-r--r-- | src/service.vala | 20 |
5 files changed, 45 insertions, 50 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index f685a97..b5aa8f1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,8 +6,8 @@ indicator_bluetooth_service_SOURCES = \ bluez.vala \ desktop.vala \ main.vala \ - menu.vala \ phone.vala \ + profile.vala \ killswitch.vala \ service.vala diff --git a/src/desktop.vala b/src/desktop.vala index 351770a..a7b8995 100644 --- a/src/desktop.vala +++ b/src/desktop.vala @@ -17,7 +17,7 @@ * Charles Kerr <charles.kerr@canonical.com> */ -class DesktopMenu: BluetoothMenu +class Desktop: Profile { private Settings settings; private Bluetooth bluetooth; @@ -27,31 +27,29 @@ class DesktopMenu: BluetoothMenu public override void add_actions_to_group (SimpleActionGroup group) { - base.add_actions_to_group (group); - - for (var i=0; i<this.all_actions.length; i++) + for (var i=0; i<all_actions.length; i++) group.insert (all_actions[i]); } - public DesktopMenu (Bluetooth bluetooth) + public Desktop (Bluetooth bluetooth) { base ("desktop"); this.bluetooth = bluetooth; - this.settings = new Settings ("com.canonical.indicator.bluetooth"); + settings = new Settings ("com.canonical.indicator.bluetooth"); - this.root_action = new SimpleAction.stateful ("root-desktop", null, action_state_for_root()); + 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 (); + all_actions = {}; + all_actions += root_action; + all_actions += create_enabled_action (bluetooth); + all_actions += create_discoverable_action (bluetooth); + all_actions += create_settings_action (); + all_actions += create_wizard_action (); - bluetooth.notify.connect (() => this.update_root_action_state()); - settings.changed["visible"].connect (()=> this.update_root_action_state()); + bluetooth.notify.connect (() => update_root_action_state()); + settings.changed["visible"].connect (()=> update_root_action_state()); Menu section; MenuItem item; @@ -63,12 +61,12 @@ class DesktopMenu: BluetoothMenu 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); + 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); + menu.append_section (null, section); } Action create_enabled_action (Bluetooth bluetooth) @@ -119,7 +117,7 @@ class DesktopMenu: BluetoothMenu bool blocked = bluetooth.blocked; bool powered = bluetooth.powered; - settings.changed["visible"].connect (()=> this.update_root_action_state()); + settings.changed["visible"].connect (()=> update_root_action_state()); bool visible = powered && settings.get_boolean("visible"); diff --git a/src/phone.vala b/src/phone.vala index a2a9917..8c9c816 100644 --- a/src/phone.vala +++ b/src/phone.vala @@ -17,29 +17,27 @@ * Charles Kerr <charles.kerr@canonical.com> */ -class PhoneMenu: BluetoothMenu +class Phone: Profile { private Action[] actions; public override void add_actions_to_group (SimpleActionGroup group) { - base.add_actions_to_group (group); - for (var i=0; i<actions.length; i++) group.insert (actions[i]); } - public PhoneMenu (Bluetooth bluetooth) + public Phone (Bluetooth bluetooth) { base ("phone"); - this.actions = {}; - this.actions += new SimpleAction.stateful ("root-phone", null, action_state_for_root()); - this.actions += create_settings_action (); + actions = {}; + actions += new SimpleAction.stateful ("root-phone", null, action_state_for_root()); + actions += create_settings_action (); var section = new Menu (); section.append (_("Sound settings…"), "indicator.phone-settings"); - this.menu.append_section (null, section); + menu.append_section (null, section); } Action create_settings_action () diff --git a/src/menu.vala b/src/profile.vala index a2c5449..6dd5f52 100644 --- a/src/menu.vala +++ b/src/profile.vala @@ -17,32 +17,33 @@ * Charles Kerr <charles.kerr@canonical.com> */ -class BluetoothMenu: Object +class Profile: Object { + protected string name; protected Menu root; protected Menu menu; - public virtual void add_actions_to_group (SimpleActionGroup group) - { - } + public virtual void add_actions_to_group (SimpleActionGroup group) {} - public BluetoothMenu (string profile) + public Profile (string name) { - this.menu = new Menu (); + this.name = name; + + menu = new Menu (); - var root_item = new MenuItem (null, "indicator.root-" + profile); + var root_item = new MenuItem (null, "indicator.root-" + name); root_item.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); - root_item.set_submenu (this.menu); + root_item.set_submenu (menu); - this.root = new Menu (); - this.root.append_item (root_item); + root = new Menu (); + root.append_item (root_item); } - public void export (DBusConnection connection, string object_path) + public void export_menu (DBusConnection connection, string object_path) { try { - message ("exporting on %s", object_path); + message ("exporting '%s' on %s", name, object_path); connection.export_menu_model (object_path, this.root); } catch (Error e) diff --git a/src/service.vala b/src/service.vala index 0f3d779..10f7f25 100644 --- a/src/service.vala +++ b/src/service.vala @@ -12,7 +12,7 @@ public class BluetoothIndicator { private MainLoop loop; private SimpleActionGroup actions; - private HashTable<string, BluetoothMenu> menus; + private HashTable<string,Profile> profiles; private DBusConnection bus; private Indicator.Service indicator_service; @@ -30,16 +30,13 @@ public class BluetoothIndicator public BluetoothIndicator (Bluetooth bluetooth) { - var phone = new PhoneMenu (bluetooth); - var desktop = new DesktopMenu (bluetooth); + profiles = new HashTable<string,Profile> (str_hash, str_equal); + profiles.insert ("phone", new Phone (bluetooth)); + profiles.insert ("desktop", new Desktop (bluetooth)); - this.menus = new HashTable<string, BluetoothMenu> (str_hash, str_equal); - this.menus.insert ("phone", phone); - this.menus.insert ("desktop", desktop); - - this.actions = new SimpleActionGroup (); - phone.add_actions_to_group (this.actions); - desktop.add_actions_to_group (this.actions); + actions = new SimpleActionGroup (); + foreach (Profile profile in profiles.get_values()) + profile.add_actions_to_group (actions); } private void init_for_bus (DBusConnection bus) @@ -178,7 +175,7 @@ public class BluetoothIndicator critical ("%s", e.message); } - this.menus.@foreach ( (profile, menu) => menu.export (connection, @"/com/canonical/indicator/bluetooth/$profile")); + this.profiles.@foreach ((name,profile) => profile.export_menu (connection, @"/com/canonical/indicator/bluetooth/$name")); } void on_name_lost (DBusConnection connection, string name) @@ -358,6 +355,7 @@ private class BluetoothMenuItem : Dbusmenu.Menuitem { for (var i = 0; uuids[i] != null; i++) { +message ("alias %s uuid #%d: %s", alias, i, uuids[i]); if (uuids[i] == "OBEXObjectPush") can_send = true; if (uuids[i] == "OBEXFileTransfer") |