[gtk/wip/otte/whatever: 88/105] filterlistmodel: Add gtk_filter_list_model_get_pending()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/whatever: 88/105] filterlistmodel: Add gtk_filter_list_model_get_pending()
- Date: Mon, 6 Jul 2020 00:53:39 +0000 (UTC)
commit 695a7815d042a9b509a54653189063c5473f3b13
Author: Benjamin Otte <otte redhat com>
Date: Tue Jun 30 04:01:39 2020 +0200
filterlistmodel: Add gtk_filter_list_model_get_pending()
This allows tracking if the model is busy filtering.
docs/reference/gtk/gtk4-sections.txt | 1 +
gtk/gtkfilterlistmodel.c | 51 ++++++++++++++++++++++++++++++++++++
gtk/gtkfilterlistmodel.h | 2 ++
3 files changed, 54 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 4016e3847b..f3a303e5f0 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -1549,6 +1549,7 @@ gtk_filter_list_model_set_filter
gtk_filter_list_model_get_filter
gtk_filter_list_model_set_incremental
gtk_filter_list_model_get_incremental
+gtk_filter_list_model_get_pending
<SUBSECTION Standard>
GTK_FILTER_LIST_MODEL
GTK_IS_FILTER_LIST_MODEL
diff --git a/gtk/gtkfilterlistmodel.c b/gtk/gtkfilterlistmodel.c
index 6078673a25..9ef3545e85 100644
--- a/gtk/gtkfilterlistmodel.c
+++ b/gtk/gtkfilterlistmodel.c
@@ -46,6 +46,7 @@ enum {
PROP_FILTER,
PROP_INCREMENTAL,
PROP_MODEL,
+ PROP_PENDING,
NUM_PROPERTIES
};
@@ -180,6 +181,7 @@ gtk_filter_list_model_run_filter (GtkFilterListModel *self,
gtk_bitset_remove_range_closed (self->pending, 0, pos);
else
g_clear_pointer (&self->pending, gtk_bitset_unref);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PENDING]);
return;
}
@@ -187,8 +189,13 @@ gtk_filter_list_model_run_filter (GtkFilterListModel *self,
static void
gtk_filter_list_model_stop_filtering (GtkFilterListModel *self)
{
+ gboolean notify_pending = self->pending != NULL;
+
g_clear_pointer (&self->pending, gtk_bitset_unref);
g_clear_handle_id (&self->pending_cb, g_source_remove);
+
+ if (notify_pending)
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PENDING]);
}
static void
@@ -240,6 +247,7 @@ gtk_filter_list_model_start_filtering (GtkFilterListModel *self,
{
gtk_bitset_union (self->pending, items);
gtk_bitset_unref (items);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PENDING]);
return;
}
@@ -258,6 +266,7 @@ gtk_filter_list_model_start_filtering (GtkFilterListModel *self,
return;
}
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PENDING]);
g_assert (self->pending_cb == 0);
self->pending_cb = g_idle_add (gtk_filter_list_model_run_filter_cb, self);
g_source_set_name_by_id (self->pending_cb, "[gtk] gtk_filter_list_model_run_filter_cb");
@@ -361,6 +370,10 @@ gtk_filter_list_model_get_property (GObject *object,
g_value_set_object (value, self->model);
break;
+ case PROP_PENDING:
+ g_value_set_uint (value, gtk_filter_list_model_get_pending (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -560,6 +573,18 @@ gtk_filter_list_model_class_init (GtkFilterListModelClass *class)
G_TYPE_LIST_MODEL,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * GtkFilterListModel:pending:
+ *
+ * Number of items not yet filtered
+ */
+ properties[PROP_PENDING] =
+ g_param_spec_uint ("pending",
+ P_("Pending"),
+ P_("Number of items not yet filtered"),
+ 0, G_MAXUINT, 0,
+ GTK_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
+
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
@@ -783,3 +808,29 @@ gtk_filter_list_model_get_incremental (GtkFilterListModel *self)
return self->incremental;
}
+
+/**
+ * gtk_filter_list_model_get_pending:
+ * @self: a #GtkFilterListModel
+ *
+ * Returns the number of items that have not been filtered yet.
+ *
+ * When incremental filtering is not enabled, this always returns 0.
+ *
+ * You can use this value to check if @self is busy filtering by
+ * comparing the return value to 0 or you can compute the percentage
+ * of the filter remaining by dividing the return value by
+ * g_list_model_get_n_items(gtk_filter_list_model_get_model (self)).
+ *
+ * Returns: The number of items not yet filtered
+ **/
+guint
+gtk_filter_list_model_get_pending (GtkFilterListModel *self)
+{
+ g_return_val_if_fail (GTK_IS_FILTER_LIST_MODEL (self), FALSE);
+
+ if (self->pending == NULL)
+ return 0;
+
+ return gtk_bitset_get_size (self->pending);
+}
diff --git a/gtk/gtkfilterlistmodel.h b/gtk/gtkfilterlistmodel.h
index 6dfb82ffee..35913c1836 100644
--- a/gtk/gtkfilterlistmodel.h
+++ b/gtk/gtkfilterlistmodel.h
@@ -55,6 +55,8 @@ void gtk_filter_list_model_set_incremental (GtkFilterListMo
gboolean incremental);
GDK_AVAILABLE_IN_ALL
gboolean gtk_filter_list_model_get_incremental (GtkFilterListModel *self);
+GDK_AVAILABLE_IN_ALL
+guint gtk_filter_list_model_get_pending (GtkFilterListModel *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]