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