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 gobject.ObjectG;
39 public  import gtkc.giotypes;
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 	 * Params:
206 	 *     searchString = the search string to use
207 	 *
208 	 * Returns: a
209 	 *     list of strvs.  Free each item with g_strfreev() and free the outer
210 	 *     list with g_free().
211 	 */
212 	public static string[][] search(string searchString)
213 	{
214 		auto retStr = g_desktop_app_info_search(Str.toStringz(searchString));
215 
216 		scope(exit) Str.freeStringArray(retStr);
217 		return Str.toStringArray(retStr);
218 	}
219 
220 	/**
221 	 * Sets the name of the desktop that the application is running in.
222 	 * This is used by g_app_info_should_show() and
223 	 * g_desktop_app_info_get_show_in() to evaluate the
224 	 * `OnlyShowIn` and `NotShowIn`
225 	 * desktop entry fields.
226 	 *
227 	 * Should be called only once; subsequent calls are ignored.
228 	 *
229 	 * Deprecated: do not use this API.  Since 2.42 the value of the
230 	 * `XDG_CURRENT_DESKTOP` environment variable will be used.
231 	 *
232 	 * Params:
233 	 *     desktopEnv = a string specifying what desktop this is
234 	 */
235 	public static void setDesktopEnv(string desktopEnv)
236 	{
237 		g_desktop_app_info_set_desktop_env(Str.toStringz(desktopEnv));
238 	}
239 
240 	/**
241 	 * Gets the user-visible display name of the "additional application
242 	 * action" specified by @action_name.
243 	 *
244 	 * This corresponds to the "Name" key within the keyfile group for the
245 	 * action.
246 	 *
247 	 * Params:
248 	 *     actionName = the name of the action as from
249 	 *         g_desktop_app_info_list_actions()
250 	 *
251 	 * Returns: the locale-specific action name
252 	 *
253 	 * Since: 2.38
254 	 */
255 	public string getActionName(string actionName)
256 	{
257 		auto retStr = g_desktop_app_info_get_action_name(gDesktopAppInfo, Str.toStringz(actionName));
258 
259 		scope(exit) Str.freeString(retStr);
260 		return Str.toString(retStr);
261 	}
262 
263 	/**
264 	 * Looks up a boolean value in the keyfile backing @info.
265 	 *
266 	 * The @key is looked up in the "Desktop Entry" group.
267 	 *
268 	 * Params:
269 	 *     key = the key to look up
270 	 *
271 	 * Returns: the boolean value, or %FALSE if the key
272 	 *     is not found
273 	 *
274 	 * Since: 2.36
275 	 */
276 	public bool getBoolean(string key)
277 	{
278 		return g_desktop_app_info_get_boolean(gDesktopAppInfo, Str.toStringz(key)) != 0;
279 	}
280 
281 	/**
282 	 * Gets the categories from the desktop file.
283 	 *
284 	 * Returns: The unparsed Categories key from the desktop file;
285 	 *     i.e. no attempt is made to split it by ';' or validate it.
286 	 */
287 	public string getCategories()
288 	{
289 		return Str.toString(g_desktop_app_info_get_categories(gDesktopAppInfo));
290 	}
291 
292 	/**
293 	 * When @info was created from a known filename, return it.  In some
294 	 * situations such as the #GDesktopAppInfo returned from
295 	 * g_desktop_app_info_new_from_keyfile(), this function will return %NULL.
296 	 *
297 	 * Returns: The full path to the file for @info,
298 	 *     or %NULL if not known.
299 	 *
300 	 * Since: 2.24
301 	 */
302 	public string getFilename()
303 	{
304 		return Str.toString(g_desktop_app_info_get_filename(gDesktopAppInfo));
305 	}
306 
307 	/**
308 	 * Gets the generic name from the destkop file.
309 	 *
310 	 * Returns: The value of the GenericName key
311 	 */
312 	public string getGenericName()
313 	{
314 		return Str.toString(g_desktop_app_info_get_generic_name(gDesktopAppInfo));
315 	}
316 
317 	/**
318 	 * A desktop file is hidden if the Hidden key in it is
319 	 * set to True.
320 	 *
321 	 * Returns: %TRUE if hidden, %FALSE otherwise.
322 	 */
323 	public bool getIsHidden()
324 	{
325 		return g_desktop_app_info_get_is_hidden(gDesktopAppInfo) != 0;
326 	}
327 
328 	/**
329 	 * Gets the keywords from the desktop file.
330 	 *
331 	 * Returns: The value of the Keywords key
332 	 *
333 	 * Since: 2.32
334 	 */
335 	public string[] getKeywords()
336 	{
337 		return Str.toStringArray(g_desktop_app_info_get_keywords(gDesktopAppInfo));
338 	}
339 
340 	/**
341 	 * Looks up a localized string value in the keyfile backing @info
342 	 * translated to the current locale.
343 	 *
344 	 * The @key is looked up in the "Desktop Entry" group.
345 	 *
346 	 * Params:
347 	 *     key = the key to look up
348 	 *
349 	 * Returns: a newly allocated string, or %NULL if the key
350 	 *     is not found
351 	 *
352 	 * Since: 2.56
353 	 */
354 	public string getLocaleString(string key)
355 	{
356 		auto retStr = g_desktop_app_info_get_locale_string(gDesktopAppInfo, Str.toStringz(key));
357 
358 		scope(exit) Str.freeString(retStr);
359 		return Str.toString(retStr);
360 	}
361 
362 	/**
363 	 * Gets the value of the NoDisplay key, which helps determine if the
364 	 * application info should be shown in menus. See
365 	 * #G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY and g_app_info_should_show().
366 	 *
367 	 * Returns: The value of the NoDisplay key
368 	 *
369 	 * Since: 2.30
370 	 */
371 	public bool getNodisplay()
372 	{
373 		return g_desktop_app_info_get_nodisplay(gDesktopAppInfo) != 0;
374 	}
375 
376 	/**
377 	 * Checks if the application info should be shown in menus that list available
378 	 * applications for a specific name of the desktop, based on the
379 	 * `OnlyShowIn` and `NotShowIn` keys.
380 	 *
381 	 * @desktop_env should typically be given as %NULL, in which case the
382 	 * `XDG_CURRENT_DESKTOP` environment variable is consulted.  If you want
383 	 * to override the default mechanism then you may specify @desktop_env,
384 	 * but this is not recommended.
385 	 *
386 	 * Note that g_app_info_should_show() for @info will include this check (with
387 	 * %NULL for @desktop_env) as well as additional checks.
388 	 *
389 	 * Params:
390 	 *     desktopEnv = a string specifying a desktop name
391 	 *
392 	 * Returns: %TRUE if the @info should be shown in @desktop_env according to the
393 	 *     `OnlyShowIn` and `NotShowIn` keys, %FALSE
394 	 *     otherwise.
395 	 *
396 	 * Since: 2.30
397 	 */
398 	public bool getShowIn(string desktopEnv)
399 	{
400 		return g_desktop_app_info_get_show_in(gDesktopAppInfo, Str.toStringz(desktopEnv)) != 0;
401 	}
402 
403 	/**
404 	 * Retrieves the StartupWMClass field from @info. This represents the
405 	 * WM_CLASS property of the main window of the application, if launched
406 	 * through @info.
407 	 *
408 	 * Returns: the startup WM class, or %NULL if none is set
409 	 *     in the desktop file.
410 	 *
411 	 * Since: 2.34
412 	 */
413 	public string getStartupWmClass()
414 	{
415 		return Str.toString(g_desktop_app_info_get_startup_wm_class(gDesktopAppInfo));
416 	}
417 
418 	/**
419 	 * Looks up a string value in the keyfile backing @info.
420 	 *
421 	 * The @key is looked up in the "Desktop Entry" group.
422 	 *
423 	 * Params:
424 	 *     key = the key to look up
425 	 *
426 	 * Returns: a newly allocated string, or %NULL if the key
427 	 *     is not found
428 	 *
429 	 * Since: 2.36
430 	 */
431 	public string getString(string key)
432 	{
433 		auto retStr = g_desktop_app_info_get_string(gDesktopAppInfo, Str.toStringz(key));
434 
435 		scope(exit) Str.freeString(retStr);
436 		return Str.toString(retStr);
437 	}
438 
439 	/**
440 	 * Looks up a string list value in the keyfile backing @info.
441 	 *
442 	 * The @key is looked up in the "Desktop Entry" group.
443 	 *
444 	 * Params:
445 	 *     key = the key to look up
446 	 *
447 	 * Returns: a %NULL-terminated string array or %NULL if the specified
448 	 *     key cannot be found. The array should be freed with g_strfreev().
449 	 *
450 	 * Since: 2.60
451 	 */
452 	public string[] getStringList(string key)
453 	{
454 		size_t length;
455 
456 		auto retStr = g_desktop_app_info_get_string_list(gDesktopAppInfo, Str.toStringz(key), &length);
457 
458 		scope(exit) Str.freeStringArray(retStr);
459 		return Str.toStringArray(retStr, length);
460 	}
461 
462 	/**
463 	 * Returns whether @key exists in the "Desktop Entry" group
464 	 * of the keyfile backing @info.
465 	 *
466 	 * Params:
467 	 *     key = the key to look up
468 	 *
469 	 * Returns: %TRUE if the @key exists
470 	 *
471 	 * Since: 2.36
472 	 */
473 	public bool hasKey(string key)
474 	{
475 		return g_desktop_app_info_has_key(gDesktopAppInfo, Str.toStringz(key)) != 0;
476 	}
477 
478 	/**
479 	 * Activates the named application action.
480 	 *
481 	 * You may only call this function on action names that were
482 	 * returned from g_desktop_app_info_list_actions().
483 	 *
484 	 * Note that if the main entry of the desktop file indicates that the
485 	 * application supports startup notification, and @launch_context is
486 	 * non-%NULL, then startup notification will be used when activating the
487 	 * action (and as such, invocation of the action on the receiving side
488 	 * must signal the end of startup notification when it is completed).
489 	 * This is the expected behaviour of applications declaring additional
490 	 * actions, as per the desktop file specification.
491 	 *
492 	 * As with g_app_info_launch() there is no way to detect failures that
493 	 * occur while using this function.
494 	 *
495 	 * Params:
496 	 *     actionName = the name of the action as from
497 	 *         g_desktop_app_info_list_actions()
498 	 *     launchContext = a #GAppLaunchContext
499 	 *
500 	 * Since: 2.38
501 	 */
502 	public void launchAction(string actionName, AppLaunchContext launchContext)
503 	{
504 		g_desktop_app_info_launch_action(gDesktopAppInfo, Str.toStringz(actionName), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct());
505 	}
506 
507 	/**
508 	 * This function performs the equivalent of g_app_info_launch_uris(),
509 	 * but is intended primarily for operating system components that
510 	 * launch applications.  Ordinary applications should use
511 	 * g_app_info_launch_uris().
512 	 *
513 	 * If the application is launched via GSpawn, then @spawn_flags, @user_setup
514 	 * and @user_setup_data are used for the call to g_spawn_async().
515 	 * Additionally, @pid_callback (with @pid_callback_data) will be called to
516 	 * inform about the PID of the created process. See g_spawn_async_with_pipes()
517 	 * for information on certain parameter conditions that can enable an
518 	 * optimized posix_spawn() codepath to be used.
519 	 *
520 	 * If application launching occurs via some other mechanism (eg: D-Bus
521 	 * activation) then @spawn_flags, @user_setup, @user_setup_data,
522 	 * @pid_callback and @pid_callback_data are ignored.
523 	 *
524 	 * Params:
525 	 *     uris = List of URIs
526 	 *     launchContext = a #GAppLaunchContext
527 	 *     spawnFlags = #GSpawnFlags, used for each process
528 	 *     userSetup = a #GSpawnChildSetupFunc, used once
529 	 *         for each process.
530 	 *     userSetupData = User data for @user_setup
531 	 *     pidCallback = Callback for child processes
532 	 *     pidCallbackData = User data for @callback
533 	 *
534 	 * Returns: %TRUE on successful launch, %FALSE otherwise.
535 	 *
536 	 * Throws: GException on failure.
537 	 */
538 	public bool launchUrisAsManager(ListG uris, AppLaunchContext launchContext, GSpawnFlags spawnFlags, GSpawnChildSetupFunc userSetup, void* userSetupData, GDesktopAppLaunchCallback pidCallback, void* pidCallbackData)
539 	{
540 		GError* err = null;
541 
542 		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;
543 
544 		if (err !is null)
545 		{
546 			throw new GException( new ErrorG(err) );
547 		}
548 
549 		return __p;
550 	}
551 
552 	/**
553 	 * Equivalent to g_desktop_app_info_launch_uris_as_manager() but allows
554 	 * you to pass in file descriptors for the stdin, stdout and stderr streams
555 	 * of the launched process.
556 	 *
557 	 * If application launching occurs via some non-spawn mechanism (e.g. D-Bus
558 	 * activation) then @stdin_fd, @stdout_fd and @stderr_fd are ignored.
559 	 *
560 	 * Params:
561 	 *     uris = List of URIs
562 	 *     launchContext = a #GAppLaunchContext
563 	 *     spawnFlags = #GSpawnFlags, used for each process
564 	 *     userSetup = a #GSpawnChildSetupFunc, used once
565 	 *         for each process.
566 	 *     userSetupData = User data for @user_setup
567 	 *     pidCallback = Callback for child processes
568 	 *     pidCallbackData = User data for @callback
569 	 *     stdinFd = file descriptor to use for child's stdin, or -1
570 	 *     stdoutFd = file descriptor to use for child's stdout, or -1
571 	 *     stderrFd = file descriptor to use for child's stderr, or -1
572 	 *
573 	 * Returns: %TRUE on successful launch, %FALSE otherwise.
574 	 *
575 	 * Since: 2.58
576 	 *
577 	 * Throws: GException on failure.
578 	 */
579 	public bool launchUrisAsManagerWithFds(ListG uris, AppLaunchContext launchContext, GSpawnFlags spawnFlags, GSpawnChildSetupFunc userSetup, void* userSetupData, GDesktopAppLaunchCallback pidCallback, void* pidCallbackData, int stdinFd, int stdoutFd, int stderrFd)
580 	{
581 		GError* err = null;
582 
583 		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;
584 
585 		if (err !is null)
586 		{
587 			throw new GException( new ErrorG(err) );
588 		}
589 
590 		return __p;
591 	}
592 
593 	/**
594 	 * Returns the list of "additional application actions" supported on the
595 	 * desktop file, as per the desktop file specification.
596 	 *
597 	 * As per the specification, this is the list of actions that are
598 	 * explicitly listed in the "Actions" key of the [Desktop Entry] group.
599 	 *
600 	 * Returns: a list of strings, always non-%NULL
601 	 *
602 	 * Since: 2.38
603 	 */
604 	public string[] listActions()
605 	{
606 		return Str.toStringArray(g_desktop_app_info_list_actions(gDesktopAppInfo));
607 	}
608 }