aboutsummaryrefslogtreecommitdiff
path: root/lib/main.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/main.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/main.vala')
-rw-r--r--lib/main.vala68
1 files changed, 3 insertions, 65 deletions
diff --git a/lib/main.vala b/lib/main.vala
index f6f823fc..d85a8c1b 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -126,50 +126,6 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
- private string abbreviate_display_name (string display_name) {
- string abbreviation = null;
-
- if (display_name != null) {
- char letters[2];
- var index = 0;
-
- for (var i = 0; i < display_name.length && index < 2; i++) {
- if (display_name[i].isupper ()) {
- letters[index++] = display_name[i];
- }
- }
-
- if (index < 2) {
- index = 0;
-
- for (var i = 0; i < display_name.length && index < 2; i++) {
- if (display_name[i].isalpha () && (i == 0 || !display_name[i - 1].isalpha ())) {
- letters[index++] = display_name[i++].toupper ();
- }
- }
-
- if (index < 2) {
- index = 0;
-
- for (var i = 0; i < display_name.length && index < 2; i++) {
- if (display_name[i].isalpha ()) {
- letters[index++] = display_name[i];
- }
- }
- }
- }
-
- if (index == 1) {
- abbreviation = @"$(letters[0])";
- } else if (index == 2) {
- abbreviation = @"$(letters[0])$(letters[1])";
- }
- }
-
- return abbreviation;
- }
-
- [DBus (visible = false)]
private uint get_icon_string_subscript (uint index) {
uint icon_string_subscript = 0;
Variant array = null;
@@ -228,19 +184,10 @@ public class Indicator.Keyboard.Service : Object {
this.xkb_info.get_layout_info (name, out display_name, null, out layout_name, null);
if (display_name == null) {
- var language = Xkl.get_language_name (layout_name);
- var country = Xkl.get_country_name (layout_name);
-
- if (language != null && country != null) {
- display_name = @"$language ($country)";
- } else if (language != null) {
- display_name = language;
- } else if (country != null) {
- display_name = country;
- }
+ display_name = get_display_name (layout_name);
}
- this.icon_strings[index] = abbreviate_display_name (display_name);
+ this.icon_strings[index] = get_abbreviation (display_name);
icon_string = this.icon_strings[index];
}
}
@@ -407,16 +354,7 @@ public class Indicator.Keyboard.Service : Object {
this.xkb_info.get_layout_info (name, out display_name, null, out layout_name, null);
if (display_name == null) {
- var language = Xkl.get_language_name (layout_name);
- var country = Xkl.get_country_name (layout_name);
-
- if (language != null && country != null) {
- name = @"$language ($country)";
- } else if (language != null) {
- name = language;
- } else if (country != null) {
- name = country;
- }
+ name = get_display_name (layout_name);
} else {
name = display_name;
}