[gnome-software/1392-unify-lozenge-styling: 13/18] gs-context-dialog-row: Use GsLozenge




commit 25dfc52114cfe30dc2559862f682ef87c46647c7
Author: Milan Crha <mcrha redhat com>
Date:   Tue May 3 20:49:09 2022 +0200

    gs-context-dialog-row: Use GsLozenge

 src/gs-context-dialog-row.c     | 37 +++++++++++++++----------------------
 src/gs-context-dialog-row.h     |  4 ++--
 src/gs-context-dialog-row.ui    | 27 +++------------------------
 src/gs-storage-context-dialog.c |  3 ++-
 4 files changed, 22 insertions(+), 49 deletions(-)
---
diff --git a/src/gs-context-dialog-row.c b/src/gs-context-dialog-row.c
index 11c9f3822..73f8fcbfc 100644
--- a/src/gs-context-dialog-row.c
+++ b/src/gs-context-dialog-row.c
@@ -30,6 +30,7 @@
 #include <gtk/gtk.h>
 
 #include "gs-context-dialog-row.h"
+#include "gs-lozenge.h"
 #include "gs-enums.h"
 
 struct _GsContextDialogRow
@@ -38,9 +39,7 @@ struct _GsContextDialogRow
 
        GsContextDialogRowImportance     importance;
 
-       GtkWidget                       *lozenge;  /* (unowned) */
-       GtkImage                        *lozenge_content_image;  /* (unowned) */
-       GtkLabel                        *lozenge_content_text;  /* (unowned) */
+       GsLozenge                       *lozenge;  /* (unowned) */
 };
 
 G_DEFINE_TYPE (GsContextDialogRow, gs_context_dialog_row, ADW_TYPE_ACTION_ROW)
@@ -111,14 +110,10 @@ gs_context_dialog_row_set_property (GObject      *object,
 
        switch ((GsContextDialogRowProperty) prop_id) {
        case PROP_ICON_NAME:
-               gtk_image_set_from_icon_name (self->lozenge_content_image, g_value_get_string (value));
-               gtk_widget_set_visible (GTK_WIDGET (self->lozenge_content_image), TRUE);
-               gtk_widget_set_visible (GTK_WIDGET (self->lozenge_content_text), FALSE);
+               gs_lozenge_set_icon_name (self->lozenge, g_value_get_string (value));
                break;
        case PROP_CONTENT:
-               gtk_label_set_text (self->lozenge_content_text, g_value_get_string (value));
-               gtk_widget_set_visible (GTK_WIDGET (self->lozenge_content_image), FALSE);
-               gtk_widget_set_visible (GTK_WIDGET (self->lozenge_content_text), TRUE);
+               gs_lozenge_set_text (self->lozenge, g_value_get_string (value));
                break;
        case PROP_IMPORTANCE: {
                GtkStyleContext *context;
@@ -127,7 +122,7 @@ gs_context_dialog_row_set_property (GObject      *object,
                self->importance = g_value_get_enum (value);
                css_class = css_class_for_importance (self->importance);
 
-               context = gtk_widget_get_style_context (self->lozenge);
+               context = gtk_widget_get_style_context (GTK_WIDGET (self->lozenge));
 
                gtk_style_context_remove_class (context, "green");
                gtk_style_context_remove_class (context, "yellow");
@@ -204,8 +199,6 @@ gs_context_dialog_row_class_init (GsContextDialogRowClass *klass)
        gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Software/gs-context-dialog-row.ui");
 
        gtk_widget_class_bind_template_child (widget_class, GsContextDialogRow, lozenge);
-       gtk_widget_class_bind_template_child (widget_class, GsContextDialogRow, lozenge_content_image);
-       gtk_widget_class_bind_template_child (widget_class, GsContextDialogRow, lozenge_content_text);
 }
 
 /**
@@ -282,7 +275,7 @@ gs_context_dialog_row_get_icon_name (GsContextDialogRow *self)
 {
        g_return_val_if_fail (GS_IS_CONTEXT_DIALOG_ROW (self), NULL);
 
-       return gtk_image_get_icon_name (self->lozenge_content_image);
+       return gs_lozenge_get_icon_name (self->lozenge);
 }
 
 /**
@@ -299,7 +292,7 @@ gs_context_dialog_row_get_content (GsContextDialogRow *self)
 {
        g_return_val_if_fail (GS_IS_CONTEXT_DIALOG_ROW (self), NULL);
 
-       return gtk_label_get_text (self->lozenge_content_text);
+       return gs_lozenge_get_text (self->lozenge);
 }
 
 /**
@@ -316,25 +309,25 @@ gs_context_dialog_row_get_content_is_markup (GsContextDialogRow *self)
 {
        g_return_val_if_fail (GS_IS_CONTEXT_DIALOG_ROW (self), FALSE);
 
-       return gtk_label_get_use_markup (self->lozenge_content_text);
+       return gs_lozenge_get_use_markup (self->lozenge);
 }
 
 /**
- * gs_context_dialog_row_set_content_is_markup:
+ * gs_context_dialog_row_set_content_markup:
  * @self: a #GsContextDialogRow
- * @is_markup: value to set
+ * @markup: markup to set
  *
- * Set to %TRUE, when the #GsContextDialogRow:content is markup.
+ * Set the @markup content as markup.
  *
  * Since: 43
  */
 void
-gs_context_dialog_row_set_content_is_markup (GsContextDialogRow *self,
-                                            gboolean is_markup)
+gs_context_dialog_row_set_content_markup (GsContextDialogRow *self,
+                                         const gchar *markup)
 {
        g_return_if_fail (GS_IS_CONTEXT_DIALOG_ROW (self));
 
-       gtk_label_set_use_markup (self->lozenge_content_text, is_markup);
+       gs_lozenge_set_markup (self->lozenge, markup);
 }
 
 /**
@@ -378,5 +371,5 @@ gs_context_dialog_row_set_size_groups (GsContextDialogRow *self,
        g_return_if_fail (description == NULL || GTK_IS_SIZE_GROUP (description));
 
        if (lozenge != NULL)
-               gtk_size_group_add_widget (lozenge, self->lozenge);
+               gtk_size_group_add_widget (lozenge, GTK_WIDGET (self->lozenge));
 }
diff --git a/src/gs-context-dialog-row.h b/src/gs-context-dialog-row.h
index 74c805918..d5d68fd25 100644
--- a/src/gs-context-dialog-row.h
+++ b/src/gs-context-dialog-row.h
@@ -57,9 +57,9 @@ const gchar                   *gs_context_dialog_row_get_content      (GsContextDialogRow   
  *self);
 GsContextDialogRowImportance    gs_context_dialog_row_get_importance   (GsContextDialogRow     *self);
 gboolean                        gs_context_dialog_row_get_content_is_markup
                                                                        (GsContextDialogRow     *self);
-void                            gs_context_dialog_row_set_content_is_markup
+void                            gs_context_dialog_row_set_content_markup
                                                                        (GsContextDialogRow     *self,
-                                                                        gboolean                is_markup);
+                                                                        const gchar            *markup);
 
 void                            gs_context_dialog_row_set_size_groups  (GsContextDialogRow     *self,
                                                                         GtkSizeGroup           *lozenge,
diff --git a/src/gs-context-dialog-row.ui b/src/gs-context-dialog-row.ui
index f759f9bf1..47a78dff1 100644
--- a/src/gs-context-dialog-row.ui
+++ b/src/gs-context-dialog-row.ui
@@ -6,35 +6,14 @@
     <property name="focusable">False</property>
 
     <child type="prefix">
-      <object class="GtkBox" id="lozenge">
-        <property name="halign">center</property>
-        <property name="valign">center</property>
-        <property name="hexpand">False</property>
+      <object class="GsLozenge" id="lozenge">
+        <property name="circular">True</property>
+        <property name="pixel-size">16</property>
         <property name="margin-top">8</property>
         <property name="margin-bottom">8</property>
         <style>
-          <class name="context-tile-lozenge"/>
           <class name="grey"/>
         </style>
-        <child>
-          <object class="GtkImage" id="lozenge_content_image">
-            <property name="halign">center</property>
-            <property name="hexpand">True</property>
-            <!-- this is a placeholder: the icon is actually set in code -->
-            <property name="icon-name">safety-symbolic</property>
-            <property name="pixel-size">16</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkLabel" id="lozenge_content_text">
-            <property name="halign">center</property>
-            <property name="hexpand">True</property>
-            <!-- this is a placeholder: the text is actually set in code -->
-            <property name="label">20 MB</property>
-            <property name="visible">False</property>
-            <property name="xalign">0.5</property>
-          </object>
-        </child>
       </object>
     </child>
   </template>
diff --git a/src/gs-storage-context-dialog.c b/src/gs-storage-context-dialog.c
index 7ca2e29d9..a03575b12 100644
--- a/src/gs-storage-context-dialog.c
+++ b/src/gs-storage-context-dialog.c
@@ -98,7 +98,8 @@ add_size_row (GtkListBox   *list_box,
 
        row = gs_context_dialog_row_new_text (size_bytes_str, GS_CONTEXT_DIALOG_ROW_IMPORTANCE_NEUTRAL,
                                              title, description);
-       gs_context_dialog_row_set_content_is_markup (GS_CONTEXT_DIALOG_ROW (row), is_markup);
+       if (is_markup)
+               gs_context_dialog_row_set_content_markup (GS_CONTEXT_DIALOG_ROW (row), size_bytes_str);
        gs_context_dialog_row_set_size_groups (GS_CONTEXT_DIALOG_ROW (row), lozenge_size_group, NULL, NULL);
        gtk_list_box_append (list_box, GTK_WIDGET (row));
 }


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