### Class

# Gtk FileFilter

since: 4.0

#### Description [src]

    final class Gtk.FileFilter : Gtk.Filter
      implements Gtk.Buildable {
      /* No available fields */
    }

`GtkFileFilter` filters files by name or mime type.

`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()` or `gtk_file_filter_add_suffix()`) or on their mime type (with `gtk_file_filter_add_mime_type()`).

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, file filters are used by adding them to a `GtkFileChooser` (see `gtk_file_chooser_add_filter()`), but it is also possible to manually use a file filter on any `GtkFilterListModel` containing `GFileInfo` objects.

# GtkFileFilter as GtkBuildable

The `GtkFileFilter` implementation of the `GtkBuildable` interface supports adding rules using the `<mime-types>` and `<patterns>` and `<suffixes>` elements and listing the rules within. Specifying a `<mime-type>` or `<pattern>` or `<suffix>` has the same effect as as calling `gtk_file_filter_add_mime_type()` or `gtk_file_filter_add_pattern()` or `gtk_file_filter_add_suffix()`.

An example of a UI definition fragment specifying `GtkFileFilter` rules:

    <object class="GtkFileFilter">
      <property name="name" translatable="yes">Text and Images</property>
      <mime-types>
        <mime-type>text/plain</mime-type>
        <mime-type>image/ *</mime-type>
      </mime-types>
      <patterns>
        <pattern>*.txt</pattern>
      </patterns>
      <suffixes>
        <suffix>png</suffix>
      </suffixes>
    </object>

Available since: 4.0

#### Ancestors

- GtkFilter
- GObject

#### Implements

- GtkBuildable

#### Constructors

###### gtk_file_filter_new

Creates a new `GtkFileFilter` with no rules added to it.

since: 4.0

###### gtk_file_filter_new_from_gvariant

Deserialize a file filter from a `GVariant`.

since: 4.0

#### Instance methods

###### gtk_file_filter_add_mime_type

Adds a rule allowing a given mime type to `filter`.

since: 4.0

###### gtk_file_filter_add_pattern

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

since: 4.0

###### gtk_file_filter_add_pixbuf_formats

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

since: 4.0

###### gtk_file_filter_add_suffix

Adds a suffix match rule to a filter.

since: 4.4

###### gtk_file_filter_get_attributes

Gets the attributes that need to be filled in for the `GFileInfo` passed to this filter.

since: 4.0

###### gtk_file_filter_get_name

Gets the human-readable name for the filter.

since: 4.0

###### gtk_file_filter_set_name

Sets a human-readable name of the filter.

since: 4.0

###### gtk_file_filter_to_gvariant

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

since: 4.0

##### Methods inherited from GtkFilter (3)

###### gtk_filter_changed

Notifies all users of the filter that it has changed.

since: 4.0

###### gtk_filter_get_strictness

Gets the known strictness of `filters`.

since: 4.0

###### gtk_filter_match

Checks if the given `item` is matched by the filter or not.

since: 4.0

##### Methods inherited from GObject (43)

Please see GObject for a full list of methods.

##### Methods inherited from GtkBuildable (1)

###### gtk_buildable_get_buildable_id

Gets the ID of the `buildable` object.

since: 4.0

#### Properties

###### Gtk.FileFilter:mime-types

The MIME types that this filter matches.

since: 4.10

###### Gtk.FileFilter:name

The human-readable name of the filter.

since: 4.0

###### Gtk.FileFilter:patterns

The patterns that this filter matches.

since: 4.10

###### Gtk.FileFilter:suffixes

The suffixes that this filter matches.

since: 4.10

#### Signals

##### Signals inherited from GtkFilter (1)

###### GtkFilter::changed

Emitted whenever the filter changed.

since: 4.0

##### Signals inherited from GObject (1)

###### GObject::notify

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.

since: 2.0