[gnome-software: 10/18] details-page: Add the is-narrow property
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 10/18] details-page: Add the is-narrow property
- Date: Fri, 13 Aug 2021 15:12:59 +0000 (UTC)
commit cb696851af8e30894e73d4471002897b30f060c6
Author: Adrien Plazas <kekun plazas laposte net>
Date: Tue Aug 10 11:11:42 2021 +0200
details-page: Add the is-narrow property
This will be used to tweak the page based on the window's width.
src/gs-details-page.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++-
src/gs-details-page.h | 4 +++
src/gs-shell.ui | 1 +
3 files changed, 71 insertions(+), 1 deletion(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index ed81f8e36..734e8c86c 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -85,6 +85,7 @@ struct _GsDetailsPage
GHashTable *packaging_format_preference; /* gchar * ~> gint */
gboolean origin_by_packaging_format; /* when TRUE, change the 'app' to the most
preferred
packaging format when the alternatives are
found */
+ gboolean is_narrow;
GtkWidget *application_details_icon;
GtkWidget *application_details_summary;
@@ -146,11 +147,12 @@ G_DEFINE_TYPE (GsDetailsPage, gs_details_page, GS_TYPE_PAGE)
typedef enum {
PROP_ODRS_PROVIDER = 1,
+ PROP_IS_NARROW,
/* Override properties: */
PROP_TITLE,
} GsDetailsPageProperty;
-static GParamSpec *obj_props[PROP_ODRS_PROVIDER + 1] = { NULL, };
+static GParamSpec *obj_props[PROP_IS_NARROW + 1] = { NULL, };
static GsDetailsPageState
gs_details_page_get_state (GsDetailsPage *self)
@@ -2123,6 +2125,9 @@ gs_details_page_get_property (GObject *object,
case PROP_ODRS_PROVIDER:
g_value_set_object (value, gs_details_page_get_odrs_provider (self));
break;
+ case PROP_IS_NARROW:
+ g_value_set_boolean (value, gs_details_page_get_is_narrow (self));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -2145,6 +2150,9 @@ gs_details_page_set_property (GObject *object,
case PROP_ODRS_PROVIDER:
gs_details_page_set_odrs_provider (self, g_value_get_object (value));
break;
+ case PROP_IS_NARROW:
+ gs_details_page_set_is_narrow (self, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -2209,6 +2217,22 @@ gs_details_page_class_init (GsDetailsPageClass *klass)
GS_TYPE_ODRS_PROVIDER,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+ /**
+ * GsDetailsPage:is-narrow:
+ *
+ * Whether the page is in narrow mode.
+ *
+ * In narrow mode, the page will take up less horizontal space, doing so
+ * by e.g. turning horizontal boxes into vertical ones. 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);
g_object_class_override_property (object_class, PROP_TITLE, "title");
@@ -2365,3 +2389,44 @@ gs_details_page_set_odrs_provider (GsDetailsPage *self,
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ODRS_PROVIDER]);
}
}
+
+/**
+ * gs_details_page_get_is_narrow:
+ * @self: a #GsDetailsPage
+ *
+ * Get the value of #GsDetailsPage:is-narrow.
+ *
+ * Returns: %TRUE if the page is in narrow mode, %FALSE otherwise
+ *
+ * Since: 41
+ */
+gboolean
+gs_details_page_get_is_narrow (GsDetailsPage *self)
+{
+ g_return_val_if_fail (GS_IS_DETAILS_PAGE (self), FALSE);
+
+ return self->is_narrow;
+}
+
+/**
+ * gs_details_page_set_is_narrow:
+ * @self: a #GsDetailsPage
+ * @is_narrow: %TRUE to set the page in narrow mode, %FALSE otherwise
+ *
+ * Set the value of #GsDetailsPage:is-narrow.
+ *
+ * Since: 41
+ */
+void
+gs_details_page_set_is_narrow (GsDetailsPage *self, gboolean is_narrow)
+{
+ g_return_if_fail (GS_IS_DETAILS_PAGE (self));
+
+ is_narrow = !!is_narrow;
+
+ if (self->is_narrow == is_narrow)
+ return;
+
+ self->is_narrow = is_narrow;
+ g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_IS_NARROW]);
+}
diff --git a/src/gs-details-page.h b/src/gs-details-page.h
index d7cc1c2da..1ec5059d1 100644
--- a/src/gs-details-page.h
+++ b/src/gs-details-page.h
@@ -30,4 +30,8 @@ GsOdrsProvider *gs_details_page_get_odrs_provider (GsDetailsPage *self);
void gs_details_page_set_odrs_provider (GsDetailsPage *self,
GsOdrsProvider *odrs_provider);
+gboolean gs_details_page_get_is_narrow (GsDetailsPage *self);
+void gs_details_page_set_is_narrow (GsDetailsPage *self,
+ gboolean is_narrow);
+
G_END_DECLS
diff --git a/src/gs-shell.ui b/src/gs-shell.ui
index 6b9b1d752..45f3dd4a7 100644
--- a/src/gs-shell.ui
+++ b/src/gs-shell.ui
@@ -481,6 +481,7 @@
<child>
<object class="GsDetailsPage" id="details_page">
<property name="visible">True</property>
+ <property name="is-narrow" bind-source="GsShell" bind-property="is-narrow"
bind-flags="sync-create"/>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]