[gnome-software: 17/24] gs-category-page: Add GsCategoryPage:category property
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software: 17/24] gs-category-page: Add GsCategoryPage:category property
- Date: Mon, 3 May 2021 15:24:14 +0000 (UTC)
commit ac3fc94924e9fcde02f6aece1e696230d04d5ea6
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu Apr 22 15:38:06 2021 +0100
gs-category-page: Add GsCategoryPage:category property
As a convenience for binding things to in future.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
src/gs-category-page.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/src/gs-category-page.c b/src/gs-category-page.c
index 344b92511..29fd3aa15 100644
--- a/src/gs-category-page.c
+++ b/src/gs-category-page.c
@@ -36,9 +36,13 @@ struct _GsCategoryPage
G_DEFINE_TYPE (GsCategoryPage, gs_category_page, GS_TYPE_PAGE)
typedef enum {
- PROP_TITLE = 1,
+ PROP_CATEGORY = 1,
+ /* Override properties: */
+ PROP_TITLE,
} GsCategoryPageProperty;
+static GParamSpec *obj_props[PROP_CATEGORY + 1] = { NULL, };
+
typedef enum {
SIGNAL_APP_CLICKED,
} GsCategoryPageSignal;
@@ -267,7 +271,8 @@ gs_category_page_set_category (GsCategoryPage *self, GsCategory *category)
if (all_subcat != NULL)
gs_category_page_load_category (self);
- /* notify of the updated title */
+ /* notify of the updates — the category’s title will have changed too */
+ g_object_notify (G_OBJECT (self), "category");
g_object_notify (G_OBJECT (self), "title");
}
@@ -298,6 +303,31 @@ gs_category_page_get_property (GObject *object,
else
g_value_set_string (value, NULL);
break;
+ case PROP_CATEGORY:
+ g_value_set_object (value, self->category);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gs_category_page_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GsCategoryPage *self = GS_CATEGORY_PAGE (object);
+
+ switch ((GsCategoryPageProperty) prop_id) {
+ case PROP_TITLE:
+ /* Read only */
+ g_assert_not_reached ();
+ break;
+ case PROP_CATEGORY:
+ gs_category_page_set_category (self, g_value_get_object (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -341,11 +371,29 @@ gs_category_page_class_init (GsCategoryPageClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->get_property = gs_category_page_get_property;
+ object_class->set_property = gs_category_page_set_property;
object_class->dispose = gs_category_page_dispose;
page_class->reload = gs_category_page_reload;
page_class->setup = gs_category_page_setup;
+ /**
+ * GsCategoryPage:category: (nullable)
+ *
+ * The category to display the apps from.
+ *
+ * This may be %NULL if no category is selected. If so, the behaviour
+ * of the widget will be safe, but undefined.
+ *
+ * Since: 41
+ */
+ obj_props[PROP_CATEGORY] =
+ g_param_spec_object ("category", NULL, NULL,
+ GS_TYPE_CATEGORY,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, G_N_ELEMENTS (obj_props), obj_props);
+
g_object_class_override_property (object_class, PROP_TITLE, "title");
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]