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