From: Marco Pesenti Gritti Date: Sun, 8 May 2005 18:26:01 +0000 (+0000) Subject: Change api to lookup from uri. Do fast lookup first, if the type is X-Git-Tag: EVINCE_0_3_1~61 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=a5e3f1314e7e27fb0e765b3b9b8e1deb92c7c536;p=evince.git Change api to lookup from uri. Do fast lookup first, if the type is 2005-05-08 Marco Pesenti Gritti * 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 --- diff --git a/ChangeLog b/ChangeLog index 6458ceb8..c5d4f22c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-05-08 Marco Pesenti Gritti + + * 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 + 2005-05-07 Marco Pesenti Gritti * thumbnailer/Makefile.am: diff --git a/shell/ev-document-types.c b/shell/ev-document-types.c index 2d64594d..a373d181 100644 --- a/shell/ev-document-types.c +++ b/shell/ev-document-types.c @@ -36,6 +36,9 @@ #endif #include +#include +#include +#include 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 #include -#include #include #include #include @@ -743,21 +742,15 @@ void ev_window_open (EvWindow *ev_window, const char *uri) { EvDocument *document = NULL; - char *mime_type; + GType document_type; + char *mime_type = NULL; g_free (ev_window->priv->uri); ev_window->priv->uri = g_strdup (uri); - mime_type = gnome_vfs_get_mime_type (uri); - - if (mime_type == NULL) - document = NULL; - else { - GType document_type = ev_document_type_lookup (mime_type); - - if (document_type!=G_TYPE_INVALID) { - document = g_object_new (document_type, NULL); - } + document_type = ev_document_type_lookup (uri, &mime_type); + if (document_type != G_TYPE_INVALID) { + document = g_object_new (document_type, NULL); } if (document) { @@ -782,16 +775,15 @@ static void ev_window_open_uri_list (EvWindow *ev_window, GList *uri_list) { GList *list; - gchar *uri, *mime_type; + gchar *uri; g_return_if_fail (uri_list != NULL); list = uri_list; while (list) { uri = gnome_vfs_uri_to_string (list->data, GNOME_VFS_URI_HIDE_NONE); - mime_type = gnome_vfs_get_mime_type (uri); - if (ev_document_type_lookup (mime_type)!=G_TYPE_INVALID) { + if (ev_document_type_lookup (uri, NULL) != G_TYPE_INVALID) { if (ev_window_is_empty (EV_WINDOW (ev_window))) { ev_window_open (ev_window, uri); @@ -806,7 +798,6 @@ ev_window_open_uri_list (EvWindow *ev_window, GList *uri_list) } } - g_free (mime_type); g_free (uri); list = g_list_next (list); diff --git a/thumbnailer/evince-thumbnailer.c b/thumbnailer/evince-thumbnailer.c index 37242a1f..dfa521be 100644 --- a/thumbnailer/evince-thumbnailer.c +++ b/thumbnailer/evince-thumbnailer.c @@ -33,17 +33,13 @@ static gboolean evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail, int size) { EvDocument *document = NULL; - char *mime_type; GError *error = NULL; GdkPixbuf *pixbuf; GType document_type; + char *mime_type = NULL; - mime_type = gnome_vfs_get_mime_type (uri); - if (mime_type == NULL) - return FALSE; - - document_type = ev_document_type_lookup (mime_type); - if (document_type==G_TYPE_INVALID) + document_type = ev_document_type_lookup (uri, &mime_type); + if (document_type == G_TYPE_INVALID) return FALSE; document = g_object_new (document_type, NULL); @@ -67,7 +63,7 @@ evince_thumbnail_pngenc_get (const char *uri, const char *thumbnail, int size) if (pixbuf != NULL) { const char *overlaid_icon_name = NULL; - if (strcmp(mime_type,"application/pdf")==0) { + if (strcmp (mime_type, "application/pdf") == 0) { overlaid_icon_name = "pdf-icon.png"; }