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         const OptionEntry[] options = {
11                 
12                         
13                         { "url", 0, 0, OptionArg.STRING, ref opt_url, "Url to grab", null },
14                         { "delay", 0, 0, OptionArg.INT, ref opt_delay, "Delay before snapshot in seconds", null },
15                         //{ "png", 0, 0, OptionArg.STRING, ref opt_target_png, "File to write (PNG)", null },
16                         { "pdf", 0, 0, OptionArg.STRING, ref opt_target_pdf, "File to write (PDF)", null },
17                         { null }
18         };
19     public static int main(string[] args) {
20         Gtk.init(ref args);
21  
22  
23         var opt_context = new OptionContext ("webkitpdf");
24                 
25                 
26                 try {
27                         opt_context.set_help_enabled (true);
28                         opt_context.add_main_entries (options, null);
29                         opt_context.parse (ref args);
30                         
31             if (webkitpdf.opt_url == null) {
32                 throw new OptionError.BAD_VALUE("missing url");
33             }
34                         //if (webkitpdf.opt_target_png == null) {
35             //    throw new OptionError.BAD_VALUE("missing png"  file path);
36             //}
37             if (webkitpdf.opt_target_pdf == null) {
38                 throw new OptionError.BAD_VALUE("missing pdf file path");
39             }
40             
41                 } catch (OptionError e) {
42                         stdout.printf ("error: %s\n", e.message);
43                         stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s", 
44                                          args[0], opt_context.get_help(true,null));
45                         return 0;
46                 }
47  
48  
49         var browser = new BrowserWindow();
50         browser.el.show_all();
51  
52         Gtk.main();
53  
54         return 0;
55     }
56 }
57
58
59