/* Copyright (C) 2003 The gtkmm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, see . */ _CONFIGINCLUDE(gtkmmconfig.h) #include _DEFS(gtkmm,gtk) _PINCLUDE(glibmm/private/object_p.h) namespace Gtk { _WRAP_ENUM(FileFilterFlags, GtkFileFilterFlags, decl_prefix GTKMM_API) /** 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(). */ class GTKMM_API FileFilter : public Glib::Object { _CLASS_GOBJECT(FileFilter, GtkFileFilter, GTK_FILE_FILTER, Glib::Object, GObject, , , GTKMM_API) _DERIVES_INITIALLY_UNOWNED() protected: _CTOR_DEFAULT public: _WRAP_CREATE() _WRAP_METHOD(void set_name(const Glib::ustring& name), gtk_file_filter_set_name) _WRAP_METHOD(Glib::ustring get_name() const, gtk_file_filter_get_name) _WRAP_METHOD(void add_mime_type(const Glib::ustring& mime_type), gtk_file_filter_add_mime_type) _WRAP_METHOD(void add_pattern(const Glib::ustring& pattern), gtk_file_filter_add_pattern) _WRAP_METHOD(void add_pixbuf_formats(), gtk_file_filter_add_pixbuf_formats) /** Information available per file when implementing a custom filter rule via * add_custom(). */ class Info { public: /// Flags indicating which of the following fields are filled. See add_custom(). FileFilterFlags contains; /// The filename of the file being tested. Glib::ustring filename; /// The URI for the file being tested. Glib::ustring uri; /// The string that will be used to display the file in the Gtk::FileChooser. Glib::ustring display_name; /// The MIME type of the file. Glib::ustring mime_type; }; /** 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: * @code * bool on_custom(const Gtk::FileFilter::Info& filter_info); * @endcode */ typedef sigc::slot SlotCustom; /** * 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. * * @param needed The FileFilterFlags identifying info needed by the @a slot. * @param slot A SlotCustom to call for each file to perform the filtering. */ void add_custom(FileFilterFlags needed, const SlotCustom& slot); _IGNORE(gtk_file_filter_add_custom) _WRAP_METHOD(FileFilterFlags get_needed() const, gtk_file_filter_get_needed) // This method is meant for implementors of FileChooser, so we don’t wrap it. // (So is get_needed() really, but we had better not remove that in gtkmm-3.) _IGNORE(gtk_file_filter_filter) }; } // namespace Gtk