From 0d409ee73408a8ba66b31d2c343994302b0b7c81 Mon Sep 17 00:00:00 2001 From: William Hua Date: Mon, 29 Apr 2013 22:38:23 -0700 Subject: Indicator visible setting. --- .bzrignore | 1 + configure.ac | 7 +++- data/Makefile.am | 8 ++++- data/com.canonical.indicator.keyboard.gschema.xml | 10 ++++++ lib/main.vala | 44 +++++++++++++++-------- 5 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 data/com.canonical.indicator.keyboard.gschema.xml diff --git a/.bzrignore b/.bzrignore index 1da93b03..fd7ff188 100644 --- a/.bzrignore +++ b/.bzrignore @@ -2,6 +2,7 @@ *.m4 *.stamp *.substvars +*.valid .deps .libs Makefile diff --git a/configure.ac b/configure.ac index c0ffbb33..2ca24b88 100644 --- a/configure.ac +++ b/configure.ac @@ -18,12 +18,17 @@ AC_PROG_LIBTOOL AC_PROG_INSTALL PKG_PROG_PKG_CONFIG([0.26]) -AC_ARG_WITH([dbus-service-dir], [AS_HELP_STRING([--with-dbus-service-dir=DIR], [D-Bus service directory [default=`pkg-config --variable=session_bus_services_dir dbus-1`]])], [], [with_dbus_service_dir=`pkg-config --variable=session_bus_services_dir dbus-1`]) +AC_ARG_ENABLE([local-install], AS_HELP_STRING([--enable-local-install], [Enable local install])) +AS_IF([test "x$enable_local_install" = "xyes"], [dbus_service_dir=$prefix/share/dbus-1/services], [dbus_service_dir=`pkg-config --variable=session_bus_services_dir dbus-1`]) + +AC_ARG_WITH([dbus-service-dir], [AS_HELP_STRING([--with-dbus-service-dir=DIR], [D-Bus service directory [default=$dbus_service_dir]])], [], [with_dbus_service_dir=$dbus_service_dir]) AC_ARG_WITH([indicator-dir], [AS_HELP_STRING([--with-indicator-dir=DIR], [Indicator directory [default=$prefix/share/unity/indicators]])], [], [with_indicator_dir=$prefix/share/unity/indicators]) AC_SUBST([DBUS_SERVICE_DIR], [$with_dbus_service_dir]) AC_SUBST([INDICATOR_DIR], [$with_indicator_dir]) +GLIB_GSETTINGS + PKG_CHECK_MODULES([GTK], [gtk+-3.0]) AC_SUBST([GTK_CFLAGS]) AC_SUBST([GTK_LIBS]) diff --git a/data/Makefile.am b/data/Makefile.am index 6171aaf0..b5212e94 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -17,4 +17,10 @@ indicator-keyboard.indicator: echo 'ObjectPath=/com/canonical/indicator/keyboard') > $@.tmp && \ mv $@.tmp $@ -EXTRA_DIST = $(dist_service_DATA) $(dist_indicator_DATA) +gsettings_SCHEMAS = com.canonical.indicator.keyboard.gschema.xml + +@GSETTINGS_RULES@ + +EXTRA_DIST = $(dist_service_DATA) \ + $(dist_indicator_DATA) \ + $(gsettings_SCHEMAS) diff --git a/data/com.canonical.indicator.keyboard.gschema.xml b/data/com.canonical.indicator.keyboard.gschema.xml new file mode 100644 index 00000000..b201ec3c --- /dev/null +++ b/data/com.canonical.indicator.keyboard.gschema.xml @@ -0,0 +1,10 @@ + + + + + true + Keyboard indicator visibility + True if the keyboard indicator is shown, false otherwise. + + + diff --git a/lib/main.vala b/lib/main.vala index c00a36da..77ea4636 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -2,7 +2,8 @@ public class Indicator.Keyboard.Service : Object { private MainLoop loop; - private Settings settings; + private Settings indicator_settings; + private Settings source_settings; private IBus.Bus ibus; private SimpleActionGroup action_group; @@ -21,9 +22,12 @@ public class Indicator.Keyboard.Service : Object { null, this.handle_name_lost); - this.settings = new Settings ("org.gnome.desktop.input-sources"); - this.settings.changed["current"].connect (this.handle_changed_current); - this.settings.changed["sources"].connect (this.handle_changed_sources); + this.indicator_settings = new Settings ("com.canonical.indicator.keyboard"); + this.indicator_settings.changed["visible"].connect (this.handle_changed_visible); + + this.source_settings = new Settings ("org.gnome.desktop.input-sources"); + this.source_settings.changed["current"].connect (this.handle_changed_current); + this.source_settings.changed["sources"].connect (this.handle_changed_sources); this.loop = new MainLoop (); this.loop.run (); @@ -95,7 +99,7 @@ public class Indicator.Keyboard.Service : Object { Variant array = null; if (this.icons == null) { - this.settings.get ("sources", "@a(ss)", out array); + this.source_settings.get ("sources", "@a(ss)", out array); this.icons = new Icon[array.n_children ()]; } @@ -104,7 +108,7 @@ public class Indicator.Keyboard.Service : Object { if (icon == null) { if (array == null) { - this.settings.get ("sources", "@a(ss)", out array); + this.source_settings.get ("sources", "@a(ss)", out array); } string type; @@ -124,7 +128,7 @@ public class Indicator.Keyboard.Service : Object { var group = new SimpleActionGroup (); group.insert (root_action); - group.insert (this.settings.create_action ("current")); + group.insert (this.source_settings.create_action ("current")); var action = new SimpleAction ("map", null); action.activate.connect (this.handle_activate_map); @@ -143,19 +147,24 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] private void update_indicator_action () { - var current = this.settings.get_uint ("current"); + var visible = this.indicator_settings.get_boolean ("visible"); + var current = this.source_settings.get_uint ("current"); var icon = get_icon (current); + Variant state; if (icon != null) { - var state = new Variant.parsed ("{ 'icon' : %v, 'visible' : }", icon.serialize ()); - get_indicator_action ().set_state (state); + state = new Variant.parsed ("{ 'visible' : <%b>, 'icon' : %v }", visible, icon.serialize ()); + } else { + state = new Variant.parsed ("{ 'visible' : <%b> }", visible); } + + get_indicator_action ().set_state (state); } [DBus (visible = false)] private SimpleAction get_indicator_action () { if (this.indicator_action == null) { - var state = new Variant.parsed ("{ 'visible' : }"); + var state = new Variant.parsed ("{ 'visible' : }"); this.indicator_action = new SimpleAction.stateful ("indicator", null, state); update_indicator_action (); } @@ -217,7 +226,7 @@ public class Indicator.Keyboard.Service : Object { string type; string name; - this.settings.get ("sources", "a(ss)", out iter); + this.source_settings.get ("sources", "a(ss)", out iter); for (var i = 0; iter.next ("(ss)", out type, out name); i++) { if (type == "xkb") { @@ -279,6 +288,11 @@ public class Indicator.Keyboard.Service : Object { return this.menu_model; } + [DBus (visible = false)] + private void handle_changed_visible (string key) { + update_indicator_action (); + } + [DBus (visible = false)] private void handle_changed_current (string key) { update_indicator_action (); @@ -286,7 +300,9 @@ public class Indicator.Keyboard.Service : Object { [DBus (visible = false)] private void handle_changed_sources (string key) { + this.icons = null; update_sources_menu (); + update_indicator_action (); } [DBus (visible = false)] @@ -302,9 +318,9 @@ public class Indicator.Keyboard.Service : Object { private void handle_activate_chart (Variant? parameter) { var layout = "us"; - var current = this.settings.get_uint ("current"); + var current = this.source_settings.get_uint ("current"); Variant array; - this.settings.get ("sources", "@a(ss)", out array); + this.source_settings.get ("sources", "@a(ss)", out array); if (current < array.n_children ()) { string type; -- cgit v1.2.3