From 6b62d63d36a107a7465c4f578ba2892b4747fa87 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 8 Jun 2022 18:19:01 +0200 Subject: [PATCH] liststore: Add "n-items" property --- gio/gliststore.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gio/gliststore.c b/gio/gliststore.c index 555b4f310..e7dbbd38f 100644 --- a/gio/gliststore.c +++ b/gio/gliststore.c @@ -64,6 +64,7 @@ enum { PROP_0, PROP_ITEM_TYPE, + PROP_N_ITEMS, N_PROPERTIES }; @@ -89,6 +90,8 @@ g_list_store_items_changed (GListStore *store, } g_list_model_items_changed (G_LIST_MODEL (store), position, removed, added); + if (removed != added) + g_object_notify_by_pspec (G_OBJECT (store), properties[PROP_N_ITEMS]); } static void @@ -115,6 +118,10 @@ g_list_store_get_property (GObject *object, g_value_set_gtype (value, store->item_type); break; + case PROP_N_ITEMS: + g_value_set_uint (value, g_sequence_get_length (store->items)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } @@ -157,10 +164,21 @@ g_list_store_class_init (GListStoreClass *klass) * * Since: 2.44 **/ - properties[PROP_ITEM_TYPE] = + properties[PROP_ITEM_TYPE] = g_param_spec_gtype ("item-type", "", "", G_TYPE_OBJECT, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + /** + * GListStore:n-items: + * + * The number of items contained in this list store. + * + * Since: 2.74 + **/ + properties[PROP_N_ITEMS] = + g_param_spec_uint ("n-items", "", "", 0, G_MAXUINT, 0, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, N_PROPERTIES, properties); }