diff options
author | portix <none@none> | 2012-03-29 11:57:55 +0200 |
---|---|---|
committer | portix <none@none> | 2012-03-29 11:57:55 +0200 |
commit | f30a5235b76f2a4ae9a93dcd39c1f65d7ff4745b (patch) | |
tree | f97462a8a12109893a0fa21efff410a2053a1cc0 /src | |
parent | 778e8afddec62b2e83d89c5eff2b1d1428e95166 (diff) | |
download | dwb-f30a5235b76f2a4ae9a93dcd39c1f65d7ff4745b.zip |
Reintroducing 'local_set', new command 'toggle_local_setting'
Diffstat (limited to 'src')
-rw-r--r-- | src/adblock.h | 1 | ||||
-rw-r--r-- | src/commands.c | 6 | ||||
-rw-r--r-- | src/completion.c | 2 | ||||
-rw-r--r-- | src/config.h | 15 | ||||
-rw-r--r-- | src/dwb.c | 106 | ||||
-rw-r--r-- | src/dwb.h | 13 | ||||
-rw-r--r-- | src/util.c | 11 | ||||
-rw-r--r-- | src/util.h | 1 |
8 files changed, 80 insertions, 75 deletions
diff --git a/src/adblock.h b/src/adblock.h index ab121d84..70c97dd9 100644 --- a/src/adblock.h +++ b/src/adblock.h @@ -24,6 +24,5 @@ gboolean adblock_running(); void adblock_end(); void adblock_connect(GList *gl); void adblock_disconnect(GList *gl); -void adblock_set_user_stylesheet(const char *file); #endif // ADBLOCK_H diff --git a/src/commands.c b/src/commands.c index ff4f7e10..b6494701 100644 --- a/src/commands.c +++ b/src/commands.c @@ -781,10 +781,8 @@ DwbStatus commands_set(KeyMap *km, Arg *arg) { const char *command = util_str_chug(arg->p); char **args = g_strsplit(command, " ", 2); -#if 0 DwbStatus ret = dwb_set_setting(args[0], args[1], arg->n); -#endif - DwbStatus ret = dwb_set_setting(args[0], args[1], 0); + //DwbStatus ret = dwb_set_setting(args[0], args[1], 0); g_strfreev(args); return ret; }/*}}}*/ @@ -792,7 +790,7 @@ commands_set(KeyMap *km, Arg *arg) { DwbStatus commands_toggle_setting(KeyMap *km, Arg *arg) { const char *command = util_str_chug(arg->p); - return dwb_toggle_setting(command); + return dwb_toggle_setting(command, arg->n); }/*}}}*/ DwbStatus commands_tab_move(KeyMap *km, Arg *arg) { diff --git a/src/completion.c b/src/completion.c index 30d1195b..e1b7b88f 100644 --- a/src/completion.c +++ b/src/completion.c @@ -561,7 +561,7 @@ completion_eval_autocompletion() { /* dwb_set_autcompletion{{{*/ DwbStatus completion_set_autcompletion(GList *l, WebSettings *s) { - dwb.comps.autocompletion = s->arg.b; + dwb.comps.autocompletion = s->arg_local.b; return STATUS_OK; }/*}}}*/ diff --git a/src/config.h b/src/config.h index 509b8ac5..8421c6ba 100644 --- a/src/config.h +++ b/src/config.h @@ -97,9 +97,7 @@ static KeyValue KEYS[] = { { "proxy", { "p" , GDK_CONTROL_MASK, }, }, { "focus_input", { "gi", 0, }, }, { "set_setting", { "ss", 0, }, }, -#if 0 { "set_local_setting", { "sl", 0, }, }, -#endif { "set_key", { "sk", 0, }, }, { "yank", { "yy", 0, }, }, { "yank_primary", { "yY", 0, }, }, @@ -168,14 +166,13 @@ static KeyValue KEYS[] = { { "execute_javascript", { NULL, 0 }, }, { "set", { NULL, 0 }, }, { "toggle_setting", { NULL, 0 }, }, + { "toggle_local_setting", { NULL, 0 }, }, { "tab_move", { "gm", 0 }, }, { "tab_move_left", { "gl", 0 }, }, { "tab_move_right", { "gr", 0 }, }, { "clear_tab", { "gc", 0 }, }, { "cancel_download", { "ad", 0 }, }, -#if 0 { "local_set", { NULL, 0 }, }, -#endif }; /* FUNCTION_MAP{{{*/ @@ -200,7 +197,6 @@ static FunctionMap FMAP [] = { { { "set", "Set a setting", }, CP_COMMANDLINE, (Func)commands_set, "Invalid value", POST_SM, { .p = NULL }, EP_NONE, { NULL }, }, -#if 0 { { "set", "Set a setting", }, CP_COMMANDLINE, (Func)commands_set, "Invalid value", POST_SM, { .p = NULL, .n = SET_GLOBAL }, EP_NONE, { NULL }, }, @@ -208,11 +204,14 @@ static FunctionMap FMAP [] = { { { "local_set", "Set a setting", }, CP_COMMANDLINE, (Func)commands_set, "Invalid value", POST_SM, { .p = NULL, .n = SET_LOCAL }, EP_NONE, { NULL }, }, -#endif { { "toggle_setting", "Toggle a setting", }, CP_COMMANDLINE, (Func)commands_toggle_setting, "Invalid value", POST_SM, - { .p = NULL }, EP_NONE, { "toggle", "tog", NULL }, }, + { .p = NULL , .n = SET_GLOBAL }, EP_NONE, { "toggle", "tog", NULL }, }, + + { { "toggle_local_setting", "Toggle a setting", }, CP_COMMANDLINE, + (Func)commands_toggle_setting, "Invalid value", POST_SM, + { .p = NULL , .n = SET_LOCAL }, EP_NONE, { "loctog", NULL }, }, { { "toggle_bars", "Toggle visibility of status and tabbar" }, CP_COMMANDLINE, (Func) commands_toggle_bars, NULL, ALWAYS_SM, @@ -541,11 +540,9 @@ static FunctionMap FMAP [] = { (Func)commands_set_setting, NULL, NEVER_SM, { .n = SETTINGS_MODE }, EP_NONE, { NULL }, }, -#if 0 { { "set_local_setting", "Set local setting", }, CP_COMMANDLINE | CP_HAS_MODE, (Func)commands_set_setting, NULL, NEVER_SM, { .n = SETTINGS_MODE_LOCAL }, EP_NONE, { NULL }, }, -#endif { { "set_key", "Set keybinding", }, CP_COMMANDLINE | CP_HAS_MODE, (Func)commands_set_key, NULL, NEVER_SM, @@ -126,7 +126,7 @@ static int MAX_COMPLETIONS = 11; static DwbStatus dwb_set_plugin_blocker(GList *gl, WebSettings *s) { View *v = gl->data; - if (s->arg.b) { + if (s->arg_local.b) { plugins_connect(gl); v->plugins->status ^= (v->plugins->status & PLUGIN_STATUS_DISABLED) | PLUGIN_STATUS_ENABLED; } @@ -140,7 +140,7 @@ dwb_set_plugin_blocker(GList *gl, WebSettings *s) { /* dwb_set_adblock {{{*/ void dwb_set_adblock(GList *gl, WebSettings *s) { - if (s->arg.b) { + if (s->arg_local.b) { for (GList *l = dwb.state.views; l; l=l->next) adblock_connect(l); } @@ -153,14 +153,14 @@ dwb_set_adblock(GList *gl, WebSettings *s) { /* dwb_set_cookies {{{ */ static DwbStatus dwb_set_cookies(GList *gl, WebSettings *s) { - dwb.state.cookie_store_policy = dwb_soup_get_cookie_store_policy(s->arg.p); + dwb.state.cookie_store_policy = dwb_soup_get_cookie_store_policy(s->arg_local.p); return STATUS_OK; }/*}}}*/ static DwbStatus dwb_set_ntlm(GList *gl, WebSettings *s) { - dwb_soup_set_ntlm(s->arg.b); + dwb_soup_set_ntlm(s->arg_local.b); return STATUS_OK; } @@ -168,9 +168,9 @@ dwb_set_ntlm(GList *gl, WebSettings *s) { static DwbStatus dwb_set_widget_packing(GList *gl, WebSettings *s) { DwbStatus ret = STATUS_OK; - if (dwb_pack(s->arg.p, true) != STATUS_OK) { - g_free(s->arg.p); - s->arg.p = g_strdup(DEFAULT_WIDGET_PACKING); + if (dwb_pack(s->arg_local.p, true) != STATUS_OK) { + g_free(s->arg_local.p); + s->arg_local.p = g_strdup(DEFAULT_WIDGET_PACKING); ret = STATUS_ERROR; } return ret; @@ -179,7 +179,7 @@ dwb_set_widget_packing(GList *gl, WebSettings *s) { /* dwb_set_private_browsing {{{ */ static DwbStatus dwb_set_private_browsing(GList *gl, WebSettings *s) { - dwb.misc.private_browsing = s->arg.b; + dwb.misc.private_browsing = s->arg_local.b; dwb_webkit_setting(gl, s); return STATUS_OK; }/*}}}*/ @@ -187,13 +187,13 @@ dwb_set_private_browsing(GList *gl, WebSettings *s) { /* dwb_set_new_tab_position_policy {{{ */ static DwbStatus dwb_set_new_tab_position_policy(GList *gl, WebSettings *s) { - if (!g_strcmp0(s->arg.p, "right")) + if (!g_strcmp0(s->arg_local.p, "right")) dwb.misc.tab_position = TAB_POSITION_RIGHT; - else if (!g_strcmp0(s->arg.p, "left")) + else if (!g_strcmp0(s->arg_local.p, "left")) dwb.misc.tab_position = TAB_POSITION_LEFT; - else if (!g_strcmp0(s->arg.p, "rightmost")) + else if (!g_strcmp0(s->arg_local.p, "rightmost")) dwb.misc.tab_position = TAB_POSITION_RIGHTMOST; - else if (!g_strcmp0(s->arg.p, "leftmost")) + else if (!g_strcmp0(s->arg_local.p, "leftmost")) dwb.misc.tab_position = TAB_POSITION_LEFTMOST; else return STATUS_ERROR; @@ -203,8 +203,8 @@ dwb_set_new_tab_position_policy(GList *gl, WebSettings *s) { /* dwb_set_cookie_accept_policy {{{ */ static DwbStatus dwb_set_cookie_accept_policy(GList *gl, WebSettings *s) { - if (dwb_soup_set_cookie_accept_policy(s->arg.p) == STATUS_ERROR) { - s->arg.p = g_strdup("always"); + if (dwb_soup_set_cookie_accept_policy(s->arg_local.p) == STATUS_ERROR) { + s->arg_local.p = g_strdup("always"); return STATUS_ERROR; } return STATUS_OK; @@ -217,10 +217,10 @@ dwb_set_sync_interval(GList *gl, WebSettings *s) { g_source_remove(dwb.misc.synctimer); dwb.misc.synctimer = 0; } - dwb.misc.sync_interval = s->arg.i; + dwb.misc.sync_interval = s->arg_local.i; - if (s->arg.i > 0) { - dwb.misc.synctimer = g_timeout_add_seconds(s->arg.i, dwb_sync_files, NULL); + if (s->arg_local.i > 0) { + dwb.misc.synctimer = g_timeout_add_seconds(s->arg_local.i, dwb_sync_files, NULL); } return STATUS_OK; }/*}}}*/ @@ -228,56 +228,56 @@ dwb_set_sync_interval(GList *gl, WebSettings *s) { /* dwb_set_scroll_step {{{*/ static DwbStatus dwb_set_scroll_step(GList *gl, WebSettings *s) { - dwb.misc.scroll_step = s->arg.d; + dwb.misc.scroll_step = s->arg_local.d; return STATUS_OK; }/*}}}*/ /* dwb_set_startpage(GList *l, WebSettings *){{{*/ static DwbStatus dwb_set_startpage(GList *l, WebSettings *s) { - dwb.misc.startpage = s->arg.p; + dwb.misc.startpage = s->arg_local.p; return STATUS_OK; }/*}}}*/ /* dwb_set_message_delay(GList *l, WebSettings *){{{*/ static DwbStatus dwb_set_message_delay(GList *l, WebSettings *s) { - dwb.misc.message_delay = s->arg.i; + dwb.misc.message_delay = s->arg_local.i; return STATUS_OK; }/*}}}*/ /* dwb_set_history_length(GList *l, WebSettings *){{{*/ static DwbStatus dwb_set_history_length(GList *l, WebSettings *s) { - dwb.misc.history_length = s->arg.i; + dwb.misc.history_length = s->arg_local.i; return STATUS_OK; }/*}}}*/ /* dwb_set_background_tab (GList *, WebSettings *s) {{{*/ static DwbStatus dwb_set_background_tab(GList *l, WebSettings *s) { - dwb.state.background_tabs = s->arg.b; + dwb.state.background_tabs = s->arg_local.b; return STATUS_OK; }/*}}}*/ /* dwb_set_auto_insert_mode {{{*/ static DwbStatus dwb_set_auto_insert_mode(GList *l, WebSettings *s) { - dwb.state.auto_insert_mode = s->arg.b; + dwb.state.auto_insert_mode = s->arg_local.b; return STATUS_OK; }/*}}}*/ /* dwb_set_tabbar_delay {{{*/ static DwbStatus dwb_set_tabbar_delay(GList *l, WebSettings *s) { - dwb.misc.tabbar_delay = s->arg.i; + dwb.misc.tabbar_delay = s->arg_local.i; return STATUS_OK; }/*}}}*/ /* dwb_set_favicon(GList *l, WebSettings *s){{{*/ static DwbStatus dwb_set_favicon(GList *l, WebSettings *s) { - if (!s->arg.b) { + if (!s->arg_local.b) { for (GList *l = dwb.state.views; l; l=l->next) { g_signal_handler_disconnect(WEBVIEW(l), VIEW(l)->status->signals[SIG_ICON_LOADED]); view_set_favicon(l, false); @@ -293,7 +293,7 @@ dwb_set_favicon(GList *l, WebSettings *s) { /* dwb_set_proxy{{{*/ DwbStatus dwb_set_proxy(GList *l, WebSettings *s) { - if (s->arg.b) { + if (s->arg_local.b) { SoupURI *uri = soup_uri_new(dwb.misc.proxyuri); g_object_set(dwb.misc.soupsession, "proxy-uri", uri, NULL); soup_uri_free(uri); @@ -301,7 +301,7 @@ dwb_set_proxy(GList *l, WebSettings *s) { else { g_object_set(dwb.misc.soupsession, "proxy-uri", NULL, NULL); } - dwb_set_normal_message(dwb.state.fview, true, "Set setting proxy: %s", s->arg.b ? "true" : "false"); + dwb_set_normal_message(dwb.state.fview, true, "Set setting proxy: %s", s->arg_local.b ? "true" : "false"); return STATUS_OK; }/*}}}*/ @@ -310,7 +310,7 @@ static DwbStatus dwb_set_scripts(GList *gl, WebSettings *s) { dwb_webkit_setting(gl, s); View *v = VIEW(gl); - if (s->arg.b) + if (s->arg_local.b) v->status->scripts = SCRIPTS_ALLOWED; else v->status->scripts = SCRIPTS_BLOCKED; @@ -320,11 +320,11 @@ dwb_set_scripts(GList *gl, WebSettings *s) { /* dwb_set_user_agent {{{*/ static DwbStatus dwb_set_user_agent(GList *gl, WebSettings *s) { - char *ua = s->arg.p; + char *ua = s->arg_local.p; if (! ua) { char *current_ua; g_object_get(dwb.state.web_settings, "user-agent", ¤t_ua, NULL); - s->arg.p = g_strdup_printf("%s %s/%s", current_ua, NAME, VERSION); + s->arg_local.p = g_strdup_printf("%s %s/%s", current_ua, NAME, VERSION); } dwb_webkit_setting(gl, s); g_hash_table_insert(dwb.settings, g_strdup("user-agent"), s); @@ -337,10 +337,10 @@ static DwbStatus dwb_webkit_setting(GList *gl, WebSettings *s) { WebKitWebSettings *settings = gl ? webkit_web_view_get_settings(WEBVIEW(gl)) : dwb.state.web_settings; switch (s->type) { - case DOUBLE: g_object_set(settings, s->n.first, s->arg.d, NULL); break; - case INTEGER: g_object_set(settings, s->n.first, s->arg.i, NULL); break; - case BOOLEAN: g_object_set(settings, s->n.first, s->arg.b, NULL); break; - case CHAR: g_object_set(settings, s->n.first, !s->arg.p || !g_strcmp0(s->arg.p, "null") ? NULL : (char*)s->arg.p , NULL); break; + case DOUBLE: g_object_set(settings, s->n.first, s->arg_local.d, NULL); break; + case INTEGER: g_object_set(settings, s->n.first, s->arg_local.i, NULL); break; + case BOOLEAN: g_object_set(settings, s->n.first, s->arg_local.b, NULL); break; + case CHAR: g_object_set(settings, s->n.first, !s->arg_local.p || !g_strcmp0(s->arg_local.p, "null") ? NULL : (char*)s->arg_local.p , NULL); break; default: return STATUS_OK; } return STATUS_OK; @@ -351,10 +351,10 @@ static DwbStatus dwb_webview_property(GList *gl, WebSettings *s) { WebKitWebView *web = gl ? WEBVIEW(gl) : CURRENT_WEBVIEW(); switch (s->type) { - case DOUBLE: g_object_set(web, s->n.first, s->arg.d, NULL); break; - case INTEGER: g_object_set(web, s->n.first, s->arg.i, NULL); break; - case BOOLEAN: g_object_set(web, s->n.first, s->arg.b, NULL); break; - case CHAR: g_object_set(web, s->n.first, (char*)s->arg.p, NULL); break; + case DOUBLE: g_object_set(web, s->n.first, s->arg_local.d, NULL); break; + case INTEGER: g_object_set(web, s->n.first, s->arg_local.i, NULL); break; + case BOOLEAN: g_object_set(web, s->n.first, s->arg_local.b, NULL); break; + case CHAR: g_object_set(web, s->n.first, (char*)s->arg_local.p, NULL); break; default: return STATUS_OK; } return STATUS_OK; @@ -1036,7 +1036,7 @@ dwb_apply_settings(WebSettings *s) { }/*}}}*/ DwbStatus -dwb_toggle_setting(const char *key) { +dwb_toggle_setting(const char *key, int scope) { WebSettings *s; DwbStatus ret = STATUS_ERROR; const char *value; @@ -1049,13 +1049,17 @@ dwb_toggle_setting(const char *key) { dwb_set_error_message(dwb.state.fview, "Not a boolean value."); } else { - oldarg = s->arg; - s->arg.b = !s->arg.b; + oldarg = s->arg_local; + s->arg_local.b = !s->arg_local.b; if (dwb_apply_settings(s) != STATUS_ERROR) { - value = s->arg.b ? "true" : "false"; + value = s->arg_local.b ? "true" : "false"; dwb_set_normal_message(dwb.state.fview, true, "Saved setting %s: %s", s->n.first, value); dwb_save_key_value(dwb.files.settings, key, value); ret = STATUS_OK; + if (scope == SET_GLOBAL) + util_arg_copy(&(s->arg), &(s->arg_local)); + + } else { s->arg = oldarg; @@ -1084,19 +1088,16 @@ dwb_set_setting(const char *key, char *value, int scope) { if ( (s = g_hash_table_lookup(t, key)) ) { if ( (a = util_char_to_arg(value, s->type))) { oldarg = s->arg; - s->arg = *a; + s->arg_local = *a; if (dwb_apply_settings(s) != STATUS_ERROR) { -#if 0 if (scope == SET_GLOBAL) { -#endif - dwb_set_normal_message(dwb.state.fview, true, "Saved setting %s: %s", s->n.first, s->type == BOOLEAN ? ( s->arg.b ? "true" : "false") : value); + util_arg_copy(&(s->arg), &(s->arg_local)); + dwb_set_normal_message(dwb.state.fview, true, "Saved setting %s: %s", s->n.first, s->type == BOOLEAN ? ( s->arg_local.b ? "true" : "false") : value); dwb_save_key_value(dwb.files.settings, key, value); -#if 0 } else { - dwb_set_normal_message(dwb.state.fview, true, "Changed %s: %s", s->n.first, s->type == BOOLEAN ? ( s->arg.b ? "true" : "false") : value); + dwb_set_normal_message(dwb.state.fview, true, "Changed %s: %s", s->n.first, s->type == BOOLEAN ? ( s->arg_local.b ? "true" : "false") : value); } -#endif ret = STATUS_OK; } else { @@ -2065,10 +2066,8 @@ dwb_entry_activate(GdkEventKey *e) { return true; case SETTINGS_MODE_LOCAL: case SETTINGS_MODE: token = g_strsplit(GET_TEXT(), " ", 2); -#if 0 - //dwb_set_setting(token[0], token[1], dwb.state.mode == SETTINGS_MODE ? SET_GLOBAL : SET_LOCAL); -#endif - dwb_set_setting(token[0], token[1], 0); + dwb_set_setting(token[0], token[1], dwb.state.mode == SETTINGS_MODE ? SET_GLOBAL : SET_LOCAL); + //dwb_set_setting(token[0], token[1], 0); dwb_change_mode(NORMAL_MODE, false); g_strfreev(token); return true; @@ -3077,6 +3076,7 @@ dwb_init_settings() { dwb_read_settings(); for (l = g_hash_table_get_values(dwb.settings); l; l = l->next) { WebSettings *s = l->data; + util_arg_copy(&(s->arg_local), &(s->arg)); if (s->apply & SETTING_BUILTIN || s->apply & SETTING_ONINIT) { s->func(NULL, s); } @@ -131,10 +131,10 @@ #define DWB_TAB_KEY(e) (e->keyval == GDK_KEY_Tab || e->keyval == GDK_KEY_ISO_Left_Tab) // Settings -#define GET_CHAR(prop) ((char*)(((WebSettings*)g_hash_table_lookup(dwb.settings, prop))->arg.p)) -#define GET_BOOL(prop) (((WebSettings*)g_hash_table_lookup(dwb.settings, prop))->arg.b) -#define GET_INT(prop) (((WebSettings*)g_hash_table_lookup(dwb.settings, prop))->arg.i) -#define GET_DOUBLE(prop) (((WebSettings*)g_hash_table_lookup(dwb.settings, prop))->arg.d) +#define GET_CHAR(prop) ((char*)(((WebSettings*)g_hash_table_lookup(dwb.settings, prop))->arg_local.p)) +#define GET_BOOL(prop) (((WebSettings*)g_hash_table_lookup(dwb.settings, prop))->arg_local.b) +#define GET_INT(prop) (((WebSettings*)g_hash_table_lookup(dwb.settings, prop))->arg_local.i) +#define GET_DOUBLE(prop) (((WebSettings*)g_hash_table_lookup(dwb.settings, prop))->arg_local.d) #define NUMMOD (dwb.state.nummod < 0 ? 1 : dwb.state.nummod) #ifdef DWB_DEBUG @@ -226,12 +226,10 @@ typedef enum { COMP_QUICKMARK, } CompletionType; -#if 0 enum SetSetting { SET_GLOBAL, SET_LOCAL, }; -#endif enum { EP_NONE = 0, EP_COMP_DEFAULT = 1<<1, @@ -568,6 +566,7 @@ struct _WebSettings { DwbType type; Arg arg; S_Func func; + Arg arg_local; }; struct _Plugins { GSList *elements; @@ -844,7 +843,7 @@ void dwb_focus_view(GList *); void dwb_clean_key_buffer(void); void dwb_set_key(const char *, char *); DwbStatus dwb_set_setting(const char *, char *value, int); -DwbStatus dwb_toggle_setting(const char *); +DwbStatus dwb_toggle_setting(const char *, int ); DwbStatus dwb_open_startpage(GList *); void dwb_init_scripts(void); void dwb_reload_userscripts(void); @@ -130,6 +130,17 @@ util_arg_new() { ret->e = NULL; return ret; } +Arg * +util_arg_copy(Arg *dest, Arg *src) { + dest->n = src->n; + dest->i = src->i; + dest->d = src->d; + dest->p = src->p; + dest->arg = src->arg; + dest->b = src->b; + dest->e = src->e; + return dest; +} /* util_char_to_arg(char *value, DwbType type) return: Arg*{{{*/ Arg * util_char_to_arg(char *value, DwbType type) { @@ -93,5 +93,6 @@ Arg * util_arg_new(void); char * util_check_directory(char *); int util_strlen_trailing_space(const char *str); const char * util_str_chug(const char *str); +Arg *util_arg_copy(Arg *dest, Arg *src); #endif |