[gdm] Reload i18n file automatically



commit 66abe9674df6cd3ac41bf5485a82f536f4d8ed3f
Author: Takao Fujiwara <tfujiwar redhat com>
Date:   Mon Dec 21 13:31:33 2009 -0500

    Reload i18n file automatically
    
    This was fixed in gdm 2.20 by bug #384603.
    
    http://bugzilla.gnome.org/show_bug.cgi?id=599273

 configure.ac                 |    2 +-
 daemon/gdm-welcome-session.c |  103 ++++++++++++++++++++++++++++++++++++++++++
 daemon/gdm.in                |   13 -----
 3 files changed, 104 insertions(+), 14 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 987f3a7..e3deed8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -271,7 +271,7 @@ AC_ARG_WITH(lang-file,
 if test x$withval != x; then
 	LANG_CONFIG_FILE="$withval"
 else
-	LANG_CONFIG_FILE='${sysconfdir}/sysconfig/i18n'
+	LANG_CONFIG_FILE='$(sysconfdir)/sysconfig/i18n'
 fi
 AC_SUBST(LANG_CONFIG_FILE)
 
diff --git a/daemon/gdm-welcome-session.c b/daemon/gdm-welcome-session.c
index e113808..52395c0 100644
--- a/daemon/gdm-welcome-session.c
+++ b/daemon/gdm-welcome-session.c
@@ -238,6 +238,108 @@ close_welcome_session (GdmWelcomeSession *welcome_session)
         return ret;
 }
 
+static void
+load_lang_config_file (const gchar *config_file, const gchar **str_array)
+{
+        gchar         *contents = NULL;
+        gchar         *p;
+        gchar         *str_joinv;
+        gchar         *pattern;
+        gchar         *key;
+        gchar         *value;
+        gsize          length;
+        GError        *error;
+        GString       *line;
+        GRegex        *re;
+
+        g_return_if_fail (config_file != NULL);
+        g_return_if_fail (str_array != NULL);
+
+        if (!g_file_test (config_file, G_FILE_TEST_EXISTS)) {
+                g_debug ("Cannot access '%s'", config_file);
+                return;
+        }
+
+        error = NULL;
+        if (!g_file_get_contents (config_file, &contents, &length, &error)) {
+                g_debug ("Failed to parse '%s': %s",
+                         config_file,
+                         (error && error->message) ? error->message : "(null)");
+                g_error_free (error);
+                return;
+        }
+
+        if (!g_utf8_validate (contents, length, NULL)) {
+                g_warning ("Invalid UTF-8 in '%s'", config_file);
+                g_free (contents);
+                return;
+        }
+
+        str_joinv = g_strjoinv ("|", str_array);
+        if (str_joinv == NULL) {
+                g_warning ("Error in joined");
+                g_free (contents);
+                return;
+        }
+
+        pattern = g_strdup_printf ("(?P<key>(%s))=(\")?(?P<value>[^\"]*)?(\")?",
+                                   str_joinv);
+        error = NULL;
+        re = g_regex_new (pattern, 0, 0, &error);
+        g_free (pattern);
+        g_free (str_joinv);
+        if (re == NULL) {
+                g_warning ("Failed to regex: %s",
+                           (error && error->message) ? error->message : "(null)");
+                g_error_free (error);
+                g_free (contents);
+                return;
+        }
+
+        line = g_string_new ("");
+        for (p = contents; p && *p; p = g_utf8_find_next_char (p, NULL)) {
+                gunichar ch;
+                GMatchInfo *match_info = NULL;
+
+                ch = g_utf8_get_char (p);
+                if ((ch != '\n') && (ch != '\0')) {
+                        g_string_append_unichar (line, ch);
+                        continue;
+                }
+
+                if (line->str && g_utf8_get_char (line->str) == '#') {
+                        goto next_line;
+                }
+
+                if (!g_regex_match (re, line->str, 0, &match_info)) {
+                        goto next_line;
+                }
+
+                if (!g_match_info_matches (match_info)) {
+                        goto next_line;
+                }
+
+                key = g_match_info_fetch_named (match_info, "key");
+                value = g_match_info_fetch_named (match_info, "value");
+
+                if (key && *key && value && *value) {
+                        g_setenv (key, value, TRUE);
+                } else if (key && *key) {
+                        g_unsetenv (key);
+                }
+
+                g_free (key);
+                g_free (value);
+next_line:
+                g_match_info_free (match_info);
+                g_string_set_size (line, 0);
+        }
+
+        g_string_free (line, TRUE);
+        g_regex_unref (re);
+        g_free (contents);
+}
+
 static GPtrArray *
 get_welcome_environment (GdmWelcomeSession *welcome_session)
 {
@@ -253,6 +355,7 @@ get_welcome_environment (GdmWelcomeSession *welcome_session)
         };
         int i;
 
+        load_lang_config_file (LANG_CONFIG_FILE, optional_environment);
         env = g_ptr_array_new ();
 
         /* create a hash table of current environment, then update keys has necessary */
diff --git a/daemon/gdm.in b/daemon/gdm.in
index adf9cf0..16bad67 100644
--- a/daemon/gdm.in
+++ b/daemon/gdm.in
@@ -6,10 +6,6 @@
 
 test -f /etc/profile && . /etc/profile
 
-# Try to set LC_MESSAGES to LANG if neither LC_MESSAGES or LC_ALL is set.
-# This ensures that gdm can display in a system's default language if only
-# LANG is set.
-
 # Make sure LANG is set
 #
 if [ -z "$LANG" ]
@@ -21,14 +17,5 @@ then
   fi
 fi
 
-if [ -z "$LC_MESSAGES" ]
-then
-  if [ -z "$LC_ALL" ]
-  then
-    LC_MESSAGES=$LANG
-    export LC_MESSAGES
-  fi
-fi
-
 exec @sbindir@/gdm-binary "$@"
 



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