FileFilter

gtk.file_filter.FileFilter filters files by name or mime type.

gtk.file_filter.FileFilter can be used to restrict the files being shown in a gtk.file_chooser.FileChooser. Files can be filtered based on their name (with gtk.file_filter.FileFilter.addPattern or gtk.file_filter.FileFilter.addSuffix) or on their mime type (with gtk.file_filter.FileFilter.addMimeType).

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 gtk.file_filter.FileFilter 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 gtk.file_chooser.FileChooser (see gtk.file_chooser.FileChooser.addFilter), but it is also possible to manually use a file filter on any gtk.filter_list_model.FilterListModel containing gio.file_info.FileInfo objects.

GtkFileFilter as GtkBuildable

The gtk.file_filter.FileFilter implementation of the gtk.buildable.Buildable 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.FileFilter.addMimeType or gtk.file_filter.FileFilter.addPattern or gtk.file_filter.FileFilter.addSuffix.

An example of a UI definition fragment specifying gtk.file_filter.FileFilter 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>

Constructors

this
this()

Creates a new gtk.file_filter.FileFilter with no rules added to it.

Members

Functions

addMimeType
void addMimeType(string mimeType)

Adds a rule allowing a given mime type to filter.

addPattern
void addPattern(string pattern)

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

addPixbufFormats
void addPixbufFormats()

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

addSuffix
void addSuffix(string suffix)

Adds a suffix match rule to a filter.

getAttributes
string[] getAttributes()

Gets the attributes that need to be filled in for the gio.file_info.FileInfo passed to this filter.

getName
string getName()

Gets the human-readable name for the filter.

setName
void setName(string name)

Sets a human-readable name of the filter.

toGvariant
glib.variant.VariantG toGvariant()

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

Static functions

newFromGvariant
gtk.file_filter.FileFilter newFromGvariant(glib.variant.VariantG variant)

Deserialize a file filter from a glib.variant.VariantG.

Mixed In Members

From mixin BuildableT!()

getBuildableId
string getBuildableId()

Gets the ID of the buildable object.

Inherited Members

From Filter

changed
void changed(gtk.types.FilterChange change)

Notifies all users of the filter that it has changed.

getStrictness
gtk.types.FilterMatch getStrictness()

Gets the known strictness of filters.

match
bool match(gobject.object.ObjectG item)

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

connectChanged
ulong connectChanged(T callback, Flag!"After" after)

Connect to Changed signal.

From Buildable

getBuildableId
string getBuildableId()

Gets the ID of the buildable object.