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 file with that id
129 	 *
130 	 * Throws: ConstructionException GTK+ fails to create the object.
131 	 */
132 	public this(string desktopId)
133 	{
134 		auto p = g_desktop_app_info_new(Str.toStringz(desktopId));
135 
136 		if(p is null)
137 		{
138 			throw new ConstructionException("null returned by new");
139 		}
140 
141 		this(cast(GDesktopAppInfo*) p, true);
142 	}
143 
144 	/**
145 	 * Creates a new #GDesktopAppInfo.
146 	 *
147 	 * Params:
148 	 *     keyFile = an opened #GKeyFile
149 	 *
150 	 * Returns: a new #GDesktopAppInfo or %NULL on error.
151 	 *
152 	 * Since: 2.18
153 	 *
154 	 * Throws: ConstructionException GTK+ fails to create the object.
155 	 */
156 	public this(KeyFile keyFile)
157 	{
158 		auto p = g_desktop_app_info_new_from_keyfile((keyFile is null) ? null : keyFile.getKeyFileStruct());
159 
160 		if(p is null)
161 		{
162 			throw new ConstructionException("null returned by new_from_keyfile");
163 		}
164 
165 		this(cast(GDesktopAppInfo*) p, true);
166 	}
167 
168 	/**
169 	 * Gets all applications that implement @interface.
170 	 *
171 	 * An application implements an interface if that interface is listed in
172 	 * the Implements= line of the desktop file of the application.
173 	 *
174 	 * Params:
175 	 *     iface = the name of the interface
176 	 *
177 	 * Returns: a list of #GDesktopAppInfo
178 	 *     objects.
179 	 *
180 	 * Since: 2.42
181 	 */
182 	public static ListG getImplementations(string iface)
183 	{
184 		auto p = g_desktop_app_info_get_implementations(Str.toStringz(iface));
185 
186 		if(p is null)
187 		{
188 			return null;
189 		}
190 
191 		return new ListG(cast(GList*) p, true);
192 	}
193 
194 	/**
195 	 * Searches desktop files for ones that match @search_string.
196 	 *
197 	 * The return value is an array of strvs.  Each strv contains a list of
198 	 * applications that matched @search_string with an equal score.  The
199 	 * outer list is sorted by score so that the first strv contains the
200 	 * best-matching applications, and so on.
201 	 * The algorithm for determining matches is undefined and may change at
202 	 * any time.
203 	 *
204 	 * Params:
205 	 *     searchString = the search string to use
206 	 *
207 	 * Returns: a
208 	 *     list of strvs.  Free each item with g_strfreev() and free the outer
209 	 *     list with g_free().
210 	 */
211 	public static string[][] search(string searchString)
212 	{
213 		auto retStr = g_desktop_app_info_search(Str.toStringz(searchString));
214 
215 		scope(exit) Str.freeStringArray(retStr);
216 		return Str.toStringArray(retStr);
217 	}
218 
219 	/**
220 	 * Sets the name of the desktop that the application is running in.
221 	 * This is used by g_app_info_should_show() and
222 	 * g_desktop_app_info_get_show_in() to evaluate the
223 	 * `OnlyShowIn` and `NotShowIn`
224 	 * desktop entry fields.
225 	 *
226 	 * Should be called only once; subsequent calls are ignored.
227 	 *
228 	 * Deprecated: do not use this API.  Since 2.42 the value of the
229 	 * `XDG_CURRENT_DESKTOP` environment variable will be used.
230 	 *
231 	 * Params:
232 	 *     desktopEnv = a string specifying what desktop this is
233 	 */
234 	public static void setDesktopEnv(string desktopEnv)
235 	{
236 		g_desktop_app_info_set_desktop_env(Str.toStringz(desktopEnv));
237 	}
238 
239 	/**
240 	 * Gets the user-visible display name of the "additional application
241 	 * action" specified by @action_name.
242 	 *
243 	 * This corresponds to the "Name" key within the keyfile group for the
244 	 * action.
245 	 *
246 	 * Params:
247 	 *     actionName = the name of the action as from
248 	 *         g_desktop_app_info_list_actions()
249 	 *
250 	 * Returns: the locale-specific action name
251 	 *
252 	 * Since: 2.38
253 	 */
254 	public string getActionName(string actionName)
255 	{
256 		auto retStr = g_desktop_app_info_get_action_name(gDesktopAppInfo, Str.toStringz(actionName));
257 
258 		scope(exit) Str.freeString(retStr);
259 		return Str.toString(retStr);
260 	}
261 
262 	/**
263 	 * Looks up a boolean value in the keyfile backing @info.
264 	 *
265 	 * The @key is looked up in the "Desktop Entry" group.
266 	 *
267 	 * Params:
268 	 *     key = the key to look up
269 	 *
270 	 * Returns: the boolean value, or %FALSE if the key
271 	 *     is not found
272 	 *
273 	 * Since: 2.36
274 	 */
275 	public bool getBoolean(string key)
276 	{
277 		return g_desktop_app_info_get_boolean(gDesktopAppInfo, Str.toStringz(key)) != 0;
278 	}
279 
280 	/**
281 	 * Gets the categories from the desktop file.
282 	 *
283 	 * Returns: The unparsed Categories key from the desktop file;
284 	 *     i.e. no attempt is made to split it by ';' or validate it.
285 	 */
286 	public string getCategories()
287 	{
288 		return Str.toString(g_desktop_app_info_get_categories(gDesktopAppInfo));
289 	}
290 
291 	/**
292 	 * When @info was created from a known filename, return it.  In some
293 	 * situations such as the #GDesktopAppInfo returned from
294 	 * g_desktop_app_info_new_from_keyfile(), this function will return %NULL.
295 	 *
296 	 * Returns: The full path to the file for @info,
297 	 *     or %NULL if not known.
298 	 *
299 	 * Since: 2.24
300 	 */
301 	public string getFilename()
302 	{
303 		return Str.toString(g_desktop_app_info_get_filename(gDesktopAppInfo));
304 	}
305 
306 	/**
307 	 * Gets the generic name from the destkop file.
308 	 *
309 	 * Returns: The value of the GenericName key
310 	 */
311 	public string getGenericName()
312 	{
313 		return Str.toString(g_desktop_app_info_get_generic_name(gDesktopAppInfo));
314 	}
315 
316 	/**
317 	 * A desktop file is hidden if the Hidden key in it is
318 	 * set to True.
319 	 *
320 	 * Returns: %TRUE if hidden, %FALSE otherwise.
321 	 */
322 	public bool getIsHidden()
323 	{
324 		return g_desktop_app_info_get_is_hidden(gDesktopAppInfo) != 0;
325 	}
326 
327 	/**
328 	 * Gets the keywords from the desktop file.
329 	 *
330 	 * Returns: The value of the Keywords key
331 	 *
332 	 * Since: 2.32
333 	 */
334 	public string[] getKeywords()
335 	{
336 		return Str.toStringArray(g_desktop_app_info_get_keywords(gDesktopAppInfo));
337 	}
338 
339 	/**
340 	 * Looks up a localized string value in the keyfile backing @info
341 	 * translated to the current locale.
342 	 *
343 	 * The @key is looked up in the "Desktop Entry" group.
344 	 *
345 	 * Params:
346 	 *     key = the key to look up
347 	 *
348 	 * Returns: a newly allocated string, or %NULL if the key
349 	 *     is not found
350 	 *
351 	 * Since: 2.56
352 	 */
353 	public string getLocaleString(string key)
354 	{
355 		auto retStr = g_desktop_app_info_get_locale_string(gDesktopAppInfo, Str.toStringz(key));
356 
357 		scope(exit) Str.freeString(retStr);
358 		return Str.toString(retStr);
359 	}
360 
361 	/**
362 	 * Gets the value of the NoDisplay key, which helps determine if the
363 	 * application info should be shown in menus. See
364 	 * #G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY and g_app_info_should_show().
365 	 *
366 	 * Returns: The value of the NoDisplay key
367 	 *
368 	 * Since: 2.30
369 	 */
370 	public bool getNodisplay()
371 	{
372 		return g_desktop_app_info_get_nodisplay(gDesktopAppInfo) != 0;
373 	}
374 
375 	/**
376 	 * Checks if the application info should be shown in menus that list available
377 	 * applications for a specific name of the desktop, based on the
378 	 * `OnlyShowIn` and `NotShowIn` keys.
379 	 *
380 	 * @desktop_env should typically be given as %NULL, in which case the
381 	 * `XDG_CURRENT_DESKTOP` environment variable is consulted.  If you want
382 	 * to override the default mechanism then you may specify @desktop_env,
383 	 * but this is not recommended.
384 	 *
385 	 * Note that g_app_info_should_show() for @info will include this check (with
386 	 * %NULL for @desktop_env) as well as additional checks.
387 	 *
388 	 * Params:
389 	 *     desktopEnv = a string specifying a desktop name
390 	 *
391 	 * Returns: %TRUE if the @info should be shown in @desktop_env according to the
392 	 *     `OnlyShowIn` and `NotShowIn` keys, %FALSE
393 	 *     otherwise.
394 	 *
395 	 * Since: 2.30
396 	 */
397 	public bool getShowIn(string desktopEnv)
398 	{
399 		return g_desktop_app_info_get_show_in(gDesktopAppInfo, Str.toStringz(desktopEnv)) != 0;
400 	}
401 
402 	/**
403 	 * Retrieves the StartupWMClass field from @info. This represents the
404 	 * WM_CLASS property of the main window of the application, if launched
405 	 * through @info.
406 	 *
407 	 * Returns: the startup WM class, or %NULL if none is set
408 	 *     in the desktop file.
409 	 *
410 	 * Since: 2.34
411 	 */
412 	public string getStartupWmClass()
413 	{
414 		return Str.toString(g_desktop_app_info_get_startup_wm_class(gDesktopAppInfo));
415 	}
416 
417 	/**
418 	 * Looks up a string value in the keyfile backing @info.
419 	 *
420 	 * The @key is looked up in the "Desktop Entry" group.
421 	 *
422 	 * Params:
423 	 *     key = the key to look up
424 	 *
425 	 * Returns: a newly allocated string, or %NULL if the key
426 	 *     is not found
427 	 *
428 	 * Since: 2.36
429 	 */
430 	public string getString(string key)
431 	{
432 		auto retStr = g_desktop_app_info_get_string(gDesktopAppInfo, Str.toStringz(key));
433 
434 		scope(exit) Str.freeString(retStr);
435 		return Str.toString(retStr);
436 	}
437 
438 	/**
439 	 * Returns whether @key exists in the "Desktop Entry" group
440 	 * of the keyfile backing @info.
441 	 *
442 	 * Params:
443 	 *     key = the key to look up
444 	 *
445 	 * Returns: %TRUE if the @key exists
446 	 *
447 	 * Since: 2.36
448 	 */
449 	public bool hasKey(string key)
450 	{
451 		return g_desktop_app_info_has_key(gDesktopAppInfo, Str.toStringz(key)) != 0;
452 	}
453 
454 	/**
455 	 * Activates the named application action.
456 	 *
457 	 * You may only call this function on action names that were
458 	 * returned from g_desktop_app_info_list_actions().
459 	 *
460 	 * Note that if the main entry of the desktop file indicates that the
461 	 * application supports startup notification, and @launch_context is
462 	 * non-%NULL, then startup notification will be used when activating the
463 	 * action (and as such, invocation of the action on the receiving side
464 	 * must signal the end of startup notification when it is completed).
465 	 * This is the expected behaviour of applications declaring additional
466 	 * actions, as per the desktop file specification.
467 	 *
468 	 * As with g_app_info_launch() there is no way to detect failures that
469 	 * occur while using this function.
470 	 *
471 	 * Params:
472 	 *     actionName = the name of the action as from
473 	 *         g_desktop_app_info_list_actions()
474 	 *     launchContext = a #GAppLaunchContext
475 	 *
476 	 * Since: 2.38
477 	 */
478 	public void launchAction(string actionName, AppLaunchContext launchContext)
479 	{
480 		g_desktop_app_info_launch_action(gDesktopAppInfo, Str.toStringz(actionName), (launchContext is null) ? null : launchContext.getAppLaunchContextStruct());
481 	}
482 
483 	/**
484 	 * This function performs the equivalent of g_app_info_launch_uris(),
485 	 * but is intended primarily for operating system components that
486 	 * launch applications.  Ordinary applications should use
487 	 * g_app_info_launch_uris().
488 	 *
489 	 * If the application is launched via traditional UNIX fork()/exec()
490 	 * then @spawn_flags, @user_setup and @user_setup_data are used for the
491 	 * call to g_spawn_async().  Additionally, @pid_callback (with
492 	 * @pid_callback_data) will be called to inform about the PID of the
493 	 * created process.
494 	 *
495 	 * If application launching occurs via some other mechanism (eg: D-Bus
496 	 * activation) then @spawn_flags, @user_setup, @user_setup_data,
497 	 * @pid_callback and @pid_callback_data are ignored.
498 	 *
499 	 * Params:
500 	 *     uris = List of URIs
501 	 *     launchContext = a #GAppLaunchContext
502 	 *     spawnFlags = #GSpawnFlags, used for each process
503 	 *     userSetup = a #GSpawnChildSetupFunc, used once
504 	 *         for each process.
505 	 *     userSetupData = User data for @user_setup
506 	 *     pidCallback = Callback for child processes
507 	 *     pidCallbackData = User data for @callback
508 	 *
509 	 * Returns: %TRUE on successful launch, %FALSE otherwise.
510 	 *
511 	 * Throws: GException on failure.
512 	 */
513 	public bool launchUrisAsManager(ListG uris, AppLaunchContext launchContext, GSpawnFlags spawnFlags, GSpawnChildSetupFunc userSetup, void* userSetupData, GDesktopAppLaunchCallback pidCallback, void* pidCallbackData)
514 	{
515 		GError* err = null;
516 
517 		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;
518 
519 		if (err !is null)
520 		{
521 			throw new GException( new ErrorG(err) );
522 		}
523 
524 		return p;
525 	}
526 
527 	/**
528 	 * Returns the list of "additional application actions" supported on the
529 	 * desktop file, as per the desktop file specification.
530 	 *
531 	 * As per the specification, this is the list of actions that are
532 	 * explicitly listed in the "Actions" key of the [Desktop Entry] group.
533 	 *
534 	 * Returns: a list of strings, always non-%NULL
535 	 *
536 	 * Since: 2.38
537 	 */
538 	public string[] listActions()
539 	{
540 		return Str.toStringArray(g_desktop_app_info_list_actions(gDesktopAppInfo));
541 	}
542 }