Fix the build
[glib.git] / gio / gcontenttype.c
blobfcc7fa2feba5aca35b83faf401852dfea6401ea4
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
4 *
5 * Copyright (C) 2006-2007 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
22 * Author: Alexander Larsson <alexl@redhat.com>
25 #include <config.h>
26 #include <sys/types.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include "gcontenttypeprivate.h"
30 #include "gthemedicon.h"
31 #include "glibintl.h"
33 #include "gioalias.h"
35 /**
36 * SECTION:gcontenttype
37 * @short_description: Platform-specific content typing
38 * @include: gio/gio.h
40 * A content type is a platform specific string that defines the type
41 * of a file. On unix it is a mime type, on win32 it is an extension string
42 * like ".doc", ".txt" or a percieved string like "audio". Such strings
43 * can be looked up in the registry at HKEY_CLASSES_ROOT.
44 **/
46 #ifdef G_OS_WIN32
48 #include <windows.h>
50 static char *
51 get_registry_classes_key (const char *subdir,
52 const wchar_t *key_name)
54 wchar_t *wc_key;
55 HKEY reg_key = NULL;
56 DWORD key_type;
57 DWORD nbytes;
58 char *value_utf8;
60 value_utf8 = NULL;
62 nbytes = 0;
63 wc_key = g_utf8_to_utf16 (subdir, -1, NULL, NULL, NULL);
64 if (RegOpenKeyExW (HKEY_CLASSES_ROOT, wc_key, 0,
65 KEY_QUERY_VALUE, &reg_key) == ERROR_SUCCESS &&
66 RegQueryValueExW (reg_key, key_name, 0,
67 &key_type, NULL, &nbytes) == ERROR_SUCCESS &&
68 key_type == REG_SZ)
70 wchar_t *wc_temp = g_new (wchar_t, (nbytes+1)/2 + 1);
71 RegQueryValueExW (reg_key, key_name, 0,
72 &key_type, (LPBYTE) wc_temp, &nbytes);
73 wc_temp[nbytes/2] = '\0';
74 value_utf8 = g_utf16_to_utf8 (wc_temp, -1, NULL, NULL, NULL);
75 g_free (wc_temp);
77 g_free (wc_key);
79 if (reg_key != NULL)
80 RegCloseKey (reg_key);
82 return value_utf8;
85 gboolean
86 g_content_type_equals (const char *type1,
87 const char *type2)
89 char *progid1, *progid2;
90 gboolean res;
92 g_return_val_if_fail (type1 != NULL, FALSE);
93 g_return_val_if_fail (type2 != NULL, FALSE);
95 if (g_ascii_strcasecmp (type1, type2) == 0)
96 return TRUE;
98 res = FALSE;
99 progid1 = get_registry_classes_key (type1, NULL);
100 progid2 = get_registry_classes_key (type2, NULL);
101 if (progid1 != NULL && progid2 != NULL &&
102 strcmp (progid1, progid2) == 0)
103 res = TRUE;
104 g_free (progid1);
105 g_free (progid2);
107 return res;
110 gboolean
111 g_content_type_is_a (const char *type,
112 const char *supertype)
114 gboolean res;
115 char *value_utf8;
117 g_return_val_if_fail (type != NULL, FALSE);
118 g_return_val_if_fail (supertype != NULL, FALSE);
120 if (g_content_type_equals (type, supertype))
121 return TRUE;
123 res = FALSE;
124 value_utf8 = get_registry_classes_key (type, L"PerceivedType");
125 if (value_utf8 && strcmp (value_utf8, supertype) == 0)
126 res = TRUE;
127 g_free (value_utf8);
129 return res;
132 gboolean
133 g_content_type_is_unknown (const char *type)
135 g_return_val_if_fail (type != NULL, FALSE);
137 return strcmp ("*", type) == 0;
140 char *
141 g_content_type_get_description (const char *type)
143 char *progid;
144 char *description;
146 g_return_val_if_fail (type != NULL, NULL);
148 progid = get_registry_classes_key (type, NULL);
149 if (progid)
151 description = get_registry_classes_key (progid, NULL);
152 g_free (progid);
154 if (description)
155 return description;
158 if (g_content_type_is_unknown (type))
159 return g_strdup (_("Unknown type"));
160 return g_strdup_printf (_("%s filetype"), type);
163 char *
164 g_content_type_get_mime_type (const char *type)
166 char *mime;
168 g_return_val_if_fail (type != NULL, NULL);
170 mime = get_registry_classes_key (type, L"Content Type");
171 if (mime)
172 return mime;
173 else if (g_content_type_is_unknown (type))
174 return g_strdup ("application/octet-stream");
175 else if (*type == '.')
176 return g_strdup_printf ("application/x-ext-%s", type+1);
177 /* TODO: Map "image" to "image/ *", etc? */
179 return g_strdup ("application/octet-stream");
182 GIcon *
183 g_content_type_get_icon (const char *type)
185 g_return_val_if_fail (type != NULL, NULL);
187 /* TODO: How do we represent icons???
188 In the registry they are the default value of
189 HKEY_CLASSES_ROOT\<progid>\DefaultIcon with typical values like:
190 <type>: <value>
191 REG_EXPAND_SZ: %SystemRoot%\System32\Wscript.exe,3
192 REG_SZ: shimgvw.dll,3
194 return NULL;
197 gboolean
198 g_content_type_can_be_executable (const char *type)
200 g_return_val_if_fail (type != NULL, FALSE);
202 if (strcmp (type, ".exe") == 0 ||
203 strcmp (type, ".com") == 0 ||
204 strcmp (type, ".bat") == 0)
205 return TRUE;
206 return FALSE;
209 static gboolean
210 looks_like_text (const guchar *data,
211 gsize data_size)
213 gsize i;
214 guchar c;
215 for (i = 0; i < data_size; i++)
217 c = data[i];
218 if (g_ascii_iscntrl (c) && !g_ascii_isspace (c))
219 return FALSE;
221 return TRUE;
224 char *
225 g_content_type_from_mime_type (const char *mime_type)
227 char *key, *content_type;
229 g_return_val_if_fail (mime_type != NULL, NULL);
231 key = g_strconcat ("MIME\\DataBase\\Content Type\\", mime_type, NULL);
232 content_type = get_registry_classes_key (key, L"Extension");
233 g_free (key);
235 return content_type;
238 char *
239 g_content_type_guess (const char *filename,
240 const guchar *data,
241 gsize data_size,
242 gboolean *result_uncertain)
244 char *basename;
245 char *type;
246 char *dot;
248 type = NULL;
250 if (filename)
252 basename = g_path_get_basename (filename);
253 dot = strrchr (basename, '.');
254 if (dot)
255 type = g_strdup (dot);
256 g_free (basename);
259 if (type)
260 return type;
262 if (data && looks_like_text (data, data_size))
263 return g_strdup (".txt");
265 return g_strdup ("*");
268 GList *
269 g_content_types_get_registered (void)
271 DWORD index;
272 wchar_t keyname[256];
273 DWORD key_len;
274 char *key_utf8;
275 GList *types;
277 types = NULL;
278 index = 0;
279 key_len = 256;
280 while (RegEnumKeyExW(HKEY_CLASSES_ROOT,
281 index,
282 keyname,
283 &key_len,
284 NULL,
285 NULL,
286 NULL,
287 NULL) == ERROR_SUCCESS)
289 key_utf8 = g_utf16_to_utf8 (keyname, -1, NULL, NULL, NULL);
290 if (key_utf8)
292 if (*key_utf8 == '.')
293 types = g_list_prepend (types, key_utf8);
294 else
295 g_free (key_utf8);
297 index++;
298 key_len = 256;
301 return g_list_reverse (types);
304 #else /* !G_OS_WIN32 - Unix specific version */
306 #include <dirent.h>
308 #define XDG_PREFIX _gio_xdg
309 #include "xdgmime/xdgmime.h"
311 /* We lock this mutex whenever we modify global state in this module. */
312 G_LOCK_DEFINE_STATIC (gio_xdgmime);
314 gsize
315 _g_unix_content_type_get_sniff_len (void)
317 gsize size;
319 G_LOCK (gio_xdgmime);
320 size = xdg_mime_get_max_buffer_extents ();
321 G_UNLOCK (gio_xdgmime);
323 return size;
326 char *
327 _g_unix_content_type_unalias (const char *type)
329 char *res;
331 G_LOCK (gio_xdgmime);
332 res = g_strdup (xdg_mime_unalias_mime_type (type));
333 G_UNLOCK (gio_xdgmime);
335 return res;
338 char **
339 _g_unix_content_type_get_parents (const char *type)
341 const char *umime;
342 char **parents;
343 GPtrArray *array;
344 int i;
346 array = g_ptr_array_new ();
348 G_LOCK (gio_xdgmime);
350 umime = xdg_mime_unalias_mime_type (type);
352 g_ptr_array_add (array, g_strdup (umime));
354 parents = xdg_mime_list_mime_parents (umime);
355 for (i = 0; parents && parents[i] != NULL; i++)
356 g_ptr_array_add (array, g_strdup (parents[i]));
358 free (parents);
360 G_UNLOCK (gio_xdgmime);
362 g_ptr_array_add (array, NULL);
364 return (char **)g_ptr_array_free (array, FALSE);
368 * g_content_type_equals:
369 * @type1: a content type string.
370 * @type2: a content type string.
372 * Compares two content types for equality.
374 * Returns: %TRUE if the two strings are identical or equivalent,
375 * %FALSE otherwise.
376 **/
377 gboolean
378 g_content_type_equals (const char *type1,
379 const char *type2)
381 gboolean res;
383 g_return_val_if_fail (type1 != NULL, FALSE);
384 g_return_val_if_fail (type2 != NULL, FALSE);
386 G_LOCK (gio_xdgmime);
387 res = xdg_mime_mime_type_equal (type1, type2);
388 G_UNLOCK (gio_xdgmime);
390 return res;
394 * g_content_type_is_a:
395 * @type: a content type string.
396 * @supertype: a string.
398 * Determines if @type is a subset of @supertype.
400 * Returns: %TRUE if @type is a kind of @supertype,
401 * %FALSE otherwise.
402 **/
403 gboolean
404 g_content_type_is_a (const char *type,
405 const char *supertype)
407 gboolean res;
409 g_return_val_if_fail (type != NULL, FALSE);
410 g_return_val_if_fail (supertype != NULL, FALSE);
412 G_LOCK (gio_xdgmime);
413 res = xdg_mime_mime_type_subclass (type, supertype);
414 G_UNLOCK (gio_xdgmime);
416 return res;
420 * g_content_type_is_unknown:
421 * @type: a content type string.
423 * Checks if the content type is the generic "unknown" type.
424 * On unix this is the "application/octet-stream" mimetype,
425 * while on win32 it is "*".
427 * Returns: %TRUE if the type is the unknown type.
428 **/
429 gboolean
430 g_content_type_is_unknown (const char *type)
432 g_return_val_if_fail (type != NULL, FALSE);
434 return strcmp (XDG_MIME_TYPE_UNKNOWN, type) == 0;
438 typedef enum {
439 MIME_TAG_TYPE_OTHER,
440 MIME_TAG_TYPE_COMMENT
441 } MimeTagType;
443 typedef struct {
444 int current_type;
445 int current_lang_level;
446 int comment_lang_level;
447 char *comment;
448 } MimeParser;
451 static int
452 language_level (const char *lang)
454 const char * const *lang_list;
455 int i;
457 /* The returned list is sorted from most desirable to least
458 desirable and always contains the default locale "C". */
459 lang_list = g_get_language_names ();
461 for (i = 0; lang_list[i]; i++)
462 if (strcmp (lang_list[i], lang) == 0)
463 return 1000-i;
465 return 0;
468 static void
469 mime_info_start_element (GMarkupParseContext *context,
470 const gchar *element_name,
471 const gchar **attribute_names,
472 const gchar **attribute_values,
473 gpointer user_data,
474 GError **error)
476 int i;
477 const char *lang;
478 MimeParser *parser = user_data;
480 if (strcmp (element_name, "comment") == 0)
482 lang = "C";
483 for (i = 0; attribute_names[i]; i++)
484 if (strcmp (attribute_names[i], "xml:lang") == 0)
486 lang = attribute_values[i];
487 break;
490 parser->current_lang_level = language_level (lang);
491 parser->current_type = MIME_TAG_TYPE_COMMENT;
493 else
494 parser->current_type = MIME_TAG_TYPE_OTHER;
498 static void
499 mime_info_end_element (GMarkupParseContext *context,
500 const gchar *element_name,
501 gpointer user_data,
502 GError **error)
504 MimeParser *parser = user_data;
506 parser->current_type = MIME_TAG_TYPE_OTHER;
509 static void
510 mime_info_text (GMarkupParseContext *context,
511 const gchar *text,
512 gsize text_len,
513 gpointer user_data,
514 GError **error)
516 MimeParser *parser = user_data;
518 if (parser->current_type == MIME_TAG_TYPE_COMMENT &&
519 parser->current_lang_level > parser->comment_lang_level)
521 g_free (parser->comment);
522 parser->comment = g_strndup (text, text_len);
523 parser->comment_lang_level = parser->current_lang_level;
527 static char *
528 load_comment_for_mime_helper (const char *dir,
529 const char *basename)
531 GMarkupParseContext *context;
532 char *filename, *data;
533 gsize len;
534 gboolean res;
535 MimeParser parse_data = {0};
536 GMarkupParser parser = {
537 mime_info_start_element,
538 mime_info_end_element,
539 mime_info_text
542 filename = g_build_filename (dir, "mime", basename, NULL);
544 res = g_file_get_contents (filename, &data, &len, NULL);
545 g_free (filename);
546 if (!res)
547 return NULL;
549 context = g_markup_parse_context_new (&parser, 0, &parse_data, NULL);
550 res = g_markup_parse_context_parse (context, data, len, NULL);
551 g_free (data);
552 g_markup_parse_context_free (context);
554 if (!res)
555 return NULL;
557 return parse_data.comment;
561 static char *
562 load_comment_for_mime (const char *mimetype)
564 const char * const* dirs;
565 char *basename;
566 char *comment;
567 int i;
569 basename = g_strdup_printf ("%s.xml", mimetype);
571 comment = load_comment_for_mime_helper (g_get_user_data_dir (), basename);
572 if (comment)
574 g_free (basename);
575 return comment;
578 dirs = g_get_system_data_dirs ();
580 for (i = 0; dirs[i] != NULL; i++)
582 comment = load_comment_for_mime_helper (dirs[i], basename);
583 if (comment)
585 g_free (basename);
586 return comment;
589 g_free (basename);
591 return g_strdup_printf (_("%s type"), mimetype);
595 * g_content_type_get_description:
596 * @type: a content type string.
598 * Gets the human readable description of the content type.
600 * Returns: a short description of the content type @type.
601 **/
602 char *
603 g_content_type_get_description (const char *type)
605 static GHashTable *type_comment_cache = NULL;
606 char *comment;
608 g_return_val_if_fail (type != NULL, NULL);
610 G_LOCK (gio_xdgmime);
611 type = xdg_mime_unalias_mime_type (type);
613 if (type_comment_cache == NULL)
614 type_comment_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
616 comment = g_hash_table_lookup (type_comment_cache, type);
617 comment = g_strdup (comment);
618 G_UNLOCK (gio_xdgmime);
620 if (comment != NULL)
621 return comment;
623 comment = load_comment_for_mime (type);
625 G_LOCK (gio_xdgmime);
626 g_hash_table_insert (type_comment_cache,
627 g_strdup (type),
628 g_strdup (comment));
629 G_UNLOCK (gio_xdgmime);
631 return comment;
635 * g_content_type_get_mime_type:
636 * @type: a content type string.
638 * Gets the mime-type for the content type. If one is registered
640 * Returns: the registered mime-type for the given @type, or NULL if unknown.
641 **/
642 char *
643 g_content_type_get_mime_type (const char *type)
645 g_return_val_if_fail (type != NULL, NULL);
647 return g_strdup (type);
651 * g_content_type_get_icon:
652 * @type: a content type string.
654 * Gets the icon for a content type.
656 * Returns: #GIcon corresponding to the content type.
657 **/
658 GIcon *
659 g_content_type_get_icon (const char *type)
661 char *mimetype_icon, *generic_mimetype_icon, *q;
662 char *xdg_mimetype_icon, *legacy_mimetype_icon;
663 char *icon_names[4];
664 int n;
665 const char *p;
666 GIcon *themed_icon;
668 g_return_val_if_fail (type != NULL, NULL);
670 G_LOCK (gio_xdgmime);
671 xdg_mimetype_icon = g_strdup (xdg_mime_get_icon (type));
672 G_UNLOCK (gio_xdgmime);
674 mimetype_icon = g_strdup (type);
676 while ((q = strchr (mimetype_icon, '/')) != NULL)
677 *q = '-';
679 p = strchr (type, '/');
680 if (p == NULL)
681 p = type + strlen (type);
683 /* Not all icons have migrated to the new icon theme spec, look for old names too */
684 legacy_mimetype_icon = g_strconcat ("gnome-mime-", mimetype_icon, NULL);
686 generic_mimetype_icon = g_malloc (p - type + strlen ("-x-generic") + 1);
687 memcpy (generic_mimetype_icon, type, p - type);
688 memcpy (generic_mimetype_icon + (p - type), "-x-generic", strlen ("-x-generic"));
689 generic_mimetype_icon[(p - type) + strlen ("-x-generic")] = 0;
691 if (xdg_mimetype_icon)
692 icon_names[n++] = xdg_mimetype_icon;
694 icon_names[n++] = mimetype_icon;
695 icon_names[n++] = legacy_mimetype_icon;
696 icon_names[n++] = generic_mimetype_icon;
698 themed_icon = g_themed_icon_new_from_names (icon_names, n);
700 g_free (xdg_mimetype_icon);
701 g_free (mimetype_icon);
702 g_free (legacy_mimetype_icon);
703 g_free (generic_mimetype_icon);
705 return themed_icon;
709 * g_content_type_can_be_executable:
710 * @type: a content type string.
712 * Checks if a content type can be executable. Note that for instance
713 * things like text files can be executables (i.e. scripts and batch files).
715 * Returns: %TRUE if the file type corresponds to a type that
716 * can be executable, %FALSE otherwise.
717 **/
718 gboolean
719 g_content_type_can_be_executable (const char *type)
721 g_return_val_if_fail (type != NULL, FALSE);
723 if (g_content_type_is_a (type, "application/x-executable") ||
724 g_content_type_is_a (type, "text/plain"))
725 return TRUE;
727 return FALSE;
730 static gboolean
731 looks_like_text (const guchar *data, gsize data_size)
733 gsize i;
734 char c;
736 for (i = 0; i < data_size; i++)
738 c = data[i];
740 if (g_ascii_iscntrl (c) &&
741 !g_ascii_isspace (c))
742 return FALSE;
744 return TRUE;
748 * g_content_type_from_mime_type:
749 * @mime_type: a mime type string.
751 * Tries to find a content type based on the mime type name.
753 * Returns: Newly allocated string with content type or NULL when does not know.
755 * Since: 2.18
757 char *
758 g_content_type_from_mime_type (const char *mime_type)
760 g_return_val_if_fail (mime_type != NULL, NULL);
762 /* mime type and content type are same on unixes */
763 return g_strdup (mime_type);
767 * g_content_type_guess:
768 * @filename: a string.
769 * @data: a stream of data.
770 * @data_size: the size of @data.
771 * @result_uncertain: a flag indicating the certainty of the
772 * result.
774 * Guesses the content type based on example data. If the function is
775 * uncertain, @result_uncertain will be set to %TRUE.
777 * Returns: a string indicating a guessed content type for the
778 * given data.
779 **/
780 char *
781 g_content_type_guess (const char *filename,
782 const guchar *data,
783 gsize data_size,
784 gboolean *result_uncertain)
786 char *basename;
787 const char *name_mimetypes[10], *sniffed_mimetype;
788 char *mimetype;
789 int i;
790 int n_name_mimetypes;
791 int sniffed_prio;
793 sniffed_prio = 0;
794 n_name_mimetypes = 0;
795 sniffed_mimetype = XDG_MIME_TYPE_UNKNOWN;
797 if (result_uncertain)
798 *result_uncertain = FALSE;
800 G_LOCK (gio_xdgmime);
802 if (filename)
804 basename = g_path_get_basename (filename);
805 n_name_mimetypes = xdg_mime_get_mime_types_from_file_name (basename, name_mimetypes, 10);
806 g_free (basename);
809 /* Got an extension match, and no conflicts. This is it. */
810 if (n_name_mimetypes == 1)
812 G_UNLOCK (gio_xdgmime);
813 return g_strdup (name_mimetypes[0]);
816 if (data)
818 sniffed_mimetype = xdg_mime_get_mime_type_for_data (data, data_size, &sniffed_prio);
819 if (sniffed_mimetype == XDG_MIME_TYPE_UNKNOWN &&
820 data &&
821 looks_like_text (data, data_size))
822 sniffed_mimetype = "text/plain";
825 if (n_name_mimetypes == 0)
827 if (sniffed_mimetype == XDG_MIME_TYPE_UNKNOWN &&
828 result_uncertain)
829 *result_uncertain = TRUE;
831 mimetype = g_strdup (sniffed_mimetype);
833 else
835 mimetype = NULL;
836 if (sniffed_mimetype != XDG_MIME_TYPE_UNKNOWN)
838 if (sniffed_prio >= 80) /* High priority sniffing match, use that */
839 mimetype = g_strdup (sniffed_mimetype);
840 else
842 /* There are conflicts between the name matches and we have a sniffed
843 type, use that as a tie breaker. */
845 for (i = 0; i < n_name_mimetypes; i++)
847 if ( xdg_mime_mime_type_subclass (name_mimetypes[i], sniffed_mimetype))
849 /* This nametype match is derived from (or the same as) the sniffed type).
850 This is probably it. */
851 mimetype = g_strdup (name_mimetypes[i]);
852 break;
858 if (mimetype == NULL)
860 /* Conflicts, and sniffed type was no help or not there. Guess on the first one */
861 mimetype = g_strdup (name_mimetypes[0]);
862 if (result_uncertain)
863 *result_uncertain = TRUE;
867 G_UNLOCK (gio_xdgmime);
869 return mimetype;
872 static void
873 enumerate_mimetypes_subdir (const char *dir,
874 const char *prefix,
875 GHashTable *mimetypes)
877 DIR *d;
878 struct dirent *ent;
879 char *mimetype;
881 d = opendir (dir);
882 if (d)
884 while ((ent = readdir (d)) != NULL)
886 if (g_str_has_suffix (ent->d_name, ".xml"))
888 mimetype = g_strdup_printf ("%s/%.*s", prefix, (int) strlen (ent->d_name) - 4, ent->d_name);
889 g_hash_table_insert (mimetypes, mimetype, NULL);
892 closedir (d);
896 static void
897 enumerate_mimetypes_dir (const char *dir,
898 GHashTable *mimetypes)
900 DIR *d;
901 struct dirent *ent;
902 char *mimedir;
903 char *name;
905 mimedir = g_build_filename (dir, "mime", NULL);
907 d = opendir (mimedir);
908 if (d)
910 while ((ent = readdir (d)) != NULL)
912 if (strcmp (ent->d_name, "packages") != 0)
914 name = g_build_filename (mimedir, ent->d_name, NULL);
915 if (g_file_test (name, G_FILE_TEST_IS_DIR))
916 enumerate_mimetypes_subdir (name, ent->d_name, mimetypes);
917 g_free (name);
920 closedir (d);
923 g_free (mimedir);
927 * g_content_types_get_registered:
929 * Gets a list of strings containing all the registered content types
930 * known to the system. The list and its data should be freed using
931 * @g_list_foreach(list, g_free, NULL) and @g_list_free(list)
932 * Returns: #GList of the registered content types.
933 **/
934 GList *
935 g_content_types_get_registered (void)
937 const char * const* dirs;
938 GHashTable *mimetypes;
939 GHashTableIter iter;
940 gpointer key;
941 int i;
942 GList *l;
944 mimetypes = g_hash_table_new (g_str_hash, g_str_equal);
946 enumerate_mimetypes_dir (g_get_user_data_dir (), mimetypes);
947 dirs = g_get_system_data_dirs ();
949 for (i = 0; dirs[i] != NULL; i++)
950 enumerate_mimetypes_dir (dirs[i], mimetypes);
952 l = NULL;
953 g_hash_table_iter_init (&iter, mimetypes);
954 while (g_hash_table_iter_next (&iter, &key, NULL))
955 l = g_list_prepend (l, key);
957 g_hash_table_destroy (mimetypes);
959 return l;
962 #endif /* Unix version */
964 #define __G_CONTENT_TYPE_C__
965 #include "gioaliasdef.c"