[gnome-initial-setup/youre-welcome: 1/10] Revert "Gut the language page"




commit 88631bc14a8f1be16b9e65dc696b30689cdaad09
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Aug 6 08:34:36 2020 -0400

    Revert "Gut the language page"
    
    This reverts commit 99dd5ee20b5ef5ec3afef23c34fe87683a53a6a5.

 .../pages/language/gis-language-page.c             |  56 ++++-
 .../pages/language/gis-language-page.ui            |  29 ++-
 .../pages/language/gis-welcome-widget.c            | 245 +++++++++++++++++++++
 .../pages/language/gis-welcome-widget.h            |  56 +++++
 gnome-initial-setup/pages/language/meson.build     |   2 +
 po/POTFILES.in                                     |   1 +
 6 files changed, 378 insertions(+), 11 deletions(-)
---
diff --git a/gnome-initial-setup/pages/language/gis-language-page.c 
b/gnome-initial-setup/pages/language/gis-language-page.c
index 09c2b988..2e5ae025 100644
--- a/gnome-initial-setup/pages/language/gis-language-page.c
+++ b/gnome-initial-setup/pages/language/gis-language-page.c
@@ -31,9 +31,9 @@
 
 #include "config.h"
 #include "language-resources.h"
+#include "gis-welcome-widget.h"
 #include "cc-language-chooser.h"
 #include "gis-language-page.h"
-#include "gis-page-header.h"
 
 #include <act/act-user-manager.h>
 #include <polkit/polkit.h>
@@ -42,6 +42,8 @@
 
 struct _GisLanguagePagePrivate
 {
+  GtkWidget *logo;
+  GtkWidget *welcome_widget;
   GtkWidget *language_chooser;
 
   GDBusProxy *localed;
@@ -150,6 +152,9 @@ language_changed (CcLanguageChooser  *chooser,
                       "notify::is-loaded",
                       G_CALLBACK (user_loaded),
                       g_strdup (priv->new_locale_id));
+
+  gis_welcome_widget_show_locale (GIS_WELCOME_WIDGET (priv->welcome_widget),
+                                  priv->new_locale_id);
 }
 
 static void
@@ -174,6 +179,36 @@ localed_proxy_ready (GObject      *source,
   priv->localed = proxy;
 }
 
+static void
+update_distro_logo (GisLanguagePage *page)
+{
+  GisLanguagePagePrivate *priv = gis_language_page_get_instance_private (page);
+  g_autofree char *id = g_get_os_info (G_OS_INFO_KEY_ID);
+  gsize i;
+
+  static const struct {
+    const char *id;
+    const char *logo;
+  } id_to_logo[] = {
+    { "debian",                         "emblem-debian" },
+    { "fedora",                         "fedora-logo-icon" },
+    { "ubuntu",                         "ubuntu-logo-icon" },
+    { "openSUSE Tumbleweed",            "opensuse-logo-icon" },
+    { "openSUSE Leap",                  "opensuse-logo-icon" },
+    { "SLED",                           "suse-logo-icon" },
+    { "SLES",                           "suse-logo-icon" },
+  };
+
+  for (i = 0; i < G_N_ELEMENTS (id_to_logo); i++)
+    {
+      if (g_strcmp0 (id, id_to_logo[i].id) == 0)
+        {
+          g_object_set (priv->logo, "icon-name", id_to_logo[i].logo, NULL);
+          break;
+        }
+    }
+}
+
 static void
 language_confirmed (CcLanguageChooser *chooser,
                     GisLanguagePage   *page)
@@ -192,6 +227,8 @@ gis_language_page_constructed (GObject *object)
 
   G_OBJECT_CLASS (gis_language_page_parent_class)->constructed (object);
 
+  update_distro_logo (page);
+
   g_signal_connect (priv->language_chooser, "notify::language",
                     G_CALLBACK (language_changed), page);
   g_signal_connect (priv->language_chooser, "confirm",
@@ -222,7 +259,17 @@ gis_language_page_constructed (GObject *object)
 static void
 gis_language_page_locale_changed (GisPage *page)
 {
-  gis_page_set_title (GIS_PAGE (page), _("Language"));
+  gis_page_set_title (GIS_PAGE (page), _("Welcome"));
+}
+
+static gboolean
+gis_language_page_skip (GisPage *page)
+{
+  GisLanguagePagePrivate *priv = gis_language_page_get_instance_private (GIS_LANGUAGE_PAGE (page));
+
+  gtk_widget_hide (priv->language_chooser);
+
+  return FALSE;
 }
 
 static void
@@ -246,10 +293,13 @@ 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);
+  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisLanguagePage, logo);
 
   page_class->page_id = PAGE_ID;
   page_class->locale_changed = gis_language_page_locale_changed;
+  page_class->skip = gis_language_page_skip;
   object_class->constructed = gis_language_page_constructed;
   object_class->dispose = gis_language_page_dispose;
 }
@@ -258,7 +308,7 @@ static void
 gis_language_page_init (GisLanguagePage *page)
 {
   g_resources_register (language_get_resource ());
-  g_type_ensure (GIS_TYPE_PAGE_HEADER);
+  g_type_ensure (GIS_TYPE_WELCOME_WIDGET);
   g_type_ensure (CC_TYPE_LANGUAGE_CHOOSER);
 
   gtk_widget_init_template (GTK_WIDGET (page));
diff --git a/gnome-initial-setup/pages/language/gis-language-page.ui 
b/gnome-initial-setup/pages/language/gis-language-page.ui
index 8980062b..8f2a08cf 100644
--- a/gnome-initial-setup/pages/language/gis-language-page.ui
+++ b/gnome-initial-setup/pages/language/gis-language-page.ui
@@ -7,20 +7,33 @@
         <property name="visible">True</property>
         <property name="orientation">vertical</property>
         <property name="halign">center</property>
-        <property name="valign">fill</property>
         <child>
-          <object class="GisPageHeader" id="header">
+          <object class="GtkBox">
             <property name="visible">True</property>
-            <property name="margin_top">24</property>
-            <property name="title" translatable="yes">Language</property>
-            <property name="subtitle" translatable="yes">Select your language.</property>
-            <property name="icon_name">preferences-desktop-locale-symbolic</property>
-            <property name="show_icon" bind-source="GisLanguagePage" bind-property="small-screen" 
bind-flags="invert-boolean|sync-create"/>
+            <property name="orientation">vertical</property>
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+            <property name="expand" bind-source="language_chooser" bind-property="visible" 
bind-flags="invert-boolean|sync-create"/>
+            <child>
+              <object class="GtkImage" id="logo">
+                <property name="visible" bind-source="GisLanguagePage" bind-property="small-screen" 
bind-flags="invert-boolean|sync-create"/>
+                <property name="can_focus">False</property>
+                <property name="margin_top">24</property>
+                <property name="pixel_size">96</property>
+                <property name="icon_name">start-here-symbolic</property>
+              </object>
+            </child>
+            <child>
+              <object class="GisWelcomeWidget" id="welcome_widget">
+                <property name="visible">True</property>
+                <property name="margin_top">18</property>
+                <property name="margin_bottom">40</property>
+              </object>
+            </child>
           </object>
         </child>
         <child>
           <object class="CcLanguageChooser" id="language_chooser">
-            <property name="margin_top">18</property>
             <property name="margin_bottom">18</property>
             <property name="width_request">400</property>
             <property name="visible">True</property>
diff --git a/gnome-initial-setup/pages/language/gis-welcome-widget.c 
b/gnome-initial-setup/pages/language/gis-welcome-widget.c
new file mode 100644
index 00000000..6f6b8b05
--- /dev/null
+++ b/gnome-initial-setup/pages/language/gis-welcome-widget.c
@@ -0,0 +1,245 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2013 Red Hat
+ *
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Written by:
+ *     Jasper St. Pierre <jstpierre mecheye net>
+ */
+
+#include "config.h"
+#include "gis-welcome-widget.h"
+
+#include <errno.h>
+#include <locale.h>
+#include <glib/gi18n.h>
+
+#include "cc-common-language.h"
+
+struct _GisWelcomeWidgetPrivate
+{
+  GtkWidget *stack;
+  GHashTable *translation_widgets;
+
+  guint timeout_id;
+};
+typedef struct _GisWelcomeWidgetPrivate GisWelcomeWidgetPrivate;
+
+#define TIMEOUT 5
+
+G_DEFINE_TYPE_WITH_PRIVATE (GisWelcomeWidget, gis_welcome_widget, GTK_TYPE_BIN);
+
+static gboolean
+advance_stack (gpointer user_data)
+{
+  GisWelcomeWidget *widget = user_data;
+  GisWelcomeWidgetPrivate *priv = gis_welcome_widget_get_instance_private (widget);
+  GList *children, *l;
+
+  children = gtk_container_get_children (GTK_CONTAINER (priv->stack));
+  if (children == NULL)
+    goto out;
+
+  for (l = children; l != NULL; l = l->next)
+    {
+      if (l->data == gtk_stack_get_visible_child (GTK_STACK (priv->stack)))
+        break;
+    }
+
+  /* wrap around */
+  if (l->next)
+    l = l->next;
+  else
+    l = children;
+
+  gtk_stack_set_visible_child (GTK_STACK (priv->stack), l->data);
+
+  g_list_free (children);
+
+ out:
+  return G_SOURCE_CONTINUE;
+}
+
+static void
+gis_welcome_widget_start (GisWelcomeWidget *widget)
+{
+  GisWelcomeWidgetPrivate *priv = gis_welcome_widget_get_instance_private (widget);
+
+  if (priv->timeout_id > 0)
+    return;
+
+  priv->timeout_id = g_timeout_add_seconds (5, advance_stack, widget);
+}
+
+static void
+gis_welcome_widget_stop (GisWelcomeWidget *widget)
+{
+  GisWelcomeWidgetPrivate *priv = gis_welcome_widget_get_instance_private (widget);
+
+  if (priv->timeout_id == 0)
+    return;
+
+  g_source_remove (priv->timeout_id);
+  priv->timeout_id = 0;
+}
+
+static void
+gis_welcome_widget_map (GtkWidget *widget)
+{
+  GTK_WIDGET_CLASS (gis_welcome_widget_parent_class)->map (widget);
+  gis_welcome_widget_start (GIS_WELCOME_WIDGET (widget));
+}
+
+static void
+gis_welcome_widget_unmap (GtkWidget *widget)
+{
+  GTK_WIDGET_CLASS (gis_welcome_widget_parent_class)->unmap (widget);
+  gis_welcome_widget_stop (GIS_WELCOME_WIDGET (widget));
+}
+
+static char *
+welcome (const char *locale_id)
+{
+  locale_t locale;
+  locale_t old_locale;
+  char *welcome;
+
+  locale = newlocale (LC_MESSAGES_MASK, locale_id, (locale_t) 0);
+  if (locale == (locale_t) 0)
+    {
+      if (errno == ENOENT)
+        g_debug ("Failed to create locale %s: %s", locale_id, g_strerror (errno));
+      else
+        g_warning ("Failed to create locale %s: %s", locale_id, g_strerror (errno));
+
+      return "Welcome!";
+    }
+
+  old_locale = uselocale (locale);
+
+  /* Translators: This is meant to be a warm, engaging welcome message,
+   * like greeting somebody at the door. If the exclamation mark is not
+   * suitable for this in your language you may replace it.
+   */
+  welcome = _("Welcome!");
+
+  uselocale (old_locale);
+  freelocale (locale);
+
+  return welcome;
+}
+
+static GtkWidget *
+big_label (const char *text)
+{
+  GtkWidget *label = gtk_label_new (text);
+
+  gtk_style_context_add_class (gtk_widget_get_style_context (label), "title-1");
+
+  return label;
+}
+
+static void
+fill_stack (GisWelcomeWidget *widget)
+{
+  GisWelcomeWidgetPrivate *priv = gis_welcome_widget_get_instance_private (widget);
+  g_autoptr(GHashTable) initial = cc_common_language_get_initial_languages ();
+  GHashTableIter iter;
+  gpointer key, value;
+  g_autoptr(GHashTable) added_translations = NULL;
+
+  added_translations = g_hash_table_new (g_str_hash, g_str_equal);
+
+  g_hash_table_iter_init (&iter, initial);
+  while (g_hash_table_iter_next (&iter, &key, &value))
+    {
+      char *locale_id = key;
+      char *text;
+      GtkWidget *label;
+
+      if (!cc_common_language_has_font (locale_id))
+        continue;
+
+      text = welcome (locale_id);
+      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);
+    }
+}
+
+static void
+gis_welcome_widget_constructed (GObject *object)
+{
+  fill_stack (GIS_WELCOME_WIDGET (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);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/initial-setup/gis-welcome-widget.ui");
+
+  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;
+}
+
+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
new file mode 100644
index 00000000..33afe8b7
--- /dev/null
+++ b/gnome-initial-setup/pages/language/gis-welcome-widget.h
@@ -0,0 +1,56 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2013 Red Hat
+ *
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Written by:
+ *     Jasper St. Pierre <jstpierre mecheye net>
+ */
+
+#ifndef __GIS_WELCOME_WIDGET_H__
+#define __GIS_WELCOME_WIDGET_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GIS_TYPE_WELCOME_WIDGET            (gis_welcome_widget_get_type ())
+#define GIS_WELCOME_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIS_TYPE_WELCOME_WIDGET, 
GisWelcomeWidget))
+#define GIS_WELCOME_WIDGET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GIS_TYPE_WELCOME_WIDGET, 
GisWelcomeWidgetClass))
+#define GIS_IS_WELCOME_WIDGET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIS_TYPE_WELCOME_WIDGET))
+#define GIS_IS_WELCOME_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GIS_TYPE_WELCOME_WIDGET))
+#define GIS_WELCOME_WIDGET_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GIS_TYPE_WELCOME_WIDGET, 
GisWelcomeWidgetClass))
+
+typedef struct _GisWelcomeWidget        GisWelcomeWidget;
+typedef struct _GisWelcomeWidgetClass   GisWelcomeWidgetClass;
+
+struct _GisWelcomeWidget
+{
+  GtkBin parent;
+};
+
+struct _GisWelcomeWidgetClass
+{
+  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__ */
diff --git a/gnome-initial-setup/pages/language/meson.build b/gnome-initial-setup/pages/language/meson.build
index f3034480..ef6ba3f7 100644
--- a/gnome-initial-setup/pages/language/meson.build
+++ b/gnome-initial-setup/pages/language/meson.build
@@ -9,6 +9,8 @@ sources += files(
     'cc-language-chooser.h',
     'cc-util.c',
     'cc-util.h',
+    'gis-welcome-widget.c',
+    'gis-welcome-widget.h',
     'gis-language-page.c',
     'gis-language-page.h',
 )
diff --git a/po/POTFILES.in b/po/POTFILES.in
index af574799..9e511b11 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -22,6 +22,7 @@ gnome-initial-setup/pages/keyboard/input-chooser.ui
 gnome-initial-setup/pages/language/cc-language-chooser.c
 gnome-initial-setup/pages/language/gis-language-page.c
 gnome-initial-setup/pages/language/gis-language-page.ui
+gnome-initial-setup/pages/language/gis-welcome-widget.c
 gnome-initial-setup/pages/network/gis-network-page.c
 gnome-initial-setup/pages/network/gis-network-page.ui
 gnome-initial-setup/pages/parental-controls/gis-parental-controls-page.c


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