aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-03-15 14:10:01 -0400
committerWilliam Hua <william.hua@canonical.com>2013-03-15 14:10:01 -0400
commit3846f9ebd88c14e9415020685f983cbd1ac358fa (patch)
tree196dcff1522b9878b4dac0e86c0ff43a2e7c7f8c /lib
downloadayatana-indicator-keyboard-3846f9ebd88c14e9415020685f983cbd1ac358fa.tar.gz
ayatana-indicator-keyboard-3846f9ebd88c14e9415020685f983cbd1ac358fa.tar.bz2
ayatana-indicator-keyboard-3846f9ebd88c14e9415020685f983cbd1ac358fa.zip
Initial commit.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am6
-rw-r--r--lib/main.vala97
2 files changed, 103 insertions, 0 deletions
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;
+ }
+}