[gnome-initial-setup] Use gnome-desktop instead of our own gdm-languages
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup] Use gnome-desktop instead of our own gdm-languages
- Date: Mon, 25 Feb 2013 19:37:13 +0000 (UTC)
commit fe2479619e341cb8cdec142bcb25cbe3b94140db
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Feb 20 14:56:56 2013 -0500
Use gnome-desktop instead of our own gdm-languages
Also, update our copy of cc-common-language
configure.ac | 3 +-
gnome-initial-setup/Makefile.am | 2 -
gnome-initial-setup/gdm-languages.c | 1327 --------------------
gnome-initial-setup/gdm-languages.h | 45 -
gnome-initial-setup/locarchive.h | 97 --
.../pages/keyboard/gnome-region-panel-input.c | 1 -
.../pages/language/cc-common-language.c | 192 +++-
.../pages/language/gis-language-page.c | 16 +-
8 files changed, 152 insertions(+), 1531 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d8ba3ae..554e3cb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,6 +20,7 @@ GTK_REQUIRED_VERSION=3.7.7
CLUTTER_REQUIRED_VERSION=1.11.3
PANGO_REQUIRED_VERSION=1.32.5
IBUS_REQUIRED_VERSION=1.4.99
+GNOME_DESKTOP_REQUIRED_VERSION=3.7.5
# EggListBox submodule
prev_top_build_prefix=$ac_top_build_prefix
@@ -36,7 +37,7 @@ PKG_CHECK_MODULES(INITIAL_SETUP,
libnm-util >= $NETWORK_MANAGER_REQUIRED_VERSION
libnm-gtk >= $NETWORK_MANAGER_REQUIRED_VERSION
accountsservice
- gnome-desktop-3.0
+ gnome-desktop-3.0 >= $GNOME_DESKTOP_REQUIRED_VERSION
gstreamer-1.0
fontconfig
gweather-3.0
diff --git a/gnome-initial-setup/Makefile.am b/gnome-initial-setup/Makefile.am
index 169884c..dd5702d 100644
--- a/gnome-initial-setup/Makefile.am
+++ b/gnome-initial-setup/Makefile.am
@@ -13,8 +13,6 @@ libexec_PROGRAMS = gnome-initial-setup gnome-initial-setup-copy-worker
gnome_initial_setup_SOURCES = \
gnome-initial-setup.c gnome-initial-setup.h \
- gdm-languages.c gdm-languages.h \
- locarchive.h \
gis-assistant.c gis-assistant.h gis-assistant-private.h \
gis-assistant-gtk.c gis-assistant-gtk.h \
gis-page.c gis-page.h \
diff --git a/gnome-initial-setup/pages/keyboard/gnome-region-panel-input.c
b/gnome-initial-setup/pages/keyboard/gnome-region-panel-input.c
index f61c883..3cc739a 100644
--- a/gnome-initial-setup/pages/keyboard/gnome-region-panel-input.c
+++ b/gnome-initial-setup/pages/keyboard/gnome-region-panel-input.c
@@ -34,7 +34,6 @@
#include <ibus.h>
#endif
-#include "gdm-languages.h"
#include "gnome-region-panel-input.h"
#define WID(s) GTK_WIDGET(gtk_builder_get_object (builder, s))
diff --git a/gnome-initial-setup/pages/language/cc-common-language.c
b/gnome-initial-setup/pages/language/cc-common-language.c
index def1f06..a2acb33 100644
--- a/gnome-initial-setup/pages/language/cc-common-language.c
+++ b/gnome-initial-setup/pages/language/cc-common-language.c
@@ -2,10 +2,10 @@
*
* Copyright 2009-2010 Red Hat, Inc,
*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -14,8 +14,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Written by: Matthias Clasen <mclasen redhat com>
*/
@@ -31,9 +30,12 @@
#include <fontconfig/fontconfig.h>
+#define GNOME_DESKTOP_USE_UNSTABLE_API
+#include <libgnome-desktop/gnome-languages.h>
+
#include "cc-common-language.h"
-#include "gdm-languages.h"
+static char *get_lang_for_user_object_path (const char *path);
gboolean
cc_common_language_has_font (const gchar *locale)
@@ -50,7 +52,7 @@ cc_common_language_has_font (const gchar *locale)
object_set = NULL;
font_set = NULL;
- if (!gdm_parse_language_name (locale, &language_code, NULL, NULL, NULL))
+ if (!gnome_parse_locale (locale, &language_code, NULL, NULL, NULL))
return FALSE;
charset = FcLangGetCharSet ((FcChar8 *) language_code);
@@ -97,17 +99,76 @@ gchar *
cc_common_language_get_current_language (void)
{
gchar *language;
+ char *path;
const gchar *locale;
+ path = g_strdup_printf ("/org/freedesktop/Accounts/User%d", getuid ());
+ language = get_lang_for_user_object_path (path);
+ g_free (path);
+ if (language != NULL && *language != '\0')
+ return language;
+
locale = (const gchar *) setlocale (LC_MESSAGES, NULL);
if (locale)
- language = gdm_normalize_language_name (locale);
+ language = gnome_normalize_locale (locale);
else
language = NULL;
return language;
}
+static gboolean
+user_language_has_translations (const char *locale)
+{
+ char *name, *language_code, *territory_code;
+ gboolean ret;
+
+ gnome_parse_locale (locale,
+ &language_code,
+ &territory_code,
+ NULL, NULL);
+ name = g_strdup_printf ("%s%s%s",
+ language_code,
+ territory_code != NULL? "_" : "",
+ territory_code != NULL? territory_code : "");
+ g_free (language_code);
+ g_free (territory_code);
+ ret = gnome_language_has_translations (name);
+ g_free (name);
+
+ return ret;
+}
+
+static char *
+get_lang_for_user_object_path (const char *path)
+{
+ GError *error = NULL;
+ GDBusProxy *user;
+ GVariant *props;
+ char *lang;
+
+ user = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.Accounts",
+ path,
+ "org.freedesktop.Accounts.User",
+ NULL,
+ &error);
+ if (user == NULL) {
+ g_warning ("Failed to get proxy for user '%s': %s",
+ path, error->message);
+ g_error_free (error);
+ return NULL;
+ }
+ props = g_dbus_proxy_get_cached_property (user, "Language");
+ lang = g_variant_dup_string (props, NULL);
+
+ g_variant_unref (props);
+ g_object_unref (user);
+ return lang;
+}
+
static void
add_other_users_language (GHashTable *ht)
{
@@ -144,43 +205,24 @@ add_other_users_language (GHashTable *ht)
}
g_variant_get (variant, "(ao)", &vi);
while (g_variant_iter_loop (vi, "o", &str)) {
- GDBusProxy *user;
- GVariant *props;
- const char *lang;
+ char *lang;
char *name;
char *language;
- user = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- NULL,
- "org.freedesktop.Accounts",
- str,
- "org.freedesktop.Accounts.User",
- NULL,
- &error);
- if (user == NULL) {
- g_warning ("Failed to get proxy for user '%s': %s",
- str, error->message);
- g_error_free (error);
- error = NULL;
- continue;
- }
- props = g_dbus_proxy_get_cached_property (user, "Language");
- lang = g_variant_get_string (props, NULL);
+ lang = get_lang_for_user_object_path (str);
if (lang != NULL && *lang != '\0' &&
cc_common_language_has_font (lang) &&
- gdm_language_has_translations (lang)) {
- name = gdm_normalize_language_name (lang);
+ user_language_has_translations (lang)) {
+ name = gnome_normalize_locale (lang);
if (!g_hash_table_lookup (ht, name)) {
- language = gdm_get_language_from_name (name, NULL);
+ language = gnome_get_language_from_locale (name, NULL);
g_hash_table_insert (ht, name, language);
}
else {
g_free (name);
}
}
- g_variant_unref (props);
- g_object_unref (user);
+ g_free (lang);
}
g_variant_iter_free (vi);
g_variant_unref (variant);
@@ -188,38 +230,86 @@ add_other_users_language (GHashTable *ht)
g_object_unref (proxy);
}
+static void
+insert_language (GHashTable *ht,
+ const char *lang)
+{
+ gboolean has_translations;
+ char *label_own_lang;
+ char *label_current_lang;
+ char *label_untranslated;
+ char *key;
+
+ has_translations = gnome_language_has_translations (lang);
+ if (!has_translations) {
+ char *lang_code = g_strndup (lang, 2);
+ has_translations = gnome_language_has_translations (lang_code);
+ g_free (lang_code);
+
+ if (!has_translations)
+ return;
+ }
+
+ g_debug ("We have translations for %s", lang);
+
+ key = g_strdup_printf ("%s.utf8", lang);
+
+ label_own_lang = gnome_get_language_from_locale (key, key);
+ label_current_lang = gnome_get_language_from_locale (key, NULL);
+ label_untranslated = gnome_get_language_from_locale (key, "C");
+
+ /* We don't have a translation for the label in
+ * its own language? */
+ if (g_strcmp0 (label_own_lang, label_untranslated) == 0) {
+ if (g_strcmp0 (label_current_lang, label_untranslated) == 0)
+ g_hash_table_insert (ht, key, g_strdup (label_untranslated));
+ else
+ g_hash_table_insert (ht, key, g_strdup (label_current_lang));
+ } else {
+ g_hash_table_insert (ht, key, g_strdup (label_own_lang));
+ }
+
+ g_free (label_own_lang);
+ g_free (label_current_lang);
+ g_free (label_untranslated);
+}
+
GHashTable *
cc_common_language_get_initial_languages (void)
{
GHashTable *ht;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+ insert_language (ht, "en_US");
+ insert_language (ht, "en_GB");
+ insert_language (ht, "de_DE");
+ insert_language (ht, "fr_FR");
+ insert_language (ht, "es_ES");
+ insert_language (ht, "zh_CN");
+ insert_language (ht, "ja_JP");
+ insert_language (ht, "ru_RU");
+ insert_language (ht, "ar_EG");
+
+ return ht;
+}
+
+GHashTable *
+cc_common_language_get_user_languages (void)
+{
+ GHashTable *ht;
char *name;
char *language;
ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- /* Add some common languages first */
- g_hash_table_insert (ht, g_strdup ("en_US.utf8"), g_strdup (_("English")));
- if (gdm_language_has_translations ("en_GB"))
- g_hash_table_insert (ht, g_strdup ("en_GB.utf8"), g_strdup (_("British English")));
- if (gdm_language_has_translations ("de") ||
- gdm_language_has_translations ("de_DE"))
- g_hash_table_insert (ht, g_strdup ("de_DE.utf8"), g_strdup (_("German")));
- if (gdm_language_has_translations ("fr") ||
- gdm_language_has_translations ("fr_FR"))
- g_hash_table_insert (ht, g_strdup ("fr_FR.utf8"), g_strdup (_("French")));
- if (gdm_language_has_translations ("es") ||
- gdm_language_has_translations ("es_ES"))
- g_hash_table_insert (ht, g_strdup ("es_ES.utf8"), g_strdup (_("Spanish")));
- if (gdm_language_has_translations ("zh_CN"))
- g_hash_table_insert (ht, g_strdup ("zh_CN.utf8"), g_strdup (_("Chinese (simplified)")));
-
/* Add the languages used by other users on the system */
add_other_users_language (ht);
/* Add current locale */
name = cc_common_language_get_current_language ();
if (g_hash_table_lookup (ht, name) == NULL) {
- language = gdm_get_language_from_name (name, NULL);
+ language = gnome_get_language_from_locale (name, NULL);
g_hash_table_insert (ht, name, language);
} else {
g_free (name);
diff --git a/gnome-initial-setup/pages/language/gis-language-page.c
b/gnome-initial-setup/pages/language/gis-language-page.c
index 1585172..66730a9 100644
--- a/gnome-initial-setup/pages/language/gis-language-page.c
+++ b/gnome-initial-setup/pages/language/gis-language-page.c
@@ -35,8 +35,10 @@
#include <gtk/gtk.h>
+#define GNOME_DESKTOP_USE_UNSTABLE_API
+#include <libgnome-desktop/gnome-languages.h>
+
#include "cc-common-language.h"
-#include "gdm-languages.h"
#include <glib-object.h>
@@ -118,7 +120,7 @@ sort_languages (gconstpointer a,
}
static char *
-use_language (char *locale_id)
+use_language (const char *locale_id)
{
char *current_locale_id;
char *use, *language;
@@ -133,7 +135,7 @@ use_language (char *locale_id)
setlocale (LC_MESSAGES, current_locale_id);
g_free (current_locale_id);
- language = gdm_get_language_from_name (locale_id, locale_id);
+ language = gnome_get_language_from_locale (locale_id, locale_id);
return g_strdup_printf (use, language);
}
@@ -174,8 +176,8 @@ language_widget_sync_show_checkmark (LanguageWidget *widget)
}
static GtkWidget *
-language_widget_new (char *locale_id,
- gboolean is_extra)
+language_widget_new (const char *locale_id,
+ gboolean is_extra)
{
gchar *locale_name;
LanguageWidget *widget = g_new0 (LanguageWidget, 1);
@@ -225,7 +227,7 @@ add_languages (GisLanguagePage *page,
priv->adding_languages = TRUE;
while (*locale_ids) {
- gchar *locale_id;
+ const gchar *locale_id;
gboolean is_extra;
GtkWidget *widget;
@@ -257,7 +259,7 @@ add_languages (GisLanguagePage *page,
static void
add_all_languages (GisLanguagePage *page)
{
- char **locale_ids = gdm_get_all_language_names ();
+ char **locale_ids = gnome_get_all_locales ();
GHashTable *initial = cc_common_language_get_initial_languages ();
add_languages (page, locale_ids, initial);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]