Description [src]

final class Gtk.FileFilter : GObject.InitiallyUnowned
  implements Gtk.Buildable {
  /* No available fields */

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:

<object class="GtkFileFilter">
    <mime-type>image/ *</mime-type>


hierarchy this GtkFileFilter implements_0 GtkBuildable this--implements_0 ancestor_0 GInitiallyUnowned ancestor_0--this ancestor_1 GObject ancestor_1--ancestor_0




Creates a new GtkFileFilter with no rules added to it. Such a filter doesn’t accept any files, so is not particularly useful until you add rules with gtk_file_filter_add_mime_type(), gtk_file_filter_add_pattern(), or gtk_file_filter_add_custom(). To create a filter that accepts any file, use:

GtkFileFilter *filter = gtk_file_filter_new ();
gtk_file_filter_add_pattern (filter, "*");

since: 2.4


Deserialize a file filter from an a{sv} variant in the format produced by gtk_file_filter_to_gvariant().

since: 3.22

Instance methods


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


Adds a rule allowing a given mime type to filter.

since: 2.4


Adds a rule allowing a shell style glob to a filter.

since: 2.4


Adds a rule allowing image files in the formats supported by GdkPixbuf.

since: 2.6


Tests whether a file should be displayed according to filter. The GtkFileFilterInfo filter_info should include the fields returned from gtk_file_filter_get_needed().

since: 2.4


Gets the human-readable name for the filter. See gtk_file_filter_set_name().

since: 2.4


Gets the fields that need to be filled in for the GtkFileFilterInfo passed to gtk_file_filter_filter().

since: 2.4


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


Serialize a file filter to an a{sv} variant.

since: 3.22

Methods inherited from GObject (43)

Please see GObject for a full list of methods.

Methods inherited from GtkBuildable (10)

Adds a child to buildable. type is an optional string describing how the child should be added.

since: 2.12


Constructs a child of buildable with the name name.

since: 2.12


This is similar to gtk_buildable_parser_finished() but is called once for each custom tag handled by the buildable.

since: 2.12


This is called at the end of each custom element handled by the buildable.

since: 2.12


This is called for each unknown element under <child>.

since: 2.12


Get the internal child called childname of the buildable object.

since: 2.12


Gets the name of the buildable object.

since: 2.12


Called when the builder finishes the parsing of a [GtkBuilder UI definition][BUILDER-UI]. Note that this will be called once for each time gtk_builder_add_from_file() or gtk_builder_add_from_string() is called on a builder.

since: 2.12


Sets the property name name to value on the buildable object.

since: 2.12


Sets the name of the buildable object.

since: 2.12


Signals inherited from GObject (1)

The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.