aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bzrignore2
-rw-r--r--data/main.vala11
-rw-r--r--lib/common.vala66
-rw-r--r--lib/main.vala30
4 files changed, 35 insertions, 74 deletions
diff --git a/.bzrignore b/.bzrignore
index 54d2de9e..e092510f 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -14,8 +14,8 @@ build-aux
config.log
config.status
configure
+data/com.canonical.indicator.keyboard
data/indicator-keyboard-icon-generator
-data/indicator-keyboard.indicator
data/indicator-keyboard.service
debian/autoreconf.after
debian/autoreconf.before
diff --git a/data/main.vala b/data/main.vala
index 9be80ebf..dec6e6cf 100644
--- a/data/main.vala
+++ b/data/main.vala
@@ -72,16 +72,11 @@ int main (string[] args) {
var occurrences = new Gee.HashMap <string, int> ();
layouts.foreach ((name) => {
- string display;
- string layout;
+ string short_name;
- info.get_layout_info (name, out display, null, out layout, null);
+ info.get_layout_info (name, null, out short_name, null, null);
- if (display == null) {
- display = get_display_name (layout);
- }
-
- var abbreviation = get_abbreviation (display);
+ var abbreviation = get_abbreviation (short_name);
if (!occurrences.has_key (abbreviation)) {
occurrences[abbreviation] = 1;
diff --git a/lib/common.vala b/lib/common.vala
index 83652c8d..0e4e58e3 100644
--- a/lib/common.vala
+++ b/lib/common.vala
@@ -1,61 +1,15 @@
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])";
+ var index = 0;
+ unichar first;
+ unichar second;
+
+ if (name.get_next_char (ref index, out first)) {
+ if (name.get_next_char (ref index, out second)) {
+ return @"$(first.toupper ())$second";
+ } else {
+ return @"$(first.toupper ())";
}
- }
-
- 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;
+ return "";
}
}
diff --git a/lib/main.vala b/lib/main.vala
index b9560459..d0986d03 100644
--- a/lib/main.vala
+++ b/lib/main.vala
@@ -259,16 +259,10 @@ public class Indicator.Keyboard.Service : Object {
array.get_child (index, "(ss)", out type, out name);
if (type == "xkb") {
- string display_name;
- string layout_name;
-
- this.xkb_info.get_layout_info (name, out display_name, null, out layout_name, null);
-
- if (display_name == null) {
- display_name = get_display_name (layout_name);
- }
+ string short_name;
- this.icon_strings[index] = get_abbreviation (display_name);
+ this.xkb_info.get_layout_info (name, null, out short_name, null, null);
+ this.icon_strings[index] = get_abbreviation (short_name);
icon_string = this.icon_strings[index];
}
}
@@ -504,6 +498,24 @@ public class Indicator.Keyboard.Service : Object {
}
[DBus (visible = false)]
+ private string get_display_name (string layout) {
+ var language = Xkl.get_language_name (layout);
+ var country = Xkl.get_country_name (layout);
+ var has_language = language != null && language.get_char () != '\0';
+ var has_country = country != null && country.get_char () != '\0';
+
+ if (has_language && has_country) {
+ return @"$language ($country)";
+ } else if (has_language) {
+ return language;
+ } else if (has_country) {
+ return country;
+ } else {
+ return "";
+ }
+ }
+
+ [DBus (visible = false)]
private void update_sources_menu () {
if (this.sources_menu != null) {
var menu = get_sources_menu ();