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 gio.DesktopAppInfo;
26 
27 private import gio.AppInfoIF;
28 private import gio.AppInfoT;
29 private import gio.AppLaunchContext;
30 private import gio.c.functions;
31 public  import gio.c.types;
32 private import glib.ConstructionException;
33 private import glib.ErrorG;
34 private import glib.GException;
35 private import glib.KeyFile;
36 private import glib.ListG;
37 private import glib.Str;
38 private import glib.c.functions;
39 private import gobject.ObjectG;
40 
41 
42 /**
43  * #GDesktopAppInfo is an implementation of #GAppInfo based on
44  * desktop files.
45  * 
46  * Note that `<gio/gdesktopappinfo.h>` belongs to the UNIX-specific
47  * GIO interfaces, thus you have to use the `gio-unix-2.0.pc` pkg-config
48  * file when using it.
49  */
50 public class DesktopAppInfo : ObjectG, AppInfoIF
51 {
52 	/** the main Gtk struct */
53 	protected GDesktopAppInfo* gDesktopAppInfo;
54 
55 	/** Get the main Gtk struct */
56 	public GDesktopAppInfo* getDesktopAppInfoStruct(bool transferOwnership = false)
57 	{
58 		if (transferOwnership)
59 			ownedRef = false;
60 		return gDesktopAppInfo;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected override void* getStruct()
65 	{
66 		return cast(void*)gDesktopAppInfo;
67 	}
68 
69 	/**
70 	 * Sets our main struct and passes it to the parent class.
71 	 */
72 	public this (GDesktopAppInfo* gDesktopAppInfo, bool ownedRef = false)
73 	{
74 		this.gDesktopAppInfo = gDesktopAppInfo;
75 		super(cast(GObject*)gDesktopAppInfo, ownedRef);
76 	}
77 
78 	// add the AppInfo capabilities
79 	mixin AppInfoT!(GDesktopAppInfo);
80 
81 	/**
82 	 * Creates a new #GDesktopAppInfo.
83 	 *
84 	 * Params:
85 	 *     filename = the path of a desktop file, in the GLib filename encoding
86 	 *
87 	 * Return: a new #GDesktopAppInfo or %NULL on error.
88 	 *
89 	 * Throws: ConstructionException GTK+ fails to create the object.
90 	 */
91 	public static DesktopAppInfo createFromFilename(string filename)
92 	{
93 		auto p = g_desktop_app_info_new_from_filename(Str.toStringz(filename));
94 
95 		if(p is null)
96 		{
97 			throw new ConstructionException("null returned by g_desktop_app_info_new_from_filename");
98 		}
99 
100 		return new DesktopAppInfo(p, true);
101 	}
102 
103 	/**
104 	 */
105 
106 	/** */
107 	public static GType getType()
108 	{
109 		return g_desktop_app_info_get_type();
110 	}
111 
112 	/**
113 	 * Creates a new #GDesktopAppInfo based on a desktop file id.
114 	 *
115 	 * A desktop file id is the basename of the desktop file, including the
116 	 * .desktop extension. GIO is looking for a desktop file with this name
117 	 * in the `applications` subdirectories of the XDG
118 	 * data directories (i.e. the directories specified in the `XDG_DATA_HOME`
119 	 * and `XDG_DATA_DIRS` environment variables). GIO also supports the
120 	 * prefix-to-subdirectory mapping that is described in the
121 	 * [Menu Spec](http://standards.freedesktop.org/menu-spec/latest/)
122 	 * (i.e. a desktop id of kde-foo.desktop will match
123 	 * `/usr/share/applications/kde/foo.desktop`).
124 	 *
125 	 * Params:
126 	 *     desktopId = the desktop file id
127 	 *
128 	 * Returns: a new #GDesktopAppInfo, or %NULL if no desktop
129 	 *     file with that id exists.
130 	 *
131 	 * Throws: ConstructionException GTK+ fails to create the object.
132 	 */
133 	public this(string desktopId)
134 	{
135 		auto __p = g_desktop_app_info_new(Str.toStringz(desktopId));
136 
137 		if(__p is null)
138 		{
139 			throw new ConstructionException("null returned by new");
140 		}
141 
142 		this(cast(GDesktopAppInfo*) __p, true);
143 	}
144 
145 	/**
146 	 * Creates a new #GDesktopAppInfo.
147 	 *
148 	 * Params:
149 	 *     keyFile = an opened #GKeyFile
150 	 *
151 	 * Returns: a new #GDesktopAppInfo or %NULL on error.
152 	 *
153 	 * Since: 2.18
154 	 *
155 	 * Throws: ConstructionException GTK+ fails to create the object.
156 	 */
157 	public this(KeyFile keyFile)
158 	{
159 		auto __p = g_desktop_app_info_new_from_keyfile((keyFile is null) ? null : keyFile.getKeyFileStruct());
160 
161 		if(__p is null)
162 		{
163 			throw new ConstructionException("null returned by new_from_keyfile");
164 		}
165 
166 		this(cast(GDesktopAppInfo*) __p, true);
167 	}
168 
169 	/**
170 	 * Gets all applications that implement @interface.
171 	 *
172 	 * An application implements an interface if that interface is listed in
173 	 * the Implements= line of the desktop file of the application.
174 	 *
175 	 * Params:
176 	 *     interface_ = the name of the interface
177 	 *
178 	 * Returns: a list of #GDesktopAppInfo
179 	 *     objects.
180 	 *
181 	 * Since: 2.42
182 	 */
183 	public static ListG getImplementations(string interface_)
184 	{
185 		auto __p = g_desktop_app_info_get_implementations(Str.toStringz(interface_));
186 
187 		if(__p is null)
188 		{
189 			return null;
190 		}
191 
192 		return new ListG(cast(GList*) __p, true);
193 	}
194 
195 	/**
196 	 * Searches desktop files for ones that match @search_string.
197 	 *
198 	 * The return value is an array of strvs.  Each strv contains a list of
199 	 * applications that matched @search_string with an equal score.  The
200 	 * outer list is sorted by score so that the first strv contains the
201 	 * best-matching applications, and so on.
202 	 * The algorithm for determining matches is undefined and may change at
203 	 * any time.
204 	 *
205 	 * None of the search results are subjected to the normal validation
206 	 * checks performed by g_desktop_app_info_new() (for example, checking that
207 	 * the executable referenced by a result exists), and so it is possible for
208 	 * g_desktop_app_info_new() to return %NULL when passed an app ID returned by
209 	 * this function. It is expected that calling code will do this when
210 	 * subsequently creating a #GDesktopAppInfo for each result.
211 	 *
212 	 * Params:
213 	 *     searchString = the search string to use
214 	 *
215 	 * Returns: a
216 	 *     list of strvs.  Free each item with g_strfreev() and free the outer
217 	 *     list with g_free().
218 	 */
219 	public static string[][] search(string searchString)
220 	{
221 		auto retStr = g_desktop_app_info_search(Str.toStringz(searchString));
222 
223 		scope(exit) Str.freeStringArray(retStr);
224 		return Str.toStringArray(retStr);
225 	}
226 
227 	/**
228 	 * Sets the name of the desktop that the application is running in.
229 	 * This is used by g_app_info_should_show() and
230 	 * g_desktop_app_info_get_show_in() to evaluate the
231 	 * `OnlyShowIn` and `NotShowIn`
232 	 * desktop entry fields.
233 	 *
234 	 * Should be called only once; subsequent calls are ignored.
235 	 *
236 	 * Deprecated: do not use this API.  Since 2.42 the value of the
237 	 * `XDG_CURRENT_DESKTOP` environment variable will be used.
238 	 *
239 	 * Params:
240 	 *     desktopEnv = a string specifying what desktop this is
241 	 */
242 	public static void setDesktopEnv(string desktopEnv)
243 	{
244 		g_desktop_app_info_set_desktop_env(Str.toStringz(desktopEnv));
245 	}
246 
247 	/**
248 	 * Gets the user-visible display name of the "additional application
249 	 * action" specified by @action_name.
250 	 *
251 	 * This corresponds to the "Name" key within the keyfile group for the
252 	 * action.
253 	 *
254 	 * Params:
255 	 *     actionName = the name of the action as from
256 	 *         g_desktop_app_info_list_actions()
257 	 *
258 	 * Returns: the locale-specific action name
259 	 *
260 	 * Since: 2.38
261 	 */
262 	public string getActionName(string actionName)
263 	{
264 		auto retStr = g_desktop_app_info_get_action_name(gDesktopAppInfo, Str.toStringz(actionName));
265 
266 		scope(exit) Str.freeString(retStr);
267 		return Str.toString(retStr);
268 	}
269 
270 	/**
271 	 * Looks up a boolean value in the keyfile backing @info.
272 	 *
273 	 * The @key is looked up in the "Desktop Entry" group.
274 	 *
275 	 * Params:
276 	 *     key = the key to look up
277 	 *
278 	 * Returns: the boolean value, or %FALSE if the key
279 	 *     is not found
280 	 *
281 	 * Since: 2.36
282 	 */
283 	public bool getBoolean(string key)
284 	{
285 		return g_desktop_app_info_get_boolean(gDesktopAppInfo, Str.toStringz(key)) != 0;
286 	}
287 
288 	/**
289 	 * Gets the categories from the desktop file.
290 	 *
291 	 * Returns: The unparsed Categories key from the desktop file;
292 	 *     i.e. no attempt is made to split it by ';' or validate it.
293 	 */
294 	public string getCategories()
295 	{
296 		return Str.toString(g_desktop_app_info_get_categories(gDesktopAppInfo));
297 	}
298 
299 	/**
300 	 * When @info was created from a known filename, return it.  In some
301 	 * situations such as the #GDesktopAppInfo returned from
302 	 * g_desktop_app_info_new_from_keyfile(), this function will return %NULL.
303 	 *
304 	 * Returns: The full path to the file for @info,
305 	 *     or %NULL if not known.
306 	 *
307 	 * Since: 2.24
308 	 */
309 	public string getFilename()
310 	{
311 		return Str.toString(g_desktop_app_info_get_filename(gDesktopAppInfo));
312 	}
313 
314 	/**
315 	 * Gets the generic name from the desktop file.
316 	 *
317 	 * Returns: The value of the GenericName key
318 	 */
319 	public string getGenericName()
320 	{
321 		return Str.toString(g_desktop_app_info_get_generic_name(gDesktopAppInfo));
322 	}
323 
324 	/**
325 	 * A desktop file is hidden if the Hidden key in it is
326 	 * set to True.
327 	 *
328 	 * Returns: %TRUE if hidden, %FALSE otherwise.
329 	 */
330 	public bool getIsHidden()
331 	{
332 		return g_desktop_app_info_get_is_hidden(gDesktopAppInfo) != 0;
333 	}
334 
335 	/**
336 	 * Gets the keywords from the desktop file.
337 	 *
338 	 * Returns: The value of the Keywords key
339 	 *
340 	 * Since: 2.32
341 	 */
342 	public string[] getKeywords()
343 	{
344 		return Str.toStringArray(g_desktop_app_info_get_keywords(gDesktopAppInfo));
345 	}
346 
347 	/**
348 	 * Looks up a localized string value in the keyfile backing @info
349 	 * translated to the current locale.
350 	 *
351 	 * The @key is looked up in the "Desktop Entry" group.
352 	 *
353 	 * Params:
354 	 *     key = the key to look up
355 	 *
356 	 * Returns: a newly allocated string, or %NULL if the key
357 	 *     is not found
358 	 *
359 	 * Since: 2.56
360 	 */
361 	public string getLocaleString(string key)
362 	{
363 		auto retStr = g_desktop_app_info_get_locale_string(gDesktopAppInfo, Str.toStringz(key));
364 
365 		scope(exit) Str.freeString(retStr);
366 		return Str.toString(retStr);
367 	}
368 
369 	/**
370 	 * Gets the value of the NoDisplay key, which helps determine if the
371 	 * application info should be shown in menus. See
372 	 * #G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY and g_app_info_should_show().
373 	 *
374 	 * Returns: The value of the NoDisplay key
375 	 *
376 	 * Since: 2.30
377 	 */
378 	public bool getNodisplay()
379 	{
380 		return g_desktop_app_info_get_nodisplay(gDesktopAppInfo) != 0;
381 	}
382 
383 	/**
384 	 * Checks if the application info should be shown in menus that list available
385 	 * applications for a specific name of the desktop, based on the
386 	 * `OnlyShowIn` and `NotShowIn` keys.
387 	 *
388 	 * @desktop_env should typically be given as %NULL, in which case the
389 	 * `XDG_CURRENT_DESKTOP` environment variable is consulted.  If you want
390 	 * to override the default mechanism then you may specify @desktop_env,
391 	 * but this is not recommended.
392 	 *
393 	 * Note that g_app_info_should_show() for @info will include this check (with
394 	 * %NULL for @desktop_env) as well as additional checks.
395 	 *
396 	 * Params:
397 	 *     desktopEnv = a string specifying a desktop name
398 	 *
399 	 * Returns: %TRUE if the @info should be shown in @desktop_env according to the
400 	 *     `OnlyShowIn` and `NotShowIn` keys, %FALSE
401 	 *     otherwise.
402 	 *
403 	 * Since: 2.30
404 	 */
405 	public bool getShowIn(string desktopEnv)
406 	{
407 		return g_desktop_app_info_get_show_in(gDesktopAppInfo, Str.toStringz(desktopEnv)) != 0;
408 	}
409 
410 	/**
411 	 * Retrieves the StartupWMClass field from @info. This represents the
412 	 * WM_CLASS property of the main window of the application, if launched
413 	 * through @info.
414 	 *
415 	 * Returns: the startup WM class, or %NULL if none is set
416 	 *     in the desktop file.
417 	 *
418 	 * Since: 2.34
419 	 */
420 	public string getStartupWmClass()
421 	{
422 		return Str.toString(g_desktop_app_info_get_startup_wm_class(gDesktopAppInfo));
423 	}
424 
425 	/**
426 	 * Looks up a string value in the keyfile backing @info.
427 	 *
428 	 * The @key is looked up in the "Desktop Entry" group.
429 	 *
430 	 * Params:
431 	 *     key = the key to look up
432 	 *
433 	 * Returns: a newly allocated string, or %NULL if the key
434 	 *     is not found
435 	 *
436 	 * Since: 2.36
437 	 */
438 	public string getString(string key)
439 	{
440 		auto retStr = g_desktop_app_info_get_string(gDesktopAppInfo, Str.toStringz(key));
441 
442 		scope(exit) Str.freeString(retStr);
443 		return Str.toString(retStr);
444 	}
445 
446 	/**
447 	 * Looks up a string list value in the keyfile backing @info.
448 	 *
449 	 * The @key is looked up in the "Desktop Entry" group.
450 	 *
451 	 * Params:
452 	 *     key = the key to look up
453 	 *
454 	 * Returns: a %NULL-terminated string array or %NULL if the specified
455 	 *     key cannot be found. The array should be freed with g_strfreev().
456 	 *
457 	 * Since: 2.60
458 	 */
459 	public string[] getStringList(string key)
460 	{
461 		size_t length;
462 
463 		auto retStr = g_desktop_app_info_get_string_list(gDesktopAppInfo, Str.toStringz(key), &length);
464 
465 		scope(exit) Str.freeStringArray(retStr);
466 		return Str.toStringArray(retStr, length);
467 	}
468 
469 	/**
470 	 * Returns whether @key exists in the "Desktop Entry" group
471 	 * of the keyfile backing @info.
472 	 *
473 	 * Params:
474 	 *     key = the key to look up
475 	 *
476 	 * Returns: %TRUE if the @key exists
477 	 *
478 	 * Since: 2.36
479 	 */
480 	public bool hasKey(string key)
481 	{
482 		return g_desktop_app_info_has_key(gDesktopAppInfo, Str.toStringz(key)) != 0;
483 	}
484 
485 	/**
486 	 * Activates the named application action.
487 	 *
488 	 * You may only call this function on action names that were
489 	 * returned from g_desktop_app_info_list_actions().
490 	 *
491 	 * Note that if the main entry of the desktop file indicates that the
492 	 * application supports startup notification, and @launch_context is
493 	 * non-%NULL, then startup notification will be used when activating the
494 	 * action (and as such, invocation of the action on the receiving side
495 	 * must signal the end of startup notification when it is completed).
496 	 * This is the expected behaviour of applications declaring additional
497 	 * actions, as per the desktop file specification.
498 	 *
499 	 * As with g_app_info_launch() there is no way to detect failures that
500 	 * occur while using this function.
501 	 *
502 	 * Params:
503 	 *     actionName = the name of the action as from
504 	 *         g_desktop_app_info_list_actions()
505 	 *     launchContext = a #GAppLaunchContext
506 	 *
507 	 * Since: 2.38
508 	 */
509 	public void launchAction(string actionName, AppLaunchContext launchContext)
510 	{
511 		g_desktop_app_info_launch_action(gDesktopAppInfo, Str.toStringz(actionName), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct());
512 	}
513 
514 	/**
515 	 * This function performs the equivalent of g_app_info_launch_uris(),
516 	 * but is intended primarily for operating system components that
517 	 * launch applications.  Ordinary applications should use
518 	 * g_app_info_launch_uris().
519 	 *
520 	 * If the application is launched via GSpawn, then @spawn_flags, @user_setup
521 	 * and @user_setup_data are used for the call to g_spawn_async().
522 	 * Additionally, @pid_callback (with @pid_callback_data) will be called to
523 	 * inform about the PID of the created process. See g_spawn_async_with_pipes()
524 	 * for information on certain parameter conditions that can enable an
525 	 * optimized posix_spawn() codepath to be used.
526 	 *
527 	 * If application launching occurs via some other mechanism (eg: D-Bus
528 	 * activation) then @spawn_flags, @user_setup, @user_setup_data,
529 	 * @pid_callback and @pid_callback_data are ignored.
530 	 *
531 	 * Params:
532 	 *     uris = List of URIs
533 	 *     launchContext = a #GAppLaunchContext
534 	 *     spawnFlags = #GSpawnFlags, used for each process
535 	 *     userSetup = a #GSpawnChildSetupFunc, used once
536 	 *         for each process.
537 	 *     userSetupData = User data for @user_setup
538 	 *     pidCallback = Callback for child processes
539 	 *     pidCallbackData = User data for @callback
540 	 *
541 	 * Returns: %TRUE on successful launch, %FALSE otherwise.
542 	 *
543 	 * Throws: GException on failure.
544 	 */
545 	public bool launchUrisAsManager(ListG uris, AppLaunchContext launchContext, GSpawnFlags spawnFlags, GSpawnChildSetupFunc userSetup, void* userSetupData, GDesktopAppLaunchCallback pidCallback, void* pidCallbackData)
546 	{
547 		GError* err = null;
548 
549 		auto __p = g_desktop_app_info_launch_uris_as_manager(gDesktopAppInfo, (uris is null) ? null : uris.getListGStruct(), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct(), spawnFlags, userSetup, userSetupData, pidCallback, pidCallbackData, &err) != 0;
550 
551 		if (err !is null)
552 		{
553 			throw new GException( new ErrorG(err) );
554 		}
555 
556 		return __p;
557 	}
558 
559 	/**
560 	 * Equivalent to g_desktop_app_info_launch_uris_as_manager() but allows
561 	 * you to pass in file descriptors for the stdin, stdout and stderr streams
562 	 * of the launched process.
563 	 *
564 	 * If application launching occurs via some non-spawn mechanism (e.g. D-Bus
565 	 * activation) then @stdin_fd, @stdout_fd and @stderr_fd are ignored.
566 	 *
567 	 * Params:
568 	 *     uris = List of URIs
569 	 *     launchContext = a #GAppLaunchContext
570 	 *     spawnFlags = #GSpawnFlags, used for each process
571 	 *     userSetup = a #GSpawnChildSetupFunc, used once
572 	 *         for each process.
573 	 *     userSetupData = User data for @user_setup
574 	 *     pidCallback = Callback for child processes
575 	 *     pidCallbackData = User data for @callback
576 	 *     stdinFd = file descriptor to use for child's stdin, or -1
577 	 *     stdoutFd = file descriptor to use for child's stdout, or -1
578 	 *     stderrFd = file descriptor to use for child's stderr, or -1
579 	 *
580 	 * Returns: %TRUE on successful launch, %FALSE otherwise.
581 	 *
582 	 * Since: 2.58
583 	 *
584 	 * Throws: GException on failure.
585 	 */
586 	public bool launchUrisAsManagerWithFds(ListG uris, AppLaunchContext launchContext, GSpawnFlags spawnFlags, GSpawnChildSetupFunc userSetup, void* userSetupData, GDesktopAppLaunchCallback pidCallback, void* pidCallbackData, int stdinFd, int stdoutFd, int stderrFd)
587 	{
588 		GError* err = null;
589 
590 		auto __p = g_desktop_app_info_launch_uris_as_manager_with_fds(gDesktopAppInfo, (uris is null) ? null : uris.getListGStruct(), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct(), spawnFlags, userSetup, userSetupData, pidCallback, pidCallbackData, stdinFd, stdoutFd, stderrFd, &err) != 0;
591 
592 		if (err !is null)
593 		{
594 			throw new GException( new ErrorG(err) );
595 		}
596 
597 		return __p;
598 	}
599 
600 	/**
601 	 * Returns the list of "additional application actions" supported on the
602 	 * desktop file, as per the desktop file specification.
603 	 *
604 	 * As per the specification, this is the list of actions that are
605 	 * explicitly listed in the "Actions" key of the [Desktop Entry] group.
606 	 *
607 	 * Returns: a list of strings, always non-%NULL
608 	 *
609 	 * Since: 2.38
610 	 */
611 	public string[] listActions()
612 	{
613 		return Str.toStringArray(g_desktop_app_info_list_actions(gDesktopAppInfo));
614 	}
615 }