diff options
author | portix <none@none> | 2012-10-02 23:59:15 +0200 |
---|---|---|
committer | portix <none@none> | 2012-10-02 23:59:15 +0200 |
commit | 24ef749b95bfb684bdc465b8a6748873514a69b8 (patch) | |
tree | 3926bfe8a8195d5a73c61959213dac22107b4d81 /src | |
parent | 0ef10deba55e01d553b887c3017cf63fcbe16565 (diff) | |
download | dwb-24ef749b95bfb684bdc465b8a6748873514a69b8.zip |
Update statusbar from scripts
Diffstat (limited to 'src')
-rw-r--r-- | src/dwb.c | 26 | ||||
-rw-r--r-- | src/scripts.c | 41 | ||||
-rw-r--r-- | src/scripts.h | 7 |
3 files changed, 69 insertions, 5 deletions
@@ -483,9 +483,7 @@ dwb_webview_property(GList *gl, WebSettings *s) { void dwb_set_status_bar_text(GtkWidget *label, const char *text, DwbColor *fg, PangoFontDescription *fd, gboolean markup) { if (markup) { - char *escaped = g_markup_escape_text(text, -1); gtk_label_set_markup(GTK_LABEL(label), text); - g_free(escaped); } else { gtk_label_set_text(GTK_LABEL(label), text); @@ -577,6 +575,8 @@ dwb_set_error_message(GList *gl, const char *error, ...) { void dwb_update_uri(GList *gl) { + if (EMIT_SCRIPT(STATUS_BAR)) + return; if (gl != dwb.state.fview) return; View *v = VIEW(gl); @@ -596,7 +596,25 @@ dwb_update_uri(GList *gl) { /* dwb_update_status_text(GList *gl) {{{*/ void dwb_update_status_text(GList *gl, GtkAdjustment *a) { - View *v = gl ? gl->data : dwb.state.fview->data; + g_return_if_fail(gl == dwb.state.fview); + View *v = gl->data; + + gboolean back = webkit_web_view_can_go_back(WEBKIT_WEB_VIEW(v->web)); + gboolean forward = webkit_web_view_can_go_forward(WEBKIT_WEB_VIEW(v->web)); + + if (EMIT_SCRIPT(STATUS_BAR)) { + char *json = util_create_json(5, + CHAR, "ssl", v->status->ssl == SSL_TRUSTED + ? "trusted" : v->status->ssl == SSL_UNTRUSTED + ? "untrusted" : "none", + BOOLEAN, "canGoBack", back, + BOOLEAN, "canGoForward", forward, + BOOLEAN, "scriptsBlocked", (v->status->scripts & SCRIPTS_BLOCKED) != 0, + BOOLEAN, "pluginBlocked", (v->plugins->status & PLUGIN_STATUS_ENABLED) != 0 && + (v->plugins->status & PLUGIN_STATUS_HAS_PLUGIN) != 0); + ScriptSignal signal = { SCRIPTS_WV(gl), SCRIPTS_SIG_META(json, STATUS_BAR, 0) }; + SCRIPTS_EMIT(signal, json); + } if (!a) { a = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(v->scroll)); @@ -604,8 +622,6 @@ dwb_update_status_text(GList *gl, GtkAdjustment *a) { dwb_update_uri(gl); GString *string = g_string_new(NULL); - gboolean back = webkit_web_view_can_go_back(WEBKIT_WEB_VIEW(v->web)); - gboolean forward = webkit_web_view_can_go_forward(WEBKIT_WEB_VIEW(v->web)); const char *bof = back && forward ? " [+-]" : back ? " [+]" : forward ? " [-]" : " "; g_string_append(string, bof); diff --git a/src/scripts.c b/src/scripts.c index dbe8751a..9ef1db0f 100644 --- a/src/scripts.c +++ b/src/scripts.c @@ -79,6 +79,7 @@ static Sigmap m_sigmap[] = { { SCRIPTS_SIG_CLOSE, "close" }, { SCRIPTS_SIG_DOCUMENT_LOADED, "documentLoaded" }, { SCRIPTS_SIG_MOUSE_MOVE, "mouseMove" }, + { SCRIPTS_SIG_STATUS_BAR, "statusBarChange" }, }; @@ -966,6 +967,24 @@ util_domain_from_host(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, s g_free(host); return ret; }/*}}}*//*}}}*/ +static JSValueRef +util_markup_escape(JSContextRef ctx, JSObjectRef f, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) { + char *string = NULL, *escaped = NULL; + if (argc > 0) { + string = js_value_to_char(ctx, argv[0], -1, exc); + if (string != NULL) { + escaped = g_markup_escape_text(string, -1); + g_free(string); + if (escaped != NULL) { + puts(escaped); + JSValueRef ret = js_char_to_value(ctx, escaped); + g_free(escaped); + return ret; + } + } + } + return JSValueMakeNull(ctx); +} /* DATA {{{*/ /* data_get_profile {{{*/ @@ -1247,6 +1266,26 @@ io_error(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t } return JSValueMakeUndefined(ctx); }/*}}}*/ +static JSValueRef +io_status_bar(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) { + if (argc < 1) + return JSValueMakeUndefined(ctx); + JSObjectRef o = JSValueToObject(ctx, argv[0], exc); + if (o == NULL) + return JSValueMakeUndefined(ctx); + char *middle = js_get_string_property(ctx, o, "middle"); + char *right = js_get_string_property(ctx, o, "right"); + if (middle != NULL) { + gtk_label_set_markup(GTK_LABEL(dwb.gui.urilabel), middle); + } + if (right != NULL) { + gtk_label_set_markup(GTK_LABEL(dwb.gui.rstatus), right); + } + + g_free(middle); + g_free(right); + return JSValueMakeUndefined(ctx); +} static JSValueRef io_dir_names(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argc, const JSValueRef argv[], JSValueRef* exc) { @@ -1765,6 +1804,7 @@ create_global_object() { { "dirNames", io_dir_names, kJSDefaultAttributes }, { "notify", io_notify, kJSDefaultAttributes }, { "error", io_error, kJSDefaultAttributes }, + { "statusBar", io_status_bar, kJSDefaultAttributes }, { 0, 0, 0 }, }; class = create_class("io", io_functions, NULL); @@ -1818,6 +1858,7 @@ create_global_object() { JSStaticFunction util_functions[] = { { "domainFromHost", util_domain_from_host, kJSDefaultAttributes }, + { "markupEscape", util_markup_escape, kJSDefaultAttributes }, { 0, 0, 0 }, }; class = create_class("util", util_functions, NULL); diff --git a/src/scripts.h b/src/scripts.h index f1beb70f..6e823aa6 100644 --- a/src/scripts.h +++ b/src/scripts.h @@ -45,6 +45,7 @@ enum SIGNALS { SCRIPTS_SIG_CLOSE, SCRIPTS_SIG_DOCUMENT_LOADED, SCRIPTS_SIG_MOUSE_MOVE, + SCRIPTS_SIG_STATUS_BAR, SCRIPTS_SIG_LAST, } ; @@ -77,6 +78,12 @@ void scripts_completion_activate(void); return true; \ } else g_free(json); \ G_STMT_END +#define SCRIPTS_EMIT(signal, json) G_STMT_START \ + if (scripts_emit(&signal)) { \ + g_free(json); \ + return; \ + } else g_free(json); \ +G_STMT_END #define SCRIPTS_WV(gl) .jsobj = (VIEW(gl)->script_wv) #define SCRIPTS_SIG_META(js, sig, num) .json = js, .signal = SCRIPTS_SIG_##sig, .numobj = num |