[tracker/collation-gconf-locale: 6/15] tracker-locale: set locale envvar to the value retrieved from gconf
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/collation-gconf-locale: 6/15] tracker-locale: set locale envvar to the value retrieved from gconf
- Date: Thu, 28 Oct 2010 16:39:55 +0000 (UTC)
commit 30772877709531c11a3c91dc80c05527e9f79fc9
Author: Aleksander Morgado <aleksander lanedo com>
Date: Thu Oct 28 12:52:11 2010 +0200
tracker-locale: set locale envvar to the value retrieved from gconf
src/libtracker-common/tracker-locale.c | 75 ++++++++++++++++++++++++++------
1 files changed, 61 insertions(+), 14 deletions(-)
---
diff --git a/src/libtracker-common/tracker-locale.c b/src/libtracker-common/tracker-locale.c
index 5fbd712..3a78789 100644
--- a/src/libtracker-common/tracker-locale.c
+++ b/src/libtracker-common/tracker-locale.c
@@ -44,12 +44,19 @@ static GStaticMutex subscribers_mutex = G_STATIC_MUTEX_INIT;
#define UNLOCK_LOCALES
#endif /* HAVE_MAEMO */
-
/* Current locales in use. They will be stored in heap and available throughout
* the whole program execution, so will be reported as still reachable by Valgrind.
*/
static gchar *current_locales[TRACKER_LOCALE_LAST];
+static gchar *locale_names[TRACKER_LOCALE_LAST] = {
+ "TRACKER_LOCALE_LANGUAGE",
+ "TRACKER_LOCALE_TIME",
+ "TRACKER_LOCALE_COLLATE",
+ "TRACKER_LOCALE_NUMERIC",
+ "TRACKER_LOCALE_MONETARY"
+};
+
/* Already initialized? */
static gboolean initialized;
@@ -89,6 +96,50 @@ static GSList *subscribers;
* reachable by Valgrind */
static GConfClient *client;
+
+static void
+tracker_locale_set (TrackerLocaleID id,
+ const gchar *value)
+{
+ if (current_locales[id]) {
+ g_debug ("Locale '%s' was changed from '%s' to '%s'",
+ locale_names[id],
+ current_locales[id],
+ value);
+ g_free (current_locales[id]);
+ } else {
+ g_debug ("Locale '%s' was set to '%s'",
+ locale_names[id],
+ value);
+ }
+
+ /* Store the new one */
+ current_locales[id] = g_strdup (value);
+
+ /* And also set the new one in the corresponding envvar */
+ switch (id) {
+ case TRACKER_LOCALE_LANGUAGE:
+ g_setenv ("LANG", value, TRUE);
+ break;
+ case TRACKER_LOCALE_TIME:
+ setlocale (LC_TIME, value);
+ break;
+ case TRACKER_LOCALE_COLLATE:
+ setlocale (LC_COLLATE, value);
+ break;
+ case TRACKER_LOCALE_NUMERIC:
+ setlocale (LC_NUMERIC, value);
+ break;
+ case TRACKER_LOCALE_MONETARY:
+ setlocale (LC_MONETARY, value);
+ break;
+ case TRACKER_LOCALE_LAST:
+ /* Make compiler happy */
+ g_warn_if_reached ();
+ break;
+ }
+}
+
static void
tracker_locale_gconf_notify_cb (GConfClient *client,
guint cnxn_id,
@@ -130,13 +181,7 @@ tracker_locale_gconf_notify_cb (GConfClient *client,
/* Protect the locale change with the lock */
LOCK_LOCALES;
- /* Clean the previous value */
- g_free (current_locales[i]);
- /* And set the new one that got just notified */
- current_locales[i] = g_strdup (gconf_value_get_string (value));
- g_debug ("Locale '%s' was changed to '%s'",
- gconf_locales[i],
- current_locales[i]);
+ tracker_locale_set (i, gconf_value_get_string (value));
UNLOCK_LOCALES;
/* Now, if any subscriber, notify the locale change */
@@ -205,7 +250,8 @@ tracker_locale_init (void)
gconf_locales[i],
&error);
if (!val) {
- g_warning ("Couldn't get locale '%s' from gconf: '%s'"
+ g_warning ("Couldn't get value for key '%s'"
+ "from gconf: '%s'"
" Defaulting to environment locale.",
gconf_locales[i],
error ? error->message : "unknown error");
@@ -216,8 +262,8 @@ tracker_locale_init (void)
gconf_locales[i]);
gconf_value_free (val);
} else {
- /* dup the string */
- current_locales[i] = g_strdup (gconf_value_get_string (val));
+ /* Set the new locale */
+ tracker_locale_set (i, gconf_value_get_string (val));
gconf_value_free (val);
}
}
@@ -246,15 +292,16 @@ tracker_locale_init (void)
env_locale = setlocale (LC_MONETARY, NULL);
break;
case TRACKER_LOCALE_LAST:
- env_locale = NULL;
+ /* Make compiler happy. The for loop avoids
+ * this from happening. */
break;
}
if (!env_locale) {
g_warning ("Locale '%d' is not set, defaulting to C locale", i);
- current_locales[i] = g_strdup ("C");
+ tracker_locale_set (i, "C");
} else {
- current_locales[i] = g_strdup (env_locale);
+ tracker_locale_set (i, env_locale);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]