[gnome-initial-setup] timezone: Add a bubble widget



commit 11b36b6f2cb4790da112f3d38f861089fb658bb4
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Oct 31 11:29:16 2013 -0400

    timezone: Add a bubble widget
    
    Telling users to search for a city.

 gnome-initial-setup/pages/timezone/Makefile.am     |    1 +
 .../pages/timezone/gis-bubble-widget.c             |  147 ++++++++++++++++++++
 .../pages/timezone/gis-bubble-widget.css           |    8 +
 .../pages/timezone/gis-bubble-widget.h             |   55 ++++++++
 .../pages/timezone/gis-bubble-widget.ui            |   39 +++++
 .../pages/timezone/gis-timezone-page.c             |    9 +-
 .../pages/timezone/gis-timezone-page.ui            |   20 +++-
 .../pages/timezone/timezone.gresource.xml          |    2 +
 8 files changed, 275 insertions(+), 6 deletions(-)
---
diff --git a/gnome-initial-setup/pages/timezone/Makefile.am b/gnome-initial-setup/pages/timezone/Makefile.am
index cdecac4..f34b56d 100644
--- a/gnome-initial-setup/pages/timezone/Makefile.am
+++ b/gnome-initial-setup/pages/timezone/Makefile.am
@@ -30,6 +30,7 @@ BUILT_SOURCES += timezone-resources.c timezone-resources.h
 
 libgistimezone_la_SOURCES =    \
        cc-timezone-map.c cc-timezone-map.h \
+       gis-bubble-widget.c gis-bubble-widget.h \
        gis-timezone-page.c gis-timezone-page.h \
        $(BUILT_SOURCES)
 
diff --git a/gnome-initial-setup/pages/timezone/gis-bubble-widget.c 
b/gnome-initial-setup/pages/timezone/gis-bubble-widget.c
new file mode 100644
index 0000000..0273ba4
--- /dev/null
+++ b/gnome-initial-setup/pages/timezone/gis-bubble-widget.c
@@ -0,0 +1,147 @@
+/* -*- 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-bubble-widget.h"
+
+struct _GisBubbleWidgetPrivate
+{
+  GtkWidget *icon;
+  GtkWidget *label;
+};
+typedef struct _GisBubbleWidgetPrivate GisBubbleWidgetPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (GisBubbleWidget, gis_bubble_widget, GTK_TYPE_BIN);
+
+enum {
+  PROP_0,
+  PROP_LABEL,
+  PROP_ICON_NAME,
+  PROP_LAST,
+};
+
+static GParamSpec *obj_props[PROP_LAST];
+
+static void
+gis_bubble_widget_get_property (GObject    *object,
+                                guint       prop_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+  GisBubbleWidget *widget = GIS_BUBBLE_WIDGET (object);
+  GisBubbleWidgetPrivate *priv = gis_bubble_widget_get_instance_private (widget);
+
+  switch (prop_id)
+    {
+    case PROP_LABEL:
+      g_value_set_string (value, gtk_label_get_label (GTK_LABEL (priv->label)));
+      break;
+    case PROP_ICON_NAME:
+      {
+        const char *icon_name;
+        gtk_image_get_icon_name (GTK_IMAGE (priv->icon), &icon_name, NULL);
+        g_value_set_string (value, icon_name);
+        break;
+      }
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gis_bubble_widget_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  GisBubbleWidget *widget = GIS_BUBBLE_WIDGET (object);
+  GisBubbleWidgetPrivate *priv = gis_bubble_widget_get_instance_private (widget);
+
+  switch (prop_id)
+    {
+    case PROP_LABEL:
+      gtk_label_set_label (GTK_LABEL (priv->label), g_value_get_string (value));
+      break;
+    case PROP_ICON_NAME:
+      g_object_set (GTK_IMAGE (priv->icon),
+                    "icon-name", g_value_get_string (value),
+                    NULL);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+add_style_from_resource (const char *resource)
+{
+  GtkCssProvider *provider;
+  GFile *file;
+  char *uri;
+
+  provider = gtk_css_provider_new ();
+
+  uri = g_strconcat ("resource://", resource, NULL);
+  file = g_file_new_for_uri (uri);
+
+  if (!gtk_css_provider_load_from_file (provider, file, NULL))
+    goto out;
+
+  gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
+                                             GTK_STYLE_PROVIDER (provider),
+                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+ out:
+  g_object_unref (file);
+  g_free (uri);
+}
+
+static void
+gis_bubble_widget_class_init (GisBubbleWidgetClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), 
"/org/gnome/initial-setup/gis-bubble-widget.ui");
+
+  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisBubbleWidget, icon);
+  gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GisBubbleWidget, label);
+
+  object_class->set_property = gis_bubble_widget_set_property;
+  object_class->get_property = gis_bubble_widget_get_property;
+
+  obj_props[PROP_LABEL] = g_param_spec_string ("label", "", "", NULL, G_PARAM_READWRITE | 
G_PARAM_STATIC_STRINGS);
+  obj_props[PROP_ICON_NAME] = g_param_spec_string ("icon-name", "", "", NULL, G_PARAM_READWRITE | 
G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (object_class, PROP_LAST, obj_props);
+
+  add_style_from_resource ("/org/gnome/initial-setup/gis-bubble-widget.css");
+}
+
+static void
+gis_bubble_widget_init (GisBubbleWidget *widget)
+{
+  gtk_widget_init_template (GTK_WIDGET (widget));
+}
diff --git a/gnome-initial-setup/pages/timezone/gis-bubble-widget.css 
b/gnome-initial-setup/pages/timezone/gis-bubble-widget.css
new file mode 100644
index 0000000..85de577
--- /dev/null
+++ b/gnome-initial-setup/pages/timezone/gis-bubble-widget.css
@@ -0,0 +1,8 @@
+
+.gis-bubble-widget {
+    border-radius: 20px;
+    background-color: rgba(0, 0, 0, 0.6);
+    color: white;
+    font-weight: bold;
+    padding: 2em;
+}
diff --git a/gnome-initial-setup/pages/timezone/gis-bubble-widget.h 
b/gnome-initial-setup/pages/timezone/gis-bubble-widget.h
new file mode 100644
index 0000000..1534d66
--- /dev/null
+++ b/gnome-initial-setup/pages/timezone/gis-bubble-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_BUBBLE_WIDGET_H__
+#define __GIS_BUBBLE_WIDGET_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GIS_TYPE_BUBBLE_WIDGET               (gis_bubble_widget_get_type ())
+#define GIS_BUBBLE_WIDGET(obj)                           (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GIS_TYPE_BUBBLE_WIDGET, GisBubbleWidget))
+#define GIS_BUBBLE_WIDGET_CLASS(klass)                   (G_TYPE_CHECK_CLASS_CAST ((klass),  
GIS_TYPE_BUBBLE_WIDGET, GisBubbleWidgetClass))
+#define GIS_IS_BUBBLE_WIDGET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIS_TYPE_BUBBLE_WIDGET))
+#define GIS_IS_BUBBLE_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GIS_TYPE_BUBBLE_WIDGET))
+#define GIS_BUBBLE_WIDGET_GET_CLASS(obj)                 (G_TYPE_INSTANCE_GET_CLASS ((obj),  
GIS_TYPE_BUBBLE_WIDGET, GisBubbleWidgetClass))
+
+typedef struct _GisBubbleWidget        GisBubbleWidget;
+typedef struct _GisBubbleWidgetClass   GisBubbleWidgetClass;
+
+struct _GisBubbleWidget
+{
+    GtkBin parent;
+};
+
+struct _GisBubbleWidgetClass
+{
+    GtkBinClass parent_class;
+};
+
+GType gis_bubble_widget_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GIS_BUBBLE_WIDGET_H__ */
diff --git a/gnome-initial-setup/pages/timezone/gis-bubble-widget.ui 
b/gnome-initial-setup/pages/timezone/gis-bubble-widget.ui
new file mode 100644
index 0000000..bbb6249
--- /dev/null
+++ b/gnome-initial-setup/pages/timezone/gis-bubble-widget.ui
@@ -0,0 +1,39 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="3.0"/>
+  <template class="GisBubbleWidget" parent="GtkBin">
+    <child>
+      <object class="GtkAspectFrame" id="aspect_frame">
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkBox" id="box">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <property name="width-request">128</property>
+            <property name="height-request">128</property>
+            <property name="halign">center</property>
+            <property name="valign">center</property>
+            <child>
+              <object class="GtkImage" id="icon">
+                <property name="visible">True</property>
+                <property name="vexpand">True</property>
+                <property name="pixel-size">64</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label">
+                <property name="visible">True</property>
+                <property name="vexpand">True</property>
+                <property name="wrap">True</property>
+                <property name="justify">center</property>
+              </object>
+            </child>
+          </object>
+          <style>
+            <class name="gis-bubble-widget" />
+          </style>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gnome-initial-setup/pages/timezone/gis-timezone-page.c 
b/gnome-initial-setup/pages/timezone/gis-timezone-page.c
index 3b6f214..d4fc0c2 100644
--- a/gnome-initial-setup/pages/timezone/gis-timezone-page.c
+++ b/gnome-initial-setup/pages/timezone/gis-timezone-page.c
@@ -26,8 +26,6 @@
 #define PAGE_ID "timezone"
 
 #include "config.h"
-#include "cc-datetime-resources.h"
-#include "timezone-resources.h"
 #include "gis-timezone-page.h"
 
 #include <glib/gi18n.h>
@@ -39,8 +37,12 @@
 #define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
 #include <libgweather/gweather.h>
 
-#include "cc-timezone-map.h"
 #include "timedated.h"
+#include "cc-datetime-resources.h"
+#include "timezone-resources.h"
+
+#include "cc-timezone-map.h"
+#include "gis-bubble-widget.h"
 
 #define DEFAULT_TZ "Europe/London"
 
@@ -370,6 +372,7 @@ gis_timezone_page_init (GisTimezonePage *page)
   g_resources_register (timezone_get_resource ());
   g_resources_register (datetime_get_resource ());
   g_type_ensure (CC_TYPE_TIMEZONE_MAP);
+  g_type_ensure (GIS_TYPE_BUBBLE_WIDGET);
 
   gtk_widget_init_template (GTK_WIDGET (page));
 }
diff --git a/gnome-initial-setup/pages/timezone/gis-timezone-page.ui 
b/gnome-initial-setup/pages/timezone/gis-timezone-page.ui
index ce15a70..5bc5dcf 100644
--- a/gnome-initial-setup/pages/timezone/gis-timezone-page.ui
+++ b/gnome-initial-setup/pages/timezone/gis-timezone-page.ui
@@ -103,10 +103,24 @@
             <property name="vexpand">True</property>
             <property name="label_xalign">0</property>
             <child>
-              <object class="CcTimezoneMap" id="map">
+              <object class="GtkOverlay" id="map_overlay">
                 <property name="visible">True</property>
-                <property name="hexpand">True</property>
-                <property name="vexpand">True</property>
+                <child>
+                  <object class="CcTimezoneMap" id="map">
+                    <property name="visible">True</property>
+                    <property name="hexpand">True</property>
+                    <property name="vexpand">True</property>
+                  </object>
+                </child>
+                <child type="overlay">
+                  <object class="GisBubbleWidget" id="search_overlay">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Please search for a nearby city</property>
+                    <property name="icon-name">edit-find-symbolic</property>
+                    <property name="halign">center</property>
+                    <property name="valign">center</property>
+                  </object>
+                </child>
               </object>
             </child>
           </object>
diff --git a/gnome-initial-setup/pages/timezone/timezone.gresource.xml 
b/gnome-initial-setup/pages/timezone/timezone.gresource.xml
index 93f150c..cf36818 100644
--- a/gnome-initial-setup/pages/timezone/timezone.gresource.xml
+++ b/gnome-initial-setup/pages/timezone/timezone.gresource.xml
@@ -2,5 +2,7 @@
 <gresources>
   <gresource prefix="/org/gnome/initial-setup">
     <file preprocess="xml-stripblanks" alias="gis-timezone-page.ui">gis-timezone-page.ui</file>
+    <file preprocess="xml-stripblanks" alias="gis-bubble-widget.ui">gis-bubble-widget.ui</file>
+    <file alias="gis-bubble-widget.css">gis-bubble-widget.css</file>
   </gresource>
 </gresources>


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