diff options
author | Que Quotion | 2018-10-15 00:58:53 +0900 |
---|---|---|
committer | Que Quotion | 2018-10-15 00:58:53 +0900 |
commit | c2a6e4ec6274b5d2bda3a164d41d5cac9d41dc8f (patch) | |
tree | 4fe4d2ad8ca934319595a5e1f785f79cc5c6b952 /add-preview-widget.patch | |
parent | c4d4f9a385d04adb91d38d2d0e7844c3c8dd2c58 (diff) | |
download | aur-c2a6e4ec6274b5d2bda3a164d41d5cac9d41dc8f.tar.gz |
Add preview widgets to epiphany's filechoosers
https://gitlab.gnome.org/GNOME/epiphany/issues/552
https://gitlab.gnome.org/GNOME/epiphany/merge_requests/46
Diffstat (limited to 'add-preview-widget.patch')
-rw-r--r-- | add-preview-widget.patch | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/add-preview-widget.patch b/add-preview-widget.patch new file mode 100644 index 000000000000..7fb730286dc9 --- /dev/null +++ b/add-preview-widget.patch @@ -0,0 +1,81 @@ +--- src/os-patches/lib/widgets/ephy-file-chooser.c~ 2018-09-30 04:45:43.003990684 +0900 ++++ src/os-patches/lib/widgets/ephy-file-chooser.c 2018-10-07 00:40:58.833626868 +0900 +@@ -32,6 +32,12 @@ + #include <gtk/gtk.h> + #include <glib/gi18n.h> + ++#include <sys/types.h> ++#include <sys/stat.h> ++#include <glib/gstdio.h> ++ ++#define MAX_PREVIEW_SIZE 180 ++#define MAX_PREVIEW_SOURCE_SIZE 4096 + + static GtkFileFilter * + ephy_file_chooser_add_pattern_filter (GtkFileChooser *dialog, +@@ -89,6 +92,53 @@ + return filth; + } + ++static void ++update_preview_cb (GtkFileChooser *file_chooser, ++ gpointer data) ++{ ++ GtkImage *preview = GTK_IMAGE (data); ++ g_autofree char *filename = gtk_file_chooser_get_preview_filename(file_chooser); ++ ++ struct g_stat st_buf; ++ if (!filename || g_stat(filename, &st_buf) || (!S_ISREG(st_buf.st_mode))) { ++ gtk_file_chooser_set_preview_widget_active(file_chooser, FALSE); ++ return; // stat failed or file is not regular ++ } ++ ++ gint preview_width = 0; ++ gint preview_height = 0; ++ GdkPixbufFormat *preview_format = gdk_pixbuf_get_file_info(filename, ++ &preview_width, ++ &preview_height); ++ if (!preview_format || ++ preview_width <= 0 || preview_height <= 0 || ++ preview_width > MAX_PREVIEW_SOURCE_SIZE || ++ preview_height > MAX_PREVIEW_SOURCE_SIZE) { ++ gtk_file_chooser_set_preview_widget_active(file_chooser, FALSE); ++ return; // unpreviewable, 0px, or unsafely large ++ } ++ ++ g_autoptr(GdkPixbuf) pixbuf = NULL; ++ if (preview_width > MAX_PREVIEW_SIZE || preview_height > MAX_PREVIEW_SIZE) { ++ pixbuf = gdk_pixbuf_new_from_file_at_size(filename, ++ MAX_PREVIEW_SIZE, ++ MAX_PREVIEW_SIZE, ++ NULL); ++ } ++ else { ++ pixbuf = gdk_pixbuf_new_from_file(filename, NULL); ++ } ++ ++ pixbuf = gdk_pixbuf_apply_embedded_orientation(pixbuf); ++ ++ gtk_widget_set_size_request(GTK_WIDGET (preview), ++ gdk_pixbuf_get_width(pixbuf) + 6, ++ gdk_pixbuf_get_height(pixbuf) + 6); ++ ++ gtk_image_set_from_pixbuf(preview, pixbuf); ++ gtk_file_chooser_set_preview_widget_active(file_chooser, pixbuf != NULL); ++} ++ + GtkFileChooser * + ephy_create_file_chooser (const char *title, + GtkWidget *parent, +@@ -121,6 +195,11 @@ + gtk_file_chooser_native_set_accept_label (GTK_FILE_CHOOSER_NATIVE (dialog), _("_Save")); + } + ++ GtkWidget *preview = gtk_image_new(); ++ gtk_file_chooser_set_preview_widget(dialog, preview); ++ gtk_file_chooser_set_use_preview_label(dialog, FALSE); ++ g_signal_connect(dialog, "update-preview", G_CALLBACK(update_preview_cb), preview); ++ + if (default_filter != EPHY_FILE_FILTER_NONE) { + filter[EPHY_FILE_FILTER_ALL_SUPPORTED] = + ephy_file_chooser_add_mime_filter |