|
24 | 24 | #include "nemo-preview-image.h" |
25 | 25 | #include "nemo-file-attributes.h" |
26 | 26 | #include "nemo-icon-info.h" |
| 27 | +#include "nemo-thumbnails.h" |
27 | 28 | #include <glib/gi18n.h> |
28 | 29 |
|
29 | 30 | #define RESIZE_DEBOUNCE_MS 150 |
@@ -218,23 +219,6 @@ on_drawing_area_draw (GtkWidget *widget, |
218 | 219 | return TRUE; |
219 | 220 | } |
220 | 221 |
|
221 | | -static gboolean |
222 | | -is_image_file (NemoFile *file) |
223 | | -{ |
224 | | - gchar *mime_type; |
225 | | - gboolean is_image; |
226 | | - |
227 | | - if (file == NULL || nemo_file_is_directory (file)) { |
228 | | - return FALSE; |
229 | | - } |
230 | | - |
231 | | - mime_type = nemo_file_get_mime_type (file); |
232 | | - is_image = mime_type != NULL && g_str_has_prefix (mime_type, "image/"); |
233 | | - g_free (mime_type); |
234 | | - |
235 | | - return is_image; |
236 | | -} |
237 | | - |
238 | 222 | static void |
239 | 223 | load_icon_at_size (NemoPreviewImage *widget, |
240 | 224 | gint width, |
@@ -335,40 +319,59 @@ load_image_at_size (NemoPreviewImage *widget, |
335 | 319 | gint height) |
336 | 320 | { |
337 | 321 | NemoPreviewImagePrivate *priv; |
338 | | - GFile *location; |
339 | | - gchar *path; |
340 | 322 | GdkPixbuf *pixbuf = NULL; |
341 | 323 | cairo_surface_t *surface = NULL; |
342 | 324 | gint ui_scale; |
343 | 325 | GError *error = NULL; |
344 | 326 |
|
345 | 327 | priv = nemo_preview_image_get_instance_private (widget); |
| 328 | + ui_scale = gtk_widget_get_scale_factor (GTK_WIDGET (widget)); |
346 | 329 |
|
347 | | - if (priv->file == NULL || !is_image_file (priv->file)) { |
| 330 | + if (priv->file == NULL) { |
348 | 331 | return; |
349 | 332 | } |
350 | 333 |
|
351 | 334 | if (width <= 1 || height <= 1) { |
352 | 335 | return; |
353 | 336 | } |
354 | 337 |
|
355 | | - location = nemo_file_get_location (priv->file); |
356 | | - path = g_file_get_path (location); |
357 | | - g_object_unref (location); |
358 | | - |
359 | | - if (path == NULL) { |
360 | | - return; |
| 338 | + if (nemo_can_thumbnail_internally (priv->file)) { |
| 339 | + gchar *path = nemo_file_get_path (priv->file); |
| 340 | + |
| 341 | + if (path != NULL) { |
| 342 | + pixbuf = gdk_pixbuf_new_from_file_at_scale (path, |
| 343 | + width * ui_scale, |
| 344 | + height * ui_scale, |
| 345 | + TRUE, |
| 346 | + &error); |
| 347 | + if (error != NULL) { |
| 348 | + g_warning ("Failed to load direct image preview: %s", error->message); |
| 349 | + g_clear_error (&error); |
| 350 | + } |
| 351 | + |
| 352 | + g_free (path); |
| 353 | + } |
| 354 | + } |
| 355 | + |
| 356 | + if (pixbuf == NULL && nemo_file_has_loaded_thumbnail (priv->file)) { |
| 357 | + gchar *thumbnail_path = nemo_file_get_thumbnail_path (priv->file); |
| 358 | + |
| 359 | + if (thumbnail_path != NULL) { |
| 360 | + pixbuf = gdk_pixbuf_new_from_file_at_scale (thumbnail_path, |
| 361 | + width * ui_scale, |
| 362 | + height * ui_scale, |
| 363 | + TRUE, |
| 364 | + &error); |
| 365 | + |
| 366 | + if (error != NULL) { |
| 367 | + g_warning ("Failed to load file thumbnail for preview: %s", error->message); |
| 368 | + g_clear_error (&error); |
| 369 | + } |
| 370 | + |
| 371 | + g_free (thumbnail_path); |
| 372 | + } |
361 | 373 | } |
362 | 374 |
|
363 | | - ui_scale = gtk_widget_get_scale_factor (GTK_WIDGET (widget)); |
364 | | - |
365 | | - /* Load image directly at the exact size we need */ |
366 | | - pixbuf = gdk_pixbuf_new_from_file_at_scale (path, |
367 | | - width * ui_scale, |
368 | | - height * ui_scale, |
369 | | - TRUE, |
370 | | - &error); |
371 | | - |
372 | 375 | if (pixbuf != NULL) { |
373 | 376 | /* Save pixbuf for quick scaling during resize */ |
374 | 377 | if (priv->current_pixbuf != NULL) { |
@@ -402,8 +405,6 @@ load_image_at_size (NemoPreviewImage *widget, |
402 | 405 | gtk_widget_hide (priv->drawing_area); |
403 | 406 | } |
404 | 407 |
|
405 | | - g_free (path); |
406 | | - |
407 | 408 | priv->current_width = width; |
408 | 409 | priv->current_height = height; |
409 | 410 | } |
@@ -510,7 +511,7 @@ on_size_allocate (GtkWidget *widget, |
510 | 511 | allocation->height < priv->current_height); |
511 | 512 |
|
512 | 513 | /* If getting smaller, immediately scale down the current pixbuf for responsive UI */ |
513 | | - if (getting_smaller && priv->current_pixbuf != NULL) { |
| 514 | + if (priv->current_pixbuf != NULL) { |
514 | 515 | scale_current_pixbuf_to_size (preview, allocation->width, allocation->height); |
515 | 516 | } |
516 | 517 |
|
@@ -569,9 +570,7 @@ nemo_preview_image_set_file (NemoPreviewImage *widget, |
569 | 570 |
|
570 | 571 | if (file != NULL) { |
571 | 572 | nemo_file_ref (file); |
572 | | - |
573 | | - if (is_image_file (file)) { |
574 | | - /* Load the image at current widget size */ |
| 573 | + if (nemo_can_thumbnail_internally (file) || nemo_file_has_loaded_thumbnail (file)) { |
575 | 574 | priv->showing_icon = FALSE; |
576 | 575 | gtk_widget_get_allocation (GTK_WIDGET (widget), &allocation); |
577 | 576 | load_image_at_size (widget, allocation.width, allocation.height); |
|
0 commit comments