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