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