BrowserWindow.bjs
[app.webkitpdf] / BrowserWindow.vala
index 438524e..b1dc3b9 100644 (file)
@@ -48,6 +48,7 @@ public class BrowserWindow : Object
                // if we have not finished in 25 seconds
                // call printit...
                  GLib.Timeout.add_seconds(25, () => { 
+                       print("Calling printit - timeout 25 seconds");
                                _this.view.printit();
                                return true;
                });
@@ -122,26 +123,18 @@ public class BrowserWindow : Object
             
             #else
              //listeners
-                        this.el.resource_request_starting.connect( (p0, webres, netreq ) => {
-                          print("resource req. started %s\n", netreq.uri);
+                      //  this.el.resource_request_starting.connect( (p0, webres, netreq ) => {
+                        //  print("resource req. started %s\n", netreq.uri);
                              
-                        });
+                      //  });
                         
                         this.el.load_finished.connect( ( ) => {
                                         
                                this.printit(); 
                          
                         });
-                        
             #endif
             }
-
-            //listeners
-            this.el.load_finished.connect( ( ) => {
-                        
-                   this.printit(); 
-             
-            });
         }
 
         // user defined functions
@@ -171,7 +164,7 @@ public class BrowserWindow : Object
                                }
         #if GTK3
                                GLib.MainLoop mainloop = new GLib.MainLoop();
-                               this.el.run_javascript.begin(str, (obj,res) => {
+                               this.el.run_javascript.begin(str, null, (obj,res) => {
                                        mainloop.quit();
                                });
                                mainloop.run();
@@ -194,6 +187,11 @@ public class BrowserWindow : Object
                        return;
                }
                        
+        
+        #if GTK3
+               print("PNG not supported in webkit2\n");
+               return;
+        #else
                        
             GLib.Timeout.add_seconds(webkitpdf.opt_delay, () => { 
            
@@ -220,7 +218,7 @@ public class BrowserWindow : Object
                  }, GLib.Priority.DEFAULT);
         
         
-            
+        #endif    
             
         }
         public bool printpdf () {
@@ -241,8 +239,23 @@ public class BrowserWindow : Object
         
                        var  pe = new  WebKit.PrintOperation(this.el);
                        pe.set_page_setup(psetup);
+                       pe.finished.connect( () => {
+                               print("print completed\n");
+                                Gtk.main_quit();
+                       
+                       });
                        
+                       var ps = new Gtk.PrintSettings();
+                   ps.set_printer("Print to File");
+                   ps.set("output-file-format", "pdf");
+                   ps.set("output-uri", "file://" + webkitpdf.opt_target_pdf);
+        
                        
+                       pe.set_print_settings(ps);
+                       
+        
+                       pe.print();
+                                 
         
         #else      
                        var  pe = new  Gtk.PrintOperation();
@@ -273,7 +286,7 @@ public class BrowserWindow : Object
                    
                    
         
-                       this.el.print(pe);
+                       this.el.get_main_frame().print(pe);
         
         
                    try {
@@ -297,7 +310,9 @@ public class BrowserWindow : Object
         // what size is the documet.
         
              print("making screenshot\n");
-             
+        #if GTK3
+        
+        #else     
             // fix vapi - get_snapshot add '?' to all null.
             var pixmap = _this.view.el.get_snapshot( null );
         
@@ -321,7 +336,7 @@ public class BrowserWindow : Object
             //});
             Gtk.main_quit();
              
-           
+        #endif