diff options
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | callbacks.c | 594 | ||||
-rw-r--r-- | callbacks.h | 189 | ||||
-rw-r--r-- | events.c (renamed from uzbl-events.c) | 2 | ||||
-rw-r--r-- | events.h (renamed from uzbl-events.h) | 0 | ||||
-rw-r--r-- | uzbl-core.c | 592 | ||||
-rw-r--r-- | uzbl-core.h | 172 |
7 files changed, 800 insertions, 758 deletions
@@ -6,7 +6,7 @@ CFLAGS!=echo -std=c99 `pkg-config --cflags gtk+-2.0 webkit-1.0 libsoup-2.4 gthre LDFLAGS:=$(shell pkg-config --libs gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0) -pthread $(LDFLAGS) LDFLAGS!=echo `pkg-config --libs gtk+-2.0 webkit-1.0 libsoup-2.4 gthread-2.0` -pthread $(LDFLAGS) -SRC = uzbl-core.c uzbl-events.c +SRC = uzbl-core.c events.c callbacks.c OBJ = ${SRC:.c=.o} all: uzbl-browser options @@ -20,10 +20,10 @@ options: @echo Compiling $< @${CC} -c ${CFLAGS} $< -${OBJ}: uzbl-core.h uzbl-events.h config.h +${OBJ}: uzbl-core.h events.h callbacks.h config.h uzbl-core: ${OBJ} - @echo Linking $< + @echo Linking object files @${CC} -o $@ ${OBJ} ${LDFLAGS} @@ -60,7 +60,8 @@ test-share-browser: uzbl-browser clean: rm -f uzbl-core rm -f uzbl-core.o - rm -f uzbl-events.o + rm -f events.o + rm -f callbacks.o cd ./tests/; $(MAKE) clean install: all diff --git a/callbacks.c b/callbacks.c new file mode 100644 index 0000000..e55d15b --- /dev/null +++ b/callbacks.c @@ -0,0 +1,594 @@ +/* + ** Callbacks + ** + ** (c) 2009 by Robert Manea et al. +*/ + +#include "uzbl-core.h" +#include "callbacks.h" +#include "events.h" + + +void +set_proxy_url() { + SoupURI *suri; + + if(uzbl.net.proxy_url == NULL || *uzbl.net.proxy_url == ' ') { + soup_session_remove_feature_by_type(uzbl.net.soup_session, + (GType) SOUP_SESSION_PROXY_URI); + } + else { + suri = soup_uri_new(uzbl.net.proxy_url); + g_object_set(G_OBJECT(uzbl.net.soup_session), + SOUP_SESSION_PROXY_URI, + suri, NULL); + soup_uri_free(suri); + } + return; +} + +void +set_icon() { + if(file_exists(uzbl.gui.icon)) { + if (uzbl.gui.main_window) + gtk_window_set_icon_from_file (GTK_WINDOW (uzbl.gui.main_window), uzbl.gui.icon, NULL); + } else { + g_printerr ("Icon \"%s\" not found. ignoring.\n", uzbl.gui.icon); + } +} + +void +cmd_set_geometry() { + if(!gtk_window_parse_geometry(GTK_WINDOW(uzbl.gui.main_window), uzbl.gui.geometry)) { + if(uzbl.state.verbose) + printf("Error in geometry string: %s\n", uzbl.gui.geometry); + } + /* update geometry var with the actual geometry + this is necessary as some WMs don't seem to honour + the above setting and we don't want to end up with + wrong geometry information + */ + retrieve_geometry(); +} + +void +cmd_set_status() { + if (!uzbl.behave.show_status) { + gtk_widget_hide(uzbl.gui.mainbar); + } else { + gtk_widget_show(uzbl.gui.mainbar); + } + update_title(); +} + +void +cmd_load_uri() { + GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); + g_array_append_val (a, uzbl.state.uri); + load_uri(uzbl.gui.web_view, a, NULL); + g_array_free (a, TRUE); +} + +void +cmd_max_conns() { + g_object_set(G_OBJECT(uzbl.net.soup_session), + SOUP_SESSION_MAX_CONNS, uzbl.net.max_conns, NULL); +} + +void +cmd_max_conns_host() { + g_object_set(G_OBJECT(uzbl.net.soup_session), + SOUP_SESSION_MAX_CONNS_PER_HOST, uzbl.net.max_conns_host, NULL); +} + +void +cmd_http_debug() { + soup_session_remove_feature + (uzbl.net.soup_session, SOUP_SESSION_FEATURE(uzbl.net.soup_logger)); + /* do we leak if this doesn't get freed? why does it occasionally crash if freed? */ + /*g_free(uzbl.net.soup_logger);*/ + + uzbl.net.soup_logger = soup_logger_new(uzbl.behave.http_debug, -1); + soup_session_add_feature(uzbl.net.soup_session, + SOUP_SESSION_FEATURE(uzbl.net.soup_logger)); +} + +WebKitWebSettings* +view_settings() { + return webkit_web_view_get_settings(uzbl.gui.web_view); +} + +void +cmd_font_size() { + WebKitWebSettings *ws = view_settings(); + if (uzbl.behave.font_size > 0) { + g_object_set (G_OBJECT(ws), "default-font-size", uzbl.behave.font_size, NULL); + } + + if (uzbl.behave.monospace_size > 0) { + g_object_set (G_OBJECT(ws), "default-monospace-font-size", + uzbl.behave.monospace_size, NULL); + } else { + g_object_set (G_OBJECT(ws), "default-monospace-font-size", + uzbl.behave.font_size, NULL); + } +} + +void +cmd_default_font_family() { + g_object_set (G_OBJECT(view_settings()), "default-font-family", + uzbl.behave.default_font_family, NULL); +} + +void +cmd_monospace_font_family() { + g_object_set (G_OBJECT(view_settings()), "monospace-font-family", + uzbl.behave.monospace_font_family, NULL); +} + +void +cmd_sans_serif_font_family() { + g_object_set (G_OBJECT(view_settings()), "sans_serif-font-family", + uzbl.behave.sans_serif_font_family, NULL); +} + +void +cmd_serif_font_family() { + g_object_set (G_OBJECT(view_settings()), "serif-font-family", + uzbl.behave.serif_font_family, NULL); +} + +void +cmd_cursive_font_family() { + g_object_set (G_OBJECT(view_settings()), "cursive-font-family", + uzbl.behave.cursive_font_family, NULL); +} + +void +cmd_fantasy_font_family() { + g_object_set (G_OBJECT(view_settings()), "fantasy-font-family", + uzbl.behave.fantasy_font_family, NULL); +} + +void +cmd_zoom_level() { + webkit_web_view_set_zoom_level (uzbl.gui.web_view, uzbl.behave.zoom_level); +} + +void +cmd_disable_plugins() { + g_object_set (G_OBJECT(view_settings()), "enable-plugins", + !uzbl.behave.disable_plugins, NULL); +} + +void +cmd_disable_scripts() { + g_object_set (G_OBJECT(view_settings()), "enable-scripts", + !uzbl.behave.disable_scripts, NULL); +} + +void +cmd_minimum_font_size() { + g_object_set (G_OBJECT(view_settings()), "minimum-font-size", + uzbl.behave.minimum_font_size, NULL); +} +void +cmd_autoload_img() { + g_object_set (G_OBJECT(view_settings()), "auto-load-images", + uzbl.behave.autoload_img, NULL); +} + + +void +cmd_autoshrink_img() { + g_object_set (G_OBJECT(view_settings()), "auto-shrink-images", + uzbl.behave.autoshrink_img, NULL); +} + + +void +cmd_enable_spellcheck() { + g_object_set (G_OBJECT(view_settings()), "enable-spell-checking", + uzbl.behave.enable_spellcheck, NULL); +} + +void +cmd_enable_private() { + g_object_set (G_OBJECT(view_settings()), "enable-private-browsing", + uzbl.behave.enable_private, NULL); +} + +void +cmd_print_bg() { + g_object_set (G_OBJECT(view_settings()), "print-backgrounds", + uzbl.behave.print_bg, NULL); +} + +void +cmd_style_uri() { + g_object_set (G_OBJECT(view_settings()), "user-stylesheet-uri", + uzbl.behave.style_uri, NULL); +} + +void +cmd_resizable_txt() { + g_object_set (G_OBJECT(view_settings()), "resizable-text-areas", + uzbl.behave.resizable_txt, NULL); +} + +void +cmd_default_encoding() { + g_object_set (G_OBJECT(view_settings()), "default-encoding", + uzbl.behave.default_encoding, NULL); +} + +void +cmd_enforce_96dpi() { + g_object_set (G_OBJECT(view_settings()), "enforce-96-dpi", + uzbl.behave.enforce_96dpi, NULL); +} + +void +cmd_caret_browsing() { + g_object_set (G_OBJECT(view_settings()), "enable-caret-browsing", + uzbl.behave.caret_browsing, NULL); +} + +void +cmd_cookie_handler() { + gchar **split = g_strsplit(uzbl.behave.cookie_handler, " ", 2); + /* pitfall: doesn't handle chain actions; must the sync_ action manually */ + if ((g_strcmp0(split[0], "sh") == 0) || + (g_strcmp0(split[0], "spawn") == 0)) { + g_free (uzbl.behave.cookie_handler); + uzbl.behave.cookie_handler = + g_strdup_printf("sync_%s %s", split[0], split[1]); + } + g_strfreev (split); +} + +void +cmd_scheme_handler() { + gchar **split = g_strsplit(uzbl.behave.scheme_handler, " ", 2); + /* pitfall: doesn't handle chain actions; must the sync_ action manually */ + if ((g_strcmp0(split[0], "sh") == 0) || + (g_strcmp0(split[0], "spawn") == 0)) { + g_free (uzbl.behave.scheme_handler); + uzbl.behave.scheme_handler = + g_strdup_printf("sync_%s %s", split[0], split[1]); + } + g_strfreev (split); +} + +void +cmd_fifo_dir() { + uzbl.behave.fifo_dir = init_fifo(uzbl.behave.fifo_dir); +} + +void +cmd_socket_dir() { + uzbl.behave.socket_dir = init_socket(uzbl.behave.socket_dir); +} + +void +cmd_inject_html() { + if(uzbl.behave.inject_html) { + webkit_web_view_load_html_string (uzbl.gui.web_view, + uzbl.behave.inject_html, NULL); + } +} + +void +cmd_useragent() { + if (*uzbl.net.useragent == ' ') { + g_free (uzbl.net.useragent); + uzbl.net.useragent = NULL; + } else { + g_object_set(G_OBJECT(uzbl.net.soup_session), SOUP_SESSION_USER_AGENT, + uzbl.net.useragent, NULL); + } +} + +/* requires webkit >=1.1.14 */ +/* +void +cmd_view_source() { + webkit_web_view_set_view_source_mode(uzbl.gui.web_view, + (gboolean) uzbl.behave.view_source); +} +*/ + +void +toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result) { + (void)page; + (void)argv; + (void)result; + + webkit_web_view_set_full_content_zoom (page, !webkit_web_view_get_full_content_zoom (page)); +} + +void +toggle_status_cb (WebKitWebView* page, GArray *argv, GString *result) { + (void)page; + (void)argv; + (void)result; + + if (uzbl.behave.show_status) { + gtk_widget_hide(uzbl.gui.mainbar); + } else { + gtk_widget_show(uzbl.gui.mainbar); + } + uzbl.behave.show_status = !uzbl.behave.show_status; + update_title(); +} + +void +link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data) { + (void) page; + (void) title; + (void) data; + State *s = &uzbl.state; + + if(s->selected_url) { + if(s->last_selected_url) + g_free(s->last_selected_url); + s->last_selected_url = g_strdup(s->selected_url); + } + else { + if(s->last_selected_url) g_free(s->last_selected_url); + s->last_selected_url = NULL; + } + + g_free(s->selected_url); + s->selected_url = NULL; + + if (link) { + s->selected_url = g_strdup(link); + + if(s->last_selected_url && + g_strcmp0(s->selected_url, s->last_selected_url)) + send_event(LINK_UNHOVER, s->last_selected_url, NULL); + + send_event(LINK_HOVER, s->selected_url, NULL); + } + else if(s->last_selected_url) { + send_event(LINK_UNHOVER, s->last_selected_url, NULL); + } + + update_title(); +} + +void +title_change_cb (WebKitWebView* web_view, GParamSpec param_spec) { + (void) web_view; + (void) param_spec; + const gchar *title = webkit_web_view_get_title(web_view); + if (uzbl.gui.main_title) + g_free (uzbl.gui.main_title); + uzbl.gui.main_title = title ? g_strdup (title) : g_strdup ("(no title)"); + update_title(); + send_event(TITLE_CHANGED, uzbl.gui.main_title, NULL); +} + +void +progress_change_cb (WebKitWebView* page, gint progress, gpointer data) { + (void) page; + (void) data; + gchar *prg_str; + + prg_str = itos(progress); + send_event(LOAD_PROGRESS, prg_str, NULL); + g_free(prg_str); + + update_title(); +} + +void +selection_changed_cb(WebKitWebView *webkitwebview, gpointer ud) { + (void)ud; + gchar *tmp; + + webkit_web_view_copy_clipboard(webkitwebview); + tmp = gtk_clipboard_wait_for_text(gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)); + send_event(SELECTION_CHANGED, tmp, NULL); + g_free(tmp); +} + +void +load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) { + (void) page; + (void) data; + + if (uzbl.behave.load_finish_handler) + run_handler(uzbl.behave.load_finish_handler, ""); + + send_event(LOAD_FINISH, webkit_web_frame_get_uri(frame), NULL); +} + +void +load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) { + (void) page; + (void) frame; + (void) data; + uzbl.gui.sbar.load_progress = 0; + if (uzbl.behave.load_start_handler) + run_handler(uzbl.behave.load_start_handler, ""); + + send_event(LOAD_START, uzbl.state.uri, NULL); +} + +void +load_error_cb (WebKitWebView* page, WebKitWebFrame* frame, gchar *uri, gpointer web_err, gpointer ud) { + (void) page; + (void) frame; + (void) ud; + GError *err = web_err; + gchar *details; + + details = g_strdup_printf("%s %d:%s", uri, err->code, err->message); + send_event(LOAD_ERROR, details, NULL); + g_free(details); +} + +void +load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) { + (void) page; + (void) data; + g_free (uzbl.state.uri); + GString* newuri = g_string_new (webkit_web_frame_get_uri (frame)); + uzbl.state.uri = g_string_free (newuri, FALSE); + + if (uzbl.behave.load_commit_handler) + run_handler(uzbl.behave.load_commit_handler, uzbl.state.uri); + + /* event message */ + send_event(LOAD_COMMIT, webkit_web_frame_get_uri (frame), NULL); +} + +void +destroy_cb (GtkWidget* widget, gpointer data) { + (void) widget; + (void) data; + gtk_main_quit (); +} + +gboolean +configure_event_cb(GtkWidget* window, GdkEventConfigure* event) { + (void) window; + (void) event; + + retrieve_geometry(); + send_event(GEOMETRY_CHANGED, uzbl.gui.geometry, NULL); + return FALSE; +} + +gboolean +key_press_cb (GtkWidget* window, GdkEventKey* event) { + (void) window; + + if(event->type == GDK_KEY_PRESS) + key_to_event(event->keyval, GDK_KEY_PRESS); + + return uzbl.behave.forward_keys ? FALSE : TRUE; +} + +gboolean +key_release_cb (GtkWidget* window, GdkEventKey* event) { + (void) window; + + if(event->type == GDK_KEY_RELEASE) + key_to_event(event->keyval, GDK_KEY_RELEASE); + + return TRUE; +} + +gboolean +navigation_decision_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) user_data; + + const gchar* uri = webkit_network_request_get_uri (request); + gboolean decision_made = FALSE; + + if (uzbl.state.verbose) + printf("Navigation requested -> %s\n", uri); + + if (uzbl.behave.scheme_handler) { + GString *s = g_string_new (""); + g_string_printf(s, "'%s'", uri); + + run_handler(uzbl.behave.scheme_handler, s->str); + + if(uzbl.comm.sync_stdout && strcmp (uzbl.comm.sync_stdout, "") != 0) { + char *p = strchr(uzbl.comm.sync_stdout, '\n' ); + if ( p != NULL ) *p = '\0'; + if (!strcmp(uzbl.comm.sync_stdout, "USED")) { + webkit_web_policy_decision_ignore(policy_decision); + decision_made = TRUE; + } + } + if (uzbl.comm.sync_stdout) + uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); + + g_string_free(s, TRUE); + } + if (!decision_made) + webkit_web_policy_decision_use(policy_decision); + + return TRUE; +} + +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); + if (uzbl.state.verbose) + printf("New window requested -> %s \n", uri); + webkit_web_policy_decision_use(policy_decision); + send_event(NEW_WINDOW, uri, NULL); + return TRUE; +} + +gboolean +mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type, WebKitWebPolicyDecision *policy_decision, gpointer user_data) { + (void) frame; + (void) request; + (void) user_data; + + /* If we can display it, let's display it... */ + if (webkit_web_view_can_show_mime_type (web_view, mime_type)) { + webkit_web_policy_decision_use (policy_decision); + return TRUE; + } + + /* ...everything we can't display is downloaded */ + webkit_web_policy_decision_download (policy_decision); + return TRUE; +} + +/*@null@*/ WebKitWebView* +create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data) { + (void) web_view; + (void) frame; + (void) user_data; + if (uzbl.state.selected_url != NULL) { + if (uzbl.state.verbose) + printf("\nNew web view -> %s\n",uzbl.state.selected_url); + new_window_load_uri(uzbl.state.selected_url); + } else { + if (uzbl.state.verbose) + printf("New web view -> %s\n","Nothing to open, exiting"); + } + return (NULL); +} + +gboolean +download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data) { + (void) web_view; + (void) user_data; + if (uzbl.behave.download_handler) { + const gchar* uri = webkit_download_get_uri ((WebKitDownload*)download); + if (uzbl.state.verbose) + printf("Download -> %s\n",uri); + /* if urls not escaped, we may have to escape and quote uri before this call */ + + GString *args = g_string_new(uri); + + if (uzbl.net.proxy_url) { + g_string_append_c(args, ' '); + g_string_append(args, uzbl.net.proxy_url); + } + + run_handler(uzbl.behave.download_handler, args->str); + + g_string_free(args, TRUE); + } + send_event(DOWNLOAD_REQ, webkit_download_get_uri ((WebKitDownload*)download), NULL); + return (FALSE); +} diff --git a/callbacks.h b/callbacks.h new file mode 100644 index 0000000..f4562c8 --- /dev/null +++ b/callbacks.h @@ -0,0 +1,189 @@ +/* (c) 2009 by Robert Manea + * Callbacks +*/ + +void +cmd_load_uri(); + +void +cmd_set_status(); + +void +set_proxy_url(); + +void +set_icon(); + +void +cmd_cookie_handler(); + +void +cmd_scheme_handler(); + +void +move_statusbar(); + +void +cmd_http_debug(); + +void +cmd_max_conns(); + +void +cmd_max_conns_host(); + +/* exported WebKitWebSettings properties */ +void +cmd_font_size(); + +void +cmd_default_font_family(); + +void +cmd_monospace_font_family(); + +void +cmd_sans_serif_font_family(); + +void +cmd_serif_font_family(); + +void +cmd_cursive_font_family(); + +void +cmd_fantasy_font_family(); + +void +cmd_zoom_level(); + +void +cmd_disable_plugins(); + +void +cmd_disable_scripts(); + +void +cmd_minimum_font_size(); + +void +cmd_fifo_dir(); + +void +cmd_socket_dir(); + +void +cmd_useragent() ; + +void +cmd_autoload_img(); + +void +cmd_autoshrink_img(); + +void +cmd_enable_spellcheck(); + +void +cmd_enable_private(); + +void +cmd_print_bg(); + +void +cmd_style_uri(); + +void +cmd_resizable_txt(); + +void +cmd_default_encoding(); + +void +cmd_enforce_96dpi(); + +void +cmd_inject_html(); + +void +cmd_caret_browsing(); + +void +cmd_set_geometry(); + +/* +void +cmd_view_source(); +*/ + +void +cmd_load_start(); + +WebKitWebSettings* +view_settings(); + +gboolean +download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data); + +void +toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result); + +void +toggle_status_cb (WebKitWebView* page, GArray *argv, GString *result); + +void +link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data); + +void +title_change_cb (WebKitWebView* web_view, GParamSpec param_spec); + +void +progress_change_cb (WebKitWebView* page, gint progress, gpointer data); + +void +load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data); + +void +load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data); + +void +load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data); + +void +load_error_cb (WebKitWebView* page, WebKitWebFrame* frame, gchar *uri, gpointer web_err, gpointer ud); + +void +selection_changed_cb(WebKitWebView *webkitwebview, gpointer ud); + +void +destroy_cb (GtkWidget* widget, gpointer data); + +gboolean +configure_event_cb(GtkWidget* window, GdkEventConfigure* event); + +gboolean +key_press_cb (GtkWidget* window, GdkEventKey* event); + +gboolean +key_release_cb (GtkWidget* window, GdkEventKey* event); + +gboolean +navigation_decision_cb (WebKitWebView *web_view, WebKitWebFrame *frame, + WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, + WebKitWebPolicyDecision *policy_decision, gpointer user_data); + +gboolean +new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, + WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, + WebKitWebPolicyDecision *policy_decision, gpointer user_data); + +gboolean +mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, + gchar *mime_type, WebKitWebPolicyDecision *policy_decision, gpointer user_data); + +/*@null@*/ WebKitWebView* +create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data); + +gboolean +download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data); + @@ -3,7 +3,7 @@ */ #include "uzbl-core.h" -#include "uzbl-events.h" +#include "events.h" UzblCore uzbl; diff --git a/uzbl-core.c b/uzbl-core.c index 71bc474..3b999e1 100644 --- a/uzbl-core.c +++ b/uzbl-core.c @@ -30,7 +30,8 @@ */ #include "uzbl-core.h" -#include "uzbl-events.h" +#include "callbacks.h" +#include "events.h" #include "config.h" UzblCore uzbl; @@ -345,7 +346,10 @@ itos(int val) { } gchar* -strfree(gchar *str) { g_free(str); return NULL; } // for freeing & setting to null in one go +strfree(gchar *str) { + g_free(str); + return NULL; +} gchar* argv_idx(const GArray *a, const guint idx) { return g_array_index(a, gchar*, idx); } @@ -495,7 +499,6 @@ clean_up(void) { } /* --- SIGNAL HANDLER --- */ - void catch_sigterm(int s) { (void) s; @@ -516,119 +519,6 @@ catch_sigalrm(int s) { uzbl.state.event_buffer = NULL; } -/* --- CALLBACKS --- */ - -gboolean -navigation_decision_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) user_data; - - const gchar* uri = webkit_network_request_get_uri (request); - gboolean decision_made = FALSE; - - if (uzbl.state.verbose) - printf("Navigation requested -> %s\n", uri); - - if (uzbl.behave.scheme_handler) { - GString *s = g_string_new (""); - g_string_printf(s, "'%s'", uri); - - run_handler(uzbl.behave.scheme_handler, s->str); - - if(uzbl.comm.sync_stdout && strcmp (uzbl.comm.sync_stdout, "") != 0) { - char *p = strchr(uzbl.comm.sync_stdout, '\n' ); - if ( p != NULL ) *p = '\0'; - if (!strcmp(uzbl.comm.sync_stdout, "USED")) { - webkit_web_policy_decision_ignore(policy_decision); - decision_made = TRUE; - } - } - if (uzbl.comm.sync_stdout) - uzbl.comm.sync_stdout = strfree(uzbl.comm.sync_stdout); - - g_string_free(s, TRUE); - } - if (!decision_made) - webkit_web_policy_decision_use(policy_decision); - - return TRUE; -} - -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); - if (uzbl.state.verbose) - printf("New window requested -> %s \n", uri); - webkit_web_policy_decision_use(policy_decision); - send_event(NEW_WINDOW, uri, NULL); - return TRUE; -} - -gboolean -mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type, WebKitWebPolicyDecision *policy_decision, gpointer user_data) { - (void) frame; - (void) request; - (void) user_data; - - /* If we can display it, let's display it... */ - if (webkit_web_view_can_show_mime_type (web_view, mime_type)) { - webkit_web_policy_decision_use (policy_decision); - return TRUE; - } - - /* ...everything we can't display is downloaded */ - webkit_web_policy_decision_download (policy_decision); - return TRUE; -} - -/*@null@*/ WebKitWebView* -create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data) { - (void) web_view; - (void) frame; - (void) user_data; - if (uzbl.state.selected_url != NULL) { - if (uzbl.state.verbose) - printf("\nNew web view -> %s\n",uzbl.state.selected_url); - new_window_load_uri(uzbl.state.selected_url); - } else { - if (uzbl.state.verbose) - printf("New web view -> %s\n","Nothing to open, exiting"); - } - return (NULL); -} - -gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data) { - (void) web_view; - (void) user_data; - if (uzbl.behave.download_handler) { - const gchar* uri = webkit_download_get_uri ((WebKitDownload*)download); - if (uzbl.state.verbose) - printf("Download -> %s\n",uri); - /* if urls not escaped, we may have to escape and quote uri before this call */ - - GString *args = g_string_new(uri); - - if (uzbl.net.proxy_url) { - g_string_append_c(args, ' '); - g_string_append(args, uzbl.net.proxy_url); - } - - run_handler(uzbl.behave.download_handler, args->str); - - g_string_free(args, TRUE); - } - send_event(DOWNLOAD_REQ, webkit_download_get_uri ((WebKitDownload*)download), NULL); - return (FALSE); -} - /* scroll a bar in a given direction */ void scroll (GtkAdjustment* bar, GArray *argv) { @@ -677,183 +567,6 @@ scroll_horz(WebKitWebView* page, GArray *argv, GString *result) { scroll(uzbl.gui.bar_h, argv); } -void -cmd_set_geometry() { - if(!gtk_window_parse_geometry(GTK_WINDOW(uzbl.gui.main_window), uzbl.gui.geometry)) { - if(uzbl.state.verbose) - printf("Error in geometry string: %s\n", uzbl.gui.geometry); - } - /* update geometry var with the actual geometry - this is necessary as some WMs don't seem to honour - the above setting and we don't want to end up with - wrong geometry information - */ - retrieve_geometry(); -} - -void -cmd_set_status() { - if (!uzbl.behave.show_status) { - gtk_widget_hide(uzbl.gui.mainbar); - } else { - gtk_widget_show(uzbl.gui.mainbar); - } - update_title(); -} - -void -toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result) { - (void)page; - (void)argv; - (void)result; - - webkit_web_view_set_full_content_zoom (page, !webkit_web_view_get_full_content_zoom (page)); -} - -void -toggle_status_cb (WebKitWebView* page, GArray *argv, GString *result) { - (void)page; - (void)argv; - (void)result; - - if (uzbl.behave.show_status) { - gtk_widget_hide(uzbl.gui.mainbar); - } else { - gtk_widget_show(uzbl.gui.mainbar); - } - uzbl.behave.show_status = !uzbl.behave.show_status; - update_title(); -} - -void -link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data) { - (void) page; - (void) title; - (void) data; - State *s = &uzbl.state; - - if(s->selected_url) { - if(s->last_selected_url) - g_free(s->last_selected_url); - s->last_selected_url = g_strdup(s->selected_url); - } - else { - if(s->last_selected_url) g_free(s->last_selected_url); - s->last_selected_url = NULL; - } - - g_free(s->selected_url); - s->selected_url = NULL; - - if (link) { - s->selected_url = g_strdup(link); - - if(s->last_selected_url && - g_strcmp0(s->selected_url, s->last_selected_url)) - send_event(LINK_UNHOVER, s->last_selected_url, NULL); - - send_event(LINK_HOVER, s->selected_url, NULL); - } - else if(s->last_selected_url) { - send_event(LINK_UNHOVER, s->last_selected_url, NULL); - } - - update_title(); -} - -void -title_change_cb (WebKitWebView* web_view, GParamSpec param_spec) { - (void) web_view; - (void) param_spec; - const gchar *title = webkit_web_view_get_title(web_view); - if (uzbl.gui.main_title) - g_free (uzbl.gui.main_title); - uzbl.gui.main_title = title ? g_strdup (title) : g_strdup ("(no title)"); - update_title(); - send_event(TITLE_CHANGED, uzbl.gui.main_title, NULL); -} - -void -progress_change_cb (WebKitWebView* page, gint progress, gpointer data) { - (void) page; - (void) data; - gchar *prg_str; - - prg_str = itos(progress); - send_event(LOAD_PROGRESS, prg_str, NULL); - g_free(prg_str); - - update_title(); -} - -void -selection_changed_cb(WebKitWebView *webkitwebview, gpointer ud) { - (void)ud; - gchar *tmp; - - webkit_web_view_copy_clipboard(webkitwebview); - tmp = gtk_clipboard_wait_for_text(gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)); - send_event(SELECTION_CHANGED, tmp, NULL); - g_free(tmp); -} - -void -load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) { - (void) page; - (void) data; - - if (uzbl.behave.load_finish_handler) - run_handler(uzbl.behave.load_finish_handler, ""); - - send_event(LOAD_FINISH, webkit_web_frame_get_uri(frame), NULL); -} - -void -load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) { - (void) page; - (void) frame; - (void) data; - uzbl.gui.sbar.load_progress = 0; - if (uzbl.behave.load_start_handler) - run_handler(uzbl.behave.load_start_handler, ""); - - send_event(LOAD_START, uzbl.state.uri, NULL); -} - -void -load_error_cb (WebKitWebView* page, WebKitWebFrame* frame, gchar *uri, gpointer web_err, gpointer ud) { - (void) page; - (void) frame; - (void) ud; - GError *err = web_err; - gchar *details; - - details = g_strdup_printf("%s %d:%s", uri, err->code, err->message); - send_event(LOAD_ERROR, details, NULL); - g_free(details); -} - -void -load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data) { - (void) page; - (void) data; - g_free (uzbl.state.uri); - GString* newuri = g_string_new (webkit_web_frame_get_uri (frame)); - uzbl.state.uri = g_string_free (newuri, FALSE); - - if (uzbl.behave.load_commit_handler) - run_handler(uzbl.behave.load_commit_handler, uzbl.state.uri); - - /* event message */ - send_event(LOAD_COMMIT, webkit_web_frame_get_uri (frame), NULL); -} - -void -destroy_cb (GtkWidget* widget, gpointer data) { - (void) widget; - (void) data; - gtk_main_quit (); -} /* VIEW funcs (little webkit wrappers) */ @@ -1559,270 +1272,6 @@ parse_command(const char *cmd, const char *param, GString *result) { g_printerr ("command \"%s\" not understood. ignoring.\n", cmd); } -void -set_proxy_url() { - SoupURI *suri; - - if(uzbl.net.proxy_url == NULL || *uzbl.net.proxy_url == ' ') { - soup_session_remove_feature_by_type(uzbl.net.soup_session, - (GType) SOUP_SESSION_PROXY_URI); - } - else { - suri = soup_uri_new(uzbl.net.proxy_url); - g_object_set(G_OBJECT(uzbl.net.soup_session), - SOUP_SESSION_PROXY_URI, - suri, NULL); - soup_uri_free(suri); - } - return; -} - -void -set_icon() { - if(file_exists(uzbl.gui.icon)) { - if (uzbl.gui.main_window) - gtk_window_set_icon_from_file (GTK_WINDOW (uzbl.gui.main_window), uzbl.gui.icon, NULL); - } else { - g_printerr ("Icon \"%s\" not found. ignoring.\n", uzbl.gui.icon); - } -} - -void -cmd_load_uri() { - GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*)); - g_array_append_val (a, uzbl.state.uri); - load_uri(uzbl.gui.web_view, a, NULL); - g_array_free (a, TRUE); -} - -void -cmd_max_conns() { - g_object_set(G_OBJECT(uzbl.net.soup_session), - SOUP_SESSION_MAX_CONNS, uzbl.net.max_conns, NULL); -} - -void -cmd_max_conns_host() { - g_object_set(G_OBJECT(uzbl.net.soup_session), - SOUP_SESSION_MAX_CONNS_PER_HOST, uzbl.net.max_conns_host, NULL); -} - -void -cmd_http_debug() { - soup_session_remove_feature - (uzbl.net.soup_session, SOUP_SESSION_FEATURE(uzbl.net.soup_logger)); - /* do we leak if this doesn't get freed? why does it occasionally crash if freed? */ - /*g_free(uzbl.net.soup_logger);*/ - - uzbl.net.soup_logger = soup_logger_new(uzbl.behave.http_debug, -1); - soup_session_add_feature(uzbl.net.soup_session, - SOUP_SESSION_FEATURE(uzbl.net.soup_logger)); -} - -WebKitWebSettings* -view_settings() { - return webkit_web_view_get_settings(uzbl.gui.web_view); -} - -void -cmd_font_size() { - WebKitWebSettings *ws = view_settings(); - if (uzbl.behave.font_size > 0) { - g_object_set (G_OBJECT(ws), "default-font-size", uzbl.behave.font_size, NULL); - } - - if (uzbl.behave.monospace_size > 0) { - g_object_set (G_OBJECT(ws), "default-monospace-font-size", - uzbl.behave.monospace_size, NULL); - } else { - g_object_set (G_OBJECT(ws), "default-monospace-font-size", - uzbl.behave.font_size, NULL); - } -} - -void -cmd_default_font_family() { - g_object_set (G_OBJECT(view_settings()), "default-font-family", - uzbl.behave.default_font_family, NULL); -} - -void -cmd_monospace_font_family() { - g_object_set (G_OBJECT(view_settings()), "monospace-font-family", - uzbl.behave.monospace_font_family, NULL); -} - -void -cmd_sans_serif_font_family() { - g_object_set (G_OBJECT(view_settings()), "sans_serif-font-family", - uzbl.behave.sans_serif_font_family, NULL); -} - -void -cmd_serif_font_family() { - g_object_set (G_OBJECT(view_settings()), "serif-font-family", - uzbl.behave.serif_font_family, NULL); -} - -void -cmd_cursive_font_family() { - g_object_set (G_OBJECT(view_settings()), "cursive-font-family", - uzbl.behave.cursive_font_family, NULL); -} - -void -cmd_fantasy_font_family() { - g_object_set (G_OBJECT(view_settings()), "fantasy-font-family", - uzbl.behave.fantasy_font_family, NULL); -} - -void -cmd_zoom_level() { - webkit_web_view_set_zoom_level (uzbl.gui.web_view, uzbl.behave.zoom_level); -} - -void -cmd_disable_plugins() { - g_object_set (G_OBJECT(view_settings()), "enable-plugins", - !uzbl.behave.disable_plugins, NULL); -} - -void -cmd_disable_scripts() { - g_object_set (G_OBJECT(view_settings()), "enable-scripts", - !uzbl.behave.disable_scripts, NULL); -} - -void -cmd_minimum_font_size() { - g_object_set (G_OBJECT(view_settings()), "minimum-font-size", - uzbl.behave.minimum_font_size, NULL); -} -void -cmd_autoload_img() { - g_object_set (G_OBJECT(view_settings()), "auto-load-images", - uzbl.behave.autoload_img, NULL); -} - - -void -cmd_autoshrink_img() { - g_object_set (G_OBJECT(view_settings()), "auto-shrink-images", - uzbl.behave.autoshrink_img, NULL); -} - - -void -cmd_enable_spellcheck() { - g_object_set (G_OBJECT(view_settings()), "enable-spell-checking", - uzbl.behave.enable_spellcheck, NULL); -} - -void -cmd_enable_private() { - g_object_set (G_OBJECT(view_settings()), "enable-private-browsing", - uzbl.behave.enable_private, NULL); -} - -void -cmd_print_bg() { - g_object_set (G_OBJECT(view_settings()), "print-backgrounds", - uzbl.behave.print_bg, NULL); -} - -void -cmd_style_uri() { - g_object_set (G_OBJECT(view_settings()), "user-stylesheet-uri", - uzbl.behave.style_uri, NULL); -} - -void -cmd_resizable_txt() { - g_object_set (G_OBJECT(view_settings()), "resizable-text-areas", - uzbl.behave.resizable_txt, NULL); -} - -void -cmd_default_encoding() { - g_object_set (G_OBJECT(view_settings()), "default-encoding", - uzbl.behave.default_encoding, NULL); -} - -void -cmd_enforce_96dpi() { - g_object_set (G_OBJECT(view_settings()), "enforce-96-dpi", - uzbl.behave.enforce_96dpi, NULL); -} - -void -cmd_caret_browsing() { - g_object_set (G_OBJECT(view_settings()), "enable-caret-browsing", - uzbl.behave.caret_browsing, NULL); -} - -void -cmd_cookie_handler() { - gchar **split = g_strsplit(uzbl.behave.cookie_handler, " ", 2); - /* pitfall: doesn't handle chain actions; must the sync_ action manually */ - if ((g_strcmp0(split[0], "sh") == 0) || - (g_strcmp0(split[0], "spawn") == 0)) { - g_free (uzbl.behave.cookie_handler); - uzbl.behave.cookie_handler = - g_strdup_printf("sync_%s %s", split[0], split[1]); - } - g_strfreev (split); -} - -void -cmd_scheme_handler() { - gchar **split = g_strsplit(uzbl.behave.scheme_handler, " ", 2); - /* pitfall: doesn't handle chain actions; must the sync_ action manually */ - if ((g_strcmp0(split[0], "sh") == 0) || - (g_strcmp0(split[0], "spawn") == 0)) { - g_free (uzbl.behave.scheme_handler); - uzbl.behave.scheme_handler = - g_strdup_printf("sync_%s %s", split[0], split[1]); - } - g_strfreev (split); -} - -void -cmd_fifo_dir() { - uzbl.behave.fifo_dir = init_fifo(uzbl.behave.fifo_dir); -} - -void -cmd_socket_dir() { - uzbl.behave.socket_dir = init_socket(uzbl.behave.socket_dir); -} - -void -cmd_inject_html() { - if(uzbl.behave.inject_html) { - webkit_web_view_load_html_string (uzbl.gui.web_view, - uzbl.behave.inject_html, NULL); - } -} - -void -cmd_useragent() { - if (*uzbl.net.useragent == ' ') { - g_free (uzbl.net.useragent); - uzbl.net.useragent = NULL; - } else { - g_object_set(G_OBJECT(uzbl.net.soup_session), SOUP_SESSION_USER_AGENT, - uzbl.net.useragent, NULL); - } -} - -/* requires webkit >=1.1.14 */ -/* -void -cmd_view_source() { - webkit_web_view_set_view_source_mode(uzbl.gui.web_view, - (gboolean) uzbl.behave.view_source); -} -*/ void move_statusbar() { @@ -2204,15 +1653,6 @@ update_title (void) { } } -gboolean -configure_event_cb(GtkWidget* window, GdkEventConfigure* event) { - (void) window; - (void) event; - - retrieve_geometry(); - send_event(GEOMETRY_CHANGED, uzbl.gui.geometry, NULL); - return FALSE; -} void key_to_event(guint keyval, gint mode) { @@ -2231,26 +1671,6 @@ key_to_event(guint keyval, gint mode) { } -gboolean -key_press_cb (GtkWidget* window, GdkEventKey* event) { - (void) window; - - if(event->type == GDK_KEY_PRESS) - key_to_event(event->keyval, GDK_KEY_PRESS); - - return uzbl.behave.forward_keys ? FALSE : TRUE; -} - -gboolean -key_release_cb (GtkWidget* window, GdkEventKey* event) { - (void) window; - - if(event->type == GDK_KEY_RELEASE) - key_to_event(event->keyval, GDK_KEY_RELEASE); - - return TRUE; -} - void create_browser () { GUI *g = &uzbl.gui; diff --git a/uzbl-core.h b/uzbl-core.h index d5fbcb7..5a32907 100644 --- a/uzbl-core.h +++ b/uzbl-core.h @@ -7,7 +7,6 @@ * * (c) 2009 by Robert Manea * - introduced struct concept - * - statusbar template * */ @@ -224,6 +223,9 @@ itos(int val); char * str_replace (const char* search, const char* replace, const char* string); +gchar* +strfree(gchar *str); + GArray* read_file_by_line (const gchar *path); @@ -248,51 +250,6 @@ set_var_value(const gchar *name, gchar *val); void print(WebKitWebView *page, GArray *argv, GString *result); -gboolean -navigation_decision_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data); - -gboolean -new_window_cb (WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, WebKitWebNavigationAction *navigation_action, WebKitWebPolicyDecision *policy_decision, gpointer user_data); - -gboolean -mime_policy_cb(WebKitWebView *web_view, WebKitWebFrame *frame, WebKitNetworkRequest *request, gchar *mime_type, WebKitWebPolicyDecision *policy_decision, gpointer user_data); - -/*@null@*/ WebKitWebView* -create_web_view_cb (WebKitWebView *web_view, WebKitWebFrame *frame, gpointer user_data); - -gboolean -download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data); - -void -toggle_zoom_type (WebKitWebView* page, GArray *argv, GString *result); - -void -toggle_status_cb (WebKitWebView* page, GArray *argv, GString *result); - -void -link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpointer data); - -void -title_change_cb (WebKitWebView* web_view, GParamSpec param_spec); - -void -progress_change_cb (WebKitWebView* page, gint progress, gpointer data); - -void -load_commit_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data); - -void -load_start_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data); - -void -load_finish_cb (WebKitWebView* page, WebKitWebFrame* frame, gpointer data); - -void -selection_changed_cb(WebKitWebView *webkitwebview, gpointer ud); - -void -destroy_cb (GtkWidget* widget, gpointer data); - void commands_hash(void); @@ -465,8 +422,8 @@ update_gui(WebKitWebView *page, GArray *argv, GString *result); void event(WebKitWebView *page, GArray *argv, GString *result); -gboolean -configure_event_cb(GtkWidget* window, GdkEventConfigure* event); +void +key_to_event(guint keyval, gint mode); typedef void (*Command)(WebKitWebView*, GArray *argv, GString *result); typedef struct { @@ -474,123 +431,4 @@ typedef struct { gboolean no_split; } CommandInfo; -/* Command callbacks */ -void -cmd_load_uri(); - -void -cmd_set_status(); - -void -set_proxy_url(); - -void -set_icon(); - -void -cmd_cookie_handler(); - -void -cmd_scheme_handler(); - -void -move_statusbar(); - -void -cmd_http_debug(); - -void -cmd_max_conns(); - -void -cmd_max_conns_host(); - -/* exported WebKitWebSettings properties */ - -void -cmd_font_size(); - -void -cmd_default_font_family(); - -void -cmd_monospace_font_family(); - -void -cmd_sans_serif_font_family(); - -void -cmd_serif_font_family(); - -void -cmd_cursive_font_family(); - -void -cmd_fantasy_font_family(); - -void -cmd_zoom_level(); - -void -cmd_disable_plugins(); - -void -cmd_disable_scripts(); - -void -cmd_minimum_font_size(); - -void -cmd_fifo_dir(); - -void -cmd_socket_dir(); - -void -cmd_useragent() ; - -void -cmd_autoload_img(); - -void -cmd_autoshrink_img(); - -void -cmd_enable_spellcheck(); - -void -cmd_enable_private(); - -void -cmd_print_bg(); - -void -cmd_style_uri(); - -void -cmd_resizable_txt(); - -void -cmd_default_encoding(); - -void -cmd_enforce_96dpi(); - -void -cmd_inject_html(); - -void -cmd_caret_browsing(); - -void -cmd_set_geometry(); - -/* -void -cmd_view_source(); -*/ - -void -cmd_load_start(); - /* vi: set et ts=4: */ |