[gtk/file-filter2: 2/5] filefilter: Convert to a GtkFilter
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/file-filter2: 2/5] filefilter: Convert to a GtkFilter
- Date: Sun, 5 Jul 2020 17:04:01 +0000 (UTC)
commit 9161f81818455b3ee7be1ce7bf40b55253afa762
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jul 4 10:57:07 2020 -0400
filefilter: Convert to a GtkFilter
Make GtkFileFilter implement GtkFilter.
gtk/gtkfilefilter.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 46 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkfilefilter.c b/gtk/gtkfilefilter.c
index 7f2560f477..8e0fe85927 100644
--- a/gtk/gtkfilefilter.c
+++ b/gtk/gtkfilefilter.c
@@ -91,12 +91,12 @@ typedef enum {
struct _GtkFileFilterClass
{
- GObjectClass parent_class;
+ GtkFilterClass parent_class;
};
struct _GtkFileFilter
{
- GObject parent_instance;
+ GtkFilter parent_instance;
gchar *name;
GSList *rules;
@@ -157,8 +157,12 @@ static void gtk_file_filter_buildable_custom_tag_end (GtkBuildable
const gchar *tagname,
gpointer data);
+static gboolean gtk_file_filter_match (GtkFilter *filter,
+ gpointer item);
+static GtkFilterMatch gtk_file_filter_get_strictness (GtkFilter *filter);
-G_DEFINE_TYPE_WITH_CODE (GtkFileFilter, gtk_file_filter, G_TYPE_OBJECT,
+
+G_DEFINE_TYPE_WITH_CODE (GtkFileFilter, gtk_file_filter, GTK_TYPE_FILTER,
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
gtk_file_filter_buildable_init))
@@ -171,11 +175,15 @@ static void
gtk_file_filter_class_init (GtkFileFilterClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+ GtkFilterClass *filter_class = GTK_FILTER_CLASS (class);
gobject_class->set_property = gtk_file_filter_set_property;
gobject_class->get_property = gtk_file_filter_get_property;
gobject_class->finalize = gtk_file_filter_finalize;
+ filter_class->get_strictness = gtk_file_filter_get_strictness;
+ filter_class->match = gtk_file_filter_match;
+
/**
* GtkFileFilter:name:
*
@@ -509,6 +517,8 @@ file_filter_add_rule (GtkFileFilter *filter,
{
filter->needed |= rule->needed;
filter->rules = g_slist_append (filter->rules, rule);
+
+ gtk_filter_changed (GTK_FILTER (filter), GTK_FILTER_CHANGE_LESS_STRICT);
}
/**
@@ -766,6 +776,39 @@ _gtk_file_filter_get_as_patterns (GtkFileFilter *filter)
return (char **)g_ptr_array_free (array, FALSE);
}
+static GtkFilterMatch
+gtk_file_filter_get_strictness (GtkFilter *filter)
+{
+ GtkFileFilter *file_filter = GTK_FILE_FILTER (filter);
+
+ /* Handle only the documented cases for 'match all'
+ * and match none. There are of course other ways to
+ * make filters that do this.
+ */
+ if (file_filter->rules == NULL)
+ return GTK_FILTER_MATCH_NONE;
+
+ if (file_filter->rules->next == NULL)
+ {
+ FilterRule *rule = file_filter->rules->data;
+ if (rule->type == FILTER_RULE_PATTERN &&
+ strcmp (rule->u.pattern, "*") == 0)
+ return GTK_FILTER_MATCH_ALL;
+ }
+
+ return GTK_FILTER_MATCH_SOME;
+}
+
+static gboolean
+gtk_file_filter_match (GtkFilter *filter,
+ gpointer item)
+{
+ if (!G_IS_FILE_INFO (item))
+ return TRUE;
+
+ return gtk_file_filter_filter (GTK_FILE_FILTER (filter), G_FILE_INFO (item));
+}
+
/**
* gtk_file_filter_filter:
* @filter: a #GtkFileFilter
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]