[gtk/file-filter2: 1/6] filefilter: Drop GtkFileFilterFlags
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/file-filter2: 1/6] filefilter: Drop GtkFileFilterFlags
- Date: Sun, 5 Jul 2020 19:14:58 +0000 (UTC)
commit 2d8fddc1e957655669ab496599c5cd0ec3328cd3
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jul 5 14:24:21 2020 -0400
filefilter: Drop GtkFileFilterFlags
Replace gtk_file_filter_get_needed by gtk_file_filter_get_attributes,
which directly returns the attributes that are needed.
Update all callers.
docs/reference/gtk/gtk4-sections.txt | 3 +--
gtk/gtkfilefilter.c | 45 +++++++++++++++++++++++++-----------
gtk/gtkfilefilter.h | 20 +---------------
testsuite/gtk/builder.c | 4 ++--
4 files changed, 36 insertions(+), 36 deletions(-)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 55d474f5c8..a2abcab1fb 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -1413,14 +1413,13 @@ GtkFileChooserButtonPrivate
<SECTION>
<FILE>gtkfilefilter</FILE>
GtkFileFilter
-GtkFileFilterFlags
gtk_file_filter_new
gtk_file_filter_set_name
gtk_file_filter_get_name
gtk_file_filter_add_mime_type
gtk_file_filter_add_pattern
gtk_file_filter_add_pixbuf_formats
-gtk_file_filter_get_needed
+gtk_file_filter_get_attributes
gtk_file_filter_filter
<SUBSECTION Serialization>
diff --git a/gtk/gtkfilefilter.c b/gtk/gtkfilefilter.c
index 65b10298e6..7d2767c27f 100644
--- a/gtk/gtkfilefilter.c
+++ b/gtk/gtkfilefilter.c
@@ -100,13 +100,12 @@ struct _GtkFileFilter
gchar *name;
GSList *rules;
- GtkFileFilterFlags needed;
+ char **attributes;
};
struct _FilterRule
{
FilterRuleType type;
- GtkFileFilterFlags needed;
union {
gchar *pattern;
@@ -253,6 +252,7 @@ gtk_file_filter_finalize (GObject *object)
GtkFileFilter *filter = GTK_FILE_FILTER (object);
g_slist_free_full (filter->rules, (GDestroyNotify)filter_rule_free);
+ g_strfreev (filter->attributes);
g_free (filter->name);
@@ -497,10 +497,29 @@ static void
file_filter_add_rule (GtkFileFilter *filter,
FilterRule *rule)
{
- filter->needed |= rule->needed;
filter->rules = g_slist_append (filter->rules, rule);
}
+static void
+file_filter_add_attribute (GtkFileFilter *filter,
+ const char *attribute)
+{
+ int i;
+
+ if (filter->attributes)
+ for (i = 0; filter->attributes[i]; i++)
+ {
+ if (strcmp (filter->attributes[i], attribute) == 0)
+ return;
+ }
+ else
+ i = 0;
+
+ filter->attributes = (char **)g_renew (char **, filter->attributes, i + 2);
+ filter->attributes[i] = g_strdup (attribute);
+ filter->attributes[i + 1] = NULL;
+}
+
/**
* gtk_file_filter_add_mime_type:
* @filter: A #GtkFileFilter
@@ -519,9 +538,9 @@ gtk_file_filter_add_mime_type (GtkFileFilter *filter,
rule = g_slice_new (FilterRule);
rule->type = FILTER_RULE_MIME_TYPE;
- rule->needed = GTK_FILE_FILTER_MIME_TYPE;
rule->u.mime_type = g_strdup (mime_type);
+ file_filter_add_attribute (filter, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
file_filter_add_rule (filter, rule);
}
@@ -543,9 +562,9 @@ gtk_file_filter_add_pattern (GtkFileFilter *filter,
rule = g_slice_new (FilterRule);
rule->type = FILTER_RULE_PATTERN;
- rule->needed = GTK_FILE_FILTER_DISPLAY_NAME;
rule->u.pattern = g_strdup (pattern);
+ file_filter_add_attribute (filter, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME);
file_filter_add_rule (filter, rule);
}
@@ -565,29 +584,29 @@ gtk_file_filter_add_pixbuf_formats (GtkFileFilter *filter)
rule = g_slice_new (FilterRule);
rule->type = FILTER_RULE_PIXBUF_FORMATS;
- rule->needed = GTK_FILE_FILTER_MIME_TYPE;
rule->u.pixbuf_formats = gdk_pixbuf_get_formats ();
+
+ file_filter_add_attribute (filter, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
file_filter_add_rule (filter, rule);
}
/**
- * gtk_file_filter_get_needed:
+ * gtk_file_filter_get_attributes:
* @filter: a #GtkFileFilter
*
- * Gets the fields that need to be filled in for the #GtkFileFilterInfo
+ * Gets the attributes that need to be filled in for the #GFileInfo
* passed to gtk_file_filter_filter()
*
* This function will not typically be used by applications; it
* is intended principally for use in the implementation of
* #GtkFileChooser.
*
- * Returns: bitfield of flags indicating needed fields when
- * calling gtk_file_filter_filter()
+ * Returns: (transfer none): the attributes
**/
-GtkFileFilterFlags
-gtk_file_filter_get_needed (GtkFileFilter *filter)
+const char **
+gtk_file_filter_get_attributes (GtkFileFilter *filter)
{
- return filter->needed;
+ return (const char **)filter->attributes;
}
#ifdef GDK_WINDOWING_QUARTZ
diff --git a/gtk/gtkfilefilter.h b/gtk/gtkfilefilter.h
index ae75e9b488..853c838fb4 100644
--- a/gtk/gtkfilefilter.h
+++ b/gtk/gtkfilefilter.h
@@ -34,24 +34,6 @@ G_BEGIN_DECLS
typedef struct _GtkFileFilter GtkFileFilter;
-/**
- * GtkFileFilterFlags:
- * @GTK_FILE_FILTER_FILENAME: the filename of the file being tested
- * @GTK_FILE_FILTER_URI: the URI for the file being tested
- * @GTK_FILE_FILTER_DISPLAY_NAME: the string that will be used to
- * display the file in the file chooser
- * @GTK_FILE_FILTER_MIME_TYPE: the mime type of the file
- *
- * These flags indicate what parts of a #GtkFileFilterInfo struct
- * are filled or need to be filled.
- */
-typedef enum {
- GTK_FILE_FILTER_FILENAME = 1 << 0,
- GTK_FILE_FILTER_URI = 1 << 1,
- GTK_FILE_FILTER_DISPLAY_NAME = 1 << 2,
- GTK_FILE_FILTER_MIME_TYPE = 1 << 3
-} GtkFileFilterFlags;
-
GDK_AVAILABLE_IN_ALL
GType gtk_file_filter_get_type (void) G_GNUC_CONST;
@@ -73,7 +55,7 @@ GDK_AVAILABLE_IN_ALL
void gtk_file_filter_add_pixbuf_formats (GtkFileFilter *filter);
GDK_AVAILABLE_IN_ALL
-GtkFileFilterFlags gtk_file_filter_get_needed (GtkFileFilter *filter);
+const char ** gtk_file_filter_get_attributes (GtkFileFilter *filter);
GDK_AVAILABLE_IN_ALL
gboolean gtk_file_filter_filter (GtkFileFilter *filter,
GFileInfo *info);
diff --git a/testsuite/gtk/builder.c b/testsuite/gtk/builder.c
index 38537a10f3..18b29e2078 100644
--- a/testsuite/gtk/builder.c
+++ b/testsuite/gtk/builder.c
@@ -2408,8 +2408,8 @@ test_file_filter (void)
g_assert (GTK_IS_FILE_FILTER (obj));
filter = GTK_FILE_FILTER (obj);
g_assert_cmpstr (gtk_file_filter_get_name (filter), ==, "Text and Images");
- g_assert (gtk_file_filter_get_needed (filter) & GTK_FILE_FILTER_MIME_TYPE);
- g_assert (gtk_file_filter_get_needed (filter) & GTK_FILE_FILTER_DISPLAY_NAME);
+ g_assert_true (g_strv_contains (gtk_file_filter_get_attributes (filter),
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE));
+ g_assert_true (g_strv_contains (gtk_file_filter_get_attributes (filter),
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME));
g_object_unref (builder);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]