X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=webkitpdf.vala;h=e9ececc9b354aab9e93d7ee452e595dbdb5093b3;hb=fafb40436ce8bf70e89ac698954dab9559a6f58d;hp=eee1ed1d1192f61504fe065ac806490f71a166b8;hpb=19fe300b5cc0ad0971bf92af5c22828f2d76793d;p=app.webkitpdf diff --git a/webkitpdf.vala b/webkitpdf.vala index eee1ed1..e9ececc 100644 --- a/webkitpdf.vala +++ b/webkitpdf.vala @@ -1,48 +1,116 @@ -//valac --vapidir=./vapi --pkg gtk+-3.0 --pkg webkit2gtk-3.0 --pkg libsoup-2.4 webkitpdf.vala BrowserWindow -o /usr/bin/wksnapshot - +/* + sudo valac --vapidir=. --thread webkitpdf.vala BrowserWindow.vala --vapidir=./vapi \ + --pkg glib-2.0 --pkg webkit-1.0 --pkg gtk+-2.0 -o /usr/bin/webkitpdf --target-glib=2.32 + + sudo valac -D GTK3 --vapidir=. --thread webkitpdf.vala BrowserWindow.vala --vapidir=./vapi \ + --pkg glib-2.0 --pkg webkit2gtk-4.0 --pkg gtk+-3.0 --pkg gio-2.0 -o /usr/bin/webkitpdf2 --target-glib=2.32 + + + +*/ public class webkitpdf { public static string? opt_url = null; public static uint opt_delay = 0; - public static string opt_target_png = null; + public static int opt_width = 0; + public static int opt_height = 0; + public static string? opt_target_png = null; + public static string? opt_target_pdf = null; + [CCode (array_length = false, array_null_terminated = true)] + public static string[] opt_inject_js; + public static string? opt_cookies = null; + const OptionEntry[] options = { - + { "width", 0, 0, OptionArg.INT, ref opt_width, "Width (default 1200)", null }, + { "height", 0, 0, OptionArg.INT, ref opt_height, "Height (PNG only) (default to expand to fit)", null }, { "url", 0, 0, OptionArg.STRING, ref opt_url, "Url to grab", null }, { "delay", 0, 0, OptionArg.INT, ref opt_delay, "Delay before snapshot in seconds", null }, { "png", 0, 0, OptionArg.STRING, ref opt_target_png, "File to write (PNG)", null }, + { "inject", 0, 0, OptionArg.STRING_ARRAY, ref opt_inject_js, "Inject Javascript file(s)", null }, + { "pdf", 0, 0, OptionArg.STRING, ref opt_target_pdf, "File to write (PDF)", null }, + { "cookies", 0, 0, OptionArg.STRING, ref opt_cookies, "Inject Cookie string", null }, { null } - }; - public static int main(string[] args) { + }; + public static int main(string[] args) + { Gtk.init(ref args); - - - var opt_context = new OptionContext ("webkitpdf"); +#if GTK3 + // this is a horrific hack from https://bugs.webkit.org/show_bug.cgi?id=128674 + Environment.unset_variable("GNOME_DESKTOP_SESSION_ID"); + Environment.unset_variable("DESKTOP_SESSION"); + // it should now fallb ack to http prox!? + + +#else + unowned string proxy = Environment.get_variable ("http_proxy"); + if (proxy != null && proxy.length > 0) { + var sess = WebKit.get_default_session(); + sess.proxy_uri = new Soup.URI(proxy); + } +#endif + var opt_context = new OptionContext ("webkitpdf"); + + try { opt_context.set_help_enabled (true); opt_context.add_main_entries (options, null); opt_context.parse (ref args); - if (Browser.opt_url == null) { + if (webkitpdf.opt_url == null) { throw new OptionError.BAD_VALUE("missing url"); } - if (Browser.opt_target_png == null) { - throw new OptionError.BAD_VALUE("missing png"); + if (webkitpdf.opt_target_png == null && webkitpdf.opt_target_pdf == null) { + throw new OptionError.BAD_VALUE("missing pdf or png filename"); } + + stdout.printf ( """Width: %d + Height: %d + URL: %s + Delay: %d + png: %s + inject: %s + PDF: %s + Cookie: %s + """, + opt_width, + opt_height, + opt_url, + (int) opt_delay, + opt_target_png == null ? "--empty--" : opt_target_png, + opt_inject_js.length < 1? "--empty--" : string.joinv(", ", opt_inject_js), + opt_target_pdf == null ? "--empty--" : opt_target_pdf, + opt_cookies == null ? "--empty--" : opt_cookies + + + ); + + } catch (OptionError e) { stdout.printf ("error: %s\n", e.message); stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s", args[0], opt_context.get_help(true,null)); return 0; } - - - var browser = new Browser(); - browser.show_all(); + + var browser = new BrowserWindow(); + browser.el.show_all(); + /* + var ses = WebKit.get_default_session(); + ses.request_queued.connect((msg) => { + print("queued request %s\n", msg.uri.to_string(false)); + msg.got_headers.connect(() => { + print("got conent type %s\n", msg.response_headers.get_content_type (null)); + if (msg.response_headers.get_content_type (null) == "image/jpeg") { + ses.cancel_message(msg,Soup.KnownStatusCode.CANCELLED); + } + }); + }); + */ Gtk.main(); @@ -51,4 +119,5 @@ public class webkitpdf { } + \ No newline at end of file