[gnome-initial-setup] language: Switch the "Welcome!" to the new language when the user selects it



commit 400075167f7cfa3f483ee41f4697f13d2e05252d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Dec 8 21:50:01 2013 -0500

    language: Switch the "Welcome!" to the new language when the user selects it
    
    Just as a nice touch...

 gnome-initial-setup/gis-driver.c                   |    5 +-
 .../pages/language/gis-language-page.c             |    5 ++
 .../pages/language/gis-welcome-widget.c            |   50 ++++++++++++++++---
 .../pages/language/gis-welcome-widget.h            |    7 ++-
 4 files changed, 54 insertions(+), 13 deletions(-)
---
diff --git a/gnome-initial-setup/gis-driver.c b/gnome-initial-setup/gis-driver.c
index f13fc63..b508450 100644
--- a/gnome-initial-setup/gis-driver.c
+++ b/gnome-initial-setup/gis-driver.c
@@ -110,11 +110,10 @@ prepare_main_window (GisDriver *driver)
                            gis_assistant_get_titlebar (priv->assistant));
 }
 
-static gboolean
+static void
 rebuild_pages (GisDriver *driver)
 {
   g_signal_emit (G_OBJECT (driver), signals[REBUILD_PAGES], 0);
-  return FALSE;
 }
 
 GisAssistant *
@@ -171,7 +170,7 @@ static void
 gis_driver_real_locale_changed (GisDriver *driver)
 {
   GisDriverPrivate *priv = gis_driver_get_instance_private (driver);
-  g_idle_add ((GSourceFunc) rebuild_pages, driver);
+  rebuild_pages (driver);
   gis_assistant_locale_changed (priv->assistant);
 }
 
diff --git a/gnome-initial-setup/pages/language/gis-language-page.c 
b/gnome-initial-setup/pages/language/gis-language-page.c
index 34b1599..c5c98e0 100644
--- a/gnome-initial-setup/pages/language/gis-language-page.c
+++ b/gnome-initial-setup/pages/language/gis-language-page.c
@@ -41,6 +41,7 @@
 
 struct _GisLanguagePagePrivate
 {
+  GtkWidget *welcome_widget;
   GtkWidget *language_chooser;
 
   GDBusProxy *localed;
@@ -144,6 +145,9 @@ language_changed (CcLanguageChooser  *chooser,
                       g_strdup (priv->new_locale_id));
 
   gis_driver_set_user_language (driver, priv->new_locale_id);
+
+  gis_welcome_widget_show_locale (GIS_WELCOME_WIDGET (priv->welcome_widget),
+                                  priv->new_locale_id);
 }
 
 static void
@@ -231,6 +235,7 @@ gis_language_page_class_init (GisLanguagePageClass *klass)
 
   gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), 
"/org/gnome/initial-setup/gis-language-page.ui");
 
+  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisLanguagePage, welcome_widget);
   gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisLanguagePage, language_chooser);
 
   page_class->page_id = PAGE_ID;
diff --git a/gnome-initial-setup/pages/language/gis-welcome-widget.c 
b/gnome-initial-setup/pages/language/gis-welcome-widget.c
index 1c12ffe..5e9a6c5 100644
--- a/gnome-initial-setup/pages/language/gis-welcome-widget.c
+++ b/gnome-initial-setup/pages/language/gis-welcome-widget.c
@@ -32,6 +32,7 @@
 struct _GisWelcomeWidgetPrivate
 {
   GtkWidget *stack;
+  GHashTable *translation_widgets;
 
   guint timeout_id;
 };
@@ -163,14 +164,15 @@ fill_stack (GisWelcomeWidget *widget)
         continue;
 
       text = welcome (locale_id);
-      if (g_hash_table_contains (added_translations, text))
-        continue;
-
-      label = big_label (text);
-      gtk_container_add (GTK_CONTAINER (priv->stack), label);
-      gtk_widget_show (label);
-
-      g_hash_table_add (added_translations, text);
+      label = g_hash_table_lookup (added_translations, text);
+      if (label == NULL) {
+        label = big_label (text);
+        gtk_container_add (GTK_CONTAINER (priv->stack), label);
+        gtk_widget_show (label);
+        g_hash_table_insert (added_translations, text, label);
+      }
+
+      g_hash_table_insert (priv->translation_widgets, locale_id, label);
     }
 
   g_hash_table_destroy (added_translations);
@@ -183,6 +185,17 @@ gis_welcome_widget_constructed (GObject *object)
 }
 
 static void
+gis_welcome_widget_dispose (GObject *object)
+{
+  GisWelcomeWidget *widget = GIS_WELCOME_WIDGET (object);
+  GisWelcomeWidgetPrivate *priv = gis_welcome_widget_get_instance_private (widget);
+
+  g_clear_pointer (&priv->translation_widgets, g_hash_table_unref);
+
+  G_OBJECT_CLASS (gis_welcome_widget_parent_class)->dispose (object);
+}
+
+static void
 gis_welcome_widget_class_init (GisWelcomeWidgetClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -193,6 +206,7 @@ gis_welcome_widget_class_init (GisWelcomeWidgetClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GisWelcomeWidget, stack);
 
   object_class->constructed = gis_welcome_widget_constructed;
+  object_class->dispose = gis_welcome_widget_dispose;
   widget_class->map = gis_welcome_widget_map;
   widget_class->unmap = gis_welcome_widget_unmap;
 }
@@ -200,5 +214,25 @@ gis_welcome_widget_class_init (GisWelcomeWidgetClass *klass)
 static void
 gis_welcome_widget_init (GisWelcomeWidget *widget)
 {
+  GisWelcomeWidgetPrivate *priv = gis_welcome_widget_get_instance_private (widget);
+
+  priv->translation_widgets = g_hash_table_new (g_str_hash, g_str_equal);
+
   gtk_widget_init_template (GTK_WIDGET (widget));
 }
+
+void
+gis_welcome_widget_show_locale (GisWelcomeWidget *widget,
+                                const char       *locale_id)
+{
+  GisWelcomeWidgetPrivate *priv = gis_welcome_widget_get_instance_private (widget);
+  GtkWidget *label;
+
+  /* Restart the widget to reset the timer. */
+  gis_welcome_widget_stop (widget);
+  gis_welcome_widget_start (widget);
+
+  label = g_hash_table_lookup (priv->translation_widgets, locale_id);
+  if (label)
+    gtk_stack_set_visible_child (GTK_STACK (priv->stack), label);
+}
diff --git a/gnome-initial-setup/pages/language/gis-welcome-widget.h 
b/gnome-initial-setup/pages/language/gis-welcome-widget.h
index 0c8c870..a84e21c 100644
--- a/gnome-initial-setup/pages/language/gis-welcome-widget.h
+++ b/gnome-initial-setup/pages/language/gis-welcome-widget.h
@@ -40,16 +40,19 @@ typedef struct _GisWelcomeWidgetClass   GisWelcomeWidgetClass;
 
 struct _GisWelcomeWidget
 {
-    GtkBin parent;
+  GtkBin parent;
 };
 
 struct _GisWelcomeWidgetClass
 {
-    GtkBinClass parent_class;
+  GtkBinClass parent_class;
 };
 
 GType gis_welcome_widget_get_type (void);
 
+void gis_welcome_widget_show_locale (GisWelcomeWidget *widget,
+                                     const char       *locale_id);
+
 G_END_DECLS
 
 #endif /* __GIS_WELCOME_WIDGET_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]