From 443fd2cffcf4608db9212b87f0519c2e999aff02 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Wed, 8 Jul 2009 22:14:10 -0600 Subject: move all the simple stuff from expand_template --- tests/test-expand.c | 34 +++++++++++++++--------------- uzbl.c | 59 +++++++++-------------------------------------------- uzbl.h | 6 +++++- 3 files changed, 33 insertions(+), 66 deletions(-) diff --git a/tests/test-expand.c b/tests/test-expand.c index c114564..a84a413 100644 --- a/tests/test-expand.c +++ b/tests/test-expand.c @@ -32,36 +32,38 @@ extern gchar* expand_template(const char*, gboolean); extern void make_var_to_name_hash(void); void -test_URI (void) { +test_uri (void) { + g_assert_cmpstr(expand("@uri", 0, FALSE), ==, ""); + uzbl.state.uri = g_strdup("http://www.uzbl.org/"); - g_assert_cmpstr(expand_template("URI", FALSE), ==, uzbl.state.uri); + g_assert_cmpstr(expand("@uri", 0, FALSE), ==, uzbl.state.uri); g_free(uzbl.state.uri); } void test_LOAD_PROGRESS (void) { uzbl.gui.sbar.load_progress = 50; - g_assert_cmpstr(expand_template("LOAD_PROGRESS", FALSE), ==, "50"); + g_assert_cmpstr(expand("@LOAD_PROGRESS", 0, FALSE), ==, "50"); } void test_LOAD_PROGRESSBAR (void) { - uzbl.gui.sbar.load_progress = 75; uzbl.gui.sbar.progress_w = 4; + progress_change_cb(NULL, 75, NULL); - g_assert_cmpstr(expand_template("LOAD_PROGRESSBAR", FALSE), ==, "===·"); + g_assert_cmpstr(expand("@LOAD_PROGRESSBAR", 0, FALSE), ==, "===·"); } void test_TITLE (void) { uzbl.gui.main_title = "Lorem Ipsum"; - g_assert_cmpstr(expand_template("TITLE", FALSE), ==, "Lorem Ipsum"); + g_assert_cmpstr(expand("@TITLE", 0, FALSE), ==, "Lorem Ipsum"); } void test_SELECTED_URI (void) { uzbl.state.selected_url = "http://example.org/"; - g_assert_cmpstr(expand_template("SELECTED_URI", FALSE), ==, "http://example.org/"); + g_assert_cmpstr(expand("@SELECTED_URI", 0, FALSE), ==, "http://example.org/"); } void @@ -89,7 +91,7 @@ test_MODE (void) { void test_MSG (void) { uzbl.gui.sbar.msg = "Hello from frosty Edmonton!"; - g_assert_cmpstr(expand_template("MSG", FALSE), ==, "Hello from frosty Edmonton!"); + g_assert_cmpstr(expand("@MSG", 0, FALSE), ==, "Hello from frosty Edmonton!"); } void @@ -184,18 +186,18 @@ main (int argc, char *argv[]) { g_type_init(); g_test_init(&argc, &argv, NULL); - g_test_add_func("/test-expand/URI", test_URI); - g_test_add_func("/test-expand/LOAD_PROGRESS", test_LOAD_PROGRESS); - g_test_add_func("/test-expand/LOAD_PROGRESSBAR", test_LOAD_PROGRESSBAR); - g_test_add_func("/test-expand/TITLE", test_TITLE); - g_test_add_func("/test-expand/SELECTED_URI", test_SELECTED_URI); + g_test_add_func("/test-expand/@uri", test_uri); + g_test_add_func("/test-expand/@LOAD_PROGRESS", test_LOAD_PROGRESS); + g_test_add_func("/test-expand/@LOAD_PROGRESSBAR", test_LOAD_PROGRESSBAR); + g_test_add_func("/test-expand/@TITLE", test_TITLE); + g_test_add_func("/test-expand/@SELECTED_URI", test_SELECTED_URI); g_test_add_func("/test-expand/NAME", test_NAME); g_test_add_func("/test-expand/KEYCMD", test_KEYCMD); g_test_add_func("/test-expand/MODE", test_MODE); g_test_add_func("/test-expand/MSG", test_MSG); - g_test_add_func("/test-expand/WEBKIT_VERSION", test_WEBKIT_VERSION); - g_test_add_func("/test-expand/ARCH_UZBL", test_ARCH_UZBL); - g_test_add_func("/test-expand/COMMIT", test_COMMIT); + g_test_add_func("/test-expand/@WEBKIT_*", test_WEBKIT_VERSION); + g_test_add_func("/test-expand/@ARCH_UZBL", test_ARCH_UZBL); + g_test_add_func("/test-expand/@COMMIT", test_COMMIT); g_test_add_func("/test-expand/cmd_useragent_simple", test_cmd_useragent_simple); g_test_add_func("/test-expand/cmd_useragent_full", test_cmd_useragent_full); diff --git a/uzbl.c b/uzbl.c index 6b01a32..2812570 100644 --- a/uzbl.c +++ b/uzbl.c @@ -161,6 +161,11 @@ const struct { { "WEBKIT_MICRO", PTR_C(uzbl.info.webkit_micro, INT, NULL)}, { "ARCH_UZBL", PTR_C(uzbl.info.arch, STR, NULL)}, { "COMMIT", PTR_C(uzbl.info.commit, STR, NULL)}, + { "LOAD_PROGRESS", PTR_C(uzbl.gui.sbar.load_progress, INT, NULL)}, + { "LOAD_PROGRESSBAR", PTR_C(uzbl.gui.sbar.progress_bar, STR, NULL)}, + { "TITLE", PTR_C(uzbl.gui.main_title, STR, NULL)}, + { "SELECTED_URI", PTR_C(uzbl.state.selected_url, STR, NULL)}, + { "MSG", PTR_C(uzbl.gui.sbar.msg, STR, NULL)}, { NULL, {.ptr = NULL, .type = TYPE_INT, .dump = 0, .writeable = 0, .func = NULL}} }, *n2v_p = var_name_to_ptr; @@ -683,11 +688,15 @@ title_change_cb (WebKitWebView* web_view, GParamSpec param_spec) { update_title(); } -static void +void progress_change_cb (WebKitWebView* page, gint progress, gpointer data) { (void) page; (void) data; uzbl.gui.sbar.load_progress = progress; + + g_free(uzbl.gui.sbar.progress_bar); + uzbl.gui.sbar.progress_bar = build_progressbar_ascii(uzbl.gui.sbar.load_progress); + update_title(); } @@ -1245,49 +1254,6 @@ expand_template(const char *template, gboolean escape_markup) { if(token == G_TOKEN_SYMBOL) { sym = GPOINTER_TO_INT(g_scanner_cur_value(uzbl.scan).v_symbol); switch(sym) { - case SYM_URI: - if(escape_markup) { - buf = uzbl.state.uri? - g_markup_printf_escaped("%s", uzbl.state.uri):g_strdup(""); - g_string_append(ret, buf); - g_free(buf); - } - else - g_string_append(ret, uzbl.state.uri? - uzbl.state.uri:g_strdup("")); - break; - case SYM_LOADPRGS: - buf = itos(uzbl.gui.sbar.load_progress); - g_string_append(ret, buf); - g_free(buf); - break; - case SYM_LOADPRGSBAR: - buf = build_progressbar_ascii(uzbl.gui.sbar.load_progress); - g_string_append(ret, buf); - g_free(buf); - break; - case SYM_TITLE: - if(escape_markup) { - buf = uzbl.gui.main_title? - g_markup_printf_escaped("%s", uzbl.gui.main_title):g_strdup(""); - g_string_append(ret, buf); - g_free(buf); - } - else - g_string_append(ret, uzbl.gui.main_title? - uzbl.gui.main_title:g_strdup("")); - break; - case SYM_SELECTED_URI: - if(escape_markup) { - buf = uzbl.state.selected_url? - g_markup_printf_escaped("%s", uzbl.state.selected_url):g_strdup(""); - g_string_append(ret, buf); - g_free(buf); - } - else - g_string_append(ret, uzbl.state.selected_url? - uzbl.state.selected_url:g_strdup("")); - break; case SYM_NAME: buf = itos(uzbl.xwin); g_string_append(ret, @@ -1310,11 +1276,6 @@ expand_template(const char *template, gboolean escape_markup) { uzbl.behave.insert_mode? uzbl.behave.insert_indicator:uzbl.behave.cmd_indicator); break; - case SYM_MSG: - g_string_append(ret, - uzbl.gui.sbar.msg?uzbl.gui.sbar.msg:""); - break; - /* useragent syms */ default: break; } diff --git a/uzbl.h b/uzbl.h index 275c5c1..2672c25 100644 --- a/uzbl.h +++ b/uzbl.h @@ -42,6 +42,7 @@ typedef struct { gchar *msg; gchar *progress_s, *progress_u; int progress_w; + gchar *progress_bar; } StatusBar; @@ -271,7 +272,7 @@ link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpoin static void title_change_cb (WebKitWebView* web_view, GParamSpec param_spec); -static void +void progress_change_cb (WebKitWebView* page, gint progress, gpointer data); static void @@ -329,6 +330,9 @@ static gboolean run_command(const gchar *command, const guint npre, const gchar **args, const gboolean sync, char **output_stdout); +static char* +build_progressbar_ascii(int percent); + static void spawn(WebKitWebView *web_view, GArray *argv, GString *result); -- cgit v1.2.3