[gnome-initial-setup] gis-language-page: Add an animating "Welcome!" label



commit c38daac27d40ad10a841a6a69054c2df695271c7
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Oct 31 09:24:23 2013 -0400

    gis-language-page: Add an animating "Welcome!" label

 gnome-initial-setup/pages/language/Makefile.am     |    1 +
 .../pages/language/gis-language-page.c             |    2 +
 .../pages/language/gis-language-page.ui            |    7 +-
 .../pages/language/gis-welcome-widget.c            |  201 ++++++++++++++++++++
 .../pages/language/gis-welcome-widget.h            |   55 ++++++
 .../pages/language/gis-welcome-widget.ui           |   15 ++
 .../pages/language/language.gresource.xml          |    1 +
 7 files changed, 281 insertions(+), 1 deletions(-)
---
diff --git a/gnome-initial-setup/pages/language/Makefile.am b/gnome-initial-setup/pages/language/Makefile.am
index 3e18392..13d95cf 100644
--- a/gnome-initial-setup/pages/language/Makefile.am
+++ b/gnome-initial-setup/pages/language/Makefile.am
@@ -21,6 +21,7 @@ libgislanguage_la_SOURCES =                           \
        cc-common-language.c cc-common-language.h       \
        cc-util.c cc-util.h                             \
        cc-language-chooser.c cc-language-chooser.h     \
+       gis-welcome-widget.c gis-welcome-widget.h       \
        gis-language-page.c gis-language-page.h         \
        $(BUILT_SOURCES)
 
diff --git a/gnome-initial-setup/pages/language/gis-language-page.c 
b/gnome-initial-setup/pages/language/gis-language-page.c
index 66f7917..da801f5 100644
--- a/gnome-initial-setup/pages/language/gis-language-page.c
+++ b/gnome-initial-setup/pages/language/gis-language-page.c
@@ -30,6 +30,7 @@
 
 #include "config.h"
 #include "language-resources.h"
+#include "gis-welcome-widget.h"
 #include "cc-language-chooser.h"
 #include "gis-language-page.h"
 
@@ -259,6 +260,7 @@ static void
 gis_language_page_init (GisLanguagePage *page)
 {
   g_resources_register (language_get_resource ());
+  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 7092afa..13e2d42 100644
--- a/gnome-initial-setup/pages/language/gis-language-page.ui
+++ b/gnome-initial-setup/pages/language/gis-language-page.ui
@@ -4,9 +4,14 @@
   <template class="GisLanguagePage" parent="GisPage">
     <child>
       <object class="GtkBox" id="box">
-        <property name="name">language-page</property>
         <property name="visible">True</property>
         <property name="orientation">vertical</property>
+        <property name="spacing">10</property>
+        <child>
+          <object class="GisWelcomeWidget" id="welcome_widget">
+            <property name="visible">True</property>
+          </object>
+        </child>
         <child>
           <object class="CcLanguageChooser" id="language_chooser">
             <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 0000000..d15e929
--- /dev/null
+++ b/gnome-initial-setup/pages/language/gis-welcome-widget.c
@@ -0,0 +1,201 @@
+/* -*- 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Written by:
+ *     Jasper St. Pierre <jstpierre mecheye net>
+ */
+
+#include "config.h"
+#include "gis-welcome-widget.h"
+
+#include <locale.h>
+#include <glib/gi18n.h>
+
+#include "cc-common-language.h"
+
+struct _GisWelcomeWidgetPrivate
+{
+  GtkWidget *stack;
+
+  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)
+{
+  char *current_locale_id;
+  char *welcome;
+
+  current_locale_id = g_strdup (setlocale (LC_MESSAGES, NULL));
+  setlocale (LC_MESSAGES, locale_id);
+  welcome = _("Welcome!");
+  setlocale (LC_MESSAGES, current_locale_id);
+  g_free (current_locale_id);
+
+  return welcome;
+}
+
+static GtkWidget *
+big_label (const char *text)
+{
+  GtkWidget *label;
+  PangoAttrList *attrs;
+
+  label = gtk_label_new (text);
+
+  attrs = pango_attr_list_new ();
+  pango_attr_list_insert (attrs, pango_attr_scale_new (1.6));
+  pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+  gtk_label_set_attributes (GTK_LABEL (label), attrs);
+  pango_attr_list_unref (attrs);
+
+  return label;
+}
+
+static void
+fill_stack (GisWelcomeWidget *widget)
+{
+  GisWelcomeWidgetPrivate *priv = gis_welcome_widget_get_instance_private (widget);
+  GHashTable *initial = cc_common_language_get_initial_languages ();
+  GHashTableIter iter;
+  gpointer key, value;
+  GHashTable *added_translations;
+
+  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;
+
+      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);
+    }
+
+  g_hash_table_destroy (added_translations);
+}
+
+static void
+gis_welcome_widget_constructed (GObject *object)
+{
+  fill_stack (GIS_WELCOME_WIDGET (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;
+  widget_class->map = gis_welcome_widget_map;
+  widget_class->unmap = gis_welcome_widget_unmap;
+}
+
+static void
+gis_welcome_widget_init (GisWelcomeWidget *widget)
+{
+  gtk_widget_init_template (GTK_WIDGET (widget));
+}
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 0000000..0c8c870
--- /dev/null
+++ b/gnome-initial-setup/pages/language/gis-welcome-widget.h
@@ -0,0 +1,55 @@
+/* -*- 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * 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);
+
+G_END_DECLS
+
+#endif /* __GIS_WELCOME_WIDGET_H__ */
diff --git a/gnome-initial-setup/pages/language/gis-welcome-widget.ui 
b/gnome-initial-setup/pages/language/gis-welcome-widget.ui
new file mode 100644
index 0000000..251ad46
--- /dev/null
+++ b/gnome-initial-setup/pages/language/gis-welcome-widget.ui
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="3.0"/>
+  <template class="GisWelcomeWidget" parent="GtkBin">
+    <property name="margin-top">10</property>
+    <property name="margin-bottom">10</property>
+    <child>
+      <object class="GtkStack" id="stack">
+        <property name="visible">True</property>
+        <property name="transition-type">slide-left</property>
+        <property name="transition-duration">1000</property>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gnome-initial-setup/pages/language/language.gresource.xml 
b/gnome-initial-setup/pages/language/language.gresource.xml
index faa4e29..de0688d 100644
--- a/gnome-initial-setup/pages/language/language.gresource.xml
+++ b/gnome-initial-setup/pages/language/language.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/initial-setup">
     <file preprocess="xml-stripblanks" alias="gis-language-page.ui">gis-language-page.ui</file>
+    <file preprocess="xml-stripblanks" alias="gis-welcome-widget.ui">gis-welcome-widget.ui</file>
   </gresource>
   <gresource prefix="/org/gnome/control-center">
     <file preprocess="xml-stripblanks" alias="language-chooser.ui">language-chooser.ui</file>


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