Description
A GtkFileFilter can be used to restrict the files being shown in a
GtkFileChooser. Files can be filtered based on their name (with
gtk_file_filter_add_pattern()), on their mime type (with
gtk_file_filter_add_mime_type()), or by a custom filter function
(with gtk_file_filter_add_custom()).
Filtering by mime types handles aliasing and subclassing of mime
types; e.g. a filter for text/plain also matches a file with mime
type application/rtf, since application/rtf is a subclass of
text/plain. Note that GtkFileFilter allows wildcards for the
subtype of a mime type, so you can e.g. filter for image/*.
Normally, filters are used by adding them to a GtkFileChooser,
see gtk_file_chooser_add_filter(), but it is also possible
to manually use a filter on a file with gtk_file_filter_filter().
GtkFileFilter as GtkBuildable
The GtkFileFilter implementation of the GtkBuildable interface
supports adding rules using the <mime-types>, <patterns> and
<applications> elements and listing the rules within. Specifying
a <mime-type> or <pattern> has the same effect as as calling
gtk_file_filter_add_mime_type() or gtk_file_filter_add_pattern().
An example of a UI definition fragment specifying GtkFileFilter
rules:
Functions
gtk_file_filter_set_name ()
void
gtk_file_filter_set_name (GtkFileFilter *filter,
const gchar *name);
Sets the human-readable name of the filter; this is the string
that will be displayed in the file selector user interface if
there is a selectable list of filters.
Since: 2.4
gtk_file_filter_get_name ()
const gchar *
gtk_file_filter_get_name (GtkFileFilter *filter);
Gets the human-readable name for the filter. See gtk_file_filter_set_name().
Returns
The human-readable name of the filter,
or NULL. This value is owned by GTK+ and must not
be modified or freed.
[nullable]
Since: 2.4
gtk_file_filter_add_mime_type ()
void
gtk_file_filter_add_mime_type (GtkFileFilter *filter,
const gchar *mime_type);
Adds a rule allowing a given mime type to filter
.
Since: 2.4
gtk_file_filter_add_pattern ()
void
gtk_file_filter_add_pattern (GtkFileFilter *filter,
const gchar *pattern);
Adds a rule allowing a shell style glob to a filter.
Since: 2.4
gtk_file_filter_add_pixbuf_formats ()
void
gtk_file_filter_add_pixbuf_formats (GtkFileFilter *filter);
Adds a rule allowing image files in the formats supported
by GdkPixbuf.
Since: 2.6
gtk_file_filter_add_custom ()
void
gtk_file_filter_add_custom (GtkFileFilter *filter,
GtkFileFilterFlags needed,
GtkFileFilterFunc func,
gpointer data,
GDestroyNotify notify);
Adds rule to a filter that allows files based on a custom callback
function. The bitfield needed
which is passed in provides information
about what sorts of information that the filter function needs;
this allows GTK+ to avoid retrieving expensive information when
it isn’t needed by the filter.
Since: 2.4
gtk_file_filter_to_gvariant ()
GVariant *
gtk_file_filter_to_gvariant (GtkFileFilter *filter);
Serialize a file filter to an a{sv} variant.
Returns
a new, floating, GVariant.
[transfer none]
Since: 3.22
Types and Values
GtkFileFilter
typedef struct _GtkFileFilter GtkFileFilter;
struct GtkFileFilterInfo
struct GtkFileFilterInfo {
GtkFileFilterFlags contains;
const gchar *filename;
const gchar *uri;
const gchar *display_name;
const gchar *mime_type;
};
A GtkFileFilterInfo is used to pass information about the
tested file to gtk_file_filter_filter().
enum GtkFileFilterFlags
These flags indicate what parts of a GtkFileFilterInfo struct
are filled or need to be filled.