Branch data Line data Source code
1 : : /* GIO - GLib Input, Output and Streaming Library
2 : : *
3 : : * Copyright (C) 2006-2007 Red Hat, Inc.
4 : : *
5 : : * SPDX-License-Identifier: LGPL-2.1-or-later
6 : : *
7 : : * This library is free software; you can redistribute it and/or
8 : : * modify it under the terms of the GNU Lesser General Public
9 : : * License as published by the Free Software Foundation; either
10 : : * version 2.1 of the License, or (at your option) any later version.
11 : : *
12 : : * This library is distributed in the hope that it will be useful,
13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : : * Lesser General Public License for more details.
16 : : *
17 : : * You should have received a copy of the GNU Lesser General
18 : : * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 : : *
20 : : * Author: Alexander Larsson <alexl@redhat.com>
21 : : */
22 : :
23 : : #include "config.h"
24 : :
25 : : #include "gappinfo.h"
26 : : #include "gappinfoprivate.h"
27 : : #include "gcontextspecificgroup.h"
28 : : #include "gtask.h"
29 : : #include "gcancellable.h"
30 : :
31 : : #include "glibintl.h"
32 : : #include "gmarshal-internal.h"
33 : : #include <gioerror.h>
34 : : #include <gfile.h>
35 : :
36 : : #ifdef G_OS_UNIX
37 : : #include "gdbusconnection.h"
38 : : #include "gdbusmessage.h"
39 : : #include "gportalsupport.h"
40 : : #include "gunixfdlist.h"
41 : : #include "gopenuriportal.h"
42 : : #include <sys/types.h>
43 : : #include <sys/stat.h>
44 : : #include <fcntl.h>
45 : : #endif
46 : :
47 : : /**
48 : : * GAppInfo:
49 : : *
50 : : * Information about an installed application and methods to launch
51 : : * it (with file arguments).
52 : :
53 : : * `GAppInfo` and `GAppLaunchContext` are used for describing and launching
54 : : * applications installed on the system.
55 : : *
56 : : * As of GLib 2.20, URIs will always be converted to POSIX paths
57 : : * (using [method@Gio.File.get_path]) when using [method@Gio.AppInfo.launch]
58 : : * even if the application requested an URI and not a POSIX path. For example
59 : : * for a desktop-file based application with Exec key `totem
60 : : * %U` and a single URI, `sftp://foo/file.avi`, then
61 : : * `/home/user/.gvfs/sftp on foo/file.avi` will be passed. This will
62 : : * only work if a set of suitable GIO extensions (such as GVfs 2.26
63 : : * compiled with FUSE support), is available and operational; if this
64 : : * is not the case, the URI will be passed unmodified to the application.
65 : : * Some URIs, such as `mailto:`, of course cannot be mapped to a POSIX
66 : : * path (in GVfs there's no FUSE mount for it); such URIs will be
67 : : * passed unmodified to the application.
68 : : *
69 : : * Specifically for GVfs 2.26 and later, the POSIX URI will be mapped
70 : : * back to the GIO URI in the [iface@Gio.File] constructors (since GVfs
71 : : * implements the GVfs extension point). As such, if the application
72 : : * needs to examine the URI, it needs to use [method@Gio.File.get_uri]
73 : : * or similar on [iface@Gio.File]. In other words, an application cannot
74 : : * assume that the URI passed to e.g. [func@Gio.File.new_for_commandline_arg]
75 : : * is equal to the result of [method@Gio.File.get_uri]. The following snippet
76 : : * illustrates this:
77 : : *
78 : : * ```c
79 : : * GFile *f;
80 : : * char *uri;
81 : : *
82 : : * file = g_file_new_for_commandline_arg (uri_from_commandline);
83 : : *
84 : : * uri = g_file_get_uri (file);
85 : : * strcmp (uri, uri_from_commandline) == 0;
86 : : * g_free (uri);
87 : : *
88 : : * if (g_file_has_uri_scheme (file, "cdda"))
89 : : * {
90 : : * // do something special with uri
91 : : * }
92 : : * g_object_unref (file);
93 : : * ```
94 : : *
95 : : * This code will work when both `cdda://sr0/Track 1.wav` and
96 : : * `/home/user/.gvfs/cdda on sr0/Track 1.wav` is passed to the
97 : : * application. It should be noted that it's generally not safe
98 : : * for applications to rely on the format of a particular URIs.
99 : : * Different launcher applications (e.g. file managers) may have
100 : : * different ideas of what a given URI means.
101 : : */
102 : :
103 : : struct _GAppLaunchContextPrivate {
104 : : char **envp;
105 : : };
106 : :
107 : : typedef GAppInfoIface GAppInfoInterface;
108 [ + + + - : 920 : G_DEFINE_INTERFACE (GAppInfo, g_app_info, G_TYPE_OBJECT)
+ + ]
109 : :
110 : : static void
111 : 28 : g_app_info_default_init (GAppInfoInterface *iface)
112 : : {
113 : 28 : }
114 : :
115 : :
116 : : /**
117 : : * g_app_info_dup:
118 : : * @appinfo: a #GAppInfo.
119 : : *
120 : : * Creates a duplicate of a #GAppInfo.
121 : : *
122 : : * Returns: (transfer full): a duplicate of @appinfo.
123 : : **/
124 : : GAppInfo *
125 : 1 : g_app_info_dup (GAppInfo *appinfo)
126 : : {
127 : : GAppInfoIface *iface;
128 : :
129 : 1 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
130 : :
131 : 1 : iface = G_APP_INFO_GET_IFACE (appinfo);
132 : :
133 : 1 : return (* iface->dup) (appinfo);
134 : : }
135 : :
136 : : /**
137 : : * g_app_info_equal:
138 : : * @appinfo1: the first #GAppInfo.
139 : : * @appinfo2: the second #GAppInfo.
140 : : *
141 : : * Checks if two #GAppInfos are equal.
142 : : *
143 : : * Note that the check *may not* compare each individual
144 : : * field, and only does an identity check. In case detecting changes in the
145 : : * contents is needed, program code must additionally compare relevant fields.
146 : : *
147 : : * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise.
148 : : **/
149 : : gboolean
150 : 62 : g_app_info_equal (GAppInfo *appinfo1,
151 : : GAppInfo *appinfo2)
152 : : {
153 : : GAppInfoIface *iface;
154 : :
155 : 62 : g_return_val_if_fail (G_IS_APP_INFO (appinfo1), FALSE);
156 : 62 : g_return_val_if_fail (G_IS_APP_INFO (appinfo2), FALSE);
157 : :
158 [ - + ]: 62 : if (G_TYPE_FROM_INSTANCE (appinfo1) != G_TYPE_FROM_INSTANCE (appinfo2))
159 : 0 : return FALSE;
160 : :
161 : 62 : iface = G_APP_INFO_GET_IFACE (appinfo1);
162 : :
163 : 62 : return (* iface->equal) (appinfo1, appinfo2);
164 : : }
165 : :
166 : : /**
167 : : * g_app_info_get_id:
168 : : * @appinfo: a #GAppInfo.
169 : : *
170 : : * Gets the ID of an application. An id is a string that
171 : : * identifies the application. The exact format of the id is
172 : : * platform dependent. For instance, on Unix this is the
173 : : * desktop file id from the xdg menu specification.
174 : : *
175 : : * Note that the returned ID may be %NULL, depending on how
176 : : * the @appinfo has been constructed.
177 : : *
178 : : * Returns: (nullable): a string containing the application's ID.
179 : : **/
180 : : const char *
181 : 92 : g_app_info_get_id (GAppInfo *appinfo)
182 : : {
183 : : GAppInfoIface *iface;
184 : :
185 : 92 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
186 : :
187 : 92 : iface = G_APP_INFO_GET_IFACE (appinfo);
188 : :
189 : 92 : return (* iface->get_id) (appinfo);
190 : : }
191 : :
192 : : /**
193 : : * g_app_info_get_name:
194 : : * @appinfo: a #GAppInfo.
195 : : *
196 : : * Gets the installed name of the application.
197 : : *
198 : : * Returns: the name of the application for @appinfo.
199 : : **/
200 : : const char *
201 : 9 : g_app_info_get_name (GAppInfo *appinfo)
202 : : {
203 : : GAppInfoIface *iface;
204 : :
205 : 9 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
206 : :
207 : 9 : iface = G_APP_INFO_GET_IFACE (appinfo);
208 : :
209 : 9 : return (* iface->get_name) (appinfo);
210 : : }
211 : :
212 : : /**
213 : : * g_app_info_get_display_name:
214 : : * @appinfo: a #GAppInfo.
215 : : *
216 : : * Gets the display name of the application. The display name is often more
217 : : * descriptive to the user than the name itself.
218 : : *
219 : : * Returns: the display name of the application for @appinfo, or the name if
220 : : * no display name is available.
221 : : *
222 : : * Since: 2.24
223 : : **/
224 : : const char *
225 : 10 : g_app_info_get_display_name (GAppInfo *appinfo)
226 : : {
227 : : GAppInfoIface *iface;
228 : :
229 : 10 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
230 : :
231 : 10 : iface = G_APP_INFO_GET_IFACE (appinfo);
232 : :
233 [ - + ]: 10 : if (iface->get_display_name == NULL)
234 : 0 : return (* iface->get_name) (appinfo);
235 : :
236 : 10 : return (* iface->get_display_name) (appinfo);
237 : : }
238 : :
239 : : /**
240 : : * g_app_info_get_description:
241 : : * @appinfo: a #GAppInfo.
242 : : *
243 : : * Gets a human-readable description of an installed application.
244 : : *
245 : : * Returns: (nullable): a string containing a description of the
246 : : * application @appinfo, or %NULL if none.
247 : : **/
248 : : const char *
249 : 6 : g_app_info_get_description (GAppInfo *appinfo)
250 : : {
251 : : GAppInfoIface *iface;
252 : :
253 : 6 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
254 : :
255 : 6 : iface = G_APP_INFO_GET_IFACE (appinfo);
256 : :
257 : 6 : return (* iface->get_description) (appinfo);
258 : : }
259 : :
260 : : /**
261 : : * g_app_info_get_executable: (virtual get_executable)
262 : : * @appinfo: a #GAppInfo
263 : : *
264 : : * Gets the executable's name for the installed application.
265 : : *
266 : : * This is intended to be used for debugging or labelling what program is going
267 : : * to be run. To launch the executable, use g_app_info_launch() and related
268 : : * functions, rather than spawning the return value from this function.
269 : : *
270 : : * Returns: (type filename): a string containing the @appinfo's application
271 : : * binaries name
272 : : **/
273 : : const char *
274 : 1 : g_app_info_get_executable (GAppInfo *appinfo)
275 : : {
276 : : GAppInfoIface *iface;
277 : :
278 : 1 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
279 : :
280 : 1 : iface = G_APP_INFO_GET_IFACE (appinfo);
281 : :
282 : 1 : return (* iface->get_executable) (appinfo);
283 : : }
284 : :
285 : :
286 : : /**
287 : : * g_app_info_get_commandline: (virtual get_commandline)
288 : : * @appinfo: a #GAppInfo
289 : : *
290 : : * Gets the commandline with which the application will be
291 : : * started.
292 : : *
293 : : * Returns: (nullable) (type filename): a string containing the @appinfo's commandline,
294 : : * or %NULL if this information is not available
295 : : *
296 : : * Since: 2.20
297 : : **/
298 : : const char *
299 : 10 : g_app_info_get_commandline (GAppInfo *appinfo)
300 : : {
301 : : GAppInfoIface *iface;
302 : :
303 : 10 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
304 : :
305 : 10 : iface = G_APP_INFO_GET_IFACE (appinfo);
306 : :
307 [ + - ]: 10 : if (iface->get_commandline)
308 : 10 : return (* iface->get_commandline) (appinfo);
309 : :
310 : 0 : return NULL;
311 : : }
312 : :
313 : : /**
314 : : * g_app_info_set_as_default_for_type:
315 : : * @appinfo: a #GAppInfo.
316 : : * @content_type: the content type.
317 : : * @error: a #GError.
318 : : *
319 : : * Sets the application as the default handler for a given type.
320 : : *
321 : : * Returns: %TRUE on success, %FALSE on error.
322 : : **/
323 : : gboolean
324 : 29 : g_app_info_set_as_default_for_type (GAppInfo *appinfo,
325 : : const char *content_type,
326 : : GError **error)
327 : : {
328 : : GAppInfoIface *iface;
329 : :
330 : 29 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
331 : 29 : g_return_val_if_fail (content_type != NULL, FALSE);
332 : :
333 : 29 : iface = G_APP_INFO_GET_IFACE (appinfo);
334 : :
335 [ + - ]: 29 : if (iface->set_as_default_for_type)
336 : 29 : return (* iface->set_as_default_for_type) (appinfo, content_type, error);
337 : :
338 : 0 : g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
339 : : _("Setting default applications not supported yet"));
340 : 0 : return FALSE;
341 : : }
342 : :
343 : : /**
344 : : * g_app_info_set_as_last_used_for_type:
345 : : * @appinfo: a #GAppInfo.
346 : : * @content_type: the content type.
347 : : * @error: a #GError.
348 : : *
349 : : * Sets the application as the last used application for a given type.
350 : : * This will make the application appear as first in the list returned
351 : : * by g_app_info_get_recommended_for_type(), regardless of the default
352 : : * application for that content type.
353 : : *
354 : : * Returns: %TRUE on success, %FALSE on error.
355 : : **/
356 : : gboolean
357 : 7 : g_app_info_set_as_last_used_for_type (GAppInfo *appinfo,
358 : : const char *content_type,
359 : : GError **error)
360 : : {
361 : : GAppInfoIface *iface;
362 : :
363 : 7 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
364 : 7 : g_return_val_if_fail (content_type != NULL, FALSE);
365 : :
366 : 7 : iface = G_APP_INFO_GET_IFACE (appinfo);
367 : :
368 [ + - ]: 7 : if (iface->set_as_last_used_for_type)
369 : 7 : return (* iface->set_as_last_used_for_type) (appinfo, content_type, error);
370 : :
371 : 0 : g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
372 : : _("Setting application as last used for type not supported yet"));
373 : 0 : return FALSE;
374 : : }
375 : :
376 : : /**
377 : : * g_app_info_set_as_default_for_extension:
378 : : * @appinfo: a #GAppInfo.
379 : : * @extension: (type filename): a string containing the file extension
380 : : * (without the dot).
381 : : * @error: a #GError.
382 : : *
383 : : * Sets the application as the default handler for the given file extension.
384 : : *
385 : : * Returns: %TRUE on success, %FALSE on error.
386 : : **/
387 : : gboolean
388 : 1 : g_app_info_set_as_default_for_extension (GAppInfo *appinfo,
389 : : const char *extension,
390 : : GError **error)
391 : : {
392 : : GAppInfoIface *iface;
393 : :
394 : 1 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
395 : 1 : g_return_val_if_fail (extension != NULL, FALSE);
396 : :
397 : 1 : iface = G_APP_INFO_GET_IFACE (appinfo);
398 : :
399 [ + - ]: 1 : if (iface->set_as_default_for_extension)
400 : 1 : return (* iface->set_as_default_for_extension) (appinfo, extension, error);
401 : :
402 : 0 : g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
403 : : "g_app_info_set_as_default_for_extension not supported yet");
404 : 0 : return FALSE;
405 : : }
406 : :
407 : :
408 : : /**
409 : : * g_app_info_add_supports_type:
410 : : * @appinfo: a #GAppInfo.
411 : : * @content_type: a string.
412 : : * @error: a #GError.
413 : : *
414 : : * Adds a content type to the application information to indicate the
415 : : * application is capable of opening files with the given content type.
416 : : *
417 : : * Returns: %TRUE on success, %FALSE on error.
418 : : **/
419 : : gboolean
420 : 12 : g_app_info_add_supports_type (GAppInfo *appinfo,
421 : : const char *content_type,
422 : : GError **error)
423 : : {
424 : : GAppInfoIface *iface;
425 : :
426 : 12 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
427 : 12 : g_return_val_if_fail (content_type != NULL, FALSE);
428 : :
429 : 12 : iface = G_APP_INFO_GET_IFACE (appinfo);
430 : :
431 [ + - ]: 12 : if (iface->add_supports_type)
432 : 12 : return (* iface->add_supports_type) (appinfo, content_type, error);
433 : :
434 : 0 : g_set_error_literal (error, G_IO_ERROR,
435 : : G_IO_ERROR_NOT_SUPPORTED,
436 : : "g_app_info_add_supports_type not supported yet");
437 : :
438 : 0 : return FALSE;
439 : : }
440 : :
441 : :
442 : : /**
443 : : * g_app_info_can_remove_supports_type:
444 : : * @appinfo: a #GAppInfo.
445 : : *
446 : : * Checks if a supported content type can be removed from an application.
447 : : *
448 : : * Returns: %TRUE if it is possible to remove supported
449 : : * content types from a given @appinfo, %FALSE if not.
450 : : **/
451 : : gboolean
452 : 1 : g_app_info_can_remove_supports_type (GAppInfo *appinfo)
453 : : {
454 : : GAppInfoIface *iface;
455 : :
456 : 1 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
457 : :
458 : 1 : iface = G_APP_INFO_GET_IFACE (appinfo);
459 : :
460 [ + - ]: 1 : if (iface->can_remove_supports_type)
461 : 1 : return (* iface->can_remove_supports_type) (appinfo);
462 : :
463 : 0 : return FALSE;
464 : : }
465 : :
466 : :
467 : : /**
468 : : * g_app_info_remove_supports_type:
469 : : * @appinfo: a #GAppInfo.
470 : : * @content_type: a string.
471 : : * @error: a #GError.
472 : : *
473 : : * Removes a supported type from an application, if possible.
474 : : *
475 : : * Returns: %TRUE on success, %FALSE on error.
476 : : **/
477 : : gboolean
478 : 18 : g_app_info_remove_supports_type (GAppInfo *appinfo,
479 : : const char *content_type,
480 : : GError **error)
481 : : {
482 : : GAppInfoIface *iface;
483 : :
484 : 18 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
485 : 18 : g_return_val_if_fail (content_type != NULL, FALSE);
486 : :
487 : 18 : iface = G_APP_INFO_GET_IFACE (appinfo);
488 : :
489 [ + - ]: 18 : if (iface->remove_supports_type)
490 : 18 : return (* iface->remove_supports_type) (appinfo, content_type, error);
491 : :
492 : 0 : g_set_error_literal (error, G_IO_ERROR,
493 : : G_IO_ERROR_NOT_SUPPORTED,
494 : : "g_app_info_remove_supports_type not supported yet");
495 : :
496 : 0 : return FALSE;
497 : : }
498 : :
499 : : /**
500 : : * g_app_info_get_supported_types:
501 : : * @appinfo: a #GAppInfo that can handle files
502 : : *
503 : : * Retrieves the list of content types that @app_info claims to support.
504 : : * If this information is not provided by the environment, this function
505 : : * will return %NULL.
506 : : * This function does not take in consideration associations added with
507 : : * g_app_info_add_supports_type(), but only those exported directly by
508 : : * the application.
509 : : *
510 : : * Returns: (transfer none) (array zero-terminated=1) (element-type utf8):
511 : : * a list of content types.
512 : : *
513 : : * Since: 2.34
514 : : */
515 : : const char **
516 : 1 : g_app_info_get_supported_types (GAppInfo *appinfo)
517 : : {
518 : : GAppInfoIface *iface;
519 : :
520 : 1 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
521 : :
522 : 1 : iface = G_APP_INFO_GET_IFACE (appinfo);
523 : :
524 [ + - ]: 1 : if (iface->get_supported_types)
525 : 1 : return iface->get_supported_types (appinfo);
526 : : else
527 : 0 : return NULL;
528 : : }
529 : :
530 : :
531 : : /**
532 : : * g_app_info_get_icon:
533 : : * @appinfo: a #GAppInfo.
534 : : *
535 : : * Gets the icon for the application.
536 : : *
537 : : * Returns: (nullable) (transfer none): the default #GIcon for @appinfo or %NULL
538 : : * if there is no default icon.
539 : : **/
540 : : GIcon *
541 : 1 : g_app_info_get_icon (GAppInfo *appinfo)
542 : : {
543 : : GAppInfoIface *iface;
544 : :
545 : 1 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
546 : :
547 : 1 : iface = G_APP_INFO_GET_IFACE (appinfo);
548 : :
549 : 1 : return (* iface->get_icon) (appinfo);
550 : : }
551 : :
552 : :
553 : : /**
554 : : * g_app_info_launch:
555 : : * @appinfo: a #GAppInfo
556 : : * @files: (nullable) (element-type GFile): a #GList of #GFile objects
557 : : * @context: (nullable): a #GAppLaunchContext or %NULL
558 : : * @error: a #GError
559 : : *
560 : : * Launches the application. Passes @files to the launched application
561 : : * as arguments, using the optional @context to get information
562 : : * about the details of the launcher (like what screen it is on).
563 : : * On error, @error will be set accordingly.
564 : : *
565 : : * To launch the application without arguments pass a %NULL @files list.
566 : : *
567 : : * Note that even if the launch is successful the application launched
568 : : * can fail to start if it runs into problems during startup. There is
569 : : * no way to detect this.
570 : : *
571 : : * Some URIs can be changed when passed through a GFile (for instance
572 : : * unsupported URIs with strange formats like mailto:), so if you have
573 : : * a textual URI you want to pass in as argument, consider using
574 : : * g_app_info_launch_uris() instead.
575 : : *
576 : : * The launched application inherits the environment of the launching
577 : : * process, but it can be modified with g_app_launch_context_setenv()
578 : : * and g_app_launch_context_unsetenv().
579 : : *
580 : : * On UNIX, this function sets the `GIO_LAUNCHED_DESKTOP_FILE`
581 : : * environment variable with the path of the launched desktop file and
582 : : * `GIO_LAUNCHED_DESKTOP_FILE_PID` to the process id of the launched
583 : : * process. This can be used to ignore `GIO_LAUNCHED_DESKTOP_FILE`,
584 : : * should it be inherited by further processes. The `DISPLAY`,
585 : : * `XDG_ACTIVATION_TOKEN` and `DESKTOP_STARTUP_ID` environment
586 : : * variables are also set, based on information provided in @context.
587 : : *
588 : : * Returns: %TRUE on successful launch, %FALSE otherwise.
589 : : **/
590 : : gboolean
591 : 14 : g_app_info_launch (GAppInfo *appinfo,
592 : : GList *files,
593 : : GAppLaunchContext *launch_context,
594 : : GError **error)
595 : : {
596 : : GAppInfoIface *iface;
597 : :
598 : 14 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
599 : :
600 : 14 : iface = G_APP_INFO_GET_IFACE (appinfo);
601 : :
602 : 14 : return (* iface->launch) (appinfo, files, launch_context, error);
603 : : }
604 : :
605 : :
606 : : /**
607 : : * g_app_info_supports_uris:
608 : : * @appinfo: a #GAppInfo.
609 : : *
610 : : * Checks if the application supports reading files and directories from URIs.
611 : : *
612 : : * Returns: %TRUE if the @appinfo supports URIs.
613 : : **/
614 : : gboolean
615 : 2 : g_app_info_supports_uris (GAppInfo *appinfo)
616 : : {
617 : : GAppInfoIface *iface;
618 : :
619 : 2 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
620 : :
621 : 2 : iface = G_APP_INFO_GET_IFACE (appinfo);
622 : :
623 : 2 : return (* iface->supports_uris) (appinfo);
624 : : }
625 : :
626 : :
627 : : /**
628 : : * g_app_info_supports_files:
629 : : * @appinfo: a #GAppInfo.
630 : : *
631 : : * Checks if the application accepts files as arguments.
632 : : *
633 : : * Returns: %TRUE if the @appinfo supports files.
634 : : **/
635 : : gboolean
636 : 2 : g_app_info_supports_files (GAppInfo *appinfo)
637 : : {
638 : : GAppInfoIface *iface;
639 : :
640 : 2 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
641 : :
642 : 2 : iface = G_APP_INFO_GET_IFACE (appinfo);
643 : :
644 : 2 : return (* iface->supports_files) (appinfo);
645 : : }
646 : :
647 : :
648 : : /**
649 : : * g_app_info_launch_uris:
650 : : * @appinfo: a #GAppInfo
651 : : * @uris: (nullable) (element-type utf8): a #GList containing URIs to launch.
652 : : * @context: (nullable): a #GAppLaunchContext or %NULL
653 : : * @error: a #GError
654 : : *
655 : : * Launches the application. This passes the @uris to the launched application
656 : : * as arguments, using the optional @context to get information
657 : : * about the details of the launcher (like what screen it is on).
658 : : * On error, @error will be set accordingly. If the application only supports
659 : : * one URI per invocation as part of their command-line, multiple instances
660 : : * of the application will be spawned.
661 : : *
662 : : * To launch the application without arguments pass a %NULL @uris list.
663 : : *
664 : : * Note that even if the launch is successful the application launched
665 : : * can fail to start if it runs into problems during startup. There is
666 : : * no way to detect this.
667 : : *
668 : : * Returns: %TRUE on successful launch, %FALSE otherwise.
669 : : **/
670 : : gboolean
671 : 44 : g_app_info_launch_uris (GAppInfo *appinfo,
672 : : GList *uris,
673 : : GAppLaunchContext *launch_context,
674 : : GError **error)
675 : : {
676 : : GAppInfoIface *iface;
677 : :
678 : 44 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
679 : :
680 : 44 : iface = G_APP_INFO_GET_IFACE (appinfo);
681 : :
682 : 44 : return (* iface->launch_uris) (appinfo, uris, launch_context, error);
683 : : }
684 : :
685 : : /**
686 : : * g_app_info_launch_uris_async:
687 : : * @appinfo: a #GAppInfo
688 : : * @uris: (nullable) (element-type utf8): a #GList containing URIs to launch.
689 : : * @context: (nullable): a #GAppLaunchContext or %NULL
690 : : * @cancellable: (nullable): a #GCancellable
691 : : * @callback: (nullable): a #GAsyncReadyCallback to call when the request is done
692 : : * @user_data: (nullable): data to pass to @callback
693 : : *
694 : : * Async version of g_app_info_launch_uris().
695 : : *
696 : : * The @callback is invoked immediately after the application launch, but it
697 : : * waits for activation in case of D-Bus–activated applications and also provides
698 : : * extended error information for sandboxed applications, see notes for
699 : : * g_app_info_launch_default_for_uri_async().
700 : : *
701 : : * Since: 2.60
702 : : **/
703 : : void
704 : 4 : g_app_info_launch_uris_async (GAppInfo *appinfo,
705 : : GList *uris,
706 : : GAppLaunchContext *context,
707 : : GCancellable *cancellable,
708 : : GAsyncReadyCallback callback,
709 : : gpointer user_data)
710 : : {
711 : : GAppInfoIface *iface;
712 : :
713 : 4 : g_return_if_fail (G_IS_APP_INFO (appinfo));
714 : 4 : g_return_if_fail (context == NULL || G_IS_APP_LAUNCH_CONTEXT (context));
715 : 4 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
716 : :
717 : 4 : iface = G_APP_INFO_GET_IFACE (appinfo);
718 [ - + ]: 4 : if (iface->launch_uris_async == NULL)
719 : : {
720 : : GTask *task;
721 : :
722 : 0 : task = g_task_new (appinfo, cancellable, callback, user_data);
723 [ # # ]: 0 : g_task_set_source_tag (task, g_app_info_launch_uris_async);
724 : 0 : g_task_return_new_error_literal (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
725 : : "Operation not supported for the current backend.");
726 : 0 : g_object_unref (task);
727 : :
728 : 0 : return;
729 : : }
730 : :
731 : 4 : (* iface->launch_uris_async) (appinfo, uris, context, cancellable, callback, user_data);
732 : : }
733 : :
734 : : /**
735 : : * g_app_info_launch_uris_finish:
736 : : * @appinfo: a #GAppInfo
737 : : * @result: a #GAsyncResult
738 : : * @error: (nullable): a #GError
739 : : *
740 : : * Finishes a g_app_info_launch_uris_async() operation.
741 : : *
742 : : * Returns: %TRUE on successful launch, %FALSE otherwise.
743 : : *
744 : : * Since: 2.60
745 : : */
746 : : gboolean
747 : 4 : g_app_info_launch_uris_finish (GAppInfo *appinfo,
748 : : GAsyncResult *result,
749 : : GError **error)
750 : : {
751 : : GAppInfoIface *iface;
752 : :
753 : 4 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
754 : :
755 : 4 : iface = G_APP_INFO_GET_IFACE (appinfo);
756 [ - + ]: 4 : if (iface->launch_uris_finish == NULL)
757 : : {
758 : 0 : g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
759 : : "Operation not supported for the current backend.");
760 : 0 : return FALSE;
761 : : }
762 : :
763 : 4 : return (* iface->launch_uris_finish) (appinfo, result, error);
764 : : }
765 : :
766 : : /**
767 : : * g_app_info_should_show:
768 : : * @appinfo: a #GAppInfo.
769 : : *
770 : : * Checks if the application info should be shown in menus that
771 : : * list available applications.
772 : : *
773 : : * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
774 : : **/
775 : : gboolean
776 : 14 : g_app_info_should_show (GAppInfo *appinfo)
777 : : {
778 : : GAppInfoIface *iface;
779 : :
780 : 14 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
781 : :
782 : 14 : iface = G_APP_INFO_GET_IFACE (appinfo);
783 : :
784 : 14 : return (* iface->should_show) (appinfo);
785 : : }
786 : :
787 : : typedef struct {
788 : : char *content_type;
789 : : gboolean must_support_uris;
790 : : } DefaultForTypeData;
791 : :
792 : : static void
793 : 6 : default_for_type_data_free (DefaultForTypeData *data)
794 : : {
795 : 6 : g_free (data->content_type);
796 : 6 : g_free (data);
797 : 6 : }
798 : :
799 : : static void
800 : 6 : get_default_for_type_thread (GTask *task,
801 : : gpointer object,
802 : : gpointer task_data,
803 : : GCancellable *cancellable)
804 : : {
805 : 6 : DefaultForTypeData *data = task_data;
806 : : GAppInfo *info;
807 : :
808 : 6 : info = g_app_info_get_default_for_type (data->content_type,
809 : : data->must_support_uris);
810 : :
811 [ + + ]: 6 : if (!info)
812 : : {
813 : 2 : g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
814 : 2 : _("Failed to find default application for "
815 : : "content type ‘%s’"), data->content_type);
816 : 2 : return;
817 : : }
818 : :
819 : 4 : g_task_return_pointer (task, g_steal_pointer (&info), g_object_unref);
820 : : }
821 : :
822 : : /**
823 : : * g_app_info_get_default_for_type_async:
824 : : * @content_type: the content type to find a #GAppInfo for
825 : : * @must_support_uris: if %TRUE, the #GAppInfo is expected to
826 : : * support URIs
827 : : * @cancellable: optional #GCancellable object, %NULL to ignore
828 : : * @callback: (nullable): a #GAsyncReadyCallback to call when the request is done
829 : : * @user_data: (nullable): data to pass to @callback
830 : : *
831 : : * Asynchronously gets the default #GAppInfo for a given content type.
832 : : *
833 : : * Since: 2.74
834 : : */
835 : : void
836 : 8 : g_app_info_get_default_for_type_async (const char *content_type,
837 : : gboolean must_support_uris,
838 : : GCancellable *cancellable,
839 : : GAsyncReadyCallback callback,
840 : : gpointer user_data)
841 : : {
842 : : GTask *task;
843 : : DefaultForTypeData *data;
844 : :
845 : 8 : g_return_if_fail (content_type != NULL && *content_type != '\0');
846 : 6 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
847 : :
848 : 6 : data = g_new0 (DefaultForTypeData, 1);
849 : 6 : data->content_type = g_strdup (content_type);
850 : 6 : data->must_support_uris = must_support_uris;
851 : :
852 : 6 : task = g_task_new (NULL, cancellable, callback, user_data);
853 [ + - ]: 6 : g_task_set_source_tag (task, g_app_info_get_default_for_type_async);
854 : 6 : g_task_set_task_data (task, data, (GDestroyNotify) default_for_type_data_free);
855 : 6 : g_task_set_check_cancellable (task, TRUE);
856 : 6 : g_task_run_in_thread (task, get_default_for_type_thread);
857 : 6 : g_object_unref (task);
858 : : }
859 : :
860 : : static void
861 : 14 : get_default_for_scheme_thread (GTask *task,
862 : : gpointer object,
863 : : gpointer task_data,
864 : : GCancellable *cancellable)
865 : : {
866 : 14 : const char *uri_scheme = task_data;
867 : : GAppInfo *info;
868 : :
869 : 14 : info = g_app_info_get_default_for_uri_scheme (uri_scheme);
870 : :
871 [ + + ]: 14 : if (!info)
872 : : {
873 : 8 : g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
874 : 8 : _("Failed to find default application for "
875 : : "URI Scheme ‘%s’"), uri_scheme);
876 : 8 : return;
877 : : }
878 : :
879 : 6 : g_task_return_pointer (task, g_steal_pointer (&info), g_object_unref);
880 : : }
881 : :
882 : : /**
883 : : * g_app_info_get_default_for_uri_scheme_async:
884 : : * @uri_scheme: a string containing a URI scheme.
885 : : * @cancellable: optional #GCancellable object, %NULL to ignore
886 : : * @callback: (nullable): a #GAsyncReadyCallback to call when the request is done
887 : : * @user_data: (nullable): data to pass to @callback
888 : : *
889 : : * Asynchronously gets the default application for handling URIs with
890 : : * the given URI scheme. A URI scheme is the initial part
891 : : * of the URI, up to but not including the ':', e.g. "http",
892 : : * "ftp" or "sip".
893 : : *
894 : : * Since: 2.74
895 : : */
896 : : void
897 : 14 : g_app_info_get_default_for_uri_scheme_async (const char *uri_scheme,
898 : : GCancellable *cancellable,
899 : : GAsyncReadyCallback callback,
900 : : gpointer user_data)
901 : : {
902 : : GTask *task;
903 : :
904 : 14 : g_return_if_fail (uri_scheme != NULL && *uri_scheme != '\0');
905 : 14 : g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
906 : :
907 : 14 : task = g_task_new (NULL, cancellable, callback, user_data);
908 [ + - ]: 14 : g_task_set_source_tag (task, g_app_info_get_default_for_uri_scheme_async);
909 : 14 : g_task_set_task_data (task, g_strdup (uri_scheme), g_free);
910 : 14 : g_task_set_check_cancellable (task, TRUE);
911 : 14 : g_task_run_in_thread (task, get_default_for_scheme_thread);
912 : 14 : g_object_unref (task);
913 : : }
914 : :
915 : : /**
916 : : * g_app_info_get_default_for_uri_scheme_finish:
917 : : * @result: a #GAsyncResult
918 : : * @error: (nullable): a #GError
919 : : *
920 : : * Finishes a default #GAppInfo lookup started by
921 : : * g_app_info_get_default_for_uri_scheme_async().
922 : : *
923 : : * If no #GAppInfo is found, then @error will be set to %G_IO_ERROR_NOT_FOUND.
924 : : *
925 : : * Returns: (transfer full): #GAppInfo for given @uri_scheme or
926 : : * %NULL on error.
927 : : *
928 : : * Since: 2.74
929 : : */
930 : : GAppInfo *
931 : 14 : g_app_info_get_default_for_uri_scheme_finish (GAsyncResult *result,
932 : : GError **error)
933 : : {
934 : 14 : g_return_val_if_fail (g_task_is_valid (result, NULL), NULL);
935 : 14 : g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
936 : : g_app_info_get_default_for_uri_scheme_async, NULL);
937 : 14 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
938 : :
939 : 14 : return g_task_propagate_pointer (G_TASK (result), error);
940 : : }
941 : :
942 : : /**
943 : : * g_app_info_get_default_for_type_finish:
944 : : * @result: a #GAsyncResult
945 : : * @error: (nullable): a #GError
946 : : *
947 : : * Finishes a default #GAppInfo lookup started by
948 : : * g_app_info_get_default_for_type_async().
949 : : *
950 : : * If no #GAppInfo is found, then @error will be set to %G_IO_ERROR_NOT_FOUND.
951 : : *
952 : : * Returns: (transfer full): #GAppInfo for given @content_type or
953 : : * %NULL on error.
954 : : *
955 : : * Since: 2.74
956 : : */
957 : : GAppInfo *
958 : 6 : g_app_info_get_default_for_type_finish (GAsyncResult *result,
959 : : GError **error)
960 : : {
961 : 6 : g_return_val_if_fail (g_task_is_valid (result, NULL), NULL);
962 : 6 : g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) ==
963 : : g_app_info_get_default_for_type_async, NULL);
964 : 6 : g_return_val_if_fail (error == NULL || *error == NULL, NULL);
965 : :
966 : 6 : return g_task_propagate_pointer (G_TASK (result), error);
967 : : }
968 : :
969 : : /**
970 : : * g_app_info_launch_default_for_uri:
971 : : * @uri: the uri to show
972 : : * @context: (nullable): an optional #GAppLaunchContext
973 : : * @error: (nullable): return location for an error, or %NULL
974 : : *
975 : : * Utility function that launches the default application
976 : : * registered to handle the specified uri. Synchronous I/O
977 : : * is done on the uri to detect the type of the file if
978 : : * required.
979 : : *
980 : : * The D-Bus–activated applications don't have to be started if your application
981 : : * terminates too soon after this function. To prevent this, use
982 : : * g_app_info_launch_default_for_uri_async() instead.
983 : : *
984 : : * Returns: %TRUE on success, %FALSE on error.
985 : : **/
986 : : gboolean
987 : 2 : g_app_info_launch_default_for_uri (const char *uri,
988 : : GAppLaunchContext *launch_context,
989 : : GError **error)
990 : : {
991 : : char *uri_scheme;
992 : 2 : GAppInfo *app_info = NULL;
993 : 2 : gboolean res = FALSE;
994 : :
995 : : /* g_file_query_default_handler() calls
996 : : * g_app_info_get_default_for_uri_scheme() too, but we have to do it
997 : : * here anyway in case GFile can't parse @uri correctly.
998 : : */
999 : 2 : uri_scheme = g_uri_parse_scheme (uri);
1000 [ + - + - ]: 2 : if (uri_scheme && uri_scheme[0] != '\0')
1001 : 2 : app_info = g_app_info_get_default_for_uri_scheme (uri_scheme);
1002 : 2 : g_free (uri_scheme);
1003 : :
1004 [ + + ]: 2 : if (!app_info)
1005 : : {
1006 : : GFile *file;
1007 : :
1008 : 1 : file = g_file_new_for_uri (uri);
1009 : 1 : app_info = g_file_query_default_handler (file, NULL, error);
1010 : 1 : g_object_unref (file);
1011 : : }
1012 : :
1013 [ + + ]: 2 : if (app_info)
1014 : : {
1015 : : GList l;
1016 : :
1017 : 1 : l.data = (char *)uri;
1018 : 1 : l.next = l.prev = NULL;
1019 : 1 : res = g_app_info_launch_uris (app_info, &l, launch_context, error);
1020 : 1 : g_object_unref (app_info);
1021 : : }
1022 : :
1023 : : #ifdef G_OS_UNIX
1024 [ + + - + ]: 2 : if (!res && glib_should_use_portal ())
1025 : : {
1026 : 0 : const char *parent_window = NULL;
1027 : :
1028 : : /* Reset any error previously set by launch_default_for_uri */
1029 : 0 : g_clear_error (error);
1030 : :
1031 [ # # # # ]: 0 : if (launch_context && launch_context->priv->envp)
1032 : 0 : parent_window = g_environ_getenv (launch_context->priv->envp, "PARENT_WINDOW_ID");
1033 : :
1034 : 0 : return g_openuri_portal_open_uri (uri, parent_window, error);
1035 : : }
1036 : : #endif
1037 : :
1038 : 2 : return res;
1039 : : }
1040 : :
1041 : : typedef struct
1042 : : {
1043 : : gchar *uri;
1044 : : GAppLaunchContext *context;
1045 : : } LaunchDefaultForUriData;
1046 : :
1047 : : static void
1048 : 3 : launch_default_for_uri_data_free (LaunchDefaultForUriData *data)
1049 : : {
1050 : 3 : g_free (data->uri);
1051 : 3 : g_clear_object (&data->context);
1052 : 3 : g_free (data);
1053 : 3 : }
1054 : :
1055 : : #ifdef G_OS_UNIX
1056 : : static void
1057 : 0 : launch_default_for_uri_portal_open_uri_cb (GObject *object,
1058 : : GAsyncResult *result,
1059 : : gpointer user_data)
1060 : : {
1061 : 0 : GTask *task = G_TASK (user_data);
1062 : 0 : GError *error = NULL;
1063 : :
1064 [ # # ]: 0 : if (g_openuri_portal_open_uri_finish (result, &error))
1065 : 0 : g_task_return_boolean (task, TRUE);
1066 : : else
1067 : 0 : g_task_return_error (task, g_steal_pointer (&error));
1068 : 0 : g_object_unref (task);
1069 : 0 : }
1070 : : #endif
1071 : :
1072 : : static void
1073 : 2 : launch_default_for_uri_portal_open_uri (GTask *task, GError *error)
1074 : : {
1075 : : #ifdef G_OS_UNIX
1076 : 2 : LaunchDefaultForUriData *data = g_task_get_task_data (task);
1077 : 2 : GCancellable *cancellable = g_task_get_cancellable (task);
1078 : :
1079 [ - + ]: 2 : if (glib_should_use_portal ())
1080 : : {
1081 : 0 : const char *parent_window = NULL;
1082 : :
1083 : : /* Reset any error previously set by launch_default_for_uri */
1084 : 0 : g_error_free (error);
1085 : :
1086 [ # # # # ]: 0 : if (data->context && data->context->priv->envp)
1087 : 0 : parent_window = g_environ_getenv (data->context->priv->envp,
1088 : : "PARENT_WINDOW_ID");
1089 : :
1090 : 0 : g_openuri_portal_open_uri_async (data->uri,
1091 : : parent_window,
1092 : : cancellable,
1093 : : launch_default_for_uri_portal_open_uri_cb,
1094 : : g_steal_pointer (&task));
1095 : 0 : return;
1096 : : }
1097 : : #endif
1098 : :
1099 : 2 : g_task_return_error (task, g_steal_pointer (&error));
1100 : 2 : g_object_unref (task);
1101 : : }
1102 : :
1103 : : static void
1104 : 1 : launch_default_for_uri_launch_uris_cb (GObject *object,
1105 : : GAsyncResult *result,
1106 : : gpointer user_data)
1107 : : {
1108 : 1 : GAppInfo *app_info = G_APP_INFO (object);
1109 : 1 : GTask *task = G_TASK (user_data);
1110 : 1 : GError *error = NULL;
1111 : :
1112 [ + - ]: 1 : if (g_app_info_launch_uris_finish (app_info, result, &error))
1113 : : {
1114 : 1 : g_task_return_boolean (task, TRUE);
1115 : 1 : g_object_unref (task);
1116 : : }
1117 : : else
1118 : 0 : launch_default_for_uri_portal_open_uri (g_steal_pointer (&task), g_steal_pointer (&error));
1119 : 1 : }
1120 : :
1121 : : static void
1122 : 1 : launch_default_for_uri_launch_uris (GTask *task,
1123 : : GAppInfo *app_info)
1124 : : {
1125 : 1 : GCancellable *cancellable = g_task_get_cancellable (task);
1126 : : GList l;
1127 : 1 : LaunchDefaultForUriData *data = g_task_get_task_data (task);
1128 : :
1129 : 1 : l.data = (char *)data->uri;
1130 : 1 : l.next = l.prev = NULL;
1131 : 1 : g_app_info_launch_uris_async (app_info,
1132 : : &l,
1133 : : data->context,
1134 : : cancellable,
1135 : : launch_default_for_uri_launch_uris_cb,
1136 : : g_steal_pointer (&task));
1137 : 1 : g_object_unref (app_info);
1138 : 1 : }
1139 : :
1140 : : static void
1141 : 2 : launch_default_for_uri_default_handler_cb (GObject *object,
1142 : : GAsyncResult *result,
1143 : : gpointer user_data)
1144 : : {
1145 : 2 : GFile *file = G_FILE (object);
1146 : 2 : GTask *task = G_TASK (user_data);
1147 : 2 : GAppInfo *app_info = NULL;
1148 : 2 : GError *error = NULL;
1149 : :
1150 : 2 : app_info = g_file_query_default_handler_finish (file, result, &error);
1151 [ - + ]: 2 : if (app_info)
1152 : 0 : launch_default_for_uri_launch_uris (g_steal_pointer (&task), g_steal_pointer (&app_info));
1153 : : else
1154 : 2 : launch_default_for_uri_portal_open_uri (g_steal_pointer (&task), g_steal_pointer (&error));
1155 : 2 : }
1156 : :
1157 : : static void
1158 : 2 : launch_default_app_for_default_handler (GTask *task)
1159 : : {
1160 : : GFile *file;
1161 : : GCancellable *cancellable;
1162 : : LaunchDefaultForUriData *data;
1163 : :
1164 : 2 : data = g_task_get_task_data (task);
1165 : 2 : cancellable = g_task_get_cancellable (task);
1166 : 2 : file = g_file_new_for_uri (data->uri);
1167 : :
1168 : 2 : g_file_query_default_handler_async (file,
1169 : : G_PRIORITY_DEFAULT,
1170 : : cancellable,
1171 : : launch_default_for_uri_default_handler_cb,
1172 : : g_steal_pointer (&task));
1173 : 2 : g_object_unref (file);
1174 : 2 : }
1175 : :
1176 : : static void
1177 : 3 : launch_default_app_for_uri_cb (GObject *object,
1178 : : GAsyncResult *result,
1179 : : gpointer user_data)
1180 : : {
1181 : 3 : GTask *task = G_TASK (user_data);
1182 : : GAppInfo *app_info;
1183 : :
1184 : 3 : app_info = g_app_info_get_default_for_uri_scheme_finish (result, NULL);
1185 : :
1186 [ + + ]: 3 : if (!app_info)
1187 : : {
1188 : 2 : launch_default_app_for_default_handler (g_steal_pointer (&task));
1189 : : }
1190 : : else
1191 : : {
1192 : 1 : launch_default_for_uri_launch_uris (g_steal_pointer (&task),
1193 : 1 : g_steal_pointer (&app_info));
1194 : : }
1195 : 3 : }
1196 : :
1197 : : /**
1198 : : * g_app_info_launch_default_for_uri_async:
1199 : : * @uri: the uri to show
1200 : : * @context: (nullable): an optional #GAppLaunchContext
1201 : : * @cancellable: (nullable): a #GCancellable
1202 : : * @callback: (nullable): a #GAsyncReadyCallback to call when the request is done
1203 : : * @user_data: (nullable): data to pass to @callback
1204 : : *
1205 : : * Async version of g_app_info_launch_default_for_uri().
1206 : : *
1207 : : * This version is useful if you are interested in receiving
1208 : : * error information in the case where the application is
1209 : : * sandboxed and the portal may present an application chooser
1210 : : * dialog to the user.
1211 : : *
1212 : : * This is also useful if you want to be sure that the D-Bus–activated
1213 : : * applications are really started before termination and if you are interested
1214 : : * in receiving error information from their activation.
1215 : : *
1216 : : * Since: 2.50
1217 : : */
1218 : : void
1219 : 3 : g_app_info_launch_default_for_uri_async (const char *uri,
1220 : : GAppLaunchContext *context,
1221 : : GCancellable *cancellable,
1222 : : GAsyncReadyCallback callback,
1223 : : gpointer user_data)
1224 : : {
1225 : : GTask *task;
1226 : : char *uri_scheme;
1227 : : LaunchDefaultForUriData *data;
1228 : :
1229 : 3 : g_return_if_fail (uri != NULL);
1230 : :
1231 : 3 : task = g_task_new (NULL, cancellable, callback, user_data);
1232 [ + - ]: 3 : g_task_set_source_tag (task, g_app_info_launch_default_for_uri_async);
1233 : :
1234 : 3 : data = g_new (LaunchDefaultForUriData, 1);
1235 : 3 : data->uri = g_strdup (uri);
1236 [ - + ]: 3 : data->context = (context != NULL) ? g_object_ref (context) : NULL;
1237 : 3 : g_task_set_task_data (task, g_steal_pointer (&data), (GDestroyNotify) launch_default_for_uri_data_free);
1238 : :
1239 : : /* g_file_query_default_handler_async() calls
1240 : : * g_app_info_get_default_for_uri_scheme() too, but we have to do it
1241 : : * here anyway in case GFile can't parse @uri correctly.
1242 : : */
1243 : 3 : uri_scheme = g_uri_parse_scheme (uri);
1244 [ + - + - ]: 3 : if (uri_scheme && uri_scheme[0] != '\0')
1245 : : {
1246 : 3 : g_app_info_get_default_for_uri_scheme_async (uri_scheme,
1247 : : cancellable,
1248 : : launch_default_app_for_uri_cb,
1249 : : g_steal_pointer (&task));
1250 : : }
1251 : : else
1252 : : {
1253 : 0 : launch_default_app_for_default_handler (g_steal_pointer (&task));
1254 : : }
1255 : :
1256 : 3 : g_free (uri_scheme);
1257 : : }
1258 : :
1259 : : /**
1260 : : * g_app_info_launch_default_for_uri_finish:
1261 : : * @result: a #GAsyncResult
1262 : : * @error: (nullable): return location for an error, or %NULL
1263 : : *
1264 : : * Finishes an asynchronous launch-default-for-uri operation.
1265 : : *
1266 : : * Returns: %TRUE if the launch was successful, %FALSE if @error is set
1267 : : *
1268 : : * Since: 2.50
1269 : : */
1270 : : gboolean
1271 : 3 : g_app_info_launch_default_for_uri_finish (GAsyncResult *result,
1272 : : GError **error)
1273 : : {
1274 : 3 : g_return_val_if_fail (g_task_is_valid (result, NULL), FALSE);
1275 : :
1276 : 3 : return g_task_propagate_boolean (G_TASK (result), error);
1277 : : }
1278 : :
1279 : : /**
1280 : : * g_app_info_can_delete:
1281 : : * @appinfo: a #GAppInfo
1282 : : *
1283 : : * Obtains the information whether the #GAppInfo can be deleted.
1284 : : * See g_app_info_delete().
1285 : : *
1286 : : * Returns: %TRUE if @appinfo can be deleted
1287 : : *
1288 : : * Since: 2.20
1289 : : */
1290 : : gboolean
1291 : 2 : g_app_info_can_delete (GAppInfo *appinfo)
1292 : : {
1293 : : GAppInfoIface *iface;
1294 : :
1295 : 2 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
1296 : :
1297 : 2 : iface = G_APP_INFO_GET_IFACE (appinfo);
1298 : :
1299 [ + - ]: 2 : if (iface->can_delete)
1300 : 2 : return (* iface->can_delete) (appinfo);
1301 : :
1302 : 0 : return FALSE;
1303 : : }
1304 : :
1305 : :
1306 : : /**
1307 : : * g_app_info_delete: (virtual do_delete)
1308 : : * @appinfo: a #GAppInfo
1309 : : *
1310 : : * Tries to delete a #GAppInfo.
1311 : : *
1312 : : * On some platforms, there may be a difference between user-defined
1313 : : * #GAppInfos which can be deleted, and system-wide ones which cannot.
1314 : : * See g_app_info_can_delete().
1315 : : *
1316 : : * Returns: %TRUE if @appinfo has been deleted
1317 : : *
1318 : : * Since: 2.20
1319 : : */
1320 : : gboolean
1321 : 12 : g_app_info_delete (GAppInfo *appinfo)
1322 : : {
1323 : : GAppInfoIface *iface;
1324 : :
1325 : 12 : g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
1326 : :
1327 : 12 : iface = G_APP_INFO_GET_IFACE (appinfo);
1328 : :
1329 [ + - ]: 12 : if (iface->do_delete)
1330 : 12 : return (* iface->do_delete) (appinfo);
1331 : :
1332 : 0 : return FALSE;
1333 : : }
1334 : :
1335 : :
1336 : : enum {
1337 : : LAUNCH_FAILED,
1338 : : LAUNCH_STARTED,
1339 : : LAUNCHED,
1340 : : LAST_SIGNAL
1341 : : };
1342 : :
1343 : : static guint signals[LAST_SIGNAL] = { 0 };
1344 : :
1345 [ + + + - : 207 : G_DEFINE_TYPE_WITH_PRIVATE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT)
+ + ]
1346 : :
1347 : : /**
1348 : : * g_app_launch_context_new:
1349 : : *
1350 : : * Creates a new application launch context. This is not normally used,
1351 : : * instead you instantiate a subclass of this, such as #GdkAppLaunchContext.
1352 : : *
1353 : : * Returns: a #GAppLaunchContext.
1354 : : **/
1355 : : GAppLaunchContext *
1356 : 4 : g_app_launch_context_new (void)
1357 : : {
1358 : 4 : return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
1359 : : }
1360 : :
1361 : : static void
1362 : 46 : g_app_launch_context_finalize (GObject *object)
1363 : : {
1364 : 46 : GAppLaunchContext *context = G_APP_LAUNCH_CONTEXT (object);
1365 : :
1366 : 46 : g_strfreev (context->priv->envp);
1367 : :
1368 : 46 : G_OBJECT_CLASS (g_app_launch_context_parent_class)->finalize (object);
1369 : 46 : }
1370 : :
1371 : : static void
1372 : 5 : g_app_launch_context_class_init (GAppLaunchContextClass *klass)
1373 : : {
1374 : 5 : GObjectClass *object_class = G_OBJECT_CLASS (klass);
1375 : :
1376 : 5 : object_class->finalize = g_app_launch_context_finalize;
1377 : :
1378 : : /**
1379 : : * GAppLaunchContext::launch-failed:
1380 : : * @context: the object emitting the signal
1381 : : * @startup_notify_id: the startup notification id for the failed launch
1382 : : *
1383 : : * The #GAppLaunchContext::launch-failed signal is emitted when a #GAppInfo launch
1384 : : * fails. The startup notification id is provided, so that the launcher
1385 : : * can cancel the startup notification.
1386 : : *
1387 : : * Because a launch operation may involve spawning multiple instances of the
1388 : : * target application, you should expect this signal to be emitted multiple
1389 : : * times, one for each spawned instance.
1390 : : *
1391 : : * Since: 2.36
1392 : : */
1393 : 5 : signals[LAUNCH_FAILED] = g_signal_new (I_("launch-failed"),
1394 : : G_OBJECT_CLASS_TYPE (object_class),
1395 : : G_SIGNAL_RUN_LAST,
1396 : : G_STRUCT_OFFSET (GAppLaunchContextClass, launch_failed),
1397 : : NULL, NULL, NULL,
1398 : : G_TYPE_NONE, 1, G_TYPE_STRING);
1399 : :
1400 : : /**
1401 : : * GAppLaunchContext::launch-started:
1402 : : * @context: the object emitting the signal
1403 : : * @info: the #GAppInfo that is about to be launched
1404 : : * @platform_data: (nullable): additional platform-specific data for this launch
1405 : : *
1406 : : * The #GAppLaunchContext::launch-started signal is emitted when a #GAppInfo is
1407 : : * about to be launched. If non-null the @platform_data is an
1408 : : * GVariant dictionary mapping strings to variants (ie `a{sv}`), which
1409 : : * contains additional, platform-specific data about this launch. On
1410 : : * UNIX, at least the `startup-notification-id` keys will be
1411 : : * present.
1412 : : *
1413 : : * The value of the `startup-notification-id` key (type `s`) is a startup
1414 : : * notification ID corresponding to the format from the [startup-notification
1415 : : * specification](https://specifications.freedesktop.org/startup-notification-spec/startup-notification-0.1.txt).
1416 : : * It allows tracking the progress of the launchee through startup.
1417 : : *
1418 : : * It is guaranteed that this signal is followed by either a #GAppLaunchContext::launched or
1419 : : * #GAppLaunchContext::launch-failed signal.
1420 : : *
1421 : : * Because a launch operation may involve spawning multiple instances of the
1422 : : * target application, you should expect this signal to be emitted multiple
1423 : : * times, one for each spawned instance.
1424 : : *
1425 : : * Since: 2.72
1426 : : */
1427 : 5 : signals[LAUNCH_STARTED] = g_signal_new (I_("launch-started"),
1428 : : G_OBJECT_CLASS_TYPE (object_class),
1429 : : G_SIGNAL_RUN_LAST,
1430 : : G_STRUCT_OFFSET (GAppLaunchContextClass, launch_started),
1431 : : NULL, NULL,
1432 : : _g_cclosure_marshal_VOID__OBJECT_VARIANT,
1433 : : G_TYPE_NONE, 2,
1434 : : G_TYPE_APP_INFO, G_TYPE_VARIANT);
1435 : 5 : g_signal_set_va_marshaller (signals[LAUNCH_STARTED],
1436 : : G_TYPE_FROM_CLASS (klass),
1437 : : _g_cclosure_marshal_VOID__OBJECT_VARIANTv);
1438 : :
1439 : : /**
1440 : : * GAppLaunchContext::launched:
1441 : : * @context: the object emitting the signal
1442 : : * @info: the #GAppInfo that was just launched
1443 : : * @platform_data: additional platform-specific data for this launch
1444 : : *
1445 : : * The #GAppLaunchContext::launched signal is emitted when a #GAppInfo is successfully
1446 : : * launched.
1447 : : *
1448 : : * Because a launch operation may involve spawning multiple instances of the
1449 : : * target application, you should expect this signal to be emitted multiple
1450 : : * times, one time for each spawned instance.
1451 : : *
1452 : : * The @platform_data is an GVariant dictionary mapping
1453 : : * strings to variants (ie `a{sv}`), which contains additional,
1454 : : * platform-specific data about this launch. On UNIX, at least the
1455 : : * `pid` and `startup-notification-id` keys will be present.
1456 : : *
1457 : : * Since 2.72 the `pid` may be 0 if the process id wasn't known (for
1458 : : * example if the process was launched via D-Bus). The `pid` may not be
1459 : : * set at all in subsequent releases.
1460 : : *
1461 : : * On Windows, `pid` is guaranteed to be valid only for the duration of the
1462 : : * #GAppLaunchContext::launched signal emission; after the signal is emitted,
1463 : : * GLib will call g_spawn_close_pid(). If you need to keep the #GPid after the
1464 : : * signal has been emitted, then you can duplicate `pid` using `DuplicateHandle()`.
1465 : : *
1466 : : * Since: 2.36
1467 : : */
1468 : 5 : signals[LAUNCHED] = g_signal_new (I_("launched"),
1469 : : G_OBJECT_CLASS_TYPE (object_class),
1470 : : G_SIGNAL_RUN_LAST,
1471 : : G_STRUCT_OFFSET (GAppLaunchContextClass, launched),
1472 : : NULL, NULL,
1473 : : _g_cclosure_marshal_VOID__OBJECT_VARIANT,
1474 : : G_TYPE_NONE, 2,
1475 : : G_TYPE_APP_INFO, G_TYPE_VARIANT);
1476 : 5 : g_signal_set_va_marshaller (signals[LAUNCHED],
1477 : : G_TYPE_FROM_CLASS (klass),
1478 : : _g_cclosure_marshal_VOID__OBJECT_VARIANTv);
1479 : 5 : }
1480 : :
1481 : : static void
1482 : 46 : g_app_launch_context_init (GAppLaunchContext *context)
1483 : : {
1484 : 46 : context->priv = g_app_launch_context_get_instance_private (context);
1485 : 46 : }
1486 : :
1487 : : /**
1488 : : * g_app_launch_context_setenv:
1489 : : * @context: a #GAppLaunchContext
1490 : : * @variable: (type filename): the environment variable to set
1491 : : * @value: (type filename): the value for to set the variable to.
1492 : : *
1493 : : * Arranges for @variable to be set to @value in the child's
1494 : : * environment when @context is used to launch an application.
1495 : : *
1496 : : * Since: 2.32
1497 : : */
1498 : : void
1499 : 27 : g_app_launch_context_setenv (GAppLaunchContext *context,
1500 : : const char *variable,
1501 : : const char *value)
1502 : : {
1503 : 27 : g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
1504 : 27 : g_return_if_fail (variable != NULL);
1505 : 27 : g_return_if_fail (value != NULL);
1506 : :
1507 [ + + ]: 27 : if (!context->priv->envp)
1508 : 24 : context->priv->envp = g_get_environ ();
1509 : :
1510 : 27 : context->priv->envp =
1511 : 27 : g_environ_setenv (context->priv->envp, variable, value, TRUE);
1512 : : }
1513 : :
1514 : : /**
1515 : : * g_app_launch_context_unsetenv:
1516 : : * @context: a #GAppLaunchContext
1517 : : * @variable: (type filename): the environment variable to remove
1518 : : *
1519 : : * Arranges for @variable to be unset in the child's environment
1520 : : * when @context is used to launch an application.
1521 : : *
1522 : : * Since: 2.32
1523 : : */
1524 : : void
1525 : 1 : g_app_launch_context_unsetenv (GAppLaunchContext *context,
1526 : : const char *variable)
1527 : : {
1528 : 1 : g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
1529 : 1 : g_return_if_fail (variable != NULL);
1530 : :
1531 [ - + ]: 1 : if (!context->priv->envp)
1532 : 0 : context->priv->envp = g_get_environ ();
1533 : :
1534 : 1 : context->priv->envp =
1535 : 1 : g_environ_unsetenv (context->priv->envp, variable);
1536 : : }
1537 : :
1538 : : /**
1539 : : * g_app_launch_context_get_environment:
1540 : : * @context: a #GAppLaunchContext
1541 : : *
1542 : : * Gets the complete environment variable list to be passed to
1543 : : * the child process when @context is used to launch an application.
1544 : : * This is a %NULL-terminated array of strings, where each string has
1545 : : * the form `KEY=VALUE`.
1546 : : *
1547 : : * Returns: (array zero-terminated=1) (element-type filename) (transfer full):
1548 : : * the child's environment
1549 : : *
1550 : : * Since: 2.32
1551 : : */
1552 : : char **
1553 : 44 : g_app_launch_context_get_environment (GAppLaunchContext *context)
1554 : : {
1555 : 44 : g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
1556 : :
1557 [ + + ]: 44 : if (!context->priv->envp)
1558 : 17 : context->priv->envp = g_get_environ ();
1559 : :
1560 : 44 : return g_strdupv (context->priv->envp);
1561 : : }
1562 : :
1563 : : /**
1564 : : * g_app_launch_context_get_display:
1565 : : * @context: a #GAppLaunchContext
1566 : : * @info: a #GAppInfo
1567 : : * @files: (element-type GFile): a #GList of #GFile objects
1568 : : *
1569 : : * Gets the display string for the @context. This is used to ensure new
1570 : : * applications are started on the same display as the launching
1571 : : * application, by setting the `DISPLAY` environment variable.
1572 : : *
1573 : : * Returns: (nullable): a display string for the display.
1574 : : */
1575 : : char *
1576 : 1 : g_app_launch_context_get_display (GAppLaunchContext *context,
1577 : : GAppInfo *info,
1578 : : GList *files)
1579 : : {
1580 : : GAppLaunchContextClass *class;
1581 : :
1582 : 1 : g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
1583 : 1 : g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
1584 : :
1585 : 1 : class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
1586 : :
1587 [ + - ]: 1 : if (class->get_display == NULL)
1588 : 1 : return NULL;
1589 : :
1590 : 0 : return class->get_display (context, info, files);
1591 : : }
1592 : :
1593 : : /**
1594 : : * g_app_launch_context_get_startup_notify_id:
1595 : : * @context: a #GAppLaunchContext
1596 : : * @info: a #GAppInfo
1597 : : * @files: (element-type GFile): a #GList of #GFile objects
1598 : : *
1599 : : * Initiates startup notification for the application and returns the
1600 : : * `XDG_ACTIVATION_TOKEN` or `DESKTOP_STARTUP_ID` for the launched operation,
1601 : : * if supported.
1602 : : *
1603 : : * The returned token may be referred to equivalently as an ‘activation token’
1604 : : * (using Wayland terminology) or a ‘startup sequence ID’ (using X11 terminology).
1605 : : * The two [are interoperable](https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/staging/xdg-activation/x11-interoperation.rst).
1606 : : *
1607 : : * Activation tokens are defined in the [XDG Activation Protocol](https://wayland.app/protocols/xdg-activation-v1),
1608 : : * and startup notification IDs are defined in the
1609 : : * [freedesktop.org Startup Notification Protocol](http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt).
1610 : : *
1611 : : * Support for the XDG Activation Protocol was added in GLib 2.76.
1612 : : *
1613 : : * Returns: (nullable): a startup notification ID for the application, or %NULL if
1614 : : * not supported.
1615 : : **/
1616 : : char *
1617 : 12 : g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
1618 : : GAppInfo *info,
1619 : : GList *files)
1620 : : {
1621 : : GAppLaunchContextClass *class;
1622 : :
1623 : 12 : g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
1624 : 12 : g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
1625 : :
1626 : 12 : class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
1627 : :
1628 [ + + ]: 12 : if (class->get_startup_notify_id == NULL)
1629 : 2 : return NULL;
1630 : :
1631 : 10 : return class->get_startup_notify_id (context, info, files);
1632 : : }
1633 : :
1634 : :
1635 : : /**
1636 : : * g_app_launch_context_launch_failed:
1637 : : * @context: a #GAppLaunchContext.
1638 : : * @startup_notify_id: the startup notification id that was returned by g_app_launch_context_get_startup_notify_id().
1639 : : *
1640 : : * Called when an application has failed to launch, so that it can cancel
1641 : : * the application startup notification started in g_app_launch_context_get_startup_notify_id().
1642 : : *
1643 : : **/
1644 : : void
1645 : 2 : g_app_launch_context_launch_failed (GAppLaunchContext *context,
1646 : : const char *startup_notify_id)
1647 : : {
1648 : 2 : g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
1649 : 2 : g_return_if_fail (startup_notify_id != NULL);
1650 : :
1651 : 2 : g_signal_emit (context, signals[LAUNCH_FAILED], 0, startup_notify_id);
1652 : : }
1653 : :
1654 : :
1655 : : /**
1656 : : * GAppInfoMonitor:
1657 : : *
1658 : : * `GAppInfoMonitor` monitors application information for changes.
1659 : : *
1660 : : * `GAppInfoMonitor` is a very simple object used for monitoring the app
1661 : : * info database for changes (newly installed or removed applications).
1662 : : *
1663 : : * Call [func@Gio.AppInfoMonitor.get] to get a `GAppInfoMonitor` and connect
1664 : : * to the [signal@Gio.AppInfoMonitor::changed] signal. The signal will be emitted once when
1665 : : * the app info database changes, and will not be emitted again until after the
1666 : : * next call to [func@Gio.AppInfo.get_all] or another `g_app_info_*()` function.
1667 : : * This is because monitoring the app info database for changes is expensive.
1668 : : *
1669 : : * The following functions will re-arm the [signal@Gio.AppInfoMonitor::changed]
1670 : : * signal so it can be emitted again:
1671 : : *
1672 : : * - [func@Gio.AppInfo.get_all]
1673 : : * - [func@Gio.AppInfo.get_all_for_type]
1674 : : * - [func@Gio.AppInfo.get_default_for_type]
1675 : : * - [func@Gio.AppInfo.get_fallback_for_type]
1676 : : * - [func@Gio.AppInfo.get_recommended_for_type]
1677 : : * - [`g_desktop_app_info_get_implementations()`](../gio-unix/type_func.DesktopAppInfo.get_implementation.html)
1678 : : * - [`g_desktop_app_info_new()`](../gio-unix/ctor.DesktopAppInfo.new.html)
1679 : : * - [`g_desktop_app_info_new_from_filename()`](../gio-unix/ctor.DesktopAppInfo.new_from_filename.html)
1680 : : * - [`g_desktop_app_info_new_from_keyfile()`](../gio-unix/ctor.DesktopAppInfo.new_from_keyfile.html)
1681 : : * - [`g_desktop_app_info_search()`](../gio-unix/type_func.DesktopAppInfo.search.html)
1682 : : *
1683 : : * The latter functions are available if using
1684 : : * [`GDesktopAppInfo`](../gio-unix/class.DesktopAppInfo.html) from
1685 : : * `gio-unix-2.0.pc` (GIR namespace `GioUnix-2.0`).
1686 : : *
1687 : : * In the usual case, applications should try to make note of the change
1688 : : * (doing things like invalidating caches) but not act on it. In
1689 : : * particular, applications should avoid making calls to `GAppInfo` APIs
1690 : : * in response to the change signal, deferring these until the time that
1691 : : * the updated data is actually required. The exception to this case is when
1692 : : * application information is actually being displayed on the screen
1693 : : * (for example, during a search or when the list of all applications is shown).
1694 : : * The reason for this is that changes to the list of installed applications
1695 : : * often come in groups (like during system updates) and rescanning the list
1696 : : * on every change is pointless and expensive.
1697 : : *
1698 : : * Since: 2.40
1699 : : */
1700 : :
1701 : : typedef struct _GAppInfoMonitorClass GAppInfoMonitorClass;
1702 : :
1703 : : struct _GAppInfoMonitor
1704 : : {
1705 : : GObject parent_instance;
1706 : : GMainContext *context;
1707 : : };
1708 : :
1709 : : struct _GAppInfoMonitorClass
1710 : : {
1711 : : GObjectClass parent_class;
1712 : : };
1713 : :
1714 : : static GContextSpecificGroup g_app_info_monitor_group;
1715 : : static guint g_app_info_monitor_changed_signal;
1716 : :
1717 [ + + + - : 178 : G_DEFINE_TYPE (GAppInfoMonitor, g_app_info_monitor, G_TYPE_OBJECT)
+ + ]
1718 : :
1719 : : static void
1720 : 1 : g_app_info_monitor_finalize (GObject *object)
1721 : : {
1722 : 1 : GAppInfoMonitor *monitor = G_APP_INFO_MONITOR (object);
1723 : :
1724 : 1 : g_context_specific_group_remove (&g_app_info_monitor_group, monitor->context, monitor, NULL);
1725 : :
1726 : 1 : G_OBJECT_CLASS (g_app_info_monitor_parent_class)->finalize (object);
1727 : 1 : }
1728 : :
1729 : : static void
1730 : 1 : g_app_info_monitor_init (GAppInfoMonitor *monitor)
1731 : : {
1732 : 1 : }
1733 : :
1734 : : static void
1735 : 2 : g_app_info_monitor_class_init (GAppInfoMonitorClass *class)
1736 : : {
1737 : 2 : GObjectClass *object_class = G_OBJECT_CLASS (class);
1738 : :
1739 : : /**
1740 : : * GAppInfoMonitor::changed:
1741 : : *
1742 : : * Signal emitted when the app info database changes, when applications are
1743 : : * installed or removed.
1744 : : *
1745 : : * Since: 2.40
1746 : : **/
1747 : 2 : g_app_info_monitor_changed_signal = g_signal_new (I_("changed"), G_TYPE_APP_INFO_MONITOR, G_SIGNAL_RUN_FIRST,
1748 : : 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
1749 : :
1750 : 2 : object_class->finalize = g_app_info_monitor_finalize;
1751 : 2 : }
1752 : :
1753 : : /**
1754 : : * g_app_info_monitor_get:
1755 : : *
1756 : : * Gets the #GAppInfoMonitor for the current thread-default main
1757 : : * context.
1758 : : *
1759 : : * The #GAppInfoMonitor will emit a "changed" signal in the
1760 : : * thread-default main context whenever the list of installed
1761 : : * applications (as reported by g_app_info_get_all()) may have changed.
1762 : : *
1763 : : * The #GAppInfoMonitor::changed signal will only be emitted once until
1764 : : * g_app_info_get_all() (or another `g_app_info_*()` function) is called. Doing
1765 : : * so will re-arm the signal ready to notify about the next change.
1766 : : *
1767 : : * You must only call g_object_unref() on the return value from under
1768 : : * the same main context as you created it.
1769 : : *
1770 : : * Returns: (transfer full): a reference to a #GAppInfoMonitor
1771 : : *
1772 : : * Since: 2.40
1773 : : **/
1774 : : GAppInfoMonitor *
1775 : 1 : g_app_info_monitor_get (void)
1776 : : {
1777 : 1 : return g_context_specific_group_get (&g_app_info_monitor_group,
1778 : : G_TYPE_APP_INFO_MONITOR,
1779 : : G_STRUCT_OFFSET (GAppInfoMonitor, context),
1780 : : NULL);
1781 : : }
1782 : :
1783 : : void
1784 : 312 : g_app_info_monitor_fire (void)
1785 : : {
1786 : 312 : g_context_specific_group_emit (&g_app_info_monitor_group, g_app_info_monitor_changed_signal);
1787 : 312 : }
|