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  * Conversion parameters:
26  * inFile  = 
27  * outPack = gtk
28  * outFile = RecentInfo
29  * strct   = GtkRecentInfo
30  * realStrct=
31  * ctorStrct=
32  * clss    = RecentInfo
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_recent_info_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * 	- changed
46  * imports:
47  * 	- glib.Str
48  * 	- glib.ErrorG
49  * 	- glib.GException
50  * 	- gio.AppInfo
51  * 	- gio.Icon
52  * 	- gio.IconIF
53  * 	- gdk.Pixbuf
54  * 	- gtkc.Loader
55  * 	- gtkc.paths
56  * structWrap:
57  * 	- GAppInfo* -> AppInfo
58  * 	- GIcon* -> IconIF
59  * 	- GdkPixbuf* -> Pixbuf
60  * 	- GtkRecentInfo* -> RecentInfo
61  * module aliases:
62  * local aliases:
63  * overrides:
64  */
65 
66 module gtk.RecentInfo;
67 
68 public  import gtkc.gtktypes;
69 
70 private import gtkc.gtk;
71 private import glib.ConstructionException;
72 private import gobject.ObjectG;
73 
74 private import gobject.Signals;
75 public  import gtkc.gdktypes;
76 
77 private import glib.Str;
78 private import glib.ErrorG;
79 private import glib.GException;
80 private import gio.AppInfo;
81 private import gio.Icon;
82 private import gio.IconIF;
83 private import gdk.Pixbuf;
84 private import gtkc.Loader;
85 private import gtkc.paths;
86 
87 
88 
89 
90 /**
91  * GtkRecentManager provides a facility for adding, removing and
92  * looking up recently used files. Each recently used file is
93  * identified by its URI, and has meta-data associated to it, like
94  * the names and command lines of the applications that have
95  * registered it, the number of time each application has registered
96  * the same file, the mime type of the file and whether the file
97  * should be displayed only by the applications that have
98  * registered it.
99  *
100  * Note
101  *
102  * The recently used files list is per user.
103  *
104  * The GtkRecentManager acts like a database of all the recently
105  * used files. You can create new GtkRecentManager objects, but
106  * it is more efficient to use the default manager created by GTK+.
107  *
108  * Adding a new recently used file is as simple as:
109  *
110  * $(DDOC_COMMENT example)
111  *
112  * The GtkRecentManager will try to gather all the needed information
113  * from the file itself through GIO.
114  *
115  * Looking up the meta-data associated with a recently used file
116  * given its URI requires calling gtk_recent_manager_lookup_item():
117  *
118  * $(DDOC_COMMENT example)
119  *
120  * In order to retrieve the list of recently used files, you can use
121  * gtk_recent_manager_get_items(), which returns a list of GtkRecentInfo
122  * structures.
123  *
124  * A GtkRecentManager is the model used to populate the contents of
125  * one, or more GtkRecentChooser implementations.
126  *
127  * Note
128  *
129  * The maximum age of the recently used files list is
130  * controllable through the "gtk-recent-files-max-age"
131  * property.
132  *
133  * Recently used files are supported since GTK+ 2.10.
134  */
135 public class RecentInfo
136 {
137 	
138 	/** the main Gtk struct */
139 	protected GtkRecentInfo* gtkRecentInfo;
140 	
141 	
142 	public GtkRecentInfo* getRecentInfoStruct()
143 	{
144 		return gtkRecentInfo;
145 	}
146 	
147 	
148 	/** the main Gtk struct as a void* */
149 	protected void* getStruct()
150 	{
151 		return cast(void*)gtkRecentInfo;
152 	}
153 	
154 	/**
155 	 * Sets our main struct and passes it to the parent class
156 	 */
157 	public this (GtkRecentInfo* gtkRecentInfo)
158 	{
159 		this.gtkRecentInfo = gtkRecentInfo;
160 	}
161 	
162 	~this ()
163 	{
164 		if (  Linker.isLoaded(LIBRARY.GTK) && gtkRecentInfo !is null )
165 		{
166 			gtk_recent_info_unref(gtkRecentInfo);
167 		}
168 	}
169 	
170 	/**
171 	 */
172 	
173 	/**
174 	 * Increases the reference count of recent_info by one.
175 	 * Since 2.10
176 	 * Returns: the recent info object with its reference count increased by one.
177 	 */
178 	public RecentInfo doref()
179 	{
180 		// GtkRecentInfo * gtk_recent_info_ref (GtkRecentInfo *info);
181 		auto p = gtk_recent_info_ref(gtkRecentInfo);
182 		
183 		if(p is null)
184 		{
185 			return null;
186 		}
187 		
188 		return ObjectG.getDObject!(RecentInfo)(cast(GtkRecentInfo*) p);
189 	}
190 	
191 	/**
192 	 * Decreases the reference count of info by one. If the reference
193 	 * count reaches zero, info is deallocated, and the memory freed.
194 	 * Since 2.10
195 	 */
196 	public void unref()
197 	{
198 		// void gtk_recent_info_unref (GtkRecentInfo *info);
199 		gtk_recent_info_unref(gtkRecentInfo);
200 	}
201 	
202 	/**
203 	 * Gets the URI of the resource.
204 	 * Since 2.10
205 	 * Returns: the URI of the resource. The returned string is owned by the recent manager, and should not be freed.
206 	 */
207 	public string getUri()
208 	{
209 		// const gchar * gtk_recent_info_get_uri (GtkRecentInfo *info);
210 		return Str.toString(gtk_recent_info_get_uri(gtkRecentInfo));
211 	}
212 	
213 	/**
214 	 * Gets the name of the resource. If none has been defined, the basename
215 	 * of the resource is obtained.
216 	 * Since 2.10
217 	 * Returns: the display name of the resource. The returned string is owned by the recent manager, and should not be freed.
218 	 */
219 	public string getDisplayName()
220 	{
221 		// const gchar * gtk_recent_info_get_display_name (GtkRecentInfo *info);
222 		return Str.toString(gtk_recent_info_get_display_name(gtkRecentInfo));
223 	}
224 	
225 	/**
226 	 * Gets the (short) description of the resource.
227 	 * Since 2.10
228 	 * Returns: the description of the resource. The returned string is owned by the recent manager, and should not be freed.
229 	 */
230 	public string getDescription()
231 	{
232 		// const gchar * gtk_recent_info_get_description (GtkRecentInfo *info);
233 		return Str.toString(gtk_recent_info_get_description(gtkRecentInfo));
234 	}
235 	
236 	/**
237 	 * Gets the MIME type of the resource.
238 	 * Since 2.10
239 	 * Returns: the MIME type of the resource. The returned string is owned by the recent manager, and should not be freed.
240 	 */
241 	public string getMimeType()
242 	{
243 		// const gchar * gtk_recent_info_get_mime_type (GtkRecentInfo *info);
244 		return Str.toString(gtk_recent_info_get_mime_type(gtkRecentInfo));
245 	}
246 	
247 	/**
248 	 * Gets the timestamp (seconds from system's Epoch) when the resource
249 	 * was added to the recently used resources list.
250 	 * Since 2.10
251 	 * Returns: the number of seconds elapsed from system's Epoch when the resource was added to the list, or -1 on failure.
252 	 */
253 	public uint getAdded()
254 	{
255 		// time_t gtk_recent_info_get_added (GtkRecentInfo *info);
256 		return gtk_recent_info_get_added(gtkRecentInfo);
257 	}
258 	
259 	/**
260 	 * Gets the timestamp (seconds from system's Epoch) when the meta-data
261 	 * for the resource was last modified.
262 	 * Since 2.10
263 	 * Returns: the number of seconds elapsed from system's Epoch when the resource was last modified, or -1 on failure.
264 	 */
265 	public uint getModified()
266 	{
267 		// time_t gtk_recent_info_get_modified (GtkRecentInfo *info);
268 		return gtk_recent_info_get_modified(gtkRecentInfo);
269 	}
270 	
271 	/**
272 	 * Gets the timestamp (seconds from system's Epoch) when the meta-data
273 	 * for the resource was last visited.
274 	 * Since 2.10
275 	 * Returns: the number of seconds elapsed from system's Epoch when the resource was last visited, or -1 on failure.
276 	 */
277 	public uint getVisited()
278 	{
279 		// time_t gtk_recent_info_get_visited (GtkRecentInfo *info);
280 		return gtk_recent_info_get_visited(gtkRecentInfo);
281 	}
282 	
283 	/**
284 	 * Gets the value of the "private" flag. Resources in the recently used
285 	 * list that have this flag set to TRUE should only be displayed by the
286 	 * applications that have registered them.
287 	 * Since 2.10
288 	 * Returns: TRUE if the private flag was found, FALSE otherwise.
289 	 */
290 	public int getPrivateHint()
291 	{
292 		// gboolean gtk_recent_info_get_private_hint (GtkRecentInfo *info);
293 		return gtk_recent_info_get_private_hint(gtkRecentInfo);
294 	}
295 	
296 	/**
297 	 * Gets the data regarding the application that has registered the resource
298 	 * pointed by info.
299 	 * If the command line contains any escape characters defined inside the
300 	 * storage specification, they will be expanded.
301 	 * Since 2.10
302 	 * Params:
303 	 * appName = the name of the application that has registered this item
304 	 * appExec = return location for the string containing the command line. [transfer none][out]
305 	 * count = return location for the number of times this item was registered. [out]
306 	 * time = return location for the timestamp this item was last registered
307 	 * for this application. [out]
308 	 * Returns: TRUE if an application with app_name has registered this resource inside the recently used list, or FALSE otherwise. The app_exec string is owned by the GtkRecentInfo and should not be modified or freed
309 	 */
310 	public int getApplicationInfo(string appName, out string appExec, out uint count, out uint time)
311 	{
312 		// gboolean gtk_recent_info_get_application_info  (GtkRecentInfo *info,  const gchar *app_name,  const gchar **app_exec,  guint *count,  time_t *time_);
313 		char* outappExec = null;
314 		
315 		auto p = gtk_recent_info_get_application_info(gtkRecentInfo, Str.toStringz(appName), &outappExec, &count, &time);
316 		
317 		appExec = Str.toString(outappExec);
318 		return p;
319 	}
320 	
321 	/**
322 	 * Retrieves the list of applications that have registered this resource.
323 	 * Since 2.10
324 	 * Returns: a newly allocated NULL-terminated array of strings. Use g_strfreev() to free it. [array length=length zero-terminated=1][transfer full]
325 	 */
326 	public string[] getApplications()
327 	{
328 		// gchar ** gtk_recent_info_get_applications (GtkRecentInfo *info,  gsize *length);
329 		gsize length;
330 		auto p = gtk_recent_info_get_applications(gtkRecentInfo, &length);
331 		
332 		string[] strArray = null;
333 		foreach ( cstr; p[0 .. length] )
334 		{
335 			strArray ~= Str.toString(cstr);
336 		}
337 		
338 		return strArray;
339 	}
340 	
341 	/**
342 	 * Gets the name of the last application that have registered the
343 	 * recently used resource represented by info.
344 	 * Since 2.10
345 	 * Returns: an application name. Use g_free() to free it.
346 	 */
347 	public string lastApplication()
348 	{
349 		// gchar * gtk_recent_info_last_application (GtkRecentInfo *info);
350 		return Str.toString(gtk_recent_info_last_application(gtkRecentInfo));
351 	}
352 	
353 	/**
354 	 * Checks whether an application registered this resource using app_name.
355 	 * Since 2.10
356 	 * Params:
357 	 * appName = a string containing an application name
358 	 * Returns: TRUE if an application with name app_name was found, FALSE otherwise.
359 	 */
360 	public int hasApplication(string appName)
361 	{
362 		// gboolean gtk_recent_info_has_application (GtkRecentInfo *info,  const gchar *app_name);
363 		return gtk_recent_info_has_application(gtkRecentInfo, Str.toStringz(appName));
364 	}
365 	
366 	/**
367 	 * Creates a GAppInfo for the specified GtkRecentInfo
368 	 * Params:
369 	 * appName = the name of the application that should
370 	 * be mapped to a GAppInfo; if NULL is used then the default
371 	 * application for the MIME type is used. [allow-none]
372 	 * Returns: the newly created GAppInfo, or NULL. In case of error, error will be set either with a GTK_RECENT_MANAGER_ERROR or a G_IO_ERROR. [transfer full]
373 	 * Throws: GException on failure.
374 	 */
375 	public AppInfo createAppInfo(string appName)
376 	{
377 		// GAppInfo * gtk_recent_info_create_app_info (GtkRecentInfo *info,  const gchar *app_name,  GError **error);
378 		GError* err = null;
379 		
380 		auto p = gtk_recent_info_create_app_info(gtkRecentInfo, Str.toStringz(appName), &err);
381 		
382 		if (err !is null)
383 		{
384 			throw new GException( new ErrorG(err) );
385 		}
386 		
387 		
388 		if(p is null)
389 		{
390 			return null;
391 		}
392 		
393 		return ObjectG.getDObject!(AppInfo)(cast(GAppInfo*) p);
394 	}
395 	
396 	/**
397 	 * Returns all groups registered for the recently used item info. The
398 	 * array of returned group names will be NULL terminated, so length might
399 	 * optionally be NULL.
400 	 * Since 2.10
401 	 * Returns: a newly allocated NULL terminated array of strings. Use g_strfreev() to free it. [array length=length zero-terminated=1][transfer full]
402 	 */
403 	public string[] getGroups()
404 	{
405 		// gchar ** gtk_recent_info_get_groups (GtkRecentInfo *info,  gsize *length);
406 		gsize length;
407 		auto p = gtk_recent_info_get_groups(gtkRecentInfo, &length);
408 		
409 		string[] strArray = null;
410 		foreach ( cstr; p[0 .. length] )
411 		{
412 			strArray ~= Str.toString(cstr);
413 		}
414 		
415 		return strArray;
416 	}
417 	
418 	/**
419 	 * Checks whether group_name appears inside the groups registered for the
420 	 * recently used item info.
421 	 * Since 2.10
422 	 * Params:
423 	 * groupName = name of a group
424 	 * Returns: TRUE if the group was found.
425 	 */
426 	public int hasGroup(string groupName)
427 	{
428 		// gboolean gtk_recent_info_has_group (GtkRecentInfo *info,  const gchar *group_name);
429 		return gtk_recent_info_has_group(gtkRecentInfo, Str.toStringz(groupName));
430 	}
431 	
432 	/**
433 	 * Retrieves the icon of size size associated to the resource MIME type.
434 	 * Since 2.10
435 	 * Params:
436 	 * size = the size of the icon in pixels
437 	 * Returns: a GdkPixbuf containing the icon, or NULL. Use g_object_unref() when finished using the icon. [transfer full]
438 	 */
439 	public Pixbuf getIcon(int size)
440 	{
441 		// GdkPixbuf * gtk_recent_info_get_icon (GtkRecentInfo *info,  gint size);
442 		auto p = gtk_recent_info_get_icon(gtkRecentInfo, size);
443 		
444 		if(p is null)
445 		{
446 			return null;
447 		}
448 		
449 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
450 	}
451 	
452 	/**
453 	 * Retrieves the icon associated to the resource MIME type.
454 	 * Since 2.22
455 	 * Returns: a GIcon containing the icon, or NULL. Use g_object_unref() when finished using the icon. [transfer full]
456 	 */
457 	public IconIF getGicon()
458 	{
459 		// GIcon * gtk_recent_info_get_gicon (GtkRecentInfo *info);
460 		auto p = gtk_recent_info_get_gicon(gtkRecentInfo);
461 		
462 		if(p is null)
463 		{
464 			return null;
465 		}
466 		
467 		return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p);
468 	}
469 	
470 	/**
471 	 * Computes a valid UTF-8 string that can be used as the name of the item in a
472 	 * menu or list. For example, calling this function on an item that refers to
473 	 * "file:///foo/bar.txt" will yield "bar.txt".
474 	 * Since 2.10
475 	 * Returns: A newly-allocated string in UTF-8 encoding; free it with g_free().
476 	 */
477 	public string getShortName()
478 	{
479 		// gchar * gtk_recent_info_get_short_name (GtkRecentInfo *info);
480 		return Str.toString(gtk_recent_info_get_short_name(gtkRecentInfo));
481 	}
482 	
483 	/**
484 	 * Gets a displayable version of the resource's URI. If the resource
485 	 * is local, it returns a local path; if the resource is not local,
486 	 * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
487 	 * Since 2.10
488 	 * Returns: a newly allocated UTF-8 string containing the resource's URI or NULL. Use g_free() when done using it.
489 	 */
490 	public string getUriDisplay()
491 	{
492 		// gchar * gtk_recent_info_get_uri_display (GtkRecentInfo *info);
493 		return Str.toString(gtk_recent_info_get_uri_display(gtkRecentInfo));
494 	}
495 	
496 	/**
497 	 * Gets the number of days elapsed since the last update of the resource
498 	 * pointed by info.
499 	 * Since 2.10
500 	 * Returns: a positive integer containing the number of days elapsed since the time this resource was last modified.
501 	 */
502 	public int getAge()
503 	{
504 		// gint gtk_recent_info_get_age (GtkRecentInfo *info);
505 		return gtk_recent_info_get_age(gtkRecentInfo);
506 	}
507 	
508 	/**
509 	 * Checks whether the resource is local or not by looking at the
510 	 * scheme of its URI.
511 	 * Since 2.10
512 	 * Returns: TRUE if the resource is local.
513 	 */
514 	public int isLocal()
515 	{
516 		// gboolean gtk_recent_info_is_local (GtkRecentInfo *info);
517 		return gtk_recent_info_is_local(gtkRecentInfo);
518 	}
519 	
520 	/**
521 	 * Checks whether the resource pointed by info still exists. At
522 	 * the moment this check is done only on resources pointing to local files.
523 	 * Since 2.10
524 	 * Returns: TRUE if the resource exists
525 	 */
526 	public int exists()
527 	{
528 		// gboolean gtk_recent_info_exists (GtkRecentInfo *info);
529 		return gtk_recent_info_exists(gtkRecentInfo);
530 	}
531 	
532 	/**
533 	 * Checks whether two GtkRecentInfo structures point to the same
534 	 * resource.
535 	 * Since 2.10
536 	 * Params:
537 	 * infoB = a GtkRecentInfo
538 	 * Returns: TRUE if both GtkRecentInfo structures point to se same resource, FALSE otherwise.
539 	 */
540 	public int match(RecentInfo infoB)
541 	{
542 		// gboolean gtk_recent_info_match (GtkRecentInfo *info_a,  GtkRecentInfo *info_b);
543 		return gtk_recent_info_match(gtkRecentInfo, (infoB is null) ? null : infoB.getRecentInfoStruct());
544 	}
545 }