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