[gnome-initial-setup] language: Only show languages
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-initial-setup] language: Only show languages
- Date: Fri, 6 Dec 2013 22:53:54 +0000 (UTC)
commit a05658f123ff53ab298820f9156bde8eb8b8443b
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Dec 6 06:54:37 2013 +0100
language: Only show languages
Reduce the language chooser to show only languages. We still
select a full locale, but we will soon introduce a separate
region chooser which will allow to refine the choice of
region as a second step.
.../pages/language/cc-language-chooser.c | 84 +++++++++++++++-----
1 files changed, 63 insertions(+), 21 deletions(-)
---
diff --git a/gnome-initial-setup/pages/language/cc-language-chooser.c
b/gnome-initial-setup/pages/language/cc-language-chooser.c
index 80bcaf6..3aac3a8 100644
--- a/gnome-initial-setup/pages/language/cc-language-chooser.c
+++ b/gnome-initial-setup/pages/language/cc-language-chooser.c
@@ -42,6 +42,7 @@ struct _CcLanguageChooserPrivate
{
GtkWidget *filter_entry;
GtkWidget *language_list;
+ GHashTable *langs;
GtkWidget *scrolled_window;
GtkWidget *no_results;
@@ -108,33 +109,30 @@ language_widget_free (gpointer data)
static GtkWidget *
language_widget_new (const char *locale_id,
+ const char *lang,
gboolean is_extra)
{
gchar *locale_name, *locale_current_name, *locale_untranslated_name;
GtkWidget *checkmark;
LanguageWidget *widget = g_new0 (LanguageWidget, 1);
- locale_name = gnome_get_language_from_locale (locale_id, locale_id);
- locale_current_name = gnome_get_language_from_locale (locale_id, NULL);
- locale_untranslated_name = gnome_get_language_from_locale (locale_id, "C");
+ locale_name = gnome_get_language_from_locale (lang, locale_id);
+ locale_current_name = gnome_get_language_from_locale (lang, NULL);
+ locale_untranslated_name = gnome_get_language_from_locale (lang, "C");
widget->box = padded_label_new (locale_name);
+ gtk_widget_set_halign (widget->box, GTK_ALIGN_FILL);
+ gtk_widget_set_margin_start (widget->box, 10);
+ gtk_widget_set_margin_end (widget->box, 10);
widget->locale_id = g_strdup (locale_id);
widget->locale_name = locale_name;
widget->locale_current_name = locale_current_name;
widget->locale_untranslated_name = locale_untranslated_name;
widget->is_extra = is_extra;
- /* We add a check on each side of the label to keep it centered. */
- checkmark = gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_MENU);
- gtk_widget_show (checkmark);
- gtk_widget_set_opacity (checkmark, 0.0);
- gtk_box_pack_start (GTK_BOX (widget->box), checkmark, FALSE, FALSE, 0);
- gtk_box_reorder_child (GTK_BOX (widget->box), checkmark, 0);
-
widget->checkmark = gtk_image_new_from_icon_name ("object-select-symbolic", GTK_ICON_SIZE_MENU);
- gtk_box_pack_start (GTK_BOX (widget->box), widget->checkmark,
- FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (widget->box), widget->checkmark, TRUE, TRUE, 0);
+ gtk_widget_set_halign (widget->checkmark, GTK_ALIGN_END);
gtk_widget_show (widget->checkmark);
g_object_set_data_full (G_OBJECT (widget->box), "language-widget", widget,
@@ -202,27 +200,58 @@ no_results_widget_new (void)
}
static void
+add_one_language (CcLanguageChooser *chooser,
+ const char *locale_id,
+ gboolean is_initial)
+{
+ CcLanguageChooserPrivate *priv = cc_language_chooser_get_instance_private (chooser);
+ GtkWidget *widget;
+ gchar *lang;
+
+ if (!g_str_has_suffix (locale_id, "utf8")) {
+ return;
+ }
+
+ if (!cc_common_language_has_font (locale_id)) {
+ return;
+ }
+
+ if (!gnome_parse_locale (locale_id, &lang, NULL, NULL, NULL)) {
+ return;
+ }
+
+ if (g_hash_table_contains (priv->langs, lang)) {
+ g_free (lang);
+ return;
+ }
+ g_hash_table_add (priv->langs, lang);
+
+ widget = language_widget_new (locale_id, lang, !is_initial);
+ gtk_container_add (GTK_CONTAINER (priv->language_list), widget);
+ g_free (lang);
+}
+
+static void
add_languages (CcLanguageChooser *chooser,
char **locale_ids,
GHashTable *initial)
{
CcLanguageChooserPrivate *priv = cc_language_chooser_get_instance_private (chooser);
+ GHashTableIter iter;
+ gchar *key;
+
+ g_hash_table_iter_init (&iter, initial);
+ while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL)) {
+ add_one_language (chooser, key, TRUE);
+ }
while (*locale_ids) {
const gchar *locale_id;
- gboolean is_initial;
- GtkWidget *widget;
locale_id = *locale_ids;
locale_ids ++;
- if (!cc_common_language_has_font (locale_id))
- continue;
-
- is_initial = (g_hash_table_lookup (initial, locale_id) != NULL);
- widget = language_widget_new (locale_id, !is_initial);
-
- gtk_container_add (GTK_CONTAINER (priv->language_list), widget);
+ add_one_language (chooser, locale_id, FALSE);
}
gtk_container_add (GTK_CONTAINER (priv->language_list), priv->more_item);
@@ -400,6 +429,7 @@ cc_language_chooser_constructed (GObject *object)
G_OBJECT_CLASS (cc_language_chooser_parent_class)->constructed (object);
+ priv->langs = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
priv->more_item = more_widget_new ();
priv->no_results = no_results_widget_new ();
@@ -427,6 +457,17 @@ cc_language_chooser_constructed (GObject *object)
}
static void
+cc_language_chooser_finalize (GObject *object)
+{
+ CcLanguageChooser *chooser = CC_LANGUAGE_CHOOSER (object);
+ CcLanguageChooserPrivate *priv = cc_language_chooser_get_instance_private (chooser);
+
+ g_hash_table_unref (priv->langs);
+
+ G_OBJECT_CLASS (cc_language_chooser_parent_class)->finalize (object);
+}
+
+static void
cc_language_chooser_get_property (GObject *object,
guint prop_id,
GValue *value,
@@ -474,6 +515,7 @@ cc_language_chooser_class_init (CcLanguageChooserClass *klass)
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), CcLanguageChooser,
language_list);
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), CcLanguageChooser,
scrolled_window);
+ object_class->finalize = cc_language_chooser_finalize;
object_class->get_property = cc_language_chooser_get_property;
object_class->set_property = cc_language_chooser_set_property;
object_class->constructed = cc_language_chooser_constructed;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]