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)
875 file = g_file_new_for_uri (uri);
881 result = g_shell_quote (uri);
885 path = g_file_get_path (file);
887 result = g_shell_quote (path);
891 path = g_file_get_path (file);
894 name = g_path_get_dirname (path);
895 result = g_shell_quote (name);
901 path = g_file_get_path (file);
904 name = g_path_get_basename (path);
905 result = g_shell_quote (name);
911 g_object_unref (file);
918 expand_macro (char macro,
920 GDesktopAppInfo *info,
923 GList *uris = *uri_list;
925 gboolean force_file_uri;
926 char force_file_uri_macro;
929 g_return_if_fail (exec != NULL);
931 /* On %u and %U, pass POSIX file path pointing to the URI via
932 * the FUSE mount in ~/.gvfs. Note that if the FUSE daemon isn't
933 * running or the URI doesn't have a POSIX file path via FUSE
934 * we'll just pass the URI.
936 force_file_uri_macro = macro;
937 force_file_uri = FALSE;
943 force_file_uri_macro = 'f';
944 force_file_uri = TRUE;
947 force_file_uri_macro = 'F';
948 force_file_uri = TRUE;
964 if (!force_file_uri ||
965 /* Pass URI if it contains an anchor */
966 strchr (uri, '#') != NULL)
968 expanded = expand_macro_single (macro, uri);
972 expanded = expand_macro_single (force_file_uri_macro, uri);
973 if (expanded == NULL)
974 expanded = expand_macro_single (macro, uri);
979 g_string_append (exec, expanded);
995 if (!force_file_uri ||
996 /* Pass URI if it contains an anchor */
997 strchr (uri, '#') != NULL)
999 expanded = expand_macro_single (macro, uri);
1003 expanded = expand_macro_single (force_file_uri_macro, uri);
1004 if (expanded == NULL)
1005 expanded = expand_macro_single (macro, uri);
1010 g_string_append (exec, expanded);
1016 if (uris != NULL && expanded)
1017 g_string_append_c (exec, ' ');
1023 if (info->icon_name)
1025 g_string_append (exec, "--icon ");
1026 expanded = g_shell_quote (info->icon_name);
1027 g_string_append (exec, expanded);
1035 expanded = g_shell_quote (info->name);
1036 g_string_append (exec, expanded);
1044 expanded = g_shell_quote (info->filename);
1045 g_string_append (exec, expanded);
1050 case 'm': /* deprecated */
1054 g_string_append_c (exec, '%');
1062 expand_application_parameters (GDesktopAppInfo *info,
1063 const gchar *exec_line,
1069 GList *uri_list = *uris;
1070 const char *p = exec_line;
1071 GString *expanded_exec;
1074 if (exec_line == NULL)
1076 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
1077 _("Desktop file didn't specify Exec field"));
1081 expanded_exec = g_string_new (NULL);
1085 if (p[0] == '%' && p[1] != '\0')
1087 expand_macro (p[1], expanded_exec, info, uris);
1091 g_string_append_c (expanded_exec, *p);
1096 /* No file substitutions */
1097 if (uri_list == *uris && uri_list != NULL)
1099 /* If there is no macro default to %f. This is also what KDE does */
1100 g_string_append_c (expanded_exec, ' ');
1101 expand_macro ('f', expanded_exec, info, uris);
1104 res = g_shell_parse_argv (expanded_exec->str, argc, argv, error);
1105 g_string_free (expanded_exec, TRUE);
1110 prepend_terminal_to_vector (int *argc,
1117 char **term_argv = NULL;
1122 g_return_val_if_fail (argc != NULL, FALSE);
1123 g_return_val_if_fail (argv != NULL, FALSE);
1131 /* compute size if not given */
1134 for (i = 0; the_argv[i] != NULL; i++)
1140 term_argv = g_new0 (char *, 3);
1142 check = g_find_program_in_path ("gnome-terminal");
1145 term_argv[0] = check;
1146 /* Note that gnome-terminal takes -x and
1147 * as -e in gnome-terminal is broken we use that. */
1148 term_argv[1] = g_strdup ("-x");
1153 check = g_find_program_in_path ("nxterm");
1155 check = g_find_program_in_path ("color-xterm");
1157 check = g_find_program_in_path ("rxvt");
1159 check = g_find_program_in_path ("xterm");
1161 check = g_find_program_in_path ("dtterm");
1164 check = g_strdup ("xterm");
1165 g_warning ("couldn't find a terminal, falling back to xterm");
1167 term_argv[0] = check;
1168 term_argv[1] = g_strdup ("-e");
1171 real_argc = term_argc + *argc;
1172 real_argv = g_new (char *, real_argc + 1);
1174 for (i = 0; i < term_argc; i++)
1175 real_argv[i] = term_argv[i];
1177 for (j = 0; j < *argc; j++, i++)
1178 real_argv[i] = (char *)the_argv[j];
1180 real_argv[i] = NULL;
1186 /* we use g_free here as we sucked all the inner strings
1187 * out from it into real_argv */
1192 #endif /* G_OS_WIN32 */
1196 create_files_for_uris (GList *uris)
1203 for (iter = uris; iter; iter = iter->next)
1205 GFile *file = g_file_new_for_uri ((char *)iter->data);
1206 res = g_list_prepend (res, file);
1209 return g_list_reverse (res);
1214 GSpawnChildSetupFunc user_setup;
1215 gpointer user_setup_data;
1221 child_setup (gpointer user_data)
1223 ChildSetupData *data = user_data;
1225 if (data->pid_envvar)
1227 pid_t pid = getpid ();
1231 /* Write the pid into the space already reserved for it in the
1232 * environment array. We can't use sprintf because it might
1233 * malloc, so we do it by hand. It's simplest to write the pid
1234 * out backwards first, then copy it over.
1236 for (i = 0; pid; i++, pid /= 10)
1237 buf[i] = (pid % 10) + '0';
1238 for (i--; i >= 0; i--)
1239 *(data->pid_envvar++) = buf[i];
1240 *data->pid_envvar = '\0';
1243 if (data->user_setup)
1244 data->user_setup (data->user_setup_data);
1248 notify_desktop_launch (GDBusConnection *session_bus,
1249 GDesktopAppInfo *info,
1251 const char *display,
1256 GVariantBuilder uri_variant;
1257 GVariantBuilder extras_variant;
1259 const char *desktop_file_id;
1260 const char *gio_desktop_file;
1262 if (session_bus == NULL)
1265 g_variant_builder_init (&uri_variant, G_VARIANT_TYPE ("as"));
1266 for (iter = uris; iter; iter = iter->next)
1267 g_variant_builder_add (&uri_variant, "s", iter->data);
1269 g_variant_builder_init (&extras_variant, G_VARIANT_TYPE ("a{sv}"));
1270 if (sn_id != NULL && g_utf8_validate (sn_id, -1, NULL))
1271 g_variant_builder_add (&extras_variant, "{sv}",
1275 gio_desktop_file = g_getenv ("GIO_LAUNCHED_DESKTOP_FILE");
1276 if (gio_desktop_file != NULL)
1277 g_variant_builder_add (&extras_variant, "{sv}",
1278 "origin-desktop-file",
1279 g_variant_new_bytestring (gio_desktop_file));
1280 if (g_get_prgname () != NULL)
1281 g_variant_builder_add (&extras_variant, "{sv}",
1283 g_variant_new_bytestring (g_get_prgname ()));
1284 g_variant_builder_add (&extras_variant, "{sv}",
1287 (gint64)getpid ()));
1290 desktop_file_id = info->filename;
1291 else if (info->desktop_id)
1292 desktop_file_id = info->desktop_id;
1294 desktop_file_id = "";
1296 msg = g_dbus_message_new_signal ("/org/gtk/gio/DesktopAppInfo",
1297 "org.gtk.gio.DesktopAppInfo",
1299 g_dbus_message_set_body (msg, g_variant_new ("(@aysxasa{sv})",
1300 g_variant_new_bytestring (desktop_file_id),
1301 display ? display : "",
1305 g_dbus_connection_send_message (session_bus,
1309 g_object_unref (msg);
1312 #define _SPAWN_FLAGS_DEFAULT (G_SPAWN_SEARCH_PATH)
1315 g_desktop_app_info_launch_uris_with_spawn (GDesktopAppInfo *info,
1316 GDBusConnection *session_bus,
1317 const gchar *exec_line,
1319 GAppLaunchContext *launch_context,
1320 GSpawnFlags spawn_flags,
1321 GSpawnChildSetupFunc user_setup,
1322 gpointer user_setup_data,
1323 GDesktopAppLaunchCallback pid_callback,
1324 gpointer pid_callback_data,
1327 gboolean completed = FALSE;
1329 char **argv, **envp;
1331 ChildSetupData data;
1333 g_return_val_if_fail (info != NULL, FALSE);
1338 envp = g_app_launch_context_get_environment (launch_context);
1340 envp = g_get_environ ();
1345 GList *launched_uris;
1347 char *display, *sn_id;
1350 if (!expand_application_parameters (info, exec_line, &uris, &argc, &argv, error))
1353 /* Get the subset of URIs we're launching with this process */
1354 launched_uris = NULL;
1355 for (iter = old_uris; iter != NULL && iter != uris; iter = iter->next)
1356 launched_uris = g_list_prepend (launched_uris, iter->data);
1357 launched_uris = g_list_reverse (launched_uris);
1359 if (info->terminal && !prepend_terminal_to_vector (&argc, &argv))
1361 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
1362 _("Unable to find terminal required for application"));
1366 data.user_setup = user_setup;
1367 data.user_setup_data = user_setup_data;
1371 envp = g_environ_setenv (envp,
1372 "GIO_LAUNCHED_DESKTOP_FILE",
1375 envp = g_environ_setenv (envp,
1376 "GIO_LAUNCHED_DESKTOP_FILE_PID",
1377 "XXXXXXXXXXXXXXXXXXXX", /* filled in child_setup */
1379 data.pid_envvar = (char *)g_environ_getenv (envp, "GIO_LAUNCHED_DESKTOP_FILE_PID");
1383 data.pid_envvar = NULL;
1390 GList *launched_files = create_files_for_uris (launched_uris);
1392 display = g_app_launch_context_get_display (launch_context,
1396 envp = g_environ_setenv (envp, "DISPLAY", display, TRUE);
1398 if (info->startup_notify)
1400 sn_id = g_app_launch_context_get_startup_notify_id (launch_context,
1403 envp = g_environ_setenv (envp, "DESKTOP_STARTUP_ID", sn_id, TRUE);
1406 g_list_free_full (launched_files, g_object_unref);
1409 if (!g_spawn_async (info->path,
1419 g_app_launch_context_launch_failed (launch_context, sn_id);
1423 g_list_free (launched_uris);
1428 if (pid_callback != NULL)
1429 pid_callback (info, pid, pid_callback_data);
1431 if (launch_context != NULL)
1433 GVariantBuilder builder;
1434 GVariant *platform_data;
1436 g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
1437 g_variant_builder_add (&builder, "{sv}", "pid", g_variant_new_int32 (pid));
1439 g_variant_builder_add (&builder, "{sv}", "startup-notification-id", g_variant_new_string (sn_id));
1440 platform_data = g_variant_ref_sink (g_variant_builder_end (&builder));
1441 g_signal_emit_by_name (launch_context, "launched", info, platform_data);
1442 g_variant_unref (platform_data);
1445 notify_desktop_launch (session_bus,
1454 g_list_free (launched_uris);
1459 while (uris != NULL);
1471 object_path_from_appid (const gchar *app_id)
1476 n = strlen (app_id);
1477 path = g_malloc (n + 2);
1481 for (i = 0; i < n; i++)
1482 if (app_id[i] != '.')
1483 path[i + 1] = app_id[i];
1493 g_desktop_app_info_make_platform_data (GDesktopAppInfo *info,
1495 GAppLaunchContext *launch_context)
1497 GVariantBuilder builder;
1499 g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
1503 GList *launched_files = create_files_for_uris (uris);
1505 if (info->startup_notify)
1509 sn_id = g_app_launch_context_get_startup_notify_id (launch_context, G_APP_INFO (info), launched_files);
1510 g_variant_builder_add (&builder, "{sv}", "desktop-startup-id", g_variant_new_take_string (sn_id));
1513 g_list_free_full (launched_files, g_object_unref);
1516 return g_variant_builder_end (&builder);
1520 g_desktop_app_info_launch_uris_with_dbus (GDesktopAppInfo *info,
1521 GDBusConnection *session_bus,
1523 GAppLaunchContext *launch_context)
1525 GVariantBuilder builder;
1528 g_return_val_if_fail (info != NULL, FALSE);
1530 g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
1536 g_variant_builder_open (&builder, G_VARIANT_TYPE_STRING_ARRAY);
1537 for (iter = uris; iter; iter = iter->next)
1538 g_variant_builder_add (&builder, "s", iter->data);
1539 g_variant_builder_close (&builder);
1542 g_variant_builder_add_value (&builder, g_desktop_app_info_make_platform_data (info, uris, launch_context));
1544 /* This is non-blocking API. Similar to launching via fork()/exec()
1545 * we don't wait around to see if the program crashed during startup.
1546 * This is what startup-notification's job is...
1548 object_path = object_path_from_appid (info->app_id);
1549 g_dbus_connection_call (session_bus, info->app_id, object_path, "org.freedesktop.Application",
1550 uris ? "Open" : "Activate", g_variant_builder_end (&builder),
1551 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
1552 g_free (object_path);
1558 g_desktop_app_info_launch_uris_internal (GAppInfo *appinfo,
1560 GAppLaunchContext *launch_context,
1561 GSpawnFlags spawn_flags,
1562 GSpawnChildSetupFunc user_setup,
1563 gpointer user_setup_data,
1564 GDesktopAppLaunchCallback pid_callback,
1565 gpointer pid_callback_data,
1568 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1569 GDBusConnection *session_bus;
1570 gboolean success = TRUE;
1572 session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
1574 if (session_bus && info->app_id)
1575 g_desktop_app_info_launch_uris_with_dbus (info, session_bus, uris, launch_context);
1577 success = g_desktop_app_info_launch_uris_with_spawn (info, session_bus, info->exec, uris, launch_context,
1578 spawn_flags, user_setup, user_setup_data,
1579 pid_callback, pid_callback_data, error);
1581 if (session_bus != NULL)
1583 /* This asynchronous flush holds a reference until it completes,
1584 * which ensures that the following unref won't immediately kill
1585 * the connection if we were the initial owner.
1587 g_dbus_connection_flush (session_bus, NULL, NULL, NULL);
1588 g_object_unref (session_bus);
1595 g_desktop_app_info_launch_uris (GAppInfo *appinfo,
1597 GAppLaunchContext *launch_context,
1600 return g_desktop_app_info_launch_uris_internal (appinfo, uris,
1602 _SPAWN_FLAGS_DEFAULT,
1603 NULL, NULL, NULL, NULL,
1608 g_desktop_app_info_supports_uris (GAppInfo *appinfo)
1610 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1612 return info->exec &&
1613 ((strstr (info->exec, "%u") != NULL) ||
1614 (strstr (info->exec, "%U") != NULL));
1618 g_desktop_app_info_supports_files (GAppInfo *appinfo)
1620 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1622 return info->exec &&
1623 ((strstr (info->exec, "%f") != NULL) ||
1624 (strstr (info->exec, "%F") != NULL));
1628 g_desktop_app_info_launch (GAppInfo *appinfo,
1630 GAppLaunchContext *launch_context,
1640 uri = g_file_get_uri (files->data);
1641 uris = g_list_prepend (uris, uri);
1642 files = files->next;
1645 uris = g_list_reverse (uris);
1647 res = g_desktop_app_info_launch_uris (appinfo, uris, launch_context, error);
1649 g_list_free_full (uris, g_free);
1655 * g_desktop_app_info_launch_uris_as_manager:
1656 * @appinfo: a #GDesktopAppInfo
1657 * @uris: (element-type utf8): List of URIs
1658 * @launch_context: a #GAppLaunchContext
1659 * @spawn_flags: #GSpawnFlags, used for each process
1660 * @user_setup: (scope call): a #GSpawnChildSetupFunc, used once for
1662 * @user_setup_data: (closure user_setup): User data for @user_setup
1663 * @pid_callback: (scope call): Callback for child processes
1664 * @pid_callback_data: (closure pid_callback): User data for @callback
1665 * @error: return location for a #GError, or %NULL
1667 * This function performs the equivalent of g_app_info_launch_uris(),
1668 * but is intended primarily for operating system components that
1669 * launch applications. Ordinary applications should use
1670 * g_app_info_launch_uris().
1672 * If the application is launched via traditional UNIX fork()/exec()
1673 * then @spawn_flags, @user_setup and @user_setup_data are used for the
1674 * call to g_spawn_async(). Additionally, @pid_callback (with
1675 * @pid_callback_data) will be called to inform about the PID of the
1678 * If application launching occurs via some other mechanism (eg: D-Bus
1679 * activation) then @spawn_flags, @user_setup, @user_setup_data,
1680 * @pid_callback and @pid_callback_data are ignored.
1682 * Returns: %TRUE on successful launch, %FALSE otherwise.
1685 g_desktop_app_info_launch_uris_as_manager (GDesktopAppInfo *appinfo,
1687 GAppLaunchContext *launch_context,
1688 GSpawnFlags spawn_flags,
1689 GSpawnChildSetupFunc user_setup,
1690 gpointer user_setup_data,
1691 GDesktopAppLaunchCallback pid_callback,
1692 gpointer pid_callback_data,
1695 return g_desktop_app_info_launch_uris_internal ((GAppInfo*)appinfo,
1707 * g_desktop_app_info_set_desktop_env:
1708 * @desktop_env: a string specifying what desktop this is
1710 * Sets the name of the desktop that the application is running in.
1711 * This is used by g_app_info_should_show() and
1712 * g_desktop_app_info_get_show_in() to evaluate the
1713 * <literal>OnlyShowIn</literal> and <literal>NotShowIn</literal>
1714 * desktop entry fields.
1716 * The <ulink url="http://standards.freedesktop.org/menu-spec/latest/">Desktop
1717 * Menu specification</ulink> recognizes the following:
1719 * <member>GNOME</member>
1720 * <member>KDE</member>
1721 * <member>ROX</member>
1722 * <member>XFCE</member>
1723 * <member>LXDE</member>
1724 * <member>Unity</member>
1725 * <member>Old</member>
1728 * Should be called only once; subsequent calls are ignored.
1731 g_desktop_app_info_set_desktop_env (const gchar *desktop_env)
1733 G_LOCK (g_desktop_env);
1735 g_desktop_env = g_strdup (desktop_env);
1736 G_UNLOCK (g_desktop_env);
1740 g_desktop_app_info_should_show (GAppInfo *appinfo)
1742 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1744 if (info->nodisplay)
1747 return g_desktop_app_info_get_show_in (info, NULL);
1756 ensure_dir (DirType type,
1759 char *path, *display_name;
1762 if (type == APP_DIR)
1763 path = g_build_filename (g_get_user_data_dir (), "applications", NULL);
1765 path = g_build_filename (g_get_user_data_dir (), "mime", "packages", NULL);
1768 if (g_mkdir_with_parents (path, 0700) == 0)
1772 display_name = g_filename_display_name (path);
1773 if (type == APP_DIR)
1774 g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
1775 _("Can't create user application configuration folder %s: %s"),
1776 display_name, g_strerror (errsv));
1778 g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
1779 _("Can't create user MIME configuration folder %s: %s"),
1780 display_name, g_strerror (errsv));
1782 g_free (display_name);
1789 update_mimeapps_list (const char *desktop_id,
1790 const char *content_type,
1791 UpdateMimeFlags flags,
1794 char *dirname, *filename, *string;
1796 gboolean load_succeeded, res;
1797 char **old_list, **list;
1798 gsize length, data_size;
1801 char **content_types;
1803 /* Don't add both at start and end */
1804 g_assert (!((flags & UPDATE_MIME_SET_DEFAULT) &&
1805 (flags & UPDATE_MIME_SET_NON_DEFAULT)));
1807 dirname = ensure_dir (APP_DIR, error);
1811 filename = g_build_filename (dirname, "mimeapps.list", NULL);
1814 key_file = g_key_file_new ();
1815 load_succeeded = g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL);
1816 if (!load_succeeded ||
1817 (!g_key_file_has_group (key_file, ADDED_ASSOCIATIONS_GROUP) &&
1818 !g_key_file_has_group (key_file, REMOVED_ASSOCIATIONS_GROUP) &&
1819 !g_key_file_has_group (key_file, DEFAULT_APPLICATIONS_GROUP)))
1821 g_key_file_free (key_file);
1822 key_file = g_key_file_new ();
1827 content_types = g_new (char *, 2);
1828 content_types[0] = g_strdup (content_type);
1829 content_types[1] = NULL;
1833 content_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP, NULL, NULL);
1836 for (k = 0; content_types && content_types[k]; k++)
1838 /* set as default, if requested so */
1839 string = g_key_file_get_string (key_file,
1840 DEFAULT_APPLICATIONS_GROUP,
1844 if (g_strcmp0 (string, desktop_id) != 0 &&
1845 (flags & UPDATE_MIME_SET_DEFAULT))
1848 string = g_strdup (desktop_id);
1850 /* add in the non-default list too, if it's not already there */
1851 flags |= UPDATE_MIME_SET_NON_DEFAULT;
1854 if (string == NULL || desktop_id == NULL)
1855 g_key_file_remove_key (key_file,
1856 DEFAULT_APPLICATIONS_GROUP,
1860 g_key_file_set_string (key_file,
1861 DEFAULT_APPLICATIONS_GROUP,
1870 /* reuse the list from above */
1874 g_strfreev (content_types);
1875 content_types = g_key_file_get_keys (key_file, ADDED_ASSOCIATIONS_GROUP, NULL, NULL);
1878 for (k = 0; content_types && content_types[k]; k++)
1880 /* Add to the right place in the list */
1883 old_list = g_key_file_get_string_list (key_file, ADDED_ASSOCIATIONS_GROUP,
1884 content_types[k], &length, NULL);
1886 list = g_new (char *, 1 + length + 1);
1890 /* if we're adding a last-used hint, just put the application in front of the list */
1891 if (flags & UPDATE_MIME_SET_LAST_USED)
1893 /* avoid adding this again as non-default later */
1894 if (flags & UPDATE_MIME_SET_NON_DEFAULT)
1895 flags ^= UPDATE_MIME_SET_NON_DEFAULT;
1897 list[i++] = g_strdup (desktop_id);
1902 for (j = 0; old_list[j] != NULL; j++)
1904 if (g_strcmp0 (old_list[j], desktop_id) != 0)
1906 /* rewrite other entries if they're different from the new one */
1907 list[i++] = g_strdup (old_list[j]);
1909 else if (flags & UPDATE_MIME_SET_NON_DEFAULT)
1911 /* we encountered an old entry which is equal to the one we're adding as non-default,
1912 * don't change its position in the list.
1914 flags ^= UPDATE_MIME_SET_NON_DEFAULT;
1915 list[i++] = g_strdup (old_list[j]);
1920 /* add it at the end of the list */
1921 if (flags & UPDATE_MIME_SET_NON_DEFAULT)
1922 list[i++] = g_strdup (desktop_id);
1926 g_strfreev (old_list);
1928 if (list[0] == NULL || desktop_id == NULL)
1929 g_key_file_remove_key (key_file,
1930 ADDED_ASSOCIATIONS_GROUP,
1934 g_key_file_set_string_list (key_file,
1935 ADDED_ASSOCIATIONS_GROUP,
1937 (const char * const *)list, i);
1944 /* reuse the list from above */
1948 g_strfreev (content_types);
1949 content_types = g_key_file_get_keys (key_file, REMOVED_ASSOCIATIONS_GROUP, NULL, NULL);
1952 for (k = 0; content_types && content_types[k]; k++)
1954 /* Remove from removed associations group (unless remove) */
1957 old_list = g_key_file_get_string_list (key_file, REMOVED_ASSOCIATIONS_GROUP,
1958 content_types[k], &length, NULL);
1960 list = g_new (char *, 1 + length + 1);
1963 if (flags & UPDATE_MIME_REMOVE)
1964 list[i++] = g_strdup (desktop_id);
1967 for (j = 0; old_list[j] != NULL; j++)
1969 if (g_strcmp0 (old_list[j], desktop_id) != 0)
1970 list[i++] = g_strdup (old_list[j]);
1975 g_strfreev (old_list);
1977 if (list[0] == NULL || desktop_id == NULL)
1978 g_key_file_remove_key (key_file,
1979 REMOVED_ASSOCIATIONS_GROUP,
1983 g_key_file_set_string_list (key_file,
1984 REMOVED_ASSOCIATIONS_GROUP,
1986 (const char * const *)list, i);
1991 g_strfreev (content_types);
1993 data = g_key_file_to_data (key_file, &data_size, error);
1994 g_key_file_free (key_file);
1996 res = g_file_set_contents (filename, data, data_size, error);
1998 mime_info_cache_reload (NULL);
2007 g_desktop_app_info_set_as_last_used_for_type (GAppInfo *appinfo,
2008 const char *content_type,
2011 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2013 if (!g_desktop_app_info_ensure_saved (info, error))
2016 if (!info->desktop_id)
2018 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
2019 _("Application information lacks an identifier"));
2023 /* both add support for the content type and set as last used */
2024 return update_mimeapps_list (info->desktop_id, content_type,
2025 UPDATE_MIME_SET_NON_DEFAULT |
2026 UPDATE_MIME_SET_LAST_USED,
2031 g_desktop_app_info_set_as_default_for_type (GAppInfo *appinfo,
2032 const char *content_type,
2035 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2037 if (!g_desktop_app_info_ensure_saved (info, error))
2040 if (!info->desktop_id)
2042 g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
2043 _("Application information lacks an identifier"));
2047 return update_mimeapps_list (info->desktop_id, content_type,
2048 UPDATE_MIME_SET_DEFAULT,
2053 update_program_done (GPid pid,
2057 /* Did the application exit correctly */
2058 if (g_spawn_check_exit_status (status, NULL))
2060 /* Here we could clean out any caches in use */
2065 run_update_command (char *command,
2074 GError *error = NULL;
2077 argv[1] = g_build_filename (g_get_user_data_dir (), subdir, NULL);
2079 if (g_spawn_async ("/", argv,
2081 G_SPAWN_SEARCH_PATH |
2082 G_SPAWN_STDOUT_TO_DEV_NULL |
2083 G_SPAWN_STDERR_TO_DEV_NULL |
2084 G_SPAWN_DO_NOT_REAP_CHILD,
2085 NULL, NULL, /* No setup function */
2088 g_child_watch_add (pid, update_program_done, NULL);
2091 /* If we get an error at this point, it's quite likely the user doesn't
2092 * have an installed copy of either 'update-mime-database' or
2093 * 'update-desktop-database'. I don't think we want to popup an error
2094 * dialog at this point, so we just do a g_warning to give the user a
2095 * chance of debugging it.
2097 g_warning ("%s", error->message);
2104 g_desktop_app_info_set_as_default_for_extension (GAppInfo *appinfo,
2105 const char *extension,
2108 char *filename, *basename, *mimetype;
2112 if (!g_desktop_app_info_ensure_saved (G_DESKTOP_APP_INFO (appinfo), error))
2115 dirname = ensure_dir (MIMETYPE_DIR, error);
2119 basename = g_strdup_printf ("user-extension-%s.xml", extension);
2120 filename = g_build_filename (dirname, basename, NULL);
2124 mimetype = g_strdup_printf ("application/x-extension-%s", extension);
2126 if (!g_file_test (filename, G_FILE_TEST_EXISTS))
2131 g_strdup_printf ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
2132 "<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">\n"
2133 " <mime-type type=\"%s\">\n"
2134 " <comment>%s document</comment>\n"
2135 " <glob pattern=\"*.%s\"/>\n"
2137 "</mime-info>\n", mimetype, extension, extension);
2139 g_file_set_contents (filename, contents, -1, NULL);
2142 run_update_command ("update-mime-database", "mime");
2146 res = g_desktop_app_info_set_as_default_for_type (appinfo,
2156 g_desktop_app_info_add_supports_type (GAppInfo *appinfo,
2157 const char *content_type,
2160 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2162 if (!g_desktop_app_info_ensure_saved (G_DESKTOP_APP_INFO (info), error))
2165 return update_mimeapps_list (info->desktop_id, content_type,
2166 UPDATE_MIME_SET_NON_DEFAULT,
2171 g_desktop_app_info_can_remove_supports_type (GAppInfo *appinfo)
2177 g_desktop_app_info_remove_supports_type (GAppInfo *appinfo,
2178 const char *content_type,
2181 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2183 if (!g_desktop_app_info_ensure_saved (G_DESKTOP_APP_INFO (info), error))
2186 return update_mimeapps_list (info->desktop_id, content_type,
2191 static const char **
2192 g_desktop_app_info_get_supported_types (GAppInfo *appinfo)
2194 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2196 return (const char**) info->mime_types;
2201 g_desktop_app_info_ensure_saved (GDesktopAppInfo *info,
2207 char *data, *desktop_id;
2212 if (info->filename != NULL)
2215 /* This is only used for object created with
2216 * g_app_info_create_from_commandline. All other
2217 * object should have a filename
2220 dirname = ensure_dir (APP_DIR, error);
2224 key_file = g_key_file_new ();
2226 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2227 "Encoding", "UTF-8");
2228 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2229 G_KEY_FILE_DESKTOP_KEY_VERSION, "1.0");
2230 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2231 G_KEY_FILE_DESKTOP_KEY_TYPE,
2232 G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
2234 g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
2235 G_KEY_FILE_DESKTOP_KEY_TERMINAL, TRUE);
2236 if (info->nodisplay)
2237 g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
2238 G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, TRUE);
2240 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2241 G_KEY_FILE_DESKTOP_KEY_EXEC, info->exec);
2243 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2244 G_KEY_FILE_DESKTOP_KEY_NAME, info->name);
2246 if (info->generic_name != NULL)
2247 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2248 GENERIC_NAME_KEY, info->generic_name);
2250 if (info->fullname != NULL)
2251 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2252 FULL_NAME_KEY, info->fullname);
2254 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
2255 G_KEY_FILE_DESKTOP_KEY_COMMENT, info->comment);
2257 g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
2258 G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, TRUE);
2260 data = g_key_file_to_data (key_file, &data_size, NULL);
2261 g_key_file_free (key_file);
2263 desktop_id = g_strdup_printf ("userapp-%s-XXXXXX.desktop", info->name);
2264 filename = g_build_filename (dirname, desktop_id, NULL);
2265 g_free (desktop_id);
2268 fd = g_mkstemp (filename);
2273 display_name = g_filename_display_name (filename);
2274 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
2275 _("Can't create user desktop file %s"), display_name);
2276 g_free (display_name);
2282 desktop_id = g_path_get_basename (filename);
2284 /* FIXME - actually handle error */
2285 (void) g_close (fd, NULL);
2287 res = g_file_set_contents (filename, data, data_size, error);
2291 g_free (desktop_id);
2296 info->filename = filename;
2297 info->desktop_id = desktop_id;
2299 run_update_command ("update-desktop-database", "applications");
2305 g_desktop_app_info_can_delete (GAppInfo *appinfo)
2307 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2311 if (strstr (info->filename, "/userapp-"))
2312 return g_access (info->filename, W_OK) == 0;
2319 g_desktop_app_info_delete (GAppInfo *appinfo)
2321 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
2325 if (g_remove (info->filename) == 0)
2327 update_mimeapps_list (info->desktop_id, NULL,
2331 g_free (info->filename);
2332 info->filename = NULL;
2333 g_free (info->desktop_id);
2334 info->desktop_id = NULL;
2344 * g_app_info_create_from_commandline:
2345 * @commandline: the commandline to use
2346 * @application_name: (allow-none): the application name, or %NULL to use @commandline
2347 * @flags: flags that can specify details of the created #GAppInfo
2348 * @error: a #GError location to store the error occurring, %NULL to ignore.
2350 * Creates a new #GAppInfo from the given information.
2352 * Note that for @commandline, the quoting rules of the Exec key of the
2353 * <ulink url="http://freedesktop.org/Standards/desktop-entry-spec">freedesktop.org Desktop
2354 * Entry Specification</ulink> are applied. For example, if the @commandline contains
2355 * percent-encoded URIs, the percent-character must be doubled in order to prevent it from
2356 * being swallowed by Exec key unquoting. See the specification for exact quoting rules.
2358 * Returns: (transfer full): new #GAppInfo for given command.
2361 g_app_info_create_from_commandline (const char *commandline,
2362 const char *application_name,
2363 GAppInfoCreateFlags flags,
2368 GDesktopAppInfo *info;
2370 g_return_val_if_fail (commandline, NULL);
2372 info = g_object_new (G_TYPE_DESKTOP_APP_INFO, NULL);
2374 info->filename = NULL;
2375 info->desktop_id = NULL;
2377 info->terminal = (flags & G_APP_INFO_CREATE_NEEDS_TERMINAL) != 0;
2378 info->startup_notify = (flags & G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION) != 0;
2379 info->hidden = FALSE;
2380 if ((flags & G_APP_INFO_CREATE_SUPPORTS_URIS) != 0)
2381 info->exec = g_strconcat (commandline, " %u", NULL);
2383 info->exec = g_strconcat (commandline, " %f", NULL);
2384 info->nodisplay = TRUE;
2385 info->binary = binary_from_exec (info->exec);
2387 if (application_name)
2388 info->name = g_strdup (application_name);
2391 /* FIXME: this should be more robust. Maybe g_shell_parse_argv and use argv[0] */
2392 split = g_strsplit (commandline, " ", 2);
2393 basename = split[0] ? g_path_get_basename (split[0]) : NULL;
2395 info->name = basename;
2396 if (info->name == NULL)
2397 info->name = g_strdup ("custom");
2399 info->comment = g_strdup_printf (_("Custom definition for %s"), info->name);
2401 return G_APP_INFO (info);
2405 g_desktop_app_info_iface_init (GAppInfoIface *iface)
2407 iface->dup = g_desktop_app_info_dup;
2408 iface->equal = g_desktop_app_info_equal;
2409 iface->get_id = g_desktop_app_info_get_id;
2410 iface->get_name = g_desktop_app_info_get_name;
2411 iface->get_description = g_desktop_app_info_get_description;
2412 iface->get_executable = g_desktop_app_info_get_executable;
2413 iface->get_icon = g_desktop_app_info_get_icon;
2414 iface->launch = g_desktop_app_info_launch;
2415 iface->supports_uris = g_desktop_app_info_supports_uris;
2416 iface->supports_files = g_desktop_app_info_supports_files;
2417 iface->launch_uris = g_desktop_app_info_launch_uris;
2418 iface->should_show = g_desktop_app_info_should_show;
2419 iface->set_as_default_for_type = g_desktop_app_info_set_as_default_for_type;
2420 iface->set_as_default_for_extension = g_desktop_app_info_set_as_default_for_extension;
2421 iface->add_supports_type = g_desktop_app_info_add_supports_type;
2422 iface->can_remove_supports_type = g_desktop_app_info_can_remove_supports_type;
2423 iface->remove_supports_type = g_desktop_app_info_remove_supports_type;
2424 iface->can_delete = g_desktop_app_info_can_delete;
2425 iface->do_delete = g_desktop_app_info_delete;
2426 iface->get_commandline = g_desktop_app_info_get_commandline;
2427 iface->get_display_name = g_desktop_app_info_get_display_name;
2428 iface->set_as_last_used_for_type = g_desktop_app_info_set_as_last_used_for_type;
2429 iface->get_supported_types = g_desktop_app_info_get_supported_types;
2433 app_info_in_list (GAppInfo *info,
2436 while (list != NULL)
2438 if (g_app_info_equal (info, list->data))
2446 * g_app_info_get_recommended_for_type:
2447 * @content_type: the content type to find a #GAppInfo for
2449 * Gets a list of recommended #GAppInfos for a given content type, i.e.
2450 * those applications which claim to support the given content type exactly,
2451 * and not by MIME type subclassing.
2452 * Note that the first application of the list is the last used one, i.e.
2453 * the last one for which g_app_info_set_as_last_used_for_type() has been
2456 * Returns: (element-type GAppInfo) (transfer full): #GList of #GAppInfos
2457 * for given @content_type or %NULL on error.
2462 g_app_info_get_recommended_for_type (const gchar *content_type)
2464 GList *desktop_entries, *l;
2466 GDesktopAppInfo *info;
2468 g_return_val_if_fail (content_type != NULL, NULL);
2470 desktop_entries = get_all_desktop_entries_for_mime_type (content_type, NULL, FALSE, NULL);
2473 for (l = desktop_entries; l != NULL; l = l->next)
2475 char *desktop_entry = l->data;
2477 info = g_desktop_app_info_new (desktop_entry);
2480 if (app_info_in_list (G_APP_INFO (info), infos))
2481 g_object_unref (info);
2483 infos = g_list_prepend (infos, info);
2485 g_free (desktop_entry);
2488 g_list_free (desktop_entries);
2490 return g_list_reverse (infos);
2494 * g_app_info_get_fallback_for_type:
2495 * @content_type: the content type to find a #GAppInfo for
2497 * Gets a list of fallback #GAppInfos for a given content type, i.e.
2498 * those applications which claim to support the given content type
2499 * by MIME type subclassing and not directly.
2501 * Returns: (element-type GAppInfo) (transfer full): #GList of #GAppInfos
2502 * for given @content_type or %NULL on error.
2507 g_app_info_get_fallback_for_type (const gchar *content_type)
2509 GList *desktop_entries, *l;
2510 GList *infos, *recommended_infos;
2511 GDesktopAppInfo *info;
2513 g_return_val_if_fail (content_type != NULL, NULL);
2515 desktop_entries = get_all_desktop_entries_for_mime_type (content_type, NULL, TRUE, NULL);
2516 recommended_infos = g_app_info_get_recommended_for_type (content_type);
2519 for (l = desktop_entries; l != NULL; l = l->next)
2521 char *desktop_entry = l->data;
2523 info = g_desktop_app_info_new (desktop_entry);
2526 if (app_info_in_list (G_APP_INFO (info), infos) ||
2527 app_info_in_list (G_APP_INFO (info), recommended_infos))
2528 g_object_unref (info);
2530 infos = g_list_prepend (infos, info);
2532 g_free (desktop_entry);
2535 g_list_free (desktop_entries);
2536 g_list_free_full (recommended_infos, g_object_unref);
2538 return g_list_reverse (infos);
2542 * g_app_info_get_all_for_type:
2543 * @content_type: the content type to find a #GAppInfo for
2545 * Gets a list of all #GAppInfos for a given content type,
2546 * including the recommended and fallback #GAppInfos. See
2547 * g_app_info_get_recommended_for_type() and
2548 * g_app_info_get_fallback_for_type().
2550 * Returns: (element-type GAppInfo) (transfer full): #GList of #GAppInfos
2551 * for given @content_type or %NULL on error.
2554 g_app_info_get_all_for_type (const char *content_type)
2556 GList *desktop_entries, *l;
2558 char *user_default = NULL;
2559 GDesktopAppInfo *info;
2561 g_return_val_if_fail (content_type != NULL, NULL);
2563 desktop_entries = get_all_desktop_entries_for_mime_type (content_type, NULL, TRUE, &user_default);
2566 /* put the user default in front of the list, for compatibility */
2567 if (user_default != NULL)
2569 info = g_desktop_app_info_new (user_default);
2572 infos = g_list_prepend (infos, info);
2575 g_free (user_default);
2577 for (l = desktop_entries; l != NULL; l = l->next)
2579 char *desktop_entry = l->data;
2581 info = g_desktop_app_info_new (desktop_entry);
2584 if (app_info_in_list (G_APP_INFO (info), infos))
2585 g_object_unref (info);
2587 infos = g_list_prepend (infos, info);
2589 g_free (desktop_entry);
2592 g_list_free (desktop_entries);
2594 return g_list_reverse (infos);
2598 * g_app_info_reset_type_associations:
2599 * @content_type: a content type
2601 * Removes all changes to the type associations done by
2602 * g_app_info_set_as_default_for_type(),
2603 * g_app_info_set_as_default_for_extension(),
2604 * g_app_info_add_supports_type() or
2605 * g_app_info_remove_supports_type().
2610 g_app_info_reset_type_associations (const char *content_type)
2612 update_mimeapps_list (NULL, content_type,
2618 * g_app_info_get_default_for_type:
2619 * @content_type: the content type to find a #GAppInfo for
2620 * @must_support_uris: if %TRUE, the #GAppInfo is expected to
2623 * Gets the default #GAppInfo for a given content type.
2625 * Returns: (transfer full): #GAppInfo for given @content_type or
2629 g_app_info_get_default_for_type (const char *content_type,
2630 gboolean must_support_uris)
2632 GList *desktop_entries, *l;
2633 char *user_default = NULL;
2636 g_return_val_if_fail (content_type != NULL, NULL);
2638 desktop_entries = get_all_desktop_entries_for_mime_type (content_type, NULL, TRUE, &user_default);
2642 if (user_default != NULL)
2644 info = (GAppInfo *) g_desktop_app_info_new (user_default);
2648 if (must_support_uris && !g_app_info_supports_uris (info))
2650 g_object_unref (info);
2656 g_free (user_default);
2660 g_list_free_full (desktop_entries, g_free);
2664 /* pick the first from the other list that matches our URI
2667 for (l = desktop_entries; l != NULL; l = l->next)
2669 char *desktop_entry = l->data;
2671 info = (GAppInfo *)g_desktop_app_info_new (desktop_entry);
2674 if (must_support_uris && !g_app_info_supports_uris (info))
2676 g_object_unref (info);
2684 g_list_free_full (desktop_entries, g_free);
2690 * g_app_info_get_default_for_uri_scheme:
2691 * @uri_scheme: a string containing a URI scheme.
2693 * Gets the default application for handling URIs with
2694 * the given URI scheme. A URI scheme is the initial part
2695 * of the URI, up to but not including the ':', e.g. "http",
2698 * Returns: (transfer full): #GAppInfo for given @uri_scheme or %NULL on error.
2701 g_app_info_get_default_for_uri_scheme (const char *uri_scheme)
2704 char *content_type, *scheme_down;
2706 scheme_down = g_ascii_strdown (uri_scheme, -1);
2707 content_type = g_strdup_printf ("x-scheme-handler/%s", scheme_down);
2708 g_free (scheme_down);
2709 app_info = g_app_info_get_default_for_type (content_type, FALSE);
2710 g_free (content_type);
2716 get_apps_from_dir (GHashTable *apps,
2717 const char *dirname,
2721 const char *basename;
2722 char *filename, *subprefix, *desktop_id;
2724 GDesktopAppInfo *appinfo;
2726 dir = g_dir_open (dirname, 0, NULL);
2729 while ((basename = g_dir_read_name (dir)) != NULL)
2731 filename = g_build_filename (dirname, basename, NULL);
2732 if (g_str_has_suffix (basename, ".desktop"))
2734 desktop_id = g_strconcat (prefix, basename, NULL);
2736 /* Use _extended so we catch NULLs too (hidden) */
2737 if (!g_hash_table_lookup_extended (apps, desktop_id, NULL, NULL))
2739 appinfo = g_desktop_app_info_new_from_filename (filename);
2742 if (appinfo && g_desktop_app_info_get_is_hidden (appinfo))
2744 g_object_unref (appinfo);
2749 if (appinfo || hidden)
2751 g_hash_table_insert (apps, g_strdup (desktop_id), appinfo);
2755 /* Reuse instead of strdup here */
2756 appinfo->desktop_id = desktop_id;
2761 g_free (desktop_id);
2765 if (g_file_test (filename, G_FILE_TEST_IS_DIR))
2767 subprefix = g_strconcat (prefix, basename, "-", NULL);
2768 get_apps_from_dir (apps, filename, subprefix);
2780 * g_app_info_get_all:
2782 * Gets a list of all of the applications currently registered
2785 * For desktop files, this includes applications that have
2786 * <literal>NoDisplay=true</literal> set or are excluded from
2787 * display by means of <literal>OnlyShowIn</literal> or
2788 * <literal>NotShowIn</literal>. See g_app_info_should_show().
2789 * The returned list does not include applications which have
2790 * the <literal>Hidden</literal> key set.
2792 * Returns: (element-type GAppInfo) (transfer full): a newly allocated #GList of references to #GAppInfo<!---->s.
2795 g_app_info_get_all (void)
2797 const char * const *dirs;
2799 GHashTableIter iter;
2804 dirs = get_applications_search_path ();
2806 apps = g_hash_table_new_full (g_str_hash, g_str_equal,
2810 for (i = 0; dirs[i] != NULL; i++)
2811 get_apps_from_dir (apps, dirs[i], "");
2815 g_hash_table_iter_init (&iter, apps);
2816 while (g_hash_table_iter_next (&iter, NULL, &value))
2819 infos = g_list_prepend (infos, value);
2822 g_hash_table_destroy (apps);
2824 return g_list_reverse (infos);
2827 /* Cacheing of mimeinfo.cache and defaults.list files */
2831 GHashTable *mime_info_cache_map;
2832 GHashTable *defaults_list_map;
2833 GHashTable *mimeapps_list_added_map;
2834 GHashTable *mimeapps_list_removed_map;
2835 GHashTable *mimeapps_list_defaults_map;
2836 time_t mime_info_cache_timestamp;
2837 time_t defaults_list_timestamp;
2838 time_t mimeapps_list_timestamp;
2842 GList *dirs; /* mimeinfo.cache and defaults.list */
2843 GHashTable *global_defaults_cache; /* global results of defaults.list lookup and validation */
2844 time_t last_stat_time;
2845 guint should_ping_mime_monitor : 1;
2848 static MimeInfoCache *mime_info_cache = NULL;
2849 G_LOCK_DEFINE_STATIC (mime_info_cache);
2851 static void mime_info_cache_dir_add_desktop_entries (MimeInfoCacheDir *dir,
2852 const char *mime_type,
2853 char **new_desktop_file_ids);
2855 static MimeInfoCache * mime_info_cache_new (void);
2858 destroy_info_cache_value (gpointer key,
2862 g_list_free_full (value, g_free);
2866 destroy_info_cache_map (GHashTable *info_cache_map)
2868 g_hash_table_foreach (info_cache_map, (GHFunc)destroy_info_cache_value, NULL);
2869 g_hash_table_destroy (info_cache_map);
2873 mime_info_cache_dir_out_of_date (MimeInfoCacheDir *dir,
2874 const char *cache_file,
2880 filename = g_build_filename (dir->path, cache_file, NULL);
2882 if (g_stat (filename, &buf) < 0)
2889 if (buf.st_mtime != *timestamp)
2895 /* Call with lock held */
2897 remove_all (gpointer key,
2906 mime_info_cache_blow_global_cache (void)
2908 g_hash_table_foreach_remove (mime_info_cache->global_defaults_cache,
2913 mime_info_cache_dir_init (MimeInfoCacheDir *dir)
2917 gchar *filename, **mime_types;
2924 if (dir->mime_info_cache_map != NULL &&
2925 !mime_info_cache_dir_out_of_date (dir, "mimeinfo.cache",
2926 &dir->mime_info_cache_timestamp))
2929 if (dir->mime_info_cache_map != NULL)
2930 destroy_info_cache_map (dir->mime_info_cache_map);
2932 dir->mime_info_cache_map = g_hash_table_new_full (g_str_hash, g_str_equal,
2933 (GDestroyNotify) g_free,
2936 key_file = g_key_file_new ();
2938 filename = g_build_filename (dir->path, "mimeinfo.cache", NULL);
2940 if (g_stat (filename, &buf) < 0)
2943 if (dir->mime_info_cache_timestamp > 0)
2944 mime_info_cache->should_ping_mime_monitor = TRUE;
2946 dir->mime_info_cache_timestamp = buf.st_mtime;
2948 g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &load_error);
2953 if (load_error != NULL)
2956 mime_types = g_key_file_get_keys (key_file, MIME_CACHE_GROUP,
2959 if (load_error != NULL)
2962 for (i = 0; mime_types[i] != NULL; i++)
2964 gchar **desktop_file_ids;
2965 char *unaliased_type;
2966 desktop_file_ids = g_key_file_get_string_list (key_file,
2972 if (desktop_file_ids == NULL)
2975 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
2976 mime_info_cache_dir_add_desktop_entries (dir,
2979 g_free (unaliased_type);
2981 g_strfreev (desktop_file_ids);
2984 g_strfreev (mime_types);
2985 g_key_file_free (key_file);
2990 g_key_file_free (key_file);
2992 if (mime_types != NULL)
2993 g_strfreev (mime_types);
2996 g_error_free (load_error);
3000 mime_info_cache_dir_init_defaults_list (MimeInfoCacheDir *dir)
3004 gchar *filename, **mime_types;
3005 char *unaliased_type;
3006 char **desktop_file_ids;
3013 if (dir->defaults_list_map != NULL &&
3014 !mime_info_cache_dir_out_of_date (dir, "defaults.list",
3015 &dir->defaults_list_timestamp))
3018 if (dir->defaults_list_map != NULL)
3019 g_hash_table_destroy (dir->defaults_list_map);
3020 dir->defaults_list_map = g_hash_table_new_full (g_str_hash, g_str_equal,
3021 g_free, (GDestroyNotify)g_strfreev);
3024 key_file = g_key_file_new ();
3026 filename = g_build_filename (dir->path, "defaults.list", NULL);
3027 if (g_stat (filename, &buf) < 0)
3030 if (dir->defaults_list_timestamp > 0)
3031 mime_info_cache->should_ping_mime_monitor = TRUE;
3033 dir->defaults_list_timestamp = buf.st_mtime;
3035 g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &load_error);
3039 if (load_error != NULL)
3042 mime_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP,
3044 if (mime_types != NULL)
3046 for (i = 0; mime_types[i] != NULL; i++)
3048 desktop_file_ids = g_key_file_get_string_list (key_file,
3049 DEFAULT_APPLICATIONS_GROUP,
3053 if (desktop_file_ids == NULL)
3056 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
3057 g_hash_table_replace (dir->defaults_list_map,
3062 g_strfreev (mime_types);
3065 g_key_file_free (key_file);
3070 g_key_file_free (key_file);
3072 if (mime_types != NULL)
3073 g_strfreev (mime_types);
3076 g_error_free (load_error);
3080 mime_info_cache_dir_init_mimeapps_list (MimeInfoCacheDir *dir)
3084 gchar *filename, **mime_types;
3085 char *unaliased_type;
3086 char **desktop_file_ids;
3094 if (dir->mimeapps_list_added_map != NULL &&
3095 !mime_info_cache_dir_out_of_date (dir, "mimeapps.list",
3096 &dir->mimeapps_list_timestamp))
3099 if (dir->mimeapps_list_added_map != NULL)
3100 g_hash_table_destroy (dir->mimeapps_list_added_map);
3101 dir->mimeapps_list_added_map = g_hash_table_new_full (g_str_hash, g_str_equal,
3102 g_free, (GDestroyNotify)g_strfreev);
3104 if (dir->mimeapps_list_removed_map != NULL)
3105 g_hash_table_destroy (dir->mimeapps_list_removed_map);
3106 dir->mimeapps_list_removed_map = g_hash_table_new_full (g_str_hash, g_str_equal,
3107 g_free, (GDestroyNotify)g_strfreev);
3109 if (dir->mimeapps_list_defaults_map != NULL)
3110 g_hash_table_destroy (dir->mimeapps_list_defaults_map);
3111 dir->mimeapps_list_defaults_map = g_hash_table_new_full (g_str_hash, g_str_equal,
3114 key_file = g_key_file_new ();
3116 filename = g_build_filename (dir->path, "mimeapps.list", NULL);
3117 if (g_stat (filename, &buf) < 0)
3120 if (dir->mimeapps_list_timestamp > 0)
3121 mime_info_cache->should_ping_mime_monitor = TRUE;
3123 dir->mimeapps_list_timestamp = buf.st_mtime;
3125 g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &load_error);
3129 if (load_error != NULL)
3132 mime_types = g_key_file_get_keys (key_file, ADDED_ASSOCIATIONS_GROUP,
3134 if (mime_types != NULL)
3136 for (i = 0; mime_types[i] != NULL; i++)
3138 desktop_file_ids = g_key_file_get_string_list (key_file,
3139 ADDED_ASSOCIATIONS_GROUP,
3143 if (desktop_file_ids == NULL)
3146 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
3147 g_hash_table_replace (dir->mimeapps_list_added_map,
3152 g_strfreev (mime_types);
3155 mime_types = g_key_file_get_keys (key_file, REMOVED_ASSOCIATIONS_GROUP,
3157 if (mime_types != NULL)
3159 for (i = 0; mime_types[i] != NULL; i++)
3161 desktop_file_ids = g_key_file_get_string_list (key_file,
3162 REMOVED_ASSOCIATIONS_GROUP,
3166 if (desktop_file_ids == NULL)
3169 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
3170 g_hash_table_replace (dir->mimeapps_list_removed_map,
3175 g_strfreev (mime_types);
3178 mime_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP,
3180 if (mime_types != NULL)
3182 for (i = 0; mime_types[i] != NULL; i++)
3184 desktop_id = g_key_file_get_string (key_file,
3185 DEFAULT_APPLICATIONS_GROUP,
3188 if (desktop_id == NULL)
3191 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
3192 g_hash_table_replace (dir->mimeapps_list_defaults_map,
3197 g_strfreev (mime_types);
3200 g_key_file_free (key_file);
3205 g_key_file_free (key_file);
3207 if (mime_types != NULL)
3208 g_strfreev (mime_types);
3211 g_error_free (load_error);
3214 static MimeInfoCacheDir *
3215 mime_info_cache_dir_new (const char *path)
3217 MimeInfoCacheDir *dir;
3219 dir = g_new0 (MimeInfoCacheDir, 1);
3220 dir->path = g_strdup (path);
3226 mime_info_cache_dir_free (MimeInfoCacheDir *dir)
3231 if (dir->mime_info_cache_map != NULL)
3233 destroy_info_cache_map (dir->mime_info_cache_map);
3234 dir->mime_info_cache_map = NULL;
3238 if (dir->defaults_list_map != NULL)
3240 g_hash_table_destroy (dir->defaults_list_map);
3241 dir->defaults_list_map = NULL;
3244 if (dir->mimeapps_list_added_map != NULL)
3246 g_hash_table_destroy (dir->mimeapps_list_added_map);
3247 dir->mimeapps_list_added_map = NULL;
3250 if (dir->mimeapps_list_removed_map != NULL)
3252 g_hash_table_destroy (dir->mimeapps_list_removed_map);
3253 dir->mimeapps_list_removed_map = NULL;
3256 if (dir->mimeapps_list_defaults_map != NULL)
3258 g_hash_table_destroy (dir->mimeapps_list_defaults_map);
3259 dir->mimeapps_list_defaults_map = NULL;
3266 mime_info_cache_dir_add_desktop_entries (MimeInfoCacheDir *dir,
3267 const char *mime_type,
3268 char **new_desktop_file_ids)
3270 GList *desktop_file_ids;
3273 desktop_file_ids = g_hash_table_lookup (dir->mime_info_cache_map,
3276 for (i = 0; new_desktop_file_ids[i] != NULL; i++)
3278 if (!g_list_find_custom (desktop_file_ids, new_desktop_file_ids[i], (GCompareFunc) strcmp))
3279 desktop_file_ids = g_list_append (desktop_file_ids,
3280 g_strdup (new_desktop_file_ids[i]));
3283 g_hash_table_insert (dir->mime_info_cache_map, g_strdup (mime_type), desktop_file_ids);
3287 mime_info_cache_init_dir_lists (void)
3289 const char * const *dirs;
3292 mime_info_cache = mime_info_cache_new ();
3294 dirs = get_applications_search_path ();
3296 for (i = 0; dirs[i] != NULL; i++)
3298 MimeInfoCacheDir *dir;
3300 dir = mime_info_cache_dir_new (dirs[i]);
3304 mime_info_cache_dir_init (dir);
3305 mime_info_cache_dir_init_defaults_list (dir);
3306 mime_info_cache_dir_init_mimeapps_list (dir);
3308 mime_info_cache->dirs = g_list_append (mime_info_cache->dirs, dir);
3314 mime_info_cache_update_dir_lists (void)
3318 tmp = mime_info_cache->dirs;
3322 MimeInfoCacheDir *dir = (MimeInfoCacheDir *) tmp->data;
3324 /* No need to do this if we had file monitors... */
3325 mime_info_cache_blow_global_cache ();
3326 mime_info_cache_dir_init (dir);
3327 mime_info_cache_dir_init_defaults_list (dir);
3328 mime_info_cache_dir_init_mimeapps_list (dir);
3335 mime_info_cache_init (void)
3337 G_LOCK (mime_info_cache);
3338 if (mime_info_cache == NULL)
3339 mime_info_cache_init_dir_lists ();
3345 if (now >= mime_info_cache->last_stat_time + 10)
3347 mime_info_cache_update_dir_lists ();
3348 mime_info_cache->last_stat_time = now;
3352 if (mime_info_cache->should_ping_mime_monitor)
3354 /* g_idle_add (emit_mime_changed, NULL); */
3355 mime_info_cache->should_ping_mime_monitor = FALSE;
3358 G_UNLOCK (mime_info_cache);
3361 static MimeInfoCache *
3362 mime_info_cache_new (void)
3364 MimeInfoCache *cache;
3366 cache = g_new0 (MimeInfoCache, 1);
3368 cache->global_defaults_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
3369 (GDestroyNotify) g_free,
3370 (GDestroyNotify) g_free);
3375 mime_info_cache_free (MimeInfoCache *cache)
3380 g_list_free_full (cache->dirs, (GDestroyNotify) mime_info_cache_dir_free);
3381 g_hash_table_destroy (cache->global_defaults_cache);
3386 * mime_info_cache_reload:
3387 * @dir: directory path which needs reloading.
3389 * Reload the mime information for the @dir.
3392 mime_info_cache_reload (const char *dir)
3394 /* FIXME: just reload the dir that needs reloading,
3395 * don't blow the whole cache
3397 if (mime_info_cache != NULL)
3399 G_LOCK (mime_info_cache);
3400 mime_info_cache_free (mime_info_cache);
3401 mime_info_cache = NULL;
3402 G_UNLOCK (mime_info_cache);
3407 append_desktop_entry (GList *list,
3408 const char *desktop_entry,
3409 GList *removed_entries)
3411 /* Add if not already in list, and valid */
3412 if (!g_list_find_custom (list, desktop_entry, (GCompareFunc) strcmp) &&
3413 !g_list_find_custom (removed_entries, desktop_entry, (GCompareFunc) strcmp))
3414 list = g_list_prepend (list, g_strdup (desktop_entry));
3420 * get_all_desktop_entries_for_mime_type:
3421 * @mime_type: a mime type.
3422 * @except: NULL or a strv list
3424 * Returns all the desktop ids for @mime_type. The desktop files
3425 * are listed in an order so that default applications are listed before
3426 * non-default ones, and handlers for inherited mimetypes are listed
3427 * after the base ones.
3429 * Optionally doesn't list the desktop ids given in the @except
3431 * Return value: a #GList containing the desktop ids which claim
3432 * to handle @mime_type.
3435 get_all_desktop_entries_for_mime_type (const char *base_mime_type,
3436 const char **except,
3437 gboolean include_fallback,
3438 char **explicit_default)
3440 GList *desktop_entries, *removed_entries, *list, *dir_list, *tmp;
3441 MimeInfoCacheDir *dir;
3442 char *mime_type, *default_entry = NULL;
3443 char *old_default_entry = NULL;
3446 char **default_entries;
3447 char **removed_associations;
3448 gboolean already_found_handler;
3453 mime_info_cache_init ();
3455 if (include_fallback)
3457 /* collect all ancestors */
3458 mime_types = _g_unix_content_type_get_parents (base_mime_type);
3459 array = g_ptr_array_new ();
3460 for (i = 0; mime_types[i]; i++)
3461 g_ptr_array_add (array, mime_types[i]);
3462 g_free (mime_types);
3463 for (i = 0; i < array->len; i++)
3465 anc = _g_unix_content_type_get_parents (g_ptr_array_index (array, i));
3466 for (j = 0; anc[j]; j++)
3468 for (k = 0; k < array->len; k++)
3470 if (strcmp (anc[j], g_ptr_array_index (array, k)) == 0)
3473 if (k == array->len) /* not found */
3474 g_ptr_array_add (array, g_strdup (anc[j]));
3478 g_ptr_array_add (array, NULL);
3479 mime_types = (char **)g_ptr_array_free (array, FALSE);
3483 mime_types = g_malloc0 (2 * sizeof (gchar *));
3484 mime_types[0] = g_strdup (base_mime_type);
3485 mime_types[1] = NULL;
3488 G_LOCK (mime_info_cache);
3490 removed_entries = NULL;
3491 desktop_entries = NULL;
3493 for (i = 0; except != NULL && except[i] != NULL; i++)
3494 removed_entries = g_list_prepend (removed_entries, g_strdup (except[i]));
3496 for (i = 0; mime_types[i] != NULL; i++)
3498 mime_type = mime_types[i];
3500 /* This is true if we already found a handler for a more specific
3501 mimetype. If its set we ignore any defaults for the less specific
3503 already_found_handler = (desktop_entries != NULL);
3505 /* Go through all apps listed in user and system dirs */
3506 for (dir_list = mime_info_cache->dirs;
3508 dir_list = dir_list->next)
3510 dir = dir_list->data;
3512 /* Pick the explicit default application if we got no result earlier
3513 * (ie, for more specific mime types)
3515 if (!already_found_handler)
3517 entry = g_hash_table_lookup (dir->mimeapps_list_defaults_map, mime_type);
3521 /* Save the default entry if it's the first one we encounter */
3522 if (default_entry == NULL)
3523 default_entry = g_strdup (entry);
3527 /* Then added associations from mimeapps.list */
3528 default_entries = g_hash_table_lookup (dir->mimeapps_list_added_map, mime_type);
3529 for (j = 0; default_entries != NULL && default_entries[j] != NULL; j++)
3530 desktop_entries = append_desktop_entry (desktop_entries, default_entries[j], removed_entries);
3532 /* Then removed associations from mimeapps.list */
3533 removed_associations = g_hash_table_lookup (dir->mimeapps_list_removed_map, mime_type);
3534 for (j = 0; removed_associations != NULL && removed_associations[j] != NULL; j++)
3535 removed_entries = append_desktop_entry (removed_entries, removed_associations[j], NULL);
3537 /* Then system defaults (or old per-user config) (using removed associations from this dir or earlier) */
3538 default_entries = g_hash_table_lookup (dir->defaults_list_map, mime_type);
3539 for (j = 0; default_entries != NULL && default_entries[j] != NULL; j++)
3541 if (default_entry == NULL && old_default_entry == NULL && !already_found_handler)
3542 old_default_entry = g_strdup (default_entries[j]);
3544 desktop_entries = append_desktop_entry (desktop_entries, default_entries[j], removed_entries);
3548 /* Go through all entries that support the mimetype */
3549 for (dir_list = mime_info_cache->dirs;
3551 dir_list = dir_list->next)
3553 dir = dir_list->data;
3555 list = g_hash_table_lookup (dir->mime_info_cache_map, mime_type);
3556 for (tmp = list; tmp != NULL; tmp = tmp->next)
3557 desktop_entries = append_desktop_entry (desktop_entries, tmp->data, removed_entries);
3561 G_UNLOCK (mime_info_cache);
3563 g_strfreev (mime_types);
3565 /* If we have no default from mimeapps.list, take it from
3566 * defaults.list intead.
3568 * If we do have a default from mimeapps.list, free any one that came
3569 * from defaults.list.
3571 if (default_entry == NULL)
3572 default_entry = old_default_entry;
3574 g_free (old_default_entry);
3576 if (explicit_default != NULL)
3577 *explicit_default = default_entry;
3579 g_free (default_entry);
3581 g_list_free_full (removed_entries, g_free);
3583 desktop_entries = g_list_reverse (desktop_entries);
3585 return desktop_entries;
3588 /* GDesktopAppInfoLookup interface: */
3590 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
3592 typedef GDesktopAppInfoLookupIface GDesktopAppInfoLookupInterface;
3593 G_DEFINE_INTERFACE (GDesktopAppInfoLookup, g_desktop_app_info_lookup, G_TYPE_OBJECT)
3596 g_desktop_app_info_lookup_default_init (GDesktopAppInfoLookupInterface *iface)
3601 * g_desktop_app_info_lookup_get_default_for_uri_scheme:
3602 * @lookup: a #GDesktopAppInfoLookup
3603 * @uri_scheme: a string containing a URI scheme.
3605 * Gets the default application for launching applications
3606 * using this URI scheme for a particular GDesktopAppInfoLookup
3609 * The GDesktopAppInfoLookup interface and this function is used
3610 * to implement g_app_info_get_default_for_uri_scheme() backends
3611 * in a GIO module. There is no reason for applications to use it
3612 * directly. Applications should use g_app_info_get_default_for_uri_scheme().
3614 * Returns: (transfer full): #GAppInfo for given @uri_scheme or %NULL on error.
3616 * Deprecated: The #GDesktopAppInfoLookup interface is deprecated and unused by gio.
3619 g_desktop_app_info_lookup_get_default_for_uri_scheme (GDesktopAppInfoLookup *lookup,
3620 const char *uri_scheme)
3622 GDesktopAppInfoLookupIface *iface;
3624 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO_LOOKUP (lookup), NULL);
3626 iface = G_DESKTOP_APP_INFO_LOOKUP_GET_IFACE (lookup);
3628 return (* iface->get_default_for_uri_scheme) (lookup, uri_scheme);
3631 G_GNUC_END_IGNORE_DEPRECATIONS
3634 * g_desktop_app_info_get_startup_wm_class:
3635 * @info: a #GDesktopAppInfo that supports startup notify
3637 * Retrieves the StartupWMClass field from @info. This represents the
3638 * WM_CLASS property of the main window of the application, if launched
3641 * Returns: (transfer none): the startup WM class, or %NULL if none is set
3642 * in the desktop file.
3647 g_desktop_app_info_get_startup_wm_class (GDesktopAppInfo *info)
3649 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
3651 return info->startup_wm_class;
3655 * g_desktop_app_info_get_string:
3656 * @info: a #GDesktopAppInfo
3657 * @key: the key to look up
3659 * Looks up a string value in the keyfile backing @info.
3661 * The @key is looked up in the "Desktop Entry" group.
3663 * Returns: a newly allocated string, or %NULL if the key
3669 g_desktop_app_info_get_string (GDesktopAppInfo *info,
3672 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
3674 return g_key_file_get_string (info->keyfile,
3675 G_KEY_FILE_DESKTOP_GROUP, key, NULL);
3679 * g_desktop_app_info_get_boolean:
3680 * @info: a #GDesktopAppInfo
3681 * @key: the key to look up
3683 * Looks up a boolean value in the keyfile backing @info.
3685 * The @key is looked up in the "Desktop Entry" group.
3687 * Returns: the boolean value, or %FALSE if the key
3693 g_desktop_app_info_get_boolean (GDesktopAppInfo *info,
3696 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
3698 return g_key_file_get_boolean (info->keyfile,
3699 G_KEY_FILE_DESKTOP_GROUP, key, NULL);
3703 * g_desktop_app_info_has_key:
3704 * @info: a #GDesktopAppInfo
3705 * @key: the key to look up
3707 * Returns whether @key exists in the "Desktop Entry" group
3708 * of the keyfile backing @info.
3710 * Returns: %TRUE if the @key exists
3715 g_desktop_app_info_has_key (GDesktopAppInfo *info,
3718 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), FALSE);
3720 return g_key_file_has_key (info->keyfile,
3721 G_KEY_FILE_DESKTOP_GROUP, key, NULL);
3725 * g_desktop_app_info_list_actions:
3726 * @info: a #GDesktopAppInfo
3728 * Returns the list of "additional application actions" supported on the
3729 * desktop file, as per the desktop file specification.
3731 * As per the specification, this is the list of actions that are
3732 * explicitly listed in the "Actions" key of the [Desktop Entry] group.
3734 * Returns: (array zero-terminated=1) (element-type utf8) (transfer none): a list of strings, always non-%NULL
3738 const gchar * const *
3739 g_desktop_app_info_list_actions (GDesktopAppInfo *info)
3741 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
3743 return (const gchar **) info->actions;
3747 app_info_has_action (GDesktopAppInfo *info,
3748 const gchar *action_name)
3752 for (i = 0; info->actions[i]; i++)
3753 if (g_str_equal (info->actions[i], action_name))
3760 * g_desktop_app_info_get_action_name:
3761 * @info: a #GDesktopAppInfo
3762 * @action_name: the name of the action as from
3763 * g_desktop_app_info_list_actions()
3765 * Gets the user-visible display name of the "additional application
3766 * action" specified by @action_name.
3768 * This corresponds to the "Name" key within the keyfile group for the
3771 * Returns: (transfer full): the locale-specific action name
3776 g_desktop_app_info_get_action_name (GDesktopAppInfo *info,
3777 const gchar *action_name)
3782 g_return_val_if_fail (G_IS_DESKTOP_APP_INFO (info), NULL);
3783 g_return_val_if_fail (action_name != NULL, NULL);
3784 g_return_val_if_fail (app_info_has_action (info, action_name), NULL);
3786 group_name = g_strdup_printf ("Desktop Action %s", action_name);
3787 result = g_key_file_get_locale_string (info->keyfile, group_name, "Name", NULL, NULL);
3788 g_free (group_name);
3790 /* The spec says that the Name field must be given.
3792 * If it's not, let's follow the behaviour of our get_name()
3793 * implementation above and never return %NULL.
3796 result = g_strdup (_("Unnamed"));
3802 * g_desktop_app_info_launch_action:
3803 * @info: a #GDesktopAppInfo
3804 * @action_name: the name of the action as from
3805 * g_desktop_app_info_list_actions()
3806 * @launch_context: (allow-none): a #GAppLaunchContext
3808 * Activates the named application action.
3810 * You may only call this function on action names that were
3811 * returned from g_desktop_app_info_list_actions().
3813 * Note that if the main entry of the desktop file indicates that the
3814 * application supports startup notification, and @launch_context is
3815 * non-%NULL, then startup notification will be used when activating the
3816 * action (and as such, invocation of the action on the receiving side
3817 * must signal the end of startup notification when it is completed).
3818 * This is the expected behaviour of applications declaring additional
3819 * actions, as per the desktop file specification.
3821 * As with g_app_info_launch() there is no way to detect failures that
3822 * occur while using this function.
3827 g_desktop_app_info_launch_action (GDesktopAppInfo *info,
3828 const gchar *action_name,
3829 GAppLaunchContext *launch_context)
3831 GDBusConnection *session_bus;
3833 g_return_if_fail (G_IS_DESKTOP_APP_INFO (info));
3834 g_return_if_fail (action_name != NULL);
3835 g_return_if_fail (app_info_has_action (info, action_name));
3837 session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
3839 if (session_bus && info->app_id)
3843 object_path = object_path_from_appid (info->app_id);
3844 g_dbus_connection_call (session_bus, info->app_id, object_path,
3845 "org.freedesktop.Application", "ActivateAction",
3846 g_variant_new ("(sav@a{sv})", action_name, NULL,
3847 g_desktop_app_info_make_platform_data (info, NULL, launch_context)),
3848 NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
3849 g_free (object_path);
3856 group_name = g_strdup_printf ("Desktop Action %s", action_name);
3857 exec_line = g_key_file_get_string (info->keyfile, group_name, "Exec", NULL);
3858 g_free (group_name);
3861 g_desktop_app_info_launch_uris_with_spawn (info, session_bus, exec_line, NULL, launch_context,
3862 _SPAWN_FLAGS_DEFAULT, NULL, NULL, NULL, NULL, NULL);
3865 if (session_bus != NULL)
3867 g_dbus_connection_flush (session_bus, NULL, NULL, NULL);
3868 g_object_unref (session_bus);