Class FileFilter

All Implemented Interfaces:
PointerInterface

public class FileFilter extends Filter
`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
[method@Gtk.FileFilter.add_pattern] or [method@Gtk.FileFilter.add_suffix])
or on their mime type (with [method@Gtk.FileFilter.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 [method@Gtk.FileChooser.add_filter]), but it is also possible to
manually use a file filter on any [class@Gtk.FilterListModel] 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
[method@Gtk.FileFilter.add_mime_type] or
[method@Gtk.FileFilter.add_pattern] or
[method@Gtk.FileFilter.add_suffix].

An example of a UI definition fragment specifying `GtkFileFilter`
rules:
```xml
<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>
```

https://docs.gtk.org/gtk4/class.FileFilter.html

  • Constructor Details

    • FileFilter

      public FileFilter(PointerContainer pointer)
    • FileFilter

      public FileFilter()
      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
      [method@Gtk.FileFilter.add_mime_type],
      [method@Gtk.FileFilter.add_pattern],
      [method@Gtk.FileFilter.add_suffix] or
      [method@Gtk.FileFilter.add_pixbuf_formats].

      To create a filter that accepts any file, use:
      ```c
      GtkFileFilter *filter = gtk_file_filter_new ();
      gtk_file_filter_add_pattern (filter, "*");
      ```
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newFromGvariantFileFilter

      public static FileFilter newFromGvariantFileFilter(@Nonnull Variant variant)
      Deserialize a file filter from a `GVariant`.

      The variant must be in the format produced by
      [method@Gtk.FileFilter.to_gvariant].
      Parameters:
      variant - an `a{sv}` `GVariant`
      Returns:
      a new `GtkFileFilter` object
    • addMimeType

      public void addMimeType(@Nonnull Str mime_type)
      Adds a rule allowing a given mime type to @filter.
      Parameters:
      mime_type - name of a MIME type
    • addMimeType

      public void addMimeType(String mime_type)
      Adds a rule allowing a given mime type to @filter.
      Parameters:
      mime_type - name of a MIME type
    • addPattern

      public void addPattern(@Nonnull Str pattern)
      Adds a rule allowing a shell style glob to a filter.

      Note that it depends on the platform whether pattern
      matching ignores case or not. On Windows, it does, on
      other platforms, it doesn't.
      Parameters:
      pattern - a shell style glob
    • addPattern

      public void addPattern(String pattern)
      Adds a rule allowing a shell style glob to a filter.

      Note that it depends on the platform whether pattern
      matching ignores case or not. On Windows, it does, on
      other platforms, it doesn't.
      Parameters:
      pattern - a shell style glob
    • addPixbufFormats

      public void addPixbufFormats()
      Adds a rule allowing image files in the formats supported
      by GdkPixbuf.

      This is equivalent to calling [method@Gtk.FileFilter.add_mime_type]
      for all the supported mime types.
    • addSuffix

      public void addSuffix(@Nonnull Str suffix)
      Adds a suffix match rule to a filter.

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

      In contrast to pattern matches, suffix matches
      are *always* case-insensitive.
      Parameters:
      suffix - filename suffix to match
    • addSuffix

      public void addSuffix(String suffix)
      Adds a suffix match rule to a filter.

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

      In contrast to pattern matches, suffix matches
      are *always* case-insensitive.
      Parameters:
      suffix - filename suffix to match
    • getAttributes

      public Strs getAttributes()
      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 principally for use in the implementation
      of `GtkFileChooser`.
      Returns:
      the attributes
    • getName

      public Str getName()
      Gets the human-readable name for the filter.

      See [method@Gtk.FileFilter.set_name].
      Returns:
      The human-readable name of the filter
    • setName

      public void setName(@Nullable Str name)
      Sets a human-readable name of the filter.

      This is the string that will be displayed in the file chooser
      if there is a selectable list of filters.
      Parameters:
      name - the human-readable-name for the filter, or %NULL to remove any existing name.
    • setName

      public void setName(String name)
      Sets a human-readable name of the filter.

      This is the string that will be displayed in the file chooser
      if there is a selectable list of filters.
      Parameters:
      name - the human-readable-name for the filter, or %NULL to remove any existing name.
    • toGvariant

      public Variant toGvariant()
      Serialize a file filter to an `a{sv}` variant.
      Returns:
      a new, floating, `GVariant`
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Returns:
      Buildable
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()