[nautilus/wip/antoniof/gnome-42: 66/72] Revert "properties-window: Don't set filechooser preview"
- From: António Fernandes <antoniof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/antoniof/gnome-42: 66/72] Revert "properties-window: Don't set filechooser preview"
- Date: Fri, 11 Feb 2022 19:28:02 +0000 (UTC)
commit 733fb6bc8d16a605d1610c5c6873a4804d10af5a
Author: António Fernandes <antoniof gnome org>
Date: Fri Feb 11 19:06:18 2022 +0000
Revert "properties-window: Don't set filechooser preview"
This reverts commit 34d0d8669ad32d566c4024f1647ed7090cd40924.
src/nautilus-properties-window.c | 56 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 55 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 320501feb..c3bdce5de 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -49,6 +49,8 @@
#include "nautilus-ui-utilities.h"
#include "nautilus-signaller.h"
+#define PREVIEW_IMAGE_WIDTH 96
+
static GHashTable *windows;
static GHashTable *pending_lists;
@@ -5175,6 +5177,49 @@ set_icon (const char *icon_uri,
}
}
+static void
+update_preview_callback (GtkFileChooser *icon_chooser,
+ NautilusPropertiesWindow *self)
+{
+ GtkWidget *preview_widget;
+ g_autoptr (GdkPixbuf) pixbuf = NULL;
+ g_autofree char *filename = NULL;
+
+ filename = gtk_file_chooser_get_filename (icon_chooser);
+ if (filename != NULL)
+ {
+ pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
+ }
+
+ if (pixbuf != NULL)
+ {
+ preview_widget = gtk_file_chooser_get_preview_widget (icon_chooser);
+ gtk_file_chooser_set_preview_widget_active (icon_chooser, TRUE);
+
+ if (gdk_pixbuf_get_width (pixbuf) > PREVIEW_IMAGE_WIDTH)
+ {
+ double scale;
+ GdkPixbuf *scaled_pixbuf;
+
+ scale = (double) gdk_pixbuf_get_height (pixbuf) /
+ gdk_pixbuf_get_width (pixbuf);
+
+ scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf,
+ PREVIEW_IMAGE_WIDTH,
+ scale * PREVIEW_IMAGE_WIDTH,
+ GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
+ pixbuf = scaled_pixbuf;
+ }
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE (preview_widget), pixbuf);
+ }
+ else
+ {
+ gtk_file_chooser_set_preview_widget_active (icon_chooser, FALSE);
+ }
+}
+
static void
custom_icon_file_chooser_response_cb (GtkDialog *dialog,
gint response,
@@ -5219,7 +5264,7 @@ static void
select_image_button_callback (GtkWidget *widget,
NautilusPropertiesWindow *self)
{
- GtkWidget *dialog;
+ GtkWidget *dialog, *preview;
GtkFileFilter *filter;
GList *l;
NautilusFile *file;
@@ -5247,6 +5292,15 @@ select_image_button_callback (GtkWidget *widget,
gtk_file_filter_add_pixbuf_formats (filter);
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
+ preview = gtk_image_new ();
+ gtk_widget_set_size_request (preview, PREVIEW_IMAGE_WIDTH, -1);
+ gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (dialog), preview);
+ gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (dialog), FALSE);
+ gtk_file_chooser_set_preview_widget_active (GTK_FILE_CHOOSER (dialog), FALSE);
+
+ g_signal_connect (dialog, "update-preview",
+ G_CALLBACK (update_preview_callback), self);
+
self->icon_chooser = dialog;
g_object_add_weak_pointer (G_OBJECT (dialog),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]