gtkmm 3.24.7
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gtk::FileFilter Class Reference

A filter for selecting a file subset. More...

#include <gtkmm/filefilter.h>

Inherits Glib::Object.

Classes

class  Info
 Information available per file when implementing a custom filter rule via add_custom(). More...
 

Public Types

typedef sigc::slot< bool, const Info & > SlotCustom
 A slot provided to add_custom() that implements a custom filter rule. More...
 

Public Member Functions

 FileFilter (FileFilter && src) noexcept
 
FileFilteroperator= (FileFilter && src) noexcept
 
 ~FileFilter () noexcept override
 
GtkFileFilter * gobj ()
 Provides access to the underlying C GObject. More...
 
const GtkFileFilter * gobj () const
 Provides access to the underlying C GObject. More...
 
GtkFileFilter * gobj_copy ()
 Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
 
void set_name (const Glib::ustring & 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. More...
 
Glib::ustring get_name () const
 Gets the human-readable name for the filter. More...
 
void add_mime_type (const Glib::ustring & mime_type)
 Adds a rule allowing a given mime type to filter. More...
 
void add_pattern (const Glib::ustring & pattern)
 Adds a rule allowing a shell style glob to a filter. More...
 
void add_pixbuf_formats ()
 Adds a rule allowing image files in the formats supported by GdkPixbuf. More...
 
void add_custom (FileFilterFlags needed, const SlotCustom & slot)
 Adds a rule to a filter that allows files based on a SlotCustom function. More...
 
FileFilterFlags get_needed () const
 Gets the fields that need to be filled in for the Gtk::FileFilterInfo passed to filter() More...
 

Static Public Member Functions

static GType get_type ()
 Get the GType for this class, for use with the underlying GObject type system. More...
 
static Glib::RefPtr< FileFiltercreate ()
 

Protected Member Functions

 FileFilter ()
 

Related Functions

(Note that these are not member functions.)

Glib::RefPtr< Gtk::FileFilterwrap (GtkFileFilter * object, bool take_copy=false)
 A Glib::wrap() method for this object. More...
 

Detailed Description

A filter for selecting a file subset.

A Gtk::FileFilter can be used to restrict the files being shown in a Gtk::FileChooser. Files can be filtered based on their name (with add_pattern()), on their MIME type (with add_mime_type()), or by a custom filter function (with 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::FileFilter allows wildcards for the subtype of a MIME type, so you can e.g. filter for image/ *.

Filters are used by adding them to a Gtk::FileChooser. See Gtk::FileChooser::add_filter().

Member Typedef Documentation

◆ SlotCustom

typedef sigc::slot<bool, const Info&> Gtk::FileFilter::SlotCustom

A slot provided to add_custom() that implements a custom filter rule.

This will be called with the Info of each file that is available, and it must return a bool indicating whether or not that file should be displayed.

For instance:

bool on_custom(const Gtk::FileFilter::Info& filter_info);
Information available per file when implementing a custom filter rule via add_custom().
Definition: filefilter.h:259

Constructor & Destructor Documentation

◆ FileFilter() [1/2]

Gtk::FileFilter::FileFilter ( FileFilter &&  src)
noexcept

◆ ~FileFilter()

Gtk::FileFilter::~FileFilter ( )
overridenoexcept

◆ FileFilter() [2/2]

Gtk::FileFilter::FileFilter ( )
protected

Member Function Documentation

◆ add_custom()

void Gtk::FileFilter::add_custom ( FileFilterFlags  needed,
const SlotCustom slot 
)

Adds a rule to a filter that allows files based on a SlotCustom function.

The Gtk::FileFilterFlags passed in provide information about what sorts of information the filter function needs; this allows the toolkit to avoid retrieving expensive information when it isn’t needed by the custom filter.

Parameters
neededThe FileFilterFlags identifying info needed by the slot.
slotA SlotCustom to call for each file to perform the filtering.

◆ add_mime_type()

void Gtk::FileFilter::add_mime_type ( const Glib::ustring &  mime_type)

Adds a rule allowing a given mime type to filter.

Since gtkmm 2.4:
Parameters
mime_typeName of a MIME type.

◆ add_pattern()

void Gtk::FileFilter::add_pattern ( const Glib::ustring &  pattern)

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

Since gtkmm 2.4:
Parameters
patternA shell style glob.

◆ add_pixbuf_formats()

void Gtk::FileFilter::add_pixbuf_formats ( )

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

Since gtkmm 2.6:

◆ create()

static Glib::RefPtr< FileFilter > Gtk::FileFilter::create ( )
static

◆ get_name()

Glib::ustring Gtk::FileFilter::get_name ( ) const

Gets the human-readable name for the filter.

See set_name().

Since gtkmm 2.4:
Returns
The human-readable name of the filter, or nullptr. This value is owned by GTK+ and must not be modified or freed.

◆ get_needed()

FileFilterFlags Gtk::FileFilter::get_needed ( ) const

Gets the fields that need to be filled in for the Gtk::FileFilterInfo passed to filter()

This function will not typically be used by applications; it is intended principally for use in the implementation of Gtk::FileChooser.

Since gtkmm 2.4:
Returns
Bitfield of flags indicating needed fields when calling filter().

◆ get_type()

static GType Gtk::FileFilter::get_type ( )
static

Get the GType for this class, for use with the underlying GObject type system.

◆ gobj() [1/2]

GtkFileFilter * Gtk::FileFilter::gobj ( )
inline

Provides access to the underlying C GObject.

◆ gobj() [2/2]

const GtkFileFilter * Gtk::FileFilter::gobj ( ) const
inline

Provides access to the underlying C GObject.

◆ gobj_copy()

GtkFileFilter * Gtk::FileFilter::gobj_copy ( )

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

◆ operator=()

FileFilter & Gtk::FileFilter::operator= ( FileFilter &&  src)
noexcept

◆ set_name()

void Gtk::FileFilter::set_name ( const Glib::ustring &  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.

Since gtkmm 2.4:
Parameters
nameThe human-readable-name for the filter, or nullptr to remove any existing name.

Friends And Related Function Documentation

◆ wrap()

Glib::RefPtr< Gtk::FileFilter > wrap ( GtkFileFilter *  object,
bool  take_copy = false 
)
related

A Glib::wrap() method for this object.

Parameters
objectThe C instance.
take_copyFalse if the result should take ownership of the C instance. True if it should take a new copy or ref.
Returns
A C++ instance that wraps this C instance.