source: appstream-generator/build/girepo/gio/DesktopAppInfo.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

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