[gnome-initial-setup: 1/3] Add GisPageHeader



commit 5316f1c7d174ef9f3fb6650a03d9a68eecd2354c
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed Jul 24 14:43:36 2019 +0200

    Add GisPageHeader
    
    This will help making the page headers consistent.

 gnome-initial-setup/gis-assistant.gresource.xml |   1 +
 gnome-initial-setup/gis-page-header.c           | 184 ++++++++++++++++++++++++
 gnome-initial-setup/gis-page-header.h           |  36 +++++
 gnome-initial-setup/gis-page-header.ui          |  43 ++++++
 gnome-initial-setup/meson.build                 |   2 +
 5 files changed, 266 insertions(+)
---
diff --git a/gnome-initial-setup/gis-assistant.gresource.xml b/gnome-initial-setup/gis-assistant.gresource.xml
index 0640c24..59102c5 100644
--- a/gnome-initial-setup/gis-assistant.gresource.xml
+++ b/gnome-initial-setup/gis-assistant.gresource.xml
@@ -2,5 +2,6 @@
 <gresources>
   <gresource prefix="/org/gnome/initial-setup">
     <file preprocess="xml-stripblanks">gis-assistant.ui</file>
+    <file preprocess="xml-stripblanks">gis-page-header.ui</file>
   </gresource>
 </gresources>
diff --git a/gnome-initial-setup/gis-page-header.c b/gnome-initial-setup/gis-page-header.c
new file mode 100644
index 0000000..26f3468
--- /dev/null
+++ b/gnome-initial-setup/gis-page-header.c
@@ -0,0 +1,184 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* -*- encoding: utf8 -*- */
+/*
+ * Copyright (C) 2019 Purism SPC
+ *
+ * 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:
+ *     Adrien Plazas <kekun plazas laposte net>
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "gis-page-header.h"
+
+enum {
+  PROP_0,
+  PROP_TITLE,
+  PROP_SUBTITLE,
+  PROP_ICON_NAME,
+  PROP_SHOW_ICON,
+  PROP_LAST,
+};
+
+static GParamSpec *obj_props[PROP_LAST];
+
+struct _GisPageHeader
+{
+  GtkBox parent;
+
+  GtkWidget *box;
+  GtkWidget *icon;
+  GtkWidget *subtitle;
+  GtkWidget *title;
+};
+
+G_DEFINE_TYPE (GisPageHeader, gis_page_header, GTK_TYPE_BOX)
+
+static gboolean
+is_valid_string (const gchar *s)
+{
+  return s != NULL && g_strcmp0 (s, "") != 0;
+}
+
+static void
+update_box_visibility (GisPageHeader *header)
+{
+  gtk_widget_set_visible (header->box, gtk_widget_get_visible (header->subtitle) ||
+                                       gtk_widget_get_visible (header->title));
+}
+
+static void
+gis_page_header_init (GisPageHeader *header)
+{
+  gtk_widget_init_template (GTK_WIDGET (header));
+
+  g_signal_connect_swapped (header->subtitle, "notify::visible",
+                            G_CALLBACK(update_box_visibility), header);
+  g_signal_connect_swapped (header->title, "notify::visible",
+                            G_CALLBACK(update_box_visibility), header);
+}
+
+static void
+gis_page_header_get_property (GObject    *object,
+                              guint       prop_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  GisPageHeader *header = GIS_PAGE_HEADER (object);
+  gchar *icon_name = NULL;
+
+  switch (prop_id)
+    {
+    case PROP_TITLE:
+      g_value_set_string (value, gtk_label_get_label (GTK_LABEL (header->title)));
+      break;
+
+    case PROP_SUBTITLE:
+      g_value_set_string (value, gtk_label_get_label (GTK_LABEL (header->subtitle)));
+      break;
+
+    case PROP_ICON_NAME:
+      g_object_get (header->icon, "icon-name", &icon_name, NULL);
+      g_value_take_string (value, icon_name);
+      break;
+
+    case PROP_SHOW_ICON:
+      g_value_set_boolean (value, gtk_widget_get_visible (header->icon));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gis_page_header_set_property (GObject      *object,
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
+{
+  GisPageHeader *header = GIS_PAGE_HEADER (object);
+
+  switch (prop_id)
+    {
+    case PROP_TITLE:
+      gtk_label_set_label (GTK_LABEL (header->title), g_value_get_string (value));
+      gtk_widget_set_visible (header->title, is_valid_string (g_value_get_string (value)));
+      break;
+
+    case PROP_SUBTITLE:
+      gtk_label_set_label (GTK_LABEL (header->subtitle), g_value_get_string (value));
+      gtk_widget_set_visible (header->subtitle, is_valid_string (g_value_get_string (value)));
+      break;
+
+    case PROP_ICON_NAME:
+      g_object_set (header->icon, "icon-name", g_value_get_string (value), NULL);
+      break;
+
+    case PROP_SHOW_ICON:
+      gtk_widget_set_visible (header->icon, g_value_get_boolean (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+gis_page_header_class_init (GisPageHeaderClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), 
"/org/gnome/initial-setup/gis-page-header.ui");
+
+  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GisPageHeader, box);
+  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GisPageHeader, icon);
+  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GisPageHeader, subtitle);
+  gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GisPageHeader, title);
+
+  gobject_class->get_property = gis_page_header_get_property;
+  gobject_class->set_property = gis_page_header_set_property;
+
+  obj_props[PROP_TITLE] =
+    g_param_spec_string ("title",
+                         "", "",
+                         NULL,
+                         G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  obj_props[PROP_SUBTITLE] =
+    g_param_spec_string ("subtitle",
+                         "", "",
+                         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);
+
+  obj_props[PROP_SHOW_ICON] =
+    g_param_spec_boolean ("show-icon",
+                          "", "",
+                          FALSE,
+                          G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+  g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
+}
diff --git a/gnome-initial-setup/gis-page-header.h b/gnome-initial-setup/gis-page-header.h
new file mode 100644
index 0000000..2ae6978
--- /dev/null
+++ b/gnome-initial-setup/gis-page-header.h
@@ -0,0 +1,36 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* -*- encoding: utf8 -*- */
+/*
+ * Copyright (C) 2019 Purism SPC
+ *
+ * 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:
+ *     Adrien Plazas <kekun plazas laposte net>
+ */
+
+#ifndef __GIS_PAGE_HEADER_H__
+#define __GIS_PAGE_HEADER_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GIS_TYPE_PAGE_HEADER               (gis_page_header_get_type ())
+
+G_DECLARE_FINAL_TYPE (GisPageHeader, gis_page_header, GIS, PAGE_HEADER, GtkBox)
+
+G_END_DECLS
+
+#endif /* __GIS_PAGE_HEADER_H__ */
diff --git a/gnome-initial-setup/gis-page-header.ui b/gnome-initial-setup/gis-page-header.ui
new file mode 100644
index 0000000..905bec6
--- /dev/null
+++ b/gnome-initial-setup/gis-page-header.ui
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="GisPageHeader" parent="GtkBox">
+    <property name="orientation">vertical</property>
+    <property name="spacing">18</property>
+    <child>
+      <object class="GtkImage" id="icon">
+        <property name="can_focus">False</property>
+        <property name="pixel_size">96</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+    </child>
+    <child>
+      <object class="GtkBox" id="box">
+        <property name="orientation">vertical</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkLabel" id="title">
+            <property name="can_focus">False</property>
+            <property name="justify">center</property>
+            <property name="max_width_chars">65</property>
+            <property name="wrap">True</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+              <attribute name="scale" value="1.8"/>
+            </attributes>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="subtitle">
+            <property name="can_focus">False</property>
+            <property name="justify">center</property>
+            <property name="max_width_chars">65</property>
+            <property name="wrap">True</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gnome-initial-setup/meson.build b/gnome-initial-setup/meson.build
index bc04108..927ae8a 100644
--- a/gnome-initial-setup/meson.build
+++ b/gnome-initial-setup/meson.build
@@ -14,11 +14,13 @@ sources += [
     'gnome-initial-setup.c',
     'gis-assistant.c',
     'gis-page.c',
+    'gis-page-header.c',
     'gis-driver.c',
     'gis-keyring.c',
     'gnome-initial-setup.h',
     'gis-assistant.h',
     'gis-page.h',
+    'gis-page-header.h',
     'gis-driver.h',
     'gis-keyring.h'
 ]


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