gtk+ r20013 - trunk/gtk/xdgmime
- From: matthiasc svn gnome org
- To: svn-commits-list gnome org
- Subject: gtk+ r20013 - trunk/gtk/xdgmime
- Date: Wed, 16 Apr 2008 23:18:28 +0100 (BST)
Author: matthiasc
Date: Wed Apr 16 23:18:27 2008
New Revision: 20013
URL: http://svn.gnome.org/viewvc/gtk+?rev=20013&view=rev
Log:
Sync xdgmime to the copy in gio
Modified:
trunk/gtk/xdgmime/ChangeLog
trunk/gtk/xdgmime/xdgmime.c
trunk/gtk/xdgmime/xdgmime.h
trunk/gtk/xdgmime/xdgmimecache.c
trunk/gtk/xdgmime/xdgmimecache.h
trunk/gtk/xdgmime/xdgmimemagic.c
trunk/gtk/xdgmime/xdgmimemagic.h
Modified: trunk/gtk/xdgmime/xdgmime.c
==============================================================================
--- trunk/gtk/xdgmime/xdgmime.c (original)
+++ trunk/gtk/xdgmime/xdgmime.c Wed Apr 16 23:18:27 2008
@@ -93,17 +93,26 @@
typedef int (*XdgDirectoryFunc) (const char *directory,
void *user_data);
-static XdgDirTimeList *
-xdg_dir_time_list_new (void)
+static void
+xdg_dir_time_list_add (char *file_name,
+ time_t mtime)
{
- XdgDirTimeList *retval;
-
- retval = calloc (1, sizeof (XdgDirTimeList));
- retval->checked = XDG_CHECKED_UNCHECKED;
+ XdgDirTimeList *list;
- return retval;
+ for (list = dir_time_list; list; list = list->next)
+ {
+ if (strcmp (list->directory_name, file_name) == 0)
+ return;
+ }
+
+ list = calloc (1, sizeof (XdgDirTimeList));
+ list->checked = XDG_CHECKED_UNCHECKED;
+ list->directory_name = file_name;
+ list->mtime = mtime;
+ list->next = dir_time_list;
+ dir_time_list = list;
}
-
+
static void
xdg_dir_time_list_free (XdgDirTimeList *list)
{
@@ -123,7 +132,6 @@
{
char *file_name;
struct stat st;
- XdgDirTimeList *list;
assert (directory != NULL);
@@ -135,11 +143,7 @@
if (cache != NULL)
{
- list = xdg_dir_time_list_new ();
- list->directory_name = file_name;
- list->mtime = st.st_mtime;
- list->next = dir_time_list;
- dir_time_list = list;
+ xdg_dir_time_list_add (file_name, st.st_mtime);
_caches = realloc (_caches, sizeof (XdgMimeCache *) * (n_caches + 2));
_caches[n_caches] = cache;
@@ -156,12 +160,7 @@
if (stat (file_name, &st) == 0)
{
_xdg_mime_glob_read_from_file (global_hash, file_name);
-
- list = xdg_dir_time_list_new ();
- list->directory_name = file_name;
- list->mtime = st.st_mtime;
- list->next = dir_time_list;
- dir_time_list = list;
+ xdg_dir_time_list_add (file_name, st.st_mtime);
}
else
{
@@ -173,12 +172,7 @@
if (stat (file_name, &st) == 0)
{
_xdg_mime_magic_read_from_file (global_magic, file_name);
-
- list = xdg_dir_time_list_new ();
- list->directory_name = file_name;
- list->mtime = st.st_mtime;
- list->next = dir_time_list;
- dir_time_list = list;
+ xdg_dir_time_list_add (file_name, st.st_mtime);
}
else
{
@@ -296,12 +290,11 @@
for (list = dir_time_list; list; list = list->next)
{
- if (! strcmp (list->directory_name, file_path) &&
- st.st_mtime == list->mtime)
+ if (! strcmp (list->directory_name, file_path))
{
- if (list->checked == XDG_CHECKED_UNCHECKED)
+ if (st.st_mtime == list->mtime)
list->checked = XDG_CHECKED_VALID;
- else if (list->checked == XDG_CHECKED_VALID)
+ else
list->checked = XDG_CHECKED_INVALID;
return (list->checked != XDG_CHECKED_VALID);
@@ -440,16 +433,17 @@
const char *
xdg_mime_get_mime_type_for_data (const void *data,
- size_t len)
+ size_t len,
+ int *result_prio)
{
const char *mime_type;
xdg_mime_init ();
if (_caches)
- return _xdg_mime_cache_get_mime_type_for_data (data, len);
+ return _xdg_mime_cache_get_mime_type_for_data (data, len, result_prio);
- mime_type = _xdg_mime_magic_lookup_data (global_magic, data, len, NULL, 0);
+ mime_type = _xdg_mime_magic_lookup_data (global_magic, data, len, result_prio, NULL, 0);
if (mime_type)
return mime_type;
@@ -524,7 +518,7 @@
return XDG_MIME_TYPE_UNKNOWN;
}
- mime_type = _xdg_mime_magic_lookup_data (global_magic, data, bytes_read,
+ mime_type = _xdg_mime_magic_lookup_data (global_magic, data, bytes_read, NULL,
mime_types, n);
free (data);
@@ -553,6 +547,19 @@
}
int
+xdg_mime_get_mime_types_from_file_name (const char *file_name,
+ const char *mime_types[],
+ int n_mime_types)
+{
+ xdg_mime_init ();
+
+ if (_caches)
+ return _xdg_mime_cache_get_mime_types_from_file_name (file_name, mime_types, n_mime_types);
+
+ return _xdg_glob_hash_lookup_file_name (global_hash, file_name, mime_types, n_mime_types);
+}
+
+int
xdg_mime_is_valid_mime_type (const char *mime_type)
{
/* FIXME: We should make this a better test
Modified: trunk/gtk/xdgmime/xdgmime.h
==============================================================================
--- trunk/gtk/xdgmime/xdgmime.h (original)
+++ trunk/gtk/xdgmime/xdgmime.h Wed Apr 16 23:18:27 2008
@@ -50,13 +50,17 @@
#define xdg_mime_get_mime_type_for_data XDG_ENTRY(get_mime_type_for_data)
#define xdg_mime_get_mime_type_for_file XDG_ENTRY(get_mime_type_for_file)
#define xdg_mime_get_mime_type_from_file_name XDG_ENTRY(get_mime_type_from_file_name)
+#define xdg_mime_get_mime_types_from_file_name XDG_ENTRY(get_mime_types_from_file_name)
#define xdg_mime_is_valid_mime_type XDG_ENTRY(is_valid_mime_type)
#define xdg_mime_mime_type_equal XDG_ENTRY(mime_type_equal)
+#define _xdg_mime_mime_type_equal XDG_ENTRY(mime_type_equal_p)
#define xdg_mime_media_type_equal XDG_ENTRY(media_type_equal)
#define xdg_mime_mime_type_subclass XDG_ENTRY(mime_type_subclass)
+#define _xdg_mime_mime_type_subclass XDG_ENTRY(mime_type_subclass_p)
#define xdg_mime_get_mime_parents XDG_ENTRY(get_mime_parents)
#define xdg_mime_list_mime_parents XDG_ENTRY(list_mime_parents)
#define xdg_mime_unalias_mime_type XDG_ENTRY(unalias_mime_type)
+#define _xdg_mime_unalias_mime_type XDG_ENTRY(unalias_mime_type_p)
#define xdg_mime_get_max_buffer_extents XDG_ENTRY(get_max_buffer_extents)
#define xdg_mime_shutdown XDG_ENTRY(shutdown)
#define xdg_mime_dump XDG_ENTRY(dump)
@@ -69,10 +73,14 @@
#define XDG_MIME_TYPE_UNKNOWN xdg_mime_type_unknown
const char *xdg_mime_get_mime_type_for_data (const void *data,
- size_t len);
+ size_t len,
+ int *result_prio);
const char *xdg_mime_get_mime_type_for_file (const char *file_name,
struct stat *statbuf);
const char *xdg_mime_get_mime_type_from_file_name (const char *file_name);
+int xdg_mime_get_mime_types_from_file_name(const char *file_name,
+ const char *mime_types[],
+ int n_mime_types);
int xdg_mime_is_valid_mime_type (const char *mime_type);
int xdg_mime_mime_type_equal (const char *mime_a,
const char *mime_b);
@@ -101,6 +109,7 @@
const char *mime_b);
int _xdg_mime_mime_type_subclass (const char *mime,
const char *base);
+const char *_xdg_mime_unalias_mime_type (const char *mime);
#ifdef __cplusplus
Modified: trunk/gtk/xdgmime/xdgmimecache.c
==============================================================================
--- trunk/gtk/xdgmime/xdgmimecache.c (original)
+++ trunk/gtk/xdgmime/xdgmimecache.c Wed Apr 16 23:18:27 2008
@@ -623,6 +623,7 @@
static const char *
cache_get_mime_type_for_data (const void *data,
size_t len,
+ int *result_prio,
const char *mime_types[],
int n_mime_types)
{
@@ -647,11 +648,15 @@
}
}
+ if (result_prio)
+ *result_prio = priority;
+
if (priority > 0)
return mime_type;
for (n = 0; n < n_mime_types; n++)
{
+
if (mime_types[n])
return mime_types[n];
}
@@ -661,9 +666,10 @@
const char *
_xdg_mime_cache_get_mime_type_for_data (const void *data,
- size_t len)
+ size_t len,
+ int *result_prio)
{
- return cache_get_mime_type_for_data (data, len, NULL, 0);
+ return cache_get_mime_type_for_data (data, len, result_prio, NULL, 0);
}
const char *
@@ -726,7 +732,7 @@
return XDG_MIME_TYPE_UNKNOWN;
}
- mime_type = cache_get_mime_type_for_data (data, bytes_read,
+ mime_type = cache_get_mime_type_for_data (data, bytes_read, NULL,
mime_types, n);
free (data);
@@ -746,6 +752,14 @@
return XDG_MIME_TYPE_UNKNOWN;
}
+int
+_xdg_mime_cache_get_mime_types_from_file_name (const char *file_name,
+ const char *mime_types[],
+ int n_mime_types)
+{
+ return cache_glob_lookup_file_name (file_name, mime_types, n_mime_types);
+}
+
#if 1
static int
is_super_type (const char *mime)
@@ -851,7 +865,7 @@
char **
_xdg_mime_cache_list_mime_parents (const char *mime)
{
- int i, j, k, p;
+ int i, j, k, l, p;
char *all_parents[128]; /* we'll stop at 128 */
char **result;
@@ -878,14 +892,25 @@
for (k = 0; k < n_parents && p < 127; k++)
{
parent_mime_offset = GET_UINT32 (cache->buffer, parents_offset + 4 + 4 * k);
- all_parents[p++] = cache->buffer + parent_mime_offset;
+
+ /* Don't add same parent multiple times.
+ * This can happen for instance if the same type is listed in multiple directories
+ */
+ for (l = 0; l < p; l++)
+ {
+ if (strcmp (all_parents[l], cache->buffer + parent_mime_offset) == 0)
+ break;
+ }
+
+ if (l == p)
+ all_parents[p++] = cache->buffer + parent_mime_offset;
}
break;
}
}
}
- all_parents[p++] = 0;
+ all_parents[p++] = NULL;
result = (char **) malloc (p * sizeof (char *));
memcpy (result, all_parents, p * sizeof (char *));
Modified: trunk/gtk/xdgmime/xdgmimecache.h
==============================================================================
--- trunk/gtk/xdgmime/xdgmimecache.h (original)
+++ trunk/gtk/xdgmime/xdgmimecache.h Wed Apr 16 23:18:27 2008
@@ -39,6 +39,7 @@
#define _xdg_mime_cache_get_mime_type_for_data XDG_ENTRY(cache_get_mime_type_for_data)
#define _xdg_mime_cache_get_mime_type_for_file XDG_ENTRY(cache_get_mime_type_for_file)
#define _xdg_mime_cache_get_mime_type_from_file_name XDG_ENTRY(cache_get_mime_type_from_file_name)
+#define _xdg_mime_cache_get_mime_types_from_file_name XDG_ENTRY(cache_get_mime_types_from_file_name)
#define _xdg_mime_cache_list_mime_parents XDG_ENTRY(cache_list_mime_parents)
#define _xdg_mime_cache_mime_type_subclass XDG_ENTRY(cache_mime_type_subclass)
#define _xdg_mime_cache_unalias_mime_type XDG_ENTRY(cache_unalias_mime_type)
@@ -53,9 +54,13 @@
const char *_xdg_mime_cache_get_mime_type_for_data (const void *data,
- size_t len);
+ size_t len,
+ int *result_prio);
const char *_xdg_mime_cache_get_mime_type_for_file (const char *file_name,
struct stat *statbuf);
+int _xdg_mime_cache_get_mime_types_from_file_name (const char *file_name,
+ const char *mime_types[],
+ int n_mime_types);
const char *_xdg_mime_cache_get_mime_type_from_file_name (const char *file_name);
int _xdg_mime_cache_is_valid_mime_type (const char *mime_type);
int _xdg_mime_cache_mime_type_equal (const char *mime_a,
Modified: trunk/gtk/xdgmime/xdgmimemagic.c
==============================================================================
--- trunk/gtk/xdgmime/xdgmimemagic.c (original)
+++ trunk/gtk/xdgmime/xdgmimemagic.c Wed Apr 16 23:18:27 2008
@@ -656,21 +656,24 @@
_xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic,
const void *data,
size_t len,
+ int *result_prio,
const char *mime_types[],
int n_mime_types)
{
XdgMimeMagicMatch *match;
const char *mime_type;
int n;
+ int prio;
+ prio = 0;
mime_type = NULL;
for (match = mime_magic->match_list; match; match = match->next)
{
if (_xdg_mime_magic_match_compare_to_data (match, data, len))
{
- if ((mime_type == NULL) || (_xdg_mime_mime_type_subclass (match->mime_type, mime_type))) {
- mime_type = match->mime_type;
- }
+ prio = match->priority;
+ mime_type = match->mime_type;
+ break;
}
else
{
@@ -691,6 +694,9 @@
mime_type = mime_types[n];
}
}
+
+ if (result_prio)
+ *result_prio = prio;
return mime_type;
}
Modified: trunk/gtk/xdgmime/xdgmimemagic.h
==============================================================================
--- trunk/gtk/xdgmime/xdgmimemagic.h (original)
+++ trunk/gtk/xdgmime/xdgmimemagic.h Wed Apr 16 23:18:27 2008
@@ -50,6 +50,7 @@
const char *_xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic,
const void *data,
size_t len,
+ int *result_prio,
const char *mime_types[],
int n_mime_types);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]