[gthumb] fixed svg images not displayed with the image viewer
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] fixed svg images not displayed with the image viewer
- Date: Sat, 15 Sep 2012 08:22:11 +0000 (UTC)
commit ac2f522f829443ac4ef22e6b781dccc78a7ba294
Author: Paolo Bacchilega <paobac src gnome org>
Date: Thu Sep 6 16:57:18 2012 +0200
fixed svg images not displayed with the image viewer
added an optional 'file' parameter to _g_content_type_get_from_stream
to get the mime type from the extension when the content type is
application/xml.
gthumb/glib-utils.c | 13 +++++++++++++
gthumb/glib-utils.h | 1 +
gthumb/gth-file-data.c | 14 +-------------
gthumb/gth-image-loader.c | 18 +++++++++---------
gthumb/gth-image-utils.c | 2 +-
gthumb/gth-thumb-loader.c | 2 +-
gthumb/pixbuf-io.c | 2 +-
7 files changed, 27 insertions(+), 25 deletions(-)
---
diff --git a/gthumb/glib-utils.c b/gthumb/glib-utils.c
index d380ecd..9370915 100644
--- a/gthumb/glib-utils.c
+++ b/gthumb/glib-utils.c
@@ -2802,6 +2802,9 @@ _g_file_info_swap_attributes (GFileInfo *info,
const char *
_g_content_type_guess_from_name (const char *filename)
{
+ if (filename == NULL)
+ return NULL;
+
#if WEBP_IS_UNKNOWN_TO_GLIB
const char *ext;
@@ -2891,6 +2894,7 @@ get_mime_type_from_magic_numbers (void *buffer,
const char *
_g_content_type_get_from_stream (GInputStream *istream,
+ GFile *file,
GCancellable *cancellable,
GError **error)
{
@@ -2913,6 +2917,15 @@ _g_content_type_get_from_stream (GInputStream *istream,
if (result_uncertain)
content_type = NULL;
+ if (((content_type == NULL) || (strcmp (content_type, "application/xml") == 0)) && (file != NULL)) {
+ char *filename;
+
+ filename = g_file_get_basename (file);
+ content_type = _g_content_type_guess_from_name (filename);
+
+ g_free (filename);
+ }
+
g_seekable_seek (G_SEEKABLE (istream), 0, G_SEEK_SET, cancellable, NULL);
return content_type;
diff --git a/gthumb/glib-utils.h b/gthumb/glib-utils.h
index f870863..0b54fd3 100644
--- a/gthumb/glib-utils.h
+++ b/gthumb/glib-utils.h
@@ -311,6 +311,7 @@ const char * _g_content_type_guess_from_name (const char *filename);
gboolean _g_content_type_is_a (const char *type,
const char *supertype);
const char * _g_content_type_get_from_stream (GInputStream *istream,
+ GFile *file, /* optional */
GCancellable *cancellable,
GError **error);
gboolean _g_mime_type_is_image (const char *mime_type);
diff --git a/gthumb/gth-file-data.c b/gthumb/gth-file-data.c
index 78704bd..ebc4228 100644
--- a/gthumb/gth-file-data.c
+++ b/gthumb/gth-file-data.c
@@ -244,35 +244,23 @@ gth_file_data_get_mime_type_from_content (GthFileData *self,
content_type = g_file_info_get_attribute_string (self->info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
if (content_type == NULL) {
- char *filename;
GInputStream *istream;
GError *error = NULL;
-
-
if (self->file == NULL)
return NULL;
- filename = g_file_get_basename (self->file);
- if (filename == NULL)
- return NULL;
-
istream = (GInputStream *) g_file_read (self->file, cancellable, &error);
if (istream == NULL) {
- g_free (filename);
g_warning ("%s", error->message);
g_clear_error (&error);
return NULL;
}
- content_type = _g_content_type_get_from_stream (istream, cancellable, &error);
- if ((content_type == NULL) || (strcmp (content_type, "application/xml") == 0))
- content_type = _g_content_type_guess_from_name (filename);
-
+ content_type = _g_content_type_get_from_stream (istream, self->file, cancellable, &error);
g_file_info_set_attribute_string (self->info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, content_type);
g_object_unref (istream);
- g_free (filename);
}
return get_static_string (content_type);
diff --git a/gthumb/gth-image-loader.c b/gthumb/gth-image-loader.c
index c3a7c20..d0bea2b 100644
--- a/gthumb/gth-image-loader.c
+++ b/gthumb/gth-image-loader.c
@@ -180,19 +180,19 @@ load_pixbuf_thread (GSimpleAsyncResult *result,
GthImageLoaderFunc loader_func = NULL;
const char *mime_type;
- mime_type = _g_content_type_get_from_stream (istream, cancellable, NULL);
+ mime_type = _g_content_type_get_from_stream (istream, load_data->file_data->file, cancellable, NULL);
if (mime_type != NULL)
loader_func = gth_main_get_image_loader_func (mime_type, self->priv->preferred_format);
if (loader_func != NULL)
image = loader_func (istream,
- load_data->file_data,
- load_data->requested_size,
- &original_width,
- &original_height,
- NULL,
- cancellable,
- &error);
+ load_data->file_data,
+ load_data->requested_size,
+ &original_width,
+ &original_height,
+ NULL,
+ cancellable,
+ &error);
else
error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("No suitable loader available for this file type"));
}
@@ -286,7 +286,7 @@ gth_image_new_from_stream (GInputStream *istream,
int original_height;
GError *error = NULL;
- mime_type = _g_content_type_get_from_stream (istream, cancellable, &error);
+ mime_type = _g_content_type_get_from_stream (istream, NULL, cancellable, &error);
if (mime_type != NULL) {
loader_func = gth_main_get_image_loader_func (mime_type, GTH_IMAGE_FORMAT_CAIRO_SURFACE);
if (loader_func != NULL)
diff --git a/gthumb/gth-image-utils.c b/gthumb/gth-image-utils.c
index c084847..c4f1928 100644
--- a/gthumb/gth-image-utils.c
+++ b/gthumb/gth-image-utils.c
@@ -126,7 +126,7 @@ _g_buffer_resize_image (void *buffer,
}
istream = g_memory_input_stream_new_from_data (buffer, count, NULL);
- mime_type = _g_content_type_get_from_stream (istream, cancellable, NULL);
+ mime_type = _g_content_type_get_from_stream (istream, (file_data != NULL ? file_data->file : NULL), cancellable, NULL);
if (mime_type == NULL) {
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "%s", _("No suitable loader available for this file type"));
return FALSE;
diff --git a/gthumb/gth-thumb-loader.c b/gthumb/gth-thumb-loader.c
index e05a742..0899fac 100644
--- a/gthumb/gth-thumb-loader.c
+++ b/gthumb/gth-thumb-loader.c
@@ -139,7 +139,7 @@ generate_thumbnail (GInputStream *istream,
if (original_height != NULL)
*original_height = -1;
- mime_type = _g_content_type_get_from_stream (istream, cancellable, error);
+ mime_type = _g_content_type_get_from_stream (istream, file_data->file, cancellable, error);
if (mime_type == NULL) {
if ((error != NULL) && (*error == NULL))
*error = g_error_new_literal (GTH_ERROR, 0, "Cannot generate the thumbnail: unknown file type");
diff --git a/gthumb/pixbuf-io.c b/gthumb/pixbuf-io.c
index 3294812..2a1f625 100644
--- a/gthumb/pixbuf-io.c
+++ b/gthumb/pixbuf-io.c
@@ -223,7 +223,7 @@ gth_pixbuf_animation_new_from_file (GInputStream *istream,
char *path;
GthImage *image;
- mime_type = _g_content_type_get_from_stream (istream, cancellable, error);
+ mime_type = _g_content_type_get_from_stream (istream, (file_data != NULL ? file_data->file : NULL), cancellable, error);
if (mime_type == NULL)
return NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]