aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am3
-rwxr-xr-xautogen.sh5
-rw-r--r--configure.ac36
-rw-r--r--data/Makefile.am7
-rw-r--r--data/indicator-keyboard.indicator4
-rw-r--r--data/indicator-keyboard.service.in3
-rw-r--r--lib/Makefile.am6
-rw-r--r--lib/main.vala97
8 files changed, 161 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 00000000..35836b13
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,3 @@
+ACLOCAL_AMFLAGS = -I m4
+
+SUBDIRS = lib data
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 00000000..b509c24a
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,5 @@
+#!/bin/sh -e
+
+mkdir -p m4
+autoreconf -i
+test -n "$NOCONFIGURE" || ./configure "$@"
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 00000000..38225c1f
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,36 @@
+AC_PREREQ([2.69])
+
+AC_INIT([indicator-keyboard], [0.0.0])
+AC_REVISION([0.0.0])
+
+AC_CONFIG_SRCDIR([configure.ac])
+AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_MACRO_DIR([m4])
+
+AM_INIT_AUTOMAKE([1.11 foreign -Wall -Woverride -Wno-portability])
+AM_SILENT_RULES([yes])
+
+LT_INIT
+
+AC_PROG_CC
+AM_PROG_VALAC
+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_WITH([indicator-dir], [AS_HELP_STRING([--with-indicator-dir=DIR], [Indicator directory [default=$sysconfdir/indicators]])], [], [with_indicator_dir=$sysconfdir/indicators])
+
+AC_SUBST([DBUS_SERVICE_DIR], [$with_dbus_service_dir])
+AC_SUBST([INDICATOR_DIR], [$with_indicator_dir])
+
+PKG_CHECK_MODULES([GIO], [gio-2.0])
+AC_SUBST(GIO_CFLAGS)
+AC_SUBST(GIO_LIBS)
+
+AC_CONFIG_FILES([Makefile
+ data/Makefile
+ data/indicator-keyboard.service
+ lib/Makefile])
+
+AC_OUTPUT
diff --git a/data/Makefile.am b/data/Makefile.am
new file mode 100644
index 00000000..86959845
--- /dev/null
+++ b/data/Makefile.am
@@ -0,0 +1,7 @@
+servicedir = $(DBUS_SERVICE_DIR)
+dist_service_DATA = indicator-keyboard.service
+
+indicatordir = $(INDICATOR_DIR)
+dist_indicator_DATA = indicator-keyboard.indicator
+
+EXTRA_DIST = $(dist_service_DATA) $(dist_indicator_DATA)
diff --git a/data/indicator-keyboard.indicator b/data/indicator-keyboard.indicator
new file mode 100644
index 00000000..8f2cab12
--- /dev/null
+++ b/data/indicator-keyboard.indicator
@@ -0,0 +1,4 @@
+[Indicator Service]
+Name=indicator-keyboard
+BusName=com.canonical.indicator.keyboard
+ObjectPath=/com/canonical/indicator/keyboard
diff --git a/data/indicator-keyboard.service.in b/data/indicator-keyboard.service.in
new file mode 100644
index 00000000..775f00bc
--- /dev/null
+++ b/data/indicator-keyboard.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=com.canonical.indicator.keyboard
+Exec=@libexecdir@/indicator-keyboard-service
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644
index 00000000..eea05532
--- /dev/null
+++ b/lib/Makefile.am
@@ -0,0 +1,6 @@
+libexec_PROGRAMS = indicator-keyboard-service
+
+indicator_keyboard_service_SOURCES = main.vala
+indicator_keyboard_service_VALAFLAGS = --pkg gio-2.0 $(AM_VALAFLAGS)
+indicator_keyboard_service_CFLAGS = $(GIO_CFLAGS) $(AM_CFLAGS)
+indicator_keyboard_service_LDFLAGS = $(GIO_LIBS) $(AM_LDFLAGS)
diff --git a/lib/main.vala b/lib/main.vala
new file mode 100644
index 00000000..a149a522
--- /dev/null
+++ b/lib/main.vala
@@ -0,0 +1,97 @@
+[DBus (name = "com.canonical.indicator.keyboard")]
+public class Indicator.Keyboard.Service : GLib.Object {
+
+ private GLib.MainLoop loop;
+ private GLib.ActionGroup action_group;
+ private GLib.MenuModel menu_model;
+
+ public Service (bool force) {
+ GLib.Bus.own_name (GLib.BusType.SESSION,
+ "com.canonical.indicator.keyboard",
+ GLib.BusNameOwnerFlags.ALLOW_REPLACEMENT | (force ? GLib.BusNameOwnerFlags.REPLACE : 0),
+ this.handle_bus_acquired,
+ null,
+ this.handle_name_lost);
+
+ this.loop = new GLib.MainLoop ();
+ this.loop.run ();
+ }
+
+ [DBus (visible = false)]
+ protected virtual GLib.ActionGroup create_action_group () {
+ const GLib.ActionEntry[] entries = {
+ { "indicator", null, null, "('X', '', '', true)", null }
+ };
+
+ var group = new GLib.SimpleActionGroup ();
+
+ group.add_entries (entries, null);
+
+ return group;
+ }
+
+ [DBus (visible = false)]
+ protected virtual GLib.MenuModel create_menu_model () {
+ var menu = new GLib.Menu ();
+
+ var submenu = new GLib.Menu ();
+
+ var section = new GLib.Menu ();
+ section.append ("Chinese - Chewing", null);
+ section.append ("Chinese - Pinyin", null);
+ section.append ("Chinese - tonepy", null);
+ section.append ("USA - Macintosh", null);
+ section.append ("USA - Dvorak", null);
+ submenu.append_section (null, section);
+
+ section = new GLib.Menu ();
+ section.append ("Character Map", null);
+ section.append ("Keyboard Layout Chart", null);
+ section.append ("Text Entry Settings...", null);
+ submenu.append_section (null, section);
+
+ var indicator = new GLib.MenuItem.submenu ("x", submenu);
+ indicator.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root");
+ indicator.set_detailed_action ("indicator");
+ menu.append_item (indicator);
+
+ return menu;
+ }
+
+ [DBus (visible = false)]
+ public GLib.ActionGroup get_action_group () {
+ if (this.action_group == null)
+ this.action_group = create_action_group ();
+
+ return this.action_group;
+ }
+
+ [DBus (visible = false)]
+ public GLib.MenuModel get_menu_model () {
+ if (this.menu_model == null)
+ this.menu_model = create_menu_model ();
+
+ return this.menu_model;
+ }
+
+ [DBus (visible = false)]
+ private void handle_bus_acquired (GLib.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 ());
+ } catch {
+ GLib.warn_if_reached ();
+ }
+ }
+
+ [DBus (visible = false)]
+ private void handle_name_lost (GLib.DBusConnection connection, string name) {
+ this.loop.quit ();
+ this.loop = null;
+ }
+
+ public static int main (string[] args) {
+ new Service ("--force" in args);
+ return 0;
+ }
+}