[gnome-control-center] common: Add a region mode to the language chooser
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] common: Add a region mode to the language chooser
- Date: Mon, 22 Aug 2011 18:31:07 +0000 (UTC)
commit 9e027939829d7dbb5598df26fd4abad8f7cb5448
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Aug 22 13:50:46 2011 -0400
common: Add a region mode to the language chooser
In this mode, locales are primarily represented by their
region component, instead of their language component.
panels/common/cc-common-language.c | 48 ++++++++++++++++++++++++++++++-
panels/common/cc-common-language.h | 2 +
panels/common/cc-language-chooser.c | 16 +++++++++-
panels/common/cc-language-chooser.h | 3 +-
panels/region/gnome-region-panel-lang.c | 2 +-
panels/user-accounts/um-user-panel.c | 2 +-
6 files changed, 67 insertions(+), 6 deletions(-)
---
diff --git a/panels/common/cc-common-language.c b/panels/common/cc-common-language.c
index 1cb9da0..54ac5a1 100644
--- a/panels/common/cc-common-language.c
+++ b/panels/common/cc-common-language.c
@@ -208,6 +208,7 @@ typedef struct
GtkListStore *store;
GHashTable *user_langs;
gchar **languages;
+ gboolean regions;
gint position;
} AsyncLangData;
@@ -245,7 +246,12 @@ add_one_language (gpointer d)
goto next;
}
- language = gdm_get_language_from_name (name, NULL);
+ if (data->regions) {
+ language = gdm_get_region_from_name (name, NULL);
+ }
+ else {
+ language = gdm_get_language_from_name (name, NULL);
+ }
if (!language) {
g_debug ("Ignoring '%s' as a locale, because we couldn't figure the language name", name);
g_free (name);
@@ -280,6 +286,7 @@ add_one_language (gpointer d)
guint
cc_common_language_add_available_languages (GtkListStore *store,
+ gboolean regions,
GHashTable *user_langs)
{
AsyncLangData *data;
@@ -289,6 +296,7 @@ cc_common_language_add_available_languages (GtkListStore *store,
data->store = g_object_ref (store);
data->user_langs = g_hash_table_ref (user_langs);
data->languages = gdm_get_all_language_names ();
+ data->regions = regions;
data->position = 0;
return gdk_threads_add_idle (add_one_language, data);
@@ -521,3 +529,41 @@ cc_common_language_get_initial_languages (void)
return ht;
}
+
+GHashTable *
+cc_common_language_get_initial_regions (const gchar *lang)
+{
+ GHashTable *ht;
+ char *language;
+ gchar **langs;
+ gint i;
+
+ ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+
+#if 0
+ /* Add some common regions */
+ g_hash_table_insert (ht, g_strdup ("en_US.utf8"), g_strdup (_("United States")));
+ g_hash_table_insert (ht, g_strdup ("de_DE.utf8"), g_strdup (_("Germany")));
+ g_hash_table_insert (ht, g_strdup ("fr_FR.utf8"), g_strdup (_("France")));
+ g_hash_table_insert (ht, g_strdup ("es_ES.utf8"), g_strdup (_("Spain")));
+ g_hash_table_insert (ht, g_strdup ("zh_CN.utf8"), g_strdup (_("China")));
+#endif
+
+ gdm_parse_language_name (lang, &language, NULL, NULL, NULL);
+ langs = gdm_get_all_language_names ();
+ for (i = 0; langs[i]; i++) {
+ gchar *l, *s;
+ gdm_parse_language_name (langs[i], &l, NULL, NULL, NULL);
+ if (g_strcmp0 (language, l) == 0) {
+ if (!g_hash_table_lookup (ht, langs[i])) {
+ s = gdm_get_region_from_name (langs[i], NULL);
+ g_hash_table_insert (ht, g_strdup (langs[i]), s);
+ }
+ }
+ g_free (l);
+ }
+ g_strfreev (langs);
+ g_free (language);
+
+ return ht;
+}
diff --git a/panels/common/cc-common-language.h b/panels/common/cc-common-language.h
index a242885..169eee4 100644
--- a/panels/common/cc-common-language.h
+++ b/panels/common/cc-common-language.h
@@ -41,11 +41,13 @@ gboolean cc_common_language_get_iter_for_region (GtkTreeModel *model,
const gchar *lang,
GtkTreeIter *iter);
guint cc_common_language_add_available_languages (GtkListStore *store,
+ gboolean regions,
GHashTable *user_langs);
gboolean cc_common_language_has_font (const gchar *locale);
gchar *cc_common_language_get_current_language (void);
GHashTable *cc_common_language_get_initial_languages (void);
+GHashTable *cc_common_language_get_initial_regions (const gchar *lang);
void cc_common_language_setup_list (GtkWidget *treeview,
GHashTable *initial);
diff --git a/panels/common/cc-language-chooser.c b/panels/common/cc-language-chooser.c
index b6cbb25..e81746e 100644
--- a/panels/common/cc-language-chooser.c
+++ b/panels/common/cc-language-chooser.c
@@ -157,17 +157,20 @@ finish_language_chooser (gpointer user_data)
guint timeout;
guint async_id;
GtkTreeSelection *selection;
+ gboolean regions;
/* Did we get called after the widget was destroyed? */
if (chooser == NULL)
return FALSE;
+ regions = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (chooser), "regions"));
+
list = g_object_get_data (G_OBJECT (chooser), "list");
model = gtk_tree_view_get_model (GTK_TREE_VIEW (list));
model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
user_langs = g_object_get_data (G_OBJECT (chooser), "user-langs");
- async_id = cc_common_language_add_available_languages (GTK_LIST_STORE (model), user_langs);
+ async_id = cc_common_language_add_available_languages (GTK_LIST_STORE (model), regions, user_langs);
g_object_set_data_full (G_OBJECT (chooser), "language-async", GUINT_TO_POINTER (async_id), remove_async);
parent = gtk_window_get_transient_for (GTK_WINDOW (chooser));
@@ -254,7 +257,7 @@ filter_languages (GtkTreeModel *model,
}
GtkWidget *
-cc_language_chooser_new (GtkWidget *parent)
+cc_language_chooser_new (GtkWidget *parent, gboolean regions)
{
GtkBuilder *builder;
const char *filename;
@@ -263,6 +266,7 @@ cc_language_chooser_new (GtkWidget *parent)
GtkWidget *list;
GtkWidget *button;
GtkWidget *entry;
+ GtkWidget *widget;
GHashTable *user_langs;
GdkCursor *cursor;
guint timeout;
@@ -281,6 +285,14 @@ cc_language_chooser_new (GtkWidget *parent)
chooser = (GtkWidget *) gtk_builder_get_object (builder, "dialog");
+ if (regions) {
+ widget = (GtkWidget *) gtk_builder_get_object (builder, "title");
+ gtk_label_set_text (GTK_LABEL (widget), _("Select a region"));
+
+ /* communicate the preference to finish_language_chooser() */
+ g_object_set_data (G_OBJECT (chooser), "regions", GINT_TO_POINTER (TRUE));
+ }
+
list = (GtkWidget *) gtk_builder_get_object (builder, "language-list");
g_object_set_data (G_OBJECT (chooser), "list", list);
g_signal_connect (list, "row-activated",
diff --git a/panels/common/cc-language-chooser.h b/panels/common/cc-language-chooser.h
index 4929436..7cd6873 100644
--- a/panels/common/cc-language-chooser.h
+++ b/panels/common/cc-language-chooser.h
@@ -28,7 +28,8 @@ G_BEGIN_DECLS
void cc_add_user_languages (GtkTreeModel *model);
-GtkWidget *cc_language_chooser_new (GtkWidget *parent);
+GtkWidget *cc_language_chooser_new (GtkWidget *parent,
+ gboolean regions);
void cc_language_chooser_clear_filter (GtkWidget *chooser);
gchar *cc_language_chooser_get_language (GtkWidget *chooser);
diff --git a/panels/region/gnome-region-panel-lang.c b/panels/region/gnome-region-panel-lang.c
index fc1452d..8ba0e39 100644
--- a/panels/region/gnome-region-panel-lang.c
+++ b/panels/region/gnome-region-panel-lang.c
@@ -161,7 +161,7 @@ add_language (GtkWidget *button, GtkWidget *treeview)
toplevel = gtk_widget_get_toplevel (button);
chooser = g_object_get_data (G_OBJECT (button), "chooser");
if (chooser == NULL) {
- chooser = cc_language_chooser_new (toplevel);
+ chooser = cc_language_chooser_new (toplevel, FALSE);
g_signal_connect (chooser, "response",
G_CALLBACK (language_response), treeview);
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index 26efdcc..9717128 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -720,7 +720,7 @@ language_changed (UmEditableCombo *combo,
return;
}
- d->language_chooser = cc_language_chooser_new (gtk_widget_get_toplevel (d->main_box));
+ d->language_chooser = cc_language_chooser_new (gtk_widget_get_toplevel (d->main_box), FALSE);
g_signal_connect (d->language_chooser, "response",
G_CALLBACK (language_response), d);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]