OLD | NEW |
1 /* -*- mode: C; c-file-style: "gnu" -*- */ | 1 /* -*- mode: C; c-file-style: "gnu" -*- */ |
2 /* xdgmime.c: XDG Mime Spec mime resolver. Based on version 0.11 of the spec. | 2 /* xdgmime.c: XDG Mime Spec mime resolver. Based on version 0.11 of the spec. |
3 * | 3 * |
4 * More info can be found at http://www.freedesktop.org/standards/ | 4 * More info can be found at http://www.freedesktop.org/standards/ |
5 * | 5 * |
6 * Copyright (C) 2003,2004 Red Hat, Inc. | 6 * Copyright (C) 2003,2004 Red Hat, Inc. |
7 * Copyright (C) 2003,2004 Jonathan Blandford <jrb@alum.mit.edu> | 7 * Copyright (C) 2003,2004 Jonathan Blandford <jrb@alum.mit.edu> |
8 * | 8 * |
9 * Licensed under the Academic Free License version 2.0 | 9 * Licensed under the Academic Free License version 2.0 |
10 * Or under the following terms: | 10 * Or under the following terms: |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 while (list) | 129 while (list) |
130 { | 130 { |
131 next = list->next; | 131 next = list->next; |
132 free (list->directory_name); | 132 free (list->directory_name); |
133 free (list); | 133 free (list); |
134 list = next; | 134 list = next; |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 static int | 138 static int |
139 xdg_mime_init_from_directory (const char *directory) | 139 xdg_mime_init_from_directory (const char *directory, void *user_data) |
140 { | 140 { |
141 char *file_name; | 141 char *file_name; |
142 struct stat st; | 142 struct stat st; |
143 | 143 |
144 assert (directory != NULL); | 144 assert (directory != NULL); |
145 | 145 |
146 file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1); | 146 file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1); |
147 strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache"); | 147 strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache"); |
148 if (stat (file_name, &st) == 0) | 148 if (stat (file_name, &st) == 0) |
149 { | 149 { |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 333 } |
334 | 334 |
335 if (exists) | 335 if (exists) |
336 *exists = FALSE; | 336 *exists = FALSE; |
337 | 337 |
338 return FALSE; | 338 return FALSE; |
339 } | 339 } |
340 | 340 |
341 static int | 341 static int |
342 xdg_check_dir (const char *directory, | 342 xdg_check_dir (const char *directory, |
343 » int *invalid_dir_list) | 343 » void *user_data) |
344 { | 344 { |
| 345 int *invalid_dir_list = user_data; |
345 int invalid, exists; | 346 int invalid, exists; |
346 char *file_name; | 347 char *file_name; |
347 | 348 |
348 assert (directory != NULL); | 349 assert (directory != NULL); |
349 | 350 |
350 /* Check the mime.cache file */ | 351 /* Check the mime.cache file */ |
351 file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1); | 352 file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1); |
352 strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache"); | 353 strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache"); |
353 invalid = xdg_check_file (file_name, &exists); | 354 invalid = xdg_check_file (file_name, &exists); |
354 free (file_name); | 355 free (file_name); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 * Returns TRUE if they have. */ | 392 * Returns TRUE if they have. */ |
392 static int | 393 static int |
393 xdg_check_dirs (void) | 394 xdg_check_dirs (void) |
394 { | 395 { |
395 XdgDirTimeList *list; | 396 XdgDirTimeList *list; |
396 int invalid_dir_list = FALSE; | 397 int invalid_dir_list = FALSE; |
397 | 398 |
398 for (list = dir_time_list; list; list = list->next) | 399 for (list = dir_time_list; list; list = list->next) |
399 list->checked = XDG_CHECKED_UNCHECKED; | 400 list->checked = XDG_CHECKED_UNCHECKED; |
400 | 401 |
401 xdg_run_command_on_dirs ((XdgDirectoryFunc) xdg_check_dir, | 402 xdg_run_command_on_dirs (xdg_check_dir, &invalid_dir_list); |
402 » » » &invalid_dir_list); | |
403 | 403 |
404 if (invalid_dir_list) | 404 if (invalid_dir_list) |
405 return TRUE; | 405 return TRUE; |
406 | 406 |
407 for (list = dir_time_list; list; list = list->next) | 407 for (list = dir_time_list; list; list = list->next) |
408 { | 408 { |
409 if (list->checked != XDG_CHECKED_VALID) | 409 if (list->checked != XDG_CHECKED_VALID) |
410 return TRUE; | 410 return TRUE; |
411 } | 411 } |
412 | 412 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 448 |
449 if (need_reread) | 449 if (need_reread) |
450 { | 450 { |
451 global_hash = _xdg_glob_hash_new (); | 451 global_hash = _xdg_glob_hash_new (); |
452 global_magic = _xdg_mime_magic_new (); | 452 global_magic = _xdg_mime_magic_new (); |
453 alias_list = _xdg_mime_alias_list_new (); | 453 alias_list = _xdg_mime_alias_list_new (); |
454 parent_list = _xdg_mime_parent_list_new (); | 454 parent_list = _xdg_mime_parent_list_new (); |
455 icon_list = _xdg_mime_icon_list_new (); | 455 icon_list = _xdg_mime_icon_list_new (); |
456 generic_icon_list = _xdg_mime_icon_list_new (); | 456 generic_icon_list = _xdg_mime_icon_list_new (); |
457 | 457 |
458 xdg_run_command_on_dirs ((XdgDirectoryFunc) xdg_mime_init_from_directory, | 458 xdg_run_command_on_dirs (xdg_mime_init_from_directory, NULL); |
459 » » » NULL); | |
460 | 459 |
461 need_reread = FALSE; | 460 need_reread = FALSE; |
462 } | 461 } |
463 } | 462 } |
464 | 463 |
465 const char * | 464 const char * |
466 xdg_mime_get_mime_type_for_data (const void *data, | 465 xdg_mime_get_mime_type_for_data (const void *data, |
467 size_t len, | 466 size_t len, |
468 int *result_prio) | 467 int *result_prio) |
469 { | 468 { |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 const char * | 924 const char * |
926 xdg_mime_get_generic_icon (const char *mime) | 925 xdg_mime_get_generic_icon (const char *mime) |
927 { | 926 { |
928 xdg_mime_init (); | 927 xdg_mime_init (); |
929 | 928 |
930 if (_caches) | 929 if (_caches) |
931 return _xdg_mime_cache_get_generic_icon (mime); | 930 return _xdg_mime_cache_get_generic_icon (mime); |
932 | 931 |
933 return _xdg_mime_icon_list_lookup (generic_icon_list, mime); | 932 return _xdg_mime_icon_list_lookup (generic_icon_list, mime); |
934 } | 933 } |
OLD | NEW |