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