Skip to content

Introduce KFileFilter class to parse and store filters

Nicolas Fella requested to merge work/filefilter into master

In KFileWidget and related classes (KFileFilterCombo, KDirModel, KDirLister) we filter the relevant files using name patterns and/or mimetypes.

The status quo is problematic for several reasons:

Filters are passed as strings with special syntax, which doesn't make for good and intuitive API.

One cannot have a filter list with both name patterns and mime types in KFileWidget

One cannot have both mimetypes and name patterns in one filter entry

One cannot have multiple mimetypes in one filter entry

This makes is hard to implement proper support for the filters used by xdg-desktop-portal (which allows all of those things) in our portal implementation.

This patch introduces KFileFilter, a class that stores a filter expression. One KFileFilter corresponds to one item in KFileFilterCombo.

It stores a list of name patterns, a list of mime patterns and a user-facing label.

It offers functions to convert to and from KFileWidget's filter syntax.

KFileFilterCombo is ported to use the new class internally. Other users will be ported in the future.

See https://flatpak.github.io/xdg-desktop-portal/#gdbus-org.freedesktop.portal.FileChooser for how xdg-desktop-portal models filters

Edited by Nicolas Fella

Merge request reports