diff --git a/configure.in.in b/configure.in.in index ceb575d..13a8f89 100644 --- a/configure.in.in +++ b/configure.in.in @@ -133,12 +133,34 @@ AC_CHECK_HEADERS([ctype.h errno.h fcntl.h grp.h limits.h locale.h memory.h \ sys/uio.h sys/wait.h time.h]) dnl ************************************ +dnl *** try to find magic files *** +dnl ************************************ + +AC_ARG_WITH(magic, + AC_HELP_STRING([--with-magic], [support libmagic support to determine the type of a file]), + [], + [with_magic=no]) + +LIBMAGIC = +AS_IF([test "x$with_magic" != xno], + [AC_CHECK_LIB([magic], [main], + [AC_SUBST([LIBMAGIC], ["-lmagic"]) + AC_DEFINE([HAVE_MAGIC_H], [1], + [Define if you have libmagic]) + ], + [AC_MSG_FAILURE( + [--with-magic was given, but test for libmagic failed])], + [])]) + +dnl ************************************ dnl *** Check for standard functions *** dnl ************************************ AC_FUNC_MMAP() AC_CHECK_FUNCS([localeconv mkdtemp pread pwrite sched_yield setgroupent \ setpassent strcoll strlcpy strptime symlink]) + + dnl ****************************** dnl *** Check for i18n support *** dnl ****************************** diff --git a/thunar/Makefile.am b/thunar/Makefile.am index b715fea..166eb0b 100644 --- a/thunar/Makefile.am +++ b/thunar/Makefile.am @@ -241,6 +241,7 @@ Thunar_CFLAGS = \ Thunar_LDFLAGS = \ -no-undefined \ $(LIBSM_LDFLAGS) \ + $(LIBMAGIC) \ $(PLATFORM_LDFLAGS) Thunar_LDADD = \ diff --git a/thunar/main.c b/thunar/main.c index 9de4bd3..478e440 100644 --- a/thunar/main.c +++ b/thunar/main.c @@ -28,6 +28,10 @@ #include #endif +#ifdef HAVE_MAGIC_H +#include +#endif + #include #ifdef HAVE_GIO_UNIX #include @@ -54,7 +58,9 @@ static gchar *opt_sm_client_id = NULL; static gboolean opt_quit = FALSE; static gboolean opt_version = FALSE; - +#ifdef HAVE_MAGIC_H +magic_t magic_cookie; +#endif /* --- command line options --- */ static GOptionEntry option_entries[] = @@ -199,6 +205,16 @@ main (int argc, char **argv) /* determine the current working directory */ working_directory = g_get_current_dir (); +#ifdef HAVE_MAGIC_H + 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); + } +#endif /* check if atleast one filename was specified, else * fall back to opening the current working directory * if daemon mode is not requested. @@ -307,6 +323,9 @@ error0: #ifdef HAVE_LIBNOTIFY thunar_notify_uninit (); #endif - + +#ifdef HAVE_MAGIC_H + magic_close(magic_cookie); +#endif return EXIT_SUCCESS; } diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 08729b3..522ada1 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -50,6 +50,10 @@ #include #endif +#ifdef HAVE_MAGIC_H +#include +#endif + #include #include @@ -138,7 +142,9 @@ 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)) - +#ifdef HAVE_MAGIC_H +extern magic_t magic_cookie; +#endif #ifdef G_ENABLE_DEBUG static gboolean thunar_file_atexit_registered = FALSE; @@ -2416,13 +2422,19 @@ 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)); +#ifdef HAVE_MAGIC_H + /* use libmagic if avaiable */ + if(magic_cookie) + if(strncmp (magic_file (magic_cookie, absolute_path), + "application/xml", strlen ("application/xml")) == 0) + return NULL; +#endif /* 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;