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