[gnome-software: 46/110] gs-info-bar: Subclass GtkWidget




commit 704c27260ae5b0de5253dc7eb44595062267cbc4
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Aug 24 09:39:59 2021 -0300

    gs-info-bar: Subclass GtkWidget

 src/gs-info-bar.c  | 26 ++++++++++++++++---
 src/gs-info-bar.h  |  2 +-
 src/gs-info-bar.ui | 73 ++++++++++++++++++++++++++++--------------------------
 3 files changed, 62 insertions(+), 39 deletions(-)
---
diff --git a/src/gs-info-bar.c b/src/gs-info-bar.c
index da9b239f1..fc946f80f 100644
--- a/src/gs-info-bar.c
+++ b/src/gs-info-bar.c
@@ -12,20 +12,22 @@
 
 struct _GsInfoBar
 {
-       GtkInfoBar       parent_instance;
+       GtkWidget        parent_instance;
 
+       GtkInfoBar      *info_bar;
        GtkWidget       *label_title;
        GtkWidget       *label_body;
        GtkWidget       *label_warning;
 };
 
-G_DEFINE_TYPE (GsInfoBar, gs_info_bar, GTK_TYPE_INFO_BAR)
+G_DEFINE_TYPE (GsInfoBar, gs_info_bar, GTK_TYPE_WIDGET)
 
 enum {
        PROP_0,
        PROP_TITLE,
        PROP_BODY,
-       PROP_WARNING
+       PROP_WARNING,
+       PROP_MESSAGE_TYPE,
 };
 
 static void
@@ -46,6 +48,9 @@ gs_info_bar_get_property (GObject *object,
        case PROP_WARNING:
                g_value_set_string (value, gs_info_bar_get_warning (infobar));
                break;
+       case PROP_MESSAGE_TYPE:
+               g_value_set_enum (value, gtk_info_bar_get_message_type (infobar->info_bar));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -70,6 +75,9 @@ gs_info_bar_set_property (GObject *object,
        case PROP_WARNING:
                gs_info_bar_set_warning (infobar, g_value_get_string (value));
                break;
+       case PROP_MESSAGE_TYPE:
+               gtk_info_bar_set_message_type (infobar->info_bar, g_value_get_enum (value));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -112,8 +120,20 @@ gs_info_bar_class_init (GsInfoBarClass *klass)
                                     NULL,
                                     G_PARAM_READWRITE));
 
+       g_object_class_install_property (object_class, PROP_MESSAGE_TYPE,
+               g_param_spec_enum ("message-type",
+                                  "Message Type",
+                                  "The type of message",
+                                  GTK_TYPE_MESSAGE_TYPE,
+                                  GTK_MESSAGE_INFO,
+                                  G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+
        gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Software/gs-info-bar.ui");
+       gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
 
+       gtk_widget_class_bind_template_child (widget_class,
+                                             GsInfoBar, info_bar);
        gtk_widget_class_bind_template_child (widget_class,
                                              GsInfoBar, label_title);
        gtk_widget_class_bind_template_child (widget_class,
diff --git a/src/gs-info-bar.h b/src/gs-info-bar.h
index 7001867bd..832e69286 100644
--- a/src/gs-info-bar.h
+++ b/src/gs-info-bar.h
@@ -14,7 +14,7 @@ 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)
+G_DECLARE_FINAL_TYPE (GsInfoBar, gs_info_bar, GS, INFO_BAR, GtkWidget)
 
 GtkWidget      *gs_info_bar_new                (void);
 const gchar    *gs_info_bar_get_title          (GsInfoBar      *bar);
diff --git a/src/gs-info-bar.ui b/src/gs-info-bar.ui
index 8977442db..b2ce23ee4 100644
--- a/src/gs-info-bar.ui
+++ b/src/gs-info-bar.ui
@@ -1,42 +1,45 @@
 <?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="spacing">0</property>
-        <property name="halign">fill</property>
-        <property name="orientation">vertical</property>
+  <template class="GsInfoBar" parent="GtkWidget">
+    <child>
+      <object class="GtkInfoBar" id="info_bar">
+        <property name="message_type">info</property>
+        <style>
+          <class name="application-details-infobar"/>
+        </style>
         <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>
-            <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>
-          </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>
+          <object class="GtkBox" id="content_area">
+            <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>
+                <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>
+              </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>
+              </object>
+            </child>
           </object>
         </child>
       </object>


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