| 
									
										
											  
											
												Implement this function by moving bits from glocalfileinfo.c
2008-02-21  David Zeuthen  <davidz@redhat.com>
	* glocalfileinfo.c: (_g_local_file_info_get):
	* gcontenttype.c:
	(g_content_type_get_icon): Implement this function by
	moving bits from glocalfileinfo.c
	(g_content_type_get_description): Unalias before getting
	description (#517687)
	* gfile.c: (g_file_class_init),
	(g_file_query_filesystem_info_async),
	(g_file_query_filesystem_info_finish),
	(query_filesystem_info_data_free),
	(query_filesystem_info_async_thread),
	(g_file_real_query_filesystem_info_async),
	(g_file_real_query_filesystem_info_finish):
	* gfile.h: Implement async version of
	g_file_query_filesystem_info()
	* gfileinfo.h: Add new attributes for filesystem::use-preview
	* gio.symbols: Update
	* gthemedicon.c: (g_themed_icon_append_name):
	* gthemedicon.h: Add new new convenience function.
	* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
	(get_mounts), (get_volumes), (get_connected_drives),
	(get_volume_for_uuid), (get_mount_for_uuid),
	(g_union_volume_monitor_init), (populate_union_monitor),
	(g_volume_monitor_get), (_g_mount_get_for_mount_path),
	(g_volume_monitor_adopt_orphan_mount):
	* gvolumemonitor.c:
	* gvolumemonitor.h: Use recursive locks so it's safe for volume
	monitor implementations to call into the main volume monitor. Also
	separate object initialization and volume monitor initialization
	such that non-native volume monitors can properly adopt their
	mounts away.
svn path=/trunk/; revision=6550
											
										 
											2008-02-21 12:35:05 +00:00
										 |  |  |  | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | /* GIO - GLib Input, Output and Streaming Library
 | 
					
						
							| 
									
										
										
										
											2012-07-03 21:13:32 -04:00
										 |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  * Copyright (C) 2006-2007 Red Hat, Inc. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-05-18 09:12:45 +01:00
										 |  |  |  |  * SPDX-License-Identifier: LGPL-2.1-or-later | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							| 
									
										
										
										
											2017-05-27 18:21:30 +02:00
										 |  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * You should have received a copy of the GNU Lesser General | 
					
						
							| 
									
										
										
										
											2014-01-23 12:58:29 +01:00
										 |  |  |  |  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Author: Alexander Larsson <alexl@redhat.com> | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-22 15:10:51 +00:00
										 |  |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | #include <sys/types.h>
 | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | #include <stdlib.h>
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | #include <string.h>
 | 
					
						
							|  |  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  |  | #include "gcontenttypeprivate.h"
 | 
					
						
							| 
									
										
											  
											
												Implement this function by moving bits from glocalfileinfo.c
2008-02-21  David Zeuthen  <davidz@redhat.com>
	* glocalfileinfo.c: (_g_local_file_info_get):
	* gcontenttype.c:
	(g_content_type_get_icon): Implement this function by
	moving bits from glocalfileinfo.c
	(g_content_type_get_description): Unalias before getting
	description (#517687)
	* gfile.c: (g_file_class_init),
	(g_file_query_filesystem_info_async),
	(g_file_query_filesystem_info_finish),
	(query_filesystem_info_data_free),
	(query_filesystem_info_async_thread),
	(g_file_real_query_filesystem_info_async),
	(g_file_real_query_filesystem_info_finish):
	* gfile.h: Implement async version of
	g_file_query_filesystem_info()
	* gfileinfo.h: Add new attributes for filesystem::use-preview
	* gio.symbols: Update
	* gthemedicon.c: (g_themed_icon_append_name):
	* gthemedicon.h: Add new new convenience function.
	* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
	(get_mounts), (get_volumes), (get_connected_drives),
	(get_volume_for_uuid), (get_mount_for_uuid),
	(g_union_volume_monitor_init), (populate_union_monitor),
	(g_volume_monitor_get), (_g_mount_get_for_mount_path),
	(g_volume_monitor_adopt_orphan_mount):
	* gvolumemonitor.c:
	* gvolumemonitor.h: Use recursive locks so it's safe for volume
	monitor implementations to call into the main volume monitor. Also
	separate object initialization and volume monitor initialization
	such that non-native volume monitors can properly adopt their
	mounts away.
svn path=/trunk/; revision=6550
											
										 
											2008-02-21 12:35:05 +00:00
										 |  |  |  | #include "gthemedicon.h"
 | 
					
						
							| 
									
										
										
										
											2008-07-02 01:54:16 +00:00
										 |  |  |  | #include "gicon.h"
 | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | #include "gfile.h"
 | 
					
						
							|  |  |  |  | #include "gfileenumerator.h"
 | 
					
						
							|  |  |  |  | #include "gfileinfo.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | #include "glibintl.h"
 | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  | #include "glib-private.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-12-03 22:37:44 +00:00
										 |  |  |  | #include <dirent.h>
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | #define XDG_PREFIX _gio_xdg
 | 
					
						
							|  |  |  |  | #include "xdgmime/xdgmime.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  | static void tree_magic_schedule_reload (void); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  | /* We lock this mutex whenever we modify global state in this module.
 | 
					
						
							|  |  |  |  |  * Taking and releasing this lock should always be associated with a pair of | 
					
						
							|  |  |  |  |  * g_begin_ignore_leaks()/g_end_ignore_leaks() calls, as any call into xdgmime | 
					
						
							|  |  |  |  |  * could trigger xdg_mime_init(), which makes a number of one-time allocations | 
					
						
							|  |  |  |  |  * which GLib can never free as it doesn’t know when is suitable to call | 
					
						
							|  |  |  |  |  * xdg_mime_shutdown(). */ | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | G_LOCK_DEFINE_STATIC (gio_xdgmime); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | gsize | 
					
						
							|  |  |  |  | _g_unix_content_type_get_sniff_len (void) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   gsize size; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_begin_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   size = xdg_mime_get_max_buffer_extents (); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_end_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return size; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | gchar * | 
					
						
							|  |  |  |  | _g_unix_content_type_unalias (const gchar *type) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   gchar *res; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_begin_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   res = g_strdup (xdg_mime_unalias_mime_type (type)); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_end_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   return res; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | gchar ** | 
					
						
							|  |  |  |  | _g_unix_content_type_get_parents (const gchar *type) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   const gchar *umime; | 
					
						
							|  |  |  |  |   gchar **parents; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   GPtrArray *array; | 
					
						
							|  |  |  |  |   int i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   array = g_ptr_array_new (); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_begin_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   umime = xdg_mime_unalias_mime_type (type); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   g_ptr_array_add (array, g_strdup (umime)); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-29 10:20:49 +00:00
										 |  |  |  |   parents = xdg_mime_list_mime_parents (umime); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   for (i = 0; parents && parents[i] != NULL; i++) | 
					
						
							|  |  |  |  |     g_ptr_array_add (array, g_strdup (parents[i])); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-29 10:20:49 +00:00
										 |  |  |  |   free (parents); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_end_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   g_ptr_array_add (array, NULL); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   return (gchar **)g_ptr_array_free (array, FALSE); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  | G_LOCK_DEFINE_STATIC (global_mime_dirs); | 
					
						
							|  |  |  |  | static gchar **global_mime_dirs = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | _g_content_type_set_mime_dirs_locked (const char * const *dirs) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_clear_pointer (&global_mime_dirs, g_strfreev); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (dirs != NULL) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       global_mime_dirs = g_strdupv ((gchar **) dirs); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   else | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       GPtrArray *mime_dirs = g_ptr_array_new_with_free_func (g_free); | 
					
						
							|  |  |  |  |       const gchar * const *system_dirs = g_get_system_data_dirs (); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       g_ptr_array_add (mime_dirs, g_build_filename (g_get_user_data_dir (), "mime", NULL)); | 
					
						
							|  |  |  |  |       for (; *system_dirs != NULL; system_dirs++) | 
					
						
							|  |  |  |  |         g_ptr_array_add (mime_dirs, g_build_filename (*system_dirs, "mime", NULL)); | 
					
						
							|  |  |  |  |       g_ptr_array_add (mime_dirs, NULL);  /* NULL terminator */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       global_mime_dirs = (gchar **) g_ptr_array_free (mime_dirs, FALSE); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   xdg_mime_set_dirs ((const gchar * const *) global_mime_dirs); | 
					
						
							|  |  |  |  |   tree_magic_schedule_reload (); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /*< private >*/ | 
					
						
							|  |  |  |  | void | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_set_mime_dirs_impl (const gchar * const *dirs) | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   G_LOCK (global_mime_dirs); | 
					
						
							|  |  |  |  |   _g_content_type_set_mime_dirs_locked (dirs); | 
					
						
							|  |  |  |  |   G_UNLOCK (global_mime_dirs); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /*< private >*/ | 
					
						
							|  |  |  |  | const gchar * const * | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_get_mime_dirs_impl (void) | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   const gchar * const *mime_dirs; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   G_LOCK (global_mime_dirs); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (global_mime_dirs == NULL) | 
					
						
							|  |  |  |  |     _g_content_type_set_mime_dirs_locked (NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   mime_dirs = (const gchar * const *) global_mime_dirs; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   G_UNLOCK (global_mime_dirs); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_assert (mime_dirs != NULL); | 
					
						
							|  |  |  |  |   return mime_dirs; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | gboolean | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_equals_impl (const gchar *type1, | 
					
						
							|  |  |  |  |                             const gchar *type2) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   gboolean res; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   g_return_val_if_fail (type1 != NULL, FALSE); | 
					
						
							|  |  |  |  |   g_return_val_if_fail (type2 != NULL, FALSE); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_begin_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   res = xdg_mime_mime_type_equal (type1, type2); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_end_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   return res; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | gboolean | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_is_a_impl (const gchar *type, | 
					
						
							|  |  |  |  |                           const gchar *supertype) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   gboolean res; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   g_return_val_if_fail (type != NULL, FALSE); | 
					
						
							|  |  |  |  |   g_return_val_if_fail (supertype != NULL, FALSE); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_begin_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   res = xdg_mime_mime_type_subclass (type, supertype); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_end_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   return res; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-08 23:02:10 -05:00
										 |  |  |  | gboolean | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_is_mime_type_impl (const gchar *type, | 
					
						
							|  |  |  |  |                                   const gchar *mime_type) | 
					
						
							| 
									
										
										
										
											2017-03-08 23:02:10 -05:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   return g_content_type_is_a (type, mime_type); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | gboolean | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_is_unknown_impl (const gchar *type) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_val_if_fail (type != NULL, FALSE); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return strcmp (XDG_MIME_TYPE_UNKNOWN, type) == 0; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | typedef enum { | 
					
						
							|  |  |  |  |   MIME_TAG_TYPE_OTHER, | 
					
						
							|  |  |  |  |   MIME_TAG_TYPE_COMMENT | 
					
						
							|  |  |  |  | } MimeTagType; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | typedef struct { | 
					
						
							|  |  |  |  |   int current_type; | 
					
						
							|  |  |  |  |   int current_lang_level; | 
					
						
							|  |  |  |  |   int comment_lang_level; | 
					
						
							|  |  |  |  |   char *comment; | 
					
						
							|  |  |  |  | } MimeParser; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static int | 
					
						
							|  |  |  |  | language_level (const char *lang) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   const char * const *lang_list; | 
					
						
							|  |  |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   /* The returned list is sorted from most desirable to least
 | 
					
						
							|  |  |  |  |      desirable and always contains the default locale "C". */ | 
					
						
							|  |  |  |  |   lang_list = g_get_language_names (); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   for (i = 0; lang_list[i]; i++) | 
					
						
							|  |  |  |  |     if (strcmp (lang_list[i], lang) == 0) | 
					
						
							|  |  |  |  |       return 1000-i; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   return 0; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  | mime_info_start_element (GMarkupParseContext  *context, | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |                          const gchar          *element_name, | 
					
						
							|  |  |  |  |                          const gchar         **attribute_names, | 
					
						
							|  |  |  |  |                          const gchar         **attribute_values, | 
					
						
							|  |  |  |  |                          gpointer              user_data, | 
					
						
							|  |  |  |  |                          GError              **error) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   int i; | 
					
						
							|  |  |  |  |   const char *lang; | 
					
						
							|  |  |  |  |   MimeParser *parser = user_data; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   if (strcmp (element_name, "comment") == 0) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       lang = "C"; | 
					
						
							|  |  |  |  |       for (i = 0; attribute_names[i]; i++) | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |         if (strcmp (attribute_names[i], "xml:lang") == 0) | 
					
						
							|  |  |  |  |           { | 
					
						
							|  |  |  |  |             lang = attribute_values[i]; | 
					
						
							|  |  |  |  |             break; | 
					
						
							|  |  |  |  |           } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |       parser->current_lang_level = language_level (lang); | 
					
						
							|  |  |  |  |       parser->current_type = MIME_TAG_TYPE_COMMENT; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   else | 
					
						
							|  |  |  |  |     parser->current_type = MIME_TAG_TYPE_OTHER; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  | mime_info_end_element (GMarkupParseContext  *context, | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |                        const gchar          *element_name, | 
					
						
							|  |  |  |  |                        gpointer              user_data, | 
					
						
							|  |  |  |  |                        GError              **error) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   MimeParser *parser = user_data; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   parser->current_type = MIME_TAG_TYPE_OTHER; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  | mime_info_text (GMarkupParseContext  *context, | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |                 const gchar          *text, | 
					
						
							|  |  |  |  |                 gsize                 text_len, | 
					
						
							|  |  |  |  |                 gpointer              user_data, | 
					
						
							|  |  |  |  |                 GError              **error) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   MimeParser *parser = user_data; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (parser->current_type == MIME_TAG_TYPE_COMMENT && | 
					
						
							|  |  |  |  |       parser->current_lang_level > parser->comment_lang_level) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       g_free (parser->comment); | 
					
						
							|  |  |  |  |       parser->comment = g_strndup (text, text_len); | 
					
						
							|  |  |  |  |       parser->comment_lang_level = parser->current_lang_level; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static char * | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | load_comment_for_mime_helper (const char *dir, | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  |                               const char *basename) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   GMarkupParseContext *context; | 
					
						
							|  |  |  |  |   char *filename, *data; | 
					
						
							|  |  |  |  |   gsize len; | 
					
						
							|  |  |  |  |   gboolean res; | 
					
						
							|  |  |  |  |   MimeParser parse_data = {0}; | 
					
						
							|  |  |  |  |   GMarkupParser parser = { | 
					
						
							|  |  |  |  |     mime_info_start_element, | 
					
						
							|  |  |  |  |     mime_info_end_element, | 
					
						
							| 
									
										
										
										
											2020-11-17 11:18:15 +01:00
										 |  |  |  |     mime_info_text, | 
					
						
							|  |  |  |  |     NULL, | 
					
						
							|  |  |  |  |     NULL | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   filename = g_build_filename (dir, basename, NULL); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   res = g_file_get_contents (filename,  &data,  &len,  NULL); | 
					
						
							|  |  |  |  |   g_free (filename); | 
					
						
							|  |  |  |  |   if (!res) | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-25 00:18:23 +01:00
										 |  |  |  |   context = g_markup_parse_context_new (&parser, G_MARKUP_DEFAULT_FLAGS, &parse_data, NULL); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   res = g_markup_parse_context_parse (context, data, len, NULL); | 
					
						
							|  |  |  |  |   g_free (data); | 
					
						
							|  |  |  |  |   g_markup_parse_context_free (context); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   if (!res) | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return parse_data.comment; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static char * | 
					
						
							|  |  |  |  | load_comment_for_mime (const char *mimetype) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   const char * const *dirs; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   char *basename; | 
					
						
							|  |  |  |  |   char *comment; | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   gsize i; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   basename = g_strdup_printf ("%s.xml", mimetype); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   dirs = g_content_type_get_mime_dirs (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   for (i = 0; dirs[i] != NULL; i++) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       comment = load_comment_for_mime_helper (dirs[i], basename); | 
					
						
							|  |  |  |  |       if (comment) | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           g_free (basename); | 
					
						
							|  |  |  |  |           return comment; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   g_free (basename); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   return g_strdup_printf (_("%s type"), mimetype); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | gchar * | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_get_description_impl (const gchar *type) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   static GHashTable *type_comment_cache = NULL; | 
					
						
							| 
									
										
										
										
											2022-06-28 10:51:42 +01:00
										 |  |  |  |   gchar *type_copy = NULL; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   gchar *comment; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_return_val_if_fail (type != NULL, NULL); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_begin_ignore_leaks (); | 
					
						
							| 
									
										
											  
											
												Implement this function by moving bits from glocalfileinfo.c
2008-02-21  David Zeuthen  <davidz@redhat.com>
	* glocalfileinfo.c: (_g_local_file_info_get):
	* gcontenttype.c:
	(g_content_type_get_icon): Implement this function by
	moving bits from glocalfileinfo.c
	(g_content_type_get_description): Unalias before getting
	description (#517687)
	* gfile.c: (g_file_class_init),
	(g_file_query_filesystem_info_async),
	(g_file_query_filesystem_info_finish),
	(query_filesystem_info_data_free),
	(query_filesystem_info_async_thread),
	(g_file_real_query_filesystem_info_async),
	(g_file_real_query_filesystem_info_finish):
	* gfile.h: Implement async version of
	g_file_query_filesystem_info()
	* gfileinfo.h: Add new attributes for filesystem::use-preview
	* gio.symbols: Update
	* gthemedicon.c: (g_themed_icon_append_name):
	* gthemedicon.h: Add new new convenience function.
	* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
	(get_mounts), (get_volumes), (get_connected_drives),
	(get_volume_for_uuid), (get_mount_for_uuid),
	(g_union_volume_monitor_init), (populate_union_monitor),
	(g_volume_monitor_get), (_g_mount_get_for_mount_path),
	(g_volume_monitor_adopt_orphan_mount):
	* gvolumemonitor.c:
	* gvolumemonitor.h: Use recursive locks so it's safe for volume
	monitor implementations to call into the main volume monitor. Also
	separate object initialization and volume monitor initialization
	such that non-native volume monitors can properly adopt their
	mounts away.
svn path=/trunk/; revision=6550
											
										 
											2008-02-21 12:35:05 +00:00
										 |  |  |  |   type = xdg_mime_unalias_mime_type (type); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_end_ignore_leaks (); | 
					
						
							| 
									
										
											  
											
												Implement this function by moving bits from glocalfileinfo.c
2008-02-21  David Zeuthen  <davidz@redhat.com>
	* glocalfileinfo.c: (_g_local_file_info_get):
	* gcontenttype.c:
	(g_content_type_get_icon): Implement this function by
	moving bits from glocalfileinfo.c
	(g_content_type_get_description): Unalias before getting
	description (#517687)
	* gfile.c: (g_file_class_init),
	(g_file_query_filesystem_info_async),
	(g_file_query_filesystem_info_finish),
	(query_filesystem_info_data_free),
	(query_filesystem_info_async_thread),
	(g_file_real_query_filesystem_info_async),
	(g_file_real_query_filesystem_info_finish):
	* gfile.h: Implement async version of
	g_file_query_filesystem_info()
	* gfileinfo.h: Add new attributes for filesystem::use-preview
	* gio.symbols: Update
	* gthemedicon.c: (g_themed_icon_append_name):
	* gthemedicon.h: Add new new convenience function.
	* gunionvolumemonitor.c: (g_union_volume_monitor_dispose),
	(get_mounts), (get_volumes), (get_connected_drives),
	(get_volume_for_uuid), (get_mount_for_uuid),
	(g_union_volume_monitor_init), (populate_union_monitor),
	(g_volume_monitor_get), (_g_mount_get_for_mount_path),
	(g_volume_monitor_adopt_orphan_mount):
	* gvolumemonitor.c:
	* gvolumemonitor.h: Use recursive locks so it's safe for volume
	monitor implementations to call into the main volume monitor. Also
	separate object initialization and volume monitor initialization
	such that non-native volume monitors can properly adopt their
	mounts away.
svn path=/trunk/; revision=6550
											
										 
											2008-02-21 12:35:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   if (type_comment_cache == NULL) | 
					
						
							|  |  |  |  |     type_comment_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   comment = g_hash_table_lookup (type_comment_cache, type); | 
					
						
							|  |  |  |  |   comment = g_strdup (comment); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   if (comment != NULL) | 
					
						
							| 
									
										
										
										
											2022-06-28 10:51:42 +01:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       G_UNLOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2022-06-28 10:57:29 +01:00
										 |  |  |  |       return g_steal_pointer (&comment); | 
					
						
							| 
									
										
										
										
											2022-06-28 10:51:42 +01:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-28 10:51:42 +01:00
										 |  |  |  |   type_copy = g_strdup (type); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-28 10:51:42 +01:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							|  |  |  |  |   comment = load_comment_for_mime (type_copy); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2022-06-28 10:51:42 +01:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   g_hash_table_insert (type_comment_cache, | 
					
						
							| 
									
										
										
										
											2022-06-28 10:51:42 +01:00
										 |  |  |  |                        g_steal_pointer (&type_copy), | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |                        g_strdup (comment)); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-28 10:57:29 +01:00
										 |  |  |  |   return g_steal_pointer (&comment); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | char * | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_get_mime_type_impl (const char *type) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_val_if_fail (type != NULL, NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return g_strdup (type); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-28 19:22:01 -04:00
										 |  |  |  | static GIcon * | 
					
						
							|  |  |  |  | g_content_type_get_icon_internal (const gchar *type, | 
					
						
							|  |  |  |  |                                   gboolean     symbolic) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-08-28 19:22:01 -04:00
										 |  |  |  |   char *mimetype_icon; | 
					
						
							| 
									
										
										
										
											2012-09-10 15:16:58 -04:00
										 |  |  |  |   char *generic_mimetype_icon = NULL; | 
					
						
							| 
									
										
										
										
											2012-08-28 19:22:01 -04:00
										 |  |  |  |   char *q; | 
					
						
							| 
									
										
										
										
											2014-02-23 00:52:31 -05:00
										 |  |  |  |   char *icon_names[6]; | 
					
						
							| 
									
										
										
										
											2008-06-10 10:51:29 +00:00
										 |  |  |  |   int n = 0; | 
					
						
							| 
									
										
										
										
											2008-02-27 11:23:35 +00:00
										 |  |  |  |   GIcon *themed_icon; | 
					
						
							| 
									
										
										
										
											2012-11-30 09:39:13 +01:00
										 |  |  |  |   const char  *xdg_icon; | 
					
						
							| 
									
										
										
										
											2014-02-23 00:52:31 -05:00
										 |  |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   g_return_val_if_fail (type != NULL, NULL); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-09 17:33:43 +00:00
										 |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_begin_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2012-11-30 09:39:13 +01:00
										 |  |  |  |   xdg_icon = xdg_mime_get_icon (type); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_end_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2008-06-09 17:33:43 +00:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-23 00:52:31 -05:00
										 |  |  |  |   if (xdg_icon) | 
					
						
							|  |  |  |  |     icon_names[n++] = g_strdup (xdg_icon); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-23 00:52:31 -05:00
										 |  |  |  |   mimetype_icon = g_strdup (type); | 
					
						
							| 
									
										
										
										
											2008-02-27 11:23:35 +00:00
										 |  |  |  |   while ((q = strchr (mimetype_icon, '/')) != NULL) | 
					
						
							|  |  |  |  |     *q = '-'; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-09 17:33:43 +00:00
										 |  |  |  |   icon_names[n++] = mimetype_icon; | 
					
						
							| 
									
										
										
										
											2008-10-10 05:07:56 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-23 00:52:31 -05:00
										 |  |  |  |   generic_mimetype_icon = g_content_type_get_generic_icon_name (type); | 
					
						
							| 
									
										
										
										
											2012-09-10 15:16:58 -04:00
										 |  |  |  |   if (generic_mimetype_icon) | 
					
						
							|  |  |  |  |     icon_names[n++] = generic_mimetype_icon; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-23 00:52:31 -05:00
										 |  |  |  |   if (symbolic) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       for (i = 0; i < n; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           icon_names[n + i] = icon_names[i]; | 
					
						
							|  |  |  |  |           icon_names[i] = g_strconcat (icon_names[i], "-symbolic", NULL); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       n += n; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-09 17:33:43 +00:00
										 |  |  |  |   themed_icon = g_themed_icon_new_from_names (icon_names, n); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-23 00:52:31 -05:00
										 |  |  |  |   for (i = 0; i < n; i++) | 
					
						
							|  |  |  |  |     g_free (icon_names[i]); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-27 11:23:35 +00:00
										 |  |  |  |   return themed_icon; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-28 19:22:01 -04:00
										 |  |  |  | GIcon * | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_get_icon_impl (const gchar *type) | 
					
						
							| 
									
										
										
										
											2012-08-28 19:22:01 -04:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   return g_content_type_get_icon_internal (type, FALSE); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | GIcon * | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_get_symbolic_icon_impl (const gchar *type) | 
					
						
							| 
									
										
										
										
											2012-08-28 19:22:01 -04:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   return g_content_type_get_icon_internal (type, TRUE); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-10 15:16:58 -04:00
										 |  |  |  | gchar * | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_get_generic_icon_name_impl (const gchar *type) | 
					
						
							| 
									
										
										
										
											2012-09-10 15:16:58 -04:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   const gchar *xdg_icon_name; | 
					
						
							|  |  |  |  |   gchar *icon_name; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-28 15:09:50 +01:00
										 |  |  |  |   g_return_val_if_fail (type != NULL, NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-10 15:16:58 -04:00
										 |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_begin_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2012-09-10 15:16:58 -04:00
										 |  |  |  |   xdg_icon_name = xdg_mime_get_generic_icon (type); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_end_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2012-09-10 15:16:58 -04:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (!xdg_icon_name) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       const char *p; | 
					
						
							|  |  |  |  |       const char *suffix = "-x-generic"; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       p = strchr (type, '/'); | 
					
						
							|  |  |  |  |       if (p == NULL) | 
					
						
							|  |  |  |  |         p = type + strlen (type); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       icon_name = g_malloc (p - type + strlen (suffix) + 1); | 
					
						
							|  |  |  |  |       memcpy (icon_name, type, p - type); | 
					
						
							|  |  |  |  |       memcpy (icon_name + (p - type), suffix, strlen (suffix)); | 
					
						
							|  |  |  |  |       icon_name[(p - type) + strlen (suffix)] = 0; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   else | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       icon_name = g_strdup (xdg_icon_name); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return icon_name; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | gboolean | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_can_be_executable_impl (const gchar *type) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_val_if_fail (type != NULL, FALSE); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (g_content_type_is_a (type, "application/x-executable")  || | 
					
						
							|  |  |  |  |       g_content_type_is_a (type, "text/plain")) | 
					
						
							|  |  |  |  |     return TRUE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return FALSE; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static gboolean | 
					
						
							|  |  |  |  | looks_like_text (const guchar *data, gsize data_size) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   gsize i; | 
					
						
							| 
									
										
										
										
											2008-01-29 14:19:46 +00:00
										 |  |  |  |   char c; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   for (i = 0; i < data_size; i++) | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-01-29 14:19:46 +00:00
										 |  |  |  |       c = data[i]; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-29 14:19:46 +00:00
										 |  |  |  |       if (g_ascii_iscntrl (c) && | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           !g_ascii_isspace (c) && | 
					
						
							|  |  |  |  |           c != '\b') | 
					
						
							|  |  |  |  |         return FALSE; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  |   return TRUE; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | gchar * | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_from_mime_type_impl (const gchar *mime_type) | 
					
						
							| 
									
										
										
										
											2008-05-18 02:50:48 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-06-30 04:59:40 +00:00
										 |  |  |  |   char *umime; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-05-18 02:50:48 +00:00
										 |  |  |  |   g_return_val_if_fail (mime_type != NULL, NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-30 04:59:40 +00:00
										 |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_begin_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2008-05-18 02:50:48 +00:00
										 |  |  |  |   /* mime type and content type are same on unixes */ | 
					
						
							| 
									
										
										
										
											2008-06-30 04:59:40 +00:00
										 |  |  |  |   umime = g_strdup (xdg_mime_unalias_mime_type (mime_type)); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_end_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2008-07-02 19:06:08 +00:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2008-06-30 04:59:40 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   return umime; | 
					
						
							| 
									
										
										
										
											2008-05-18 02:50:48 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | gchar * | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_guess_impl (const gchar  *filename, | 
					
						
							|  |  |  |  |                            const guchar *data, | 
					
						
							|  |  |  |  |                            gsize         data_size, | 
					
						
							|  |  |  |  |                            gboolean     *result_uncertain) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   char *basename; | 
					
						
							|  |  |  |  |   const char *name_mimetypes[10], *sniffed_mimetype; | 
					
						
							|  |  |  |  |   char *mimetype; | 
					
						
							|  |  |  |  |   int i; | 
					
						
							|  |  |  |  |   int n_name_mimetypes; | 
					
						
							|  |  |  |  |   int sniffed_prio; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   sniffed_prio = 0; | 
					
						
							|  |  |  |  |   n_name_mimetypes = 0; | 
					
						
							|  |  |  |  |   sniffed_mimetype = XDG_MIME_TYPE_UNKNOWN; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (result_uncertain) | 
					
						
							|  |  |  |  |     *result_uncertain = FALSE; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-27 09:25:37 +02:00
										 |  |  |  |   /* our test suite and potentially other code used -1 in the past, which is
 | 
					
						
							|  |  |  |  |    * not documented and not allowed; guard against that */ | 
					
						
							|  |  |  |  |   g_return_val_if_fail (data_size != (gsize) -1, g_strdup (XDG_MIME_TYPE_UNKNOWN)); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_LOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_begin_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   if (filename) | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-09-15 16:06:05 +00:00
										 |  |  |  |       i = strlen (filename); | 
					
						
							| 
									
										
										
										
											2022-02-16 18:50:17 +04:00
										 |  |  |  |       if (i > 0 && filename[i - 1] == '/') | 
					
						
							| 
									
										
										
										
											2008-09-16 11:36:52 +00:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           name_mimetypes[0] = "inode/directory"; | 
					
						
							|  |  |  |  |           name_mimetypes[1] = NULL; | 
					
						
							|  |  |  |  |           n_name_mimetypes = 1; | 
					
						
							|  |  |  |  |           if (result_uncertain) | 
					
						
							|  |  |  |  |             *result_uncertain = TRUE; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |       else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |           basename = g_path_get_basename (filename); | 
					
						
							|  |  |  |  |           n_name_mimetypes = xdg_mime_get_mime_types_from_file_name (basename, name_mimetypes, 10); | 
					
						
							|  |  |  |  |           g_free (basename); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   /* Got an extension match, and no conflicts. This is it. */ | 
					
						
							|  |  |  |  |   if (n_name_mimetypes == 1) | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-01-24 12:33:39 +09:00
										 |  |  |  |       gchar *s = g_strdup (name_mimetypes[0]); | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |       g_end_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |       G_UNLOCK (gio_xdgmime); | 
					
						
							| 
									
										
										
										
											2013-01-24 12:33:39 +09:00
										 |  |  |  |       return s; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   if (data) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       sniffed_mimetype = xdg_mime_get_mime_type_for_data (data, data_size, &sniffed_prio); | 
					
						
							|  |  |  |  |       if (sniffed_mimetype == XDG_MIME_TYPE_UNKNOWN && | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           data && | 
					
						
							|  |  |  |  |           looks_like_text (data, data_size)) | 
					
						
							|  |  |  |  |         sniffed_mimetype = "text/plain"; | 
					
						
							| 
									
										
										
										
											2009-02-20 07:46:57 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |       /* For security reasons we don't ever want to sniff desktop files
 | 
					
						
							|  |  |  |  |        * where we know the filename and it doesn't have a .desktop extension. | 
					
						
							|  |  |  |  |        * This is because desktop files allow executing any application and | 
					
						
							|  |  |  |  |        * we don't want to make it possible to hide them looking like something | 
					
						
							|  |  |  |  |        * else. | 
					
						
							|  |  |  |  |        */ | 
					
						
							|  |  |  |  |       if (filename != NULL && | 
					
						
							|  |  |  |  |           strcmp (sniffed_mimetype, "application/x-desktop") == 0) | 
					
						
							|  |  |  |  |         sniffed_mimetype = "text/plain"; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   if (n_name_mimetypes == 0) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       if (sniffed_mimetype == XDG_MIME_TYPE_UNKNOWN && | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           result_uncertain) | 
					
						
							|  |  |  |  |         *result_uncertain = TRUE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |       mimetype = g_strdup (sniffed_mimetype); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   else | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       mimetype = NULL; | 
					
						
							|  |  |  |  |       if (sniffed_mimetype != XDG_MIME_TYPE_UNKNOWN) | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           if (sniffed_prio >= 80) /* High priority sniffing match, use that */ | 
					
						
							|  |  |  |  |             mimetype = g_strdup (sniffed_mimetype); | 
					
						
							|  |  |  |  |           else | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |               /* There are conflicts between the name matches and we
 | 
					
						
							|  |  |  |  |                * have a sniffed type, use that as a tie breaker. | 
					
						
							|  |  |  |  |                */ | 
					
						
							|  |  |  |  |               for (i = 0; i < n_name_mimetypes; i++) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                   if ( xdg_mime_mime_type_subclass (name_mimetypes[i], sniffed_mimetype)) | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                       /* This nametype match is derived from (or the same as)
 | 
					
						
							|  |  |  |  |                        * the sniffed type). This is probably it. | 
					
						
							|  |  |  |  |                        */ | 
					
						
							|  |  |  |  |                       mimetype = g_strdup (name_mimetypes[i]); | 
					
						
							|  |  |  |  |                       break; | 
					
						
							|  |  |  |  |                     } | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |       if (mimetype == NULL) | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           /* Conflicts, and sniffed type was no help or not there.
 | 
					
						
							|  |  |  |  |            * Guess on the first one | 
					
						
							|  |  |  |  |            */ | 
					
						
							|  |  |  |  |           mimetype = g_strdup (name_mimetypes[0]); | 
					
						
							|  |  |  |  |           if (result_uncertain) | 
					
						
							|  |  |  |  |             *result_uncertain = TRUE; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 13:13:40 +01:00
										 |  |  |  |   g_end_ignore_leaks (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   G_UNLOCK (gio_xdgmime); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return mimetype; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | enumerate_mimetypes_subdir (const char *dir, | 
					
						
							|  |  |  |  |                             const char *prefix, | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  |                             GHashTable *mimetypes) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   DIR *d; | 
					
						
							|  |  |  |  |   struct dirent *ent; | 
					
						
							|  |  |  |  |   char *mimetype; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   d = opendir (dir); | 
					
						
							|  |  |  |  |   if (d) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       while ((ent = readdir (d)) != NULL) | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           if (g_str_has_suffix (ent->d_name, ".xml")) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |               mimetype = g_strdup_printf ("%s/%.*s", prefix, (int) strlen (ent->d_name) - 4, ent->d_name); | 
					
						
							|  |  |  |  |               g_hash_table_replace (mimetypes, mimetype, NULL); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |       closedir (d); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | enumerate_mimetypes_dir (const char *dir, | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  |                          GHashTable *mimetypes) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   DIR *d; | 
					
						
							|  |  |  |  |   struct dirent *ent; | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   const char *mimedir; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   char *name; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   mimedir = dir; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   d = opendir (mimedir); | 
					
						
							|  |  |  |  |   if (d) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       while ((ent = readdir (d)) != NULL) | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           if (strcmp (ent->d_name, "packages") != 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |               name = g_build_filename (mimedir, ent->d_name, NULL); | 
					
						
							|  |  |  |  |               if (g_file_test (name, G_FILE_TEST_IS_DIR)) | 
					
						
							|  |  |  |  |                 enumerate_mimetypes_subdir (name, ent->d_name, mimetypes); | 
					
						
							|  |  |  |  |               g_free (name); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |       closedir (d); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | GList * | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_types_get_registered_impl (void) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   const char * const *dirs; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   GHashTable *mimetypes; | 
					
						
							| 
									
										
										
										
											2007-12-15 04:39:26 +00:00
										 |  |  |  |   GHashTableIter iter; | 
					
						
							|  |  |  |  |   gpointer key; | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   gsize i; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   GList *l; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-20 16:49:16 +00:00
										 |  |  |  |   mimetypes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   dirs = g_content_type_get_mime_dirs (); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   for (i = 0; dirs[i] != NULL; i++) | 
					
						
							|  |  |  |  |     enumerate_mimetypes_dir (dirs[i], mimetypes); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   l = NULL; | 
					
						
							| 
									
										
										
										
											2007-12-15 04:39:26 +00:00
										 |  |  |  |   g_hash_table_iter_init (&iter, mimetypes); | 
					
						
							|  |  |  |  |   while (g_hash_table_iter_next (&iter, &key, NULL)) | 
					
						
							| 
									
										
										
										
											2008-10-20 16:49:16 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       l = g_list_prepend (l, key); | 
					
						
							|  |  |  |  |       g_hash_table_iter_steal (&iter); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2007-12-15 04:39:26 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   g_hash_table_destroy (mimetypes); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return l; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | /* tree magic data */ | 
					
						
							|  |  |  |  | static GList *tree_matches = NULL; | 
					
						
							|  |  |  |  | static gboolean need_reload = FALSE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | G_LOCK_DEFINE_STATIC (gio_treemagic); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | typedef struct | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   gchar *path; | 
					
						
							|  |  |  |  |   GFileType type; | 
					
						
							|  |  |  |  |   guint match_case : 1; | 
					
						
							|  |  |  |  |   guint executable : 1; | 
					
						
							|  |  |  |  |   guint non_empty  : 1; | 
					
						
							|  |  |  |  |   guint on_disc    : 1; | 
					
						
							|  |  |  |  |   gchar *mimetype; | 
					
						
							|  |  |  |  |   GList *matches; | 
					
						
							|  |  |  |  | } TreeMatchlet; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | typedef struct | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   gchar *contenttype; | 
					
						
							|  |  |  |  |   gint priority; | 
					
						
							|  |  |  |  |   GList *matches; | 
					
						
							|  |  |  |  | } TreeMatch; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | tree_matchlet_free (TreeMatchlet *matchlet) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-01-02 16:30:11 +01:00
										 |  |  |  |   g_list_free_full (matchlet->matches, (GDestroyNotify) tree_matchlet_free); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   g_free (matchlet->path); | 
					
						
							|  |  |  |  |   g_free (matchlet->mimetype); | 
					
						
							|  |  |  |  |   g_slice_free (TreeMatchlet, matchlet); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | tree_match_free (TreeMatch *match) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-01-02 16:30:11 +01:00
										 |  |  |  |   g_list_free_full (match->matches, (GDestroyNotify) tree_matchlet_free); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   g_free (match->contenttype); | 
					
						
							|  |  |  |  |   g_slice_free (TreeMatch, match); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static TreeMatch * | 
					
						
							|  |  |  |  | parse_header (gchar *line) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   gint len; | 
					
						
							|  |  |  |  |   gchar *s; | 
					
						
							|  |  |  |  |   TreeMatch *match; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   len = strlen (line); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (line[0] != '[' || line[len - 1] != ']') | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   line[len - 1] = 0; | 
					
						
							|  |  |  |  |   s = strchr (line, ':'); | 
					
						
							| 
									
										
										
										
											2021-10-11 13:52:26 +03:00
										 |  |  |  |   if (s == NULL) | 
					
						
							|  |  |  |  |     return NULL; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   match = g_slice_new0 (TreeMatch); | 
					
						
							|  |  |  |  |   match->priority = atoi (line + 1); | 
					
						
							|  |  |  |  |   match->contenttype = g_strdup (s + 1); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return match; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static TreeMatchlet * | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | parse_match_line (gchar *line, | 
					
						
							|  |  |  |  |                   gint  *depth) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   gchar *s, *p; | 
					
						
							|  |  |  |  |   TreeMatchlet *matchlet; | 
					
						
							|  |  |  |  |   gchar **parts; | 
					
						
							|  |  |  |  |   gint i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   matchlet = g_slice_new0 (TreeMatchlet); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   if (line[0] == '>') | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       *depth = 0; | 
					
						
							|  |  |  |  |       s = line; | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   else | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       *depth = atoi (line); | 
					
						
							|  |  |  |  |       s = strchr (line, '>'); | 
					
						
							| 
									
										
										
										
											2021-10-11 13:52:26 +03:00
										 |  |  |  |       if (s == NULL) | 
					
						
							|  |  |  |  |         goto handle_error; | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   s += 2; | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   p = strchr (s, '"'); | 
					
						
							| 
									
										
										
										
											2021-10-11 13:52:26 +03:00
										 |  |  |  |   if (p == NULL) | 
					
						
							|  |  |  |  |     goto handle_error; | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   *p = 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   matchlet->path = g_strdup (s); | 
					
						
							|  |  |  |  |   s = p + 1; | 
					
						
							|  |  |  |  |   parts = g_strsplit (s, ",", 0); | 
					
						
							|  |  |  |  |   if (strcmp (parts[0], "=file") == 0) | 
					
						
							|  |  |  |  |     matchlet->type = G_FILE_TYPE_REGULAR; | 
					
						
							|  |  |  |  |   else if (strcmp (parts[0], "=directory") == 0) | 
					
						
							|  |  |  |  |     matchlet->type = G_FILE_TYPE_DIRECTORY; | 
					
						
							|  |  |  |  |   else if (strcmp (parts[0], "=link") == 0) | 
					
						
							|  |  |  |  |     matchlet->type = G_FILE_TYPE_SYMBOLIC_LINK; | 
					
						
							|  |  |  |  |   else | 
					
						
							|  |  |  |  |     matchlet->type = G_FILE_TYPE_UNKNOWN; | 
					
						
							|  |  |  |  |   for (i = 1; parts[i]; i++) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       if (strcmp (parts[i], "executable") == 0) | 
					
						
							|  |  |  |  |         matchlet->executable = 1; | 
					
						
							|  |  |  |  |       else if (strcmp (parts[i], "match-case") == 0) | 
					
						
							|  |  |  |  |         matchlet->match_case = 1; | 
					
						
							|  |  |  |  |       else if (strcmp (parts[i], "non-empty") == 0) | 
					
						
							|  |  |  |  |         matchlet->non_empty = 1; | 
					
						
							|  |  |  |  |       else if (strcmp (parts[i], "on-disc") == 0) | 
					
						
							|  |  |  |  |         matchlet->on_disc = 1; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         matchlet->mimetype = g_strdup (parts[i]); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_strfreev (parts); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return matchlet; | 
					
						
							| 
									
										
										
										
											2021-10-11 13:52:26 +03:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | handle_error: | 
					
						
							|  |  |  |  |   g_slice_free (TreeMatchlet, matchlet); | 
					
						
							|  |  |  |  |   return NULL; | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static gint | 
					
						
							|  |  |  |  | cmp_match (gconstpointer a, gconstpointer b) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   const TreeMatch *aa = (const TreeMatch *)a; | 
					
						
							|  |  |  |  |   const TreeMatch *bb = (const TreeMatch *)b; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return bb->priority - aa->priority; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | insert_match (TreeMatch *match) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   tree_matches = g_list_insert_sorted (tree_matches, match, cmp_match); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | insert_matchlet (TreeMatch    *match, | 
					
						
							|  |  |  |  |                  TreeMatchlet *matchlet, | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                  gint          depth) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   if (depth == 0) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     match->matches = g_list_append (match->matches, matchlet); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   else | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       GList *last; | 
					
						
							|  |  |  |  |       TreeMatchlet *m; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       last = g_list_last (match->matches); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       if (!last) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           tree_matchlet_free (matchlet); | 
					
						
							|  |  |  |  |           g_warning ("can't insert tree matchlet at depth %d", depth); | 
					
						
							|  |  |  |  |           return; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       m = (TreeMatchlet *) last->data; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       while (--depth > 0) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           last = g_list_last (m->matches); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           if (!last) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |             { | 
					
						
							|  |  |  |  |               tree_matchlet_free (matchlet); | 
					
						
							|  |  |  |  |               g_warning ("can't insert tree matchlet at depth %d", depth); | 
					
						
							|  |  |  |  |               return; | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |           m = (TreeMatchlet *) last->data; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |       m->matches = g_list_append (m->matches, matchlet); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | read_tree_magic_from_directory (const gchar *prefix) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   gchar *filename; | 
					
						
							|  |  |  |  |   gchar *text; | 
					
						
							|  |  |  |  |   gsize len; | 
					
						
							|  |  |  |  |   gchar **lines; | 
					
						
							| 
									
										
										
										
											2021-10-11 13:52:26 +03:00
										 |  |  |  |   gsize i; | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   TreeMatch *match; | 
					
						
							|  |  |  |  |   TreeMatchlet *matchlet; | 
					
						
							|  |  |  |  |   gint depth; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   filename = g_build_filename (prefix, "treemagic", NULL); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   if (g_file_get_contents (filename, &text, &len, NULL)) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       if (strcmp (text, "MIME-TreeMagic") == 0) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           lines = g_strsplit (text + strlen ("MIME-TreeMagic") + 2, "\n", 0); | 
					
						
							|  |  |  |  |           match = NULL; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           for (i = 0; lines[i] && lines[i][0]; i++) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2021-10-11 13:52:26 +03:00
										 |  |  |  |               if (lines[i][0] == '[' && (match = parse_header (lines[i])) != NULL) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                 { | 
					
						
							|  |  |  |  |                   insert_match (match); | 
					
						
							|  |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2013-11-26 11:12:48 +00:00
										 |  |  |  |               else if (match != NULL) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                 { | 
					
						
							|  |  |  |  |                   matchlet = parse_match_line (lines[i], &depth); | 
					
						
							| 
									
										
										
										
											2021-10-11 13:52:26 +03:00
										 |  |  |  |                   if (matchlet == NULL) | 
					
						
							|  |  |  |  |                     { | 
					
						
							|  |  |  |  |                       g_warning ("%s: body corrupt; skipping", filename); | 
					
						
							|  |  |  |  |                       break; | 
					
						
							|  |  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                   insert_matchlet (match, matchlet, depth); | 
					
						
							|  |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2013-11-26 11:12:48 +00:00
										 |  |  |  |               else | 
					
						
							|  |  |  |  |                 { | 
					
						
							| 
									
										
										
										
											2018-04-27 16:45:36 +01:00
										 |  |  |  |                   g_warning ("%s: header corrupt; skipping", filename); | 
					
						
							| 
									
										
										
										
											2013-11-26 11:12:48 +00:00
										 |  |  |  |                   break; | 
					
						
							|  |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |           g_strfreev (lines); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2018-04-27 16:45:36 +01:00
										 |  |  |  |         g_warning ("%s: header not found, skipping", filename); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |       g_free (text); | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   g_free (filename); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | tree_magic_schedule_reload (void) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   need_reload = TRUE; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | xdg_mime_reload (void *user_data) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   tree_magic_schedule_reload (); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | tree_magic_shutdown (void) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-01-02 16:30:11 +01:00
										 |  |  |  |   g_list_free_full (tree_matches, (GDestroyNotify) tree_match_free); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   tree_matches = NULL; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | tree_magic_init (void) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   static gboolean initialized = FALSE; | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |   gsize i; | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   if (!initialized) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       initialized = TRUE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       xdg_mime_register_reload_callback (xdg_mime_reload, NULL, NULL); | 
					
						
							|  |  |  |  |       need_reload = TRUE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   if (need_reload) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |       const char * const *dirs; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |       need_reload = FALSE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       tree_magic_shutdown (); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-13 16:55:48 +00:00
										 |  |  |  |       dirs = g_content_type_get_mime_dirs (); | 
					
						
							|  |  |  |  |       for (i = 0; dirs[i] != NULL; i++) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         read_tree_magic_from_directory (dirs[i]); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /* a filtering enumerator */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | typedef struct | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   gchar *path; | 
					
						
							|  |  |  |  |   gint depth; | 
					
						
							|  |  |  |  |   gboolean ignore_case; | 
					
						
							|  |  |  |  |   gchar **components; | 
					
						
							|  |  |  |  |   gchar **case_components; | 
					
						
							|  |  |  |  |   GFileEnumerator **enumerators; | 
					
						
							|  |  |  |  |   GFile **children; | 
					
						
							|  |  |  |  | } Enumerator; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static gboolean | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | component_match (Enumerator  *e, | 
					
						
							|  |  |  |  |                  gint         depth, | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                  const gchar *name) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2023-11-13 12:14:01 +00:00
										 |  |  |  |   gchar *case_folded, *key, *utf8_name; | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   gboolean found; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (strcmp (name, e->components[depth]) == 0) | 
					
						
							|  |  |  |  |     return TRUE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (!e->ignore_case) | 
					
						
							|  |  |  |  |     return FALSE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-13 12:14:01 +00:00
										 |  |  |  |   utf8_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL); | 
					
						
							|  |  |  |  |   if (utf8_name == NULL) | 
					
						
							|  |  |  |  |     utf8_name = g_utf8_make_valid (name, -1); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   case_folded = g_utf8_casefold (utf8_name, -1); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   key = g_utf8_collate_key (case_folded, -1); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   found = strcmp (key, e->case_components[depth]) == 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-13 12:14:01 +00:00
										 |  |  |  |   g_free (utf8_name); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |   g_free (case_folded); | 
					
						
							|  |  |  |  |   g_free (key); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return found; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static GFile * | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | next_match_recurse (Enumerator *e, | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                     gint        depth) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFile *file; | 
					
						
							|  |  |  |  |   GFileInfo *info; | 
					
						
							|  |  |  |  |   const gchar *name; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   while (TRUE) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       if (e->enumerators[depth] == NULL) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           if (depth > 0) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |             { | 
					
						
							|  |  |  |  |               file = next_match_recurse (e, depth - 1); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |               if (file) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                 { | 
					
						
							|  |  |  |  |                   e->children[depth] = file; | 
					
						
							|  |  |  |  |                   e->enumerators[depth] = g_file_enumerate_children (file, | 
					
						
							|  |  |  |  |                                                                      G_FILE_ATTRIBUTE_STANDARD_NAME, | 
					
						
							|  |  |  |  |                                                                      G_FILE_QUERY_INFO_NONE, | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |                                                                      NULL, | 
					
						
							|  |  |  |  |                                                                      NULL); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |           if (e->enumerators[depth] == NULL) | 
					
						
							|  |  |  |  |             return NULL; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       while ((info = g_file_enumerator_next_file (e->enumerators[depth], NULL, NULL))) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           name = g_file_info_get_name (info); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           if (component_match (e, depth, name)) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |             { | 
					
						
							|  |  |  |  |               file = g_file_get_child (e->children[depth], name); | 
					
						
							|  |  |  |  |               g_object_unref (info); | 
					
						
							|  |  |  |  |               return file; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |           g_object_unref (info); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       g_object_unref (e->enumerators[depth]); | 
					
						
							|  |  |  |  |       e->enumerators[depth] = NULL; | 
					
						
							|  |  |  |  |       g_object_unref (e->children[depth]); | 
					
						
							|  |  |  |  |       e->children[depth] = NULL; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static GFile * | 
					
						
							|  |  |  |  | enumerator_next (Enumerator *e) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   return next_match_recurse (e, e->depth - 1); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static Enumerator * | 
					
						
							|  |  |  |  | enumerator_new (GFile      *root, | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |                 const char *path, | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                 gboolean    ignore_case) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   Enumerator *e; | 
					
						
							|  |  |  |  |   gint i; | 
					
						
							|  |  |  |  |   gchar *case_folded; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   e = g_new0 (Enumerator, 1); | 
					
						
							|  |  |  |  |   e->path = g_strdup (path); | 
					
						
							|  |  |  |  |   e->ignore_case = ignore_case; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   e->components = g_strsplit (e->path, G_DIR_SEPARATOR_S, -1); | 
					
						
							|  |  |  |  |   e->depth = g_strv_length (e->components); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   if (e->ignore_case) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       e->case_components = g_new0 (char *, e->depth + 1); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       for (i = 0; e->components[i]; i++) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           case_folded = g_utf8_casefold (e->components[i], -1); | 
					
						
							|  |  |  |  |           e->case_components[i] = g_utf8_collate_key (case_folded, -1); | 
					
						
							|  |  |  |  |           g_free (case_folded); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   e->children = g_new0 (GFile *, e->depth); | 
					
						
							|  |  |  |  |   e->children[0] = g_object_ref (root); | 
					
						
							|  |  |  |  |   e->enumerators = g_new0 (GFileEnumerator *, e->depth); | 
					
						
							|  |  |  |  |   e->enumerators[0] = g_file_enumerate_children (root, | 
					
						
							|  |  |  |  |                                                  G_FILE_ATTRIBUTE_STANDARD_NAME, | 
					
						
							|  |  |  |  |                                                  G_FILE_QUERY_INFO_NONE, | 
					
						
							|  |  |  |  |                                                  NULL, | 
					
						
							|  |  |  |  |                                                  NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return e; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | enumerator_free (Enumerator *e) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   gint i; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   for (i = 0; i < e->depth; i++) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       if (e->enumerators[i]) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         g_object_unref (e->enumerators[i]); | 
					
						
							|  |  |  |  |       if (e->children[i]) | 
					
						
							|  |  |  |  |         g_object_unref (e->children[i]); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_free (e->enumerators); | 
					
						
							|  |  |  |  |   g_free (e->children); | 
					
						
							|  |  |  |  |   g_strfreev (e->components); | 
					
						
							|  |  |  |  |   if (e->case_components) | 
					
						
							|  |  |  |  |     g_strfreev (e->case_components); | 
					
						
							|  |  |  |  |   g_free (e->path); | 
					
						
							|  |  |  |  |   g_free (e); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static gboolean | 
					
						
							|  |  |  |  | matchlet_match (TreeMatchlet *matchlet, | 
					
						
							|  |  |  |  |                 GFile        *root) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFile *file; | 
					
						
							|  |  |  |  |   GFileInfo *info; | 
					
						
							|  |  |  |  |   gboolean result; | 
					
						
							|  |  |  |  |   const gchar *attrs; | 
					
						
							|  |  |  |  |   Enumerator *e; | 
					
						
							|  |  |  |  |   GList *l; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   e = enumerator_new (root, matchlet->path, !matchlet->match_case); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   do | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       file = enumerator_next (e); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       if (!file) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           enumerator_free (e); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |           return FALSE; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       if (matchlet->mimetype) | 
					
						
							|  |  |  |  |         attrs = G_FILE_ATTRIBUTE_STANDARD_TYPE "," | 
					
						
							|  |  |  |  |                 G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE "," | 
					
						
							|  |  |  |  |                 G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE; | 
					
						
							|  |  |  |  |       else | 
					
						
							|  |  |  |  |         attrs = G_FILE_ATTRIBUTE_STANDARD_TYPE "," | 
					
						
							|  |  |  |  |                 G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       info = g_file_query_info (file, | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                                 attrs, | 
					
						
							|  |  |  |  |                                 G_FILE_QUERY_INFO_NONE, | 
					
						
							|  |  |  |  |                                 NULL, | 
					
						
							|  |  |  |  |                                 NULL); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       if (info) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           result = TRUE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |           if (matchlet->type != G_FILE_TYPE_UNKNOWN && | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |               g_file_info_get_file_type (info) != matchlet->type) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |             result = FALSE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |           if (matchlet->executable && | 
					
						
							|  |  |  |  |               !g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE)) | 
					
						
							|  |  |  |  |             result = FALSE; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |       else | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         result = FALSE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       if (result && matchlet->non_empty) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           GFileEnumerator *child_enum; | 
					
						
							|  |  |  |  |           GFileInfo *child_info; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           child_enum = g_file_enumerate_children (file, | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |                                                   G_FILE_ATTRIBUTE_STANDARD_NAME, | 
					
						
							|  |  |  |  |                                                   G_FILE_QUERY_INFO_NONE, | 
					
						
							|  |  |  |  |                                                   NULL, | 
					
						
							|  |  |  |  |                                                   NULL); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |           if (child_enum) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |             { | 
					
						
							|  |  |  |  |               child_info = g_file_enumerator_next_file (child_enum, NULL, NULL); | 
					
						
							|  |  |  |  |               if (child_info) | 
					
						
							|  |  |  |  |                 g_object_unref (child_info); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |               else | 
					
						
							|  |  |  |  |                 result = FALSE; | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |               g_object_unref (child_enum); | 
					
						
							|  |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           else | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |             result = FALSE; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |       if (result && matchlet->mimetype) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |           if (strcmp (matchlet->mimetype, g_file_info_get_content_type (info)) != 0) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |             result = FALSE; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-28 20:41:49 +00:00
										 |  |  |  |       if (info) | 
					
						
							|  |  |  |  |         g_object_unref (info); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |       g_object_unref (file); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |   while (!result); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   enumerator_free (e); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (!matchlet->matches) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     return TRUE; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   for (l = matchlet->matches; l; l = l->next) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       TreeMatchlet *submatchlet; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       submatchlet = l->data; | 
					
						
							|  |  |  |  |       if (matchlet_match (submatchlet, root)) | 
					
						
							|  |  |  |  |         return TRUE; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return FALSE; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | match_match (TreeMatch    *match, | 
					
						
							|  |  |  |  |              GFile        *root, | 
					
						
							|  |  |  |  |              GPtrArray    *types) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GList *l; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   for (l = match->matches; l; l = l->next) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       TreeMatchlet *matchlet = l->data; | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |       if (matchlet_match (matchlet, root)) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |         { | 
					
						
							|  |  |  |  |           g_ptr_array_add (types, g_strdup (match->contenttype)); | 
					
						
							|  |  |  |  |           break; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  | gchar ** | 
					
						
							| 
									
										
										
										
											2024-07-24 15:58:39 +02:00
										 |  |  |  | g_content_type_guess_for_tree_impl (GFile *root) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   GPtrArray *types; | 
					
						
							|  |  |  |  |   GList *l; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   types = g_ptr_array_new (); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   G_LOCK (gio_treemagic); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   tree_magic_init (); | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   for (l = tree_matches; l; l = l->next) | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |       TreeMatch *match = l->data; | 
					
						
							|  |  |  |  |       match_match (match, root, types); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   G_UNLOCK (gio_treemagic); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_ptr_array_add (types, NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-05 00:56:12 -04:00
										 |  |  |  |   return (gchar **)g_ptr_array_free (types, FALSE); | 
					
						
							| 
									
										
										
										
											2008-07-18 15:33:22 +00:00
										 |  |  |  | } |