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 
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 	 * Adds rule to a filter that allows files based on a custom callback
151 	 * function. The bitfield @needed which is passed in provides information
152 	 * about what sorts of information that the filter function needs;
153 	 * this allows GTK+ to avoid retrieving expensive information when
154 	 * it isn’t needed by the filter.
155 	 *
156 	 * Params:
157 	 *     needed = bitfield of flags indicating the information that the custom
158 	 *         filter function needs.
159 	 *     func = callback function; if the function returns %TRUE, then
160 	 *         the file will be displayed.
161 	 *     data = data to pass to @func
162 	 *     notify = function to call to free @data when it is no longer needed.
163 	 *
164 	 * Since: 2.4
165 	 */
166 	public void addCustom(GtkFileFilterFlags needed, GtkFileFilterFunc func, void* data, GDestroyNotify notify)
167 	{
168 		gtk_file_filter_add_custom(gtkFileFilter, needed, func, data, notify);
169 	}
170 
171 	/**
172 	 * Adds a rule allowing a given mime type to @filter.
173 	 *
174 	 * Params:
175 	 *     mimeType = name of a MIME type
176 	 *
177 	 * Since: 2.4
178 	 */
179 	public void addMimeType(string mimeType)
180 	{
181 		gtk_file_filter_add_mime_type(gtkFileFilter, Str.toStringz(mimeType));
182 	}
183 
184 	/**
185 	 * Adds a rule allowing a shell style glob to a filter.
186 	 *
187 	 * Params:
188 	 *     pattern = a shell style glob
189 	 *
190 	 * Since: 2.4
191 	 */
192 	public void addPattern(string pattern)
193 	{
194 		gtk_file_filter_add_pattern(gtkFileFilter, Str.toStringz(pattern));
195 	}
196 
197 	/**
198 	 * Adds a rule allowing image files in the formats supported
199 	 * by GdkPixbuf.
200 	 *
201 	 * Since: 2.6
202 	 */
203 	public void addPixbufFormats()
204 	{
205 		gtk_file_filter_add_pixbuf_formats(gtkFileFilter);
206 	}
207 
208 	/**
209 	 * Tests whether a file should be displayed according to @filter.
210 	 * The #GtkFileFilterInfo @filter_info should include
211 	 * the fields returned from gtk_file_filter_get_needed().
212 	 *
213 	 * This function will not typically be used by applications; it
214 	 * is intended principally for use in the implementation of
215 	 * #GtkFileChooser.
216 	 *
217 	 * Params:
218 	 *     filterInfo = a #GtkFileFilterInfo containing information
219 	 *         about a file.
220 	 *
221 	 * Return: %TRUE if the file should be displayed
222 	 *
223 	 * Since: 2.4
224 	 */
225 	public bool filter(GtkFileFilterInfo* filterInfo)
226 	{
227 		return gtk_file_filter_filter(gtkFileFilter, filterInfo) != 0;
228 	}
229 
230 	/**
231 	 * Gets the human-readable name for the filter. See gtk_file_filter_set_name().
232 	 *
233 	 * Return: The human-readable name of the filter,
234 	 *     or %NULL. This value is owned by GTK+ and must not
235 	 *     be modified or freed.
236 	 *
237 	 * Since: 2.4
238 	 */
239 	public string getName()
240 	{
241 		return Str.toString(gtk_file_filter_get_name(gtkFileFilter));
242 	}
243 
244 	/**
245 	 * Gets the fields that need to be filled in for the #GtkFileFilterInfo
246 	 * passed to gtk_file_filter_filter()
247 	 *
248 	 * This function will not typically be used by applications; it
249 	 * is intended principally for use in the implementation of
250 	 * #GtkFileChooser.
251 	 *
252 	 * Return: bitfield of flags indicating needed fields when
253 	 *     calling gtk_file_filter_filter()
254 	 *
255 	 * Since: 2.4
256 	 */
257 	public GtkFileFilterFlags getNeeded()
258 	{
259 		return gtk_file_filter_get_needed(gtkFileFilter);
260 	}
261 
262 	/**
263 	 * Sets the human-readable name of the filter; this is the string
264 	 * that will be displayed in the file selector user interface if
265 	 * there is a selectable list of filters.
266 	 *
267 	 * Params:
268 	 *     name = the human-readable-name for the filter, or %NULL
269 	 *         to remove any existing name.
270 	 *
271 	 * Since: 2.4
272 	 */
273 	public void setName(string name)
274 	{
275 		gtk_file_filter_set_name(gtkFileFilter, Str.toStringz(name));
276 	}
277 }