diff --git a/thunar/main.c b/thunar/main.c index 9de4bd3..5cdedb5 100644 --- a/thunar/main.c +++ b/thunar/main.c @@ -28,6 +28,8 @@ #include #endif +#include + #include #ifdef HAVE_GIO_UNIX #include @@ -54,6 +56,7 @@ static gchar *opt_sm_client_id = NULL; static gboolean opt_quit = FALSE; static gboolean opt_version = FALSE; +magic_t magic_cookie; /* --- command line options --- */ @@ -199,6 +202,14 @@ main (int argc, char **argv) /* determine the current working directory */ working_directory = g_get_current_dir (); + magic_cookie = magic_open(MAGIC_MIME); + if (magic_cookie == NULL) + g_fprintf(stderr, "Thunar: unable to initialize magic library\n"); + if (magic_load(magic_cookie, NULL) != 0) { + g_fprintf(stderr, "Thunar: unable to load magic database: %s\n", + magic_error(magic_cookie)); + magic_close(magic_cookie); + } /* check if atleast one filename was specified, else * fall back to opening the current working directory * if daemon mode is not requested. @@ -307,6 +318,7 @@ error0: #ifdef HAVE_LIBNOTIFY thunar_notify_uninit (); #endif - + + magic_close(magic_cookie); return EXIT_SUCCESS; } diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 08729b3..c759bfc 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -31,6 +31,8 @@ #include #endif +#include + #ifdef HAVE_ERRNO_H #include #endif @@ -138,7 +140,7 @@ static guint file_signals[LAST_SIGNAL]; G_DEFINE_TYPE_WITH_CODE (ThunarFile, thunar_file, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (THUNARX_TYPE_FILE_INFO, thunar_file_info_init)) - +extern magic_t magic_cookie; #ifdef G_ENABLE_DEBUG static gboolean thunar_file_atexit_registered = FALSE; @@ -2416,13 +2418,17 @@ thunar_file_get_image_size (const ThunarFile *file, gchar *absolute_path; GdkPixbufFormat *result = NULL; - _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL); - + _thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL); + absolute_path = g_file_get_path (thunar_file_get_file (file)); + /* use libmagic if avaiable */ + if(magic_cookie) + if(strncmp (magic_file (magic_cookie, absolute_path), + "application/xml", strlen ("application/xml")) == 0) + return NULL; /* Don't use gdk_pixbuf_get_file_info for some vector formats */ if(strcmp ("image/svg+xml", thunar_file_get_content_type (file)) == 0) return NULL; - absolute_path = g_file_get_path (thunar_file_get_file (file)); result = gdk_pixbuf_get_file_info (absolute_path, width, height); g_free (absolute_path); return result;