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