diff options
author | portix <none@none> | 2012-12-04 00:45:31 +0100 |
---|---|---|
committer | portix <none@none> | 2012-12-04 00:45:31 +0100 |
commit | 7eb29868217b2e7b96f3a8abcacab60656591776 (patch) | |
tree | 8f2430402d53a4cc5aea3c439df7e7add13c7646 /src | |
parent | 9df243d0c0787acc5305ed49516bc5fe4f7dc32c (diff) | |
download | dwb-7eb29868217b2e7b96f3a8abcacab60656591776.zip |
Indentation in local.c
Diffstat (limited to 'src')
-rw-r--r-- | src/commands.c | 1286 | ||||
-rw-r--r-- | src/local.c | 518 |
2 files changed, 988 insertions, 816 deletions
diff --git a/src/commands.c b/src/commands.c index abc7d81c..6ab6b6aa 100644 --- a/src/commands.c +++ b/src/commands.c @@ -43,818 +43,945 @@ modulo(int x, int y) { /* commands.h {{{*/ /* commands_simple_command(keyMap *km) {{{*/ DwbStatus -commands_simple_command(KeyMap *km) { - gboolean (*func)(void *, void *) = km->map->func; - Arg *arg = &km->map->arg; - arg->e = NULL; - int ret; - - if (dwb.state.mode & AUTO_COMPLETE) { - completion_clean_autocompletion(); - } +commands_simple_command(KeyMap *km) +{ + int ret; + gboolean (*func)(void *, void *) = km->map->func; + Arg *arg = &km->map->arg; + arg->e = NULL; + + if (dwb.state.mode & AUTO_COMPLETE) + { + completion_clean_autocompletion(); + } - ret = func(km, arg); - switch (ret) { - case STATUS_OK: - if (km->map->hide == NEVER_SM) - dwb_set_normal_message(dwb.state.fview, false, "%s:", km->map->n.second); - else if (km->map->hide == ALWAYS_SM) { - gtk_widget_hide(dwb.gui.entry); - CLEAR_COMMAND_TEXT(); - } - break; - case STATUS_ERROR: - dwb_set_error_message(dwb.state.fview, arg->e ? arg->e : km->map->error); - break; - case STATUS_END: - return ret; - default: break; - } - if (! km->map->arg.ro) - km->map->arg.p = NULL; - dwb_clean_key_buffer(); - return ret; + ret = func(km, arg); + switch (ret) + { + case STATUS_OK: + if (km->map->hide == NEVER_SM) + dwb_set_normal_message(dwb.state.fview, false, "%s:", km->map->n.second); + else if (km->map->hide == ALWAYS_SM) + { + gtk_widget_hide(dwb.gui.entry); + CLEAR_COMMAND_TEXT(); + } + break; + case STATUS_ERROR: + dwb_set_error_message(dwb.state.fview, arg->e ? arg->e : km->map->error); + break; + case STATUS_END: + return ret; + default: break; + } + if (! km->map->arg.ro) + km->map->arg.p = NULL; + dwb_clean_key_buffer(); + return ret; }/*}}}*/ static WebKitWebView * -commands_get_webview_with_nummod() { - if (dwb.state.nummod > 0 && dwb.state.nummod <= (gint)g_list_length(dwb.state.views)) - return WEBVIEW(g_list_nth(dwb.state.views, NUMMOD - 1)); - else - return CURRENT_WEBVIEW(); +commands_get_webview_with_nummod() +{ + if (dwb.state.nummod > 0 && dwb.state.nummod <= (gint)g_list_length(dwb.state.views)) + return WEBVIEW(g_list_nth(dwb.state.views, NUMMOD - 1)); + else + return CURRENT_WEBVIEW(); } static GList * -commands_get_view_from_nummod() { - if (dwb.state.nummod > 0 && dwb.state.nummod <= (gint)g_list_length(dwb.state.views)) - return g_list_nth(dwb.state.views, NUMMOD - 1); - return dwb.state.fview; +commands_get_view_from_nummod() +{ + if (dwb.state.nummod > 0 && dwb.state.nummod <= (gint)g_list_length(dwb.state.views)) + return g_list_nth(dwb.state.views, NUMMOD - 1); + return dwb.state.fview; } /* commands_add_view(KeyMap *, Arg *) {{{*/ DwbStatus -commands_add_view(KeyMap *km, Arg *arg) { - view_add(arg->p, false); - if (arg->p == NULL) - dwb_open_startpage(dwb.state.fview); - return STATUS_OK; +commands_add_view(KeyMap *km, Arg *arg) +{ + view_add(arg->p, false); + if (arg->p == NULL) + dwb_open_startpage(dwb.state.fview); + return STATUS_OK; }/*}}}*/ /* commands_set_setting {{{*/ DwbStatus -commands_set_setting(KeyMap *km, Arg *arg) { - dwb.state.mode = arg->n; - entry_focus(); - return STATUS_OK; +commands_set_setting(KeyMap *km, Arg *arg) +{ + dwb.state.mode = arg->n; + entry_focus(); + return STATUS_OK; }/*}}}*/ /* commands_set_key {{{*/ DwbStatus -commands_set_key(KeyMap *km, Arg *arg) { - dwb.state.mode = KEY_MODE; - entry_focus(); - return STATUS_OK; +commands_set_key(KeyMap *km, Arg *arg) +{ + dwb.state.mode = KEY_MODE; + entry_focus(); + return STATUS_OK; }/*}}}*/ /* commands_focus_input {{{*/ DwbStatus -commands_focus_input(KeyMap *km, Arg *a) { - char *value; - DwbStatus ret = STATUS_OK; +commands_focus_input(KeyMap *km, Arg *a) +{ + char *value; + DwbStatus ret = STATUS_OK; + + if ( (value = js_call_as_function(MAIN_FRAME(), CURRENT_VIEW()->js_base, "focusInput", NULL, kJSTypeUndefined, &value)) ) + { + if (!g_strcmp0(value, "_dwb_no_input_")) + ret = STATUS_ERROR; + g_free(value); + } - if ( (value = js_call_as_function(MAIN_FRAME(), CURRENT_VIEW()->js_base, "focusInput", NULL, kJSTypeUndefined, &value)) ) { - if (!g_strcmp0(value, "_dwb_no_input_")) - ret = STATUS_ERROR; - g_free(value); - } - - return ret; + return ret; }/*}}}*/ /* commands_add_search_field(KeyMap *km, Arg *) {{{*/ DwbStatus -commands_add_search_field(KeyMap *km, Arg *a) { - char *value; - if ( (value = js_call_as_function(MAIN_FRAME(), CURRENT_VIEW()->js_base, "addSearchEngine", NULL, kJSTypeUndefined, &value)) ) { - if (!g_strcmp0(value, "_dwb_no_hints_")) { - return STATUS_ERROR; +commands_add_search_field(KeyMap *km, Arg *a) +{ + char *value; + if ( (value = js_call_as_function(MAIN_FRAME(), CURRENT_VIEW()->js_base, "addSearchEngine", NULL, kJSTypeUndefined, &value)) ) { + if (!g_strcmp0(value, "_dwb_no_hints_")) { + return STATUS_ERROR; + } } - } - dwb.state.mode = SEARCH_FIELD_MODE; - dwb_set_normal_message(dwb.state.fview, false, "Keyword:"); - entry_focus(); - g_free(value); - return STATUS_OK; + dwb.state.mode = SEARCH_FIELD_MODE; + dwb_set_normal_message(dwb.state.fview, false, "Keyword:"); + entry_focus(); + g_free(value); + return STATUS_OK; }/*}}}*/ DwbStatus -commands_insert_mode(KeyMap *km, Arg *a) { - return dwb_change_mode(INSERT_MODE); +commands_insert_mode(KeyMap *km, Arg *a) +{ + return dwb_change_mode(INSERT_MODE); } DwbStatus -commands_normal_mode(KeyMap *km, Arg *a) { - dwb_change_mode(NORMAL_MODE, true); - return STATUS_OK; +commands_normal_mode(KeyMap *km, Arg *a) +{ + dwb_change_mode(NORMAL_MODE, true); + return STATUS_OK; } /* commands_toggle_proxy {{{*/ DwbStatus -commands_toggle_proxy(KeyMap *km, Arg *a) { - WebSettings *s = g_hash_table_lookup(dwb.settings, "proxy"); - s->arg_local.b = !s->arg_local.b; +commands_toggle_proxy(KeyMap *km, Arg *a) +{ + WebSettings *s = g_hash_table_lookup(dwb.settings, "proxy"); + s->arg_local.b = !s->arg_local.b; - dwb_set_proxy(NULL, s); + dwb_set_proxy(NULL, s); - return STATUS_OK; + return STATUS_OK; }/*}}}*/ /*commands_find {{{*/ DwbStatus -commands_find(KeyMap *km, Arg *arg) { - View *v = CURRENT_VIEW(); - dwb.state.mode = FIND_MODE; - dwb.state.search_flags = arg->n; - if (v->status->search_string) { - g_free(v->status->search_string); - v->status->search_string = NULL; - } - entry_focus(); - return STATUS_OK; +commands_find(KeyMap *km, Arg *arg) +{ + View *v = CURRENT_VIEW(); + dwb.state.mode = FIND_MODE; + dwb.state.search_flags = arg->n; + + if (v->status->search_string) { + g_free(v->status->search_string); + v->status->search_string = NULL; + } + + entry_focus(); + return STATUS_OK; }/*}}}*/ DwbStatus -commands_search(KeyMap *km, Arg *arg) { - if (!dwb_search(arg)) - return STATUS_ERROR; - return STATUS_OK; +commands_search(KeyMap *km, Arg *arg) +{ + if (!dwb_search(arg)) + return STATUS_ERROR; + return STATUS_OK; } /* commands_show_hints {{{*/ DwbStatus -commands_show_hints(KeyMap *km, Arg *arg) { +commands_show_hints(KeyMap *km, Arg *arg) +{ return dwb_show_hints(arg); }/*}}}*/ DwbStatus -commands_show(KeyMap *km, Arg *arg) { +commands_show(KeyMap *km, Arg *arg) +{ html_load(dwb.state.fview, arg->p); return STATUS_OK; } /* commands_allow_cookie {{{*/ DwbStatus -commands_allow_cookie(KeyMap *km, Arg *arg) { - switch (arg->n) { - case COOKIE_ALLOW_PERSISTENT: - return dwb_soup_allow_cookie(&dwb.fc.cookies_allow, dwb.files[FILES_COOKIES_ALLOW], arg->n); - case COOKIE_ALLOW_SESSION: - return dwb_soup_allow_cookie(&dwb.fc.cookies_session_allow, dwb.files[FILES_COOKIES_SESSION_ALLOW], arg->n); - case COOKIE_ALLOW_SESSION_TMP: - dwb_soup_allow_cookie_tmp(); - break; - default: - break; +commands_allow_cookie(KeyMap *km, Arg *arg) +{ + switch (arg->n) + { + case COOKIE_ALLOW_PERSISTENT: + return dwb_soup_allow_cookie(&dwb.fc.cookies_allow, dwb.files[FILES_COOKIES_ALLOW], arg->n); + case COOKIE_ALLOW_SESSION: + return dwb_soup_allow_cookie(&dwb.fc.cookies_session_allow, dwb.files[FILES_COOKIES_SESSION_ALLOW], arg->n); + case COOKIE_ALLOW_SESSION_TMP: + dwb_soup_allow_cookie_tmp(); + break; + default: + break; - } - return STATUS_OK; + } + return STATUS_OK; }/*}}}*/ /* commands_bookmark {{{*/ DwbStatus -commands_bookmark(KeyMap *km, Arg *arg) { - gboolean noerror = STATUS_ERROR; - if ( (noerror = dwb_prepend_navigation(dwb.state.fview, &dwb.fc.bookmarks)) == STATUS_OK) { - util_file_add_navigation(dwb.files[FILES_BOOKMARKS], dwb.fc.bookmarks->data, true, -1); - dwb.fc.bookmarks = g_list_sort(dwb.fc.bookmarks, (GCompareFunc)util_navigation_compare_first); - dwb_set_normal_message(dwb.state.fview, true, "Saved bookmark: %s", webkit_web_view_get_uri(CURRENT_WEBVIEW())); - } - return noerror; +commands_bookmark(KeyMap *km, Arg *arg) +{ + gboolean noerror = STATUS_ERROR; + if ( (noerror = dwb_prepend_navigation(dwb.state.fview, &dwb.fc.bookmarks)) == STATUS_OK) + { + util_file_add_navigation(dwb.files[FILES_BOOKMARKS], dwb.fc.bookmarks->data, true, -1); + dwb.fc.bookmarks = g_list_sort(dwb.fc.bookmarks, (GCompareFunc)util_navigation_compare_first); + dwb_set_normal_message(dwb.state.fview, true, "Saved bookmark: %s", webkit_web_view_get_uri(CURRENT_WEBVIEW())); + } + return noerror; }/*}}}*/ /* commands_quickmark(KeyMap *km, Arg *arg) {{{*/ DwbStatus -commands_quickmark(KeyMap *km, Arg *arg) { - if (dwb.state.nv == OPEN_NORMAL) - dwb_set_open_mode(arg->i); - entry_focus(); - dwb.state.mode = arg->n; - return STATUS_OK; +commands_quickmark(KeyMap *km, Arg *arg) +{ + if (dwb.state.nv == OPEN_NORMAL) + dwb_set_open_mode(arg->i); + entry_focus(); + dwb.state.mode = arg->n; + return STATUS_OK; }/*}}}*/ /* commands_reload(KeyMap *km, Arg *){{{*/ DwbStatus -commands_reload(KeyMap *km, Arg *arg) { - GList *gl = dwb.state.nummod > 0 && dwb.state.nummod <= (gint)g_list_length(dwb.state.views) - ? g_list_nth(dwb.state.views, dwb.state.nummod-1) - : dwb.state.fview; - dwb_reload(gl); - return STATUS_OK; +commands_reload(KeyMap *km, Arg *arg) +{ + GList *gl = dwb.state.nummod > 0 && dwb.state.nummod <= (gint)g_list_length(dwb.state.views) + ? g_list_nth(dwb.state.views, dwb.state.nummod-1) + : dwb.state.fview; + dwb_reload(gl); + return STATUS_OK; }/*}}}*/ /* commands_reload_bypass_cache {{{*/ DwbStatus -commands_reload_bypass_cache(KeyMap *km, Arg *arg) { - webkit_web_view_reload_bypass_cache(commands_get_webview_with_nummod()); - return STATUS_OK; +commands_reload_bypass_cache(KeyMap *km, Arg *arg) +{ + webkit_web_view_reload_bypass_cache(commands_get_webview_with_nummod()); + return STATUS_OK; } /*}}}*/ /* commands_stop_loading {{{*/ DwbStatus -commands_stop_loading(KeyMap *km, Arg *arg) { - webkit_web_view_stop_loading(commands_get_webview_with_nummod()); - return STATUS_OK; +commands_stop_loading(KeyMap *km, Arg *arg) +{ + webkit_web_view_stop_loading(commands_get_webview_with_nummod()); + return STATUS_OK; } /*}}}*/ /* commands_view_source(Arg) {{{*/ DwbStatus -commands_view_source(KeyMap *km, Arg *arg) { - WebKitWebView *web = CURRENT_WEBVIEW(); - webkit_web_view_set_view_source_mode(web, !webkit_web_view_get_view_source_mode(web)); - webkit_web_view_reload(web); - return STATUS_OK; +commands_view_source(KeyMap *km, Arg *arg) +{ + WebKitWebView *web = CURRENT_WEBVIEW(); + webkit_web_view_set_view_source_mode(web, !webkit_web_view_get_view_source_mode(web)); + webkit_web_view_reload(web); + return STATUS_OK; }/*}}}*/ /* commands_zoom_in(void *arg) {{{*/ DwbStatus -commands_zoom(KeyMap *km, Arg *arg) { - View *v = dwb.state.fview->data; - WebKitWebView *web = WEBKIT_WEB_VIEW(v->web); - - gfloat zoomlevel = MAX(webkit_web_view_get_zoom_level(web) + arg->i * NUMMOD * GET_DOUBLE("zoom-step"), 0); - webkit_web_view_set_zoom_level(web, zoomlevel); - dwb_set_normal_message(dwb.state.fview, true, "Zoomlevel: %d%%", (int)(zoomlevel * 100)); - return STATUS_OK; +commands_zoom(KeyMap *km, Arg *arg) +{ + View *v = dwb.state.fview->data; + WebKitWebView *web = WEBKIT_WEB_VIEW(v->web); + + gfloat zoomlevel = MAX(webkit_web_view_get_zoom_level(web) + arg->i * NUMMOD * GET_DOUBLE("zoom-step"), 0); + webkit_web_view_set_zoom_level(web, zoomlevel); + dwb_set_normal_message(dwb.state.fview, true, "Zoomlevel: %d%%", (int)(zoomlevel * 100)); + return STATUS_OK; }/*}}}*/ /* commands_scroll {{{*/ DwbStatus -commands_scroll(KeyMap *km, Arg *arg) { - GList *gl = arg->p ? arg->p : dwb.state.fview; - dwb_scroll(gl, dwb.misc.scroll_step, arg->n); - return STATUS_OK; +commands_scroll(KeyMap *km, Arg *arg) +{ + GList *gl = arg->p ? arg->p : dwb.state.fview; + dwb_scroll(gl, dwb.misc.scroll_step, arg->n); + return STATUS_OK; }/*}}}*/ /* commands_set_zoom_level(KeyMap *km, Arg *arg) {{{*/ DwbStatus -commands_set_zoom_level(KeyMap *km, Arg *arg) { - GList *gl = arg->p ? arg->p : dwb.state.fview; - double zoomlevel = dwb.state.nummod < 0 ? arg->d : (double)dwb.state.nummod / 100; - webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(((View*)gl->data)->web), zoomlevel); - dwb_set_normal_message(dwb.state.fview, true, "Zoomlevel: %d%%", (int)(zoomlevel * 100)); - return STATUS_OK; +commands_set_zoom_level(KeyMap *km, Arg *arg) +{ + GList *gl = arg->p ? arg->p : dwb.state.fview; + double zoomlevel = dwb.state.nummod < 0 ? arg->d : (double)dwb.state.nummod / 100; + + webkit_web_view_set_zoom_level(WEBKIT_WEB_VIEW(((View*)gl->data)->web), zoomlevel); + dwb_set_normal_message(dwb.state.fview, true, "Zoomlevel: %d%%", (int)(zoomlevel * 100)); + return STATUS_OK; }/*}}}*/ /* History {{{*/ DwbStatus -commands_history(KeyMap *km, Arg *arg) { - return dwb_history(arg); +commands_history(KeyMap *km, Arg *arg) +{ + return dwb_history(arg); }/*}}}*/ /* commands_open(KeyMap *km, Arg *arg) {{{*/ DwbStatus -commands_open(KeyMap *km, Arg *arg) { - if (dwb.state.nv & OPEN_NORMAL) - dwb_set_open_mode(arg->n & ~SET_URL); +commands_open(KeyMap *km, Arg *arg) +{ + if (dwb.state.nv & OPEN_NORMAL) + dwb_set_open_mode(arg->n & ~SET_URL); + + if (arg) + dwb.state.type = arg->i; - if (arg) - dwb.state.type = arg->i; - - if (arg && arg->p && ! (arg->n & SET_URL)) { - dwb_load_uri(NULL, arg->p); - CLEAR_COMMAND_TEXT(); + if (arg && arg->p && ! (arg->n & SET_URL)) + { + dwb_load_uri(NULL, arg->p); + CLEAR_COMMAND_TEXT(); + return STATUS_OK; + } + else + { + entry_focus(); + if (arg && (arg->n & SET_URL)) + entry_set_text(arg->p ? arg->p : CURRENT_URL()); + } return STATUS_OK; - } - else { - entry_focus(); - if (arg && (arg->n & SET_URL)) - entry_set_text(arg->p ? arg->p : CURRENT_URL()); - } - return STATUS_OK; } /*}}}*/ /* commands_open(KeyMap *km, Arg *arg) {{{*/ DwbStatus -commands_open_startpage(KeyMap *km, Arg *arg) { - return dwb_open_startpage(NULL); +commands_open_startpage(KeyMap *km, Arg *arg) +{ + return dwb_open_startpage(NULL); } /*}}}*/ /* commands_remove_view(KeyMap *km, Arg *arg) {{{*/ DwbStatus -commands_remove_view(KeyMap *km, Arg *arg) { - return view_remove(NULL); +commands_remove_view(KeyMap *km, Arg *arg) +{ + return view_remove(NULL); }/*}}}*/ /* commands_focus(KeyMap *km, Arg *arg) {{{*/ DwbStatus -commands_focus(KeyMap *km, Arg *arg) { - if (dwb.state.views->next) { - int pos = modulo(g_list_position(dwb.state.views, dwb.state.fview) + NUMMOD * arg->n, g_list_length(dwb.state.views)); - GList *g = g_list_nth(dwb.state.views, pos); - dwb_focus_view(g); - return STATUS_OK; - } - return STATUS_ERROR; +commands_focus(KeyMap *km, Arg *arg) +{ + if (dwb.state.views->next) + { + int pos = modulo(g_list_position(dwb.state.views, dwb.state.fview) + NUMMOD * arg->n, g_list_length(dwb.state.views)); + GList *g = g_list_nth(dwb.state.views, pos); + dwb_focus_view(g); + return STATUS_OK; + } + return STATUS_ERROR; }/*}}}*/ /* commands_focus_view{{{*/ DwbStatus -commands_focus_nth_view(KeyMap *km, Arg *arg) { - GList *l = NULL; - if (!dwb.state.views->next) - return STATUS_OK; +commands_focus_nth_view(KeyMap *km, Arg *arg) +{ + GList *l = NULL; + if (!dwb.state.views->next) + return STATUS_OK; + + switch (dwb.state.nummod) + { + case 0 : l = g_list_last(dwb.state.views); break; + case -1 : l = g_list_first(dwb.state.views); break; + default : l = g_list_nth(dwb.state.views, dwb.state.nummod - 1); + } - switch (dwb.state.nummod) { - case 0 : l = g_list_last(dwb.state.views); break; - case -1 : l = g_list_first(dwb.state.views); break; - default : l = g_list_nth(dwb.state.views, dwb.state.nummod - 1); - } - if (l == NULL) - return STATUS_ERROR; + if (l == NULL) + return STATUS_ERROR; - dwb_focus_view(l); - return STATUS_OK; + dwb_focus_view(l); + return STATUS_OK; }/*}}}*/ /* commands_yank {{{*/ DwbStatus -commands_yank(KeyMap *km, Arg *arg) { - GdkAtom atom = GDK_POINTER_TO_ATOM(arg->p); - const char *text = NULL; - WebKitWebView *wv = commands_get_webview_with_nummod(); - if (arg->n == CA_URI) - text = webkit_web_view_get_uri(wv); - else if (arg->n == CA_TITLE) - text = webkit_web_view_get_title(wv); +commands_yank(KeyMap *km, Arg *arg) +{ + const char *text = NULL; + GdkAtom atom = GDK_POINTER_TO_ATOM(arg->p); + WebKitWebView *wv = commands_get_webview_with_nummod(); + + if (arg->n == CA_URI) + text = webkit_web_view_get_uri(wv); + else if (arg->n == CA_TITLE) + text = webkit_web_view_get_title(wv); - return dwb_set_clipboard(text, atom); + return dwb_set_clipboard(text, atom); }/*}}}*/ /* commands_paste {{{*/ DwbStatus -commands_paste(KeyMap *km, Arg *arg) { - GdkAtom atom = GDK_POINTER_TO_ATOM(arg->p); - char *text = NULL; - - if ( (text = dwb_clipboard_get_text(atom)) ) { - if (dwb.state.nv == OPEN_NORMAL) - dwb_set_open_mode(arg->n); - dwb_load_uri(NULL, text); - g_free(text); - return STATUS_OK; - } - return STATUS_ERROR; +commands_paste(KeyMap *km, Arg *arg) +{ + GdkAtom atom = GDK_POINTER_TO_ATOM(arg->p); + char *text = NULL; + + if ( (text = dwb_clipboard_get_text(atom)) ) + { + if (dwb.state.nv == OPEN_NORMAL) + dwb_set_open_mode(arg->n); + dwb_load_uri(NULL, text); + g_free(text); + return STATUS_OK; + } + return STATUS_ERROR; }/*}}}*/ /* dwb_entry_movement() {{{*/ DwbStatus -commands_entry_movement(KeyMap *m, Arg *a) { - entry_move_cursor_step(a->n, a->i, a->b); - return STATUS_OK; +commands_entry_movement(KeyMap *m, Arg *a) +{ + entry_move_cursor_step(a->n, a->i, a->b); + return STATUS_OK; }/*}}}*/ /* commands_entry_history_forward {{{*/ DwbStatus -commands_entry_history_forward(KeyMap *km, Arg *a) { - if (dwb.state.mode == COMMAND_MODE) - return entry_history_forward(&dwb.state.last_com_history); - else - return entry_history_forward(&dwb.state.last_nav_history); +commands_entry_history_forward(KeyMap *km, Arg *a) +{ + if (dwb.state.mode == COMMAND_MODE) + return entry_history_forward(&dwb.state.last_com_history); + else + return entry_history_forward(&dwb.state.last_nav_history); }/*}}}*/ /* commands_entry_history_back {{{*/ DwbStatus -commands_entry_history_back(KeyMap *km, Arg *a) { - if (dwb.state.mode == COMMAND_MODE) - return entry_history_back(&dwb.fc.commands, &dwb.state.last_com_history); - else - return entry_history_back(&dwb.fc.navigations, &dwb.state.last_nav_history); +commands_entry_history_back(KeyMap *km, Arg *a) +{ + if (dwb.state.mode == COMMAND_MODE) + return entry_history_back(&dwb.fc.commands, &dwb.state.last_com_history); + else + return entry_history_back(&dwb.fc.navigations, &dwb.state.last_nav_history); }/*}}}*/ /* commands_entry_confirm {{{*/ DwbStatus -commands_entry_confirm(KeyMap *km, Arg *a) { - GdkEventKey e = { .state = 0, .keyval = GDK_KEY_Return }; - gboolean ret; - g_signal_emit_by_name(dwb.gui.entry, "key-press-event", &e, &ret); - return STATUS_OK; +commands_entry_confirm(KeyMap *km, Arg *a) +{ + gboolean ret; + GdkEventKey e = { .state = 0, .keyval = GDK_KEY_Return }; + g_signal_emit_by_name(dwb.gui.entry, "key-press-event", &e, &ret); + + return STATUS_OK; }/*}}}*/ /* commands_entry_escape {{{*/ DwbStatus -commands_entry_escape(KeyMap *km, Arg *a) { - dwb_change_mode(NORMAL_MODE, true); - return STATUS_OK; +commands_entry_escape(KeyMap *km, Arg *a) +{ + dwb_change_mode(NORMAL_MODE, true); + return STATUS_OK; }/*}}}*/ /* commands_save_session {{{*/ DwbStatus -commands_save_session(KeyMap *km, Arg *arg) { - if (arg->n == NORMAL_MODE) { - dwb.state.mode = SAVE_SESSION; - session_save(NULL, SESSION_FORCE); - dwb_end(); - return STATUS_END; - } - else { - dwb.state.mode = arg->n; - entry_focus(); - dwb_set_normal_message(dwb.state.fview, false, "Session name:"); - } - return STATUS_OK; +commands_save_session(KeyMap *km, Arg *arg) +{ + if (arg->n == NORMAL_MODE) + { + dwb.state.mode = SAVE_SESSION; + session_save(NULL, SESSION_FORCE); + dwb_end(); + return STATUS_END; + } + else + { + dwb.state.mode = arg->n; + entry_focus(); + dwb_set_normal_message(dwb.state.fview, false, "Session name:"); + } + return STATUS_OK; }/*}}}*/ /* commands_bookmarks {{{*/ DwbStatus -commands_bookmarks(KeyMap *km, Arg *arg) { - if (!g_list_length(dwb.fc.bookmarks)) { - return STATUS_ERROR; - } - if (dwb.state.nv == OPEN_NORMAL) - dwb_set_open_mode(arg->n); - completion_complete(COMP_BOOKMARK, 0); - entry_focus(); - if (dwb.comps.active_comp != NULL) { - completion_set_entry_text((Completion*)dwb.comps.active_comp->data); - } - return STATUS_OK; +commands_bookmarks(KeyMap *km, Arg *arg) +{ + if (!g_list_length(dwb.fc.bookmarks)) + return STATUS_ERROR; + + if (dwb.state.nv == OPEN_NORMAL) + dwb_set_open_mode(arg->n); + + completion_complete(COMP_BOOKMARK, 0); + entry_focus(); + + if (dwb.comps.active_comp != NULL) + completion_set_entry_text((Completion*)dwb.comps.active_comp->data); + + return STATUS_OK; }/*}}}*/ /* commands_history{{{*/ DwbStatus -commands_complete_type(KeyMap *km, Arg *arg) { - return completion_complete(arg->n, 0); +commands_complete_type(KeyMap *km, Arg *arg) +{ + return completion_complete(arg->n, 0); }/*}}}*/ void -commands_toggle(Arg *arg, const char *filename, GList **tmp, GList **pers, const char *message) { - char *host = NULL; - const char *block = NULL; - gboolean allowed; - if (arg->n & ALLOW_HOST) { - host = dwb_get_host(CURRENT_WEBVIEW()); - block = host; - } - else if (arg->n & ALLOW_URI) { - block = webkit_web_view_get_uri(CURRENT_WEBVIEW()); - } - else if (arg->p) { - block = arg->p; - } - if (block != NULL) { - if (arg->n & ALLOW_TMP) { - GList *l; - if ( (l = g_list_find_custom(*tmp, block, (GCompareFunc)g_strcmp0)) ) { - g_free(l->data); - *tmp = g_list_delete_link(*tmp, l); - allowed = false; - } - else { - *tmp = g_list_prepend(*tmp, g_strdup(block)); - allowed = true; - } - dwb_set_normal_message(dwb.state.fview, true, "%s temporarily %s for %s", message, allowed ? "allowed" : "blocked", block); +commands_toggle(Arg *arg, const char *filename, GList **tmp, GList **pers, const char *message) +{ + char *host = NULL; + const char *block = NULL; + gboolean allowed; + + if (arg->n & ALLOW_HOST) + { + host = dwb_get_host(CURRENT_WEBVIEW()); + block = host; } - else { - allowed = dwb_toggle_allowed(filename, block, pers); - dwb_set_normal_message(dwb.state.fview, true, "%s %s for %s", message, allowed ? "allowed" : "blocked", block); + else if (arg->n & ALLOW_URI) + block = webkit_web_view_get_uri(CURRENT_WEBVIEW()); + else if (arg->p) + block = arg->p; + if (block != NULL) + { + if (arg->n & ALLOW_TMP) + { + GList *l; + if ( (l = g_list_find_custom(*tmp, block, (GCompareFunc)g_strcmp0)) ) + { + g_free(l->data); + *tmp = g_list_delete_link(*tmp, l); + allowed = false; + } + else + { + *tmp = g_list_prepend(*tmp, g_strdup(block)); + allowed = true; + } + dwb_set_normal_message(dwb.state.fview, true, "%s temporarily %s for %s", message, allowed ? "allowed" : "blocked", block); + } + else + { + allowed = dwb_toggle_allowed(filename, block, pers); + dwb_set_normal_message(dwb.state.fview, true, "%s %s for %s", message, allowed ? "allowed" : "blocked", block); + } } - } - else - CLEAR_COMMAND_TEXT(); + else + CLEAR_COMMAND_TEXT(); } DwbStatus -commands_toggle_plugin_blocker(KeyMap *km, Arg *arg) { - commands_toggle(arg, dwb.files[FILES_PLUGINS_ALLOW], &dwb.fc.tmp_plugins, &dwb.fc.pers_plugins, "Plugins"); - return STATUS_OK; +commands_toggle_plugin_blocker(KeyMap *km, Arg *arg) +{ + commands_toggle(arg, dwb.files[FILES_PLUGINS_ALLOW], &dwb.fc.tmp_plugins, &dwb.fc.pers_plugins, "Plugins"); + return STATUS_OK; } /* commands_toggle_scripts {{{ */ DwbStatus -commands_toggle_scripts(KeyMap *km, Arg *arg) { - commands_toggle(arg, dwb.files[FILES_SCRIPTS_ALLOW], &dwb.fc.tmp_scripts, &dwb.fc.pers_scripts, "Scripts"); - return STATUS_OK; +commands_toggle_scripts(KeyMap *km, Arg *arg) +{ + commands_toggle(arg, dwb.files[FILES_SCRIPTS_ALLOW], &dwb.fc.tmp_scripts, &dwb.fc.pers_scripts, "Scripts"); + return STATUS_OK; }/*}}}*/ /* commands_new_window_or_view{{{*/ DwbStatus -commands_new_window_or_view(KeyMap *km, Arg *arg) { - dwb_set_open_mode(arg->n | OPEN_EXPLICIT); - return STATUS_OK; +commands_new_window_or_view(KeyMap *km, Arg *arg) +{ + dwb_set_open_mode(arg->n | OPEN_EXPLICIT); + return STATUS_OK; }/*}}}*/ /* commands_save_files(KeyMap *km, Arg *arg) {{{*/ DwbStatus -commands_save_files(KeyMap *km, Arg *arg) { - if (dwb_save_files(false)) { - dwb_set_normal_message(dwb.state.fview, true, "Configuration files saved"); - return STATUS_OK; +commands_save_files(KeyMap *km, Arg *arg) +{ + if (dwb_save_files(false)) + { + dwb_set_normal_message(dwb.state.fview, true, "Configuration files saved"); + return STATUS_OK; } return STATUS_ERROR; }/*}}}*/ /* commands_undo() {{{*/ DwbStatus -commands_undo(KeyMap *km, Arg *arg) { - if (dwb.state.undo_list) { - WebKitWebView *web = WEBVIEW(view_add(NULL, false)); - WebKitWebBackForwardList *bflist = webkit_web_back_forward_list_new_with_web_view(web); - for (GList *l = dwb.state.undo_list->data; l; l=l->next) { - Navigation *n = l->data; - WebKitWebHistoryItem *item = webkit_web_history_item_new_with_data(n->first, n->second); - webkit_web_back_forward_list_add_item(bflist, item); - if (!l->next) { - webkit_web_view_go_to_back_forward_item(web, item); +commands_undo(KeyMap *km, Arg *arg) +{ + if (dwb.state.undo_list) + { + WebKitWebView *web = WEBVIEW(view_add(NULL, false)); + WebKitWebBackForwardList *bflist = webkit_web_back_forward_list_new_with_web_view(web); + + for (GList *l = dwb.state.undo_list->data; l; l=l->next) + { + Navigation *n = l->data; + WebKitWebHistoryItem *item = webkit_web_history_item_new_with_data(n->first, n->second); + + webkit_web_back_forward_list_add_item(bflist, item); + if (!l->next) + webkit_web_view_go_to_back_forward_item(web, item); + + dwb_navigation_free(n); } - dwb_navigation_free(n); - } - g_list_free(dwb.state.undo_list->data); - dwb.state.undo_list = g_list_delete_link(dwb.state.undo_list, dwb.state.undo_list); - return STATUS_OK; + g_list_free(dwb.state.undo_list->data); + dwb.state.undo_list = g_list_delete_link(dwb.state.undo_list, dwb.state.undo_list); + return STATUS_OK; } return STATUS_ERROR; }/*}}}*/ /* commands_print (Arg *) {{{*/ DwbStatus -commands_print(KeyMap *km, Arg *arg) { - WebKitWebView *wv = commands_get_webview_with_nummod(); - WebKitWebFrame *frame = webkit_web_view_get_focused_frame(wv); - if (frame) { - webkit_web_frame_print(frame); - return STATUS_OK; - } - return STATUS_ERROR; +commands_print(KeyMap *km, Arg *arg) +{ + WebKitWebView *wv = commands_get_webview_with_nummod(); + WebKitWebFrame *frame = webkit_web_view_get_focused_frame(wv); + if (frame) + { + webkit_web_frame_print(frame); + return STATUS_OK; + } + return STATUS_ERROR; }/*}}}*/ /* commands_web_inspector {{{*/ DwbStatus -commands_web_inspector(KeyMap *km, Arg *arg) { - if (GET_BOOL("enable-developer-extras")) { - WebKitWebView *wv = commands_get_webview_with_nummod(); - webkit_web_inspector_show(webkit_web_view_get_inspector(wv)); - return STATUS_OK; - } - return STATUS_ERROR; +commands_web_inspector(KeyMap *km, Arg *arg) +{ + if (GET_BOOL("enable-developer-extras")) + { + WebKitWebView *wv = commands_get_webview_with_nummod(); + webkit_web_inspector_show(webkit_web_view_get_inspector(wv)); + return STATUS_OK; + } + return STATUS_ERROR; }/*}}}*/ /* commands_execute_userscript (Arg *) {{{*/ DwbStatus -commands_execute_userscript(KeyMap *km, Arg *arg) { - if (!dwb.misc.userscripts) - return STATUS_ERROR; - - if (arg->p) { - char *path = g_build_filename(dwb.files[FILES_USERSCRIPTS], arg->p, NULL); - Arg a = { .arg = path }; - dwb_execute_user_script(km, &a); - g_free(path); - } - else { - entry_focus(); - completion_complete(COMP_USERSCRIPT, 0); - } +commands_execute_userscript(KeyMap *km, Arg *arg) +{ + if (!dwb.misc.userscripts) + return STATUS_ERROR; + + if (arg->p) + { + char *path = g_build_filename(dwb.files[FILES_USERSCRIPTS], arg->p, NULL); + Arg a = { .arg = path }; + dwb_execute_user_script(km, &a); + g_free(path); + } + else + { + entry_focus(); + completion_complete(COMP_USERSCRIPT, 0); + } - return STATUS_OK; + return STATUS_OK; }/*}}}*/ /* commands_toggle_hidden_files {{{*/ DwbStatus -commands_toggle_hidden_files(KeyMap *km, Arg *arg) { - dwb.state.hidden_files = !dwb.state.hidden_files; - dwb_reload(dwb.state.fview); - return STATUS_OK; +commands_toggle_hidden_files(KeyMap *km, Arg *arg) +{ + dwb.state.hidden_files = !dwb.state.hidden_files; + dwb_reload(dwb.state.fview); + return STATUS_OK; }/*}}}*/ /* commands_quit {{{*/ DwbStatus -commands_quit(KeyMap *km, Arg *arg) { - dwb_end(); - return STATUS_END; +commands_quit(KeyMap *km, Arg *arg) +{ + dwb_end(); + return STATUS_END; }/*}}}*/ DwbStatus -commands_reload_user_scripts(KeyMap *km, Arg *arg) { - dwb_reload_userscripts(); - return STATUS_OK; +commands_reload_user_scripts(KeyMap *km, Arg *arg) +{ + dwb_reload_userscripts(); + return STATUS_OK; } /* commands_reload_scripts {{{*/ DwbStatus -commands_fullscreen(KeyMap *km, Arg *arg) { - if (dwb.state.bar_visible & BAR_PRESENTATION) - return STATUS_ERROR; - dwb.state.fullscreen = !dwb.state.fullscreen; - if (dwb.state.fullscreen) - gtk_window_fullscreen(GTK_WINDOW(dwb.gui.window)); - else - gtk_window_unfullscreen(GTK_WINDOW(dwb.gui.window)); - return STATUS_OK; +commands_fullscreen(KeyMap *km, Arg *arg) +{ + if (dwb.state.bar_visible & BAR_PRESENTATION) + return STATUS_ERROR; + dwb.state.fullscreen = !dwb.state.fullscreen; + + if (dwb.state.fullscreen) + gtk_window_fullscreen(GTK_WINDOW(dwb.gui.window)); + else + gtk_window_unfullscreen(GTK_WINDOW(dwb.gui.window)); + + return STATUS_OK; }/*}}}*/ /* commands_reload_scripts {{{*/ DwbStatus -commands_open_editor(KeyMap *km, Arg *arg) { - return dwb_open_in_editor(); +commands_open_editor(KeyMap *km, Arg *arg) +{ + return dwb_open_in_editor(); }/*}}}*/ /* dwb_command_mode {{{*/ DwbStatus -commands_command_mode(KeyMap *km, Arg *arg) { - return dwb_change_mode(COMMAND_MODE); +commands_command_mode(KeyMap *km, Arg *arg) +{ + return dwb_change_mode(COMMAND_MODE); }/*}}}*/ /* dwb_command_mode {{{*/ DwbStatus -commands_only(KeyMap *km, Arg *arg) { - DwbStatus ret = STATUS_ERROR; - GList *l = dwb.state.views, *next; - while (l) { - next = l->next; - if (l != dwb.state.fview) { - view_remove(l); - ret = STATUS_OK; +commands_only(KeyMap *km, Arg *arg) +{ + DwbStatus ret = STATUS_ERROR; + GList *l = dwb.state.views, *next; + while (l) + { + next = l->next; + if (l != dwb.state.fview) + { + view_remove(l); + ret = STATUS_OK; + } + l = next; } - l = next; - } - return ret; + return ret; }/*}}}*/ static void -commands_set_bars(int status) { - gtk_widget_set_visible(dwb.gui.topbox, (status & BAR_VIS_TOP) && (GET_BOOL("show-single-tab") || dwb.state.views->next)); - gtk_widget_set_visible(dwb.gui.bottombox, status & BAR_VIS_STATUS); - if ((status & BAR_VIS_STATUS) ) { - dwb_dom_remove_from_parent(WEBKIT_DOM_NODE(CURRENT_VIEW()->hover.element), NULL); - } +commands_set_bars(int status) +{ + gtk_widget_set_visible(dwb.gui.topbox, (status & BAR_VIS_TOP) && (GET_BOOL("show-single-tab") || dwb.state.views->next)); + gtk_widget_set_visible(dwb.gui.bottombox, status & BAR_VIS_STATUS); + if ((status & BAR_VIS_STATUS) ) + dwb_dom_remove_from_parent(WEBKIT_DOM_NODE(CURRENT_VIEW()->hover.element), NULL); } /* commands_toggle_bars {{{*/ DwbStatus -commands_toggle_bars(KeyMap *km, Arg *arg) { - dwb.state.bar_visible ^= arg->n; - commands_set_bars(dwb.state.bar_visible); - return STATUS_OK; +commands_toggle_bars(KeyMap *km, Arg *arg) +{ + dwb.state.bar_visible ^= arg->n; + commands_set_bars(dwb.state.bar_visible); + return STATUS_OK; }/*}}}*/ /* commands_presentation_mode {{{*/ DwbStatus -commands_presentation_mode(KeyMap *km, Arg *arg) { - static int last; - if (dwb.state.bar_visible & BAR_PRESENTATION) { - if (! dwb.state.fullscreen) - gtk_window_unfullscreen(GTK_WINDOW(dwb.gui.window)); - commands_set_bars(last); - dwb.state.bar_visible = last & ~BAR_PRESENTATION; - } - else { - dwb.state.bar_visible |= BAR_PRESENTATION; - if (! dwb.state.fullscreen) - gtk_window_fullscreen(GTK_WINDOW(dwb.gui.window)); - commands_set_bars(0); - last = dwb.state.bar_visible; - dwb.state.bar_visible = BAR_PRESENTATION; - } - return STATUS_OK; +commands_presentation_mode(KeyMap *km, Arg *arg) +{ + static int last; + if (dwb.state.bar_visible & BAR_PRESENTATION) + { + if (! dwb.state.fullscreen) + gtk_window_unfullscreen(GTK_WINDOW(dwb.gui.window)); + + commands_set_bars(last); + dwb.state.bar_visible = last & ~BAR_PRESENTATION; + } + else + { + dwb.state.bar_visible |= BAR_PRESENTATION; + if (! dwb.state.fullscreen) + gtk_window_fullscreen(GTK_WINDOW(dwb.gui.window)); + commands_set_bars(0); + last = dwb.state.bar_visible; + dwb.state.bar_visible = BAR_PRESENTATION; + } + return STATUS_OK; }/*}}}*/ /* commands_toggle_lock_protect {{{*/ DwbStatus -commands_toggle_lock_protect(KeyMap *km, Arg *arg) { +commands_toggle_lock_protect(KeyMap *km, Arg *arg) +{ GList *gl = dwb.state.nummod < 0 ? dwb.state.fview : g_list_nth(dwb.state.views, dwb.state.nummod-1); if (gl == NULL) return STATUS_ERROR; + View *v = VIEW(gl); v->status->lockprotect ^= arg->n; dwb_update_status(gl, NULL); + if (arg->n & LP_VISIBLE && gl != dwb.state.fview) gtk_widget_set_visible(v->scroll, LP_VISIBLE(v)); + return STATUS_OK; }/*}}}*/ /* commands_execute_javascript {{{*/ DwbStatus -commands_execute_javascript(KeyMap *km, Arg *arg) { - static char *script; - if (arg->p == NULL && script == NULL) - return STATUS_ERROR; - if (arg->p) { - FREE0(script); - script = g_strdup(arg->p); - } - WebKitWebView *wv = commands_get_webview_with_nummod(); - dwb_execute_script(webkit_web_view_get_focused_frame(wv), script, false); - return STATUS_OK; +commands_execute_javascript(KeyMap *km, Arg *arg) +{ + static char *script; + if (arg->p == NULL && script == NULL) + return STATUS_ERROR; + if (arg->p) { + FREE0(script); + script = g_strdup(arg->p); + } + WebKitWebView *wv = commands_get_webview_with_nummod(); + dwb_execute_script(webkit_web_view_get_focused_frame(wv), script, false); + return STATUS_OK; }/*}}}*/ /* commands_set {{{*/ DwbStatus -commands_set(KeyMap *km, Arg *arg) { - DwbStatus ret = STATUS_ERROR; - const char *command = util_str_chug(arg->p); - if (command && *command) { - char **args = g_strsplit(command, " ", 2); - if (g_strv_length(args) >= 2) - ret = dwb_set_setting(args[0], args[1], arg->n); - g_strfreev(args); - } - return ret; +commands_set(KeyMap *km, Arg *arg) +{ + DwbStatus ret = STATUS_ERROR; + const char *command = util_str_chug(arg->p); + if (command && *command) + { + char **args = g_strsplit(command, " ", 2); + if (g_strv_length(args) >= 2) + ret = dwb_set_setting(args[0], args[1], arg->n); + g_strfreev(args); + } + return ret; }/*}}}*/ /* commands_set {{{*/ DwbStatus -commands_toggle_setting(KeyMap *km, Arg *arg) { - const char *command = util_str_chug(arg->p); - return dwb_toggle_setting(command, arg->n); +commands_toggle_setting(KeyMap *km, Arg *arg) +{ + const char *command = util_str_chug(arg->p); + return dwb_toggle_setting(command, arg->n); }/*}}}*/ DwbStatus -commands_tab_move(KeyMap *km, Arg *arg) { - int l = g_list_length(dwb.state.views); - int newpos; - if (dwb.state.views->next == NULL) - return STATUS_ERROR; - switch (arg->n) { - case TAB_MOVE_LEFT : newpos = MAX(MIN(l-1, g_list_position(dwb.state.views, dwb.state.fview)-NUMMOD), 0); break; - case TAB_MOVE_RIGHT : newpos = MAX(MIN(l-1, g_list_position(dwb.state.views, dwb.state.fview)+NUMMOD), 0); break; - default : newpos = MAX(MIN(l, NUMMOD)-1, 0); break; - } - gtk_box_reorder_child(GTK_BOX(dwb.gui.topbox), CURRENT_VIEW()->tabevent, l-(newpos+1)); - gtk_box_reorder_child(GTK_BOX(dwb.gui.mainbox), CURRENT_VIEW()->scroll, newpos); - dwb.state.views = g_list_remove_link(dwb.state.views, dwb.state.fview); - GList *sibling = g_list_nth(dwb.state.views, newpos); - g_list_position(dwb.state.fview, sibling); - if (sibling == NULL) { - GList *last = g_list_last(dwb.state.views); - last->next = dwb.state.fview; - dwb.state.fview->prev = last; - } - else if (sibling->prev == NULL) { - dwb.state.views->prev = dwb.state.fview; - dwb.state.fview->next = dwb.state.views; - dwb.state.views = dwb.state.fview; - } - else { - sibling->prev->next = dwb.state.fview; - dwb.state.fview->prev = sibling->prev; - sibling->prev = dwb.state.fview; - dwb.state.fview->next = sibling; - } - dwb_focus(dwb.state.fview); - dwb_update_layout(); - return STATUS_OK; +commands_tab_move(KeyMap *km, Arg *arg) +{ + GList *sibling; + int newpos; + int l = g_list_length(dwb.state.views); + if (dwb.state.views->next == NULL) + return STATUS_ERROR; + switch (arg->n) + { + case TAB_MOVE_LEFT : newpos = MAX(MIN(l-1, g_list_position(dwb.state.views, dwb.state.fview)-NUMMOD), 0); break; + case TAB_MOVE_RIGHT : newpos = MAX(MIN(l-1, g_list_position(dwb.state.views, dwb.state.fview)+NUMMOD), 0); break; + default : newpos = MAX(MIN(l, NUMMOD)-1, 0); break; + } + gtk_box_reorder_child(GTK_BOX(dwb.gui.topbox), CURRENT_VIEW()->tabevent, l-(newpos+1)); + gtk_box_reorder_child(GTK_BOX(dwb.gui.mainbox), CURRENT_VIEW()->scroll, newpos); + + dwb.state.views = g_list_remove_link(dwb.state.views, dwb.state.fview); + + sibling = g_list_nth(dwb.state.views, newpos); + g_list_position(dwb.state.fview, sibling); + + if (sibling == NULL) + { + GList *last = g_list_last(dwb.state.views); + last->next = dwb.state.fview; + dwb.state.fview->prev = last; + } + else if (sibling->prev == NULL) { + dwb.state.views->prev = dwb.state.fview; + dwb.state.fview->next = dwb.state.views; + dwb.state.views = dwb.state.fview; + } + else + { + sibling->prev->next = dwb.state.fview; + dwb.state.fview->prev = sibling->prev; + sibling->prev = dwb.state.fview; + dwb.state.fview->next = sibling; + } + dwb_focus(dwb.state.fview); + dwb_update_layout(); + return STATUS_OK; } DwbStatus -commands_clear_tab(KeyMap *km, Arg *arg) { - GList *gl = commands_get_view_from_nummod(); - view_clear_tab(gl); - return STATUS_OK; +commands_clear_tab(KeyMap *km, Arg *arg) +{ + GList *gl = commands_get_view_from_nummod(); + view_clear_tab(gl); + return STATUS_OK; } DwbStatus -commands_cancel_download(KeyMap *km, Arg *arg) { - return download_cancel(dwb.state.nummod); +commands_cancel_download(KeyMap *km, Arg *arg) +{ + return download_cancel(dwb.state.nummod); } DwbStatus -commands_dump(KeyMap *km, Arg *arg) { - char *data = dwb_get_raw_data(dwb.state.fview); - if (data == NULL) - return STATUS_ERROR; - if (arg->p == NULL) - puts(data); - else { - util_set_file_content(arg->p, data); - arg->p = NULL; - } - return STATUS_OK; +commands_dump(KeyMap *km, Arg *arg) +{ + char *data = dwb_get_raw_data(dwb.state.fview); + if (data == NULL) + return STATUS_ERROR; + + if (arg->p == NULL) + puts(data); + else + { + util_set_file_content(arg->p, data); + arg->p = NULL; + } + return STATUS_OK; } /*{{{*/ DwbStatus -commands_sanitize(KeyMap *km, Arg *arg) { - Sanitize s = util_string_to_sanitize(arg->p); - if (s == SANITIZE_ERROR) { - return STATUS_ERROR; - } - if (s & SANITIZE_HISTORY) { - dwb_free_list(dwb.fc.history, (void_func)dwb_navigation_free); - dwb.fc.history = NULL; - remove(dwb.files[FILES_HISTORY]); - } - if (s & (SANITIZE_HISTORY | SANITIZE_CACHE)) { - for (GList *gl = dwb.state.views; gl; gl=gl->next) { - WebKitWebBackForwardList *bf_list = webkit_web_view_get_back_forward_list(WEBVIEW(gl)); - webkit_web_back_forward_list_clear(bf_list); +commands_sanitize(KeyMap *km, Arg *arg) +{ + Sanitize s = util_string_to_sanitize(arg->p); + if (s == SANITIZE_ERROR) + return STATUS_ERROR; + + if (s & SANITIZE_HISTORY) + { + dwb_free_list(dwb.fc.history, (void_func)dwb_navigation_free); + dwb.fc.history = NULL; + remove(dwb.files[FILES_HISTORY]); } - } - if (s & SANITIZE_COOKIES) { - remove(dwb.files[FILES_COOKIES]); - } - if (s & (SANITIZE_CACHE | SANITIZE_COOKIES)) { - dwb_soup_clear_cookies(); - } - if (s & (SANITIZE_SESSION)) { - session_clear_session(); - } - if (s & (SANITIZE_ALLSESSIONS)) { - remove(dwb.files[FILES_SESSION]); - } - dwb_set_normal_message(dwb.state.fview, true, "Sanitized %s", arg->p ? arg->p : "all"); - return STATUS_OK; + if (s & (SANITIZE_HISTORY | SANITIZE_CACHE)) + { + for (GList *gl = dwb.state.views; gl; gl=gl->next) + { + WebKitWebBackForwardList *bf_list = webkit_web_view_get_back_forward_list(WEBVIEW(gl)); + webkit_web_back_forward_list_clear(bf_list); + } + } + if (s & SANITIZE_COOKIES) + remove(dwb.files[FILES_COOKIES]); + + if (s & (SANITIZE_CACHE | SANITIZE_COOKIES)) + dwb_soup_clear_cookies(); + + if (s & (SANITIZE_SESSION)) + session_clear_session(); + + if (s & (SANITIZE_ALLSESSIONS)) + remove(dwb.files[FILES_SESSION]); + + dwb_set_normal_message(dwb.state.fview, true, "Sanitized %s", arg->p ? arg->p : "all"); + return STATUS_OK; }/*}}}*/ DwbStatus -commands_eval(KeyMap *km, Arg *arg) { - if (arg->p != NULL) { - if (scripts_execute_one(arg->p)) +commands_eval(KeyMap *km, Arg *arg) +{ + if (arg->p != NULL && scripts_execute_one(arg->p)) + { return STATUS_OK; } return STATUS_ERROR; @@ -862,23 +989,27 @@ commands_eval(KeyMap *km, Arg *arg) { /*}}}*/ DwbStatus -commands_download(KeyMap *km, Arg *arg) { - WebKitNetworkRequest *request = webkit_network_request_new(CURRENT_URL()); - if (request != NULL) { - dwb.state.mimetype_request = NULL; - WebKitDownload *download = webkit_download_new(request); - download_get_path(dwb.state.fview, download); - } - return STATUS_OK; +commands_download(KeyMap *km, Arg *arg) +{ + WebKitNetworkRequest *request = webkit_network_request_new(CURRENT_URL()); + if (request != NULL) + { + dwb.state.mimetype_request = NULL; + WebKitDownload *download = webkit_download_new(request); + download_get_path(dwb.state.fview, download); + } + return STATUS_OK; } DwbStatus -commands_toggle_tab(KeyMap *km, Arg *arg) { - GList *last = g_list_nth(dwb.state.views, dwb.state.last_tab); - if (last) { - dwb_focus_view(last); - return STATUS_OK; - } - return STATUS_ERROR; +commands_toggle_tab(KeyMap *km, Arg *arg) +{ + GList *last = g_list_nth(dwb.state.views, dwb.state.last_tab); + if (last) + { + dwb_focus_view(last); + return STATUS_OK; + } + return STATUS_ERROR; } #if 0 @@ -895,37 +1026,40 @@ commands_group_show(KeyMap *km, Arg *arg) { } return STATUS_OK; } -#endif DwbStatus -commands_group_toggle(KeyMap *km, Arg *arg) { - int n = MIN(NUMMOD, 9), i=0; - dwb.state.current_groups ^= (1<<n); - for (GList *gl = dwb.state.views; gl; gl=gl->next, i++) { +commands_group_toggle(KeyMap *km, Arg *arg) +{ + int n = MIN(NUMMOD, 9), i=0; + dwb.state.current_groups ^= (1<<n); + for (GList *gl = dwb.state.views; gl; gl=gl->next, i++) + { - } - printf("%d\n", dwb.state.current_groups); - return STATUS_OK; + } + printf("%d\n", dwb.state.current_groups); + return STATUS_OK; } DwbStatus -commands_group_tag(KeyMap *km, Arg *arg) { - int n = MIN(NUMMOD, 9); - if (dwb.state.nummod > 9 || dwb.state.nummod < 0) - return STATUS_ERROR; - CURRENT_VIEW()->status->group &= (1<<n); - tab_update(dwb.state.fview); - - //if (CURRENT_VIEW()->status->group & (1<<n)) { - // CURRENT_VIEW()->status->group &= ~(1<<n); - // if (!GROUP_VISIBLE(dwb.state.fview)) - // dwb_hide_tab(dwb.state.fview); - // dwb_set_normal_message(dwb.state.fview, true, "Untagged group %d", n); - //} - //else { - // CURRENT_VIEW()->status->group |= 1<<n; - // if (GROUP_VISIBLE(dwb.state.fview)) - // dwb_show_tab(dwb.state.fview); - // dwb_set_normal_message(dwb.state.fview, true, "Tagged group %d", n); - //} +commands_group_tag(KeyMap *km, Arg *arg) +{ + int n = MIN(NUMMOD, 9); + if (dwb.state.nummod > 9 || dwb.state.nummod < 0) + return STATUS_ERROR; + CURRENT_VIEW()->status->group &= (1<<n); + tab_update(dwb.state.fview); + + //if (CURRENT_VIEW()->status->group & (1<<n)) { + // CURRENT_VIEW()->status->group &= ~(1<<n); + // if (!GROUP_VISIBLE(dwb.state.fview)) + // dwb_hide_tab(dwb.state.fview); + // dwb_set_normal_message(dwb.state.fview, true, "Untagged group %d", n); + //} + //else { + // CURRENT_VIEW()->status->group |= 1<<n; + // if (GROUP_VISIBLE(dwb.state.fview)) + // dwb_show_tab(dwb.state.fview); + // dwb_set_normal_message(dwb.state.fview, true, "Tagged group %d", n); + //} - return STATUS_OK; + return STATUS_OK; } +#endif diff --git a/src/local.c b/src/local.c index 64ff7424..32a9a43a 100644 --- a/src/local.c +++ b/src/local.c @@ -29,22 +29,26 @@ /* local_toggle_hidden_cb {{{*/ gboolean -local_toggle_hidden_cb(WebKitDOMElement *el, WebKitDOMEvent *ev, GList *gl) { - dwb.state.hidden_files = webkit_dom_html_input_element_get_checked(WEBKIT_DOM_HTML_INPUT_ELEMENT(el)); - local_check_directory(gl, webkit_web_view_get_uri(WEBVIEW(gl)), false, NULL); - return true; +local_toggle_hidden_cb(WebKitDOMElement *el, WebKitDOMEvent *ev, GList *gl) +{ + dwb.state.hidden_files = webkit_dom_html_input_element_get_checked(WEBKIT_DOM_HTML_INPUT_ELEMENT(el)); + local_check_directory(gl, webkit_web_view_get_uri(WEBVIEW(gl)), false, NULL); + return true; }/*}}}*/ /* local_load_directory_cb {{{*/ void -local_load_directory_cb(WebKitWebView *wv, GParamSpec *p, GList *gl) { - if (webkit_web_view_get_load_status(wv) != WEBKIT_LOAD_FINISHED) - return; - WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv); - WebKitDOMElement *e = webkit_dom_document_get_element_by_id(doc, "dwb_local_checkbox"); - webkit_dom_html_input_element_set_checked(WEBKIT_DOM_HTML_INPUT_ELEMENT(e), dwb.state.hidden_files); - webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(e), "change", G_CALLBACK(local_toggle_hidden_cb), false, gl); - g_signal_handlers_disconnect_by_func(wv, local_load_directory_cb, gl); +local_load_directory_cb(WebKitWebView *wv, GParamSpec *p, GList *gl) +{ + if (webkit_web_view_get_load_status(wv) != WEBKIT_LOAD_FINISHED) + return; + + WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv); + WebKitDOMElement *e = webkit_dom_document_get_element_by_id(doc, "dwb_local_checkbox"); + + webkit_dom_html_input_element_set_checked(WEBKIT_DOM_HTML_INPUT_ELEMENT(e), dwb.state.hidden_files); + webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(e), "change", G_CALLBACK(local_toggle_hidden_cb), false, gl); + g_signal_handlers_disconnect_by_func(wv, local_load_directory_cb, gl); }/*}}}*/ /* local_show_directory(WebKitWebView *, const char *path, gboolean add_to_history) @@ -55,246 +59,280 @@ local_load_directory_cb(WebKitWebView *wv, GParamSpec *p, GList *gl) { * gboolean add_to_history * {{{*/ static void -local_show_directory(GList *gl, const char *path, gboolean add_to_history) { - /* TODO needs fix: when opening local files close commandline */ - char *fullpath; - const char *filename; - char *newpath = NULL; - const char *tmp; - const char *orig_path; - GSList *content = NULL; - GDir *dir = NULL; - GString *buffer; - GError *error = NULL; - if (g_path_is_absolute(path)) { - orig_path = path; - } - else { - /* resolve absolute path */ - char *current_dir = g_get_current_dir(); - char *full = g_build_filename(current_dir, path, NULL); - char **components = g_strsplit(full, "/", -1); - - g_free(current_dir); - g_free(full); - - int up = 0; - char *tmppath = NULL; - for (int i = g_strv_length(components)-1; i>=0; i--) { - if (!g_strcmp0(components[i], "..")) - up++; - else if (! g_strcmp0(components[i], ".")) - continue; - else if (up > 0) - up--; - else { - newpath = g_build_filename("/", components[i], tmppath, NULL); - if (tmppath != NULL) - g_free(tmppath); - tmppath = newpath; - } - } - orig_path = newpath; - g_strfreev(components); - } - - if (! (dir = g_dir_open(orig_path, 0, &error))) { - fprintf(stderr, "dwb error: %s\n", error->message); - g_clear_error(&error); - return; - } - - fullpath = g_build_filename(orig_path, "..", NULL); - content = g_slist_prepend(content, fullpath); - while ( (filename = g_dir_read_name(dir)) ) { - fullpath = g_build_filename(orig_path, filename, NULL); - content = g_slist_prepend(content, fullpath); - } - content = g_slist_sort(content, (GCompareFunc)util_compare_path); - g_dir_close(dir); - buffer = g_string_new(NULL); - for (GSList *l = content; l; l=l->next) { - fullpath = l->data; - filename = g_strrstr(fullpath, "/") + 1; - if (!dwb.state.hidden_files && filename[0] == '.' && filename[1] != '.') - continue; - struct stat st; - char date[50]; - char time[50]; - char size[50]; - char class[30] = { 0 }; - char *link = NULL; - char *printname = NULL; - if (lstat(fullpath, &st) != 0) { - fprintf(stderr, "stat failed for %s\n", fullpath); - continue; - } - strftime(date, sizeof(date), "%x", localtime(&st.st_mtime)); - strftime(time, sizeof(time), "%X", localtime(&st.st_mtime)); - if (st.st_size > BPGB) - snprintf(size, sizeof(size), "%.1fG", (double)st.st_size / BPGB); - else if (st.st_size > BPMB) - snprintf(size, sizeof(size), "%.1fM", (double)st.st_size / BPMB); - else if (st.st_size > BPKB) - snprintf(size, sizeof(size), "%.1fK", (double)st.st_size / BPKB); +local_show_directory(GList *gl, const char *path, gboolean add_to_history) +{ + /* TODO needs fix: when opening local files close commandline */ + char *fullpath; + char *match; + const char *filename; + char *newpath = NULL; + const char *tmp; + const char *orig_path; + GSList *content = NULL; + GDir *dir = NULL; + GString *buffer; + GError *error = NULL; + char *local_file, *filecontent, *favicon, *page; + + if (g_path_is_absolute(path)) + orig_path = path; else - snprintf(size, sizeof(size), "%lu", st.st_size); - - char perm[11]; - int bits = 0; - if (S_ISREG(st.st_mode)) - perm[bits++] = '-'; - else if (S_ISCHR(st.st_mode)) { - perm[bits++] = 'c'; - strcpy(class, "dwb_local_character_device"); - } - else if (S_ISDIR(st.st_mode)) { - perm[bits++] = 'd'; - strcpy(class, "dwb_local_directory"); - } - else if (S_ISBLK(st.st_mode)) { - perm[bits++] = 'b'; - strcpy(class, "dwb_local_blockdevice"); - } - else if (S_ISFIFO(st.st_mode)) { - perm[bits++] = 'f'; - strcpy(class, "dwb_local_fifo"); + { + /* resolve absolute path */ + int up = 0; + char *tmppath = NULL; + char *current_dir = g_get_current_dir(); + char *full = g_build_filename(current_dir, path, NULL); + char **components = g_strsplit(full, "/", -1); + + g_free(current_dir); + g_free(full); + + for (int i = g_strv_length(components)-1; i>=0; i--) + { + if (!g_strcmp0(components[i], "..")) + up++; + else if (! g_strcmp0(components[i], ".")) + continue; + else if (up > 0) + up--; + else + { + newpath = g_build_filename("/", components[i], tmppath, NULL); + if (tmppath != NULL) + g_free(tmppath); + tmppath = newpath; + } + } + orig_path = newpath; + g_strfreev(components); } - else if (S_ISLNK(st.st_mode)) { - perm[bits++] = 'l'; - strcpy(class, "dwb_local_link"); - link = g_file_read_link(fullpath, NULL); - if (link != NULL) { - char *tmp_path = fullpath; - printname = g_strdup_printf("%s -> %s", filename, link); - l->data = fullpath = g_build_filename(orig_path, link, NULL); - g_free(tmp_path); - g_free(link); - } + + if (! (dir = g_dir_open(orig_path, 0, &error))) + { + fprintf(stderr, "dwb error: %s\n", error->message); + g_clear_error(&error); + return; } - /* user permissions */ - perm[bits++] = st.st_mode & S_IRUSR ? 'r' : '-'; - perm[bits++] = st.st_mode & S_IWUSR ? 'w' : '-'; - if (st.st_mode & S_ISUID) { - perm[bits++] = st.st_mode & S_IXUSR ? 's' : 'S'; - strcpy(class, "dwb_local_setuid"); + + fullpath = g_build_filename(orig_path, "..", NULL); + content = g_slist_prepend(content, fullpath); + + while ( (filename = g_dir_read_name(dir)) ) + { + fullpath = g_build_filename(orig_path, filename, NULL); + content = g_slist_prepend(content, fullpath); } - else - perm[bits++] = st.st_mode & S_IXUSR ? 'x' : '-'; - if (st.st_mode & S_IXUSR && *class == 0) - strcpy(class, "dwb_local_executable"); - /* group permissons */ - perm[bits++] = st.st_mode & S_IRGRP ? 'r' : '-'; - perm[bits++] = st.st_mode & S_IWGRP ? 'w' : '-'; - if (st.st_mode & S_ISGID) { - perm[bits++] = st.st_mode & S_IXGRP ? 's' : 'S'; - strcpy(class, "dwb_local_setuid"); + content = g_slist_sort(content, (GCompareFunc)util_compare_path); + g_dir_close(dir); + + buffer = g_string_new(NULL); + for (GSList *l = content; l; l=l->next) + { + fullpath = l->data; + filename = g_strrstr(fullpath, "/") + 1; + if (!dwb.state.hidden_files && filename[0] == '.' && filename[1] != '.') + continue; + struct stat st; + char date[50]; + char time[50]; + char size[50]; + char class[30] = { 0 }; + char *link = NULL; + char *printname = NULL; + char perm[11]; + int bits = 0; + char *tmp_path; + + if (lstat(fullpath, &st) != 0) + { + fprintf(stderr, "stat failed for %s\n", fullpath); + continue; + } + strftime(date, sizeof(date), "%x", localtime(&st.st_mtime)); + strftime(time, sizeof(time), "%X", localtime(&st.st_mtime)); + + if (st.st_size > BPGB) + snprintf(size, sizeof(size), "%.1fG", (double)st.st_size / BPGB); + else if (st.st_size > BPMB) + snprintf(size, sizeof(size), "%.1fM", (double)st.st_size / BPMB); + else if (st.st_size > BPKB) + snprintf(size, sizeof(size), "%.1fK", (double)st.st_size / BPKB); + else + snprintf(size, sizeof(size), "%lu", st.st_size); + + if (S_ISREG(st.st_mode)) + perm[bits++] = '-'; + else if (S_ISCHR(st.st_mode)) + { + perm[bits++] = 'c'; + strcpy(class, "dwb_local_character_device"); + } + else if (S_ISDIR(st.st_mode)) + { + perm[bits++] = 'd'; + strcpy(class, "dwb_local_directory"); + } + else if (S_ISBLK(st.st_mode)) + { + perm[bits++] = 'b'; + strcpy(class, "dwb_local_blockdevice"); + } + else if (S_ISFIFO(st.st_mode)) + { + perm[bits++] = 'f'; + strcpy(class, "dwb_local_fifo"); + } + else if (S_ISLNK(st.st_mode)) + { + perm[bits++] = 'l'; + strcpy(class, "dwb_local_link"); + link = g_file_read_link(fullpath, NULL); + if (link != NULL) + { + tmp_path = fullpath; + printname = g_strdup_printf("%s -> %s", filename, link); + l->data = fullpath = g_build_filename(orig_path, link, NULL); + g_free(tmp_path); + g_free(link); + } + } + /* user permissions */ + perm[bits++] = st.st_mode & S_IRUSR ? 'r' : '-'; + perm[bits++] = st.st_mode & S_IWUSR ? 'w' : '-'; + if (st.st_mode & S_ISUID) + { + perm[bits++] = st.st_mode & S_IXUSR ? 's' : 'S'; + strcpy(class, "dwb_local_setuid"); + } + else + perm[bits++] = st.st_mode & S_IXUSR ? 'x' : '-'; + + if (st.st_mode & S_IXUSR && *class == 0) + strcpy(class, "dwb_local_executable"); + + /* group permissons */ + perm[bits++] = st.st_mode & S_IRGRP ? 'r' : '-'; + perm[bits++] = st.st_mode & S_IWGRP ? 'w' : '-'; + if (st.st_mode & S_ISGID) + { + perm[bits++] = st.st_mode & S_IXGRP ? 's' : 'S'; + strcpy(class, "dwb_local_setuid"); + } + else + perm[bits++] = st.st_mode & S_IXGRP ? 'x' : '-'; + + /* other */ + perm[bits++] = st.st_mode & S_IROTH ? 'r' : '-'; + perm[bits++] = st.st_mode & S_IWOTH ? 'w' : '-'; + if (st.st_mode & S_ISVTX) + { + perm[bits++] = st.st_mode & S_IXOTH ? 't' : 'T'; + strcpy(class, "dwb_local_sticky"); + } + else + perm[bits++] = st.st_mode & S_IXOTH ? 'x' : '-'; + + perm[bits] = '\0'; + + struct passwd *pwd = getpwuid(st.st_uid); + char *user = pwd && pwd->pw_name ? pwd->pw_name : ""; + struct group *grp = getgrgid(st.st_gid); + char *group = grp && grp->gr_name ? grp->gr_name : ""; + + if (*class == 0) + strcpy(class, "dwb_local_regular"); + + g_string_append_printf(buffer, "<div class='dwb_local_table_row'>\ + <div class='dwb_local_header_permission'>%s</div>\ + <div class='dwb_local_header_link'>%"PRId64"</div>\ + <div class='dwb_local_header_user'>%s</div>\ + <div class='dwb_local_header_group'>%s</div>\ + <div class='dwb_local_header_size'>%s</div>\ + <div class='dwb_local_header_date'>%s</div>\ + <div class='dwb_local_header_time'>%s</div>\ + <div class='%s'><a href='%s'>%s</a></div></div>", + perm, (int64_t)st.st_nlink, user, group, size, date, time, class, fullpath, printname == NULL ? filename: printname); + g_free(printname); + } - else - perm[bits++] = st.st_mode & S_IXGRP ? 'x' : '-'; - /* other */ - perm[bits++] = st.st_mode & S_IROTH ? 'r' : '-'; - perm[bits++] = st.st_mode & S_IWOTH ? 'w' : '-'; - if (st.st_mode & S_ISVTX) { - perm[bits++] = st.st_mode & S_IXOTH ? 't' : 'T'; - strcpy(class, "dwb_local_sticky"); + tmp = orig_path+1; + GString *path_buffer = g_string_new("/<a class='dwb_local_headline' href='"); + while ((match = strchr(tmp, '/'))) { + g_string_append_len(path_buffer, orig_path, match-orig_path); + g_string_append(path_buffer, "'>"); + g_string_append_len(path_buffer, tmp, match-tmp); + tmp = match+1; + g_string_append(path_buffer, "</a>/<a href='"); } - else - perm[bits++] = st.st_mode & S_IXOTH ? 'x' : '-'; - perm[bits] = '\0'; - struct passwd *pwd = getpwuid(st.st_uid); - char *user = pwd && pwd->pw_name ? pwd->pw_name : ""; - struct group *grp = getgrgid(st.st_gid); - char *group = grp && grp->gr_name ? grp->gr_name : ""; - if (*class == 0) - strcpy(class, "dwb_local_regular"); - - g_string_append_printf(buffer, "<div class='dwb_local_table_row'>\ - <div class='dwb_local_header_permission'>%s</div>\ - <div class='dwb_local_header_link'>%"PRId64"</div>\ - <div class='dwb_local_header_user'>%s</div>\ - <div class='dwb_local_header_group'>%s</div>\ - <div class='dwb_local_header_size'>%s</div>\ - <div class='dwb_local_header_date'>%s</div>\ - <div class='dwb_local_header_time'>%s</div>\ - <div class='%s'><a href='%s'>%s</a></div></div>", - perm, (int64_t)st.st_nlink, user, group, size, date, time, class, fullpath, printname == NULL ? filename: printname); - g_free(printname); - - } - tmp = orig_path+1; - char *match; - GString *path_buffer = g_string_new("/<a class='dwb_local_headline' href='"); - while ((match = strchr(tmp, '/'))) { g_string_append_len(path_buffer, orig_path, match-orig_path); g_string_append(path_buffer, "'>"); g_string_append_len(path_buffer, tmp, match-tmp); - tmp = match+1; - g_string_append(path_buffer, "</a>/<a href='"); - } - g_string_append_len(path_buffer, orig_path, match-orig_path); - g_string_append(path_buffer, "'>"); - g_string_append_len(path_buffer, tmp, match-tmp); - g_string_append(path_buffer, "</a>"); - - char *local_file = util_get_data_file(LOCAL_FILE, "lib"); - char *filecontent = util_get_file_content(local_file, NULL); - if (filecontent == NULL) /* File doesn't exist or is a directory */ - return; - - char *favicon = dwb_get_stock_item_base64_encoded("gtk-harddisk"); - /* title, favicon, toppath, content */ - char *page = g_strdup_printf(filecontent, orig_path, favicon, path_buffer->str, buffer->str); - - g_free(favicon); - g_free(local_file); - g_free(filecontent); - g_string_free(buffer, true); - g_string_free(path_buffer, true); - - fullpath = g_strdup_printf("file://%s", orig_path); - /* add a history item */ - /* TODO sqlite */ - WebKitWebView *web = WEBVIEW(gl); - if (add_to_history) { - WebKitWebBackForwardList *bf_list = webkit_web_view_get_back_forward_list(web); - WebKitWebHistoryItem *item = webkit_web_history_item_new_with_data(fullpath, fullpath); - webkit_web_back_forward_list_add_item(bf_list, item); - } - - g_signal_connect(web, "notify::load-status", G_CALLBACK(local_load_directory_cb), gl); - webkit_web_view_load_string(web, page, NULL, NULL, fullpath); - - g_free(fullpath); - g_free(page); - g_free(newpath); - - for (GSList *l = content; l; l=l->next) { - g_free(l->data); - } - g_slist_free(content); + g_string_append(path_buffer, "</a>"); + + local_file = util_get_data_file(LOCAL_FILE, "lib"); + filecontent = util_get_file_content(local_file, NULL); + if (filecontent == NULL) /* File doesn't exist or is a directory */ + return; + + favicon = dwb_get_stock_item_base64_encoded("gtk-harddisk"); + /* title, favicon, toppath, content */ + page = g_strdup_printf(filecontent, orig_path, favicon, path_buffer->str, buffer->str); + + g_free(favicon); + g_free(local_file); + g_free(filecontent); + g_string_free(buffer, true); + g_string_free(path_buffer, true); + + fullpath = g_strdup_printf("file://%s", orig_path); + /* add a history item */ + /* TODO sqlite */ + WebKitWebView *web = WEBVIEW(gl); + if (add_to_history) { + WebKitWebBackForwardList *bf_list = webkit_web_view_get_back_forward_list(web); + WebKitWebHistoryItem *item = webkit_web_history_item_new_with_data(fullpath, fullpath); + webkit_web_back_forward_list_add_item(bf_list, item); + } + + g_signal_connect(web, "notify::load-status", G_CALLBACK(local_load_directory_cb), gl); + webkit_web_view_load_string(web, page, NULL, NULL, fullpath); + + g_free(fullpath); + g_free(page); + g_free(newpath); + + for (GSList *l = content; l; l=l->next) + g_free(l->data); + + g_slist_free(content); }/*}}}*/ /* dwb_check_directory(const char *) {{{*/ gboolean -local_check_directory(GList *gl, const char *path, gboolean add_to_history, GError **error) { - char *unescaped = g_uri_unescape_string(path, NULL); - char *local = unescaped; - gboolean ret = true; - if (g_str_has_prefix(local, "file://")) - local += *(local + 8) == '/' ? 8 : 7; - if (!g_file_test(local, G_FILE_TEST_IS_DIR)) { - ret = false; - goto out; - } - if (access(local, R_OK)) - g_set_error(error, 0, 1, "Cannot access %s", local); - int len = strlen (local); - if (len>1 && local[len-1] == '/') - local[len-1] = '\0'; - - local_show_directory(gl, local, add_to_history); +local_check_directory(GList *gl, const char *path, gboolean add_to_history, GError **error) +{ + int len; + char *unescaped = g_uri_unescape_string(path, NULL); + char *local = unescaped; + gboolean ret = true; + if (g_str_has_prefix(local, "file://")) + local += *(local + 8) == '/' ? 8 : 7; + + if (!g_file_test(local, G_FILE_TEST_IS_DIR)) + { + ret = false; + goto out; + } + if (access(local, R_OK)) + g_set_error(error, 0, 1, "Cannot access %s", local); + + len = strlen (local); + if (len>1 && local[len-1] == '/') + local[len-1] = '\0'; + + local_show_directory(gl, local, add_to_history); out: - g_free(unescaped); - return ret; + g_free(unescaped); + return ret; }/*}}}*/ |