webkitpdf.vala
[app.webkitpdf] / webkitpdf.vala
1
2 //valac --vapidir=./vapi --pkg gtk+-3.0 --pkg webkit2gtk-3.0 --pkg libsoup-2.4 webkitpdf.vala BrowserWindow -o /usr/bin/wksnapshot
3  
4 public class webkitpdf {
5  
6     public static string? opt_url = null;
7         public static uint opt_delay = 0;
8         public static string opt_target_png = null;
9         public static string opt_target_pdf = null;     
10         public static string[] opt_inject_js = null;            
11         const OptionEntry[] options = {
12                 
13                         
14                         { "url", 0, 0, OptionArg.STRING, ref opt_url, "Url to grab", null },
15                         { "delay", 0, 0, OptionArg.INT, ref opt_delay, "Delay before snapshot in seconds", null },
16                         //{ "png", 0, 0, OptionArg.STRING, ref opt_target_png, "File to write (PNG)", null },
17                         { "inject", 0, 0, OptionArg.STRING, ref opt_inject_js, "Inject Javascript", null },
18                         { "pdf", 0, 0, OptionArg.STRING, ref opt_target_pdf, "File to write (PDF)", null },
19                         { null }
20         };
21     public static int main(string[] args) {
22         Gtk.init(ref args);
23  
24  
25         var opt_context = new OptionContext ("webkitpdf");
26                 
27                 
28                 try {
29                         opt_context.set_help_enabled (true);
30                         opt_context.add_main_entries (options, null);
31                         opt_context.parse (ref args);
32                         
33             if (webkitpdf.opt_url == null) {
34                 throw new OptionError.BAD_VALUE("missing url");
35             }
36                         //if (webkitpdf.opt_target_png == null) {
37             //    throw new OptionError.BAD_VALUE("missing png"  file path);
38             //}
39             if (webkitpdf.opt_target_pdf == null) {
40                 throw new OptionError.BAD_VALUE("missing pdf file path");
41             }
42             
43                 } catch (OptionError e) {
44                         stdout.printf ("error: %s\n", e.message);
45                         stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s", 
46                                          args[0], opt_context.get_help(true,null));
47                         return 0;
48                 }
49  
50  
51         var browser = new BrowserWindow();
52         browser.el.show_all();
53  
54         Gtk.main();
55  
56         return 0;
57     }
58 }
59
60
61