forked from AuroraMiddleware/gtk
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.
This commit is contained in:
parent
644d522d19
commit
2d8fddc1e9
@ -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>
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user