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 	public static GType getType()
122 	{
123 		return gtk_recent_filter_get_type();
124 	}
125 
126 	/**
127 	 * Creates a new #GtkRecentFilter with no rules added to it.
128 	 * Such filter does not accept any recently used resources, so is not
129 	 * particularly useful until you add rules with
130 	 * gtk_recent_filter_add_pattern(), gtk_recent_filter_add_mime_type(),
131 	 * gtk_recent_filter_add_application(), gtk_recent_filter_add_age().
132 	 * To create a filter that accepts any recently used resource, use:
133 	 * |[<!-- language="C" -->
134 	 * GtkRecentFilter *filter = gtk_recent_filter_new ();
135 	 * gtk_recent_filter_add_pattern (filter, "*");
136 	 * ]|
137 	 *
138 	 * Return: a new #GtkRecentFilter
139 	 *
140 	 * Since: 2.10
141 	 *
142 	 * Throws: ConstructionException GTK+ fails to create the object.
143 	 */
144 	public this()
145 	{
146 		auto p = gtk_recent_filter_new();
147 		
148 		if(p is null)
149 		{
150 			throw new ConstructionException("null returned by new");
151 		}
152 		
153 		this(cast(GtkRecentFilter*) p);
154 	}
155 
156 	/**
157 	 * Adds a rule that allows resources based on their age - that is, the number
158 	 * of days elapsed since they were last modified.
159 	 *
160 	 * Params:
161 	 *     days = number of days
162 	 *
163 	 * Since: 2.10
164 	 */
165 	public void addAge(int days)
166 	{
167 		gtk_recent_filter_add_age(gtkRecentFilter, days);
168 	}
169 
170 	/**
171 	 * Adds a rule that allows resources based on the name of the application
172 	 * that has registered them.
173 	 *
174 	 * Params:
175 	 *     application = an application name
176 	 *
177 	 * Since: 2.10
178 	 */
179 	public void addApplication(string application)
180 	{
181 		gtk_recent_filter_add_application(gtkRecentFilter, Str.toStringz(application));
182 	}
183 
184 	/**
185 	 * Adds a rule to a filter that allows resources based on a custom callback
186 	 * function. The bitfield @needed which is passed in provides information
187 	 * about what sorts of information that the filter function needs;
188 	 * this allows GTK+ to avoid retrieving expensive information when
189 	 * it isn’t needed by the filter.
190 	 *
191 	 * Params:
192 	 *     needed = bitfield of flags indicating the information that the custom
193 	 *         filter function needs.
194 	 *     func = callback function; if the function returns %TRUE, then
195 	 *         the file will be displayed.
196 	 *     data = data to pass to @func
197 	 *     dataDestroy = function to call to free @data when it is no longer needed.
198 	 *
199 	 * Since: 2.10
200 	 */
201 	public void addCustom(GtkRecentFilterFlags needed, GtkRecentFilterFunc func, void* data, GDestroyNotify dataDestroy)
202 	{
203 		gtk_recent_filter_add_custom(gtkRecentFilter, needed, func, data, dataDestroy);
204 	}
205 
206 	/**
207 	 * Adds a rule that allows resources based on the name of the group
208 	 * to which they belong
209 	 *
210 	 * Params:
211 	 *     group = a group name
212 	 *
213 	 * Since: 2.10
214 	 */
215 	public void addGroup(string group)
216 	{
217 		gtk_recent_filter_add_group(gtkRecentFilter, Str.toStringz(group));
218 	}
219 
220 	/**
221 	 * Adds a rule that allows resources based on their registered MIME type.
222 	 *
223 	 * Params:
224 	 *     mimeType = a MIME type
225 	 *
226 	 * Since: 2.10
227 	 */
228 	public void addMimeType(string mimeType)
229 	{
230 		gtk_recent_filter_add_mime_type(gtkRecentFilter, Str.toStringz(mimeType));
231 	}
232 
233 	/**
234 	 * Adds a rule that allows resources based on a pattern matching their
235 	 * display name.
236 	 *
237 	 * Params:
238 	 *     pattern = a file pattern
239 	 *
240 	 * Since: 2.10
241 	 */
242 	public void addPattern(string pattern)
243 	{
244 		gtk_recent_filter_add_pattern(gtkRecentFilter, Str.toStringz(pattern));
245 	}
246 
247 	/**
248 	 * Adds a rule allowing image files in the formats supported
249 	 * by GdkPixbuf.
250 	 *
251 	 * Since: 2.10
252 	 */
253 	public void addPixbufFormats()
254 	{
255 		gtk_recent_filter_add_pixbuf_formats(gtkRecentFilter);
256 	}
257 
258 	/**
259 	 * Tests whether a file should be displayed according to @filter.
260 	 * The #GtkRecentFilterInfo @filter_info should include
261 	 * the fields returned from gtk_recent_filter_get_needed(), and
262 	 * must set the #GtkRecentFilterInfo.contains field of @filter_info
263 	 * to indicate which fields have been set.
264 	 *
265 	 * This function will not typically be used by applications; it
266 	 * is intended principally for use in the implementation of
267 	 * #GtkRecentChooser.
268 	 *
269 	 * Params:
270 	 *     filterInfo = a #GtkRecentFilterInfo containing information
271 	 *         about a recently used resource
272 	 *
273 	 * Return: %TRUE if the file should be displayed
274 	 *
275 	 * Since: 2.10
276 	 */
277 	public bool filter(GtkRecentFilterInfo* filterInfo)
278 	{
279 		return gtk_recent_filter_filter(gtkRecentFilter, filterInfo) != 0;
280 	}
281 
282 	/**
283 	 * Gets the human-readable name for the filter.
284 	 * See gtk_recent_filter_set_name().
285 	 *
286 	 * Return: the name of the filter, or %NULL.  The returned string
287 	 *     is owned by the filter object and should not be freed.
288 	 *
289 	 * Since: 2.10
290 	 */
291 	public string getName()
292 	{
293 		return Str.toString(gtk_recent_filter_get_name(gtkRecentFilter));
294 	}
295 
296 	/**
297 	 * Gets the fields that need to be filled in for the #GtkRecentFilterInfo
298 	 * passed to gtk_recent_filter_filter()
299 	 *
300 	 * This function will not typically be used by applications; it
301 	 * is intended principally for use in the implementation of
302 	 * #GtkRecentChooser.
303 	 *
304 	 * Return: bitfield of flags indicating needed fields when
305 	 *     calling gtk_recent_filter_filter()
306 	 *
307 	 * Since: 2.10
308 	 */
309 	public GtkRecentFilterFlags getNeeded()
310 	{
311 		return gtk_recent_filter_get_needed(gtkRecentFilter);
312 	}
313 
314 	/**
315 	 * Sets the human-readable name of the filter; this is the string
316 	 * that will be displayed in the recently used resources selector
317 	 * user interface if there is a selectable list of filters.
318 	 *
319 	 * Params:
320 	 *     name = then human readable name of @filter
321 	 *
322 	 * Since: 2.10
323 	 */
324 	public void setName(string name)
325 	{
326 		gtk_recent_filter_set_name(gtkRecentFilter, Str.toStringz(name));
327 	}
328 }