Skip to content

Commit 4620188

Browse files
committed
use thumbnails as backup.
1 parent 17d86df commit 4620188

4 files changed

Lines changed: 54 additions & 42 deletions

File tree

libnemo-private/nemo-file.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4555,6 +4555,18 @@ nemo_file_has_loaded_thumbnail (NemoFile *file)
45554555
return file->details->thumbnail_is_up_to_date;
45564556
}
45574557

4558+
char *
4559+
nemo_file_get_thumbnail_path (NemoFile *file)
4560+
{
4561+
g_return_val_if_fail (NEMO_IS_FILE (file), NULL);
4562+
4563+
if (file->details->thumbnail_path != NULL) {
4564+
return g_strdup (file->details->thumbnail_path);
4565+
}
4566+
4567+
return NULL;
4568+
}
4569+
45584570
static void
45594571
prepend_icon_name (const char *name,
45604572
GThemedIcon *icon)

libnemo-private/nemo-file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ NemoRequestStatus nemo_file_get_deep_counts (NemoFile
252252
gboolean nemo_file_should_show_thumbnail (NemoFile *file);
253253
void nemo_file_delete_thumbnail (NemoFile *file);
254254
gboolean nemo_file_has_loaded_thumbnail (NemoFile *file);
255+
char * nemo_file_get_thumbnail_path (NemoFile *file);
255256
gboolean nemo_file_should_show_directory_item_count (NemoFile *file);
256257
gboolean nemo_file_should_show_type (NemoFile *file);
257258
GList * nemo_file_get_keywords (NemoFile *file);

libnemo-private/nemo-preview-image.c

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "nemo-preview-image.h"
2525
#include "nemo-file-attributes.h"
2626
#include "nemo-icon-info.h"
27+
#include "nemo-thumbnails.h"
2728
#include <glib/gi18n.h>
2829

2930
#define RESIZE_DEBOUNCE_MS 150
@@ -218,23 +219,6 @@ on_drawing_area_draw (GtkWidget *widget,
218219
return TRUE;
219220
}
220221

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-
238222
static void
239223
load_icon_at_size (NemoPreviewImage *widget,
240224
gint width,
@@ -335,40 +319,59 @@ load_image_at_size (NemoPreviewImage *widget,
335319
gint height)
336320
{
337321
NemoPreviewImagePrivate *priv;
338-
GFile *location;
339-
gchar *path;
340322
GdkPixbuf *pixbuf = NULL;
341323
cairo_surface_t *surface = NULL;
342324
gint ui_scale;
343325
GError *error = NULL;
344326

345327
priv = nemo_preview_image_get_instance_private (widget);
328+
ui_scale = gtk_widget_get_scale_factor (GTK_WIDGET (widget));
346329

347-
if (priv->file == NULL || !is_image_file (priv->file)) {
330+
if (priv->file == NULL) {
348331
return;
349332
}
350333

351334
if (width <= 1 || height <= 1) {
352335
return;
353336
}
354337

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+
}
361373
}
362374

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-
372375
if (pixbuf != NULL) {
373376
/* Save pixbuf for quick scaling during resize */
374377
if (priv->current_pixbuf != NULL) {
@@ -402,8 +405,6 @@ load_image_at_size (NemoPreviewImage *widget,
402405
gtk_widget_hide (priv->drawing_area);
403406
}
404407

405-
g_free (path);
406-
407408
priv->current_width = width;
408409
priv->current_height = height;
409410
}
@@ -510,7 +511,7 @@ on_size_allocate (GtkWidget *widget,
510511
allocation->height < priv->current_height);
511512

512513
/* 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) {
514515
scale_current_pixbuf_to_size (preview, allocation->width, allocation->height);
515516
}
516517

@@ -569,9 +570,7 @@ nemo_preview_image_set_file (NemoPreviewImage *widget,
569570

570571
if (file != NULL) {
571572
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)) {
575574
priv->showing_icon = FALSE;
576575
gtk_widget_get_allocation (GTK_WIDGET (widget), &allocation);
577576
load_image_at_size (widget, allocation.width, allocation.height);

src/nemo-window-menus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ nemo_window_initialize_menus (NemoWindow *window)
19821982
gtk_action_set_visible (action_to_hide, eel_vfs_supports_uri_scheme ("trash"));
19831983
action_to_hide = gtk_action_group_get_action (action_group, "Go to Network");
19841984
gtk_action_set_visible (action_to_hide, eel_vfs_supports_uri_scheme ("network"));
1985-
g_printerr ("FUCKKKKKK\n");
1985+
19861986
gtk_action_group_add_toggle_actions (action_group,
19871987
main_toggle_entries, G_N_ELEMENTS (main_toggle_entries),
19881988
window);

0 commit comments

Comments
 (0)