[epiphany/webkit2: 9/17] Port printing to WebKit2



commit 464748ca598ddff3619d8774259996ad15a9413d
Author: Carlos Garcia Campos <cgarcia igalia com>
Date:   Wed May 30 17:18:19 2012 +0200

    Port printing to WebKit2

 embed/ephy-web-view.c |   79 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 60 insertions(+), 19 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index ee7b91e..81672af 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -3767,11 +3767,30 @@ ephy_web_view_get_security_level (EphyWebView *view,
 }
 
 static void
+ephy_web_view_print_failed (EphyWebView *view, GError *error)
+{
+  GtkWidget *info_bar;
+  GtkWidget *label;
+  GtkContainer *content_area;
+  EphyEmbed *embed = EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view);
+
+  info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
+  label = gtk_label_new (error->message);
+  content_area = GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar)));
+
+  gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
+  gtk_container_add (content_area, label);
+  g_signal_connect (info_bar, "response",
+                    G_CALLBACK (gtk_widget_destroy), NULL);
+
+  ephy_embed_add_top_widget (embed, info_bar, FALSE);
+  gtk_widget_show_all (info_bar);
+}
+
+#ifndef HAVE_WEBKIT2
+static void
 ephy_web_view_run_print_action (EphyWebView *view, GtkPrintOperationAction action)
 {
-#ifdef HAVE_WEBKIT2
-  /* TODO: Printing */
-#else
   WebKitWebFrame *main_frame;
   GtkPrintOperation *operation;
   GError *error;
@@ -3788,30 +3807,34 @@ ephy_web_view_run_print_action (EphyWebView *view, GtkPrintOperationAction actio
   webkit_web_frame_print_full (main_frame, operation, action, &error);
 
   if (error) {
-    GtkWidget *info_bar;
-    GtkWidget *label;
-    GtkContainer *content_area;
-    EphyEmbed *embed = EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW (view);
-
-    info_bar = gtk_info_bar_new_with_buttons (GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
-    label = gtk_label_new (error->message);
-    content_area = GTK_CONTAINER (gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar)));
+    ephy_web_view_print_failed (view, error);
     g_error_free (error);
-
-    gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_ERROR);
-    gtk_container_add (content_area, label);
-    g_signal_connect (info_bar, "response",
-                      G_CALLBACK (gtk_widget_destroy), NULL);
-
-    ephy_embed_add_top_widget (embed, info_bar, FALSE);
-    gtk_widget_show_all (info_bar);
   } else
     ephy_embed_shell_set_page_setup (shell, gtk_print_operation_get_default_page_setup (operation));
 
   g_object_unref (operation);
+}
 #endif
+
+#ifdef HAVE_WEBKIT2
+static void
+print_operation_finished_cb (WebKitPrintOperation *operation,
+                             EphyWebView *view)
+{
+  ephy_embed_shell_set_page_setup (ephy_embed_shell_get_default (),
+                                   webkit_print_operation_get_page_setup (operation));
 }
 
+static void
+print_operation_failed_cb (WebKitPrintOperation *operation,
+                           GError *error,
+                           EphyWebView *view)
+{
+  g_signal_handlers_disconnect_by_func (operation, print_operation_finished_cb, view);
+  ephy_web_view_print_failed (view, error);
+}
+#endif
+
 /**
  * ephy_web_view_print:
  * @view: an #EphyWebView
@@ -3823,7 +3846,25 @@ ephy_web_view_run_print_action (EphyWebView *view, GtkPrintOperationAction actio
 void
 ephy_web_view_print (EphyWebView *view)
 {
+#ifdef HAVE_WEBKIT2
+  WebKitPrintOperation *operation;
+  EphyEmbedShell *shell;
+
+  shell = ephy_embed_shell_get_default ();
+
+  operation = webkit_print_operation_new (WEBKIT_WEB_VIEW (view));
+  g_signal_connect (operation, "finished",
+                    G_CALLBACK (print_operation_finished_cb),
+                    view);
+  g_signal_connect (operation, "failed",
+                    G_CALLBACK (print_operation_failed_cb),
+                    view);
+  webkit_print_operation_set_page_setup (operation, ephy_embed_shell_get_page_setup (shell));
+  webkit_print_operation_run_dialog (operation, NULL);
+  g_object_unref (operation);
+#else
   ephy_web_view_run_print_action (view, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
+#endif
 }
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]