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