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 | |
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
-rw-r--r-- | .SRCINFO | 6 | ||||
-rw-r--r-- | PKGBUILD | 16 | ||||
-rw-r--r-- | add-preview-widget.patch | 81 | ||||
-rw-r--r-- | block-webkit-filechooser.patch | 87 |
4 files changed, 186 insertions, 4 deletions
@@ -1,7 +1,7 @@ pkgbase = epiphany-pantheon pkgdesc = GNOME web browser based on the WebKit rendering engine (with elementary OS patches) pkgver = 3.28.0.1+1ubuntu1+r21.dbc305d50 - pkgrel = 2 + pkgrel = 3 url = https://gitlab.gnome.org/GNOME/epiphany/ arch = i686 arch = x86_64 @@ -27,9 +27,13 @@ pkgbase = epiphany-pantheon source = git+https://github.com/elementary/os-patches.git#branch=epiphany-browser-bionic-patched source = epiphany-sync source = epiphany-sync.service + source = block-webkit-filechooser.patch + source = add-preview-widget.patch sha256sums = SKIP sha256sums = cf90f3ea93fff8c61f82da40c8d07d5db2f33dc9a0d91408a6ffc4142bbedd20 sha256sums = ce1ac321d7bf9d88638634a141dfcb99119fc59ee44c4892e0874608e85006ba + sha256sums = deabdc2edc635d854ca40789cf949afdb51b9c598b01891390c238cc769524f7 + sha256sums = df1828b4fe05bd6aeb198db0c56c83c10d54eef27d7a9a6c63cbddc516d6221f pkgname = epiphany-pantheon @@ -3,7 +3,7 @@ pkgname=epiphany-pantheon pkgver=3.28.0.1+1ubuntu1+r21.dbc305d50 -pkgrel=2 +pkgrel=3 pkgdesc="GNOME web browser based on the WebKit rendering engine (with elementary OS patches)" url="https://gitlab.gnome.org/GNOME/epiphany/" arch=('i686' 'x86_64') @@ -16,10 +16,14 @@ replaces=(epiphany-pantheon-bzr) provides=(epiphany="${pkgver}" epiphany-sync) conflicts=(epiphany) source=("git+https://github.com/elementary/os-patches.git#branch=epiphany-browser-bionic-patched" - epiphany-sync{,.service}) + epiphany-sync{,.service} + "block-webkit-filechooser.patch" + "add-preview-widget.patch") sha256sums=('SKIP' 'cf90f3ea93fff8c61f82da40c8d07d5db2f33dc9a0d91408a6ffc4142bbedd20' - 'ce1ac321d7bf9d88638634a141dfcb99119fc59ee44c4892e0874608e85006ba') + 'ce1ac321d7bf9d88638634a141dfcb99119fc59ee44c4892e0874608e85006ba' + 'deabdc2edc635d854ca40789cf949afdb51b9c598b01891390c238cc769524f7' + 'df1828b4fe05bd6aeb198db0c56c83c10d54eef27d7a9a6c63cbddc516d6221f') pkgver() { cd "os-patches" @@ -27,6 +31,12 @@ pkgver() { printf "3.28.0.1+1ubuntu1+r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" } +prepare () { + cd "os-patches" + patch -Np2 < ../block-webkit-filechooser.patch + patch -Np2 < ../add-preview-widget.patch +} + build() { cd "os-patches" [ -d build ] && rm -rf build 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 diff --git a/block-webkit-filechooser.patch b/block-webkit-filechooser.patch new file mode 100644 index 000000000000..8c2a98df31a2 --- /dev/null +++ b/block-webkit-filechooser.patch @@ -0,0 +1,87 @@ +--- src/os-patches/embed/ephy-web-view.c~ 2018-10-13 04:25:04.320563918 +0900 ++++ src/os-patches/embed/ephy-web-view.c 2018-10-14 15:48:39.428728086 +0900 +@@ -31,6 +31,7 @@ + #include "ephy-embed-utils.h" + #include "ephy-embed.h" + #include "ephy-favicon-helpers.h" ++#include "ephy-file-chooser.h" + #include "ephy-file-helpers.h" + #include "ephy-file-monitor.h" + #include "ephy-gsb-utils.h" +@@ -293,6 +294,58 @@ + } + + static void ++open_response_cb (GtkFileChooser* dialog, gint response, WebKitFileChooserRequest* request) ++{ ++ if (response == GTK_RESPONSE_ACCEPT) { ++ GSList *filesList = gtk_file_chooser_get_filenames (dialog); ++ GPtrArray *filesArray = g_ptr_array_new (); ++ for (GSList *file = filesList; file; file = g_slist_next (file)) ++ g_ptr_array_add (filesArray, file->data); ++ g_ptr_array_add (filesArray, 0); ++ webkit_file_chooser_request_select_files (request, (const gchar * const *)filesArray->pdata); ++ g_slist_free (filesList); ++ g_ptr_array_free (filesArray, FALSE); ++ } else { ++ webkit_file_chooser_request_cancel (request); ++ } ++ ++ g_object_unref (request); ++ ++ g_object_unref (dialog); ++} ++ ++static gboolean ++ephy_web_view_run_file_chooser (WebKitWebView *web_view, ++ WebKitFileChooserRequest *request) ++{ ++ ++ GtkWidget* toplevel = gtk_widget_get_toplevel(GTK_WIDGET(web_view)); ++ ++ GtkFileChooser *dialog; ++ ++ dialog = ephy_create_file_chooser (_("Open"), ++ GTK_WIDGET (toplevel), ++ GTK_FILE_CHOOSER_ACTION_OPEN, ++ EPHY_FILE_FILTER_ALL_SUPPORTED); ++ ++ gboolean allowsMultipleSelection = webkit_file_chooser_request_get_select_multiple(request); ++ ++ GtkFileFilter* filter = webkit_file_chooser_request_get_mime_types_filter(request); ++ ++ if (filter) ++ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); ++ ++ gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), allowsMultipleSelection); ++ ++ g_signal_connect (dialog, "response", ++ G_CALLBACK (open_response_cb), g_object_ref(request)); ++ ++ gtk_native_dialog_show (GTK_NATIVE_DIALOG (dialog)); ++ ++ return TRUE; ++} ++ ++static void + ephy_web_view_set_popups_allowed (EphyWebView *view, + gboolean allowed) + { +@@ -1057,7 +1104,8 @@ + ephy_web_view_class_init (EphyWebViewClass *klass) + { + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); ++ WebKitWebViewClass *webkit_webview_class = WEBKIT_WEB_VIEW_CLASS (klass); + + gobject_class->dispose = ephy_web_view_dispose; + gobject_class->finalize = ephy_web_view_finalize; +@@ -1068,6 +1116,8 @@ + widget_class->button_press_event = ephy_web_view_button_press_event; + widget_class->key_press_event = ephy_web_view_key_press_event; + ++ webkit_webview_class->run_file_chooser = ephy_web_view_run_file_chooser; ++ + /** + * EphyWebView:address: + * |