[gnome-initial-setup/shell/4765: 299/362] Infrastructure for keyboard detection by language



commit f1758663d017143fa82162ea1d59fa9470fe8d8f
Author: Roddy Shuler <roddy endlessm com>
Date:   Fri Dec 5 08:24:22 2014 -0800

    Infrastructure for keyboard detection by language
    
    This allows simpler detection trees that only need to distinguish
    among the likely keyboards for a user's language.
    
    Using gettext locale rules, search for the best available match
    in order from most desirable to least desirable, and fall back to
    the full detection tree (default locale "C") if no better match.
    
    To add support for a specific language, create the appropriate
    directory in gnome-initial-setup/pages/keyboard/detector-trees
    with a tweaked version of pc105.tree, and add the file path to
    gnome-initial-setup/pages/keyboard/keyboard.gresource.xml.
    
    [endlessm/eos-shell#4213]

 .../pages/keyboard/cc-keyboard-detector.c          |   40 ++++++++++++++++++--
 .../keyboard/{ => detector-trees/C}/pc105.tree     |    0
 .../pages/keyboard/keyboard.gresource.xml          |    2 +-
 3 files changed, 37 insertions(+), 5 deletions(-)
---
diff --git a/gnome-initial-setup/pages/keyboard/cc-keyboard-detector.c 
b/gnome-initial-setup/pages/keyboard/cc-keyboard-detector.c
index 7aa992d..b976269 100644
--- a/gnome-initial-setup/pages/keyboard/cc-keyboard-detector.c
+++ b/gnome-initial-setup/pages/keyboard/cc-keyboard-detector.c
@@ -21,6 +21,7 @@
 
 #include <config.h>
 #include <string.h>
+#include <stdio.h>
 
 #include "cc-keyboard-detector.h"
 
@@ -29,13 +30,44 @@ keyboard_detector_new (void)
 {
   GError *error = NULL;
   GInputStream *istream;
-  KeyboardDetector *det = g_new0 (KeyboardDetector, 1);
+  KeyboardDetector *det;
+  const gchar * const *language_names = g_get_language_names ();
+  const gchar *language_name;
+  int idx;
+
+  /* Find the detector tree that is the best match for the user's language. */
+  for (idx = 0; (language_name = language_names[idx]) != NULL; idx++)
+    {
+      gchar *path = g_strdup_printf (
+          "/org/gnome/initial-setup/detector-trees/%s/pc105.tree",
+          language_name);
+      g_clear_error (&error);
+      istream = g_resources_open_stream (path,
+                                         G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
+      g_free (path);
+
+      if (istream == NULL)
+        {
+          g_debug ("Unable to load keyboard detector tree for %s: %s",
+                   language_name, error->message);
+          /* Don't clear the error here, as we need the message
+           * for the last error outside the loop.  Instead, we will
+           * clear the error at the start of the next iteration. */
+        }
+      else
+        {
+          g_debug ("Successfully loaded keyboard detector tree for %s",
+                   language_name);
+          break;
+        }
+    }
 
-  det->current_step = -1;
-  istream = g_resources_open_stream ("/org/gnome/initial-setup/pc105.tree",
-                                     G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
   if (istream == NULL)
     g_error ("Error loading keyboard detector tree: %s", error->message);
+
+  det = g_new0 (KeyboardDetector, 1);
+
+  det->current_step = -1;
   det->fp = g_data_input_stream_new (istream);
   g_object_unref (istream);
 
diff --git a/gnome-initial-setup/pages/keyboard/pc105.tree 
b/gnome-initial-setup/pages/keyboard/detector-trees/C/pc105.tree
similarity index 100%
rename from gnome-initial-setup/pages/keyboard/pc105.tree
rename to gnome-initial-setup/pages/keyboard/detector-trees/C/pc105.tree
diff --git a/gnome-initial-setup/pages/keyboard/keyboard.gresource.xml 
b/gnome-initial-setup/pages/keyboard/keyboard.gresource.xml
index db34d78..73ed9d5 100644
--- a/gnome-initial-setup/pages/keyboard/keyboard.gresource.xml
+++ b/gnome-initial-setup/pages/keyboard/keyboard.gresource.xml
@@ -4,6 +4,6 @@
     <file preprocess="xml-stripblanks">gis-keyboard-page.ui</file>
     <file preprocess="xml-stripblanks">input-chooser.ui</file>
     <file preprocess="xml-stripblanks">keyboard-detector.ui</file>
-    <file>pc105.tree</file>
+    <file>detector-trees/C/pc105.tree</file>
   </gresource>
 </gresources>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]