| 1 |
/* Copyright (C) 2003 The gtkmm Development Team |
| 2 |
* |
| 3 |
* This library is free software; you can redistribute it and/or |
| 4 |
* modify it under the terms of the GNU Lesser General Public |
| 5 |
* License as published by the Free Software Foundation; either |
| 6 |
* version 2.1 of the License, or (at your option) any later version. |
| 7 |
* |
| 8 |
* This library is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
* Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public |
| 14 |
* License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
_CONFIGINCLUDE(gtkmmconfig.h) |
| 18 |
|
| 19 |
#include <glibmm/object.h> |
| 20 |
|
| 21 |
_DEFS(gtkmm,gtk) |
| 22 |
_PINCLUDE(glibmm/private/object_p.h) |
| 23 |
|
| 24 |
namespace Gtk |
| 25 |
{ |
| 26 |
|
| 27 |
_WRAP_ENUM(FileFilterFlags, GtkFileFilterFlags, decl_prefix GTKMM_API) |
| 28 |
|
| 29 |
/** A filter for selecting a file subset. |
| 30 |
* |
| 31 |
* A Gtk::FileFilter can be used to restrict the files being shown in a Gtk::FileChooser. |
| 32 |
* Files can be filtered based on their name (with add_pattern()), |
| 33 |
* on their MIME type (with add_mime_type()), or by a custom filter |
| 34 |
* function (with add_custom()). |
| 35 |
* |
| 36 |
* Filtering by MIME types handles aliasing and subclassing of MIME types; |
| 37 |
* e.g. a filter for <tt>text/plain</tt> also matches a file with MIME type |
| 38 |
* <tt>application/rtf</tt>, since <tt>application/rtf</tt> is a subclass of |
| 39 |
* <tt>text/plain</tt>. Note that Gtk::FileFilter allows wildcards for the |
| 40 |
* subtype of a MIME type, so you can e.g. filter for <tt>image/ *</tt>. |
| 41 |
* |
| 42 |
* Filters are used by adding them to a Gtk::FileChooser. See Gtk::FileChooser::add_filter(). |
| 43 |
*/ |
| 44 |
class GTKMM_API FileFilter : public Glib::Object |
| 45 |
{ |
| 46 |
_CLASS_GOBJECT(FileFilter, GtkFileFilter, GTK_FILE_FILTER, Glib::Object, GObject, , , GTKMM_API) |
| 47 |
_DERIVES_INITIALLY_UNOWNED() |
| 48 |
protected: |
| 49 |
_CTOR_DEFAULT |
| 50 |
|
| 51 |
public: |
| 52 |
_WRAP_CREATE() |
| 53 |
|
| 54 |
_WRAP_METHOD(void set_name(const Glib::ustring& name), gtk_file_filter_set_name) |
| 55 |
_WRAP_METHOD(Glib::ustring get_name() const, gtk_file_filter_get_name) |
| 56 |
|
| 57 |
_WRAP_METHOD(void add_mime_type(const Glib::ustring& mime_type), gtk_file_filter_add_mime_type) |
| 58 |
_WRAP_METHOD(void add_pattern(const Glib::ustring& pattern), gtk_file_filter_add_pattern) |
| 59 |
_WRAP_METHOD(void add_pixbuf_formats(), gtk_file_filter_add_pixbuf_formats) |
| 60 |
|
| 61 |
/** Information available per file when implementing a custom filter rule via |
| 62 |
* add_custom(). |
| 63 |
*/ |
| 64 |
class Info |
| 65 |
{ |
| 66 |
public: |
| 67 |
/// Flags indicating which of the following fields are filled. See add_custom(). |
| 68 |
FileFilterFlags contains; |
| 69 |
|
| 70 |
/// The filename of the file being tested. |
| 71 |
Glib::ustring filename; |
| 72 |
|
| 73 |
/// The URI for the file being tested. |
| 74 |
Glib::ustring uri; |
| 75 |
|
| 76 |
/// The string that will be used to display the file in the Gtk::FileChooser. |
| 77 |
Glib::ustring display_name; |
| 78 |
|
| 79 |
/// The MIME type of the file. |
| 80 |
Glib::ustring mime_type; |
| 81 |
}; |
| 82 |
|
| 83 |
/** A slot provided to add_custom() that implements a custom filter rule. This |
| 84 |
* will be called with the Info of each file that is available, and it must |
| 85 |
* return a bool indicating whether or not that file should be displayed. |
| 86 |
* |
| 87 |
* For instance: |
| 88 |
* @code |
| 89 |
* bool on_custom(const Gtk::FileFilter::Info& filter_info); |
| 90 |
* @endcode |
| 91 |
*/ |
| 92 |
typedef sigc::slot<bool, const Info&> SlotCustom; |
| 93 |
|
| 94 |
/** |
| 95 |
* Adds a rule to a filter that allows files based on a SlotCustom function. |
| 96 |
* The Gtk::FileFilterFlags passed in provide information about what sorts of |
| 97 |
* information the filter function needs; this allows the toolkit to avoid |
| 98 |
* retrieving expensive information when it isn’t needed by the custom filter. |
| 99 |
* |
| 100 |
* @param needed The FileFilterFlags identifying info needed by the @a slot. |
| 101 |
* @param slot A SlotCustom to call for each file to perform the filtering. |
| 102 |
*/ |
| 103 |
void add_custom(FileFilterFlags needed, const SlotCustom& slot); |
| 104 |
_IGNORE(gtk_file_filter_add_custom) |
| 105 |
|
| 106 |
_WRAP_METHOD(FileFilterFlags get_needed() const, gtk_file_filter_get_needed) |
| 107 |
|
| 108 |
// This method is meant for implementors of FileChooser, so we don’t wrap it. |
| 109 |
// (So is get_needed() really, but we had better not remove that in gtkmm-3.) |
| 110 |
_IGNORE(gtk_file_filter_filter) |
| 111 |
}; |
| 112 |
|
| 113 |
} // namespace Gtk |