aboutsummaryrefslogtreecommitdiff
path: root/lib/main.vala
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2014-04-04 15:51:14 +1300
committerWilliam Hua <william.hua@canonical.com>2014-04-04 15:51:14 +1300
commitddb87c4d8bbe8011c743e2706a681ae7d30bb2c4 (patch)
treee9bd876433bf9f25841d9604602006cbece1aab7 /lib/main.vala
parent414d5d9f8a41805ecec5808ace466c37d03fa9f3 (diff)
parent26afec3a316a0f7c2e62ae8d574a5d354ebcdde4 (diff)
downloadayatana-indicator-keyboard-ddb87c4d8bbe8011c743e2706a681ae7d30bb2c4.tar.gz
ayatana-indicator-keyboard-ddb87c4d8bbe8011c743e2706a681ae7d30bb2c4.tar.bz2
ayatana-indicator-keyboard-ddb87c4d8bbe8011c743e2706a681ae7d30bb2c4.zip
Merge 1291962-2.
Diffstat (limited to 'lib/main.vala')
-rw-r--r--lib/main.vala108
1 files changed, 25 insertions, 83 deletions
diff --git a/lib/main.vala b/lib/main.vala
index 7cfb5fac..d8c1f060 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -45,9 +45,8 @@ public class Indicator.Keyboard.Service : Object {
private SimpleActionGroup? action_group;
private SimpleAction? indicator_action;
- private MenuModel? menu_model;
- private Menu? sources_menu;
- private IBusMenu? ibus_menu;
+ private IndicatorMenu? desktop_menu;
+ private IndicatorMenu? desktop_greeter_menu;
private UnitySession? unity_session;
private uint session_current;
@@ -74,8 +73,12 @@ public class Indicator.Keyboard.Service : Object {
}
}
- if (sources_menu != null) {
- update_sources_menu ();
+ if (desktop_menu != null) {
+ get_desktop_menu ().set_sources (get_sources ());
+ }
+
+ if (desktop_greeter_menu != null) {
+ get_desktop_greeter_menu ().set_sources (get_sources ());
}
if (indicator_action != null) {
@@ -645,7 +648,7 @@ public class Indicator.Keyboard.Service : Object {
}
panel_timeout = Timeout.add (PROPERTIES_DELAY, () => {
- update_ibus_menu (list);
+ get_desktop_menu ().set_properties (list);
panel_timeout = 0;
return false;
});
@@ -653,7 +656,7 @@ public class Indicator.Keyboard.Service : Object {
[DBus (visible = false)]
private void handle_property_updated (IBus.Property property) {
- get_ibus_menu ().update_property (property);
+ get_desktop_menu ().update_property (property);
}
[DBus (visible = false)]
@@ -753,48 +756,11 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
- private void update_sources_menu () {
- if (sources_menu != null) {
- var menu = get_sources_menu ();
- menu.remove_all ();
-
- var sources = get_sources ();
- for (var i = 0; i < sources.length; i++) {
- var item = new MenuItem (sources[i].name, "indicator.current");
- item.set_attribute (Menu.ATTRIBUTE_TARGET, "u", i);
-
- var icon = sources[i].icon;
- if (icon != null) {
- item.set_icon ((!) icon);
- }
-
- menu.append_item (item);
- }
- } else {
- get_sources_menu ();
- }
- }
-
- [DBus (visible = false)]
- private Menu get_sources_menu () {
- if (sources_menu == null) {
- sources_menu = new Menu ();
- update_sources_menu ();
- }
-
- return (!) sources_menu;
- }
-
- [DBus (visible = false)]
- private void update_ibus_menu (IBus.PropList list) {
- get_ibus_menu ().set_properties (list);
- }
-
- [DBus (visible = false)]
- private IBusMenu get_ibus_menu () {
- if (ibus_menu == null) {
- ibus_menu = new IBusMenu (get_action_group ());
- ((!) ibus_menu).activate.connect ((property, state) => {
+ public IndicatorMenu get_desktop_menu () {
+ if (desktop_menu == null) {
+ desktop_menu = new IndicatorMenu (get_action_group ());
+ ((!) desktop_menu).set_sources (get_sources ());
+ ((!) desktop_menu).activate.connect ((property, state) => {
var panel = get_ibus_panel ();
if (panel != null) {
@@ -807,43 +773,17 @@ public class Indicator.Keyboard.Service : Object {
});
}
- return (!) ibus_menu;
- }
-
- [DBus (visible = false)]
- protected virtual MenuModel create_menu_model (MenuModel sources_menu, MenuModel ibus_menu) {
- var menu = new Menu ();
-
- var submenu = new Menu ();
-
- submenu.append_section (null, sources_menu);
- submenu.append_section (null, ibus_menu);
-
- if (!is_login_user ()) {
- var section = new Menu ();
- section.append (_ ("Character Map"), "indicator.map");
- section.append (_ ("Keyboard Layout Chart"), "indicator.chart");
- section.append (_ ("Text Entry Settings..."), "indicator.settings");
- submenu.append_section (null, section);
- }
-
- var indicator = new MenuItem.submenu ("x", submenu);
- indicator.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root");
- indicator.set_attribute ("x-canonical-secondary-action", "s", "indicator.next");
- indicator.set_attribute ("x-canonical-scroll-action", "s", "indicator.scroll");
- indicator.set_detailed_action ("indicator.indicator");
- menu.append_item (indicator);
-
- return menu;
+ return (!) desktop_menu;
}
[DBus (visible = false)]
- public MenuModel get_menu_model () {
- if (menu_model == null) {
- menu_model = create_menu_model (get_sources_menu (), get_ibus_menu ());
+ public IndicatorMenu get_desktop_greeter_menu () {
+ if (desktop_greeter_menu == null) {
+ desktop_greeter_menu = new IndicatorMenu (get_action_group (), IndicatorMenu.Options.NONE);
+ ((!) desktop_greeter_menu).set_sources (get_sources ());
}
- return (!) menu_model;
+ return (!) desktop_greeter_menu;
}
[DBus (visible = false)]
@@ -861,7 +801,8 @@ public class Indicator.Keyboard.Service : Object {
private void handle_changed_sources (string key) {
sources = null;
- update_sources_menu ();
+ get_desktop_menu ().set_sources (get_sources ());
+ get_desktop_greeter_menu ().set_sources (get_sources ());
update_indicator_action ();
update_login_layout ();
}
@@ -996,7 +937,8 @@ public class Indicator.Keyboard.Service : Object {
private void handle_bus_acquired (DBusConnection connection, string name) {
try {
connection.export_action_group ("/com/canonical/indicator/keyboard", get_action_group ());
- connection.export_menu_model ("/com/canonical/indicator/keyboard/desktop", get_menu_model ());
+ connection.export_menu_model ("/com/canonical/indicator/keyboard/desktop", get_desktop_menu ());
+ connection.export_menu_model ("/com/canonical/indicator/keyboard/desktop_greeter", get_desktop_greeter_menu ());
} catch (Error error) {
warning ("error: %s", error.message);
}