diff options
author | William Hua <william.hua@canonical.com> | 2013-06-04 17:09:37 -0400 |
---|---|---|
committer | William Hua <william.hua@canonical.com> | 2013-06-04 17:09:37 -0400 |
commit | 97c38e4e24e63dcd4fa34a7fadc27e9395c6a7ae (patch) | |
tree | 1ef52a8787ff72161c039e0e7a627d5659103f45 | |
parent | 7f9e0c6f74e4d85db873f2d8782f6b3da2d74c85 (diff) | |
download | ayatana-indicator-keyboard-97c38e4e24e63dcd4fa34a7fadc27e9395c6a7ae.tar.gz ayatana-indicator-keyboard-97c38e4e24e63dcd4fa34a7fadc27e9395c6a7ae.tar.bz2 ayatana-indicator-keyboard-97c38e4e24e63dcd4fa34a7fadc27e9395c6a7ae.zip |
Icon generator.
-rw-r--r-- | .bzrignore | 10 | ||||
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | data/Makefile.am | 26 | ||||
-rw-r--r-- | data/icon-1.svg.in | 1 | ||||
-rw-r--r-- | data/icon.svg.in | 1 | ||||
-rw-r--r-- | data/main.vala | 138 | ||||
-rw-r--r-- | lib/Makefile.am | 12 |
7 files changed, 181 insertions, 11 deletions
@@ -1,3 +1,4 @@ +*.c *.log *.m4 *.stamp @@ -13,16 +14,15 @@ build-aux config.log config.status configure +data/indicator-keyboard-icon-generator +data/indicator-keyboard.indicator +data/indicator-keyboard.service debian/autoreconf.after debian/autoreconf.before debian/files debian/indicator-keyboard debian/tmp -indicator-keyboard-service -indicator-keyboard.indicator -indicator-keyboard.service -lib/common.c -lib/main.c +lib/indicator-keyboard-service libtool po/POTFILES po/stamp-it diff --git a/configure.ac b/configure.ac index 5a1b9671..39d72f56 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,10 @@ IT_PROG_INTLTOOL GLIB_GSETTINGS +PKG_CHECK_MODULES([GEE], [gee-1.0]) +AC_SUBST([GEE_CFLAGS]) +AC_SUBST([GEE_LIBS]) + 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 b5212e94..125289bb 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,3 +1,29 @@ +AM_CFLAGS = -DGNOME_DESKTOP_USE_UNSTABLE_API +AM_LDFLAGS = -lm +AM_VALAFLAGS = --metadatadir $(top_srcdir)/deps \ + --vapidir $(top_srcdir)/deps + +noinst_PROGRAMS = indicator-keyboard-icon-generator + +indicator_keyboard_icon_generator_SOURCES = main.vala \ + $(top_srcdir)/lib/common.vala +indicator_keyboard_icon_generator_VALAFLAGS = $(AM_VALAFLAGS) \ + --pkg gee-1.0 \ + --pkg gtk+-3.0 \ + --pkg GDesktopEnums-3.0 \ + --pkg gnome-desktop-3.0 \ + --pkg Xkl-1.0 +indicator_keyboard_icon_generator_CFLAGS = $(AM_CFLAGS) \ + $(GEE_CFLAGS) \ + $(GTK_CFLAGS) \ + $(GNOME_DESKTOP_CFLAGS) \ + $(LIBXKLAVIER_CFLAGS) +indicator_keyboard_icon_generator_LDFLAGS = $(AM_LDFLAGS) \ + $(GEE_LIBS) \ + $(GTK_LIBS) \ + $(GNOME_DESKTOP_LIBS) \ + $(LIBXKLAVIER_LIBS) + servicedir = $(DBUS_SERVICE_DIR) dist_service_DATA = indicator-keyboard.service diff --git a/data/icon-1.svg.in b/data/icon-1.svg.in new file mode 100644 index 00000000..e223c017 --- /dev/null +++ b/data/icon-1.svg.in @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><svg version="1.1" width="22" height="22"><defs><mask id="m"><rect x="0" y="0" width="22" height="22" style="fill:white"/><text x="@LAYOUT_X@" y="@LAYOUT_Y@" style="font-size:12px;font-weight:500;fill:black;font-family:Ubuntu">@LAYOUT@</text></mask></defs><rect x="0" y="0" width="22" height="22" rx="4" mask="url(#m)" style="fill:@COLOUR@"/></svg> diff --git a/data/icon.svg.in b/data/icon.svg.in new file mode 100644 index 00000000..e223c017 --- /dev/null +++ b/data/icon.svg.in @@ -0,0 +1 @@ +<?xml version="1.0" encoding="UTF-8"?><svg version="1.1" width="22" height="22"><defs><mask id="m"><rect x="0" y="0" width="22" height="22" style="fill:white"/><text x="@LAYOUT_X@" y="@LAYOUT_Y@" style="font-size:12px;font-weight:500;fill:black;font-family:Ubuntu">@LAYOUT@</text></mask></defs><rect x="0" y="0" width="22" height="22" rx="4" mask="url(#m)" style="fill:@COLOUR@"/></svg> diff --git a/data/main.vala b/data/main.vala new file mode 100644 index 00000000..2c28ace7 --- /dev/null +++ b/data/main.vala @@ -0,0 +1,138 @@ +int main (string[] args) { + var force = false; + var colour = "grey"; + string output_path = null; + string no_subscript_path = null; + string with_subscript_path = null; + + OptionEntry[] options = new OptionEntry[6]; + options[0] = { "force", 'f', 0, OptionArg.NONE, ref force, "Overwrite existing files" }; + options[1] = { "colour", 'c', 0, OptionArg.STRING, ref colour, "Icon colour", "COLOUR" }; + options[2] = { "output", 'o', 0, OptionArg.FILENAME, ref output_path, "Output directory", "PATH" }; + options[3] = { "no-subscript", 's', 0, OptionArg.FILENAME, ref no_subscript_path, "Icon template", "PATH" }; + options[4] = { "with-subscript", 'S', 0, OptionArg.FILENAME, ref with_subscript_path, "Subscript icon template", "PATH" }; + options[5] = { null }; + + try { + var context = new OptionContext ("- generate keyboard layout icons"); + context.add_main_entries (options, null); + context.set_help_enabled (true); + context.parse (ref args); + } catch (OptionError error) { + stderr.printf ("error: %s\n", error.message); + return 1; + } + + if (no_subscript_path == null && with_subscript_path == null) { + stderr.printf ("error: No icon template\n"); + return 2; + } else if (no_subscript_path == null) { + no_subscript_path = with_subscript_path; + } else if (with_subscript_path == null) { + with_subscript_path = no_subscript_path; + } + + if (output_path != null) { + var file = File.new_for_path (output_path); + + if (!file.query_exists (null)) { + try { + file.make_directory_with_parents (null); + } catch (Error error) { + stderr.printf ("error: %s\n", error.message); + return 3; + } + } + } else { + output_path = "."; + } + + Gtk.init (ref args); + + var info = new Gnome.XkbInfo (); + var layouts = info.get_all_layouts (); + var occurrences = new Gee.HashMap <string, int> (); + + layouts.foreach ((name) => { + string display; + string layout; + + info.get_layout_info (name, out display, null, out layout, null); + + if (display == null) { + display = get_display_name (layout); + } + + var abbreviation = get_abbreviation (display); + + if (!occurrences.has_key (abbreviation)) { + occurrences[abbreviation] = 1; + } else { + occurrences[abbreviation] = occurrences[abbreviation] + 1; + } + }); + + string no_subscript_data; + string with_subscript_data; + + try { + uint8[] contents; + + File.new_for_path (no_subscript_path).load_contents (null, out contents, null); + no_subscript_data = ((string) contents).replace ("@COLOUR@", colour); + + File.new_for_path (with_subscript_path).load_contents (null, out contents, null); + with_subscript_data = ((string) contents).replace ("@COLOUR@", colour); + } catch (Error error) { + stderr.printf ("error: %s\n", error.message); + return 4; + } + + foreach (var entry in occurrences.entries) { + var layout = entry.key; + var count = entry.value; + var file = File.new_for_path (@"$output_path/$layout.svg"); + + if (force || !file.query_exists (null)) { + var output_data = no_subscript_data; + + output_data = output_data.replace ("@LAYOUT@", layout); + output_data = output_data.replace ("@LAYOUT_X@", "3.5"); + output_data = output_data.replace ("@LAYOUT_Y@", "15.5"); + + try { + file.replace_contents (output_data.data, null, false, FileCreateFlags.REPLACE_DESTINATION, null, null); + } catch (Error error) { + stderr.printf ("error: %s\n", error.message); + } + } + + if (count > 1) { + var partial_data = with_subscript_data; + + partial_data = partial_data.replace ("@LAYOUT@", layout); + + for (var i = 1; i <= count; i++) { + file = File.new_for_path (@"$output_path/$layout-$i.svg"); + + if (force || !file.query_exists (null)) { + var output_data = partial_data; + + output_data = output_data.replace ("@LAYOUT_X@", "3.5"); + output_data = output_data.replace ("@LAYOUT_Y@", "15.5"); + output_data = output_data.replace ("@SUBSCRIPT@", @"$i"); + output_data = output_data.replace ("@SUBSCRIPT_X@", "15"); + output_data = output_data.replace ("@SUBSCRIPT_Y@", "10"); + + try { + file.replace_contents (output_data.data, null, false, FileCreateFlags.REPLACE_DESTINATION, null, null); + } catch (Error error) { + stderr.printf ("error: %s\n", error.message); + } + } + } + } + } + + return 0; +} diff --git a/lib/Makefile.am b/lib/Makefile.am index 80496827..5f808108 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -16,17 +16,17 @@ indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \ --pkg Xkl-1.0 \ --pkg libgnomekbd \ --pkg ibus-1.0 -indicator_keyboard_service_CFLAGS = $(GTK_CFLAGS) \ +indicator_keyboard_service_CFLAGS = $(AM_CFLAGS) \ + $(GTK_CFLAGS) \ $(PANGOCAIRO_CFLAGS) \ $(GNOME_DESKTOP_CFLAGS) \ $(LIBXKLAVIER_CFLAGS) \ $(LIBGNOMEKBD_CFLAGS) \ - $(IBUS_CFLAGS) \ - $(AM_CFLAGS) -indicator_keyboard_service_LDFLAGS = $(GTK_LIBS) \ + $(IBUS_CFLAGS) +indicator_keyboard_service_LDFLAGS = $(AM_LDFLAGS) \ + $(GTK_LIBS) \ $(PANGOCAIRO_LIBS) \ $(GNOME_DESKTOP_LIBS) \ $(LIBXKLAVIER_LIBS) \ $(LIBGNOMEKBD_LIBS) \ - $(IBUS_LIBS) \ - $(AM_LDFLAGS) + $(IBUS_LIBS) |