Migrate fancy to GTK3 and fix fancy_print
authorMichael Rasmussen <mir@datanom.net>
Mon, 5 Nov 2018 16:13:50 +0000 (17:13 +0100)
committerMichael Rasmussen <mir@datanom.net>
Mon, 5 Nov 2018 16:13:50 +0000 (17:13 +0100)
Signed-off-by: Michael Rasmussen <mir@datanom.net>
configure.ac
src/plugins/fancy/fancy_prefs.h
src/plugins/fancy/fancy_viewer.c
src/plugins/fancy/fancy_viewer.h

index b5e956bc616a3e483260466db08e6f97aaa319c9..c2836731c4eb2a33e5a30421589b531bbdb869fc 100644 (file)
@@ -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)
 
@@ -1511,7 +1511,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"
index 2c95e8c7621ca8759d39b598c305fee6a8a4bfab..fcb840857bef9ae584b39c5c8e8579cd925ab38f 100644 (file)
 #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;
index 3792e846bbc767a298e03fc1e5c27cf9095a5c3d..235a21e7f76e2baf9d7b6ccbb2bab2438176d267 100644 (file)
@@ -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));
        }
 }
 
index c22ca401403d99f81ecd3e38bea917cabaf27db9..30d49077587eb3384edd75fe5d1221c71134a19f 100644 (file)
 #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;