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