From decdfe42f12a8a13f11c16726590c717b8b6e776 Mon Sep 17 00:00:00 2001 From: Guido Berhoerster Date: Tue, 16 Apr 2013 09:29:26 +0200 Subject: Fix saving/retrieving of the language setting Add user_get_language() for retrieving the language setting. Remove unused user_get_locale(). Always save the language to both accountsservice and dmrc. Actually retrieve the language setting and export the locale via LANG and GDM_LANG environment variables. --- src/accounts.c | 67 ++++++++++++++++++++++++++++++++++++++-------------------- src/accounts.h | 2 +- src/display.c | 9 ++++++++ 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/src/accounts.c b/src/accounts.c index e974c543..5be23981 100644 --- a/src/accounts.c +++ b/src/accounts.c @@ -44,9 +44,6 @@ struct UserPrivate /* Language */ gchar *language; - /* Locale */ - gchar *locale; - /* X session */ gchar *xsession; }; @@ -332,36 +329,59 @@ user_get_shell (User *user) return user->priv->shell; } +void +user_set_language (User *user, const gchar *language) +{ + g_return_if_fail (user != NULL); + + call_method (user->priv->proxy, "SetLanguage", g_variant_new ("(s)", language), "()", NULL); + save_string_to_dmrc (user->priv->name, "Desktop", "Language", language); +} + const gchar * -user_get_locale (User *user) +user_get_language (User *user) { + GVariant *variant, *inner; + gboolean success; + g_return_val_if_fail (user != NULL, NULL); - g_free (user->priv->locale); + g_free (user->priv->language); if (user->priv->proxy) - user->priv->locale = NULL; + { + /* get_property () uses g_dbus_proxy_get_cached_property () which would + * return the previous (cached) value of the "Language" property */ +#if 0 + if (get_property (user->priv->proxy, "Language", "s", &variant)) + { + g_variant_get (variant, "s", &user->priv->language); + g_variant_unref (variant); + } + else + user->priv->language = NULL; +#endif + success = call_method (user->priv->proxy, "org.freedesktop.DBus.Properties.Get", g_variant_new ("(ss)", g_dbus_proxy_get_interface_name(user->priv->proxy), "Language"), "(v)", &variant); + if (success) + { + g_variant_get (variant, "(v)", &inner); + user->priv->language = g_variant_dup_string (inner, NULL); + g_variant_unref (inner); + g_variant_unref (variant); + } + else + user->priv->language = NULL; + } else - user->priv->locale = get_string_from_dmrc (user->priv->name, "Desktop", "Language"); + user->priv->language = get_string_from_dmrc (user->priv->name, "Desktop", "Language"); - /* Treat a blank locale as unset */ - if (g_strcmp0 (user->priv->locale, "") == 0) + /* Treat a blank language as unset */ + if (g_strcmp0 (user->priv->language, "") == 0) { - g_free (user->priv->locale); - user->priv->locale = NULL; + g_free (user->priv->language); + user->priv->language = NULL; } - return user->priv->locale; -} - -void -user_set_language (User *user, const gchar *language) -{ - g_return_if_fail (user != NULL); - - if (user->priv->proxy) - call_method (user->priv->proxy, "SetLanguage", g_variant_new ("(s)", language), "()", NULL); - else - save_string_to_dmrc (user->priv->name, "Desktop", "Language", language); + return user->priv->language; } void @@ -436,6 +456,7 @@ user_finalize (GObject *object) g_free (self->priv->gecos); g_free (self->priv->home_directory); g_free (self->priv->shell); + g_free (self->priv->language); G_OBJECT_CLASS (user_parent_class)->finalize (object); } diff --git a/src/accounts.h b/src/accounts.h index 8bd52479..5e1264f2 100644 --- a/src/accounts.h +++ b/src/accounts.h @@ -58,7 +58,7 @@ const gchar *user_get_xsession (User *user); void user_set_xsession (User *user, const gchar *session); -const gchar *user_get_locale (User *user); +const gchar *user_get_language (User *user); void user_set_language (User *user, const gchar *language); diff --git a/src/display.c b/src/display.c index 92c25dba..c935571f 100644 --- a/src/display.c +++ b/src/display.c @@ -702,6 +702,7 @@ display_start_session (Display *display) { User *user; gchar *filename, *sessions_dir, *path; + const gchar *language; gchar **argv; user = session_get_user (display->priv->session); @@ -725,6 +726,14 @@ display_start_session (Display *display) if (!argv) return TRUE; + /* Retrieve language setting */ + language = user_get_language (user); + if (language != NULL && language != '\0') + { + session_set_env (display->priv->session, "LANG", language); + session_set_env (display->priv->session, "GDM_LANG", language); + } + session_set_env (display->priv->session, "DESKTOP_SESSION", display->priv->user_session); // FIXME: Apparently deprecated? session_set_env (display->priv->session, "GDMSESSION", display->priv->user_session); // FIXME: Not cross-desktop -- cgit v1.2.1