Blame gio/gappinfo.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 *
Packit ae235b
 * Copyright (C) 2006-2007 Red Hat, Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: Alexander Larsson <alexl@redhat.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
Packit ae235b
#include "gappinfo.h"
Packit ae235b
#include "gappinfoprivate.h"
Packit ae235b
#include "gcontextspecificgroup.h"
Packit ae235b
#include "gtask.h"
Packit ae235b
Packit ae235b
#include "glibintl.h"
Packit ae235b
#include <gioerror.h>
Packit ae235b
#include <gfile.h>
Packit ae235b
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
#include "gdbusconnection.h"
Packit ae235b
#include "gdbusmessage.h"
Packit ae235b
#include "gportalsupport.h"
Packit ae235b
#include "gunixfdlist.h"
Packit ae235b
#include "gopenuriportal.h"
Packit ae235b
#include <sys/types.h>
Packit ae235b
#include <sys/stat.h>
Packit ae235b
#include <fcntl.h>
Packit ae235b
#endif
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gappinfo
Packit ae235b
 * @short_description: Application information and launch contexts
Packit ae235b
 * @include: gio/gio.h
Packit ae235b
 * @see_also: #GAppInfoMonitor
Packit ae235b
 * 
Packit ae235b
 * #GAppInfo and #GAppLaunchContext are used for describing and launching
Packit ae235b
 * applications installed on the system.
Packit ae235b
 *
Packit ae235b
 * As of GLib 2.20, URIs will always be converted to POSIX paths
Packit ae235b
 * (using g_file_get_path()) when using g_app_info_launch() even if
Packit ae235b
 * the application requested an URI and not a POSIX path. For example
Packit ae235b
 * for an desktop-file based application with Exec key `totem
Packit ae235b
 * %U` and a single URI, `sftp://foo/file.avi`, then
Packit ae235b
 * `/home/user/.gvfs/sftp on foo/file.avi` will be passed. This will
Packit ae235b
 * only work if a set of suitable GIO extensions (such as gvfs 2.26
Packit ae235b
 * compiled with FUSE support), is available and operational; if this
Packit ae235b
 * is not the case, the URI will be passed unmodified to the application.
Packit ae235b
 * Some URIs, such as `mailto:`, of course cannot be mapped to a POSIX
Packit ae235b
 * path (in gvfs there's no FUSE mount for it); such URIs will be
Packit ae235b
 * passed unmodified to the application.
Packit ae235b
 *
Packit ae235b
 * Specifically for gvfs 2.26 and later, the POSIX URI will be mapped
Packit ae235b
 * back to the GIO URI in the #GFile constructors (since gvfs
Packit ae235b
 * implements the #GVfs extension point). As such, if the application
Packit ae235b
 * needs to examine the URI, it needs to use g_file_get_uri() or
Packit ae235b
 * similar on #GFile. In other words, an application cannot assume
Packit ae235b
 * that the URI passed to e.g. g_file_new_for_commandline_arg() is
Packit ae235b
 * equal to the result of g_file_get_uri(). The following snippet
Packit ae235b
 * illustrates this:
Packit ae235b
 *
Packit ae235b
 * |[ 
Packit ae235b
 * GFile *f;
Packit ae235b
 * char *uri;
Packit ae235b
 *
Packit ae235b
 * file = g_file_new_for_commandline_arg (uri_from_commandline);
Packit ae235b
 *
Packit ae235b
 * uri = g_file_get_uri (file);
Packit ae235b
 * strcmp (uri, uri_from_commandline) == 0;
Packit ae235b
 * g_free (uri);
Packit ae235b
 *
Packit ae235b
 * if (g_file_has_uri_scheme (file, "cdda"))
Packit ae235b
 *   {
Packit ae235b
 *     // do something special with uri
Packit ae235b
 *   }
Packit ae235b
 * g_object_unref (file);
Packit ae235b
 * ]|
Packit ae235b
 *
Packit ae235b
 * This code will work when both `cdda://sr0/Track 1.wav` and
Packit ae235b
 * `/home/user/.gvfs/cdda on sr0/Track 1.wav` is passed to the
Packit ae235b
 * application. It should be noted that it's generally not safe
Packit ae235b
 * for applications to rely on the format of a particular URIs.
Packit ae235b
 * Different launcher applications (e.g. file managers) may have
Packit ae235b
 * different ideas of what a given URI means.
Packit ae235b
 */
Packit ae235b
Packit ae235b
struct _GAppLaunchContextPrivate {
Packit ae235b
  char **envp;
Packit ae235b
};
Packit ae235b
Packit ae235b
typedef GAppInfoIface GAppInfoInterface;
Packit ae235b
G_DEFINE_INTERFACE (GAppInfo, g_app_info, G_TYPE_OBJECT)
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_app_info_default_init (GAppInfoInterface *iface)
Packit ae235b
{
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_dup:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * 
Packit ae235b
 * Creates a duplicate of a #GAppInfo.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): a duplicate of @appinfo.
Packit ae235b
 **/
Packit ae235b
GAppInfo *
Packit ae235b
g_app_info_dup (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->dup) (appinfo);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_equal:
Packit ae235b
 * @appinfo1: the first #GAppInfo.
Packit ae235b
 * @appinfo2: the second #GAppInfo.
Packit ae235b
 *
Packit ae235b
 * Checks if two #GAppInfos are equal.
Packit ae235b
 *
Packit ae235b
 * Note that the check <emphasis>may not</emphasis> compare each individual
Packit ae235b
 * field, and only does an identity check. In case detecting changes in the 
Packit ae235b
 * contents is needed, program code must additionally compare relevant fields.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_equal (GAppInfo *appinfo1,
Packit ae235b
		  GAppInfo *appinfo2)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo1), FALSE);
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo2), FALSE);
Packit ae235b
Packit ae235b
  if (G_TYPE_FROM_INSTANCE (appinfo1) != G_TYPE_FROM_INSTANCE (appinfo2))
Packit ae235b
    return FALSE;
Packit ae235b
  
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo1);
Packit ae235b
Packit ae235b
  return (* iface->equal) (appinfo1, appinfo2);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_get_id:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * 
Packit ae235b
 * Gets the ID of an application. An id is a string that
Packit ae235b
 * identifies the application. The exact format of the id is
Packit ae235b
 * platform dependent. For instance, on Unix this is the
Packit ae235b
 * desktop file id from the xdg menu specification.
Packit ae235b
 *
Packit ae235b
 * Note that the returned ID may be %NULL, depending on how
Packit ae235b
 * the @appinfo has been constructed.
Packit ae235b
 *
Packit ae235b
 * Returns: a string containing the application's ID.
Packit ae235b
 **/
Packit ae235b
const char *
Packit ae235b
g_app_info_get_id (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->get_id) (appinfo);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_get_name:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * 
Packit ae235b
 * Gets the installed name of the application. 
Packit ae235b
 *
Packit ae235b
 * Returns: the name of the application for @appinfo.
Packit ae235b
 **/
Packit ae235b
const char *
Packit ae235b
g_app_info_get_name (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->get_name) (appinfo);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_get_display_name:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 *
Packit ae235b
 * Gets the display name of the application. The display name is often more
Packit ae235b
 * descriptive to the user than the name itself.
Packit ae235b
 *
Packit ae235b
 * Returns: the display name of the application for @appinfo, or the name if
Packit ae235b
 * no display name is available.
Packit ae235b
 *
Packit ae235b
 * Since: 2.24
Packit ae235b
 **/
Packit ae235b
const char *
Packit ae235b
g_app_info_get_display_name (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  if (iface->get_display_name == NULL)
Packit ae235b
    return (* iface->get_name) (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->get_display_name) (appinfo);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_get_description:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * 
Packit ae235b
 * Gets a human-readable description of an installed application.
Packit ae235b
 *
Packit ae235b
 * Returns: a string containing a description of the 
Packit ae235b
 * application @appinfo, or %NULL if none. 
Packit ae235b
 **/
Packit ae235b
const char *
Packit ae235b
g_app_info_get_description (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->get_description) (appinfo);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_get_executable:
Packit ae235b
 * @appinfo: a #GAppInfo
Packit ae235b
 * 
Packit ae235b
 * Gets the executable's name for the installed application.
Packit ae235b
 *
Packit ae235b
 * Returns: (type filename): a string containing the @appinfo's application
Packit ae235b
 * binaries name
Packit ae235b
 **/
Packit ae235b
const char *
Packit ae235b
g_app_info_get_executable (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->get_executable) (appinfo);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_get_commandline:
Packit ae235b
 * @appinfo: a #GAppInfo
Packit ae235b
 * 
Packit ae235b
 * Gets the commandline with which the application will be
Packit ae235b
 * started.  
Packit ae235b
 *
Packit ae235b
 * Returns: (type filename): a string containing the @appinfo's commandline,
Packit ae235b
 *     or %NULL if this information is not available
Packit ae235b
 *
Packit ae235b
 * Since: 2.20
Packit ae235b
 **/
Packit ae235b
const char *
Packit ae235b
g_app_info_get_commandline (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  if (iface->get_commandline)
Packit ae235b
    return (* iface->get_commandline) (appinfo);
Packit ae235b
 
Packit ae235b
  return NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_set_as_default_for_type:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * @content_type: the content type.
Packit ae235b
 * @error: a #GError.
Packit ae235b
 * 
Packit ae235b
 * Sets the application as the default handler for a given type.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on success, %FALSE on error.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_set_as_default_for_type (GAppInfo    *appinfo,
Packit ae235b
				    const char  *content_type,
Packit ae235b
				    GError     **error)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
  g_return_val_if_fail (content_type != NULL, FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->set_as_default_for_type) (appinfo, content_type, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_set_as_last_used_for_type:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * @content_type: the content type.
Packit ae235b
 * @error: a #GError.
Packit ae235b
 *
Packit ae235b
 * Sets the application as the last used application for a given type.
Packit ae235b
 * This will make the application appear as first in the list returned
Packit ae235b
 * by g_app_info_get_recommended_for_type(), regardless of the default
Packit ae235b
 * application for that content type.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on success, %FALSE on error.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_set_as_last_used_for_type (GAppInfo    *appinfo,
Packit ae235b
                                      const char  *content_type,
Packit ae235b
                                      GError     **error)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
  g_return_val_if_fail (content_type != NULL, FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->set_as_last_used_for_type) (appinfo, content_type, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_set_as_default_for_extension:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * @extension: (type filename): a string containing the file extension
Packit ae235b
 *     (without the dot).
Packit ae235b
 * @error: a #GError.
Packit ae235b
 * 
Packit ae235b
 * Sets the application as the default handler for the given file extension.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on success, %FALSE on error.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_set_as_default_for_extension (GAppInfo    *appinfo,
Packit ae235b
					 const char  *extension,
Packit ae235b
					 GError     **error)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
  g_return_val_if_fail (extension != NULL, FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  if (iface->set_as_default_for_extension)
Packit ae235b
    return (* iface->set_as_default_for_extension) (appinfo, extension, error);
Packit ae235b
Packit ae235b
  g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
Packit ae235b
                       "g_app_info_set_as_default_for_extension not supported yet");
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_add_supports_type:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * @content_type: a string.
Packit ae235b
 * @error: a #GError.
Packit ae235b
 * 
Packit ae235b
 * Adds a content type to the application information to indicate the 
Packit ae235b
 * application is capable of opening files with the given content type.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on success, %FALSE on error.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_add_supports_type (GAppInfo    *appinfo,
Packit ae235b
			      const char  *content_type,
Packit ae235b
			      GError     **error)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
  g_return_val_if_fail (content_type != NULL, FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  if (iface->add_supports_type)
Packit ae235b
    return (* iface->add_supports_type) (appinfo, content_type, error);
Packit ae235b
Packit ae235b
  g_set_error_literal (error, G_IO_ERROR, 
Packit ae235b
                       G_IO_ERROR_NOT_SUPPORTED, 
Packit ae235b
                       "g_app_info_add_supports_type not supported yet");
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_can_remove_supports_type:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * 
Packit ae235b
 * Checks if a supported content type can be removed from an application.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if it is possible to remove supported 
Packit ae235b
 *     content types from a given @appinfo, %FALSE if not.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_can_remove_supports_type (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  if (iface->can_remove_supports_type)
Packit ae235b
    return (* iface->can_remove_supports_type) (appinfo);
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_remove_supports_type:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * @content_type: a string.
Packit ae235b
 * @error: a #GError.
Packit ae235b
 *
Packit ae235b
 * Removes a supported type from an application, if possible.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE on success, %FALSE on error.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_remove_supports_type (GAppInfo    *appinfo,
Packit ae235b
				 const char  *content_type,
Packit ae235b
				 GError     **error)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
  g_return_val_if_fail (content_type != NULL, FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  if (iface->remove_supports_type)
Packit ae235b
    return (* iface->remove_supports_type) (appinfo, content_type, error);
Packit ae235b
Packit ae235b
  g_set_error_literal (error, G_IO_ERROR, 
Packit ae235b
                       G_IO_ERROR_NOT_SUPPORTED, 
Packit ae235b
                       "g_app_info_remove_supports_type not supported yet");
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_get_supported_types:
Packit ae235b
 * @appinfo: a #GAppInfo that can handle files
Packit ae235b
 *
Packit ae235b
 * Retrieves the list of content types that @app_info claims to support.
Packit ae235b
 * If this information is not provided by the environment, this function
Packit ae235b
 * will return %NULL.
Packit ae235b
 * This function does not take in consideration associations added with
Packit ae235b
 * g_app_info_add_supports_type(), but only those exported directly by
Packit ae235b
 * the application.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none) (array zero-terminated=1) (element-type utf8):
Packit ae235b
 *    a list of content types.
Packit ae235b
 *
Packit ae235b
 * Since: 2.34
Packit ae235b
 */
Packit ae235b
const char **
Packit ae235b
g_app_info_get_supported_types (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  if (iface->get_supported_types)
Packit ae235b
    return iface->get_supported_types (appinfo);
Packit ae235b
  else
Packit ae235b
    return NULL;
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_get_icon:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * 
Packit ae235b
 * Gets the icon for the application.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer none): the default #GIcon for @appinfo or %NULL
Packit ae235b
 * if there is no default icon.
Packit ae235b
 **/
Packit ae235b
GIcon *
Packit ae235b
g_app_info_get_icon (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), NULL);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->get_icon) (appinfo);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_launch:
Packit ae235b
 * @appinfo: a #GAppInfo
Packit ae235b
 * @files: (nullable) (element-type GFile): a #GList of #GFile objects
Packit ae235b
 * @context: (nullable): a #GAppLaunchContext or %NULL
Packit ae235b
 * @error: a #GError
Packit ae235b
 * 
Packit ae235b
 * Launches the application. Passes @files to the launched application
Packit ae235b
 * as arguments, using the optional @context to get information
Packit ae235b
 * about the details of the launcher (like what screen it is on).
Packit ae235b
 * On error, @error will be set accordingly.
Packit ae235b
 *
Packit ae235b
 * To launch the application without arguments pass a %NULL @files list.
Packit ae235b
 *
Packit ae235b
 * Note that even if the launch is successful the application launched
Packit ae235b
 * can fail to start if it runs into problems during startup. There is
Packit ae235b
 * no way to detect this.
Packit ae235b
 *
Packit ae235b
 * Some URIs can be changed when passed through a GFile (for instance
Packit ae235b
 * unsupported URIs with strange formats like mailto:), so if you have
Packit ae235b
 * a textual URI you want to pass in as argument, consider using
Packit ae235b
 * g_app_info_launch_uris() instead.
Packit ae235b
 *
Packit ae235b
 * The launched application inherits the environment of the launching
Packit ae235b
 * process, but it can be modified with g_app_launch_context_setenv()
Packit ae235b
 * and g_app_launch_context_unsetenv().
Packit ae235b
 *
Packit ae235b
 * On UNIX, this function sets the `GIO_LAUNCHED_DESKTOP_FILE`
Packit ae235b
 * environment variable with the path of the launched desktop file and
Packit ae235b
 * `GIO_LAUNCHED_DESKTOP_FILE_PID` to the process id of the launched
Packit ae235b
 * process. This can be used to ignore `GIO_LAUNCHED_DESKTOP_FILE`,
Packit ae235b
 * should it be inherited by further processes. The `DISPLAY` and
Packit ae235b
 * `DESKTOP_STARTUP_ID` environment variables are also set, based
Packit ae235b
 * on information provided in @context.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on successful launch, %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_launch (GAppInfo           *appinfo,
Packit ae235b
		   GList              *files,
Packit ae235b
		   GAppLaunchContext  *launch_context,
Packit ae235b
		   GError            **error)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->launch) (appinfo, files, launch_context, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_supports_uris:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * 
Packit ae235b
 * Checks if the application supports reading files and directories from URIs.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the @appinfo supports URIs.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_supports_uris (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->supports_uris) (appinfo);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_supports_files:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 * 
Packit ae235b
 * Checks if the application accepts files as arguments.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the @appinfo supports files.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_supports_files (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->supports_files) (appinfo);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_launch_uris:
Packit ae235b
 * @appinfo: a #GAppInfo
Packit ae235b
 * @uris: (nullable) (element-type utf8): a #GList containing URIs to launch.
Packit ae235b
 * @context: (nullable): a #GAppLaunchContext or %NULL
Packit ae235b
 * @error: a #GError
Packit ae235b
 * 
Packit ae235b
 * Launches the application. This passes the @uris to the launched application
Packit ae235b
 * as arguments, using the optional @context to get information
Packit ae235b
 * about the details of the launcher (like what screen it is on).
Packit ae235b
 * On error, @error will be set accordingly.
Packit ae235b
 *
Packit ae235b
 * To launch the application without arguments pass a %NULL @uris list.
Packit ae235b
 *
Packit ae235b
 * Note that even if the launch is successful the application launched
Packit ae235b
 * can fail to start if it runs into problems during startup. There is
Packit ae235b
 * no way to detect this.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE on successful launch, %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_launch_uris (GAppInfo           *appinfo,
Packit ae235b
			GList              *uris,
Packit ae235b
			GAppLaunchContext  *launch_context,
Packit ae235b
			GError            **error)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->launch_uris) (appinfo, uris, launch_context, error);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_should_show:
Packit ae235b
 * @appinfo: a #GAppInfo.
Packit ae235b
 *
Packit ae235b
 * Checks if the application info should be shown in menus that 
Packit ae235b
 * list available applications.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_should_show (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  return (* iface->should_show) (appinfo);
Packit ae235b
}
Packit ae235b
Packit ae235b
static gboolean
Packit ae235b
launch_default_for_uri (const char         *uri,
Packit ae235b
                        GAppLaunchContext  *context,
Packit ae235b
                        GError            **error)
Packit ae235b
{
Packit ae235b
  char *uri_scheme;
Packit ae235b
  GAppInfo *app_info = NULL;
Packit ae235b
  GList l;
Packit ae235b
  gboolean res;
Packit ae235b
Packit ae235b
  /* g_file_query_default_handler() calls
Packit ae235b
   * g_app_info_get_default_for_uri_scheme() too, but we have to do it
Packit ae235b
   * here anyway in case GFile can't parse @uri correctly.
Packit ae235b
   */
Packit ae235b
  uri_scheme = g_uri_parse_scheme (uri);
Packit ae235b
  if (uri_scheme && uri_scheme[0] != '\0')
Packit ae235b
    app_info = g_app_info_get_default_for_uri_scheme (uri_scheme);
Packit ae235b
  g_free (uri_scheme);
Packit ae235b
Packit ae235b
  if (!app_info)
Packit ae235b
    {
Packit ae235b
      GFile *file;
Packit ae235b
Packit ae235b
      file = g_file_new_for_uri (uri);
Packit ae235b
      app_info = g_file_query_default_handler (file, NULL, error);
Packit ae235b
      g_object_unref (file);
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (app_info == NULL)
Packit ae235b
    return FALSE;
Packit ae235b
Packit ae235b
  l.data = (char *)uri;
Packit ae235b
  l.next = l.prev = NULL;
Packit ae235b
  res = g_app_info_launch_uris (app_info, &l, context, error);
Packit ae235b
Packit ae235b
  g_object_unref (app_info);
Packit ae235b
Packit ae235b
  return res;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_launch_default_for_uri:
Packit ae235b
 * @uri: the uri to show
Packit ae235b
 * @context: (nullable): an optional #GAppLaunchContext
Packit ae235b
 * @error: (nullable): return location for an error, or %NULL
Packit ae235b
 *
Packit ae235b
 * Utility function that launches the default application
Packit ae235b
 * registered to handle the specified uri. Synchronous I/O
Packit ae235b
 * is done on the uri to detect the type of the file if
Packit ae235b
 * required.
Packit ae235b
 * 
Packit ae235b
 * Returns: %TRUE on success, %FALSE on error.
Packit ae235b
 **/
Packit ae235b
gboolean
Packit ae235b
g_app_info_launch_default_for_uri (const char         *uri,
Packit ae235b
				   GAppLaunchContext  *launch_context,
Packit ae235b
				   GError            **error)
Packit ae235b
{
Packit ae235b
  if (launch_default_for_uri (uri, launch_context, error))
Packit ae235b
    return TRUE;
Packit ae235b
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  if (glib_should_use_portal ())
Packit ae235b
    {
Packit ae235b
      const char *parent_window = NULL;
Packit ae235b
Packit ae235b
      /* Reset any error previously set by launch_default_for_uri */
Packit ae235b
      g_clear_error (error);
Packit ae235b
Packit ae235b
      if (launch_context && launch_context->priv->envp)
Packit ae235b
        parent_window = g_environ_getenv (launch_context->priv->envp, "PARENT_WINDOW_ID");
Packit ae235b
Packit ae235b
      return g_openuri_portal_open_uri (uri, parent_window, error);
Packit ae235b
Packit ae235b
    }
Packit ae235b
#endif
Packit ae235b
Packit ae235b
  return FALSE;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_launch_default_for_uri_async:
Packit ae235b
 * @uri: the uri to show
Packit ae235b
 * @context: (nullable): an optional #GAppLaunchContext
Packit ae235b
 * @cancellable: (nullable): a #GCancellable
Packit ae235b
 * @callback: (nullable): a #GASyncReadyCallback to call when the request is done
Packit ae235b
 * @user_data: (nullable): data to pass to @callback
Packit ae235b
 *
Packit ae235b
 * Async version of g_app_info_launch_default_for_uri().
Packit ae235b
 *
Packit ae235b
 * This version is useful if you are interested in receiving
Packit ae235b
 * error information in the case where the application is
Packit ae235b
 * sandboxed and the portal may present an application chooser
Packit ae235b
 * dialog to the user.
Packit ae235b
 *
Packit ae235b
 * Since: 2.50
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_app_info_launch_default_for_uri_async (const char          *uri,
Packit ae235b
                                         GAppLaunchContext   *context,
Packit ae235b
                                         GCancellable        *cancellable,
Packit ae235b
                                         GAsyncReadyCallback  callback,
Packit ae235b
                                         gpointer             user_data)
Packit ae235b
{
Packit ae235b
  gboolean res;
Packit ae235b
  GError *error = NULL;
Packit ae235b
  GTask *task;
Packit ae235b
Packit ae235b
  res = launch_default_for_uri (uri, context, &error);
Packit ae235b
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  if (!res && glib_should_use_portal ())
Packit ae235b
    {
Packit ae235b
      const  char *parent_window = NULL;
Packit ae235b
Packit ae235b
      if (context && context->priv->envp)
Packit ae235b
        parent_window = g_environ_getenv (context->priv->envp, "PARENT_WINDOW_ID");
Packit ae235b
Packit ae235b
      g_openuri_portal_open_uri_async (uri, parent_window, cancellable, callback, user_data);
Packit ae235b
      return;
Packit ae235b
    }
Packit ae235b
#endif
Packit ae235b
Packit ae235b
  task = g_task_new (context, cancellable, callback, user_data);
Packit ae235b
  if (!res)
Packit ae235b
    g_task_return_error (task, error);
Packit ae235b
  else
Packit ae235b
    g_task_return_boolean (task, TRUE);
Packit ae235b
Packit ae235b
  g_object_unref (task);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_launch_default_for_uri_finish:
Packit ae235b
 * @result: a #GAsyncResult
Packit ae235b
 * @error: (nullable): return location for an error, or %NULL
Packit ae235b
 *
Packit ae235b
 * Finishes an asynchronous launch-default-for-uri operation.
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if the launch was successful, %FALSE if @error is set
Packit ae235b
 *
Packit ae235b
 * Since: 2.50
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_app_info_launch_default_for_uri_finish (GAsyncResult  *result,
Packit ae235b
                                          GError       **error)
Packit ae235b
{
Packit ae235b
#ifdef G_OS_UNIX
Packit ae235b
  return g_openuri_portal_open_uri_finish (result, error);
Packit ae235b
#else
Packit ae235b
  return g_task_propagate_boolean (G_TASK (result), error);
Packit ae235b
#endif
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_can_delete:
Packit ae235b
 * @appinfo: a #GAppInfo
Packit ae235b
 *
Packit ae235b
 * Obtains the information whether the #GAppInfo can be deleted.
Packit ae235b
 * See g_app_info_delete().
Packit ae235b
 *
Packit ae235b
 * Returns: %TRUE if @appinfo can be deleted
Packit ae235b
 *
Packit ae235b
 * Since: 2.20
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_app_info_can_delete (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  if (iface->can_delete)
Packit ae235b
    return (* iface->can_delete) (appinfo);
Packit ae235b
 
Packit ae235b
  return FALSE; 
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_delete:
Packit ae235b
 * @appinfo: a #GAppInfo
Packit ae235b
 *
Packit ae235b
 * Tries to delete a #GAppInfo.
Packit ae235b
 *
Packit ae235b
 * On some platforms, there may be a difference between user-defined
Packit ae235b
 * #GAppInfos which can be deleted, and system-wide ones which cannot.
Packit ae235b
 * See g_app_info_can_delete().
Packit ae235b
 *
Packit ae235b
 * Virtual: do_delete
Packit ae235b
 * Returns: %TRUE if @appinfo has been deleted
Packit ae235b
 *
Packit ae235b
 * Since: 2.20
Packit ae235b
 */
Packit ae235b
gboolean
Packit ae235b
g_app_info_delete (GAppInfo *appinfo)
Packit ae235b
{
Packit ae235b
  GAppInfoIface *iface;
Packit ae235b
  
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (appinfo), FALSE);
Packit ae235b
Packit ae235b
  iface = G_APP_INFO_GET_IFACE (appinfo);
Packit ae235b
Packit ae235b
  if (iface->do_delete)
Packit ae235b
    return (* iface->do_delete) (appinfo);
Packit ae235b
 
Packit ae235b
  return FALSE; 
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
enum {
Packit ae235b
  LAUNCH_FAILED,
Packit ae235b
  LAUNCHED,
Packit ae235b
  LAST_SIGNAL
Packit ae235b
};
Packit ae235b
Packit ae235b
static guint signals[LAST_SIGNAL] = { 0 };
Packit ae235b
Packit ae235b
G_DEFINE_TYPE_WITH_PRIVATE (GAppLaunchContext, g_app_launch_context, G_TYPE_OBJECT)
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_launch_context_new:
Packit ae235b
 * 
Packit ae235b
 * Creates a new application launch context. This is not normally used,
Packit ae235b
 * instead you instantiate a subclass of this, such as #GdkAppLaunchContext.
Packit ae235b
 *
Packit ae235b
 * Returns: a #GAppLaunchContext.
Packit ae235b
 **/
Packit ae235b
GAppLaunchContext *
Packit ae235b
g_app_launch_context_new (void)
Packit ae235b
{
Packit ae235b
  return g_object_new (G_TYPE_APP_LAUNCH_CONTEXT, NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_app_launch_context_finalize (GObject *object)
Packit ae235b
{
Packit ae235b
  GAppLaunchContext *context = G_APP_LAUNCH_CONTEXT (object);
Packit ae235b
Packit ae235b
  g_strfreev (context->priv->envp);
Packit ae235b
Packit ae235b
  G_OBJECT_CLASS (g_app_launch_context_parent_class)->finalize (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_app_launch_context_class_init (GAppLaunchContextClass *klass)
Packit ae235b
{
Packit ae235b
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
Packit ae235b
Packit ae235b
  object_class->finalize = g_app_launch_context_finalize;
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GAppLaunchContext::launch-failed:
Packit ae235b
   * @context: the object emitting the signal
Packit ae235b
   * @startup_notify_id: the startup notification id for the failed launch
Packit ae235b
   *
Packit ae235b
   * The ::launch-failed signal is emitted when a #GAppInfo launch
Packit ae235b
   * fails. The startup notification id is provided, so that the launcher
Packit ae235b
   * can cancel the startup notification.
Packit ae235b
   *
Packit ae235b
   * Since: 2.36
Packit ae235b
   */
Packit ae235b
  signals[LAUNCH_FAILED] = g_signal_new (I_("launch-failed"),
Packit ae235b
                                         G_OBJECT_CLASS_TYPE (object_class),
Packit ae235b
                                         G_SIGNAL_RUN_LAST,
Packit ae235b
                                         G_STRUCT_OFFSET (GAppLaunchContextClass, launch_failed),
Packit ae235b
                                         NULL, NULL, NULL,
Packit ae235b
                                         G_TYPE_NONE, 1, G_TYPE_STRING);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GAppLaunchContext::launched:
Packit ae235b
   * @context: the object emitting the signal
Packit ae235b
   * @info: the #GAppInfo that was just launched
Packit ae235b
   * @platform_data: additional platform-specific data for this launch
Packit ae235b
   *
Packit ae235b
   * The ::launched signal is emitted when a #GAppInfo is successfully
Packit ae235b
   * launched. The @platform_data is an GVariant dictionary mapping
Packit ae235b
   * strings to variants (ie a{sv}), which contains additional,
Packit ae235b
   * platform-specific data about this launch. On UNIX, at least the
Packit ae235b
   * "pid" and "startup-notification-id" keys will be present.
Packit ae235b
   *
Packit ae235b
   * Since: 2.36
Packit ae235b
   */
Packit ae235b
  signals[LAUNCHED] = g_signal_new (I_("launched"),
Packit ae235b
                                    G_OBJECT_CLASS_TYPE (object_class),
Packit ae235b
                                    G_SIGNAL_RUN_LAST,
Packit ae235b
                                    G_STRUCT_OFFSET (GAppLaunchContextClass, launched),
Packit ae235b
                                    NULL, NULL, NULL,
Packit ae235b
                                    G_TYPE_NONE, 2,
Packit ae235b
                                    G_TYPE_APP_INFO, G_TYPE_VARIANT);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_app_launch_context_init (GAppLaunchContext *context)
Packit ae235b
{
Packit ae235b
  context->priv = g_app_launch_context_get_instance_private (context);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_launch_context_setenv:
Packit ae235b
 * @context: a #GAppLaunchContext
Packit ae235b
 * @variable: (type filename): the environment variable to set
Packit ae235b
 * @value: (type filename): the value for to set the variable to.
Packit ae235b
 *
Packit ae235b
 * Arranges for @variable to be set to @value in the child's
Packit ae235b
 * environment when @context is used to launch an application.
Packit ae235b
 *
Packit ae235b
 * Since: 2.32
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_app_launch_context_setenv (GAppLaunchContext *context,
Packit ae235b
                             const char        *variable,
Packit ae235b
                             const char        *value)
Packit ae235b
{
Packit ae235b
  if (!context->priv->envp)
Packit ae235b
    context->priv->envp = g_get_environ ();
Packit ae235b
Packit ae235b
  context->priv->envp =
Packit ae235b
    g_environ_setenv (context->priv->envp, variable, value, TRUE);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_launch_context_unsetenv:
Packit ae235b
 * @context: a #GAppLaunchContext
Packit ae235b
 * @variable: (type filename): the environment variable to remove
Packit ae235b
 *
Packit ae235b
 * Arranges for @variable to be unset in the child's environment
Packit ae235b
 * when @context is used to launch an application.
Packit ae235b
 *
Packit ae235b
 * Since: 2.32
Packit ae235b
 */
Packit ae235b
void
Packit ae235b
g_app_launch_context_unsetenv (GAppLaunchContext *context,
Packit ae235b
                               const char        *variable)
Packit ae235b
{
Packit ae235b
  if (!context->priv->envp)
Packit ae235b
    context->priv->envp = g_get_environ ();
Packit ae235b
Packit ae235b
  context->priv->envp =
Packit ae235b
    g_environ_unsetenv (context->priv->envp, variable);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_launch_context_get_environment:
Packit ae235b
 * @context: a #GAppLaunchContext
Packit ae235b
 *
Packit ae235b
 * Gets the complete environment variable list to be passed to
Packit ae235b
 * the child process when @context is used to launch an application.
Packit ae235b
 * This is a %NULL-terminated array of strings, where each string has
Packit ae235b
 * the form `KEY=VALUE`.
Packit ae235b
 *
Packit ae235b
 * Returns: (array zero-terminated=1) (element-type filename) (transfer full):
Packit ae235b
 *     the child's environment
Packit ae235b
 *
Packit ae235b
 * Since: 2.32
Packit ae235b
 */
Packit ae235b
char **
Packit ae235b
g_app_launch_context_get_environment (GAppLaunchContext *context)
Packit ae235b
{
Packit ae235b
  if (!context->priv->envp)
Packit ae235b
    context->priv->envp = g_get_environ ();
Packit ae235b
Packit ae235b
  return g_strdupv (context->priv->envp);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_launch_context_get_display:
Packit ae235b
 * @context: a #GAppLaunchContext
Packit ae235b
 * @info: a #GAppInfo
Packit ae235b
 * @files: (element-type GFile): a #GList of #GFile objects
Packit ae235b
 *
Packit ae235b
 * Gets the display string for the @context. This is used to ensure new
Packit ae235b
 * applications are started on the same display as the launching
Packit ae235b
 * application, by setting the `DISPLAY` environment variable.
Packit ae235b
 *
Packit ae235b
 * Returns: a display string for the display.
Packit ae235b
 */
Packit ae235b
char *
Packit ae235b
g_app_launch_context_get_display (GAppLaunchContext *context,
Packit ae235b
				  GAppInfo          *info,
Packit ae235b
				  GList             *files)
Packit ae235b
{
Packit ae235b
  GAppLaunchContextClass *class;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
Packit ae235b
Packit ae235b
  class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
Packit ae235b
Packit ae235b
  if (class->get_display == NULL)
Packit ae235b
    return NULL;
Packit ae235b
Packit ae235b
  return class->get_display (context, info, files);
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_launch_context_get_startup_notify_id:
Packit ae235b
 * @context: a #GAppLaunchContext
Packit ae235b
 * @info: a #GAppInfo
Packit ae235b
 * @files: (element-type GFile): a #GList of of #GFile objects
Packit ae235b
 * 
Packit ae235b
 * Initiates startup notification for the application and returns the
Packit ae235b
 * `DESKTOP_STARTUP_ID` for the launched operation, if supported.
Packit ae235b
 *
Packit ae235b
 * Startup notification IDs are defined in the 
Packit ae235b
 * [FreeDesktop.Org Startup Notifications standard](http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt").
Packit ae235b
 *
Packit ae235b
 * Returns: a startup notification ID for the application, or %NULL if
Packit ae235b
 *     not supported.
Packit ae235b
 **/
Packit ae235b
char *
Packit ae235b
g_app_launch_context_get_startup_notify_id (GAppLaunchContext *context,
Packit ae235b
					    GAppInfo          *info,
Packit ae235b
					    GList             *files)
Packit ae235b
{
Packit ae235b
  GAppLaunchContextClass *class;
Packit ae235b
Packit ae235b
  g_return_val_if_fail (G_IS_APP_LAUNCH_CONTEXT (context), NULL);
Packit ae235b
  g_return_val_if_fail (G_IS_APP_INFO (info), NULL);
Packit ae235b
Packit ae235b
  class = G_APP_LAUNCH_CONTEXT_GET_CLASS (context);
Packit ae235b
Packit ae235b
  if (class->get_startup_notify_id == NULL)
Packit ae235b
    return NULL;
Packit ae235b
Packit ae235b
  return class->get_startup_notify_id (context, info, files);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_launch_context_launch_failed:
Packit ae235b
 * @context: a #GAppLaunchContext.
Packit ae235b
 * @startup_notify_id: the startup notification id that was returned by g_app_launch_context_get_startup_notify_id().
Packit ae235b
 *
Packit ae235b
 * Called when an application has failed to launch, so that it can cancel
Packit ae235b
 * the application startup notification started in g_app_launch_context_get_startup_notify_id().
Packit ae235b
 * 
Packit ae235b
 **/
Packit ae235b
void
Packit ae235b
g_app_launch_context_launch_failed (GAppLaunchContext *context,
Packit ae235b
				    const char        *startup_notify_id)
Packit ae235b
{
Packit ae235b
  g_return_if_fail (G_IS_APP_LAUNCH_CONTEXT (context));
Packit ae235b
  g_return_if_fail (startup_notify_id != NULL);
Packit ae235b
Packit ae235b
  g_signal_emit (context, signals[LAUNCH_FAILED], 0, startup_notify_id);
Packit ae235b
}
Packit ae235b
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * SECTION:gappinfomonitor
Packit ae235b
 * @short_description: Monitor application information for changes
Packit ae235b
 *
Packit ae235b
 * #GAppInfoMonitor is a very simple object used for monitoring the app
Packit ae235b
 * info database for changes (ie: newly installed or removed
Packit ae235b
 * applications).
Packit ae235b
 *
Packit ae235b
 * Call g_app_info_monitor_get() to get a #GAppInfoMonitor and connect
Packit ae235b
 * to the "changed" signal.
Packit ae235b
 *
Packit ae235b
 * In the usual case, applications should try to make note of the change
Packit ae235b
 * (doing things like invalidating caches) but not act on it.  In
Packit ae235b
 * particular, applications should avoid making calls to #GAppInfo APIs
Packit ae235b
 * in response to the change signal, deferring these until the time that
Packit ae235b
 * the data is actually required.  The exception to this case is when
Packit ae235b
 * application information is actually being displayed on the screen
Packit ae235b
 * (eg: during a search or when the list of all applications is shown).
Packit ae235b
 * The reason for this is that changes to the list of installed
Packit ae235b
 * applications often come in groups (like during system updates) and
Packit ae235b
 * rescanning the list on every change is pointless and expensive.
Packit ae235b
 *
Packit ae235b
 * Since: 2.40
Packit ae235b
 **/
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * GAppInfoMonitor:
Packit ae235b
 *
Packit ae235b
 * The only thing you can do with this is to get it via
Packit ae235b
 * g_app_info_monitor_get() and connect to the "changed" signal.
Packit ae235b
 *
Packit ae235b
 * Since: 2.40
Packit ae235b
 **/
Packit ae235b
Packit ae235b
typedef struct _GAppInfoMonitorClass GAppInfoMonitorClass;
Packit ae235b
Packit ae235b
struct _GAppInfoMonitor
Packit ae235b
{
Packit ae235b
  GObject parent_instance;
Packit ae235b
  GMainContext *context;
Packit ae235b
};
Packit ae235b
Packit ae235b
struct _GAppInfoMonitorClass
Packit ae235b
{
Packit ae235b
  GObjectClass parent_class;
Packit ae235b
};
Packit ae235b
Packit ae235b
static GContextSpecificGroup g_app_info_monitor_group;
Packit ae235b
static guint                 g_app_info_monitor_changed_signal;
Packit ae235b
Packit ae235b
G_DEFINE_TYPE (GAppInfoMonitor, g_app_info_monitor, G_TYPE_OBJECT)
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_app_info_monitor_finalize (GObject *object)
Packit ae235b
{
Packit ae235b
  GAppInfoMonitor *monitor = G_APP_INFO_MONITOR (object);
Packit ae235b
Packit ae235b
  g_context_specific_group_remove (&g_app_info_monitor_group, monitor->context, monitor, NULL);
Packit ae235b
Packit ae235b
  G_OBJECT_CLASS (g_app_info_monitor_parent_class)->finalize (object);
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_app_info_monitor_init (GAppInfoMonitor *monitor)
Packit ae235b
{
Packit ae235b
}
Packit ae235b
Packit ae235b
static void
Packit ae235b
g_app_info_monitor_class_init (GAppInfoMonitorClass *class)
Packit ae235b
{
Packit ae235b
  GObjectClass *object_class = G_OBJECT_CLASS (class);
Packit ae235b
Packit ae235b
  /**
Packit ae235b
   * GAppInfoMonitor::changed:
Packit ae235b
   *
Packit ae235b
   * Signal emitted when the app info database for changes (ie: newly installed
Packit ae235b
   * or removed applications).
Packit ae235b
   **/
Packit ae235b
  g_app_info_monitor_changed_signal = g_signal_new (I_("changed"), G_TYPE_APP_INFO_MONITOR, G_SIGNAL_RUN_FIRST,
Packit ae235b
                                                    0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
Packit ae235b
Packit ae235b
  object_class->finalize = g_app_info_monitor_finalize;
Packit ae235b
}
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * g_app_info_monitor_get:
Packit ae235b
 *
Packit ae235b
 * Gets the #GAppInfoMonitor for the current thread-default main
Packit ae235b
 * context.
Packit ae235b
 *
Packit ae235b
 * The #GAppInfoMonitor will emit a "changed" signal in the
Packit ae235b
 * thread-default main context whenever the list of installed
Packit ae235b
 * applications (as reported by g_app_info_get_all()) may have changed.
Packit ae235b
 *
Packit ae235b
 * You must only call g_object_unref() on the return value from under
Packit ae235b
 * the same main context as you created it.
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): a reference to a #GAppInfoMonitor
Packit ae235b
 *
Packit ae235b
 * Since: 2.40
Packit ae235b
 **/
Packit ae235b
GAppInfoMonitor *
Packit ae235b
g_app_info_monitor_get (void)
Packit ae235b
{
Packit ae235b
  return g_context_specific_group_get (&g_app_info_monitor_group,
Packit ae235b
                                       G_TYPE_APP_INFO_MONITOR,
Packit ae235b
                                       G_STRUCT_OFFSET (GAppInfoMonitor, context),
Packit ae235b
                                       NULL);
Packit ae235b
}
Packit ae235b
Packit ae235b
void
Packit ae235b
g_app_info_monitor_fire (void)
Packit ae235b
{
Packit ae235b
  g_context_specific_group_emit (&g_app_info_monitor_group, g_app_info_monitor_changed_signal);
Packit ae235b
}