diff options
author | Marco Pesenti Gritti <mpg@redhat.com> | 2005-05-08 18:26:01 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2005-05-08 18:26:01 (GMT) |
commit | a5e3f1314e7e27fb0e765b3b9b8e1deb92c7c536 (patch) | |
tree | 877ee4110e50389f75507166a092d0a9c0049d51 /shell/ev-document-types.c | |
parent | b9898930ba07edc66523a753de8dd5a4f69703dd (diff) |
Change api to lookup from uri. Do fast lookup first, if the type is
2005-05-08 Marco Pesenti Gritti <mpg@redhat.com>
* shell/ev-document-types.c: (get_slow_mime_type),
(get_document_type_from_mime), (ev_document_type_lookup):
* shell/ev-document-types.h:
Change api to lookup from uri. Do fast lookup first, if the
type is unknown try with data sniffing.
* shell/ev-window.c: (ev_window_open), (ev_window_open_uri_list):
* thumbnailer/evince-thumbnailer.c: (evince_thumbnail_pngenc_get):
Adapt to api change
Diffstat (limited to 'shell/ev-document-types.c')
-rw-r--r-- | shell/ev-document-types.c | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/shell/ev-document-types.c b/shell/ev-document-types.c index 2d64594..a373d18 100644 --- a/shell/ev-document-types.c +++ b/shell/ev-document-types.c @@ -36,6 +36,9 @@ #endif #include <string.h> +#include <libgnomevfs/gnome-vfs-mime-utils.h> +#include <libgnomevfs/gnome-vfs-file-info.h> +#include <libgnomevfs/gnome-vfs-ops.h> typedef struct _EvDocumentType EvDocumentType; struct _EvDocumentType @@ -102,16 +105,36 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type) return retval; } -GType -ev_document_type_lookup (const char *mime_type) +static char * +get_slow_mime_type (const char *uri) { - int i; + GnomeVFSFileInfo *info; + char *mime_type; + GnomeVFSResult result; + + info = gnome_vfs_file_info_new (); + result = gnome_vfs_get_file_info (uri, info, + GNOME_VFS_FILE_INFO_GET_MIME_TYPE | + GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE | + GNOME_VFS_FILE_INFO_FOLLOW_LINKS); + if (info->mime_type == NULL || result != GNOME_VFS_OK) { + mime_type = NULL; + } else { + mime_type = g_strdup (info->mime_type); + } + gnome_vfs_file_info_unref (info); + + return mime_type; +} - g_return_val_if_fail (mime_type, G_TYPE_INVALID); +static GType +get_document_type_from_mime (const char *mime_type) +{ + int i; - for (i=0;i<G_N_ELEMENTS (document_types);i++) { - if (0==strcmp(mime_type, document_types[i].mime_type)) { - g_assert (document_types[i].document_type_factory_callback!=NULL); + for (i = 0; i < G_N_ELEMENTS (document_types); i++) { + if (strcmp (mime_type, document_types[i].mime_type) == 0) { + g_assert (document_types[i].document_type_factory_callback != NULL); return document_types[i].document_type_factory_callback(); } } @@ -122,3 +145,33 @@ ev_document_type_lookup (const char *mime_type) return G_TYPE_INVALID; } + +GType +ev_document_type_lookup (const char *uri, char **mime_type) +{ + GType type = G_TYPE_INVALID; + char *mime; + + g_return_val_if_fail (uri, G_TYPE_INVALID); + + mime = gnome_vfs_get_mime_type (uri); + if (mime) { + type = get_document_type_from_mime (mime); + } + + if (type == G_TYPE_INVALID) { + g_free (mime); + mime = get_slow_mime_type (uri); + if (mime) { + type = get_document_type_from_mime (mime); + } + } + + if (mime_type) { + *mime_type = mime; + } else { + g_free (mime); + } + + return type; +} |