1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Author: Alexander Larsson <alexl@redhat.com>
24 #include "gappinfoprivate.h"
25 #include "gcontextspecificgroup.h"
34 * @short_description: Application information and launch contexts
36 * @see_also: #GAppInfoMonitor
38 * #GAppInfo and #GAppLaunchContext are used for describing and launching
39 * applications installed on the system.
41 * As of GLib 2.20, URIs will always be converted to POSIX paths
42 * (using g_file_get_path()) when using g_app_info_launch() even if
43 * the application requested an URI and not a POSIX path. For example
44 * for an desktop-file based application with Exec key `totem
45 * %U` and a single URI, `sftp://foo/file.avi`, then
46 * `/home/user/.gvfs/sftp on foo/file.avi` will be passed. This will
47 * only work if a set of suitable GIO extensions (such as gvfs 2.26
48 * compiled with FUSE support), is available and operational; if this
49 * is not the case, the URI will be passed unmodified to the application.
50 * Some URIs, such as `mailto:`, of course cannot be mapped to a POSIX
51 * path (in gvfs there's no FUSE mount for it); such URIs will be
52 * passed unmodified to the application.
54 * Specifically for gvfs 2.26 and later, the POSIX URI will be mapped
55 * back to the GIO URI in the #GFile constructors (since gvfs
56 * implements the #GVfs extension point). As such, if the application
57 * needs to examine the URI, it needs to use g_file_get_uri() or
58 * similar on #GFile. In other words, an application cannot assume
59 * that the URI passed to e.g. g_file_new_for_commandline_arg() is
60 * equal to the result of g_file_get_uri(). The following snippet
67 * file = g_file_new_for_commandline_arg (uri_from_commandline);
69 * uri = g_file_get_uri (file);
70 * strcmp (uri, uri_from_commandline) == 0;
73 * if (g_file_has_uri_scheme (file, "cdda"))
75 * // do something special with uri
77 * g_object_unref (file);
80 * This code will work when both `cdda://sr0/Track 1.wav` and
81 * `/home/user/.gvfs/cdda on sr0/Track 1.wav` is passed to the
82 * application. It should be noted that it's generally not safe
83 * for applications to rely on the format of a particular URIs.
84 * Different launcher applications (e.g. file managers) may have
85 * different ideas of what a given URI means.
88 typedef GAppInfoIface GAppInfoInterface
;
89 G_DEFINE_INTERFACE (GAppInfo
, g_app_info
, G_TYPE_OBJECT
)
92 g_app_info_default_init (GAppInfoInterface
*iface
)
99 * @appinfo: a #GAppInfo.
101 * Creates a duplicate of a #GAppInfo.
103 * Returns: (transfer full): a duplicate of @appinfo.
106 g_app_info_dup (GAppInfo
*appinfo
)
108 GAppInfoIface
*iface
;
110 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), NULL
);
112 iface
= G_APP_INFO_GET_IFACE (appinfo
);
114 return (* iface
->dup
) (appinfo
);
119 * @appinfo1: the first #GAppInfo.
120 * @appinfo2: the second #GAppInfo.
122 * Checks if two #GAppInfos are equal.
124 * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise.
127 g_app_info_equal (GAppInfo
*appinfo1
,
130 GAppInfoIface
*iface
;
132 g_return_val_if_fail (G_IS_APP_INFO (appinfo1
), FALSE
);
133 g_return_val_if_fail (G_IS_APP_INFO (appinfo2
), FALSE
);
135 if (G_TYPE_FROM_INSTANCE (appinfo1
) != G_TYPE_FROM_INSTANCE (appinfo2
))
138 iface
= G_APP_INFO_GET_IFACE (appinfo1
);
140 return (* iface
->equal
) (appinfo1
, appinfo2
);
145 * @appinfo: a #GAppInfo.
147 * Gets the ID of an application. An id is a string that
148 * identifies the application. The exact format of the id is
149 * platform dependent. For instance, on Unix this is the
150 * desktop file id from the xdg menu specification.
152 * Note that the returned ID may be %NULL, depending on how
153 * the @appinfo has been constructed.
155 * Returns: a string containing the application's ID.
158 g_app_info_get_id (GAppInfo
*appinfo
)
160 GAppInfoIface
*iface
;
162 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), NULL
);
164 iface
= G_APP_INFO_GET_IFACE (appinfo
);
166 return (* iface
->get_id
) (appinfo
);
170 * g_app_info_get_name:
171 * @appinfo: a #GAppInfo.
173 * Gets the installed name of the application.
175 * Returns: the name of the application for @appinfo.
178 g_app_info_get_name (GAppInfo
*appinfo
)
180 GAppInfoIface
*iface
;
182 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), NULL
);
184 iface
= G_APP_INFO_GET_IFACE (appinfo
);
186 return (* iface
->get_name
) (appinfo
);
190 * g_app_info_get_display_name:
191 * @appinfo: a #GAppInfo.
193 * Gets the display name of the application. The display name is often more
194 * descriptive to the user than the name itself.
196 * Returns: the display name of the application for @appinfo, or the name if
197 * no display name is available.
202 g_app_info_get_display_name (GAppInfo
*appinfo
)
204 GAppInfoIface
*iface
;
206 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), NULL
);
208 iface
= G_APP_INFO_GET_IFACE (appinfo
);
210 if (iface
->get_display_name
== NULL
)
211 return (* iface
->get_name
) (appinfo
);
213 return (* iface
->get_display_name
) (appinfo
);
217 * g_app_info_get_description:
218 * @appinfo: a #GAppInfo.
220 * Gets a human-readable description of an installed application.
222 * Returns: a string containing a description of the
223 * application @appinfo, or %NULL if none.
226 g_app_info_get_description (GAppInfo
*appinfo
)
228 GAppInfoIface
*iface
;
230 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), NULL
);
232 iface
= G_APP_INFO_GET_IFACE (appinfo
);
234 return (* iface
->get_description
) (appinfo
);
238 * g_app_info_get_executable:
239 * @appinfo: a #GAppInfo
241 * Gets the executable's name for the installed application.
243 * Returns: a string containing the @appinfo's application
247 g_app_info_get_executable (GAppInfo
*appinfo
)
249 GAppInfoIface
*iface
;
251 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), NULL
);
253 iface
= G_APP_INFO_GET_IFACE (appinfo
);
255 return (* iface
->get_executable
) (appinfo
);
260 * g_app_info_get_commandline:
261 * @appinfo: a #GAppInfo
263 * Gets the commandline with which the application will be
266 * Returns: a string containing the @appinfo's commandline,
267 * or %NULL if this information is not available
272 g_app_info_get_commandline (GAppInfo
*appinfo
)
274 GAppInfoIface
*iface
;
276 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), NULL
);
278 iface
= G_APP_INFO_GET_IFACE (appinfo
);
280 if (iface
->get_commandline
)
281 return (* iface
->get_commandline
) (appinfo
);
287 * g_app_info_set_as_default_for_type:
288 * @appinfo: a #GAppInfo.
289 * @content_type: the content type.
292 * Sets the application as the default handler for a given type.
294 * Returns: %TRUE on success, %FALSE on error.
297 g_app_info_set_as_default_for_type (GAppInfo
*appinfo
,
298 const char *content_type
,
301 GAppInfoIface
*iface
;
303 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
304 g_return_val_if_fail (content_type
!= NULL
, FALSE
);
306 iface
= G_APP_INFO_GET_IFACE (appinfo
);
308 return (* iface
->set_as_default_for_type
) (appinfo
, content_type
, error
);
312 * g_app_info_set_as_last_used_for_type:
313 * @appinfo: a #GAppInfo.
314 * @content_type: the content type.
317 * Sets the application as the last used application for a given type.
318 * This will make the application appear as first in the list returned
319 * by g_app_info_get_recommended_for_type(), regardless of the default
320 * application for that content type.
322 * Returns: %TRUE on success, %FALSE on error.
325 g_app_info_set_as_last_used_for_type (GAppInfo
*appinfo
,
326 const char *content_type
,
329 GAppInfoIface
*iface
;
331 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
332 g_return_val_if_fail (content_type
!= NULL
, FALSE
);
334 iface
= G_APP_INFO_GET_IFACE (appinfo
);
336 return (* iface
->set_as_last_used_for_type
) (appinfo
, content_type
, error
);
340 * g_app_info_set_as_default_for_extension:
341 * @appinfo: a #GAppInfo.
342 * @extension: a string containing the file extension (without the dot).
345 * Sets the application as the default handler for the given file extension.
347 * Returns: %TRUE on success, %FALSE on error.
350 g_app_info_set_as_default_for_extension (GAppInfo
*appinfo
,
351 const char *extension
,
354 GAppInfoIface
*iface
;
356 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
357 g_return_val_if_fail (extension
!= NULL
, FALSE
);
359 iface
= G_APP_INFO_GET_IFACE (appinfo
);
361 if (iface
->set_as_default_for_extension
)
362 return (* iface
->set_as_default_for_extension
) (appinfo
, extension
, error
);
364 g_set_error_literal (error
, G_IO_ERROR
, G_IO_ERROR_NOT_SUPPORTED
,
365 "g_app_info_set_as_default_for_extension not supported yet");
371 * g_app_info_add_supports_type:
372 * @appinfo: a #GAppInfo.
373 * @content_type: a string.
376 * Adds a content type to the application information to indicate the
377 * application is capable of opening files with the given content type.
379 * Returns: %TRUE on success, %FALSE on error.
382 g_app_info_add_supports_type (GAppInfo
*appinfo
,
383 const char *content_type
,
386 GAppInfoIface
*iface
;
388 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
389 g_return_val_if_fail (content_type
!= NULL
, FALSE
);
391 iface
= G_APP_INFO_GET_IFACE (appinfo
);
393 if (iface
->add_supports_type
)
394 return (* iface
->add_supports_type
) (appinfo
, content_type
, error
);
396 g_set_error_literal (error
, G_IO_ERROR
,
397 G_IO_ERROR_NOT_SUPPORTED
,
398 "g_app_info_add_supports_type not supported yet");
405 * g_app_info_can_remove_supports_type:
406 * @appinfo: a #GAppInfo.
408 * Checks if a supported content type can be removed from an application.
410 * Returns: %TRUE if it is possible to remove supported
411 * content types from a given @appinfo, %FALSE if not.
414 g_app_info_can_remove_supports_type (GAppInfo
*appinfo
)
416 GAppInfoIface
*iface
;
418 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
420 iface
= G_APP_INFO_GET_IFACE (appinfo
);
422 if (iface
->can_remove_supports_type
)
423 return (* iface
->can_remove_supports_type
) (appinfo
);
430 * g_app_info_remove_supports_type:
431 * @appinfo: a #GAppInfo.
432 * @content_type: a string.
435 * Removes a supported type from an application, if possible.
437 * Returns: %TRUE on success, %FALSE on error.
440 g_app_info_remove_supports_type (GAppInfo
*appinfo
,
441 const char *content_type
,
444 GAppInfoIface
*iface
;
446 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
447 g_return_val_if_fail (content_type
!= NULL
, FALSE
);
449 iface
= G_APP_INFO_GET_IFACE (appinfo
);
451 if (iface
->remove_supports_type
)
452 return (* iface
->remove_supports_type
) (appinfo
, content_type
, error
);
454 g_set_error_literal (error
, G_IO_ERROR
,
455 G_IO_ERROR_NOT_SUPPORTED
,
456 "g_app_info_remove_supports_type not supported yet");
462 * g_app_info_get_supported_types:
463 * @appinfo: a #GAppInfo that can handle files
465 * Retrieves the list of content types that @app_info claims to support.
466 * If this information is not provided by the environment, this function
468 * This function does not take in consideration associations added with
469 * g_app_info_add_supports_type(), but only those exported directly by
472 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8):
473 * a list of content types.
478 g_app_info_get_supported_types (GAppInfo
*appinfo
)
480 GAppInfoIface
*iface
;
482 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), NULL
);
484 iface
= G_APP_INFO_GET_IFACE (appinfo
);
486 if (iface
->get_supported_types
)
487 return iface
->get_supported_types (appinfo
);
494 * g_app_info_get_icon:
495 * @appinfo: a #GAppInfo.
497 * Gets the icon for the application.
499 * Returns: (transfer none): the default #GIcon for @appinfo or %NULL
500 * if there is no default icon.
503 g_app_info_get_icon (GAppInfo
*appinfo
)
505 GAppInfoIface
*iface
;
507 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), NULL
);
509 iface
= G_APP_INFO_GET_IFACE (appinfo
);
511 return (* iface
->get_icon
) (appinfo
);
517 * @appinfo: a #GAppInfo
518 * @files: (allow-none) (element-type GFile): a #GList of #GFile objects
519 * @launch_context: (allow-none): a #GAppLaunchContext or %NULL
522 * Launches the application. Passes @files to the launched application
523 * as arguments, using the optional @launch_context to get information
524 * about the details of the launcher (like what screen it is on).
525 * On error, @error will be set accordingly.
527 * To launch the application without arguments pass a %NULL @files list.
529 * Note that even if the launch is successful the application launched
530 * can fail to start if it runs into problems during startup. There is
531 * no way to detect this.
533 * Some URIs can be changed when passed through a GFile (for instance
534 * unsupported URIs with strange formats like mailto:), so if you have
535 * a textual URI you want to pass in as argument, consider using
536 * g_app_info_launch_uris() instead.
538 * The launched application inherits the environment of the launching
539 * process, but it can be modified with g_app_launch_context_setenv()
540 * and g_app_launch_context_unsetenv().
542 * On UNIX, this function sets the `GIO_LAUNCHED_DESKTOP_FILE`
543 * environment variable with the path of the launched desktop file and
544 * `GIO_LAUNCHED_DESKTOP_FILE_PID` to the process id of the launched
545 * process. This can be used to ignore `GIO_LAUNCHED_DESKTOP_FILE`,
546 * should it be inherited by further processes. The `DISPLAY` and
547 * `DESKTOP_STARTUP_ID` environment variables are also set, based
548 * on information provided in @launch_context.
550 * Returns: %TRUE on successful launch, %FALSE otherwise.
553 g_app_info_launch (GAppInfo
*appinfo
,
555 GAppLaunchContext
*launch_context
,
558 GAppInfoIface
*iface
;
560 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
562 iface
= G_APP_INFO_GET_IFACE (appinfo
);
564 return (* iface
->launch
) (appinfo
, files
, launch_context
, error
);
569 * g_app_info_supports_uris:
570 * @appinfo: a #GAppInfo.
572 * Checks if the application supports reading files and directories from URIs.
574 * Returns: %TRUE if the @appinfo supports URIs.
577 g_app_info_supports_uris (GAppInfo
*appinfo
)
579 GAppInfoIface
*iface
;
581 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
583 iface
= G_APP_INFO_GET_IFACE (appinfo
);
585 return (* iface
->supports_uris
) (appinfo
);
590 * g_app_info_supports_files:
591 * @appinfo: a #GAppInfo.
593 * Checks if the application accepts files as arguments.
595 * Returns: %TRUE if the @appinfo supports files.
598 g_app_info_supports_files (GAppInfo
*appinfo
)
600 GAppInfoIface
*iface
;
602 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
604 iface
= G_APP_INFO_GET_IFACE (appinfo
);
606 return (* iface
->supports_files
) (appinfo
);
611 * g_app_info_launch_uris:
612 * @appinfo: a #GAppInfo
613 * @uris: (allow-none) (element-type utf8): a #GList containing URIs to launch.
614 * @launch_context: (allow-none): a #GAppLaunchContext or %NULL
617 * Launches the application. This passes the @uris to the launched application
618 * as arguments, using the optional @launch_context to get information
619 * about the details of the launcher (like what screen it is on).
620 * On error, @error will be set accordingly.
622 * To launch the application without arguments pass a %NULL @uris list.
624 * Note that even if the launch is successful the application launched
625 * can fail to start if it runs into problems during startup. There is
626 * no way to detect this.
628 * Returns: %TRUE on successful launch, %FALSE otherwise.
631 g_app_info_launch_uris (GAppInfo
*appinfo
,
633 GAppLaunchContext
*launch_context
,
636 GAppInfoIface
*iface
;
638 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
640 iface
= G_APP_INFO_GET_IFACE (appinfo
);
642 return (* iface
->launch_uris
) (appinfo
, uris
, launch_context
, error
);
647 * g_app_info_should_show:
648 * @appinfo: a #GAppInfo.
650 * Checks if the application info should be shown in menus that
651 * list available applications.
653 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
656 g_app_info_should_show (GAppInfo
*appinfo
)
658 GAppInfoIface
*iface
;
660 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
662 iface
= G_APP_INFO_GET_IFACE (appinfo
);
664 return (* iface
->should_show
) (appinfo
);
668 * g_app_info_launch_default_for_uri:
669 * @uri: the uri to show
670 * @launch_context: (allow-none): an optional #GAppLaunchContext.
673 * Utility function that launches the default application
674 * registered to handle the specified uri. Synchronous I/O
675 * is done on the uri to detect the type of the file if
678 * Returns: %TRUE on success, %FALSE on error.
681 g_app_info_launch_default_for_uri (const char *uri
,
682 GAppLaunchContext
*launch_context
,
686 GAppInfo
*app_info
= NULL
;
690 /* g_file_query_default_handler() calls
691 * g_app_info_get_default_for_uri_scheme() too, but we have to do it
692 * here anyway in case GFile can't parse @uri correctly.
694 uri_scheme
= g_uri_parse_scheme (uri
);
695 if (uri_scheme
&& uri_scheme
[0] != '\0')
696 app_info
= g_app_info_get_default_for_uri_scheme (uri_scheme
);
703 file
= g_file_new_for_uri (uri
);
704 app_info
= g_file_query_default_handler (file
, NULL
, error
);
705 g_object_unref (file
);
706 if (app_info
== NULL
)
709 /* We still use the original @uri rather than calling
710 * g_file_get_uri(), because GFile might have modified the URI
711 * in ways we don't want (eg, removing the fragment identifier
716 l
.data
= (char *)uri
;
717 l
.next
= l
.prev
= NULL
;
718 res
= g_app_info_launch_uris (app_info
, &l
,
719 launch_context
, error
);
721 g_object_unref (app_info
);
727 * g_app_info_can_delete:
728 * @appinfo: a #GAppInfo
730 * Obtains the information whether the #GAppInfo can be deleted.
731 * See g_app_info_delete().
733 * Returns: %TRUE if @appinfo can be deleted
738 g_app_info_can_delete (GAppInfo
*appinfo
)
740 GAppInfoIface
*iface
;
742 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
744 iface
= G_APP_INFO_GET_IFACE (appinfo
);
746 if (iface
->can_delete
)
747 return (* iface
->can_delete
) (appinfo
);
755 * @appinfo: a #GAppInfo
757 * Tries to delete a #GAppInfo.
759 * On some platforms, there may be a difference between user-defined
760 * #GAppInfos which can be deleted, and system-wide ones which cannot.
761 * See g_app_info_can_delete().
764 * Returns: %TRUE if @appinfo has been deleted
769 g_app_info_delete (GAppInfo
*appinfo
)
771 GAppInfoIface
*iface
;
773 g_return_val_if_fail (G_IS_APP_INFO (appinfo
), FALSE
);
775 iface
= G_APP_INFO_GET_IFACE (appinfo
);
777 if (iface
->do_delete
)
778 return (* iface
->do_delete
) (appinfo
);
790 struct _GAppLaunchContextPrivate
{
794 static guint signals
[LAST_SIGNAL
] = { 0 };
796 G_DEFINE_TYPE_WITH_PRIVATE (GAppLaunchContext
, g_app_launch_context
, G_TYPE_OBJECT
)
799 * g_app_launch_context_new:
801 * Creates a new application launch context. This is not normally used,
802 * instead you instantiate a subclass of this, such as #GdkAppLaunchContext.
804 * Returns: a #GAppLaunchContext.
807 g_app_launch_context_new (void)
809 return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT
, NULL
);
813 g_app_launch_context_finalize (GObject
*object
)
815 GAppLaunchContext
*context
= G_APP_LAUNCH_CONTEXT (object
);
817 g_strfreev (context
->priv
->envp
);
819 G_OBJECT_CLASS (g_app_launch_context_parent_class
)->finalize (object
);
823 g_app_launch_context_class_init (GAppLaunchContextClass
*klass
)
825 GObjectClass
*object_class
= G_OBJECT_CLASS (klass
);
827 object_class
->finalize
= g_app_launch_context_finalize
;
830 * GAppLaunchContext::launch-failed:
831 * @context: the object emitting the signal
832 * @startup_notify_id: the startup notification id for the failed launch
834 * The ::launch-failed signal is emitted when a #GAppInfo launch
835 * fails. The startup notification id is provided, so that the launcher
836 * can cancel the startup notification.
840 signals
[LAUNCH_FAILED
] = g_signal_new (I_("launch-failed"),
841 G_OBJECT_CLASS_TYPE (object_class
),
843 G_STRUCT_OFFSET (GAppLaunchContextClass
, launch_failed
),
845 G_TYPE_NONE
, 1, G_TYPE_STRING
);
848 * GAppLaunchContext::launched:
849 * @context: the object emitting the signal
850 * @info: the #GAppInfo that was just launched
851 * @platform_data: additional platform-specific data for this launch
853 * The ::launched signal is emitted when a #GAppInfo is successfully
854 * launched. The @platform_data is an GVariant dictionary mapping
855 * strings to variants (ie a{sv}), which contains additional,
856 * platform-specific data about this launch. On UNIX, at least the
857 * "pid" and "startup-notification-id" keys will be present.
861 signals
[LAUNCHED
] = g_signal_new (I_("launched"),
862 G_OBJECT_CLASS_TYPE (object_class
),
864 G_STRUCT_OFFSET (GAppLaunchContextClass
, launched
),
867 G_TYPE_APP_INFO
, G_TYPE_VARIANT
);
871 g_app_launch_context_init (GAppLaunchContext
*context
)
873 context
->priv
= g_app_launch_context_get_instance_private (context
);
877 * g_app_launch_context_setenv:
878 * @context: a #GAppLaunchContext
879 * @variable: the environment variable to set
880 * @value: the value for to set the variable to.
882 * Arranges for @variable to be set to @value in the child's
883 * environment when @context is used to launch an application.
888 g_app_launch_context_setenv (GAppLaunchContext
*context
,
889 const char *variable
,
892 if (!context
->priv
->envp
)
893 context
->priv
->envp
= g_get_environ ();
895 context
->priv
->envp
=
896 g_environ_setenv (context
->priv
->envp
, variable
, value
, TRUE
);
900 * g_app_launch_context_unsetenv:
901 * @context: a #GAppLaunchContext
902 * @variable: the environment variable to remove
904 * Arranges for @variable to be unset in the child's environment
905 * when @context is used to launch an application.
910 g_app_launch_context_unsetenv (GAppLaunchContext
*context
,
911 const char *variable
)
913 if (!context
->priv
->envp
)
914 context
->priv
->envp
= g_get_environ ();
916 context
->priv
->envp
=
917 g_environ_unsetenv (context
->priv
->envp
, variable
);
921 * g_app_launch_context_get_environment:
922 * @context: a #GAppLaunchContext
924 * Gets the complete environment variable list to be passed to
925 * the child process when @context is used to launch an application.
926 * This is a %NULL-terminated array of strings, where each string has
927 * the form `KEY=VALUE`.
929 * Returns: (array zero-terminated=1) (transfer full): the
930 * child's environment
935 g_app_launch_context_get_environment (GAppLaunchContext
*context
)
937 if (!context
->priv
->envp
)
938 context
->priv
->envp
= g_get_environ ();
940 return g_strdupv (context
->priv
->envp
);
944 * g_app_launch_context_get_display:
945 * @context: a #GAppLaunchContext
947 * @files: (element-type GFile): a #GList of #GFile objects
949 * Gets the display string for the @context. This is used to ensure new
950 * applications are started on the same display as the launching
951 * application, by setting the `DISPLAY` environment variable.
953 * Returns: a display string for the display.
956 g_app_launch_context_get_display (GAppLaunchContext
*context
,
960 GAppLaunchContextClass
*class;
962 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context
), NULL
);
963 g_return_val_if_fail (G_IS_APP_INFO (info
), NULL
);
965 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context
);
967 if (class->get_display
== NULL
)
970 return class->get_display (context
, info
, files
);
974 * g_app_launch_context_get_startup_notify_id:
975 * @context: a #GAppLaunchContext
977 * @files: (element-type GFile): a #GList of of #GFile objects
979 * Initiates startup notification for the application and returns the
980 * `DESKTOP_STARTUP_ID` for the launched operation, if supported.
982 * Startup notification IDs are defined in the
983 * [FreeDesktop.Org Startup Notifications standard](http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt").
985 * Returns: a startup notification ID for the application, or %NULL if
989 g_app_launch_context_get_startup_notify_id (GAppLaunchContext
*context
,
993 GAppLaunchContextClass
*class;
995 g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context
), NULL
);
996 g_return_val_if_fail (G_IS_APP_INFO (info
), NULL
);
998 class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context
);
1000 if (class->get_startup_notify_id
== NULL
)
1003 return class->get_startup_notify_id (context
, info
, files
);
1008 * g_app_launch_context_launch_failed:
1009 * @context: a #GAppLaunchContext.
1010 * @startup_notify_id: the startup notification id that was returned by g_app_launch_context_get_startup_notify_id().
1012 * Called when an application has failed to launch, so that it can cancel
1013 * the application startup notification started in g_app_launch_context_get_startup_notify_id().
1017 g_app_launch_context_launch_failed (GAppLaunchContext
*context
,
1018 const char *startup_notify_id
)
1020 g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context
));
1021 g_return_if_fail (startup_notify_id
!= NULL
);
1023 g_signal_emit (context
, signals
[LAUNCH_FAILED
], 0, startup_notify_id
);
1028 * SECTION:gappinfomonitor
1029 * @short_description: Monitor application information for changes
1031 * #GAppInfoMonitor is a very simple object used for monitoring the app
1032 * info database for changes (ie: newly installed or removed
1035 * Call g_app_info_monitor_get() to get a #GAppInfoMonitor and connect
1036 * to the "changed" signal.
1038 * In the usual case, applications should try to make note of the change
1039 * (doing things like invalidating caches) but not act on it. In
1040 * particular, applications should avoid making calls to #GAppInfo APIs
1041 * in response to the change signal, deferring these until the time that
1042 * the data is actually required. The exception to this case is when
1043 * application information is actually being displayed on the screen
1044 * (eg: during a search or when the list of all applications is shown).
1045 * The reason for this is that changes to the list of installed
1046 * applications often come in groups (like during system updates) and
1047 * rescanning the list on every change is pointless and expensive.
1055 * The only thing you can do with this is to get it via
1056 * g_app_info_monitor_get() and connect to the "changed" signal.
1061 typedef struct _GAppInfoMonitorClass GAppInfoMonitorClass
;
1063 struct _GAppInfoMonitor
1065 GObject parent_instance
;
1066 GMainContext
*context
;
1069 struct _GAppInfoMonitorClass
1071 GObjectClass parent_class
;
1074 static GContextSpecificGroup g_app_info_monitor_group
;
1075 static guint g_app_info_monitor_changed_signal
;
1077 G_DEFINE_TYPE (GAppInfoMonitor
, g_app_info_monitor
, G_TYPE_OBJECT
)
1080 g_app_info_monitor_finalize (GObject
*object
)
1082 GAppInfoMonitor
*monitor
= G_APP_INFO_MONITOR (object
);
1084 g_context_specific_group_remove (&g_app_info_monitor_group
, monitor
->context
, monitor
, NULL
);
1086 G_OBJECT_CLASS (g_app_info_monitor_parent_class
)->finalize (object
);
1090 g_app_info_monitor_init (GAppInfoMonitor
*monitor
)
1095 g_app_info_monitor_class_init (GAppInfoMonitorClass
*class)
1097 GObjectClass
*object_class
= G_OBJECT_CLASS (class);
1100 * GAppInfoMonitor::changed:
1102 * Signal emitted when the app info database for changes (ie: newly installed
1103 * or removed applications).
1105 g_app_info_monitor_changed_signal
= g_signal_new (I_("changed"), G_TYPE_APP_INFO_MONITOR
, G_SIGNAL_RUN_FIRST
,
1106 0, NULL
, NULL
, g_cclosure_marshal_VOID__VOID
, G_TYPE_NONE
, 0);
1108 object_class
->finalize
= g_app_info_monitor_finalize
;
1112 * g_app_info_monitor_get:
1114 * Gets the #GAppInfoMonitor for the current thread-default main
1117 * The #GAppInfoMonitor will emit a "changed" signal in the
1118 * thread-default main context whenever the list of installed
1119 * applications (as reported by g_app_info_get_all()) may have changed.
1121 * You must only call g_object_unref() on the return value from under
1122 * the same main context as you created it.
1124 * Returns: (transfer full): a reference to a #GAppInfoMonitor
1129 g_app_info_monitor_get (void)
1131 return g_context_specific_group_get (&g_app_info_monitor_group
,
1132 G_TYPE_APP_INFO_MONITOR
,
1133 G_STRUCT_OFFSET (GAppInfoMonitor
, context
),
1138 g_app_info_monitor_fire (void)
1140 g_context_specific_group_emit (&g_app_info_monitor_group
, g_app_info_monitor_changed_signal
);