From 43059ed45ac41e1bf6172b3eec236ea086d81cda Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 3 Aug 2013 10:47:23 -0500 Subject: change the 'BluetoothMenu' superclass to 'Profile' --- src/Makefile.am | 2 +- src/desktop.vala | 34 ++++++++++++++++------------------ src/menu.vala | 53 ----------------------------------------------------- src/phone.vala | 14 ++++++-------- src/profile.vala | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/service.vala | 20 +++++++++----------- 6 files changed, 86 insertions(+), 91 deletions(-) delete mode 100644 src/menu.vala create mode 100644 src/profile.vala (limited to 'src') 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 */ -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.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/menu.vala b/src/menu.vala deleted file mode 100644 index a2c5449..0000000 --- a/src/menu.vala +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2013 Canonical Ltd. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - * - * Authors: - * Charles Kerr - */ - -class BluetoothMenu: Object -{ - protected Menu root; - protected Menu menu; - - public virtual void add_actions_to_group (SimpleActionGroup group) - { - } - - public BluetoothMenu (string profile) - { - this.menu = new Menu (); - - var root_item = new MenuItem (null, "indicator.root-" + profile); - root_item.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root"); - root_item.set_submenu (this.menu); - - this.root = new Menu (); - this.root.append_item (root_item); - } - - public void export (DBusConnection connection, string object_path) - { - try - { - message ("exporting on %s", object_path); - connection.export_menu_model (object_path, this.root); - } - catch (Error e) - { - critical ("%s", e.message); - } - } -} 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 */ -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. + * + * Authors: + * Charles Kerr + */ + +class Profile: Object +{ + protected string name; + protected Menu root; + protected Menu menu; + + public virtual void add_actions_to_group (SimpleActionGroup group) {} + + public Profile (string name) + { + this.name = name; + + menu = new Menu (); + + 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 (menu); + + root = new Menu (); + root.append_item (root_item); + } + + public void export_menu (DBusConnection connection, string object_path) + { + try + { + message ("exporting '%s' on %s", name, object_path); + connection.export_menu_model (object_path, this.root); + } + catch (Error e) + { + critical ("%s", e.message); + } + } +} 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 menus; + private HashTable 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 (str_hash, str_equal); + profiles.insert ("phone", new Phone (bluetooth)); + profiles.insert ("desktop", new Desktop (bluetooth)); - this.menus = new HashTable (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") -- cgit v1.2.3