1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
4 * Copyright © 2007 Ryan Lortie
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Author: Alexander Larsson <alexl@redhat.com>
22 * Ryan Lortie <desrt@desrt.ca>
31 #ifdef HAVE_CRT_EXTERNS_H
32 #include <crt_externs.h>
35 #include "gcontenttypeprivate.h"
36 #include "gdesktopappinfo.h"
38 #include "glib-unix.h"
42 #include "gthemedicon.h"
43 #include "gfileicon.h"
44 #include <glib/gstdio.h>
46 #include "giomodule-priv.h"
51 * SECTION:gdesktopappinfo
52 * @title: GDesktopAppInfo
53 * @short_description: Application information from desktop files
54 * @include: gio/gdesktopappinfo.h
56 * #GDesktopAppInfo is an implementation of #GAppInfo based on
59 * Note that <filename><gio/gdesktopappinfo.h></filename> belongs to
60 * the UNIX-specific GIO interfaces, thus you have to use the
61 * <filename>gio-unix-2.0.pc</filename> pkg-config file when using it.
64 #define DEFAULT_APPLICATIONS_GROUP "Default Applications"
65 #define ADDED_ASSOCIATIONS_GROUP "Added Associations"
66 #define REMOVED_ASSOCIATIONS_GROUP "Removed Associations"
67 #define MIME_CACHE_GROUP "MIME Cache"
68 #define GENERIC_NAME_KEY "GenericName"
69 #define FULL_NAME_KEY "X-GNOME-FullName"
70 #define KEYWORDS_KEY "Keywords"
71 #define STARTUP_WM_CLASS_KEY "StartupWMClass"
78 static void g_desktop_app_info_iface_init (GAppInfoIface *iface);
79 static GList * get_all_desktop_entries_for_mime_type (const char *base_mime_type,
81 gboolean include_fallback,
82 char **explicit_default);
83 static void mime_info_cache_reload (const char *dir);
84 static gboolean g_desktop_app_info_ensure_saved (GDesktopAppInfo *info,
90 * Information about an installed application from a desktop file.
92 struct _GDesktopAppInfo
94 GObject parent_instance;
116 char *startup_wm_class;
123 guint startup_notify : 1;
128 UPDATE_MIME_NONE = 1 << 0,
129 UPDATE_MIME_SET_DEFAULT = 1 << 1,
130 UPDATE_MIME_SET_NON_DEFAULT = 1 << 2,
131 UPDATE_MIME_REMOVE = 1 << 3,
132 UPDATE_MIME_SET_LAST_USED = 1 << 4,
135 G_DEFINE_TYPE_WITH_CODE (GDesktopAppInfo, g_desktop_app_info, G_TYPE_OBJECT,
136 G_IMPLEMENT_INTERFACE (G_TYPE_APP_INFO,
137 g_desktop_app_info_iface_init))
139 G_LOCK_DEFINE_STATIC (g_desktop_env);
140 static gchar *g_desktop_env = NULL;
143 search_path_init (gpointer data)
146 const char * const *data_dirs;
147 const char *user_data_dir;
150 data_dirs = g_get_system_data_dirs ();
151 length = g_strv_length ((char **) data_dirs);
153 args = g_new (char *, length + 2);
156 user_data_dir = g_get_user_data_dir ();
157 args[j++] = g_build_filename (user_data_dir, "applications", NULL);
158 for (i = 0; i < length; i++)
159 args[j++] = g_build_filename (data_dirs[i],
160 "applications", NULL);
166 static const char * const *
167 get_applications_search_path (void)
169 static GOnce once_init = G_ONCE_INIT;
170 return g_once (&once_init, search_path_init, NULL);
174 g_desktop_app_info_finalize (GObject *object)
176 GDesktopAppInfo *info;
178 info = G_DESKTOP_APP_INFO (object);
180 g_free (info->desktop_id);
181 g_free (info->filename);
184 g_key_file_unref (info->keyfile);
187 g_free (info->generic_name);
188 g_free (info->fullname);
189 g_free (info->comment);
190 g_free (info->icon_name);
192 g_object_unref (info->icon);
193 g_strfreev (info->keywords);
194 g_strfreev (info->only_show_in);
195 g_strfreev (info->not_show_in);
196 g_free (info->try_exec);
198 g_free (info->binary);
200 g_free (info->categories);
201 g_free (info->startup_wm_class);
202 g_strfreev (info->mime_types);
203 g_free (info->app_id);
204 g_strfreev (info->actions);
206 G_OBJECT_CLASS (g_desktop_app_info_parent_class)->finalize (object);
210 g_desktop_app_info_set_property(GObject *object,
215 GDesktopAppInfo *self = G_DESKTOP_APP_INFO (object);
220 self->filename = g_value_dup_string (value);
224 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
230 g_desktop_app_info_get_property (GObject *object,
235 GDesktopAppInfo *self = G_DESKTOP_APP_INFO (object);
240 g_value_set_string (value, self->filename);
243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
249 g_desktop_app_info_class_init (GDesktopAppInfoClass *klass)
251 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
253 gobject_class->get_property = g_desktop_app_info_get_property;
254 gobject_class->set_property = g_desktop_app_info_set_property;
255 gobject_class->finalize = g_desktop_app_info_finalize;
258 * GDesktopAppInfo:filename:
260 * The origin filename of this #GDesktopAppInfo
262 g_object_class_install_property (gobject_class,
264 g_param_spec_string ("filename", "Filename", "",
266 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
270 g_desktop_app_info_init (GDesktopAppInfo *local)
275 binary_from_exec (const char *exec)
277 const char *p, *start;
283 while (*p != ' ' && *p != 0)
286 return g_strndup (start, p - start);
291 g_desktop_app_info_load_from_keyfile (GDesktopAppInfo *info,
298 gboolean bus_activatable;
300 start_group = g_key_file_get_start_group (key_file);
301 if (start_group == NULL || strcmp (start_group, G_KEY_FILE_DESKTOP_GROUP) != 0)
303 g_free (start_group);
306 g_free (start_group);
308 type = g_key_file_get_string (key_file,
309 G_KEY_FILE_DESKTOP_GROUP,
310 G_KEY_FILE_DESKTOP_KEY_TYPE,
312 if (type == NULL || strcmp (type, G_KEY_FILE_DESKTOP_TYPE_APPLICATION) != 0)
319 try_exec = g_key_file_get_string (key_file,
320 G_KEY_FILE_DESKTOP_GROUP,
321 G_KEY_FILE_DESKTOP_KEY_TRY_EXEC,
323 if (try_exec && try_exec[0] != '\0')
326 t = g_find_program_in_path (try_exec);
335 exec = g_key_file_get_string (key_file,
336 G_KEY_FILE_DESKTOP_GROUP,
337 G_KEY_FILE_DESKTOP_KEY_EXEC,
339 if (exec && exec[0] != '\0')
343 if (!g_shell_parse_argv (exec, &argc, &argv, NULL))
352 t = g_find_program_in_path (argv[0]);
365 info->name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
366 info->generic_name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, GENERIC_NAME_KEY, NULL, NULL);
367 info->fullname = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, FULL_NAME_KEY, NULL, NULL);
368 info->keywords = g_key_file_get_locale_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, KEYWORDS_KEY, NULL, NULL, NULL);
369 info->comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
370 info->nodisplay = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, NULL) != FALSE;
371 info->icon_name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL, NULL);
372 info->only_show_in = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ONLY_SHOW_IN, NULL, NULL);
373 info->not_show_in = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NOT_SHOW_IN, NULL, NULL);
374 info->try_exec = try_exec;
376 info->path = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_PATH, NULL);
377 info->terminal = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL) != FALSE;
378 info->startup_notify = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, NULL) != FALSE;
379 info->no_fuse = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, "X-GIO-NoFuse", NULL) != FALSE;
380 info->hidden = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_HIDDEN, NULL) != FALSE;
381 info->categories = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_CATEGORIES, NULL);
382 info->startup_wm_class = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, STARTUP_WM_CLASS_KEY, NULL);
383 info->mime_types = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_MIME_TYPE, NULL, NULL);
384 bus_activatable = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_DBUS_ACTIVATABLE, NULL);
385 info->actions = g_key_file_get_string_list (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ACTIONS, NULL, NULL);
387 /* Remove the special-case: no Actions= key just means 0 extra actions */
388 if (info->actions == NULL)
389 info->actions = g_new0 (gchar *, 0 + 1);
394 if (g_path_is_absolute (info->icon_name))
398 file = g_file_new_for_path (info->icon_name);
399 info->icon = g_file_icon_new (file);
400 g_object_unref (file);
406 /* Work around a common mistake in desktop files */
407 if ((p = strrchr (info->icon_name, '.')) != NULL &&
408 (strcmp (p, ".png") == 0 ||
409 strcmp (p, ".xpm") == 0 ||
410 strcmp (p, ".svg") == 0))
413 info->icon = g_themed_icon_new (info->icon_name);
418 info->binary = binary_from_exec (info->exec);
420 if (info->path && info->path[0] == '\0')
431 basename = g_path_get_basename (info->filename);
432 last_dot = strrchr (basename, '.');
434 if (last_dot && g_str_equal (last_dot, ".desktop"))
438 if (g_dbus_is_interface_name (basename))
439 info->app_id = g_strdup (basename);
445 info->keyfile = g_key_file_ref (key_file);
451 g_desktop_app_info_load_file (GDesktopAppInfo *self)
454 gboolean retval = FALSE;
456 g_return_val_if_fail (self->filename != NULL, FALSE);
458 self->desktop_id = g_path_get_basename (self->filename);
460 key_file = g_key_file_new ();
462 if (g_key_file_load_from_file (key_file,
467 retval = g_desktop_app_info_load_from_keyfile (self, key_file);
470 g_key_file_unref (key_file);
475 * g_desktop_app_info_new_from_keyfile:
476 * @key_file: an opened #GKeyFile
478 * Creates a new #GDesktopAppInfo.
480 * Returns: a new #GDesktopAppInfo or %NULL on error.
485 g_desktop_app_info_new_from_keyfile (GKeyFile *key_file)
487 GDesktopAppInfo *info;
489 info = g_object_new (G_TYPE_DESKTOP_APP_INFO, NULL);
490 info->filename = NULL;
491 if (!g_desktop_app_info_load_from_keyfile (info, key_file))
493 g_object_unref (info);
500 * g_desktop_app_info_new_from_filename:
501 * @filename: the path of a desktop file, in the GLib filename encoding
503 * Creates a new #GDesktopAppInfo.
505 * Returns: a new #GDesktopAppInfo or %NULL on error.
508 g_desktop_app_info_new_from_filename (const char *filename)
510 GDesktopAppInfo *info = NULL;
512 info = g_object_new (G_TYPE_DESKTOP_APP_INFO, "filename", filename, NULL);
513 if (!g_desktop_app_info_load_file (info))
515 g_object_unref (info);
522 * g_desktop_app_info_new:
523 * @desktop_id: the desktop file id
525 * Creates a new #GDesktopAppInfo based on a desktop file id.
527 * A desktop file id is the basename of the desktop file, including the
528 * .desktop extension. GIO is looking for a desktop file with this name
529 * in the <filename>applications</filename> subdirectories of the XDG data
530 * directories (i.e. the directories specified in the
531 * <envar>XDG_DATA_HOME</envar> and <envar>XDG_DATA_DIRS</envar> environment
532 * variables). GIO also supports the prefix-to-subdirectory mapping that is
533 * described in the <ulink url="http://standards.freedesktop.org/menu-spec/latest/">Menu Spec</ulink>
534 * (i.e. a desktop id of kde-foo.desktop will match
535 * <filename>/usr/share/applications/kde/foo.desktop</filename>).
537 * Returns: a new #GDesktopAppInfo, or %NULL if no desktop file with that id
540 g_desktop_app_info_new (const char *desktop_id)
542 GDesktopAppInfo *appinfo;
543 const char * const *dirs;
547 dirs = get_applications_search_path ();
549 basename = g_strdup (desktop_id);
551 for (i = 0; dirs[i] != NULL; i++)
556 filename = g_build_filename (dirs[i], desktop_id, NULL);
557 appinfo = g_desktop_app_info_new_from_filename (filename);
563 while ((p = strchr (p, '-')) != NULL)
567 filename = g_build_filename (dirs[i], basename, NULL);
568 appinfo = g_desktop_app_info_new_from_filename (filename);
583 g_free (appinfo->desktop_id);
584 appinfo->desktop_id = g_strdup (desktop_id);
586 if (g_desktop_app_info_get_is_hidden (appinfo))
588 g_object_unref (appinfo);
596 g_desktop_app_info_dup (GAppInfo *appinfo)
598 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
599 GDesktopAppInfo *new_info;
601 new_info = g_object_new (G_TYPE_DESKTOP_APP_INFO, NULL);
603 new_info->filename = g_strdup (info->filename);
604 new_info->desktop_id = g_strdup (info->desktop_id);
607 new_info->keyfile = g_key_file_ref (info->keyfile);
609 new_info->name = g_strdup (info->name);
610 new_info->generic_name = g_strdup (info->generic_name);
611 new_info->fullname = g_strdup (info->fullname);
612 new_info->keywords = g_strdupv (info->keywords);
613 new_info->comment = g_strdup (info->comment);
614 new_info->nodisplay = info->nodisplay;
615 new_info->icon_name = g_strdup (info->icon_name);
617 new_info->icon = g_object_ref (info->icon);
618 new_info->only_show_in = g_strdupv (info->only_show_in);
619 new_info->not_show_in = g_strdupv (info->not_show_in);
620 new_info->try_exec = g_strdup (info->try_exec);
621 new_info->exec = g_strdup (info->exec);
622 new_info->binary = g_strdup (info->binary);
623 new_info->path = g_strdup (info->path);
624 new_info->app_id = g_strdup (info->app_id);
625 new_info->hidden = info->hidden;
626 new_info->terminal = info->terminal;
627 new_info->startup_notify = info->startup_notify;
629 return G_APP_INFO (new_info);
633 g_desktop_app_info_equal (GAppInfo *appinfo1,
636 GDesktopAppInfo *info1 = G_DESKTOP_APP_INFO (appinfo1);
637 GDesktopAppInfo *info2 = G_DESKTOP_APP_INFO (appinfo2);
639 if (info1->desktop_id == NULL ||
640 info2->desktop_id == NULL)
641 return info1 == info2;
643 return strcmp (info1->desktop_id, info2->desktop_id) == 0;
647 g_desktop_app_info_get_id (GAppInfo *appinfo)
649 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
651 return info->desktop_id;
655 g_desktop_app_info_get_name (GAppInfo *appinfo)
657 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
659 if (info->name == NULL)
665 g_desktop_app_info_get_display_name (GAppInfo *appinfo)
667 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
669 if (info->fullname == NULL)
670 return g_desktop_app_info_get_name (appinfo);
671 return info->fullname;
675 * g_desktop_app_info_get_is_hidden:
676 * @info: a #GDesktopAppInfo.
678 * A desktop file is hidden if the Hidden key in it is
681 * Returns: %TRUE if hidden, %FALSE otherwise.
684 g_desktop_app_info_get_is_hidden (GDesktopAppInfo *info)
690 * g_desktop_app_info_get_filename:
691 * @info: a #GDesktopAppInfo
693 * When @info was created from a known filename, return it. In some
694 * situations such as the #GDesktopAppInfo returned from
695 * g_desktop_app_info_new_from_keyfile(), this function will return %NULL.
697 * Returns: The full path to the file for @info, or %NULL if not known.
701 g_desktop_app_info_get_filename (GDesktopAppInfo *info)
703 return info->filename;
707 g_desktop_app_info_get_description (GAppInfo *appinfo)
709 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
711 return info->comment;
715 g_desktop_app_info_get_executable (GAppInfo *appinfo)
717 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
723 g_desktop_app_info_get_commandline (GAppInfo *appinfo)
725 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
731 g_desktop_app_info_get_icon (GAppInfo *appinfo)
733 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
739 * g_desktop_app_info_get_categories:
740 * @info: a #GDesktopAppInfo
742 * Gets the categories from the desktop file.
744 * Returns: The unparsed Categories key from the desktop file;
745 * i.e. no attempt is made to split it by ';' or validate it.
748 g_desktop_app_info_get_categories (GDesktopAppInfo *info)
750 return info->categories;
754 * g_desktop_app_info_get_keywords:
755 * @info: a #GDesktopAppInfo
757 * Gets the keywords from the desktop file.
759 * Returns: (transfer none): The value of the Keywords key
764 g_desktop_app_info_get_keywords (GDesktopAppInfo *info)
766 return (const char * const *)info->keywords;
770 * g_desktop_app_info_get_generic_name:
771 * @info: a #GDesktopAppInfo
773 * Gets the generic name from the destkop file.
775 * Returns: The value of the GenericName key
778 g_desktop_app_info_get_generic_name (GDesktopAppInfo *info)
780 return info->generic_name;
784 * g_desktop_app_info_get_nodisplay:
785 * @info: a #GDesktopAppInfo
787 * Gets the value of the NoDisplay key, which helps determine if the
788 * application info should be shown in menus. See
789 * #G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY and g_app_info_should_show().
791 * Returns: The value of the NoDisplay key
796 g_desktop_app_info_get_nodisplay (GDesktopAppInfo *info)
798 return info->nodisplay;
802 * g_desktop_app_info_get_show_in:
803 * @info: a #GDesktopAppInfo
804 * @desktop_env: a string specifying a desktop name
806 * Checks if the application info should be shown in menus that list available
807 * applications for a specific name of the desktop, based on the
808 * <literal>OnlyShowIn</literal> and <literal>NotShowIn</literal> keys.
810 * If @desktop_env is %NULL, then the name of the desktop set with
811 * g_desktop_app_info_set_desktop_env() is used.
813 * Note that g_app_info_should_show() for @info will include this check (with
814 * %NULL for @desktop_env) as well as additional checks.
816 * Returns: %TRUE if the @info should be shown in @desktop_env according to the
817 * <literal>OnlyShowIn</literal> and <literal>NotShowIn</literal> keys, %FALSE
823 g_desktop_app_info_get_show_in (GDesktopAppInfo *info,
824 const gchar *desktop_env)
829 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
832 G_LOCK (g_desktop_env);
833 desktop_env = g_desktop_env;
834 G_UNLOCK (g_desktop_env);
837 if (info->only_show_in)
839 if (desktop_env == NULL)
843 for (i = 0; info->only_show_in[i] != NULL; i++)
845 if (strcmp (info->only_show_in[i], desktop_env) == 0)
855 if (info->not_show_in && desktop_env)
857 for (i = 0; info->not_show_in[i] != NULL; i++)
859 if (strcmp (info->not_show_in[i], desktop_env) == 0)
868 expand_macro_single (char macro, char *uri)
874 file = g_file_new_for_uri (uri);
875 path = g_file_get_path (file);
876 g_object_unref (file);
882 result = g_shell_quote (uri);
887 result = g_shell_quote (path);
893 name = g_path_get_dirname (path);
894 result = g_shell_quote (name);
902 name = g_path_get_basename (path);
903 result = g_shell_quote (name);
915 expand_macro (char macro,
917 GDesktopAppInfo *info,
920 GList *uris = *uri_list;
922 gboolean force_file_uri;
923 char force_file_uri_macro;
926 g_return_if_fail (exec != NULL);
928 /* On %u and %U, pass POSIX file path pointing to the URI via
929 * the FUSE mount in ~/.gvfs. Note that if the FUSE daemon isn't
930 * running or the URI doesn't have a POSIX file path via FUSE
931 * we'll just pass the URI.
933 force_file_uri_macro = macro;
934 force_file_uri = FALSE;
940 force_file_uri_macro = 'f';
941 force_file_uri = TRUE;
944 force_file_uri_macro = 'F';
945 force_file_uri = TRUE;
961 if (!force_file_uri ||
962 /* Pass URI if it contains an anchor */
963 strchr (uri, '#') != NULL)
965 expanded = expand_macro_single (macro, uri);
969 expanded = expand_macro_single (force_file_uri_macro, uri);
970 if (expanded == NULL)
971 expanded = expand_macro_single (macro, uri);
976 g_string_append (exec, expanded);
992 if (!force_file_uri ||
993 /* Pass URI if it contains an anchor */
994 strchr (uri, '#') != NULL)
996 expanded = expand_macro_single (macro, uri);
1000 expanded = expand_macro_single (force_file_uri_macro, uri);
1001 if (expanded == NULL)
1002 expanded = expand_macro_single (macro, uri);
1007 g_string_append (exec, expanded);
1013 if (uris != NULL && expanded)
1014 g_string_append_c (exec, ' ');
1020 if (info->icon_name)
1022 g_string_append (exec, "--icon ");
1023 expanded = g_shell_quote (info->icon_name);
1024 g_string_append (exec, expanded);
1032 expanded = g_shell_quote (info->name);
1033 g_string_append (exec, expanded);
1041 expanded = g_shell_quote (info->filename);
1042 g_string_append (exec, expanded);
1047 case 'm': /* deprecated */
1051 g_string_append_c (exec, '%');
1059 expand_application_parameters (GDesktopAppInfo *info,
1060 const gchar *exec_line,
1066 GList *uri_list = *uris;
1067 const char *p = exec_line;
1068 GString *expanded_exec;
1071 if (exec_line == NULL)
1073 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
1074 _("Desktop file didn't specify Exec field"));
1078 expanded_exec = g_string_new (NULL);
1082 if (p[0] == '%' && p[1] != '\0')
1084 expand_macro (p[1], expanded_exec, info, uris);
1088 g_string_append_c (expanded_exec, *p);
1093 /* No file substitutions */
1094 if (uri_list == *uris && uri_list != NULL)
1096 /* If there is no macro default to %f. This is also what KDE does */
1097 g_string_append_c (expanded_exec, ' ');
1098 expand_macro ('f', expanded_exec, info, uris);
1101 res = g_shell_parse_argv (expanded_exec->str, argc, argv, error);
1102 g_string_free (expanded_exec, TRUE);
1107 prepend_terminal_to_vector (int *argc,
1114 char **term_argv = NULL;
1119 g_return_val_if_fail (argc != NULL, FALSE);
1120 g_return_val_if_fail (argv != NULL, FALSE);
1128 /* compute size if not given */
1131 for (i = 0; the_argv[i] != NULL; i++)
1137 term_argv = g_new0 (char *, 3);
1139 check = g_find_program_in_path ("gnome-terminal");
1142 term_argv[0] = check;
1143 /* Note that gnome-terminal takes -x and
1144 * as -e in gnome-terminal is broken we use that. */
1145 term_argv[1] = g_strdup ("-x");
1150 check = g_find_program_in_path ("nxterm");
1152 check = g_find_program_in_path ("color-xterm");
1154 check = g_find_program_in_path ("rxvt");
1156 check = g_find_program_in_path ("xterm");
1158 check = g_find_program_in_path ("dtterm");
1161 check = g_strdup ("xterm");
1162 g_warning ("couldn't find a terminal, falling back to xterm");
1164 term_argv[0] = check;
1165 term_argv[1] = g_strdup ("-e");
1168 real_argc = term_argc + *argc;
1169 real_argv = g_new (char *, real_argc + 1);
1171 for (i = 0; i < term_argc; i++)
1172 real_argv[i] = term_argv[i];
1174 for (j = 0; j < *argc; j++, i++)
1175 real_argv[i] = (char *)the_argv[j];
1177 real_argv[i] = NULL;
1183 /* we use g_free here as we sucked all the inner strings
1184 * out from it into real_argv */
1189 #endif /* G_OS_WIN32 */
1193 create_files_for_uris (GList *uris)
1200 for (iter = uris; iter; iter = iter->next)
1202 GFile *file = g_file_new_for_uri ((char *)iter->data);
1203 res = g_list_prepend (res, file);
1206 return g_list_reverse (res);
1211 GSpawnChildSetupFunc user_setup;
1212 gpointer user_setup_data;
1218 child_setup (gpointer user_data)
1220 ChildSetupData *data = user_data;
1222 if (data->pid_envvar)
1224 pid_t pid = getpid ();
1228 /* Write the pid into the space already reserved for it in the
1229 * environment array. We can't use sprintf because it might
1230 * malloc, so we do it by hand. It's simplest to write the pid
1231 * out backwards first, then copy it over.
1233 for (i = 0; pid; i++, pid /= 10)
1234 buf[i] = (pid % 10) + '0';
1235 for (i--; i >= 0; i--)
1236 *(data->pid_envvar++) = buf[i];
1237 *data->pid_envvar = '\0';
1240 if (data->user_setup)
1241 data->user_setup (data->user_setup_data);
1245 notify_desktop_launch (GDBusConnection *session_bus,
1246 GDesktopAppInfo *info,
1248 const char *display,
1253 GVariantBuilder uri_variant;
1254 GVariantBuilder extras_variant;
1256 const char *desktop_file_id;
1257 const char *gio_desktop_file;
1259 if (session_bus == NULL)
1262 g_variant_builder_init (&uri_variant, G_VARIANT_TYPE ("as"));
1263 for (iter = uris; iter; iter = iter->next)
1264 g_variant_builder_add (&uri_variant, "s", iter->data);
1266 g_variant_builder_init (&extras_variant, G_VARIANT_TYPE ("a{sv}"));
1267 if (sn_id != NULL && g_utf8_validate (sn_id, -1, NULL))
1268 g_variant_builder_add (&extras_variant, "{sv}",
1272 gio_desktop_file = g_getenv ("GIO_LAUNCHED_DESKTOP_FILE");
1273 if (gio_desktop_file != NULL)
1274 g_variant_builder_add (&extras_variant, "{sv}",
1275 "origin-desktop-file",
1276 g_variant_new_bytestring (gio_desktop_file));
1277 if (g_get_prgname () != NULL)
1278 g_variant_builder_add (&extras_variant, "{sv}",
1280 g_variant_new_bytestring (g_get_prgname ()));
1281 g_variant_builder_add (&extras_variant, "{sv}",
1284 (gint64)getpid ()));
1287 desktop_file_id = info->filename;
1288 else if (info->desktop_id)
1289 desktop_file_id = info->desktop_id;
1291 desktop_file_id = "";
1293 msg = g_dbus_message_new_signal ("/org/gtk/gio/DesktopAppInfo",
1294 "org.gtk.gio.DesktopAppInfo",
1296 g_dbus_message_set_body (msg, g_variant_new ("(@aysxasa{sv})",
1297 g_variant_new_bytestring (desktop_file_id),
1298 display ? display : "",
1302 g_dbus_connection_send_message (session_bus,
1306 g_object_unref (msg);
1309 #define _SPAWN_FLAGS_DEFAULT (G_SPAWN_SEARCH_PATH)
1312 g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
1313 GDBusConnection *session_bus,
1314 const gchar *exec_line,
1316 GAppLaunchContext *launch_context,
1317 GSpawnFlags spawn_flags,
1318 GSpawnChildSetupFunc user_setup,
1319 gpointer user_setup_data,
1320 GDesktopAppLaunchCallback pid_callback,
1321 gpointer pid_callback_data,
1324 gboolean completed = FALSE;
1326 char **argv, **envp;
1328 ChildSetupData data;
1330 g_return_val_if_fail (info != NULL, FALSE);
1335 envp = g_app_launch_context_get_environment (launch_context);
1337 envp = g_get_environ ();
1342 GList *launched_uris;
1344 char *display, *sn_id;
1347 if (!expand_application_parameters (info, exec_line, &uris, &argc, &argv, error))
1350 /* Get the subset of URIs we're launching with this process */
1351 launched_uris = NULL;
1352 for (iter = old_uris; iter != NULL && iter != uris; iter = iter->next)
1353 launched_uris = g_list_prepend (launched_uris, iter->data);
1354 launched_uris = g_list_reverse (launched_uris);
1356 if (info->terminal && !prepend_terminal_to_vector (&argc, &argv))
1358 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
1359 _("Unable to find terminal required for application"));
1363 data.user_setup = user_setup;
1364 data.user_setup_data = user_setup_data;
1368 envp = g_environ_setenv (envp,
1369 "GIO_LAUNCHED_DESKTOP_FILE",
1372 envp = g_environ_setenv (envp,
1373 "GIO_LAUNCHED_DESKTOP_FILE_PID",
1374 "XXXXXXXXXXXXXXXXXXXX", /* filled in child_setup */
1376 data.pid_envvar = (char *)g_environ_getenv (envp, "GIO_LAUNCHED_DESKTOP_FILE_PID");
1380 data.pid_envvar = NULL;
1387 GList *launched_files = create_files_for_uris (launched_uris);
1389 display = g_app_launch_context_get_display (launch_context,
1393 envp = g_environ_setenv (envp, "DISPLAY", display, TRUE);
1395 if (info->startup_notify)
1397 sn_id = g_app_launch_context_get_startup_notify_id (launch_context,
1400 envp = g_environ_setenv (envp, "DESKTOP_STARTUP_ID", sn_id, TRUE);
1403 g_list_free_full (launched_files, g_object_unref);
1406 if (!g_spawn_async (info->path,
1416 g_app_launch_context_launch_failed (launch_context, sn_id);
1420 g_list_free (launched_uris);
1425 if (pid_callback != NULL)
1426 pid_callback (info, pid, pid_callback_data);
1428 if (launch_context != NULL)
1430 GVariantBuilder builder;
1431 GVariant *platform_data;
1433 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
1434 g_variant_builder_add (&builder, "{sv}", "pid", g_variant_new_int32 (pid));
1436 g_variant_builder_add (&builder, "{sv}", "startup-notification-id", g_variant_new_string (sn_id));
1437 platform_data = g_variant_ref_sink (g_variant_builder_end (&builder));
1438 g_signal_emit_by_name (launch_context, "launched", info, platform_data);
1439 g_variant_unref (platform_data);
1442 notify_desktop_launch (session_bus,
1451 g_list_free (launched_uris);
1456 while (uris != NULL);
1468 object_path_from_appid (const gchar *app_id)
1473 n = strlen (app_id);
1474 path = g_malloc (n + 2);
1478 for (i = 0; i < n; i++)
1479 if (app_id[i] != '.')
1480 path[i + 1] = app_id[i];
1490 g_desktop_app_info_make_platform_data (GDesktopAppInfo *info,
1492 GAppLaunchContext *launch_context)
1494 GVariantBuilder builder;
1496 g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
1500 GList *launched_files = create_files_for_uris (uris);
1502 if (info->startup_notify)
1506 sn_id = g_app_launch_context_get_startup_notify_id (launch_context, G_APP_INFO (info), launched_files);
1507 g_variant_builder_add (&builder, "{sv}", "desktop-startup-id", g_variant_new_take_string (sn_id));
1510 g_list_free_full (launched_files, g_object_unref);
1513 return g_variant_builder_end (&builder);
1517 g_desktop_app_info_launch_uris_with_dbus (GDesktopAppInfo *info,
1518 GDBusConnection *session_bus,
1520 GAppLaunchContext *launch_context)
1522 GVariantBuilder builder;
1525 g_return_val_if_fail (info != NULL, FALSE);
1527 g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
1533 g_variant_builder_open (&builder, G_VARIANT_TYPE_STRING_ARRAY);
1534 for (iter = uris; iter; iter = iter->next)
1535 g_variant_builder_add (&builder, "s", iter->data);
1536 g_variant_builder_close (&builder);
1539 g_variant_builder_add_value (&builder, g_desktop_app_info_make_platform_data (info, uris, launch_context));
1541 /* This is non-blocking API. Similar to launching via fork()/exec()
1542 * we don't wait around to see if the program crashed during startup.
1543 * This is what startup-notification's job is...
1545 object_path = object_path_from_appid (info->app_id);
1546 g_dbus_connection_call (session_bus, info->app_id, object_path, "org.freedesktop.Application",
1547 uris ? "Open" : "Activate", g_variant_builder_end (&builder),
1548 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
1549 g_free (object_path);
1555 g_desktop_app_info_launch_uris_internal (GAppInfo *appinfo,
1557 GAppLaunchContext *launch_context,
1558 GSpawnFlags spawn_flags,
1559 GSpawnChildSetupFunc user_setup,
1560 gpointer user_setup_data,
1561 GDesktopAppLaunchCallback pid_callback,
1562 gpointer pid_callback_data,
1565 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1566 GDBusConnection *session_bus;
1567 gboolean success = TRUE;
1569 session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
1571 if (session_bus && info->app_id)
1572 g_desktop_app_info_launch_uris_with_dbus (info, session_bus, uris, launch_context);
1574 success = g_desktop_app_info_launch_uris_with_spawn (info, session_bus, info->exec, uris, launch_context,
1575 spawn_flags, user_setup, user_setup_data,
1576 pid_callback, pid_callback_data, error);
1578 if (session_bus != NULL)
1580 /* This asynchronous flush holds a reference until it completes,
1581 * which ensures that the following unref won't immediately kill
1582 * the connection if we were the initial owner.
1584 g_dbus_connection_flush (session_bus, NULL, NULL, NULL);
1585 g_object_unref (session_bus);
1592 g_desktop_app_info_launch_uris (GAppInfo *appinfo,
1594 GAppLaunchContext *launch_context,
1597 return g_desktop_app_info_launch_uris_internal (appinfo, uris,
1599 _SPAWN_FLAGS_DEFAULT,
1600 NULL, NULL, NULL, NULL,
1605 g_desktop_app_info_supports_uris (GAppInfo *appinfo)
1607 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1609 return info->exec &&
1610 ((strstr (info->exec, "%u") != NULL) ||
1611 (strstr (info->exec, "%U") != NULL));
1615 g_desktop_app_info_supports_files (GAppInfo *appinfo)
1617 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1619 return info->exec &&
1620 ((strstr (info->exec, "%f") != NULL) ||
1621 (strstr (info->exec, "%F") != NULL));
1625 g_desktop_app_info_launch (GAppInfo *appinfo,
1627 GAppLaunchContext *launch_context,
1637 uri = g_file_get_uri (files->data);
1638 uris = g_list_prepend (uris, uri);
1639 files = files->next;
1642 uris = g_list_reverse (uris);
1644 res = g_desktop_app_info_launch_uris (appinfo, uris, launch_context, error);
1646 g_list_free_full (uris, g_free);
1652 * g_desktop_app_info_launch_uris_as_manager:
1653 * @appinfo: a #GDesktopAppInfo
1654 * @uris: (element-type utf8): List of URIs
1655 * @launch_context: a #GAppLaunchContext
1656 * @spawn_flags: #GSpawnFlags, used for each process
1657 * @user_setup: (scope call): a #GSpawnChildSetupFunc, used once for
1659 * @user_setup_data: (closure user_setup): User data for @user_setup
1660 * @pid_callback: (scope call): Callback for child processes
1661 * @pid_callback_data: (closure pid_callback): User data for @callback
1662 * @error: return location for a #GError, or %NULL
1664 * This function performs the equivalent of g_app_info_launch_uris(),
1665 * but is intended primarily for operating system components that
1666 * launch applications. Ordinary applications should use
1667 * g_app_info_launch_uris().
1669 * If the application is launched via traditional UNIX fork()/exec()
1670 * then @spawn_flags, @user_setup and @user_setup_data are used for the
1671 * call to g_spawn_async(). Additionally, @pid_callback (with
1672 * @pid_callback_data) will be called to inform about the PID of the
1675 * If application launching occurs via some other mechanism (eg: D-Bus
1676 * activation) then @spawn_flags, @user_setup, @user_setup_data,
1677 * @pid_callback and @pid_callback_data are ignored.
1679 * Returns: %TRUE on successful launch, %FALSE otherwise.
1682 g_desktop_app_info_launch_uris_as_manager (GDesktopAppInfo *appinfo,
1684 GAppLaunchContext *launch_context,
1685 GSpawnFlags spawn_flags,
1686 GSpawnChildSetupFunc user_setup,
1687 gpointer user_setup_data,
1688 GDesktopAppLaunchCallback pid_callback,
1689 gpointer pid_callback_data,
1692 return g_desktop_app_info_launch_uris_internal ((GAppInfo*)appinfo,
1704 * g_desktop_app_info_set_desktop_env:
1705 * @desktop_env: a string specifying what desktop this is
1707 * Sets the name of the desktop that the application is running in.
1708 * This is used by g_app_info_should_show() and
1709 * g_desktop_app_info_get_show_in() to evaluate the
1710 * <literal>OnlyShowIn</literal> and <literal>NotShowIn</literal>
1711 * desktop entry fields.
1713 * The <ulink url="http://standards.freedesktop.org/menu-spec/latest/">Desktop
1714 * Menu specification</ulink> recognizes the following:
1716 * <member>GNOME</member>
1717 * <member>KDE</member>
1718 * <member>ROX</member>
1719 * <member>XFCE</member>
1720 * <member>LXDE</member>
1721 * <member>Unity</member>
1722 * <member>Old</member>
1725 * Should be called only once; subsequent calls are ignored.
1728 g_desktop_app_info_set_desktop_env (const gchar *desktop_env)
1730 G_LOCK (g_desktop_env);
1732 g_desktop_env = g_strdup (desktop_env);
1733 G_UNLOCK (g_desktop_env);
1737 g_desktop_app_info_should_show (GAppInfo *appinfo)
1739 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1741 if (info->nodisplay)
1744 return g_desktop_app_info_get_show_in (info, NULL);
1753 ensure_dir (DirType type,
1756 char *path, *display_name;
1759 if (type == APP_DIR)
1760 path = g_build_filename (g_get_user_data_dir (), "applications", NULL);
1762 path = g_build_filename (g_get_user_data_dir (), "mime", "packages", NULL);
1765 if (g_mkdir_with_parents (path, 0700) == 0)
1769 display_name = g_filename_display_name (path);
1770 if (type == APP_DIR)
1771 g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
1772 _("Can't create user application configuration folder %s: %s"),
1773 display_name, g_strerror (errsv));
1775 g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
1776 _("Can't create user MIME configuration folder %s: %s"),
1777 display_name, g_strerror (errsv));
1779 g_free (display_name);
1786 update_mimeapps_list (const char *desktop_id,
1787 const char *content_type,
1788 UpdateMimeFlags flags,
1791 char *dirname, *filename, *string;
1793 gboolean load_succeeded, res;
1794 char **old_list, **list;
1795 gsize length, data_size;
1798 char **content_types;
1800 /* Don't add both at start and end */
1801 g_assert (!((flags & UPDATE_MIME_SET_DEFAULT) &&
1802 (flags & UPDATE_MIME_SET_NON_DEFAULT)));
1804 dirname = ensure_dir (APP_DIR, error);
1808 filename = g_build_filename (dirname, "mimeapps.list", NULL);
1811 key_file = g_key_file_new ();
1812 load_succeeded = g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL);
1813 if (!load_succeeded ||
1814 (!g_key_file_has_group (key_file, ADDED_ASSOCIATIONS_GROUP) &&
1815 !g_key_file_has_group (key_file, REMOVED_ASSOCIATIONS_GROUP) &&
1816 !g_key_file_has_group (key_file, DEFAULT_APPLICATIONS_GROUP)))
1818 g_key_file_free (key_file);
1819 key_file = g_key_file_new ();
1824 content_types = g_new (char *, 2);
1825 content_types[0] = g_strdup (content_type);
1826 content_types[1] = NULL;
1830 content_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP, NULL, NULL);
1833 for (k = 0; content_types && content_types[k]; k++)
1835 /* set as default, if requested so */
1836 string = g_key_file_get_string (key_file,
1837 DEFAULT_APPLICATIONS_GROUP,
1841 if (g_strcmp0 (string, desktop_id) != 0 &&
1842 (flags & UPDATE_MIME_SET_DEFAULT))
1845 string = g_strdup (desktop_id);
1847 /* add in the non-default list too, if it's not already there */
1848 flags |= UPDATE_MIME_SET_NON_DEFAULT;
1851 if (string == NULL || desktop_id == NULL)
1852 g_key_file_remove_key (key_file,
1853 DEFAULT_APPLICATIONS_GROUP,
1857 g_key_file_set_string (key_file,
1858 DEFAULT_APPLICATIONS_GROUP,
1867 /* reuse the list from above */
1871 g_strfreev (content_types);
1872 content_types = g_key_file_get_keys (key_file, ADDED_ASSOCIATIONS_GROUP, NULL, NULL);
1875 for (k = 0; content_types && content_types[k]; k++)
1877 /* Add to the right place in the list */
1880 old_list = g_key_file_get_string_list (key_file, ADDED_ASSOCIATIONS_GROUP,
1881 content_types[k], &length, NULL);
1883 list = g_new (char *, 1 + length + 1);
1887 /* if we're adding a last-used hint, just put the application in front of the list */
1888 if (flags & UPDATE_MIME_SET_LAST_USED)
1890 /* avoid adding this again as non-default later */
1891 if (flags & UPDATE_MIME_SET_NON_DEFAULT)
1892 flags ^= UPDATE_MIME_SET_NON_DEFAULT;
1894 list[i++] = g_strdup (desktop_id);
1899 for (j = 0; old_list[j] != NULL; j++)
1901 if (g_strcmp0 (old_list[j], desktop_id) != 0)
1903 /* rewrite other entries if they're different from the new one */
1904 list[i++] = g_strdup (old_list[j]);
1906 else if (flags & UPDATE_MIME_SET_NON_DEFAULT)
1908 /* we encountered an old entry which is equal to the one we're adding as non-default,
1909 * don't change its position in the list.
1911 flags ^= UPDATE_MIME_SET_NON_DEFAULT;
1912 list[i++] = g_strdup (old_list[j]);
1917 /* add it at the end of the list */
1918 if (flags & UPDATE_MIME_SET_NON_DEFAULT)
1919 list[i++] = g_strdup (desktop_id);
1923 g_strfreev (old_list);
1925 if (list[0] == NULL || desktop_id == NULL)
1926 g_key_file_remove_key (key_file,
1927 ADDED_ASSOCIATIONS_GROUP,
1931 g_key_file_set_string_list (key_file,
1932 ADDED_ASSOCIATIONS_GROUP,
1934 (const char * const *)list, i);
1941 /* reuse the list from above */
1945 g_strfreev (content_types);
1946 content_types = g_key_file_get_keys (key_file, REMOVED_ASSOCIATIONS_GROUP, NULL, NULL);
1949 for (k = 0; content_types && content_types[k]; k++)
1951 /* Remove from removed associations group (unless remove) */
1954 old_list = g_key_file_get_string_list (key_file, REMOVED_ASSOCIATIONS_GROUP,
1955 content_types[k], &length, NULL);
1957 list = g_new (char *, 1 + length + 1);
1960 if (flags & UPDATE_MIME_REMOVE)
1961 list[i++] = g_strdup (desktop_id);
1964 for (j = 0; old_list[j] != NULL; j++)
1966 if (g_strcmp0 (old_list[j], desktop_id) != 0)
1967 list[i++] = g_strdup (old_list[j]);
1972 g_strfreev (old_list);
1974 if (list[0] == NULL || desktop_id == NULL)
1975 g_key_file_remove_key (key_file,
1976 REMOVED_ASSOCIATIONS_GROUP,
1980 g_key_file_set_string_list (key_file,
1981 REMOVED_ASSOCIATIONS_GROUP,
1983 (const char * const *)list, i);
1988 g_strfreev (content_types);
1990 data = g_key_file_to_data (key_file, &data_size, error);
1991 g_key_file_free (key_file);
1993 res = g_file_set_contents (filename, data, data_size, error);
1995 mime_info_cache_reload (NULL);
2004 g_desktop_app_info_set_as_last_used_for_type (GAppInfo *appinfo,
2005 const char *content_type,
2008 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2010 if (!g_desktop_app_info_ensure_saved (info, error))
2013 if (!info->desktop_id)
2015 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
2016 _("Application information lacks an identifier"));
2020 /* both add support for the content type and set as last used */
2021 return update_mimeapps_list (info->desktop_id, content_type,
2022 UPDATE_MIME_SET_NON_DEFAULT |
2023 UPDATE_MIME_SET_LAST_USED,
2028 g_desktop_app_info_set_as_default_for_type (GAppInfo *appinfo,
2029 const char *content_type,
2032 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2034 if (!g_desktop_app_info_ensure_saved (info, error))
2037 if (!info->desktop_id)
2039 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
2040 _("Application information lacks an identifier"));
2044 return update_mimeapps_list (info->desktop_id, content_type,
2045 UPDATE_MIME_SET_DEFAULT,
2050 update_program_done (GPid pid,
2054 /* Did the application exit correctly */
2055 if (g_spawn_check_exit_status (status, NULL))
2057 /* Here we could clean out any caches in use */
2062 run_update_command (char *command,
2071 GError *error = NULL;
2074 argv[1] = g_build_filename (g_get_user_data_dir (), subdir, NULL);
2076 if (g_spawn_async ("/", argv,
2078 G_SPAWN_SEARCH_PATH |
2079 G_SPAWN_STDOUT_TO_DEV_NULL |
2080 G_SPAWN_STDERR_TO_DEV_NULL |
2081 G_SPAWN_DO_NOT_REAP_CHILD,
2082 NULL, NULL, /* No setup function */
2085 g_child_watch_add (pid, update_program_done, NULL);
2088 /* If we get an error at this point, it's quite likely the user doesn't
2089 * have an installed copy of either 'update-mime-database' or
2090 * 'update-desktop-database'. I don't think we want to popup an error
2091 * dialog at this point, so we just do a g_warning to give the user a
2092 * chance of debugging it.
2094 g_warning ("%s", error->message);
2101 g_desktop_app_info_set_as_default_for_extension (GAppInfo *appinfo,
2102 const char *extension,
2105 char *filename, *basename, *mimetype;
2109 if (!g_desktop_app_info_ensure_saved (G_DESKTOP_APP_INFO (appinfo), error))
2112 dirname = ensure_dir (MIMETYPE_DIR, error);
2116 basename = g_strdup_printf ("user-extension-%s.xml", extension);
2117 filename = g_build_filename (dirname, basename, NULL);
2121 mimetype = g_strdup_printf ("application/x-extension-%s", extension);
2123 if (!g_file_test (filename, G_FILE_TEST_EXISTS))
2128 g_strdup_printf ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
2129 "<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">\n"
2130 " <mime-type type=\"%s\">\n"
2131 " <comment>%s document</comment>\n"
2132 " <glob pattern=\"*.%s\"/>\n"
2134 "</mime-info>\n", mimetype, extension, extension);
2136 g_file_set_contents (filename, contents, -1, NULL);
2139 run_update_command ("update-mime-database", "mime");
2143 res = g_desktop_app_info_set_as_default_for_type (appinfo,
2153 g_desktop_app_info_add_supports_type (GAppInfo *appinfo,
2154 const char *content_type,
2157 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2159 if (!g_desktop_app_info_ensure_saved (G_DESKTOP_APP_INFO (info), error))
2162 return update_mimeapps_list (info->desktop_id, content_type,
2163 UPDATE_MIME_SET_NON_DEFAULT,
2168 g_desktop_app_info_can_remove_supports_type (GAppInfo *appinfo)
2174 g_desktop_app_info_remove_supports_type (GAppInfo *appinfo,
2175 const char *content_type,
2178 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2180 if (!g_desktop_app_info_ensure_saved (G_DESKTOP_APP_INFO (info), error))
2183 return update_mimeapps_list (info->desktop_id, content_type,
2188 static const char **
2189 g_desktop_app_info_get_supported_types (GAppInfo *appinfo)
2191 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2193 return (const char**) info->mime_types;
2198 g_desktop_app_info_ensure_saved (GDesktopAppInfo *info,
2204 char *data, *desktop_id;
2209 if (info->filename != NULL)
2212 /* This is only used for object created with
2213 * g_app_info_create_from_commandline. All other
2214 * object should have a filename
2217 dirname = ensure_dir (APP_DIR, error);
2221 key_file = g_key_file_new ();
2223 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2224 "Encoding", "UTF-8");
2225 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2226 G_KEY_FILE_DESKTOP_KEY_VERSION, "1.0");
2227 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2228 G_KEY_FILE_DESKTOP_KEY_TYPE,
2229 G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
2231 g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
2232 G_KEY_FILE_DESKTOP_KEY_TERMINAL, TRUE);
2233 if (info->nodisplay)
2234 g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
2235 G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, TRUE);
2237 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2238 G_KEY_FILE_DESKTOP_KEY_EXEC, info->exec);
2240 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2241 G_KEY_FILE_DESKTOP_KEY_NAME, info->name);
2243 if (info->generic_name != NULL)
2244 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2245 GENERIC_NAME_KEY, info->generic_name);
2247 if (info->fullname != NULL)
2248 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2249 FULL_NAME_KEY, info->fullname);
2251 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2252 G_KEY_FILE_DESKTOP_KEY_COMMENT, info->comment);
2254 g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
2255 G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, TRUE);
2257 data = g_key_file_to_data (key_file, &data_size, NULL);
2258 g_key_file_free (key_file);
2260 desktop_id = g_strdup_printf ("userapp-%s-XXXXXX.desktop", info->name);
2261 filename = g_build_filename (dirname, desktop_id, NULL);
2262 g_free (desktop_id);
2265 fd = g_mkstemp (filename);
2270 display_name = g_filename_display_name (filename);
2271 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
2272 _("Can't create user desktop file %s"), display_name);
2273 g_free (display_name);
2279 desktop_id = g_path_get_basename (filename);
2281 /* FIXME - actually handle error */
2282 (void) g_close (fd, NULL);
2284 res = g_file_set_contents (filename, data, data_size, error);
2288 g_free (desktop_id);
2293 info->filename = filename;
2294 info->desktop_id = desktop_id;
2296 run_update_command ("update-desktop-database", "applications");
2302 g_desktop_app_info_can_delete (GAppInfo *appinfo)
2304 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2308 if (strstr (info->filename, "/userapp-"))
2309 return g_access (info->filename, W_OK) == 0;
2316 g_desktop_app_info_delete (GAppInfo *appinfo)
2318 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2322 if (g_remove (info->filename) == 0)
2324 update_mimeapps_list (info->desktop_id, NULL,
2328 g_free (info->filename);
2329 info->filename = NULL;
2330 g_free (info->desktop_id);
2331 info->desktop_id = NULL;
2341 * g_app_info_create_from_commandline:
2342 * @commandline: the commandline to use
2343 * @application_name: (allow-none): the application name, or %NULL to use @commandline
2344 * @flags: flags that can specify details of the created #GAppInfo
2345 * @error: a #GError location to store the error occurring, %NULL to ignore.
2347 * Creates a new #GAppInfo from the given information.
2349 * Note that for @commandline, the quoting rules of the Exec key of the
2350 * <ulink url="http://freedesktop.org/Standards/desktop-entry-spec">freedesktop.org Desktop
2351 * Entry Specification</ulink> are applied. For example, if the @commandline contains
2352 * percent-encoded URIs, the percent-character must be doubled in order to prevent it from
2353 * being swallowed by Exec key unquoting. See the specification for exact quoting rules.
2355 * Returns: (transfer full): new #GAppInfo for given command.
2358 g_app_info_create_from_commandline (const char *commandline,
2359 const char *application_name,
2360 GAppInfoCreateFlags flags,
2365 GDesktopAppInfo *info;
2367 g_return_val_if_fail (commandline, NULL);
2369 info = g_object_new (G_TYPE_DESKTOP_APP_INFO, NULL);
2371 info->filename = NULL;
2372 info->desktop_id = NULL;
2374 info->terminal = (flags & G_APP_INFO_CREATE_NEEDS_TERMINAL) != 0;
2375 info->startup_notify = (flags & G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION) != 0;
2376 info->hidden = FALSE;
2377 if ((flags & G_APP_INFO_CREATE_SUPPORTS_URIS) != 0)
2378 info->exec = g_strconcat (commandline, " %u", NULL);
2380 info->exec = g_strconcat (commandline, " %f", NULL);
2381 info->nodisplay = TRUE;
2382 info->binary = binary_from_exec (info->exec);
2384 if (application_name)
2385 info->name = g_strdup (application_name);
2388 /* FIXME: this should be more robust. Maybe g_shell_parse_argv and use argv[0] */
2389 split = g_strsplit (commandline, " ", 2);
2390 basename = split[0] ? g_path_get_basename (split[0]) : NULL;
2392 info->name = basename;
2393 if (info->name == NULL)
2394 info->name = g_strdup ("custom");
2396 info->comment = g_strdup_printf (_("Custom definition for %s"), info->name);
2398 return G_APP_INFO (info);
2402 g_desktop_app_info_iface_init (GAppInfoIface *iface)
2404 iface->dup = g_desktop_app_info_dup;
2405 iface->equal = g_desktop_app_info_equal;
2406 iface->get_id = g_desktop_app_info_get_id;
2407 iface->get_name = g_desktop_app_info_get_name;
2408 iface->get_description = g_desktop_app_info_get_description;
2409 iface->get_executable = g_desktop_app_info_get_executable;
2410 iface->get_icon = g_desktop_app_info_get_icon;
2411 iface->launch = g_desktop_app_info_launch;
2412 iface->supports_uris = g_desktop_app_info_supports_uris;
2413 iface->supports_files = g_desktop_app_info_supports_files;
2414 iface->launch_uris = g_desktop_app_info_launch_uris;
2415 iface->should_show = g_desktop_app_info_should_show;
2416 iface->set_as_default_for_type = g_desktop_app_info_set_as_default_for_type;
2417 iface->set_as_default_for_extension = g_desktop_app_info_set_as_default_for_extension;
2418 iface->add_supports_type = g_desktop_app_info_add_supports_type;
2419 iface->can_remove_supports_type = g_desktop_app_info_can_remove_supports_type;
2420 iface->remove_supports_type = g_desktop_app_info_remove_supports_type;
2421 iface->can_delete = g_desktop_app_info_can_delete;
2422 iface->do_delete = g_desktop_app_info_delete;
2423 iface->get_commandline = g_desktop_app_info_get_commandline;
2424 iface->get_display_name = g_desktop_app_info_get_display_name;
2425 iface->set_as_last_used_for_type = g_desktop_app_info_set_as_last_used_for_type;
2426 iface->get_supported_types = g_desktop_app_info_get_supported_types;
2430 app_info_in_list (GAppInfo *info,
2433 while (list != NULL)
2435 if (g_app_info_equal (info, list->data))
2443 * g_app_info_get_recommended_for_type:
2444 * @content_type: the content type to find a #GAppInfo for
2446 * Gets a list of recommended #GAppInfos for a given content type, i.e.
2447 * those applications which claim to support the given content type exactly,
2448 * and not by MIME type subclassing.
2449 * Note that the first application of the list is the last used one, i.e.
2450 * the last one for which g_app_info_set_as_last_used_for_type() has been
2453 * Returns: (element-type GAppInfo) (transfer full): #GList of #GAppInfos
2454 * for given @content_type or %NULL on error.
2459 g_app_info_get_recommended_for_type (const gchar *content_type)
2461 GList *desktop_entries, *l;
2463 GDesktopAppInfo *info;
2465 g_return_val_if_fail (content_type != NULL, NULL);
2467 desktop_entries = get_all_desktop_entries_for_mime_type (content_type, NULL, FALSE, NULL);
2470 for (l = desktop_entries; l != NULL; l = l->next)
2472 char *desktop_entry = l->data;
2474 info = g_desktop_app_info_new (desktop_entry);
2477 if (app_info_in_list (G_APP_INFO (info), infos))
2478 g_object_unref (info);
2480 infos = g_list_prepend (infos, info);
2482 g_free (desktop_entry);
2485 g_list_free (desktop_entries);
2487 return g_list_reverse (infos);
2491 * g_app_info_get_fallback_for_type:
2492 * @content_type: the content type to find a #GAppInfo for
2494 * Gets a list of fallback #GAppInfos for a given content type, i.e.
2495 * those applications which claim to support the given content type
2496 * by MIME type subclassing and not directly.
2498 * Returns: (element-type GAppInfo) (transfer full): #GList of #GAppInfos
2499 * for given @content_type or %NULL on error.
2504 g_app_info_get_fallback_for_type (const gchar *content_type)
2506 GList *desktop_entries, *l;
2507 GList *infos, *recommended_infos;
2508 GDesktopAppInfo *info;
2510 g_return_val_if_fail (content_type != NULL, NULL);
2512 desktop_entries = get_all_desktop_entries_for_mime_type (content_type, NULL, TRUE, NULL);
2513 recommended_infos = g_app_info_get_recommended_for_type (content_type);
2516 for (l = desktop_entries; l != NULL; l = l->next)
2518 char *desktop_entry = l->data;
2520 info = g_desktop_app_info_new (desktop_entry);
2523 if (app_info_in_list (G_APP_INFO (info), infos) ||
2524 app_info_in_list (G_APP_INFO (info), recommended_infos))
2525 g_object_unref (info);
2527 infos = g_list_prepend (infos, info);
2529 g_free (desktop_entry);
2532 g_list_free (desktop_entries);
2533 g_list_free_full (recommended_infos, g_object_unref);
2535 return g_list_reverse (infos);
2539 * g_app_info_get_all_for_type:
2540 * @content_type: the content type to find a #GAppInfo for
2542 * Gets a list of all #GAppInfos for a given content type,
2543 * including the recommended and fallback #GAppInfos. See
2544 * g_app_info_get_recommended_for_type() and
2545 * g_app_info_get_fallback_for_type().
2547 * Returns: (element-type GAppInfo) (transfer full): #GList of #GAppInfos
2548 * for given @content_type or %NULL on error.
2551 g_app_info_get_all_for_type (const char *content_type)
2553 GList *desktop_entries, *l;
2555 char *user_default = NULL;
2556 GDesktopAppInfo *info;
2558 g_return_val_if_fail (content_type != NULL, NULL);
2560 desktop_entries = get_all_desktop_entries_for_mime_type (content_type, NULL, TRUE, &user_default);
2563 /* put the user default in front of the list, for compatibility */
2564 if (user_default != NULL)
2566 info = g_desktop_app_info_new (user_default);
2569 infos = g_list_prepend (infos, info);
2572 g_free (user_default);
2574 for (l = desktop_entries; l != NULL; l = l->next)
2576 char *desktop_entry = l->data;
2578 info = g_desktop_app_info_new (desktop_entry);
2581 if (app_info_in_list (G_APP_INFO (info), infos))
2582 g_object_unref (info);
2584 infos = g_list_prepend (infos, info);
2586 g_free (desktop_entry);
2589 g_list_free (desktop_entries);
2591 return g_list_reverse (infos);
2595 * g_app_info_reset_type_associations:
2596 * @content_type: a content type
2598 * Removes all changes to the type associations done by
2599 * g_app_info_set_as_default_for_type(),
2600 * g_app_info_set_as_default_for_extension(),
2601 * g_app_info_add_supports_type() or
2602 * g_app_info_remove_supports_type().
2607 g_app_info_reset_type_associations (const char *content_type)
2609 update_mimeapps_list (NULL, content_type,
2615 * g_app_info_get_default_for_type:
2616 * @content_type: the content type to find a #GAppInfo for
2617 * @must_support_uris: if %TRUE, the #GAppInfo is expected to
2620 * Gets the default #GAppInfo for a given content type.
2622 * Returns: (transfer full): #GAppInfo for given @content_type or
2626 g_app_info_get_default_for_type (const char *content_type,
2627 gboolean must_support_uris)
2629 GList *desktop_entries, *l;
2630 char *user_default = NULL;
2633 g_return_val_if_fail (content_type != NULL, NULL);
2635 desktop_entries = get_all_desktop_entries_for_mime_type (content_type, NULL, TRUE, &user_default);
2639 if (user_default != NULL)
2641 info = (GAppInfo *) g_desktop_app_info_new (user_default);
2645 if (must_support_uris && !g_app_info_supports_uris (info))
2647 g_object_unref (info);
2653 g_free (user_default);
2657 g_list_free_full (desktop_entries, g_free);
2661 /* pick the first from the other list that matches our URI
2664 for (l = desktop_entries; l != NULL; l = l->next)
2666 char *desktop_entry = l->data;
2668 info = (GAppInfo *)g_desktop_app_info_new (desktop_entry);
2671 if (must_support_uris && !g_app_info_supports_uris (info))
2673 g_object_unref (info);
2681 g_list_free_full (desktop_entries, g_free);
2687 * g_app_info_get_default_for_uri_scheme:
2688 * @uri_scheme: a string containing a URI scheme.
2690 * Gets the default application for handling URIs with
2691 * the given URI scheme. A URI scheme is the initial part
2692 * of the URI, up to but not including the ':', e.g. "http",
2695 * Returns: (transfer full): #GAppInfo for given @uri_scheme or %NULL on error.
2698 g_app_info_get_default_for_uri_scheme (const char *uri_scheme)
2701 char *content_type, *scheme_down;
2703 scheme_down = g_ascii_strdown (uri_scheme, -1);
2704 content_type = g_strdup_printf ("x-scheme-handler/%s", scheme_down);
2705 g_free (scheme_down);
2706 app_info = g_app_info_get_default_for_type (content_type, FALSE);
2707 g_free (content_type);
2713 get_apps_from_dir (GHashTable *apps,
2714 const char *dirname,
2718 const char *basename;
2719 char *filename, *subprefix, *desktop_id;
2721 GDesktopAppInfo *appinfo;
2723 dir = g_dir_open (dirname, 0, NULL);
2726 while ((basename = g_dir_read_name (dir)) != NULL)
2728 filename = g_build_filename (dirname, basename, NULL);
2729 if (g_str_has_suffix (basename, ".desktop"))
2731 desktop_id = g_strconcat (prefix, basename, NULL);
2733 /* Use _extended so we catch NULLs too (hidden) */
2734 if (!g_hash_table_lookup_extended (apps, desktop_id, NULL, NULL))
2736 appinfo = g_desktop_app_info_new_from_filename (filename);
2739 if (appinfo && g_desktop_app_info_get_is_hidden (appinfo))
2741 g_object_unref (appinfo);
2746 if (appinfo || hidden)
2748 g_hash_table_insert (apps, g_strdup (desktop_id), appinfo);
2752 /* Reuse instead of strdup here */
2753 appinfo->desktop_id = desktop_id;
2758 g_free (desktop_id);
2762 if (g_file_test (filename, G_FILE_TEST_IS_DIR))
2764 subprefix = g_strconcat (prefix, basename, "-", NULL);
2765 get_apps_from_dir (apps, filename, subprefix);
2777 * g_app_info_get_all:
2779 * Gets a list of all of the applications currently registered
2782 * For desktop files, this includes applications that have
2783 * <literal>NoDisplay=true</literal> set or are excluded from
2784 * display by means of <literal>OnlyShowIn</literal> or
2785 * <literal>NotShowIn</literal>. See g_app_info_should_show().
2786 * The returned list does not include applications which have
2787 * the <literal>Hidden</literal> key set.
2789 * Returns: (element-type GAppInfo) (transfer full): a newly allocated #GList of references to #GAppInfo<!---->s.
2792 g_app_info_get_all (void)
2794 const char * const *dirs;
2796 GHashTableIter iter;
2801 dirs = get_applications_search_path ();
2803 apps = g_hash_table_new_full (g_str_hash, g_str_equal,
2807 for (i = 0; dirs[i] != NULL; i++)
2808 get_apps_from_dir (apps, dirs[i], "");
2812 g_hash_table_iter_init (&iter, apps);
2813 while (g_hash_table_iter_next (&iter, NULL, &value))
2816 infos = g_list_prepend (infos, value);
2819 g_hash_table_destroy (apps);
2821 return g_list_reverse (infos);
2824 /* Cacheing of mimeinfo.cache and defaults.list files */
2828 GHashTable *mime_info_cache_map;
2829 GHashTable *defaults_list_map;
2830 GHashTable *mimeapps_list_added_map;
2831 GHashTable *mimeapps_list_removed_map;
2832 GHashTable *mimeapps_list_defaults_map;
2833 time_t mime_info_cache_timestamp;
2834 time_t defaults_list_timestamp;
2835 time_t mimeapps_list_timestamp;
2839 GList *dirs; /* mimeinfo.cache and defaults.list */
2840 GHashTable *global_defaults_cache; /* global results of defaults.list lookup and validation */
2841 time_t last_stat_time;
2842 guint should_ping_mime_monitor : 1;
2845 static MimeInfoCache *mime_info_cache = NULL;
2846 G_LOCK_DEFINE_STATIC (mime_info_cache);
2848 static void mime_info_cache_dir_add_desktop_entries (MimeInfoCacheDir *dir,
2849 const char *mime_type,
2850 char **new_desktop_file_ids);
2852 static MimeInfoCache * mime_info_cache_new (void);
2855 destroy_info_cache_value (gpointer key,
2859 g_list_free_full (value, g_free);
2863 destroy_info_cache_map (GHashTable *info_cache_map)
2865 g_hash_table_foreach (info_cache_map, (GHFunc)destroy_info_cache_value, NULL);
2866 g_hash_table_destroy (info_cache_map);
2870 mime_info_cache_dir_out_of_date (MimeInfoCacheDir *dir,
2871 const char *cache_file,
2877 filename = g_build_filename (dir->path, cache_file, NULL);
2879 if (g_stat (filename, &buf) < 0)
2886 if (buf.st_mtime != *timestamp)
2892 /* Call with lock held */
2894 remove_all (gpointer key,
2903 mime_info_cache_blow_global_cache (void)
2905 g_hash_table_foreach_remove (mime_info_cache->global_defaults_cache,
2910 mime_info_cache_dir_init (MimeInfoCacheDir *dir)
2914 gchar *filename, **mime_types;
2921 if (dir->mime_info_cache_map != NULL &&
2922 !mime_info_cache_dir_out_of_date (dir, "mimeinfo.cache",
2923 &dir->mime_info_cache_timestamp))
2926 if (dir->mime_info_cache_map != NULL)
2927 destroy_info_cache_map (dir->mime_info_cache_map);
2929 dir->mime_info_cache_map = g_hash_table_new_full (g_str_hash, g_str_equal,
2930 (GDestroyNotify) g_free,
2933 key_file = g_key_file_new ();
2935 filename = g_build_filename (dir->path, "mimeinfo.cache", NULL);
2937 if (g_stat (filename, &buf) < 0)
2940 if (dir->mime_info_cache_timestamp > 0)
2941 mime_info_cache->should_ping_mime_monitor = TRUE;
2943 dir->mime_info_cache_timestamp = buf.st_mtime;
2945 g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &load_error);
2950 if (load_error != NULL)
2953 mime_types = g_key_file_get_keys (key_file, MIME_CACHE_GROUP,
2956 if (load_error != NULL)
2959 for (i = 0; mime_types[i] != NULL; i++)
2961 gchar **desktop_file_ids;
2962 char *unaliased_type;
2963 desktop_file_ids = g_key_file_get_string_list (key_file,
2969 if (desktop_file_ids == NULL)
2972 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
2973 mime_info_cache_dir_add_desktop_entries (dir,
2976 g_free (unaliased_type);
2978 g_strfreev (desktop_file_ids);
2981 g_strfreev (mime_types);
2982 g_key_file_free (key_file);
2987 g_key_file_free (key_file);
2989 if (mime_types != NULL)
2990 g_strfreev (mime_types);
2993 g_error_free (load_error);
2997 mime_info_cache_dir_init_defaults_list (MimeInfoCacheDir *dir)
3001 gchar *filename, **mime_types;
3002 char *unaliased_type;
3003 char **desktop_file_ids;
3010 if (dir->defaults_list_map != NULL &&
3011 !mime_info_cache_dir_out_of_date (dir, "defaults.list",
3012 &dir->defaults_list_timestamp))
3015 if (dir->defaults_list_map != NULL)
3016 g_hash_table_destroy (dir->defaults_list_map);
3017 dir->defaults_list_map = g_hash_table_new_full (g_str_hash, g_str_equal,
3018 g_free, (GDestroyNotify)g_strfreev);
3021 key_file = g_key_file_new ();
3023 filename = g_build_filename (dir->path, "defaults.list", NULL);
3024 if (g_stat (filename, &buf) < 0)
3027 if (dir->defaults_list_timestamp > 0)
3028 mime_info_cache->should_ping_mime_monitor = TRUE;
3030 dir->defaults_list_timestamp = buf.st_mtime;
3032 g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &load_error);
3036 if (load_error != NULL)
3039 mime_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP,
3041 if (mime_types != NULL)
3043 for (i = 0; mime_types[i] != NULL; i++)
3045 desktop_file_ids = g_key_file_get_string_list (key_file,
3046 DEFAULT_APPLICATIONS_GROUP,
3050 if (desktop_file_ids == NULL)
3053 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
3054 g_hash_table_replace (dir->defaults_list_map,
3059 g_strfreev (mime_types);
3062 g_key_file_free (key_file);
3067 g_key_file_free (key_file);
3069 if (mime_types != NULL)
3070 g_strfreev (mime_types);
3073 g_error_free (load_error);
3077 mime_info_cache_dir_init_mimeapps_list (MimeInfoCacheDir *dir)
3081 gchar *filename, **mime_types;
3082 char *unaliased_type;
3083 char **desktop_file_ids;
3091 if (dir->mimeapps_list_added_map != NULL &&
3092 !mime_info_cache_dir_out_of_date (dir, "mimeapps.list",
3093 &dir->mimeapps_list_timestamp))
3096 if (dir->mimeapps_list_added_map != NULL)
3097 g_hash_table_destroy (dir->mimeapps_list_added_map);
3098 dir->mimeapps_list_added_map = g_hash_table_new_full (g_str_hash, g_str_equal,
3099 g_free, (GDestroyNotify)g_strfreev);
3101 if (dir->mimeapps_list_removed_map != NULL)
3102 g_hash_table_destroy (dir->mimeapps_list_removed_map);
3103 dir->mimeapps_list_removed_map = g_hash_table_new_full (g_str_hash, g_str_equal,
3104 g_free, (GDestroyNotify)g_strfreev);
3106 if (dir->mimeapps_list_defaults_map != NULL)
3107 g_hash_table_destroy (dir->mimeapps_list_defaults_map);
3108 dir->mimeapps_list_defaults_map = g_hash_table_new_full (g_str_hash, g_str_equal,
3111 key_file = g_key_file_new ();
3113 filename = g_build_filename (dir->path, "mimeapps.list", NULL);
3114 if (g_stat (filename, &buf) < 0)
3117 if (dir->mimeapps_list_timestamp > 0)
3118 mime_info_cache->should_ping_mime_monitor = TRUE;
3120 dir->mimeapps_list_timestamp = buf.st_mtime;
3122 g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &load_error);
3126 if (load_error != NULL)
3129 mime_types = g_key_file_get_keys (key_file, ADDED_ASSOCIATIONS_GROUP,
3131 if (mime_types != NULL)
3133 for (i = 0; mime_types[i] != NULL; i++)
3135 desktop_file_ids = g_key_file_get_string_list (key_file,
3136 ADDED_ASSOCIATIONS_GROUP,
3140 if (desktop_file_ids == NULL)
3143 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
3144 g_hash_table_replace (dir->mimeapps_list_added_map,
3149 g_strfreev (mime_types);
3152 mime_types = g_key_file_get_keys (key_file, REMOVED_ASSOCIATIONS_GROUP,
3154 if (mime_types != NULL)
3156 for (i = 0; mime_types[i] != NULL; i++)
3158 desktop_file_ids = g_key_file_get_string_list (key_file,
3159 REMOVED_ASSOCIATIONS_GROUP,
3163 if (desktop_file_ids == NULL)
3166 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
3167 g_hash_table_replace (dir->mimeapps_list_removed_map,
3172 g_strfreev (mime_types);
3175 mime_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP,
3177 if (mime_types != NULL)
3179 for (i = 0; mime_types[i] != NULL; i++)
3181 desktop_id = g_key_file_get_string (key_file,
3182 DEFAULT_APPLICATIONS_GROUP,
3185 if (desktop_id == NULL)
3188 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
3189 g_hash_table_replace (dir->mimeapps_list_defaults_map,
3194 g_strfreev (mime_types);
3197 g_key_file_free (key_file);
3202 g_key_file_free (key_file);
3204 if (mime_types != NULL)
3205 g_strfreev (mime_types);
3208 g_error_free (load_error);
3211 static MimeInfoCacheDir *
3212 mime_info_cache_dir_new (const char *path)
3214 MimeInfoCacheDir *dir;
3216 dir = g_new0 (MimeInfoCacheDir, 1);
3217 dir->path = g_strdup (path);
3223 mime_info_cache_dir_free (MimeInfoCacheDir *dir)
3228 if (dir->mime_info_cache_map != NULL)
3230 destroy_info_cache_map (dir->mime_info_cache_map);
3231 dir->mime_info_cache_map = NULL;
3235 if (dir->defaults_list_map != NULL)
3237 g_hash_table_destroy (dir->defaults_list_map);
3238 dir->defaults_list_map = NULL;
3241 if (dir->mimeapps_list_added_map != NULL)
3243 g_hash_table_destroy (dir->mimeapps_list_added_map);
3244 dir->mimeapps_list_added_map = NULL;
3247 if (dir->mimeapps_list_removed_map != NULL)
3249 g_hash_table_destroy (dir->mimeapps_list_removed_map);
3250 dir->mimeapps_list_removed_map = NULL;
3253 if (dir->mimeapps_list_defaults_map != NULL)
3255 g_hash_table_destroy (dir->mimeapps_list_defaults_map);
3256 dir->mimeapps_list_defaults_map = NULL;
3263 mime_info_cache_dir_add_desktop_entries (MimeInfoCacheDir *dir,
3264 const char *mime_type,
3265 char **new_desktop_file_ids)
3267 GList *desktop_file_ids;
3270 desktop_file_ids = g_hash_table_lookup (dir->mime_info_cache_map,
3273 for (i = 0; new_desktop_file_ids[i] != NULL; i++)
3275 if (!g_list_find_custom (desktop_file_ids, new_desktop_file_ids[i], (GCompareFunc) strcmp))
3276 desktop_file_ids = g_list_append (desktop_file_ids,
3277 g_strdup (new_desktop_file_ids[i]));
3280 g_hash_table_insert (dir->mime_info_cache_map, g_strdup (mime_type), desktop_file_ids);
3284 mime_info_cache_init_dir_lists (void)
3286 const char * const *dirs;
3289 mime_info_cache = mime_info_cache_new ();
3291 dirs = get_applications_search_path ();
3293 for (i = 0; dirs[i] != NULL; i++)
3295 MimeInfoCacheDir *dir;
3297 dir = mime_info_cache_dir_new (dirs[i]);
3301 mime_info_cache_dir_init (dir);
3302 mime_info_cache_dir_init_defaults_list (dir);
3303 mime_info_cache_dir_init_mimeapps_list (dir);
3305 mime_info_cache->dirs = g_list_append (mime_info_cache->dirs, dir);
3311 mime_info_cache_update_dir_lists (void)
3315 tmp = mime_info_cache->dirs;
3319 MimeInfoCacheDir *dir = (MimeInfoCacheDir *) tmp->data;
3321 /* No need to do this if we had file monitors... */
3322 mime_info_cache_blow_global_cache ();
3323 mime_info_cache_dir_init (dir);
3324 mime_info_cache_dir_init_defaults_list (dir);
3325 mime_info_cache_dir_init_mimeapps_list (dir);
3332 mime_info_cache_init (void)
3334 G_LOCK (mime_info_cache);
3335 if (mime_info_cache == NULL)
3336 mime_info_cache_init_dir_lists ();
3342 if (now >= mime_info_cache->last_stat_time + 10)
3344 mime_info_cache_update_dir_lists ();
3345 mime_info_cache->last_stat_time = now;
3349 if (mime_info_cache->should_ping_mime_monitor)
3351 /* g_idle_add (emit_mime_changed, NULL); */
3352 mime_info_cache->should_ping_mime_monitor = FALSE;
3355 G_UNLOCK (mime_info_cache);
3358 static MimeInfoCache *
3359 mime_info_cache_new (void)
3361 MimeInfoCache *cache;
3363 cache = g_new0 (MimeInfoCache, 1);
3365 cache->global_defaults_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
3366 (GDestroyNotify) g_free,
3367 (GDestroyNotify) g_free);
3372 mime_info_cache_free (MimeInfoCache *cache)
3377 g_list_free_full (cache->dirs, (GDestroyNotify) mime_info_cache_dir_free);
3378 g_hash_table_destroy (cache->global_defaults_cache);
3383 * mime_info_cache_reload:
3384 * @dir: directory path which needs reloading.
3386 * Reload the mime information for the @dir.
3389 mime_info_cache_reload (const char *dir)
3391 /* FIXME: just reload the dir that needs reloading,
3392 * don't blow the whole cache
3394 if (mime_info_cache != NULL)
3396 G_LOCK (mime_info_cache);
3397 mime_info_cache_free (mime_info_cache);
3398 mime_info_cache = NULL;
3399 G_UNLOCK (mime_info_cache);
3404 append_desktop_entry (GList *list,
3405 const char *desktop_entry,
3406 GList *removed_entries)
3408 /* Add if not already in list, and valid */
3409 if (!g_list_find_custom (list, desktop_entry, (GCompareFunc) strcmp) &&
3410 !g_list_find_custom (removed_entries, desktop_entry, (GCompareFunc) strcmp))
3411 list = g_list_prepend (list, g_strdup (desktop_entry));
3417 * get_all_desktop_entries_for_mime_type:
3418 * @mime_type: a mime type.
3419 * @except: NULL or a strv list
3421 * Returns all the desktop ids for @mime_type. The desktop files
3422 * are listed in an order so that default applications are listed before
3423 * non-default ones, and handlers for inherited mimetypes are listed
3424 * after the base ones.
3426 * Optionally doesn't list the desktop ids given in the @except
3428 * Return value: a #GList containing the desktop ids which claim
3429 * to handle @mime_type.
3432 get_all_desktop_entries_for_mime_type (const char *base_mime_type,
3433 const char **except,
3434 gboolean include_fallback,
3435 char **explicit_default)
3437 GList *desktop_entries, *removed_entries, *list, *dir_list, *tmp;
3438 MimeInfoCacheDir *dir;
3439 char *mime_type, *default_entry = NULL;
3440 char *old_default_entry = NULL;
3443 char **default_entries;
3444 char **removed_associations;
3445 gboolean already_found_handler;
3450 mime_info_cache_init ();
3452 if (include_fallback)
3454 /* collect all ancestors */
3455 mime_types = _g_unix_content_type_get_parents (base_mime_type);
3456 array = g_ptr_array_new ();
3457 for (i = 0; mime_types[i]; i++)
3458 g_ptr_array_add (array, mime_types[i]);
3459 g_free (mime_types);
3460 for (i = 0; i < array->len; i++)
3462 anc = _g_unix_content_type_get_parents (g_ptr_array_index (array, i));
3463 for (j = 0; anc[j]; j++)
3465 for (k = 0; k < array->len; k++)
3467 if (strcmp (anc[j], g_ptr_array_index (array, k)) == 0)
3470 if (k == array->len) /* not found */
3471 g_ptr_array_add (array, g_strdup (anc[j]));
3475 g_ptr_array_add (array, NULL);
3476 mime_types = (char **)g_ptr_array_free (array, FALSE);
3480 mime_types = g_malloc0 (2 * sizeof (gchar *));
3481 mime_types[0] = g_strdup (base_mime_type);
3482 mime_types[1] = NULL;
3485 G_LOCK (mime_info_cache);
3487 removed_entries = NULL;
3488 desktop_entries = NULL;
3490 for (i = 0; except != NULL && except[i] != NULL; i++)
3491 removed_entries = g_list_prepend (removed_entries, g_strdup (except[i]));
3493 for (i = 0; mime_types[i] != NULL; i++)
3495 mime_type = mime_types[i];
3497 /* This is true if we already found a handler for a more specific
3498 mimetype. If its set we ignore any defaults for the less specific
3500 already_found_handler = (desktop_entries != NULL);
3502 /* Go through all apps listed in user and system dirs */
3503 for (dir_list = mime_info_cache->dirs;
3505 dir_list = dir_list->next)
3507 dir = dir_list->data;
3509 /* Pick the explicit default application if we got no result earlier
3510 * (ie, for more specific mime types)
3512 if (!already_found_handler)
3514 entry = g_hash_table_lookup (dir->mimeapps_list_defaults_map, mime_type);
3518 /* Save the default entry if it's the first one we encounter */
3519 if (default_entry == NULL)
3520 default_entry = g_strdup (entry);
3524 /* Then added associations from mimeapps.list */
3525 default_entries = g_hash_table_lookup (dir->mimeapps_list_added_map, mime_type);
3526 for (j = 0; default_entries != NULL && default_entries[j] != NULL; j++)
3527 desktop_entries = append_desktop_entry (desktop_entries, default_entries[j], removed_entries);
3529 /* Then removed associations from mimeapps.list */
3530 removed_associations = g_hash_table_lookup (dir->mimeapps_list_removed_map, mime_type);
3531 for (j = 0; removed_associations != NULL && removed_associations[j] != NULL; j++)
3532 removed_entries = append_desktop_entry (removed_entries, removed_associations[j], NULL);
3534 /* Then system defaults (or old per-user config) (using removed associations from this dir or earlier) */
3535 default_entries = g_hash_table_lookup (dir->defaults_list_map, mime_type);
3536 for (j = 0; default_entries != NULL && default_entries[j] != NULL; j++)
3538 if (default_entry == NULL && old_default_entry == NULL && !already_found_handler)
3539 old_default_entry = g_strdup (default_entries[j]);
3541 desktop_entries = append_desktop_entry (desktop_entries, default_entries[j], removed_entries);
3545 /* Go through all entries that support the mimetype */
3546 for (dir_list = mime_info_cache->dirs;
3548 dir_list = dir_list->next)
3550 dir = dir_list->data;
3552 list = g_hash_table_lookup (dir->mime_info_cache_map, mime_type);
3553 for (tmp = list; tmp != NULL; tmp = tmp->next)
3554 desktop_entries = append_desktop_entry (desktop_entries, tmp->data, removed_entries);
3558 G_UNLOCK (mime_info_cache);
3560 g_strfreev (mime_types);
3562 /* If we have no default from mimeapps.list, take it from
3563 * defaults.list intead.
3565 * If we do have a default from mimeapps.list, free any one that came
3566 * from defaults.list.
3568 if (default_entry == NULL)
3569 default_entry = old_default_entry;
3571 g_free (old_default_entry);
3573 if (explicit_default != NULL)
3574 *explicit_default = default_entry;
3576 g_free (default_entry);
3578 g_list_free_full (removed_entries, g_free);
3580 desktop_entries = g_list_reverse (desktop_entries);
3582 return desktop_entries;
3585 /* GDesktopAppInfoLookup interface: */
3587 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
3589 typedef GDesktopAppInfoLookupIface GDesktopAppInfoLookupInterface;
3590 G_DEFINE_INTERFACE (GDesktopAppInfoLookup, g_desktop_app_info_lookup, G_TYPE_OBJECT)
3593 g_desktop_app_info_lookup_default_init (GDesktopAppInfoLookupInterface *iface)
3598 * g_desktop_app_info_lookup_get_default_for_uri_scheme:
3599 * @lookup: a #GDesktopAppInfoLookup
3600 * @uri_scheme: a string containing a URI scheme.
3602 * Gets the default application for launching applications
3603 * using this URI scheme for a particular GDesktopAppInfoLookup
3606 * The GDesktopAppInfoLookup interface and this function is used
3607 * to implement g_app_info_get_default_for_uri_scheme() backends
3608 * in a GIO module. There is no reason for applications to use it
3609 * directly. Applications should use g_app_info_get_default_for_uri_scheme().
3611 * Returns: (transfer full): #GAppInfo for given @uri_scheme or %NULL on error.
3613 * Deprecated: The #GDesktopAppInfoLookup interface is deprecated and unused by gio.
3616 g_desktop_app_info_lookup_get_default_for_uri_scheme (GDesktopAppInfoLookup *lookup,
3617 const char *uri_scheme)
3619 GDesktopAppInfoLookupIface *iface;
3621 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO_LOOKUP (lookup), NULL);
3623 iface = G_DESKTOP_APP_INFO_LOOKUP_GET_IFACE (lookup);
3625 return (* iface->get_default_for_uri_scheme) (lookup, uri_scheme);
3628 G_GNUC_END_IGNORE_DEPRECATIONS
3631 * g_desktop_app_info_get_startup_wm_class:
3632 * @info: a #GDesktopAppInfo that supports startup notify
3634 * Retrieves the StartupWMClass field from @info. This represents the
3635 * WM_CLASS property of the main window of the application, if launched
3638 * Returns: (transfer none): the startup WM class, or %NULL if none is set
3639 * in the desktop file.
3644 g_desktop_app_info_get_startup_wm_class (GDesktopAppInfo *info)
3646 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
3648 return info->startup_wm_class;
3652 * g_desktop_app_info_get_string:
3653 * @info: a #GDesktopAppInfo
3654 * @key: the key to look up
3656 * Looks up a string value in the keyfile backing @info.
3658 * The @key is looked up in the "Desktop Entry" group.
3660 * Returns: a newly allocated string, or %NULL if the key
3666 g_desktop_app_info_get_string (GDesktopAppInfo *info,
3669 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
3671 return g_key_file_get_string (info->keyfile,
3672 G_KEY_FILE_DESKTOP_GROUP, key, NULL);
3676 * g_desktop_app_info_get_boolean:
3677 * @info: a #GDesktopAppInfo
3678 * @key: the key to look up
3680 * Looks up a boolean value in the keyfile backing @info.
3682 * The @key is looked up in the "Desktop Entry" group.
3684 * Returns: the boolean value, or %FALSE if the key
3690 g_desktop_app_info_get_boolean (GDesktopAppInfo *info,
3693 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
3695 return g_key_file_get_boolean (info->keyfile,
3696 G_KEY_FILE_DESKTOP_GROUP, key, NULL);
3700 * g_desktop_app_info_has_key:
3701 * @info: a #GDesktopAppInfo
3702 * @key: the key to look up
3704 * Returns whether @key exists in the "Desktop Entry" group
3705 * of the keyfile backing @info.
3707 * Returns: %TRUE if the @key exists
3712 g_desktop_app_info_has_key (GDesktopAppInfo *info,
3715 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
3717 return g_key_file_has_key (info->keyfile,
3718 G_KEY_FILE_DESKTOP_GROUP, key, NULL);
3722 * g_desktop_app_info_list_actions:
3723 * @info: a #GDesktopAppInfo
3725 * Returns the list of "additional application actions" supported on the
3726 * desktop file, as per the desktop file specification.
3728 * As per the specification, this is the list of actions that are
3729 * explicitly listed in the "Actions" key of the [Desktop Entry] group.
3731 * Returns: (array zero-terminated=1) (element-type utf8) (transfer none): a list of strings, always non-%NULL
3735 const gchar * const *
3736 g_desktop_app_info_list_actions (GDesktopAppInfo *info)
3738 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
3740 return (const gchar **) info->actions;
3744 app_info_has_action (GDesktopAppInfo *info,
3745 const gchar *action_name)
3749 for (i = 0; info->actions[i]; i++)
3750 if (g_str_equal (info->actions[i], action_name))
3757 * g_desktop_app_info_get_action_name:
3758 * @info: a #GDesktopAppInfo
3759 * @action_name: the name of the action as from
3760 * g_desktop_app_info_list_actions()
3762 * Gets the user-visible display name of the "additional application
3763 * action" specified by @action_name.
3765 * This corresponds to the "Name" key within the keyfile group for the
3768 * Returns: (transfer full): the locale-specific action name
3773 g_desktop_app_info_get_action_name (GDesktopAppInfo *info,
3774 const gchar *action_name)
3779 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
3780 g_return_val_if_fail (action_name != NULL, NULL);
3781 g_return_val_if_fail (app_info_has_action (info, action_name), NULL);
3783 group_name = g_strdup_printf ("Desktop Action %s", action_name);
3784 result = g_key_file_get_locale_string (info->keyfile, group_name, "Name", NULL, NULL);
3785 g_free (group_name);
3787 /* The spec says that the Name field must be given.
3789 * If it's not, let's follow the behaviour of our get_name()
3790 * implementation above and never return %NULL.
3793 result = g_strdup (_("Unnamed"));
3799 * g_desktop_app_info_launch_action:
3800 * @info: a #GDesktopAppInfo
3801 * @action_name: the name of the action as from
3802 * g_desktop_app_info_list_actions()
3803 * @launch_context: (allow-none): a #GAppLaunchContext
3805 * Activates the named application action.
3807 * You may only call this function on action names that were
3808 * returned from g_desktop_app_info_list_actions().
3810 * Note that if the main entry of the desktop file indicates that the
3811 * application supports startup notification, and @launch_context is
3812 * non-%NULL, then startup notification will be used when activating the
3813 * action (and as such, invocation of the action on the receiving side
3814 * must signal the end of startup notification when it is completed).
3815 * This is the expected behaviour of applications declaring additional
3816 * actions, as per the desktop file specification.
3818 * As with g_app_info_launch() there is no way to detect failures that
3819 * occur while using this function.
3824 g_desktop_app_info_launch_action (GDesktopAppInfo *info,
3825 const gchar *action_name,
3826 GAppLaunchContext *launch_context)
3828 GDBusConnection *session_bus;
3830 g_return_if_fail (G_IS_DESKTOP_APP_INFO (info));
3831 g_return_if_fail (action_name != NULL);
3832 g_return_if_fail (app_info_has_action (info, action_name));
3834 session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
3836 if (session_bus && info->app_id)
3840 object_path = object_path_from_appid (info->app_id);
3841 g_dbus_connection_call (session_bus, info->app_id, object_path,
3842 "org.freedesktop.Application", "ActivateAction",
3843 g_variant_new ("(sav@a{sv})", action_name, NULL,
3844 g_desktop_app_info_make_platform_data (info, NULL, launch_context)),
3845 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
3846 g_free (object_path);
3853 group_name = g_strdup_printf ("Desktop Action %s", action_name);
3854 exec_line = g_key_file_get_string (info->keyfile, group_name, "Exec", NULL);
3855 g_free (group_name);
3858 g_desktop_app_info_launch_uris_with_spawn (info, session_bus, exec_line, NULL, launch_context,
3859 _SPAWN_FLAGS_DEFAULT, NULL, NULL, NULL, NULL, NULL);
3862 if (session_bus != NULL)
3864 g_dbus_connection_flush (session_bus, NULL, NULL, NULL);
3865 g_object_unref (session_bus);