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