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