aboutsummaryrefslogtreecommitdiff
path: root/lib/common.vala
diff options
context:
space:
mode:
authorWilliam Hua <william.hua@canonical.com>2013-06-04 10:09:22 -0400
committerWilliam Hua <william.hua@canonical.com>2013-06-04 10:09:22 -0400
commit7f9e0c6f74e4d85db873f2d8782f6b3da2d74c85 (patch)
tree9531d9373259ac252e11a3556a54f7855db37ad9 /lib/common.vala
parentaabf5155c14bc9a7c757d591c3a2192e8370b2b8 (diff)
downloadayatana-indicator-keyboard-7f9e0c6f74e4d85db873f2d8782f6b3da2d74c85.tar.gz
ayatana-indicator-keyboard-7f9e0c6f74e4d85db873f2d8782f6b3da2d74c85.tar.bz2
ayatana-indicator-keyboard-7f9e0c6f74e4d85db873f2d8782f6b3da2d74c85.zip
Factor out common code.
Diffstat (limited to 'lib/common.vala')
-rw-r--r--lib/common.vala61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/common.vala b/lib/common.vala
new file mode 100644
index 00000000..83652c8d
--- /dev/null
+++ b/lib/common.vala
@@ -0,0 +1,61 @@
+string get_abbreviation (string name) {
+ string abbreviation = null;
+
+ if (name != null) {
+ char letters[2];
+ var index = 0;
+
+ for (var i = 0; i < name.length && index < 2; i++) {
+ if (name[i].isupper ()) {
+ letters[index++] = name[i];
+ }
+ }
+
+ if (index < 2) {
+ index = 0;
+
+ for (var i = 0; i < name.length && index < 2; i++) {
+ if (name[i].isalpha () && (i == 0 || !name[i - 1].isalpha ())) {
+ letters[index++] = name[i++].toupper ();
+ }
+ }
+
+ if (index < 2) {
+ index = 0;
+
+ for (var i = 0; i < name.length && index < 2; i++) {
+ if (name[i].isalpha ()) {
+ letters[index++] = name[i];
+ }
+ }
+ }
+ }
+
+ if (index == 2) {
+ abbreviation = @"$(letters[0])$(letters[1])";
+ } else if (index == 1) {
+ abbreviation = @"$(letters[0])";
+ }
+ }
+
+ return abbreviation;
+}
+
+string? get_display_name (string? layout) {
+ if (layout == null) {
+ return null;
+ }
+
+ var language = Xkl.get_language_name (layout);
+ var country = Xkl.get_country_name (layout);
+
+ if (language != null && country != null) {
+ return @"$language ($country)";
+ } else if (language != null) {
+ return language;
+ } else if (country != null) {
+ return country;
+ } else {
+ return null;
+ }
+}