From e6f0542071874fdc4d041e9f2161e0f0bac2ecf4 Mon Sep 17 00:00:00 2001 From: dusanx Date: Mon, 27 Apr 2009 22:57:38 +0200 Subject: Uri check -- append http:// if needed --- uzbl.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'uzbl.c') diff --git a/uzbl.c b/uzbl.c index 3528bf4..da73bfe 100644 --- a/uzbl.c +++ b/uzbl.c @@ -214,9 +214,20 @@ static Command commands[] = /* -- CORE FUNCTIONS -- */ +static gchar* +uricheck (gchar* uri) { + if (g_strrstr (uri,"://") == NULL) { + GString* newuri = g_string_new (uri); + free(uri); + g_string_prepend (newuri, "http://"); + uri = g_string_free (newuri, FALSE); + } + return (uri); +} + + static bool -file_exists (const char * filename) -{ +file_exists (const char * filename) { FILE *file = fopen (filename, "r"); if (file) { fclose (file); @@ -260,7 +271,7 @@ parse_command(const char *cmd) { if (c->func_2_params != NULL) { if (command_param != NULL) { printf ("command executing: \"%s %s\"\n", command_name, command_param); - c->func_2_params (web_view, command_param); + c->func_2_params (web_view, uricheck(command_param)); } else { if (c->func_1_param != NULL) { printf ("command executing: \"%s\"\n", command_name); @@ -605,7 +616,7 @@ main (int argc, char* argv[]) { main_window = create_window (); gtk_container_add (GTK_CONTAINER (main_window), vbox); - webkit_web_view_load_uri (web_view, uri); + webkit_web_view_load_uri (web_view, uricheck(uri)); gtk_widget_grab_focus (GTK_WIDGET (web_view)); gtk_widget_show_all (main_window); -- cgit v1.2.3 From 5d0a67929ce39365c9b7a46250c88af511e43c2f Mon Sep 17 00:00:00 2001 From: dusanx Date: Tue, 28 Apr 2009 01:00:44 +0200 Subject: Proper uri handling, fixed segfault --- uzbl.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) (limited to 'uzbl.c') diff --git a/uzbl.c b/uzbl.c index 1b4cd8b..309ff6a 100644 --- a/uzbl.c +++ b/uzbl.c @@ -108,7 +108,7 @@ static void update_title (GtkWindow* window); static void -load_uri ( WebKitWebView * web_view, gchar * uri); +load_uri ( WebKitWebView * web_view, const gchar * uri); static gboolean run_command(const char *command, const char *args); @@ -217,18 +217,6 @@ static Command commands[] = /* -- CORE FUNCTIONS -- */ -static gchar* -uricheck (gchar* uri) { - if (g_strrstr (uri,"://") == NULL) { - GString* newuri = g_string_new (uri); - free(uri); - g_string_prepend (newuri, "http://"); - uri = g_string_free (newuri, FALSE); - } - return (uri); -} - - static bool file_exists (const char * filename) { FILE *file = fopen (filename, "r"); @@ -240,8 +228,14 @@ file_exists (const char * filename) { } static void -load_uri ( WebKitWebView * web_view, gchar * uri) { - webkit_web_view_load_uri (web_view, uricheck(uri)); +load_uri (WebKitWebView * web_view, const gchar * uri) { + if (uri != NULL) { + GString* newuri = g_string_new (uri); + if (g_strrstr (uri, "://") == NULL) + g_string_prepend (newuri, "http://"); + webkit_web_view_load_uri (web_view, newuri->str); + g_string_free (newuri, TRUE); + } } @@ -280,7 +274,7 @@ parse_command(const char *cmd) { if (c->func_2_params != NULL) { if (command_param != NULL) { printf ("command executing: \"%s %s\"\n", command_name, command_param); - c->func_2_params (web_view, uricheck(command_param)); + c->func_2_params (web_view, command_param); } else { if (c->func_1_param != NULL) { printf ("command executing: \"%s\"\n", command_name); @@ -625,7 +619,7 @@ main (int argc, char* argv[]) { main_window = create_window (); gtk_container_add (GTK_CONTAINER (main_window), vbox); - webkit_web_view_load_uri (web_view, uricheck(uri)); + load_uri (web_view, uri); gtk_widget_grab_focus (GTK_WIDGET (web_view)); gtk_widget_show_all (main_window); -- cgit v1.2.3 From 3e42283eb5eb296ecac9b9219cdc728e92b3c287 Mon Sep 17 00:00:00 2001 From: dusanx Date: Tue, 28 Apr 2009 02:35:24 +0200 Subject: Download and open in new window --- CHECKLIST | 2 ++ uzbl.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) (limited to 'uzbl.c') diff --git a/CHECKLIST b/CHECKLIST index 454ccaa..790fe69 100644 --- a/CHECKLIST +++ b/CHECKLIST @@ -15,6 +15,8 @@ Also testers and interested people can use this list to see what uzbl is about, all should be valid strings and contain things like the pid, fifo file, config file,.. (see README for details). * XDG_CONFIG_HOME and XDG_CONFIG_DIRS (+ default values) fully supported and working (looks for a config file called 'uzbl'). * --uri can be specified without http:// -- if missing will be prepended. +* Download completely finished +* Open in new window partially finished: target _new works, from popup meny does not work yet TODO: add stuff about internal/external keybinds, mod key, insert mode, status bar, behavior settings,.... diff --git a/uzbl.c b/uzbl.c index 309ff6a..f76642c 100644 --- a/uzbl.c +++ b/uzbl.c @@ -115,6 +115,28 @@ run_command(const char *command, const char *args); /* --- CALLBACKS --- */ +static gboolean +new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data) { + (void) web_view; + (void) frame; + (void) navigation_action; + (void) policy_decision; + (void) user_data; + const gchar* uri = webkit_network_request_get_uri (request); + printf("New window requested -> %s \n", uri); + return (FALSE); +} + +static gboolean +download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data) { + (void) web_view; + (void) user_data; + const gchar* uri = webkit_download_get_uri ((WebKitDownload*)download); + printf("Download -> %s\n",uri); + run_command(download_handler, uri); + return (FALSE); +} + static void go_back_cb (WebKitWebView* page) { (void) page; @@ -419,6 +441,8 @@ create_browser () { g_signal_connect (G_OBJECT (web_view), "load-committed", G_CALLBACK (log_history_cb), web_view); g_signal_connect (G_OBJECT (web_view), "hovering-over-link", G_CALLBACK (link_hover_cb), web_view); g_signal_connect (G_OBJECT (web_view), "key-press-event", G_CALLBACK (key_press_cb), web_view); + g_signal_connect (G_OBJECT (web_view), "new-window-policy-decision-requested", G_CALLBACK (new_window_cb), web_view); + g_signal_connect (G_OBJECT (web_view), "download-requested", G_CALLBACK (download_cb), web_view); return scrolled_window; } -- cgit v1.2.3