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.
127 	 * At the moment this check is done only on resources pointing
128 	 * to local files.
129 	 *
130 	 * Return: %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 	 * Return: 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 	 * Return: 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 	 * Return: %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 	 * Return: 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 		return Str.toStringArray(gtk_recent_info_get_applications(gtkRecentInfo, &length));
213 	}
214 
215 	/**
216 	 * Gets the (short) description of the resource.
217 	 *
218 	 * Return: the description of the resource. The returned string
219 	 *     is owned by the recent manager, and should not be freed.
220 	 *
221 	 * Since: 2.10
222 	 */
223 	public string getDescription()
224 	{
225 		return Str.toString(gtk_recent_info_get_description(gtkRecentInfo));
226 	}
227 
228 	/**
229 	 * Gets the name of the resource. If none has been defined, the basename
230 	 * of the resource is obtained.
231 	 *
232 	 * Return: the display name of the resource. The returned string
233 	 *     is owned by the recent manager, and should not be freed.
234 	 *
235 	 * Since: 2.10
236 	 */
237 	public string getDisplayName()
238 	{
239 		return Str.toString(gtk_recent_info_get_display_name(gtkRecentInfo));
240 	}
241 
242 	/**
243 	 * Retrieves the icon associated to the resource MIME type.
244 	 *
245 	 * Return: a #GIcon containing the icon, or %NULL.
246 	 *     Use g_object_unref() when finished using the icon
247 	 *
248 	 * Since: 2.22
249 	 */
250 	public IconIF getGicon()
251 	{
252 		auto p = gtk_recent_info_get_gicon(gtkRecentInfo);
253 		
254 		if(p is null)
255 		{
256 			return null;
257 		}
258 		
259 		return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p);
260 	}
261 
262 	/**
263 	 * Returns all groups registered for the recently used item @info.
264 	 * The array of returned group names will be %NULL terminated, so
265 	 * length might optionally be %NULL.
266 	 *
267 	 * Return: a newly allocated %NULL terminated array of strings.
268 	 *     Use g_strfreev() to free it.
269 	 *
270 	 * Since: 2.10
271 	 */
272 	public string[] getGroups()
273 	{
274 		size_t length;
275 		
276 		return Str.toStringArray(gtk_recent_info_get_groups(gtkRecentInfo, &length));
277 	}
278 
279 	/**
280 	 * Retrieves the icon of size @size associated to the resource MIME type.
281 	 *
282 	 * Params:
283 	 *     size = the size of the icon in pixels
284 	 *
285 	 * Return: a #GdkPixbuf containing the icon,
286 	 *     or %NULL. Use g_object_unref() when finished using the icon.
287 	 *
288 	 * Since: 2.10
289 	 */
290 	public Pixbuf getIcon(int size)
291 	{
292 		auto p = gtk_recent_info_get_icon(gtkRecentInfo, size);
293 		
294 		if(p is null)
295 		{
296 			return null;
297 		}
298 		
299 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p, true);
300 	}
301 
302 	/**
303 	 * Gets the MIME type of the resource.
304 	 *
305 	 * Return: the MIME type of the resource. The returned string
306 	 *     is owned by the recent manager, and should not be freed.
307 	 *
308 	 * Since: 2.10
309 	 */
310 	public string getMimeType()
311 	{
312 		return Str.toString(gtk_recent_info_get_mime_type(gtkRecentInfo));
313 	}
314 
315 	/**
316 	 * Gets the timestamp (seconds from system’s Epoch) when the meta-data
317 	 * for the resource was last modified.
318 	 *
319 	 * Return: the number of seconds elapsed from system’s Epoch when
320 	 *     the resource was last modified, or -1 on failure.
321 	 *
322 	 * Since: 2.10
323 	 */
324 	public uint getModified()
325 	{
326 		return gtk_recent_info_get_modified(gtkRecentInfo);
327 	}
328 
329 	/**
330 	 * Gets the value of the “private” flag. Resources in the recently used
331 	 * list that have this flag set to %TRUE should only be displayed by the
332 	 * applications that have registered them.
333 	 *
334 	 * Return: %TRUE if the private flag was found, %FALSE otherwise
335 	 *
336 	 * Since: 2.10
337 	 */
338 	public bool getPrivateHint()
339 	{
340 		return gtk_recent_info_get_private_hint(gtkRecentInfo) != 0;
341 	}
342 
343 	/**
344 	 * Computes a valid UTF-8 string that can be used as the
345 	 * name of the item in a menu or list. For example, calling
346 	 * this function on an item that refers to
347 	 * “file:///foo/bar.txt” will yield “bar.txt”.
348 	 *
349 	 * Return: A newly-allocated string in UTF-8 encoding
350 	 *     free it with g_free()
351 	 *
352 	 * Since: 2.10
353 	 */
354 	public string getShortName()
355 	{
356 		return Str.toString(gtk_recent_info_get_short_name(gtkRecentInfo));
357 	}
358 
359 	/**
360 	 * Gets the URI of the resource.
361 	 *
362 	 * Return: the URI of the resource. The returned string is
363 	 *     owned by the recent manager, and should not be freed.
364 	 *
365 	 * Since: 2.10
366 	 */
367 	public string getUri()
368 	{
369 		return Str.toString(gtk_recent_info_get_uri(gtkRecentInfo));
370 	}
371 
372 	/**
373 	 * Gets a displayable version of the resource’s URI. If the resource
374 	 * is local, it returns a local path; if the resource is not local,
375 	 * it returns the UTF-8 encoded content of gtk_recent_info_get_uri().
376 	 *
377 	 * Return: a newly allocated UTF-8 string containing the
378 	 *     resource’s URI or %NULL. Use g_free() when done using it.
379 	 *
380 	 * Since: 2.10
381 	 */
382 	public string getUriDisplay()
383 	{
384 		return Str.toString(gtk_recent_info_get_uri_display(gtkRecentInfo));
385 	}
386 
387 	/**
388 	 * Gets the timestamp (seconds from system’s Epoch) when the meta-data
389 	 * for the resource was last visited.
390 	 *
391 	 * Return: the number of seconds elapsed from system’s Epoch when
392 	 *     the resource was last visited, or -1 on failure.
393 	 *
394 	 * Since: 2.10
395 	 */
396 	public uint getVisited()
397 	{
398 		return gtk_recent_info_get_visited(gtkRecentInfo);
399 	}
400 
401 	/**
402 	 * Checks whether an application registered this resource using @app_name.
403 	 *
404 	 * Params:
405 	 *     appName = a string containing an application name
406 	 *
407 	 * Return: %TRUE if an application with name @app_name was found,
408 	 *     %FALSE otherwise
409 	 *
410 	 * Since: 2.10
411 	 */
412 	public bool hasApplication(string appName)
413 	{
414 		return gtk_recent_info_has_application(gtkRecentInfo, Str.toStringz(appName)) != 0;
415 	}
416 
417 	/**
418 	 * Checks whether @group_name appears inside the groups
419 	 * registered for the recently used item @info.
420 	 *
421 	 * Params:
422 	 *     groupName = name of a group
423 	 *
424 	 * Return: %TRUE if the group was found
425 	 *
426 	 * Since: 2.10
427 	 */
428 	public bool hasGroup(string groupName)
429 	{
430 		return gtk_recent_info_has_group(gtkRecentInfo, Str.toStringz(groupName)) != 0;
431 	}
432 
433 	/**
434 	 * Checks whether the resource is local or not by looking at the
435 	 * scheme of its URI.
436 	 *
437 	 * Return: %TRUE if the resource is local
438 	 *
439 	 * Since: 2.10
440 	 */
441 	public bool isLocal()
442 	{
443 		return gtk_recent_info_is_local(gtkRecentInfo) != 0;
444 	}
445 
446 	/**
447 	 * Gets the name of the last application that have registered the
448 	 * recently used resource represented by @info.
449 	 *
450 	 * Return: an application name. Use g_free() to free it.
451 	 *
452 	 * Since: 2.10
453 	 */
454 	public string lastApplication()
455 	{
456 		return Str.toString(gtk_recent_info_last_application(gtkRecentInfo));
457 	}
458 
459 	/**
460 	 * Checks whether two #GtkRecentInfo-struct point to the same
461 	 * resource.
462 	 *
463 	 * Params:
464 	 *     infoB = a #GtkRecentInfo
465 	 *
466 	 * Return: %TRUE if both #GtkRecentInfo-struct point to the same
467 	 *     resource, %FALSE otherwise
468 	 *
469 	 * Since: 2.10
470 	 */
471 	public bool match(RecentInfo infoB)
472 	{
473 		return gtk_recent_info_match(gtkRecentInfo, (infoB is null) ? null : infoB.getRecentInfoStruct()) != 0;
474 	}
475 
476 	/**
477 	 * Increases the reference count of @recent_info by one.
478 	 *
479 	 * Return: the recent info object with its reference count
480 	 *     increased by one
481 	 *
482 	 * Since: 2.10
483 	 */
484 	public RecentInfo doref()
485 	{
486 		auto p = gtk_recent_info_ref(gtkRecentInfo);
487 		
488 		if(p is null)
489 		{
490 			return null;
491 		}
492 		
493 		return ObjectG.getDObject!(RecentInfo)(cast(GtkRecentInfo*) p);
494 	}
495 
496 	/**
497 	 * Decreases the reference count of @info by one. If the reference
498 	 * count reaches zero, @info is deallocated, and the memory freed.
499 	 *
500 	 * Since: 2.10
501 	 */
502 	public void unref()
503 	{
504 		gtk_recent_info_unref(gtkRecentInfo);
505 	}
506 }