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>
31 #ifdef HAVE_CRT_EXTERNS_H
32 #include <crt_externs.h>
35 #include "gcontenttypeprivate.h"
36 #include "gdesktopappinfo.h"
38 #include "gthemedicon.h"
39 #include "gfileicon.h"
40 #include <glib/gstdio.h>
46 * SECTION:gdesktopappinfo
47 * @short_description: Application information from desktop files
48 * @include: gio/gdesktopappinfo.h
50 * #GDesktopAppInfo is an implementation of #GAppInfo based on
55 #define DEFAULT_APPLICATIONS_GROUP "Default Applications"
56 #define MIME_CACHE_GROUP "MIME Cache"
58 static void g_desktop_app_info_iface_init (GAppInfoIface *iface);
60 static GList *get_all_desktop_entries_for_mime_type (const char *base_mime_type);
61 static void mime_info_cache_reload (const char *dir);
66 * Information about an installed application from a desktop file.
68 struct _GDesktopAppInfo
70 GObject parent_instance;
76 /* FIXME: what about GenericName ? */
90 guint startup_notify : 1;
91 /* FIXME: what about StartupWMClass ? */
94 G_DEFINE_TYPE_WITH_CODE (GDesktopAppInfo, g_desktop_app_info, G_TYPE_OBJECT,
95 G_IMPLEMENT_INTERFACE (G_TYPE_APP_INFO,
96 g_desktop_app_info_iface_init))
99 search_path_init (gpointer data)
102 const char * const *data_dirs;
103 const char *user_data_dir;
106 data_dirs = g_get_system_data_dirs ();
107 length = g_strv_length ((char **) data_dirs);
109 args = g_new (char *, length + 2);
112 user_data_dir = g_get_user_data_dir ();
113 args[j++] = g_build_filename (user_data_dir, "applications", NULL);
114 for (i = 0; i < length; i++)
115 args[j++] = g_build_filename (data_dirs[i],
116 "applications", NULL);
122 static const char * const *
123 get_applications_search_path (void)
125 static GOnce once_init = G_ONCE_INIT;
126 return g_once (&once_init, search_path_init, NULL);
130 g_desktop_app_info_finalize (GObject *object)
132 GDesktopAppInfo *info;
134 info = G_DESKTOP_APP_INFO (object);
136 g_free (info->desktop_id);
137 g_free (info->filename);
139 g_free (info->comment);
140 g_free (info->icon_name);
142 g_object_unref (info->icon);
143 g_strfreev (info->only_show_in);
144 g_strfreev (info->not_show_in);
145 g_free (info->try_exec);
147 g_free (info->binary);
150 G_OBJECT_CLASS (g_desktop_app_info_parent_class)->finalize (object);
154 g_desktop_app_info_class_init (GDesktopAppInfoClass *klass)
156 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
158 gobject_class->finalize = g_desktop_app_info_finalize;
162 g_desktop_app_info_init (GDesktopAppInfo *local)
167 * g_desktop_app_info_new_from_filename:
168 * @filename: a string containing a file name.
170 * Creates a new #GDesktopAppInfo.
172 * Returns: a new #GDesktopAppInfo or %NULL on error.
175 g_desktop_app_info_new_from_filename (const char *filename)
177 GDesktopAppInfo *info;
183 key_file = g_key_file_new ();
185 if (!g_key_file_load_from_file (key_file,
191 start_group = g_key_file_get_start_group (key_file);
192 if (start_group == NULL || strcmp (start_group, G_KEY_FILE_DESKTOP_GROUP) != 0)
194 g_free (start_group);
197 g_free (start_group);
199 type = g_key_file_get_string (key_file,
200 G_KEY_FILE_DESKTOP_GROUP,
201 G_KEY_FILE_DESKTOP_KEY_TYPE,
203 if (type == NULL || strcmp (type, G_KEY_FILE_DESKTOP_TYPE_APPLICATION) != 0)
210 try_exec = g_key_file_get_string (key_file,
211 G_KEY_FILE_DESKTOP_GROUP,
212 G_KEY_FILE_DESKTOP_KEY_TRY_EXEC,
217 t = g_find_program_in_path (try_exec);
226 info = g_object_new (G_TYPE_DESKTOP_APP_INFO, NULL);
227 info->filename = g_strdup (filename);
229 info->name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
230 info->comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
231 info->nodisplay = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, NULL) != FALSE;
232 info->icon_name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL, NULL);
233 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);
234 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);
235 info->try_exec = try_exec;
236 info->exec = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
237 info->path = g_key_file_get_string (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_PATH, NULL);
238 info->terminal = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL) != FALSE;
239 info->startup_notify = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_STARTUP_NOTIFY, NULL) != FALSE;
240 info->hidden = g_key_file_get_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_HIDDEN, NULL) != FALSE;
245 if (g_path_is_absolute (info->icon_name))
249 file = g_file_new_for_path (info->icon_name);
250 info->icon = g_file_icon_new (file);
251 g_object_unref (file);
254 info->icon = g_themed_icon_new (info->icon_name);
265 while (*p != ' ' && *p != 0)
268 info->binary = g_strndup (start, p - start);
275 * g_desktop_app_info_new:
276 * @desktop_id: the desktop file id
278 * Creates a new #GDesktopAppInfo.
280 * Returns: a new #GDesktopAppInfo, or %NULL if no desktop file with that id
283 g_desktop_app_info_new (const char *desktop_id)
285 GDesktopAppInfo *appinfo;
286 const char * const *dirs;
289 dirs = get_applications_search_path ();
291 for (i = 0; dirs[i] != NULL; i++)
297 filename = g_build_filename (dirs[i], desktop_id, NULL);
298 appinfo = g_desktop_app_info_new_from_filename (filename);
305 basename = g_strdup (desktop_id);
307 while ((p = strchr (p, '-')) != NULL)
311 filename = g_build_filename (dirs[i], basename, NULL);
312 appinfo = g_desktop_app_info_new_from_filename (filename);
327 appinfo->desktop_id = g_strdup (desktop_id);
329 if (g_desktop_app_info_get_is_hidden (appinfo))
331 g_object_unref (appinfo);
339 g_desktop_app_info_dup (GAppInfo *appinfo)
341 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
342 GDesktopAppInfo *new_info;
344 new_info = g_object_new (G_TYPE_DESKTOP_APP_INFO, NULL);
346 new_info->filename = g_strdup (info->filename);
347 new_info->desktop_id = g_strdup (info->desktop_id);
349 new_info->name = g_strdup (info->name);
350 new_info->comment = g_strdup (info->comment);
351 new_info->nodisplay = info->nodisplay;
352 new_info->icon_name = g_strdup (info->icon_name);
353 new_info->icon = g_object_ref (info->icon);
354 new_info->only_show_in = g_strdupv (info->only_show_in);
355 new_info->not_show_in = g_strdupv (info->not_show_in);
356 new_info->try_exec = g_strdup (info->try_exec);
357 new_info->exec = g_strdup (info->exec);
358 new_info->binary = g_strdup (info->binary);
359 new_info->path = g_strdup (info->path);
360 new_info->hidden = info->hidden;
361 new_info->terminal = info->terminal;
362 new_info->startup_notify = info->startup_notify;
364 return G_APP_INFO (new_info);
368 g_desktop_app_info_equal (GAppInfo *appinfo1,
371 GDesktopAppInfo *info1 = G_DESKTOP_APP_INFO (appinfo1);
372 GDesktopAppInfo *info2 = G_DESKTOP_APP_INFO (appinfo2);
374 if (info1->desktop_id == NULL ||
375 info2->desktop_id == NULL)
378 return strcmp (info1->desktop_id, info2->desktop_id) == 0;
382 g_desktop_app_info_get_id (GAppInfo *appinfo)
384 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
386 return info->desktop_id;
390 g_desktop_app_info_get_name (GAppInfo *appinfo)
392 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
394 if (info->name == NULL)
400 * g_desktop_app_info_get_is_hidden:
401 * @info: a #GDesktopAppInfo.
403 * A desktop file is hidden if the Hidden key in it is
406 * Returns: %TRUE if hidden, %FALSE otherwise.
409 g_desktop_app_info_get_is_hidden (GDesktopAppInfo *info)
415 g_desktop_app_info_get_description (GAppInfo *appinfo)
417 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
419 return info->comment;
423 g_desktop_app_info_get_executable (GAppInfo *appinfo)
425 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
431 g_desktop_app_info_get_icon (GAppInfo *appinfo)
433 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
439 expand_macro_single (char macro, GFile *file)
444 path = g_file_get_path (file);
445 uri = g_file_get_uri (file);
451 result = g_shell_quote (uri);
456 result = g_shell_quote (path);
461 result = g_shell_quote (g_path_get_dirname (path));
466 result = g_shell_quote (g_path_get_basename (path));
477 expand_macro (char macro,
479 GDesktopAppInfo *info,
482 GList *files = *file_list;
485 g_return_if_fail (exec != NULL);
495 expanded = expand_macro_single (macro, files->data);
498 g_string_append (exec, expanded);
512 expanded = expand_macro_single (macro, files->data);
515 g_string_append (exec, expanded);
521 if (files != NULL && expanded)
522 g_string_append_c (exec, ' ');
530 g_string_append (exec, "--icon ");
531 g_string_append (exec, info->icon_name);
537 g_string_append (exec, info->name);
542 g_string_append (exec, info->filename);
545 case 'm': /* deprecated */
549 g_string_append_c (exec, '%');
557 expand_application_parameters (GDesktopAppInfo *info,
563 GList *file_list = *files;
564 const char *p = info->exec;
565 GString *expanded_exec = g_string_new (NULL);
568 if (info->exec == NULL)
570 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
571 _("Desktop file didn't specify Exec field"));
577 if (p[0] == '%' && p[1] != '\0')
579 expand_macro (p[1], expanded_exec, info, files);
583 g_string_append_c (expanded_exec, *p);
588 /* No file substitutions */
589 if (file_list == *files && file_list != NULL)
591 /* If there is no macro default to %f. This is also what KDE does */
592 g_string_append_c (expanded_exec, ' ');
593 expand_macro ('f', expanded_exec, info, files);
596 res = g_shell_parse_argv (expanded_exec->str, argc, argv, error);
597 g_string_free (expanded_exec, TRUE);
602 prepend_terminal_to_vector (int *argc,
609 char **term_argv = NULL;
614 g_return_val_if_fail (argc != NULL, FALSE);
615 g_return_val_if_fail (argv != NULL, FALSE);
623 /* compute size if not given */
626 for (i = 0; the_argv[i] != NULL; i++)
632 term_argv = g_new0 (char *, 3);
634 check = g_find_program_in_path ("gnome-terminal");
637 term_argv[0] = check;
638 /* Note that gnome-terminal takes -x and
639 * as -e in gnome-terminal is broken we use that. */
640 term_argv[1] = g_strdup ("-x");
645 check = g_find_program_in_path ("nxterm");
647 check = g_find_program_in_path ("color-xterm");
649 check = g_find_program_in_path ("rxvt");
651 check = g_find_program_in_path ("xterm");
653 check = g_find_program_in_path ("dtterm");
656 check = g_strdup ("xterm");
657 g_warning ("couldn't find a terminal, falling back to xterm");
659 term_argv[0] = check;
660 term_argv[1] = g_strdup ("-e");
663 real_argc = term_argc + *argc;
664 real_argv = g_new (char *, real_argc + 1);
666 for (i = 0; i < term_argc; i++)
667 real_argv[i] = term_argv[i];
669 for (j = 0; j < *argc; j++, i++)
670 real_argv[i] = (char *)the_argv[j];
678 /* we use g_free here as we sucked all the inner strings
679 * out from it into real_argv */
684 #endif /* G_OS_WIN32 */
687 /* '=' is the new '\0'.
688 * DO NOT CALL unless at least one string ends with '='
691 is_env (const char *a,
696 if (*a == 0 || *b == 0)
709 /* free with g_strfreev */
711 replace_env_var (char **old_environ,
713 const char *new_value)
715 int length, new_length;
716 int index, new_index;
720 /* do two things at once:
721 * - discover the length of the environment ('length')
722 * - find the location (if any) of the env var ('index')
725 for (length = 0; old_environ[length]; length++)
727 /* if we already have it in our environment, replace */
728 if (is_env (old_environ[length], env_var))
733 /* no current env var, no desired env value.
736 if (new_value == NULL && index == -1)
739 /* in all cases now, we will be using a modified environment.
740 * determine its length and allocated it.
743 * new_index = location to insert, if any
744 * new_length = length of the new array
745 * new_environ = the pointer array for the new environment
748 if (new_value == NULL && index >= 0)
750 /* in this case, we will be removing an entry */
751 new_length = length - 1;
754 else if (new_value != NULL && index < 0)
756 /* in this case, we will be adding an entry to the end */
757 new_length = length + 1;
761 /* in this case, we will be replacing the existing entry */
767 new_environ = g_malloc (sizeof (char *) * (new_length + 1));
768 new_environ[new_length] = NULL;
770 /* now we do the copying.
771 * for each entry in the new environment, we decide what to do
775 for (new_i = 0; new_i < new_length; new_i++)
777 if (new_i == new_index)
779 /* insert our new item */
780 new_environ[new_i] = g_strconcat (env_var,
785 /* if we had an old entry, skip it now */
791 /* if this is the old DESKTOP_STARTUP_ID, skip it */
795 /* copy an old item */
796 new_environ[new_i] = g_strdup (old_environ[i]);
801 g_strfreev (old_environ);
807 dup_list_segment (GList *start,
813 while (start != NULL && start != end)
815 res = g_list_prepend (res, start->data);
819 return g_list_reverse (res);
822 #ifdef HAVE__NSGETENVIRON
823 #define environ (*_NSGetEnviron())
824 #elif !defined(G_OS_WIN32)
826 /* According to the Single Unix Specification, environ is not in
827 * * any system header, although unistd.h often declares it.
829 extern char **environ;
833 g_desktop_app_info_launch (GAppInfo *appinfo,
835 GAppLaunchContext *launch_context,
838 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
839 gboolean completed = FALSE;
841 GList *launched_files;
848 g_return_val_if_fail (appinfo != NULL, FALSE);
856 if (!expand_application_parameters (info, &files,
857 &argc, &argv, error))
860 if (info->terminal && !prepend_terminal_to_vector (&argc, &argv))
862 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
863 _("Unable to find terminal required for application"));
870 launched_files = dup_list_segment (old_files, files);
872 display = g_app_launch_context_get_display (launch_context,
877 if (info->startup_notify)
878 sn_id = g_app_launch_context_get_startup_notify_id (launch_context,
882 if (display || sn_id)
886 envp = g_new0 (char *, 1);
888 envp = g_strdupv (environ);
892 envp = replace_env_var (envp,
897 envp = replace_env_var (envp,
898 "DESKTOP_STARTUP_ID",
904 g_list_free (launched_files);
907 if (!g_spawn_async (info->path, /* working directory */
910 G_SPAWN_SEARCH_PATH /* flags */,
911 NULL /* child_setup */,
913 NULL /* child_pid */,
918 g_app_launch_context_launch_failed (launch_context, sn_id);
932 while (files != NULL);
944 g_desktop_app_info_supports_uris (GAppInfo *appinfo)
946 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
949 ((strstr (info->exec, "%u") != NULL) ||
950 (strstr (info->exec, "%U") != NULL));
954 g_desktop_app_info_launch_uris (GAppInfo *appinfo,
956 GAppLaunchContext *launch_context,
966 file = g_file_new_for_uri (uris->data);
968 g_warning ("Invalid uri passed to g_desktop_app_info_launch_uris");
971 files = g_list_prepend (files, file);
974 files = g_list_reverse (files);
976 res = g_desktop_app_info_launch (appinfo, files, launch_context, error);
978 g_list_foreach (files, (GFunc)g_object_unref, NULL);
985 g_desktop_app_info_should_show (GAppInfo *appinfo,
986 const char *desktop_env)
988 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
995 if (info->only_show_in)
997 if (desktop_env == NULL)
1001 for (i = 0; info->only_show_in[i] != NULL; i++)
1003 if (strcmp (info->only_show_in[i], desktop_env) == 0)
1013 if (info->not_show_in && desktop_env)
1015 for (i = 0; info->not_show_in[i] != NULL; i++)
1017 if (strcmp (info->not_show_in[i], desktop_env) == 0)
1031 ensure_dir (DirType type,
1034 char *path, *display_name;
1037 if (type == APP_DIR)
1038 path = g_build_filename (g_get_user_data_dir (), "applications", NULL);
1040 path = g_build_filename (g_get_user_data_dir (), "mime", "packages", NULL);
1043 if (g_mkdir_with_parents (path, 0700) == 0)
1047 display_name = g_filename_display_name (path);
1048 if (type == APP_DIR)
1049 g_set_error (error, G_IO_ERROR, g_io_error_from_errno (err),
1050 _("Can't create user application configuration folder %s: %s"),
1051 display_name, g_strerror (err));
1053 g_set_error (error, G_IO_ERROR, g_io_error_from_errno (err),
1054 _("Can't create user MIME configuration folder %s: %s"),
1055 display_name, g_strerror (err));
1057 g_free (display_name);
1064 update_default_list (const char *desktop_id,
1065 const char *content_type,
1069 char *dirname, *filename;
1071 gboolean load_succeeded, res;
1074 gsize length, data_size;
1078 dirname = ensure_dir (APP_DIR, error);
1082 filename = g_build_filename (dirname, "defaults.list", NULL);
1085 key_file = g_key_file_new ();
1086 load_succeeded = g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL);
1087 if (!load_succeeded || !g_key_file_has_group (key_file, DEFAULT_APPLICATIONS_GROUP))
1089 g_key_file_free (key_file);
1090 key_file = g_key_file_new ();
1094 old_list = g_key_file_get_string_list (key_file, DEFAULT_APPLICATIONS_GROUP,
1095 content_type, &length, NULL);
1097 list = g_new (char *, 1 + length + 1);
1101 list[i++] = g_strdup (desktop_id);
1104 for (j = 0; old_list[j] != NULL; j++)
1106 if (strcmp (old_list[j], desktop_id) != 0)
1107 list[i++] = g_strdup (old_list[j]);
1112 g_strfreev (old_list);
1114 g_key_file_set_string_list (key_file,
1115 DEFAULT_APPLICATIONS_GROUP,
1117 (const char * const *)list, i);
1121 data = g_key_file_to_data (key_file, &data_size, error);
1122 g_key_file_free (key_file);
1124 res = g_file_set_contents (filename, data, data_size, error);
1126 mime_info_cache_reload (NULL);
1135 g_desktop_app_info_set_as_default_for_type (GAppInfo *appinfo,
1136 const char *content_type,
1139 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1141 if (!g_app_info_add_supports_type (appinfo, content_type, error))
1144 return update_default_list (info->desktop_id, content_type, TRUE, error);
1148 update_program_done (GPid pid,
1152 /* Did the application exit correctly */
1153 if (WIFEXITED (status) &&
1154 WEXITSTATUS (status) == 0)
1156 /* Here we could clean out any caches in use */
1161 run_update_command (char *command,
1170 GError *error = NULL;
1173 argv[1] = g_build_filename (g_get_user_data_dir (), subdir, NULL);
1175 if (g_spawn_async ("/", argv,
1177 G_SPAWN_SEARCH_PATH |
1178 G_SPAWN_STDOUT_TO_DEV_NULL |
1179 G_SPAWN_STDERR_TO_DEV_NULL |
1180 G_SPAWN_DO_NOT_REAP_CHILD,
1181 NULL, NULL, /* No setup function */
1184 g_child_watch_add (pid, update_program_done, NULL);
1187 /* If we get an error at this point, it's quite likely the user doesn't
1188 * have an installed copy of either 'update-mime-database' or
1189 * 'update-desktop-database'. I don't think we want to popup an error
1190 * dialog at this point, so we just do a g_warning to give the user a
1191 * chance of debugging it.
1193 g_warning ("%s", error->message);
1200 g_desktop_app_info_set_as_default_for_extension (GAppInfo *appinfo,
1201 const char *extension,
1204 char *filename, *basename, *mimetype;
1208 dirname = ensure_dir (MIMETYPE_DIR, error);
1212 basename = g_strdup_printf ("user-extension-%s.xml", extension);
1213 filename = g_build_filename (dirname, basename, NULL);
1217 mimetype = g_strdup_printf ("application/x-extension-%s", extension);
1219 if (!g_file_test (filename, G_FILE_TEST_EXISTS))
1224 g_strdup_printf ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
1225 "<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">\n"
1226 " <mime-type type=\"%s\">\n"
1227 " <comment>%s document</comment>\n"
1228 " <glob pattern=\"*.%s\"/>\n"
1230 "</mime-info>\n", mimetype, extension, extension);
1232 g_file_set_contents (filename, contents, -1, NULL);
1235 run_update_command ("update-mime-database", "mime");
1239 res = g_desktop_app_info_set_as_default_for_type (appinfo,
1249 g_desktop_app_info_add_supports_type (GAppInfo *appinfo,
1250 const char *content_type,
1253 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1255 char *new_mimetypes, *old_mimetypes, *content;
1259 keyfile = g_key_file_new ();
1260 if (!g_key_file_load_from_file (keyfile, info->filename,
1261 G_KEY_FILE_KEEP_COMMENTS |
1262 G_KEY_FILE_KEEP_TRANSLATIONS, error))
1264 g_key_file_free (keyfile);
1268 old_mimetypes = g_key_file_get_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_MIME_TYPE, NULL);
1269 new_mimetypes = g_strconcat (content_type, ";", old_mimetypes, NULL);
1270 g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_MIME_TYPE, new_mimetypes);
1271 g_free (old_mimetypes);
1272 g_free (new_mimetypes);
1274 content = g_key_file_to_data (keyfile, NULL, NULL);
1275 g_key_file_free (keyfile);
1277 dirname = ensure_dir (APP_DIR, error);
1284 filename = g_build_filename (dirname, info->desktop_id, NULL);
1287 if (!g_file_set_contents (filename, content, -1, error))
1296 run_update_command ("update-desktop-database", "applications");
1301 g_desktop_app_info_can_remove_supports_type (GAppInfo *appinfo)
1303 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1306 user_dirname = g_build_filename (g_get_user_data_dir (), "applications", NULL);
1307 return g_str_has_prefix (info->filename, user_dirname);
1311 g_desktop_app_info_remove_supports_type (GAppInfo *appinfo,
1312 const char *content_type,
1315 GDesktopAppInfo *info = G_DESKTOP_APP_INFO (appinfo);
1317 char *new_mimetypes, *old_mimetypes, *content;
1322 keyfile = g_key_file_new ();
1323 if (!g_key_file_load_from_file (keyfile, info->filename,
1324 G_KEY_FILE_KEEP_COMMENTS |
1325 G_KEY_FILE_KEEP_TRANSLATIONS, error))
1327 g_key_file_free (keyfile);
1331 old_mimetypes = g_key_file_get_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_MIME_TYPE, NULL);
1332 new_mimetypes = g_strdup (old_mimetypes);
1335 found = strstr (new_mimetypes, content_type);
1336 if (found && *(found + strlen (content_type)) == ';')
1338 char *rest = found + strlen (content_type) + 1;
1339 memmove (found, rest, strlen (rest) + 1);
1341 g_key_file_set_string (keyfile, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_MIME_TYPE, new_mimetypes);
1342 g_free (old_mimetypes);
1343 g_free (new_mimetypes);
1345 content = g_key_file_to_data (keyfile, NULL, NULL);
1346 g_key_file_free (keyfile);
1348 dirname = ensure_dir (APP_DIR, error);
1355 filename = g_build_filename (dirname, info->desktop_id, NULL);
1357 if (!g_file_set_contents (filename, content, -1, error))
1366 run_update_command ("update-desktop-database", "applications");
1368 return update_default_list (info->desktop_id, content_type, FALSE, error);
1372 * g_app_info_create_from_commandline:
1373 * @commandline: the commandline to use
1374 * @application_name: the application name, or %NULL to use @commandline
1375 * @flags: flags that can specify details of the created #GAppInfo
1376 * @error: a #GError location to store the error occuring, %NULL to ignore.
1378 * Creates a new #GAppInfo from the given information.
1380 * Returns: new #GAppInfo for given command.
1383 g_app_info_create_from_commandline (const char *commandline,
1384 const char *application_name,
1385 GAppInfoCreateFlags flags,
1391 char *basename, *exec, *filename, *comment;
1392 char *data, *desktop_id;
1395 GDesktopAppInfo *info;
1398 dirname = ensure_dir (APP_DIR, error);
1402 key_file = g_key_file_new ();
1404 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1405 "Encoding", "UTF-8");
1406 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1407 G_KEY_FILE_DESKTOP_KEY_VERSION, "1.0");
1408 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1409 G_KEY_FILE_DESKTOP_KEY_TYPE,
1410 G_KEY_FILE_DESKTOP_TYPE_APPLICATION);
1411 if (flags & G_APP_INFO_CREATE_NEEDS_TERMINAL)
1412 g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
1413 G_KEY_FILE_DESKTOP_KEY_TERMINAL, TRUE);
1415 exec = g_strconcat (commandline, " %f", NULL);
1416 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1417 G_KEY_FILE_DESKTOP_KEY_EXEC, exec);
1420 /* FIXME: this should be more robust. Maybe g_shell_parse_argv and use argv[0] */
1421 split = g_strsplit (commandline, " ", 2);
1422 basename = g_path_get_basename (split[0]);
1424 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1425 G_KEY_FILE_DESKTOP_KEY_NAME, application_name?application_name:basename);
1427 comment = g_strdup_printf (_("Custom definition for %s"), basename);
1428 g_key_file_set_string (key_file, G_KEY_FILE_DESKTOP_GROUP,
1429 G_KEY_FILE_DESKTOP_KEY_COMMENT, comment);
1432 g_key_file_set_boolean (key_file, G_KEY_FILE_DESKTOP_GROUP,
1433 G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, TRUE);
1435 data = g_key_file_to_data (key_file, &data_size, NULL);
1436 g_key_file_free (key_file);
1438 desktop_id = g_strdup_printf ("userapp-%s-XXXXXX.desktop", basename);
1440 filename = g_build_filename (dirname, desktop_id, NULL);
1441 g_free (desktop_id);
1444 fd = g_mkstemp (filename);
1449 display_name = g_filename_display_name (filename);
1450 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
1451 _("Can't create user desktop file %s"), display_name);
1452 g_free (display_name);
1458 desktop_id = g_path_get_basename (filename);
1462 res = g_file_set_contents (filename, data, data_size, error);
1465 g_free (desktop_id);
1470 run_update_command ("update-desktop-database", "applications");
1472 info = g_desktop_app_info_new_from_filename (filename);
1475 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
1476 _("Can't load just created desktop file"));
1478 info->desktop_id = g_strdup (desktop_id);
1480 g_free (desktop_id);
1482 return G_APP_INFO (info);
1487 g_desktop_app_info_iface_init (GAppInfoIface *iface)
1489 iface->dup = g_desktop_app_info_dup;
1490 iface->equal = g_desktop_app_info_equal;
1491 iface->get_id = g_desktop_app_info_get_id;
1492 iface->get_name = g_desktop_app_info_get_name;
1493 iface->get_description = g_desktop_app_info_get_description;
1494 iface->get_executable = g_desktop_app_info_get_executable;
1495 iface->get_icon = g_desktop_app_info_get_icon;
1496 iface->launch = g_desktop_app_info_launch;
1497 iface->supports_uris = g_desktop_app_info_supports_uris;
1498 iface->launch_uris = g_desktop_app_info_launch_uris;
1499 iface->should_show = g_desktop_app_info_should_show;
1500 iface->set_as_default_for_type = g_desktop_app_info_set_as_default_for_type;
1501 iface->set_as_default_for_extension = g_desktop_app_info_set_as_default_for_extension;
1502 iface->add_supports_type = g_desktop_app_info_add_supports_type;
1503 iface->can_remove_supports_type = g_desktop_app_info_can_remove_supports_type;
1504 iface->remove_supports_type = g_desktop_app_info_remove_supports_type;
1508 app_info_in_list (GAppInfo *info,
1511 while (list != NULL)
1513 if (g_app_info_equal (info, list->data))
1522 * g_app_info_get_all_for_type:
1523 * @content_type: the content type to find a #GAppInfo for
1525 * Gets a list of all #GAppInfo s for a given content type.
1527 * Returns: #GList of #GAppInfo s for given @content_type.
1530 g_app_info_get_all_for_type (const char *content_type)
1532 GList *desktop_entries, *l;
1534 GDesktopAppInfo *info;
1536 desktop_entries = get_all_desktop_entries_for_mime_type (content_type);
1539 for (l = desktop_entries; l != NULL; l = l->next)
1541 char *desktop_entry = l->data;
1543 info = g_desktop_app_info_new (desktop_entry);
1546 if (app_info_in_list (G_APP_INFO (info), infos))
1547 g_object_unref (info);
1549 infos = g_list_prepend (infos, info);
1551 g_free (desktop_entry);
1554 g_list_free (desktop_entries);
1556 return g_list_reverse (infos);
1561 * g_app_info_get_default_for_type:
1562 * @content_type: the content type to find a #GAppInfo for
1563 * @must_support_uris: if %TRUE, the #GAppInfo is expected to
1566 * Gets the #GAppInfo that correspond to a given content type.
1568 * Returns: #GAppInfo for given @content_type.
1571 g_app_info_get_default_for_type (const char *content_type,
1572 gboolean must_support_uris)
1574 GList *desktop_entries, *l;
1577 desktop_entries = get_all_desktop_entries_for_mime_type (content_type);
1580 for (l = desktop_entries; l != NULL; l = l->next)
1582 char *desktop_entry = l->data;
1584 info = (GAppInfo *)g_desktop_app_info_new (desktop_entry);
1587 if (must_support_uris && !g_app_info_supports_uris (info))
1589 g_object_unref (info);
1597 g_list_foreach (desktop_entries, (GFunc)g_free, NULL);
1598 g_list_free (desktop_entries);
1605 * g_app_info_get_default_for_uri_scheme:
1606 * @uri_scheme: a string containing a URI scheme.
1608 * Gets the default application for launching applications
1609 * using this URI scheme.
1611 * TODO: This is currently unimplemented.
1616 g_app_info_get_default_for_uri_scheme (const char *uri_scheme)
1618 /* TODO: Implement this using giomodules, reading the gconf settings
1619 * in /desktop/gnome/url-handlers
1626 get_apps_from_dir (GHashTable *apps,
1627 const char *dirname,
1631 const char *basename;
1632 char *filename, *subprefix, *desktop_id;
1634 GDesktopAppInfo *appinfo;
1636 dir = g_dir_open (dirname, 0, NULL);
1639 while ((basename = g_dir_read_name (dir)) != NULL)
1641 filename = g_build_filename (dirname, basename, NULL);
1642 if (g_str_has_suffix (basename, ".desktop"))
1644 desktop_id = g_strconcat (prefix, basename, NULL);
1646 /* Use _extended so we catch NULLs too (hidden) */
1647 if (!g_hash_table_lookup_extended (apps, desktop_id, NULL, NULL))
1649 appinfo = g_desktop_app_info_new_from_filename (filename);
1651 /* Don't return apps that don't take arguments */
1653 (g_desktop_app_info_get_is_hidden (appinfo) ||
1655 strstr (appinfo->exec,"%U") == NULL &&
1656 strstr (appinfo->exec,"%u") == NULL &&
1657 strstr (appinfo->exec,"%f") == NULL &&
1658 strstr (appinfo->exec,"%F") == NULL)))
1660 g_object_unref (appinfo);
1665 if (appinfo != NULL || hidden)
1667 g_hash_table_insert (apps, g_strdup (desktop_id), appinfo);
1671 /* Reuse instead of strdup here */
1672 appinfo->desktop_id = desktop_id;
1677 g_free (desktop_id);
1681 if (g_file_test (filename, G_FILE_TEST_IS_DIR))
1683 subprefix = g_strconcat (prefix, basename, "-", NULL);
1684 get_apps_from_dir (apps, filename, subprefix);
1696 * g_app_info_get_all:
1698 * Gets a list of all of the applications currently registered on this system.
1700 * Returns: a newly allocated #GList of references to #GAppInfo<!---->s.
1703 g_app_info_get_all (void)
1705 const char * const *dirs;
1707 GHashTableIter iter;
1712 dirs = get_applications_search_path ();
1714 apps = g_hash_table_new_full (g_str_hash, g_str_equal,
1718 for (i = 0; dirs[i] != NULL; i++)
1719 get_apps_from_dir (apps, dirs[i], "");
1723 g_hash_table_iter_init (&iter, apps);
1724 while (g_hash_table_iter_next (&iter, NULL, &value))
1727 infos = g_list_prepend (infos, value);
1730 g_hash_table_destroy (apps);
1732 return g_list_reverse (infos);
1735 /* Cacheing of mimeinfo.cache and defaults.list files */
1739 GHashTable *mime_info_cache_map;
1740 GHashTable *defaults_list_map;
1741 time_t mime_info_cache_timestamp;
1742 time_t defaults_list_timestamp;
1746 GList *dirs; /* mimeinfo.cache and defaults.list */
1747 GHashTable *global_defaults_cache; /* global results of defaults.list lookup and validation */
1748 time_t last_stat_time;
1749 guint should_ping_mime_monitor : 1;
1752 static MimeInfoCache *mime_info_cache = NULL;
1753 G_LOCK_DEFINE_STATIC (mime_info_cache);
1755 static void mime_info_cache_dir_add_desktop_entries (MimeInfoCacheDir *dir,
1756 const char *mime_type,
1757 char **new_desktop_file_ids);
1759 static MimeInfoCache * mime_info_cache_new (void);
1762 destroy_info_cache_value (gpointer key,
1766 g_list_foreach (value, (GFunc)g_free, NULL);
1767 g_list_free (value);
1771 destroy_info_cache_map (GHashTable *info_cache_map)
1773 g_hash_table_foreach (info_cache_map, (GHFunc)destroy_info_cache_value, NULL);
1774 g_hash_table_destroy (info_cache_map);
1778 mime_info_cache_dir_out_of_date (MimeInfoCacheDir *dir,
1779 const char *cache_file,
1785 filename = g_build_filename (dir->path, cache_file, NULL);
1787 if (g_stat (filename, &buf) < 0)
1794 if (buf.st_mtime != *timestamp)
1800 /* Call with lock held */
1802 remove_all (gpointer key,
1811 mime_info_cache_blow_global_cache (void)
1813 g_hash_table_foreach_remove (mime_info_cache->global_defaults_cache,
1818 mime_info_cache_dir_init (MimeInfoCacheDir *dir)
1822 gchar *filename, **mime_types;
1829 if (dir->mime_info_cache_map != NULL &&
1830 !mime_info_cache_dir_out_of_date (dir, "mimeinfo.cache",
1831 &dir->mime_info_cache_timestamp))
1834 if (dir->mime_info_cache_map != NULL)
1835 destroy_info_cache_map (dir->mime_info_cache_map);
1837 dir->mime_info_cache_map = g_hash_table_new_full (g_str_hash, g_str_equal,
1838 (GDestroyNotify) g_free,
1841 key_file = g_key_file_new ();
1843 filename = g_build_filename (dir->path, "mimeinfo.cache", NULL);
1845 if (g_stat (filename, &buf) < 0)
1848 if (dir->mime_info_cache_timestamp > 0)
1849 mime_info_cache->should_ping_mime_monitor = TRUE;
1851 dir->mime_info_cache_timestamp = buf.st_mtime;
1853 g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &load_error);
1858 if (load_error != NULL)
1861 mime_types = g_key_file_get_keys (key_file, MIME_CACHE_GROUP,
1864 if (load_error != NULL)
1867 for (i = 0; mime_types[i] != NULL; i++)
1869 gchar **desktop_file_ids;
1870 char *unaliased_type;
1871 desktop_file_ids = g_key_file_get_string_list (key_file,
1877 if (desktop_file_ids == NULL)
1880 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
1881 mime_info_cache_dir_add_desktop_entries (dir,
1884 g_free (unaliased_type);
1886 g_strfreev (desktop_file_ids);
1889 g_strfreev (mime_types);
1890 g_key_file_free (key_file);
1895 g_key_file_free (key_file);
1897 if (mime_types != NULL)
1898 g_strfreev (mime_types);
1901 g_error_free (load_error);
1905 mime_info_cache_dir_init_defaults_list (MimeInfoCacheDir *dir)
1909 gchar *filename, **mime_types;
1910 char *unaliased_type;
1911 char **desktop_file_ids;
1918 if (dir->defaults_list_map != NULL &&
1919 !mime_info_cache_dir_out_of_date (dir, "defaults.list",
1920 &dir->defaults_list_timestamp))
1923 if (dir->defaults_list_map != NULL)
1924 g_hash_table_destroy (dir->defaults_list_map);
1926 dir->defaults_list_map = g_hash_table_new_full (g_str_hash, g_str_equal,
1927 g_free, (GDestroyNotify)g_strfreev);
1929 key_file = g_key_file_new ();
1931 filename = g_build_filename (dir->path, "defaults.list", NULL);
1932 if (g_stat (filename, &buf) < 0)
1935 if (dir->defaults_list_timestamp > 0)
1936 mime_info_cache->should_ping_mime_monitor = TRUE;
1938 dir->defaults_list_timestamp = buf.st_mtime;
1940 g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, &load_error);
1944 if (load_error != NULL)
1947 mime_types = g_key_file_get_keys (key_file, DEFAULT_APPLICATIONS_GROUP,
1950 if (load_error != NULL)
1953 for (i = 0; mime_types[i] != NULL; i++)
1955 desktop_file_ids = g_key_file_get_string_list (key_file,
1956 DEFAULT_APPLICATIONS_GROUP,
1960 if (desktop_file_ids == NULL)
1963 unaliased_type = _g_unix_content_type_unalias (mime_types[i]);
1964 g_hash_table_replace (dir->defaults_list_map,
1969 g_strfreev (mime_types);
1970 g_key_file_free (key_file);
1975 g_key_file_free (key_file);
1977 if (mime_types != NULL)
1978 g_strfreev (mime_types);
1981 g_error_free (load_error);
1984 static MimeInfoCacheDir *
1985 mime_info_cache_dir_new (const char *path)
1987 MimeInfoCacheDir *dir;
1989 dir = g_new0 (MimeInfoCacheDir, 1);
1990 dir->path = g_strdup (path);
1996 mime_info_cache_dir_free (MimeInfoCacheDir *dir)
2001 if (dir->mime_info_cache_map != NULL)
2003 destroy_info_cache_map (dir->mime_info_cache_map);
2004 dir->mime_info_cache_map = NULL;
2008 if (dir->defaults_list_map != NULL)
2010 g_hash_table_destroy (dir->defaults_list_map);
2011 dir->defaults_list_map = NULL;
2018 mime_info_cache_dir_add_desktop_entries (MimeInfoCacheDir *dir,
2019 const char *mime_type,
2020 char **new_desktop_file_ids)
2022 GList *desktop_file_ids;
2025 desktop_file_ids = g_hash_table_lookup (dir->mime_info_cache_map,
2028 for (i = 0; new_desktop_file_ids[i] != NULL; i++)
2030 if (!g_list_find (desktop_file_ids, new_desktop_file_ids[i]))
2031 desktop_file_ids = g_list_append (desktop_file_ids,
2032 g_strdup (new_desktop_file_ids[i]));
2035 g_hash_table_insert (dir->mime_info_cache_map, g_strdup (mime_type), desktop_file_ids);
2039 mime_info_cache_init_dir_lists (void)
2041 const char * const *dirs;
2044 mime_info_cache = mime_info_cache_new ();
2046 dirs = get_applications_search_path ();
2048 for (i = 0; dirs[i] != NULL; i++)
2050 MimeInfoCacheDir *dir;
2052 dir = mime_info_cache_dir_new (dirs[i]);
2056 mime_info_cache_dir_init (dir);
2057 mime_info_cache_dir_init_defaults_list (dir);
2059 mime_info_cache->dirs = g_list_append (mime_info_cache->dirs, dir);
2065 mime_info_cache_update_dir_lists (void)
2069 tmp = mime_info_cache->dirs;
2073 MimeInfoCacheDir *dir = (MimeInfoCacheDir *) tmp->data;
2075 /* No need to do this if we had file monitors... */
2076 mime_info_cache_blow_global_cache ();
2077 mime_info_cache_dir_init (dir);
2078 mime_info_cache_dir_init_defaults_list (dir);
2085 mime_info_cache_init (void)
2087 G_LOCK (mime_info_cache);
2088 if (mime_info_cache == NULL)
2089 mime_info_cache_init_dir_lists ();
2095 if (now >= mime_info_cache->last_stat_time + 10)
2097 mime_info_cache_update_dir_lists ();
2098 mime_info_cache->last_stat_time = now;
2102 if (mime_info_cache->should_ping_mime_monitor)
2104 /* g_idle_add (emit_mime_changed, NULL); */
2105 mime_info_cache->should_ping_mime_monitor = FALSE;
2108 G_UNLOCK (mime_info_cache);
2111 static MimeInfoCache *
2112 mime_info_cache_new (void)
2114 MimeInfoCache *cache;
2116 cache = g_new0 (MimeInfoCache, 1);
2118 cache->global_defaults_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
2119 (GDestroyNotify) g_free,
2120 (GDestroyNotify) g_free);
2125 mime_info_cache_free (MimeInfoCache *cache)
2130 g_list_foreach (cache->dirs,
2131 (GFunc) mime_info_cache_dir_free,
2133 g_list_free (cache->dirs);
2134 g_hash_table_destroy (cache->global_defaults_cache);
2139 * mime_info_cache_reload:
2140 * @dir: directory path which needs reloading.
2142 * Reload the mime information for the @dir.
2145 mime_info_cache_reload (const char *dir)
2147 /* FIXME: just reload the dir that needs reloading,
2148 * don't blow the whole cache
2150 if (mime_info_cache != NULL)
2152 G_LOCK (mime_info_cache);
2153 mime_info_cache_free (mime_info_cache);
2154 mime_info_cache = NULL;
2155 G_UNLOCK (mime_info_cache);
2160 append_desktop_entry (GList *list,
2161 const char *desktop_entry)
2163 /* Add if not already in list, and valid */
2164 if (!g_list_find_custom (list, desktop_entry, (GCompareFunc) strcmp))
2165 list = g_list_prepend (list, g_strdup (desktop_entry));
2171 * get_all_desktop_entries_for_mime_type:
2172 * @mime_type: a mime type.
2174 * Returns all the desktop ids for @mime_type. The desktop files
2175 * are listed in an order so that default applications are listed before
2176 * non-default ones, and handlers for inherited mimetypes are listed
2177 * after the base ones.
2179 * Return value: a #GList containing the desktop ids which claim
2180 * to handle @mime_type.
2183 get_all_desktop_entries_for_mime_type (const char *base_mime_type)
2185 GList *desktop_entries, *list, *dir_list, *tmp;
2186 MimeInfoCacheDir *dir;
2189 char **default_entries;
2192 mime_info_cache_init ();
2194 mime_types = _g_unix_content_type_get_parents (base_mime_type);
2195 G_LOCK (mime_info_cache);
2197 desktop_entries = NULL;
2198 for (i = 0; mime_types[i] != NULL; i++)
2200 mime_type = mime_types[i];
2202 /* Go through all apps listed as defaults */
2203 for (dir_list = mime_info_cache->dirs;
2205 dir_list = dir_list->next)
2207 dir = dir_list->data;
2208 default_entries = g_hash_table_lookup (dir->defaults_list_map, mime_type);
2209 for (j = 0; default_entries != NULL && default_entries[j] != NULL; j++)
2210 desktop_entries = append_desktop_entry (desktop_entries, default_entries[j]);
2213 /* Go through all entries that support the mimetype */
2214 for (dir_list = mime_info_cache->dirs;
2216 dir_list = dir_list->next)
2218 dir = dir_list->data;
2220 list = g_hash_table_lookup (dir->mime_info_cache_map, mime_type);
2221 for (tmp = list; tmp != NULL; tmp = tmp->next)
2222 desktop_entries = append_desktop_entry (desktop_entries, tmp->data);
2226 G_UNLOCK (mime_info_cache);
2228 g_strfreev (mime_types);
2230 desktop_entries = g_list_reverse (desktop_entries);
2232 return desktop_entries;
2235 #define __G_DESKTOP_APP_INFO_C__
2236 #include "gioaliasdef.c"