Next: , Previous: GtkFileChooserWidget, Up: Top


85 GtkFileFilter

A filter for selecting a file subset

85.1 Overview

A GtkFileFilter can be used to restrict the files being shown in a <gtk-file-chooser>. 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 <gtk-file-filter> 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 <gtk-file-chooser>, see gtk-file-chooser-add-filter, but it is also possible to manually use a filter on a file with gtk-file-filter-filter.

85.2 Usage

— Class: <gtk-file-filter>

Derives from <gtk-object>.

This class defines no direct slots.

— Function: gtk-file-filter-new ⇒  (ret <gtk-file-filter>)

Creates a new <gtk-file-filter> 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, "*");
ret
a new <gtk-file-filter>

Since 2.4

— Function: gtk-file-filter-set-name (self <gtk-file-filter>) (name mchars)
— Method: set-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.

filter
a <gtk-file-filter>
name
the human-readable-name for the filter, or ‘#f’ to remove any existing name.

Since 2.4

— Function: gtk-file-filter-get-name (self <gtk-file-filter>) ⇒  (ret mchars)
— Method: get-name

Gets the human-readable name for the filter. See gtk-file-filter-set-name.

filter
a <gtk-file-filter>
ret
The human-readable name of the filter, or ‘#f’. This value is owned by GTK+ and must not be modified or freed.

Since 2.4

— Function: gtk-file-filter-add-mime-type (self <gtk-file-filter>) (mime_type mchars)
— Method: add-mime-type

Adds a rule allowing a given mime type to filter.

filter
A <gtk-file-filter>
mime-type
name of a MIME type

Since 2.4

— Function: gtk-file-filter-add-pattern (self <gtk-file-filter>) (pattern mchars)
— Method: add-pattern

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

filter
a <gtk-file-filter>
pattern
a shell style glob

Since 2.4

— Function: gtk-file-filter-add-pixbuf-formats (self <gtk-file-filter>)
— Method: add-pixbuf-formats

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

filter
a <gtk-file-filter>

Since 2.6

— Function: gtk-file-filter-get-needed (self <gtk-file-filter>) ⇒  (ret <gtk-file-filter-flags>)
— Method: get-needed

Gets the fields that need to be filled in for the structure passed to gtk-file-filter-filter

This function will not typically be used by applications; it is intended principally for use in the implementation of <gtk-file-chooser>.

filter
a <gtk-file-filter>
ret
bitfield of flags indicating needed fields when calling gtk-file-filter-filter

Since 2.4