gi-gtk4-4.0.12: Gtk 4.x bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | None
Language | Haskell2010

GI.Gtk.Objects.FileFilter

Contents

- Exported types
- Methods
  - addMimeType
  - addMimeTypes
  - addPattern
  - addPixbufFormats
  - addSuffix
  - getAttributes
  - getName
  - new
  - newFromGvariant
  - setName
  - toGvariant
- Properties
  - mimeTypes
  - name
  - patterns
  - suffixes

Description

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 `fileFilterAddPattern` or `fileFilterAddSuffix`) or on their mime type (with `fileFilterAddMimeType`).

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 `fileDialogSetFilters`), but it is also possible to manually use a file filter on any `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 `fileFilterAddMimeType` or `fileFilterAddPattern` or `fileFilterAddSuffix`.

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

### xml code

    <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>

Synopsis

- newtype FileFilter = FileFilter (ManagedPtr FileFilter)
- class (GObject o, IsDescendantOf FileFilter o) => IsFileFilter o
- toFileFilter :: (MonadIO m, IsFileFilter o) => o -> m FileFilter
- fileFilterAddMimeType :: (HasCallStack, MonadIO m, IsFileFilter a) => a -> Text -> m ()
- fileFilterAddMimeTypes :: (HasCallStack, MonadIO m, IsFileFilter a) => a -> [Text] -> m ()
- fileFilterAddPattern :: (HasCallStack, MonadIO m, IsFileFilter a) => a -> Text -> m ()
- fileFilterAddPixbufFormats :: (HasCallStack, MonadIO m, IsFileFilter a) => a -> m ()
- fileFilterAddSuffix :: (HasCallStack, MonadIO m, IsFileFilter a) => a -> Text -> m ()
- fileFilterGetAttributes :: (HasCallStack, MonadIO m, IsFileFilter a) => a -> m [Text]
- fileFilterGetName :: (HasCallStack, MonadIO m, IsFileFilter a) => a -> m (Maybe Text)
- fileFilterNew :: (HasCallStack, MonadIO m) => m FileFilter
- fileFilterNewFromGvariant :: (HasCallStack, MonadIO m) => GVariant -> m FileFilter
- fileFilterSetName :: (HasCallStack, MonadIO m, IsFileFilter a) => a -> Maybe Text -> m ()
- fileFilterToGvariant :: (HasCallStack, MonadIO m, IsFileFilter a) => a -> m GVariant
- constructFileFilterMimeTypes :: (IsFileFilter o, MonadIO m) => [Text] -> m (GValueConstruct o)
- clearFileFilterName :: (MonadIO m, IsFileFilter o) => o -> m ()
- constructFileFilterName :: (IsFileFilter o, MonadIO m) => Text -> m (GValueConstruct o)
- getFileFilterName :: (MonadIO m, IsFileFilter o) => o -> m (Maybe Text)
- setFileFilterName :: (MonadIO m, IsFileFilter o) => o -> Text -> m ()
- constructFileFilterPatterns :: (IsFileFilter o, MonadIO m) => [Text] -> m (GValueConstruct o)
- constructFileFilterSuffixes :: (IsFileFilter o, MonadIO m) => [Text] -> m (GValueConstruct o)

# Exported types

newtype FileFilter Source #

Memory-managed wrapper type.

Constructors

FileFilter (ManagedPtr FileFilter) |

#### Instances

Instances details

Eq FileFilter Source # |
Instance details Defined in GI.Gtk.Objects.FileFilter Methods (==) :: FileFilter -> FileFilter -> Bool Source # (/=) :: FileFilter -> FileFilter -> Bool Source #
GObject FileFilter Source # |
Instance details Defined in GI.Gtk.Objects.FileFilter
ManagedPtrNewtype FileFilter Source # |
Instance details Defined in GI.Gtk.Objects.FileFilter Methods toManagedPtr :: FileFilter -> ManagedPtr FileFilter Source #
TypedObject FileFilter Source # |
Instance details Defined in GI.Gtk.Objects.FileFilter Methods glibType :: IO GType Source #
HasParentTypes FileFilter Source # |
Instance details Defined in GI.Gtk.Objects.FileFilter
IsGValue (Maybe FileFilter) Source # | Convert `FileFilter` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.Gtk.Objects.FileFilter Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe FileFilter -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe FileFilter) Source #
type ParentTypes FileFilter Source # |
Instance details Defined in GI.Gtk.Objects.FileFilter type ParentTypes FileFilter = '[Filter, Object, Buildable]

class (GObject o, IsDescendantOf FileFilter o) => IsFileFilter o Source #

Type class for types which can be safely cast to `FileFilter`, for instance with `toFileFilter`.

#### Instances

Instances details

(GObject o, IsDescendantOf FileFilter o) => IsFileFilter o Source # |
Instance details Defined in GI.Gtk.Objects.FileFilter

toFileFilter :: (MonadIO m, IsFileFilter o) => o -> m FileFilter Source #

Cast to `FileFilter`, for types for which this is known to be safe. For general casts, use `castTo`.

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

addMimeType, addMimeTypes, addPattern, addPixbufFormats, addSuffix, bindProperty, bindPropertyFull, changed, forceFloating, freezeNotify, getv, isFloating, match, notify, notifyByPspec, ref, refSink, runDispose, stealData, stealQdata, thawNotify, toGvariant, unref, watchClosure.

#### Getters

getAttributes, getBuildableId, getData, getName, getProperty, getQdata, getStrictness.

#### Setters

setData, setDataFull, setName, setProperty.

## addMimeType

fileFilterAddMimeType Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileFilter a) |
=> a | `filter`: A file filter
-> Text | `mimeType`: name of a MIME type
-> m () |

Adds a rule allowing a given mime type.

## addMimeTypes

fileFilterAddMimeTypes Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileFilter a) |
=> a | `filter`: a file filter
-> [Text] | `mimeTypes`: a `Nothing`-terminated array of mime types
-> m () |

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 `fileFilterAddMimeType` for all the supported mime types.

Since: 4.22

## addPattern

fileFilterAddPattern Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileFilter a) |
=> a | `filter`: a file filter
-> Text | `pattern`: a shell style glob pattern
-> m () |

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.

## addPixbufFormats

fileFilterAddPixbufFormats Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileFilter a) |
=> a | `filter`: a file filter
-> m () |

Deprecated: (Since version 4.20)Use the api of your image loading framework (e.g. glycin)to enumerate supported formats

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

This is equivalent to calling `fileFilterAddMimeType` for all the supported mime types.

## addSuffix

fileFilterAddSuffix Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileFilter a) |
=> a | `filter`: a file filter
-> Text | `suffix`: filename suffix to match
-> m () |

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":

### c code

    gtk_file_filter_add_suffix (filter, "sub");

Filters with multiple dots are allowed.

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

Since: 4.4

## getAttributes

fileFilterGetAttributes Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileFilter a) |
=> a | `filter`: a file filter
-> m [Text] | Returns: the attributes

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.

## getName

fileFilterGetName Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileFilter a) |
=> a | `filter`: a file filter
-> m (Maybe Text) | Returns: the human-readable name of the filter

Gets the human-readable name for the filter.

See `fileFilterSetName`.

## new

fileFilterNew Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m FileFilter | Returns: a new `GtkFileFilter`

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 `fileFilterAddMimeType`, `fileFilterAddPattern`, `fileFilterAddSuffix` or `fileFilterAddPixbufFormats`.

To create a filter that accepts any file, use:

### c code

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

## newFromGvariant

fileFilterNewFromGvariant Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> GVariant | `variant`: an `a{sv}` `GVariant`
-> m FileFilter | Returns: a new `GtkFileFilter` object

Deserialize a file filter from a `GVariant`.

The variant must be in the format produced by `fileFilterToGvariant`.

## setName

fileFilterSetName Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileFilter a) |
=> a | `filter`: a file filter
-> Maybe Text | `name`: the human-readable name for the filter
-> m () |

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.

## toGvariant

fileFilterToGvariant Source #

Arguments

:: (HasCallStack, MonadIO m, IsFileFilter a) |
=> a | `filter`: a file filter
-> m GVariant | Returns: a new, floating, `GVariant`

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

# Properties

## mimeTypes

The MIME types that this filter matches.

Since: 4.10

constructFileFilterMimeTypes :: (IsFileFilter o, MonadIO m) => [Text] -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`mime-types`” property. This is rarely needed directly, but it is used by `new`.

## name

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.

clearFileFilterName :: (MonadIO m, IsFileFilter o) => o -> m () Source #

Set the value of the “`name`” property to `Nothing`. When overloading is enabled, this is equivalent to

    clear #name

constructFileFilterName :: (IsFileFilter o, MonadIO m) => Text -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`name`” property. This is rarely needed directly, but it is used by `new`.

getFileFilterName :: (MonadIO m, IsFileFilter o) => o -> m (Maybe Text) Source #

Get the value of the “`name`” property. When overloading is enabled, this is equivalent to

    get fileFilter #name

setFileFilterName :: (MonadIO m, IsFileFilter o) => o -> Text -> m () Source #

Set the value of the “`name`” property. When overloading is enabled, this is equivalent to

    set fileFilter [ #name := value ]

## patterns

The patterns that this filter matches.

Since: 4.10

constructFileFilterPatterns :: (IsFileFilter o, MonadIO m) => [Text] -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`patterns`” property. This is rarely needed directly, but it is used by `new`.

## suffixes

The suffixes that this filter matches.

Since: 4.10

constructFileFilterSuffixes :: (IsFileFilter o, MonadIO m) => [Text] -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`suffixes`” property. This is rarely needed directly, but it is used by `new`.