[gnome-software: 2/13] app-row: Add is-narrow property




commit 44c30356055ffce59414c22195adebf1297c74ea
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu Jun 24 12:06:50 2021 +0200

    app-row: Add is-narrow property
    
    This is used to decide whether to set the row in narrow mode or not,
    showing the progress button's icon when narrow.

 src/gs-app-row.c  | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/gs-app-row.h  |  3 +++
 src/gs-app-row.ui |  1 +
 3 files changed, 74 insertions(+), 1 deletion(-)
---
diff --git a/src/gs-app-row.c b/src/gs-app-row.c
index 369d2a184..57675dd6d 100644
--- a/src/gs-app-row.c
+++ b/src/gs-app-row.c
@@ -46,6 +46,7 @@ typedef struct
        gboolean         show_update;
        gboolean         show_installed_size;
        guint            pending_refresh_id;
+       gboolean         is_narrow;
 } GsAppRowPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsAppRow, gs_app_row, GTK_TYPE_LIST_BOX_ROW)
@@ -63,9 +64,10 @@ typedef enum {
        PROP_SHOW_SOURCE,
        PROP_SHOW_BUTTONS,
        PROP_SHOW_INSTALLED_SIZE,
+       PROP_IS_NARROW,
 } GsAppRowProperty;
 
-static GParamSpec *obj_props[PROP_SHOW_INSTALLED_SIZE + 1] = { NULL, };
+static GParamSpec *obj_props[PROP_IS_NARROW + 1] = { NULL, };
 
 /**
  * gs_app_row_get_description:
@@ -619,6 +621,9 @@ gs_app_row_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
        case PROP_SHOW_INSTALLED_SIZE:
                g_value_set_boolean (value, priv->show_installed_size);
                break;
+       case PROP_IS_NARROW:
+               g_value_set_boolean (value, gs_app_row_get_is_narrow (app_row));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -643,6 +648,9 @@ gs_app_row_set_property (GObject *object, guint prop_id, const GValue *value, GP
        case PROP_SHOW_INSTALLED_SIZE:
                gs_app_row_set_show_installed_size (app_row, g_value_get_boolean (value));
                break;
+       case PROP_IS_NARROW:
+               gs_app_row_set_is_narrow (app_row, g_value_get_boolean (value));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -725,6 +733,22 @@ gs_app_row_class_init (GsAppRowClass *klass)
                                      FALSE,
                                      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
+       /**
+        * GsAppRow:is-narrow:
+        *
+        * Whether the row is in narrow mode.
+        *
+        * In narrow mode, the row will take up less horizontal space, doing so
+        * by e.g. using icons rather than labels in buttons. This is needed to
+        * keep the UI useable on small form-factors like smartphones.
+        *
+        * Since: 41
+        */
+       obj_props[PROP_IS_NARROW] =
+               g_param_spec_boolean ("is-narrow", NULL, NULL,
+                                     FALSE,
+                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
        g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_props), obj_props);
 
        signals [SIGNAL_BUTTON_CLICKED] =
@@ -843,6 +867,51 @@ gs_app_row_set_show_installed_size (GsAppRow *app_row, gboolean show_size)
        gs_app_row_schedule_refresh (app_row);
 }
 
+/**
+ * gs_app_row_get_is_narrow:
+ * @app_row: a #GsAppRow
+ *
+ * Get the value of #GsAppRow:is-narrow.
+ *
+ * Retruns: %TRUE if the row is in narrow mode, %FALSE otherwise
+ *
+ * Since: 41
+ */
+gboolean
+gs_app_row_get_is_narrow (GsAppRow *app_row)
+{
+       GsAppRowPrivate *priv = gs_app_row_get_instance_private (app_row);
+
+       g_return_val_if_fail (GS_IS_APP_ROW (app_row), FALSE);
+
+       return priv->is_narrow;
+}
+
+/**
+ * gs_app_row_set_is_narrow:
+ * @app_row: a #GsAppRow
+ * @is_narrow: %TRUE to set the row in narrow mode, %FALSE otherwise
+ *
+ * Set the value of #GsAppRow:is-narrow.
+ *
+ * Since: 41
+ */
+void
+gs_app_row_set_is_narrow (GsAppRow *app_row, gboolean is_narrow)
+{
+       GsAppRowPrivate *priv = gs_app_row_get_instance_private (app_row);
+
+       g_return_if_fail (GS_IS_APP_ROW (app_row));
+
+       is_narrow = !!is_narrow;
+
+       if (priv->is_narrow == is_narrow)
+               return;
+
+       priv->is_narrow = is_narrow;
+       g_object_notify_by_pspec (G_OBJECT (app_row), obj_props[PROP_IS_NARROW]);
+}
+
 /**
  * gs_app_row_set_show_update:
  *
diff --git a/src/gs-app-row.h b/src/gs-app-row.h
index afe386df2..2d486a0c4 100644
--- a/src/gs-app-row.h
+++ b/src/gs-app-row.h
@@ -46,5 +46,8 @@ void           gs_app_row_set_size_groups             (GsAppRow       *app_row,
                                                         GtkSizeGroup   *button);
 void            gs_app_row_set_show_installed_size     (GsAppRow       *app_row,
                                                         gboolean        show_size);
+gboolean        gs_app_row_get_is_narrow               (GsAppRow       *app_row);
+void            gs_app_row_set_is_narrow               (GsAppRow       *app_row,
+                                                        gboolean        is_narrow);
 
 G_END_DECLS
diff --git a/src/gs-app-row.ui b/src/gs-app-row.ui
index 75a4bfe21..6f46b22f7 100644
--- a/src/gs-app-row.ui
+++ b/src/gs-app-row.ui
@@ -205,6 +205,7 @@
                     <property name="visible">False</property>
                     <property name="width_request">100</property>
                     <property name="halign">end</property>
+                    <property name="show-icon" bind-source="GsAppRow" bind-property="is-narrow" 
bind-flags="sync-create"/>
                  </object>
                  <packing>
                     <property name="pack_type">end</property>


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