aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/uzbl-core.c
diff options
context:
space:
mode:
authorGravatar David Keijser <keijser@gmail.com>2011-05-24 18:13:47 +0200
committerGravatar David Keijser <keijser@gmail.com>2011-05-24 18:45:21 +0200
commitfc09b334f196b5abd6c6c88f82597e5d6ac71d0e (patch)
treee2a2bd273199519cb4172d8a48574fff97f9ff1f /src/uzbl-core.c
parent778ca3f14946df1738b744621807321992f556bb (diff)
split commands from uzbl-core.c
Diffstat (limited to 'src/uzbl-core.c')
-rw-r--r--src/uzbl-core.c442
1 files changed, 7 insertions, 435 deletions
diff --git a/src/uzbl-core.c b/src/uzbl-core.c
index 693f3ce..d670774 100644
--- a/src/uzbl-core.c
+++ b/src/uzbl-core.c
@@ -454,194 +454,8 @@ scroll(GtkAdjustment* bar, gchar *amount_str) {
gtk_adjustment_set_value (bar, value);
}
-/*
- * scroll vertical 20
- * scroll vertical 20%
- * scroll vertical -40
- * scroll vertical begin
- * scroll vertical end
- * scroll horizontal 10
- * scroll horizontal -500
- * scroll horizontal begin
- * scroll horizontal end
- */
-void
-scroll_cmd(WebKitWebView* page, GArray *argv, GString *result) {
- (void) page; (void) result;
- gchar *direction = g_array_index(argv, gchar*, 0);
- gchar *argv1 = g_array_index(argv, gchar*, 1);
- GtkAdjustment *bar = NULL;
-
- if (g_strcmp0(direction, "horizontal") == 0)
- bar = uzbl.gui.bar_h;
- else if (g_strcmp0(direction, "vertical") == 0)
- bar = uzbl.gui.bar_v;
- else {
- if(uzbl.state.verbose)
- puts("Unrecognized scroll format");
- return;
- }
-
- if (g_strcmp0(argv1, "begin") == 0)
- gtk_adjustment_set_value(bar, gtk_adjustment_get_lower(bar));
- else if (g_strcmp0(argv1, "end") == 0)
- gtk_adjustment_set_value (bar, gtk_adjustment_get_upper(bar) -
- gtk_adjustment_get_page_size(bar));
- else
- scroll(bar, argv1);
-}
-
-
-/* VIEW funcs (little webkit wrappers) */
-#define VIEWFUNC(name) void view_##name(WebKitWebView *page, GArray *argv, GString *result){(void)argv; (void)result; webkit_web_view_##name(page);}
-VIEWFUNC(reload)
-VIEWFUNC(reload_bypass_cache)
-VIEWFUNC(stop_loading)
-VIEWFUNC(zoom_in)
-VIEWFUNC(zoom_out)
-VIEWFUNC(go_back)
-VIEWFUNC(go_forward)
-#undef VIEWFUNC
-
-/* -- command to callback/function map for things we cannot attach to any signals */
-CommandInfo cmdlist[] =
-{ /* key function no_split */
- { "back", view_go_back, 0 },
- { "forward", view_go_forward, 0 },
- { "scroll", scroll_cmd, 0 },
- { "reload", view_reload, 0 },
- { "reload_ign_cache", view_reload_bypass_cache, 0 },
- { "stop", view_stop_loading, 0 },
- { "zoom_in", view_zoom_in, 0 }, //Can crash (when max zoom reached?).
- { "zoom_out", view_zoom_out, 0 },
- { "toggle_zoom_type", toggle_zoom_type, 0 },
- { "uri", load_uri, TRUE },
- { "js", run_js, TRUE },
- { "script", run_external_js, 0 },
- { "toggle_status", toggle_status_cb, 0 },
- { "spawn", spawn_async, 0 },
- { "sync_spawn", spawn_sync, 0 },
- { "sync_spawn_exec", spawn_sync_exec, 0 }, // needed for load_cookies.sh :(
- { "sh", spawn_sh_async, 0 },
- { "sync_sh", spawn_sh_sync, 0 },
- { "exit", close_uzbl, 0 },
- { "search", search_forward_text, TRUE },
- { "search_reverse", search_reverse_text, TRUE },
- { "search_clear", search_clear, TRUE },
- { "dehilight", dehilight, 0 },
- { "set", set_var, TRUE },
- { "dump_config", act_dump_config, 0 },
- { "dump_config_as_events", act_dump_config_as_events, 0 },
- { "chain", chain, 0 },
- { "print", print, TRUE },
- { "event", event, TRUE },
- { "request", event, TRUE },
- { "menu_add", menu_add, TRUE },
- { "menu_link_add", menu_add_link, TRUE },
- { "menu_image_add", menu_add_image, TRUE },
- { "menu_editable_add", menu_add_edit, TRUE },
- { "menu_separator", menu_add_separator, TRUE },
- { "menu_link_separator", menu_add_separator_link, TRUE },
- { "menu_image_separator", menu_add_separator_image, TRUE },
- { "menu_editable_separator", menu_add_separator_edit, TRUE },
- { "menu_remove", menu_remove, TRUE },
- { "menu_link_remove", menu_remove_link, TRUE },
- { "menu_image_remove", menu_remove_image, TRUE },
- { "menu_editable_remove", menu_remove_edit, TRUE },
- { "hardcopy", hardcopy, TRUE },
- { "include", include, TRUE },
- { "show_inspector", show_inspector, 0 },
- { "add_cookie", add_cookie, 0 },
- { "delete_cookie", delete_cookie, 0 },
- { "clear_cookies", clear_cookies, 0 },
- { "download", download, 0 }
-};
-
-void
-commands_hash(void) {
- unsigned int i;
- uzbl.behave.commands = g_hash_table_new(g_str_hash, g_str_equal);
-
- for (i = 0; i < LENGTH(cmdlist); i++)
- g_hash_table_insert(uzbl.behave.commands, (gpointer) cmdlist[i].key, &cmdlist[i]);
-}
-
-
-void
-builtins() {
- unsigned int i;
- unsigned int len = LENGTH(cmdlist);
- GString* command_list = g_string_new("");
-
- for (i = 0; i < len; i++) {
- g_string_append(command_list, cmdlist[i].key);
- g_string_append_c(command_list, ' ');
- }
-
- send_event(BUILTINS, NULL, TYPE_STR, command_list->str, NULL);
- g_string_free(command_list, TRUE);
-}
-
/* -- CORE FUNCTIONS -- */
-void
-set_var(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) result;
-
- if(!argv_idx(argv, 0))
- return;
-
- gchar **split = g_strsplit(argv_idx(argv, 0), "=", 2);
- if (split[0] != NULL) {
- gchar *value = split[1] ? g_strchug(split[1]) : " ";
- set_var_value(g_strstrip(split[0]), value);
- }
- g_strfreev(split);
-}
-
-
-void
-event(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) result;
- GString *event_name;
- gchar **split = NULL;
-
- if(!argv_idx(argv, 0))
- return;
-
- split = g_strsplit(argv_idx(argv, 0), " ", 2);
- if(split[0])
- event_name = g_string_ascii_up(g_string_new(split[0]));
- else
- return;
-
- send_event(0, event_name->str, TYPE_FORMATTEDSTR, split[1] ? split[1] : "", NULL);
-
- g_string_free(event_name, TRUE);
- g_strfreev(split);
-}
-
-void
-print(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) result;
- gchar* buf;
-
- if(!result)
- return;
-
- buf = expand(argv_idx(argv, 0), 0);
- g_string_assign(result, buf);
- g_free(buf);
-}
-
-void
-hardcopy(WebKitWebView *page, GArray *argv, GString *result) {
- (void) argv;
- (void) result;
-
- webkit_web_frame_print(webkit_web_view_get_main_frame(page));
-}
-
/* just a wrapper so parse_cmd_line can be used with for_each_line_in_file */
static void
parse_cmd_line_cb(const char *line, void *user_data) {
@@ -650,118 +464,12 @@ parse_cmd_line_cb(const char *line, void *user_data) {
}
void
-include(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page;
- (void) result;
- gchar *path = argv_idx(argv, 0);
-
- if(!path)
- return;
-
- if((path = find_existing_file(path))) {
- if(!for_each_line_in_file(path, parse_cmd_line_cb, NULL)) {
- gchar *tmp = g_strdup_printf("File %s can not be read.", path);
- send_event(COMMAND_ERROR, NULL, TYPE_STR, tmp, NULL);
- g_free(tmp);
- }
-
- send_event(FILE_INCLUDED, NULL, TYPE_STR, path, NULL);
- g_free(path);
- }
-}
-
-void
-show_inspector(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) argv; (void) result;
-
- webkit_web_inspector_show(uzbl.gui.inspector);
-}
-
-void
-add_cookie(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) result;
- gchar *host, *path, *name, *value;
- gboolean secure = 0;
- SoupDate *expires = NULL;
-
- if(argv->len != 6)
- return;
-
- // Parse with same syntax as ADD_COOKIE event
- host = argv_idx (argv, 0);
- path = argv_idx (argv, 1);
- name = argv_idx (argv, 2);
- value = argv_idx (argv, 3);
- secure = strcmp (argv_idx (argv, 4), "https") == 0;
- if (strlen (argv_idx (argv, 5)) != 0)
- expires = soup_date_new_from_time_t (
- strtoul (argv_idx (argv, 5), NULL, 10));
-
- // Create new cookie
- SoupCookie * cookie = soup_cookie_new (name, value, host, path, -1);
- soup_cookie_set_secure (cookie, secure);
- if (expires)
- soup_cookie_set_expires (cookie, expires);
-
- // Add cookie to jar
- uzbl.net.soup_cookie_jar->in_manual_add = 1;
- soup_cookie_jar_add_cookie (SOUP_COOKIE_JAR (uzbl.net.soup_cookie_jar), cookie);
- uzbl.net.soup_cookie_jar->in_manual_add = 0;
-}
-
-void
-delete_cookie(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) result;
-
- if(argv->len < 4)
- return;
-
- SoupCookie * cookie = soup_cookie_new (
- argv_idx (argv, 2),
- argv_idx (argv, 3),
- argv_idx (argv, 0),
- argv_idx (argv, 1),
- 0);
-
- uzbl.net.soup_cookie_jar->in_manual_add = 1;
- soup_cookie_jar_delete_cookie (SOUP_COOKIE_JAR (uzbl.net.soup_cookie_jar), cookie);
- uzbl.net.soup_cookie_jar->in_manual_add = 0;
-}
-
-
-void
-clear_cookies(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page; (void) argv; (void) result;
-
- // Replace the current cookie jar with a new empty jar
- soup_session_remove_feature (uzbl.net.soup_session,
- SOUP_SESSION_FEATURE (uzbl.net.soup_cookie_jar));
- g_object_unref (G_OBJECT (uzbl.net.soup_cookie_jar));
- uzbl.net.soup_cookie_jar = uzbl_cookie_jar_new ();
- soup_session_add_feature(uzbl.net.soup_session,
- SOUP_SESSION_FEATURE (uzbl.net.soup_cookie_jar));
-}
-
-void
-download(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void) result;
-
- const gchar *uri = argv_idx(argv, 0);
- const gchar *destination = NULL;
- if(argv->len > 1)
- destination = argv_idx(argv, 1);
-
- WebKitNetworkRequest *req = webkit_network_request_new(uri);
- WebKitDownload *download = webkit_download_new(req);
-
- download_cb(web_view, download, (gpointer)destination);
-
- if(webkit_download_get_destination_uri(download))
- webkit_download_start(download);
- else
- g_object_unref(download);
-
- g_object_unref(req);
+run_command_file(const gchar *path) {
+ if(!for_each_line_in_file(path, parse_cmd_line_cb, NULL)) {
+ gchar *tmp = g_strdup_printf("File %s can not be read.", path);
+ send_event(COMMAND_ERROR, NULL, TYPE_STR, tmp, NULL);
+ g_free(tmp);
+ }
}
void
@@ -774,13 +482,6 @@ act_dump_config_as_events() {
dump_config_as_events();
}
-void
-load_uri(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void) web_view; (void) result;
- gchar * uri = argv_idx(argv, 0);
- set_var_value("uri", uri ? uri : "");
-}
-
/* Javascript*/
void
eval_js(WebKitWebView * web_view, const gchar *script, GString *result, const char *file) {
@@ -862,40 +563,6 @@ eval_js(WebKitWebView * web_view, const gchar *script, GString *result, const ch
}
void
-run_js (WebKitWebView * web_view, GArray *argv, GString *result) {
- if (argv_idx(argv, 0))
- eval_js(web_view, argv_idx(argv, 0), result, "(command)");
-}
-
-void
-run_external_js (WebKitWebView * web_view, GArray *argv, GString *result) {
- (void) result;
- gchar *path = NULL;
-
- if (argv_idx(argv, 0) &&
- ((path = find_existing_file(argv_idx(argv, 0)))) ) {
- gchar *file_contents = NULL;
-
- GIOChannel *chan = g_io_channel_new_file(path, "r", NULL);
- if (chan) {
- gsize len;
- g_io_channel_read_to_end(chan, &file_contents, &len, NULL);
- g_io_channel_unref (chan);
- }
-
- if (uzbl.state.verbose)
- printf ("External JavaScript file %s loaded\n", argv_idx(argv, 0));
-
- gchar *js = str_replace("%s", argv_idx (argv, 1) ? argv_idx (argv, 1) : "", file_contents);
- g_free (file_contents);
-
- eval_js (web_view, js, result, path);
- g_free (js);
- g_free(path);
- }
-}
-
-void
search_text (WebKitWebView *page, GArray *argv, const gboolean forward) {
if (argv_idx(argv, 0) && (*argv_idx(argv, 0) != '\0')) {
if (g_strcmp0 (uzbl.state.searchtx, argv_idx(argv, 0)) != 0) {
@@ -916,61 +583,6 @@ search_text (WebKitWebView *page, GArray *argv, const gboolean forward) {
}
void
-search_clear(WebKitWebView *page, GArray *argv, GString *result) {
- (void) argv;
- (void) result;
-
- webkit_web_view_unmark_text_matches (page);
- g_free(uzbl.state.searchtx);
- uzbl.state.searchtx = NULL;
-}
-
-void
-search_forward_text (WebKitWebView *page, GArray *argv, GString *result) {
- (void) result;
- search_text(page, argv, TRUE);
-}
-
-void
-search_reverse_text(WebKitWebView *page, GArray *argv, GString *result) {
- (void) result;
- search_text(page, argv, FALSE);
-}
-
-void
-dehilight(WebKitWebView *page, GArray *argv, GString *result) {
- (void) argv; (void) result;
- webkit_web_view_set_highlight_text_matches (page, FALSE);
-}
-
-void
-chain(WebKitWebView *page, GArray *argv, GString *result) {
- (void) page;
- guint i = 0;
- const gchar *cmd;
- GString *r = g_string_new ("");
- while ((cmd = argv_idx(argv, i++))) {
- GArray *a = g_array_new (TRUE, FALSE, sizeof(gchar*));
- const CommandInfo *c = parse_command_parts(cmd, a);
- if (c)
- run_parsed_command(c, a, r);
- g_array_free (a, TRUE);
- }
- if(result)
- g_string_assign (result, r->str);
-
- g_string_free(r, TRUE);
-}
-
-void
-close_uzbl (WebKitWebView *page, GArray *argv, GString *result) {
- (void)page;
- (void)argv;
- (void)result;
- gtk_main_quit ();
-}
-
-void
sharg_append(GArray *a, const gchar *str) {
const gchar *s = (str ? str : "");
g_array_append_val(a, s);
@@ -1089,29 +701,6 @@ spawn(GArray *argv, GString *result, gboolean exec) {
}
void
-spawn_async(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void)web_view; (void)result;
- spawn(argv, NULL, FALSE);
-}
-
-void
-spawn_sync(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void)web_view;
- spawn(argv, result, FALSE);
-}
-
-void
-spawn_sync_exec(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void)web_view;
- if(!result) {
- GString *force_result = g_string_new("");
- spawn(argv, force_result, TRUE);
- g_string_free (force_result, TRUE);
- } else
- spawn(argv, result, TRUE);
-}
-
-void
spawn_sh(GArray *argv, GString *result) {
if (!uzbl.behave.shell_cmd) {
g_printerr ("spawn_sh: shell_cmd is not set!\n");
@@ -1142,18 +731,6 @@ spawn_sh(GArray *argv, GString *result) {
}
void
-spawn_sh_async(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void)web_view; (void)result;
- spawn_sh(argv, NULL);
-}
-
-void
-spawn_sh_sync(WebKitWebView *web_view, GArray *argv, GString *result) {
- (void)web_view; (void)result;
- spawn_sh(argv, result);
-}
-
-void
run_parsed_command(const CommandInfo *c, GArray *a, GString *result) {
/* send the COMMAND_EXECUTED event, except for set and event/request commands */
if(strcmp("set", c->key) &&
@@ -1254,7 +831,6 @@ parse_command(const char *cmd, const char *params, GString *result) {
}
}
-
void
move_statusbar() {
if (!uzbl.gui.scrolled_win && !uzbl.gui.mainbar)
@@ -1587,11 +1163,7 @@ settings_init () {
/* Load config file, if any */
if (s->config_file) {
- if (!for_each_line_in_file(s->config_file, parse_cmd_line_cb, NULL)) {
- gchar *tmp = g_strdup_printf("File %s can not be read.", s->config_file);
- send_event(COMMAND_ERROR, NULL, TYPE_STR, tmp, NULL);
- g_free(tmp);
- }
+ run_command_file(s->config_file);
g_setenv("UZBL_CONFIG", s->config_file, TRUE);
} else if (uzbl.state.verbose)
printf ("No configuration file loaded.\n");