Coverage Report

Created: 2026-10-28 06:45

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