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