1.67 <GtkFileFilter>

Class: <GtkFileFilter>

It derives from <GtkFilter>.

Filters files by name or mime type.

<GtkFileFilter> can be used to restrict the files being shown in a file chooser. Files can be filtered based on their name (with file-filter:add-pattern or file-filter:add-suffix) or on their mime type (with 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 file chooser (see file-dialog:set-filters), 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 file-filter:add-mime-type or file-filter:add-pattern or 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>

Properties

Property: file-filter:mime-types self

The MIME types that this filter matches.

Its value is a list or vector, each a string, or #f.

It can only be set when the object is made, with #:mime-types. It cannot be read.

Property: file-filter:name self

The human-readable name of the filter.

This is the string that will be displayed in the user interface if there is a selectable list of filters.

Its value is a string, or #f.

Set it with (set! (file-filter:name self) value).

Property: file-filter:patterns self

The patterns that this filter matches.

Its value is a list or vector, each a string, or #f.

It can only be set when the object is made, with #:patterns. It cannot be read.

Property: file-filter:suffixes self

The suffixes that this filter matches.

Its value is a list or vector, each a string, or #f.

It can only be set when the object is made, with #:suffixes. It cannot be read.

Procedures

Method: file-filter:add-mime-type self mime-type
Method: add-mime-type self mime-type

Adds a rule allowing a given mime type.

self

Passed: a <GtkFileFilter>.

A file filter

mime-type

Passed: a string.

name of a MIME type

Method: file-filter:add-mime-types self mime-types
Method: add-mime-types self mime-types

Adds a rule allowing a given array of mime types. It can for example be used with Gly.Loader.get_mime_types.

This is equivalent to calling file-filter:add-mime-type for all the supported mime types.

self

Passed: a <GtkFileFilter>.

a file filter

mime-types

Passed: a list or vector, each a string.

a #f-terminated array of mime types

Method: file-filter:add-pattern self pattern
Method: add-pattern self pattern

Adds a rule allowing a shell style glob pattern.

Note that it depends on the platform whether pattern matching ignores case or not. On Windows, it does, on other platforms, it doesn’t.

self

Passed: a <GtkFileFilter>.

a file filter

pattern

Passed: a string.

a shell style glob pattern

Method: file-filter:add-pixbuf-formats self
Method: add-pixbuf-formats self

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

This is equivalent to calling file-filter:add-mime-type for all the supported mime types.

self

Passed: a <GtkFileFilter>.

a file filter

Method: file-filter:add-suffix self suffix
Method: add-suffix self suffix

Adds a suffix match rule to a filter.

This is similar to adding a match for the pattern "*.suffix"

An exaple to filter files with the suffix ".sub":

gtk_file_filter_add_suffix (filter, "sub");

Filters with multiple dots are allowed.

In contrast to pattern matches, suffix matches are always case-insensitive.

self

Passed: a <GtkFileFilter>.

a file filter

suffix

Passed: a string.

filename suffix to match

Method: file-filter:get-attributes self ⇒ %return
Method: get-attributes self ⇒ %return

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

This function will not typically be used by applications; it is intended for use in file chooser implementation.

self

Passed: a <GtkFileFilter>.

a file filter

%return

Returned: a vector, each a string.

the attributes

Method: file-filter:get-name self ⇒ %return
Method: get-name self ⇒ %return

Gets the human-readable name for the filter.

See file-filter:set-name.

self

Passed: a <GtkFileFilter>.

a file filter

%return

Returned: a string, or #f.

the human-readable name of the filter

Procedure: file-filter:new ⇒ %return

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 file-filter:add-mime-type, file-filter:add-pattern, file-filter:add-suffix or file-filter:add-pixbuf-formats.

To create a filter that accepts any file, use:

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

Returned: a <GtkFileFilter>.

a new <GtkFileFilter>

Procedure: file-filter:new-from-gvariant variant ⇒ %return

Deserialize a file filter from a <GVariant>.

The variant must be in the format produced by file-filter:to-gvariant.

variant

Passed: a <GVariant>.

an a{sv} <GVariant>

%return

Returned: a <GtkFileFilter>.

a new <GtkFileFilter> object

Method: file-filter:set-name self [name]
Method: set-name self [name]

Sets a human-readable name of the filter.

This is the string that will be displayed in the user interface if there is a selectable list of filters.

self

Passed: a <GtkFileFilter>.

a file filter

name

Passed, or left out: a string, or #f.

the human-readable name for the filter

Method: file-filter:to-gvariant self ⇒ %return
Method: to-gvariant self ⇒ %return

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

self

Passed: a <GtkFileFilter>.

a file filter

%return

Returned: a <GVariant>.

a new, floating, <GVariant>