1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.FileFilter;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import glib.Variant;
30 private import gobject.ObjectG;
31 private import gtk.BuildableIF;
32 private import gtk.BuildableT;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * A GtkFileFilter can be used to restrict the files being shown in a
40  * #GtkFileChooser. Files can be filtered based on their name (with
41  * gtk_file_filter_add_pattern()), on their mime type (with
42  * gtk_file_filter_add_mime_type()), or by a custom filter function
43  * (with gtk_file_filter_add_custom()).
44  * 
45  * Filtering by mime types handles aliasing and subclassing of mime
46  * types; e.g. a filter for text/plain also matches a file with mime
47  * type application/rtf, since application/rtf is a subclass of
48  * text/plain. Note that #GtkFileFilter allows wildcards for the
49  * subtype of a mime type, so you can e.g. filter for image/\*.
50  * 
51  * Normally, filters are used by adding them to a #GtkFileChooser,
52  * see gtk_file_chooser_add_filter(), but it is also possible
53  * to manually use a filter on a file with gtk_file_filter_filter().
54  * 
55  * # GtkFileFilter as GtkBuildable
56  * 
57  * The GtkFileFilter implementation of the GtkBuildable interface
58  * supports adding rules using the <mime-types>, <patterns> and
59  * <applications> elements and listing the rules within. Specifying
60  * a <mime-type> or <pattern> has the same effect as as calling
61  * gtk_file_filter_add_mime_type() or gtk_file_filter_add_pattern().
62  * 
63  * An example of a UI definition fragment specifying GtkFileFilter
64  * rules:
65  * |[
66  * <object class="GtkFileFilter">
67  * <mime-types>
68  * <mime-type>text/plain</mime-type>
69  * <mime-type>image/ *</mime-type>
70  * </mime-types>
71  * <patterns>
72  * <pattern>*.txt</pattern>
73  * <pattern>*.png</pattern>
74  * </patterns>
75  * </object>
76  * ]|
77  */
78 public class FileFilter : ObjectG, BuildableIF
79 {
80 	/** the main Gtk struct */
81 	protected GtkFileFilter* gtkFileFilter;
82 
83 	/** Get the main Gtk struct */
84 	public GtkFileFilter* getFileFilterStruct(bool transferOwnership = false)
85 	{
86 		if (transferOwnership)
87 			ownedRef = false;
88 		return gtkFileFilter;
89 	}
90 
91 	/** the main Gtk struct as a void* */
92 	protected override void* getStruct()
93 	{
94 		return cast(void*)gtkFileFilter;
95 	}
96 
97 	/**
98 	 * Sets our main struct and passes it to the parent class.
99 	 */
100 	public this (GtkFileFilter* gtkFileFilter, bool ownedRef = false)
101 	{
102 		this.gtkFileFilter = gtkFileFilter;
103 		super(cast(GObject*)gtkFileFilter, ownedRef);
104 	}
105 
106 	// add the Buildable capabilities
107 	mixin BuildableT!(GtkFileFilter);
108 
109 
110 	/** */
111 	public static GType getType()
112 	{
113 		return gtk_file_filter_get_type();
114 	}
115 
116 	/**
117 	 * Creates a new #GtkFileFilter with no rules added to it.
118 	 * Such a filter doesn’t accept any files, so is not
119 	 * particularly useful until you add rules with
120 	 * gtk_file_filter_add_mime_type(), gtk_file_filter_add_pattern(),
121 	 * or gtk_file_filter_add_custom(). To create a filter
122 	 * that accepts any file, use:
123 	 * |[<!-- language="C" -->
124 	 * GtkFileFilter *filter = gtk_file_filter_new ();
125 	 * gtk_file_filter_add_pattern (filter, "*");
126 	 * ]|
127 	 *
128 	 * Returns: a new #GtkFileFilter
129 	 *
130 	 * Since: 2.4
131 	 *
132 	 * Throws: ConstructionException GTK+ fails to create the object.
133 	 */
134 	public this()
135 	{
136 		auto p = gtk_file_filter_new();
137 
138 		if(p is null)
139 		{
140 			throw new ConstructionException("null returned by new");
141 		}
142 
143 		this(cast(GtkFileFilter*) p);
144 	}
145 
146 	/**
147 	 * Deserialize a file filter from an a{sv} variant in
148 	 * the format produced by gtk_file_filter_to_gvariant().
149 	 *
150 	 * Params:
151 	 *     variant = an a{sv} #GVariant
152 	 *
153 	 * Returns: a new #GtkFileFilter object
154 	 *
155 	 * Since: 3.22
156 	 *
157 	 * Throws: ConstructionException GTK+ fails to create the object.
158 	 */
159 	public this(Variant variant)
160 	{
161 		auto p = gtk_file_filter_new_from_gvariant((variant is null) ? null : variant.getVariantStruct());
162 
163 		if(p is null)
164 		{
165 			throw new ConstructionException("null returned by new_from_gvariant");
166 		}
167 
168 		this(cast(GtkFileFilter*) p, true);
169 	}
170 
171 	/**
172 	 * Adds rule to a filter that allows files based on a custom callback
173 	 * function. The bitfield @needed which is passed in provides information
174 	 * about what sorts of information that the filter function needs;
175 	 * this allows GTK+ to avoid retrieving expensive information when
176 	 * it isn’t needed by the filter.
177 	 *
178 	 * Params:
179 	 *     needed = bitfield of flags indicating the information that the custom
180 	 *         filter function needs.
181 	 *     func = callback function; if the function returns %TRUE, then
182 	 *         the file will be displayed.
183 	 *     data = data to pass to @func
184 	 *     notify = function to call to free @data when it is no longer needed.
185 	 *
186 	 * Since: 2.4
187 	 */
188 	public void addCustom(GtkFileFilterFlags needed, GtkFileFilterFunc func, void* data, GDestroyNotify notify)
189 	{
190 		gtk_file_filter_add_custom(gtkFileFilter, needed, func, data, notify);
191 	}
192 
193 	/**
194 	 * Adds a rule allowing a given mime type to @filter.
195 	 *
196 	 * Params:
197 	 *     mimeType = name of a MIME type
198 	 *
199 	 * Since: 2.4
200 	 */
201 	public void addMimeType(string mimeType)
202 	{
203 		gtk_file_filter_add_mime_type(gtkFileFilter, Str.toStringz(mimeType));
204 	}
205 
206 	/**
207 	 * Adds a rule allowing a shell style glob to a filter.
208 	 *
209 	 * Params:
210 	 *     pattern = a shell style glob
211 	 *
212 	 * Since: 2.4
213 	 */
214 	public void addPattern(string pattern)
215 	{
216 		gtk_file_filter_add_pattern(gtkFileFilter, Str.toStringz(pattern));
217 	}
218 
219 	/**
220 	 * Adds a rule allowing image files in the formats supported
221 	 * by GdkPixbuf.
222 	 *
223 	 * Since: 2.6
224 	 */
225 	public void addPixbufFormats()
226 	{
227 		gtk_file_filter_add_pixbuf_formats(gtkFileFilter);
228 	}
229 
230 	/**
231 	 * Tests whether a file should be displayed according to @filter.
232 	 * The #GtkFileFilterInfo @filter_info should include
233 	 * the fields returned from gtk_file_filter_get_needed().
234 	 *
235 	 * This function will not typically be used by applications; it
236 	 * is intended principally for use in the implementation of
237 	 * #GtkFileChooser.
238 	 *
239 	 * Params:
240 	 *     filterInfo = a #GtkFileFilterInfo containing information
241 	 *         about a file.
242 	 *
243 	 * Returns: %TRUE if the file should be displayed
244 	 *
245 	 * Since: 2.4
246 	 */
247 	public bool filter(GtkFileFilterInfo* filterInfo)
248 	{
249 		return gtk_file_filter_filter(gtkFileFilter, filterInfo) != 0;
250 	}
251 
252 	/**
253 	 * Gets the human-readable name for the filter. See gtk_file_filter_set_name().
254 	 *
255 	 * Returns: The human-readable name of the filter,
256 	 *     or %NULL. This value is owned by GTK+ and must not
257 	 *     be modified or freed.
258 	 *
259 	 * Since: 2.4
260 	 */
261 	public string getName()
262 	{
263 		return Str.toString(gtk_file_filter_get_name(gtkFileFilter));
264 	}
265 
266 	/**
267 	 * Gets the fields that need to be filled in for the #GtkFileFilterInfo
268 	 * passed to gtk_file_filter_filter()
269 	 *
270 	 * This function will not typically be used by applications; it
271 	 * is intended principally for use in the implementation of
272 	 * #GtkFileChooser.
273 	 *
274 	 * Returns: bitfield of flags indicating needed fields when
275 	 *     calling gtk_file_filter_filter()
276 	 *
277 	 * Since: 2.4
278 	 */
279 	public GtkFileFilterFlags getNeeded()
280 	{
281 		return gtk_file_filter_get_needed(gtkFileFilter);
282 	}
283 
284 	/**
285 	 * Sets the human-readable name of the filter; this is the string
286 	 * that will be displayed in the file selector user interface if
287 	 * there is a selectable list of filters.
288 	 *
289 	 * Params:
290 	 *     name = the human-readable-name for the filter, or %NULL
291 	 *         to remove any existing name.
292 	 *
293 	 * Since: 2.4
294 	 */
295 	public void setName(string name)
296 	{
297 		gtk_file_filter_set_name(gtkFileFilter, Str.toStringz(name));
298 	}
299 
300 	/**
301 	 * Serialize a file filter to an a{sv} variant.
302 	 *
303 	 * Returns: a new, floating, #GVariant
304 	 *
305 	 * Since: 3.22
306 	 */
307 	public Variant toGvariant()
308 	{
309 		auto p = gtk_file_filter_to_gvariant(gtkFileFilter);
310 
311 		if(p is null)
312 		{
313 			return null;
314 		}
315 
316 		return new Variant(cast(GVariant*) p);
317 	}
318 }