commit 5a29ec1740d96fb0515ba7418c6bd16375b17a0f
parent 421fce6ee3f290da26f97488eb7b75a7ecb3f88e
Author: Michael Rasmussen <mir@datanom.net>
Date: Mon, 5 Nov 2018 17:13:50 +0100
Migrate fancy to GTK3 and fix fancy_print
Signed-off-by: Michael Rasmussen <mir@datanom.net>
Diffstat:
4 files changed, 47 insertions(+), 39 deletions(-)
diff --git a/configure.ac b/configure.ac
@@ -1156,7 +1156,7 @@ AC_SUBST(EXPAT_CFLAGS)
AC_SUBST(EXPAT_LIBS)
dnl webkit *********************************************************************
-PKG_CHECK_MODULES(WEBKIT, webkit-1.0 >= 1.10.0, HAVE_WEBKIT=yes, HAVE_WEBKIT=no)
+PKG_CHECK_MODULES(WEBKIT, webkit2gtk-4.0 >= 2.18.0, HAVE_WEBKIT=yes, HAVE_WEBKIT=no)
AC_SUBST(WEBKIT_LIBS)
AC_SUBST(WEBKIT_CFLAGS)
@@ -1517,7 +1517,7 @@ if test x"$enable_fancy_plugin" != xno; then
dependencies_missing=""
if test x"$HAVE_WEBKIT" = xno; then
- dependencies_missing="libwebkit-1.0 $dependencies_missing"
+ dependencies_missing="libwebkit2gtk-4.0 $dependencies_missing"
fi
if test x"$HAVE_CURL" = xno; then
dependencies_missing="libcurl $dependencies_missing"
diff --git a/src/plugins/fancy/fancy_prefs.h b/src/plugins/fancy/fancy_prefs.h
@@ -21,12 +21,12 @@
#define FANCY_PREFS_H
#include <glib.h>
-#include <webkit/webkitwebsettings.h>
+#include <webkit2/webkit2.h>
typedef struct _FancyPrefs FancyPrefs;
struct _FancyPrefs
{
- WebKitWebSettings *web_settings;
+ WebKitSettings *web_settings;
gboolean enable_images;
gboolean enable_remote_content;
diff --git a/src/plugins/fancy/fancy_viewer.c b/src/plugins/fancy/fancy_viewer.c
@@ -31,7 +31,6 @@
#include <file-utils.h>
#include <printing.h>
-#include <webkit/webkithittestresult.h>
static void
load_start_cb (WebKitWebView *view, gint progress, FancyViewer *viewer);
@@ -263,10 +262,8 @@ static gboolean fancy_set_contents(FancyViewer *viewer, gboolean use_defaults)
}
contents = file_read_to_str_no_recode(viewer->filename);
- webkit_web_view_load_string(viewer->view,
+ webkit_web_view_load_html(viewer->view,
contents,
- "text/html",
- charset,
NULL);
g_free(contents);
}
@@ -301,38 +298,54 @@ static void fancy_show_mimepart(MimeViewer *_viewer, const gchar *infile,
g_timeout_add(5, (GSourceFunc)fancy_show_mimepart_prepare, viewer);
}
+static void fancy_print_fail_cb(WebKitPrintOperation *print_operation,
+ GError *error,
+ gpointer user_data) {
+ /* avoid warning for unused variable
+ FancyViewer *viewer = (FancyViewer *) user_data;
+ */
+
+ debug_print("Error printing message: %s\n",
+ error ? error->message : "no details");
+}
+
static void fancy_print(MimeViewer *_viewer)
{
FancyViewer *viewer = (FancyViewer *) _viewer;
- GtkPrintOperationResult res;
- GError *error = NULL;
- GtkPrintOperation *op;
+ WebKitPrintOperationResponse res;
+ WebKitPrintOperation *printoperation;
+ GtkPrintSettings *printsettings;
+ GtkPageSetup *pagesetup;
gtk_widget_realize(GTK_WIDGET(viewer->view));
while (viewer->loading)
claws_do_idle();
- op = gtk_print_operation_new();
-
- /* Config for printing */
- gtk_print_operation_set_print_settings(op, printing_get_settings());
- gtk_print_operation_set_default_page_setup(op, printing_get_page_setup());
- /* enable Page Size and Orientation in the print dialog */
- gtk_print_operation_set_embed_page_setup(op, TRUE);
-
- /* Start printing process */
- res = webkit_web_frame_print_full(webkit_web_view_get_main_frame(viewer->view),
- op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
- &error);
-
- if (res == GTK_PRINT_OPERATION_RESULT_ERROR) {
- gtk_print_operation_get_error(op, &error);
- debug_print("Error printing message: %s\n",
- error ? error->message : "no details");
- } else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
- /* store settings for next printing session */
- printing_store_settings(gtk_print_operation_get_print_settings(op));
+ printoperation = webkit_print_operation_new(viewer->view);
+ g_signal_connect(G_OBJECT(printoperation), "failed",
+ G_CALLBACK(fancy_print_fail_cb), viewer);
+
+ printsettings = webkit_print_operation_get_print_settings(printoperation);
+ if (!printsettings) {
+ printsettings = printing_get_settings();
+ webkit_print_operation_set_print_settings(printoperation, printsettings);
+ }
+ pagesetup = webkit_print_operation_get_page_setup(printoperation);
+ if (!pagesetup) {
+ pagesetup = printing_get_page_setup();
+ webkit_print_operation_set_page_setup(printoperation, pagesetup);
+ }
+
+ MainWindow *mainwin = mainwindow_get_mainwindow();
+ res = webkit_print_operation_run_dialog(
+ printoperation,
+ mainwin ? GTK_WINDOW(mainwin->window):NULL);
+
+ if (res == WEBKIT_PRINT_OPERATION_RESPONSE_PRINT) {
+ // store settings for next printing session
+ printing_store_settings(
+ webkit_print_operation_get_print_settings(printoperation));
}
}
diff --git a/src/plugins/fancy/fancy_viewer.h b/src/plugins/fancy/fancy_viewer.h
@@ -29,13 +29,8 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <webkit/webkitwebview.h>
-#include <webkit/webkitversion.h>
-#include <webkit/webkitwebframe.h>
-#include <webkit/webkitnetworkrequest.h>
-#include <webkit/webkitwebnavigationaction.h>
-#include <webkit/webkitwebpolicydecision.h>
-#include <webkit/webkitglobals.h>
+#include <webkit2/webkit2.h>
+#include <webkitdom/webkitdom.h>
#include <prefs_common.h>
#include "common/claws.h"
#include "common/version.h"
@@ -97,7 +92,7 @@ struct _FancyViewer
GtkWidget *stylesheet;
GtkWidget *progress;
- WebKitWebSettings *settings;
+ WebKitSettings *settings;
gboolean printing;
gboolean override_prefs_images;
gboolean override_prefs_remote_content;