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