[gnome-software] Break out the info bar widgets as a separate class



commit 0e0544b85efc81170c25406cc320e322fecef24d
Author: Rafal Luzynski <digitalfreak lingonborough com>
Date:   Thu Mar 17 02:00:40 2016 +0100

    Break out the info bar widgets as a separate class
    
    gs-shell-details.ui file is huge already, let's make it a little
    smaller. Another advantage is that any future changes in the info
    boxes appearance will be easier.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763010
    
    Signed-off-by: Richard Hughes <richard hughsie com>

 src/Makefile.am                  |    2 +
 src/gnome-software.gresource.xml |    1 +
 src/gs-info-bar.c                |  217 ++++++++++++++++++++++++++++++++++++++
 src/gs-info-bar.h                |   47 ++++++++
 src/gs-info-bar.ui               |   54 ++++++++++
 src/gs-shell-details.ui          |  179 ++-----------------------------
 6 files changed, 333 insertions(+), 167 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index d18bc7b..aa4c15e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -137,6 +137,8 @@ gnome_software_SOURCES =                            \
        gs-fixed-size-bin.c                             \
        gs-hiding-box.h                                 \
        gs-hiding-box.c                                 \
+       gs-info-bar.h                                   \
+       gs-info-bar.c                                   \
        gs-language.c                                   \
        gs-language.h                                   \
        gs-os-release.c                                 \
diff --git a/src/gnome-software.gresource.xml b/src/gnome-software.gresource.xml
index 9c29e61..f27026c 100644
--- a/src/gnome-software.gresource.xml
+++ b/src/gnome-software.gresource.xml
@@ -13,6 +13,7 @@
   <file preprocess="xml-stripblanks">gs-app-row.ui</file>
   <file preprocess="xml-stripblanks">gs-first-run-dialog.ui</file>
   <file preprocess="xml-stripblanks">gs-history-dialog.ui</file>
+  <file preprocess="xml-stripblanks">gs-info-bar.ui</file>
   <file preprocess="xml-stripblanks">gs-review-dialog.ui</file>
   <file preprocess="xml-stripblanks">gs-review-histogram.ui</file>
   <file preprocess="xml-stripblanks">gs-review-row.ui</file>
diff --git a/src/gs-info-bar.c b/src/gs-info-bar.c
new file mode 100644
index 0000000..d9f94c0
--- /dev/null
+++ b/src/gs-info-bar.c
@@ -0,0 +1,217 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 Rafał Lużyński <digitalfreak lingonborough com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "gs-info-bar.h"
+
+struct _GsInfoBar
+{
+       GtkInfoBar       parent_instance;
+
+       GtkWidget       *label_title;
+       GtkWidget       *label_body;
+       GtkWidget       *label_warning;
+};
+
+G_DEFINE_TYPE (GsInfoBar, gs_info_bar, GTK_TYPE_INFO_BAR)
+
+enum {
+       PROP_0,
+       PROP_TITLE,
+       PROP_BODY,
+       PROP_WARNING
+};
+
+static void
+gs_info_bar_get_property (GObject *object,
+                         guint prop_id,
+                         GValue *value,
+                         GParamSpec *pspec)
+{
+       GsInfoBar *infobar = GS_INFO_BAR (object);
+
+       switch (prop_id) {
+       case PROP_TITLE:
+               g_value_set_string (value, gs_info_bar_get_title (infobar));
+               break;
+       case PROP_BODY:
+               g_value_set_string (value, gs_info_bar_get_body (infobar));
+               break;
+       case PROP_WARNING:
+               g_value_set_string (value, gs_info_bar_get_warning (infobar));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+gs_info_bar_set_property (GObject *object,
+                         guint prop_id,
+                         const GValue *value,
+                         GParamSpec *pspec)
+{
+       GsInfoBar *infobar = GS_INFO_BAR (object);
+
+       switch (prop_id) {
+       case PROP_TITLE:
+               gs_info_bar_set_title (infobar, g_value_get_string (value));
+               break;
+       case PROP_BODY:
+               gs_info_bar_set_body (infobar, g_value_get_string (value));
+               break;
+       case PROP_WARNING:
+               gs_info_bar_set_warning (infobar, g_value_get_string (value));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+gs_info_bar_init (GsInfoBar *infobar)
+{
+       gtk_widget_set_has_window (GTK_WIDGET (infobar), FALSE);
+       gtk_widget_init_template (GTK_WIDGET (infobar));
+}
+
+static void
+gs_info_bar_class_init (GsInfoBarClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+       object_class->get_property = gs_info_bar_get_property;
+       object_class->set_property = gs_info_bar_set_property;
+
+       g_object_class_install_property (object_class, PROP_TITLE,
+               g_param_spec_string ("title",
+                                    "Title Text",
+                                    "The title (header) text of the info bar",
+                                    "",
+                                    G_PARAM_READWRITE));
+
+       g_object_class_install_property (object_class, PROP_BODY,
+               g_param_spec_string ("body",
+                                    "Body Text",
+                                    "The body (main) text of the info bar",
+                                    NULL,
+                                    G_PARAM_READWRITE));
+
+       g_object_class_install_property (object_class, PROP_WARNING,
+               g_param_spec_string ("warning",
+                                    "Warning Text",
+                                    "The warning text of the info bar, below the body text",
+                                    NULL,
+                                    G_PARAM_READWRITE));
+
+       gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-info-bar.ui");
+
+       gtk_widget_class_bind_template_child (widget_class,
+                                             GsInfoBar, label_title);
+       gtk_widget_class_bind_template_child (widget_class,
+                                             GsInfoBar, label_body);
+       gtk_widget_class_bind_template_child (widget_class,
+                                             GsInfoBar, label_warning);
+}
+
+GtkWidget *
+gs_info_bar_new (void)
+{
+       GsInfoBar *infobar;
+
+       infobar = g_object_new (GS_TYPE_INFO_BAR, NULL);
+
+       return GTK_WIDGET (infobar);
+}
+
+static const gchar *
+retrieve_from_label (GtkWidget *label)
+{
+       if (!gtk_widget_get_visible (label))
+               return NULL;
+       else
+               return gtk_label_get_label (GTK_LABEL (label));
+}
+
+static void
+update_label (GtkWidget *label, const gchar *text)
+{
+       gtk_label_set_label (GTK_LABEL (label), text);
+       gtk_widget_set_visible (label,
+                               text != NULL && *text != '\0');
+}
+
+const gchar *
+gs_info_bar_get_title (GsInfoBar *bar)
+{
+       g_return_val_if_fail (GS_IS_INFO_BAR (bar), NULL);
+
+       return retrieve_from_label (bar->label_title);
+}
+
+void
+gs_info_bar_set_title (GsInfoBar *bar, const gchar *text)
+{
+       g_return_if_fail (GS_IS_INFO_BAR (bar));
+
+       update_label (bar->label_title, text);
+}
+
+const gchar *
+gs_info_bar_get_body (GsInfoBar *bar)
+{
+       g_return_val_if_fail (GS_IS_INFO_BAR (bar), NULL);
+
+       return retrieve_from_label (bar->label_body);
+}
+
+void
+gs_info_bar_set_body (GsInfoBar *bar, const gchar *text)
+{
+       g_return_if_fail (GS_IS_INFO_BAR (bar));
+
+       update_label (bar->label_body, text);
+}
+
+const gchar *
+gs_info_bar_get_warning (GsInfoBar *bar)
+{
+       g_return_val_if_fail (GS_IS_INFO_BAR (bar), NULL);
+
+       return retrieve_from_label (bar->label_warning);
+}
+
+void
+gs_info_bar_set_warning (GsInfoBar *bar, const gchar *text)
+{
+       g_return_if_fail (GS_IS_INFO_BAR (bar));
+
+       update_label (bar->label_warning, text);
+}
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-info-bar.h b/src/gs-info-bar.h
new file mode 100644
index 0000000..55ab93a
--- /dev/null
+++ b/src/gs-info-bar.h
@@ -0,0 +1,47 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2016 Rafał Lużyński <digitalfreak lingonborough com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef GS_INFO_BAR_H
+#define GS_INFO_BAR_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GS_TYPE_INFO_BAR (gs_info_bar_get_type ())
+
+G_DECLARE_FINAL_TYPE (GsInfoBar, gs_info_bar, GS, INFO_BAR, GtkInfoBar)
+
+GtkWidget      *gs_info_bar_new                (void);
+const gchar    *gs_info_bar_get_title          (GsInfoBar      *bar);
+void            gs_info_bar_set_title          (GsInfoBar      *bar,
+                                                const gchar    *text);
+const gchar    *gs_info_bar_get_body           (GsInfoBar      *bar);
+void            gs_info_bar_set_body           (GsInfoBar      *bar,
+                                                const gchar    *text);
+const gchar    *gs_info_bar_get_warning        (GsInfoBar      *bar);
+void            gs_info_bar_set_warning        (GsInfoBar      *bar,
+                                                const gchar    *text);
+G_END_DECLS
+
+#endif /* GS_INFO_BAR_H */
+
+/* vim: set noexpandtab: */
diff --git a/src/gs-info-bar.ui b/src/gs-info-bar.ui
new file mode 100644
index 0000000..718c0a7
--- /dev/null
+++ b/src/gs-info-bar.ui
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="GsInfoBar" parent="GtkInfoBar">
+    <property name="app_paintable">True</property>
+    <property name="message_type">info</property>
+    <style>
+      <class name="application-details-infobar"/>
+    </style>
+    <child internal-child="content_area">
+      <object class="GtkBox" id="content_area">
+        <property name="can_focus">False</property>
+        <property name="spacing">0</property>
+        <property name="halign">fill</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkLabel" id="label_title">
+            <property name="justify">center</property>
+            <property name="wrap">True</property>
+            <property name="max_width_chars">30</property>
+            <property name="visible">False</property>
+            <property name="can_focus">False</property>
+            <attributes>
+              <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label_body">
+            <property name="justify">center</property>
+            <property name="wrap">True</property>
+            <property name="max_width_chars">30</property>
+            <property name="visible">False</property>
+            <property name="can_focus">False</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label_warning">
+            <property name="justify">center</property>
+            <property name="wrap">True</property>
+            <property name="max_width_chars">30</property>
+            <property name="visible">False</property>
+            <property name="can_focus">False</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">False</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/src/gs-shell-details.ui b/src/gs-shell-details.ui
index fae9910..c5f87f6 100644
--- a/src/gs-shell-details.ui
+++ b/src/gs-shell-details.ui
@@ -336,51 +336,12 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkInfoBar" id="infobar_details_app_repo">
+                      <object class="GsInfoBar" id="infobar_details_app_repo">
                         <property name="visible">True</property>
-                        <property name="app_paintable">True</property>
                         <property name="can_focus">False</property>
-                        <property name="message_type">info</property>
                         <property name="margin_top">20</property>
-                        <style>
-                          <class name="application-details-infobar"/>
-                        </style>
-                        <child internal-child="content_area">
-                          <object class="GtkBox" id="infobar-content_area1">
-                            <property name="can_focus">False</property>
-                            <property name="spacing">0</property>
-                            <property name="halign">fill</property>
-                            <property name="orientation">vertical</property>
-                            <child>
-                              <object class="GtkLabel" id="label_header_details_app_repo">
-                                <property name="justify">center</property>
-                                <property name="wrap">True</property>
-                                <property name="max_width_chars">30</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes">Software Source Included</property>
-                                <attributes>
-                                  <attribute name="weight" value="bold"/>
-                                </attributes>
-                              </object>
-                            </child>
-                            <child>
-                              <object class="GtkLabel" id="label_details_app_repo">
-                                <property name="justify">center</property>
-                                <property name="wrap">True</property>
-                                <property name="max_width_chars">30</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes">This application includes a 
software source which provides updates, as well as access to other software.</property>
-                              </object>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
+                        <property name="title" translatable="yes">Software Source Included</property>
+                        <property name="body" translatable="yes">This application includes a software source 
which provides updates, as well as access to other software.</property>
                       </object>
                       <packing>
                         <property name="expand">False</property>
@@ -389,51 +350,12 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkInfoBar" id="infobar_details_app_norepo">
+                      <object class="GsInfoBar" id="infobar_details_app_norepo">
                         <property name="visible">True</property>
-                        <property name="app_paintable">True</property>
                         <property name="can_focus">False</property>
-                        <property name="message_type">info</property>
                         <property name="margin_top">20</property>
-                        <style>
-                          <class name="application-details-infobar"/>
-                        </style>
-                        <child internal-child="content_area">
-                          <object class="GtkBox" id="infobar-content_area2">
-                            <property name="can_focus">False</property>
-                            <property name="spacing">0</property>
-                            <property name="halign">fill</property>
-                            <property name="orientation">vertical</property>
-                            <child>
-                              <object class="GtkLabel" id="label_header_details_app_norepo">
-                                <property name="justify">center</property>
-                                <property name="wrap">True</property>
-                                <property name="max_width_chars">30</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes">No Software Source 
Included</property>
-                                <attributes>
-                                  <attribute name="weight" value="bold"/>
-                                </attributes>
-                              </object>
-                            </child>
-                            <child>
-                              <object class="GtkLabel" id="label_details_app_norepo">
-                                <property name="justify">center</property>
-                                <property name="wrap">True</property>
-                                <property name="max_width_chars">30</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes">This application does not include 
a software source. It will not be updated with new versions.</property>
-                              </object>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
+                        <property name="title" translatable="yes">No Software Source Included</property>
+                        <property name="body" translatable="yes">This application does not include a 
software source. It will not be updated with new versions.</property>
                       </object>
                       <packing>
                         <property name="expand">False</property>
@@ -442,41 +364,12 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkInfoBar" id="infobar_details_package_baseos">
+                      <object class="GsInfoBar" id="infobar_details_package_baseos">
                         <property name="visible">True</property>
-                        <property name="app_paintable">True</property>
                         <property name="can_focus">False</property>
                         <property name="message_type">warning</property>
                         <property name="margin_top">20</property>
-                        <style>
-                          <class name="application-details-infobar"/>
-                        </style>
-                        <child internal-child="content_area">
-                          <object class="GtkBox" id="infobar-content_area3">
-                            <property name="can_focus">False</property>
-                            <property name="spacing">0</property>
-                            <property name="halign">fill</property>
-                            <property name="orientation">vertical</property>
-                            <child>
-                              <object class="GtkLabel" id="label_header_details_package_baseos">
-                                <property name="justify">center</property>
-                                <property name="wrap">True</property>
-                                <property name="max_width_chars">30</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes">This software is already provided 
by your distribution and should not be replaced.</property>
-                                <attributes>
-                                  <attribute name="weight" value="bold"/>
-                                </attributes>
-                              </object>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
+                        <property name="title" translatable="yes">This software is already provided by your 
distribution and should not be replaced.</property>
                       </object>
                       <packing>
                         <property name="expand">False</property>
@@ -485,61 +378,13 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkInfoBar" id="infobar_details_repo">
+                      <object class="GsInfoBar" id="infobar_details_repo">
                         <property name="visible">True</property>
-                        <property name="app_paintable">True</property>
                         <property name="can_focus">False</property>
-                        <property name="message_type">info</property>
                         <property name="margin_top">20</property>
-                        <style>
-                          <class name="application-details-infobar"/>
-                        </style>
-                        <child internal-child="content_area">
-                          <object class="GtkBox" id="infobar-content_area4">
-                            <property name="can_focus">False</property>
-                            <property name="spacing">0</property>
-                            <property name="halign">fill</property>
-                            <property name="orientation">vertical</property>
-                            <child>
-                              <object class="GtkLabel" id="label_header_details_repo">
-                                <property name="justify">center</property>
-                                <property name="wrap">True</property>
-                                <property name="max_width_chars">30</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes" comments="Translators: a 
repository file used for installing software has been discovered.">Software Source Identified</property>
-                                <attributes>
-                                  <attribute name="weight" value="bold"/>
-                                </attributes>
-                              </object>
-                            </child>
-                            <child>
-                              <object class="GtkLabel" id="label_details_repo">
-                                <property name="justify">center</property>
-                                <property name="wrap">True</property>
-                                <property name="max_width_chars">30</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes">Adding this software source will 
give you access to additional software and upgrades.</property>
-                              </object>
-                            </child>
-                            <child>
-                              <object class="GtkLabel" id="label_details_repo2">
-                                <property name="justify">center</property>
-                                <property name="wrap">True</property>
-                                <property name="max_width_chars">30</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="label" translatable="yes">Only use software sources that you 
trust.</property>
-                              </object>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
+                        <property name="title" translatable="yes" comments="Translators: a repository file 
used for installing software has been discovered.">Software Source Identified</property>
+                        <property name="body" translatable="yes">Adding this software source will give you 
access to additional software and upgrades.</property>
+                        <property name="warning" translatable="yes">Only use software sources that you 
trust.</property>
                       </object>
                       <packing>
                         <property name="expand">False</property>


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