From: Daniel Carl Date: Sun, 24 Feb 2013 17:38:56 +0000 (+0100) Subject: Split the VpCore struct into the local and global part. X-Git-Url: https://git.owens.tech/assets/static/git-logo.png/assets/static/git-logo.png/git?a=commitdiff_plain;h=4404ba3667a34bcc6343b0e3dc15415bbdb979d0;p=vimb.git Split the VpCore struct into the local and global part. This makes the way to have global configs that are loaded on application start an local settings that are kept for every window/tab. --- diff --git a/src/command.c b/src/command.c index 900f8ce..02398a6 100644 --- a/src/command.c +++ b/src/command.c @@ -97,23 +97,23 @@ static void command_write_input(const char* str); void command_init(void) { guint i; - vp.behave.commands = g_hash_table_new(g_str_hash, g_str_equal); + core.behave.commands = g_hash_table_new(g_str_hash, g_str_equal); for (i = 0; i < LENGTH(cmd_list); i++) { - g_hash_table_insert(vp.behave.commands, (gpointer)cmd_list[i].name, &cmd_list[i]); + g_hash_table_insert(core.behave.commands, (gpointer)cmd_list[i].name, &cmd_list[i]); } } void command_cleanup(void) { - if (vp.behave.commands) { - g_hash_table_destroy(vp.behave.commands); + if (core.behave.commands) { + g_hash_table_destroy(core.behave.commands); } } gboolean command_exists(const char* name) { - return g_hash_table_contains(vp.behave.commands, name); + return g_hash_table_contains(core.behave.commands, name); } gboolean command_run(const char* name, const char* param) @@ -121,7 +121,7 @@ gboolean command_run(const char* name, const char* param) CommandInfo* c = NULL; gboolean result; Arg a; - c = g_hash_table_lookup(vp.behave.commands, name); + c = g_hash_table_lookup(core.behave.commands, name); if (!c) { vp_echo(VP_MSG_ERROR, TRUE, "Command '%s' not found", name); vp_set_mode(VP_MODE_NORMAL, FALSE); @@ -142,7 +142,7 @@ gboolean command_open(const Arg* arg) gboolean result; if (!arg->s || arg->s[0] == '\0') { - Arg a = {arg->i, vp.config.home_page}; + Arg a = {arg->i, core.config.home_page}; return vp_load_uri(&a); } /* check for searchengine handles */ @@ -172,7 +172,7 @@ gboolean command_open_closed(const Arg* arg) gboolean result; Arg a = {arg->i}; - a.s = util_get_file_contents(vp.files[FILES_CLOSED], NULL); + a.s = util_get_file_contents(core.files[FILES_CLOSED], NULL); result = vp_load_uri(&a); g_free(a.s); @@ -250,7 +250,7 @@ gboolean command_scroll(const Arg* arg) gdouble value; int count = vp.state.count ? vp.state.count : 1; if (arg->i & VP_SCROLL_UNIT_LINE) { - value = vp.config.scrollstep; + value = core.config.scrollstep; } else if (arg->i & VP_SCROLL_UNIT_HALFPAGE) { value = gtk_adjustment_get_page_size(adjust) / 2; } else { @@ -529,21 +529,20 @@ gboolean command_zoom(const Arg* arg) gboolean command_history(const Arg* arg) { - State* state = &vp.state; - const int len = g_list_length(state->history); + const int len = g_list_length(core.behave.history); char* message = NULL; - const int count = state->count ? state->count : 1; + const int count = vp.state.count ? vp.state.count : 1; if (!len) { return FALSE; } if (arg->i == VP_SEARCH_BACKWARD) { - state->history_pointer = (len + state->history_pointer - count) % len; + core.behave.history_pointer = (len + core.behave.history_pointer - count) % len; } else { - state->history_pointer = (len + state->history_pointer + count) % len; + core.behave.history_pointer = (len + core.behave.history_pointer + count) % len; } - const char* command = (char*)g_list_nth_data(state->history, state->history_pointer); + const char* command = (char*)g_list_nth_data(core.behave.history, core.behave.history_pointer); message = g_strconcat(arg->s, command, NULL); command_write_input(message); g_free(message); @@ -557,9 +556,9 @@ static void command_write_input(const char* str) /* reset the colors and fonts to defalts */ vp_set_widget_font( vp.gui.inputbox, - &vp.style.input_fg[VP_MSG_NORMAL], - &vp.style.input_bg[VP_MSG_NORMAL], - vp.style.input_font[VP_MSG_NORMAL] + &core.style.input_fg[VP_MSG_NORMAL], + &core.style.input_bg[VP_MSG_NORMAL], + core.style.input_font[VP_MSG_NORMAL] ); /* remove content from input box */ diff --git a/src/completion.c b/src/completion.c index 39ba98b..5ce48ce 100644 --- a/src/completion.c +++ b/src/completion.c @@ -59,11 +59,11 @@ gboolean completion_complete(gboolean back) input = GET_TEXT(); /* TODO move these decision to a more generic place */ if (g_str_has_prefix(input, ":set ")) { - source = g_hash_table_get_keys(vp.settings); + source = g_hash_table_get_keys(core.settings); source = g_list_sort(source, (GCompareFunc)g_strcmp0); vp.comps.completions = completion_init_completion(vp.comps.completions, source, ":set "); } else { - source = g_hash_table_get_keys(vp.behave.commands); + source = g_hash_table_get_keys(core.behave.commands); source = g_list_sort(source, (GCompareFunc)g_strcmp0); vp.comps.completions = completion_init_completion(vp.comps.completions, source, ":"); } @@ -145,7 +145,7 @@ static GList* completion_update(GList* completion, GList* active, gboolean back) Completion *c; int length = g_list_length(completion); - int max = vp.config.max_completion_items; + int max = core.config.max_completion_items; int items = MAX(length, max); int r = (max) % 2; int offset = max / 2 - 1 + r; @@ -197,15 +197,15 @@ static GList* completion_update(GList* completion, GList* active, gboolean back) completion_set_color( old->data, - &vp.style.comp_fg[VP_COMP_NORMAL], - &vp.style.comp_bg[VP_COMP_NORMAL], - vp.style.comp_font[VP_COMP_NORMAL] + &core.style.comp_fg[VP_COMP_NORMAL], + &core.style.comp_bg[VP_COMP_NORMAL], + core.style.comp_font[VP_COMP_NORMAL] ); completion_set_color( new->data, - &vp.style.comp_fg[VP_COMP_ACTIVE], - &vp.style.comp_bg[VP_COMP_ACTIVE], - vp.style.comp_font[VP_COMP_ACTIVE] + &core.style.comp_fg[VP_COMP_ACTIVE], + &core.style.comp_bg[VP_COMP_ACTIVE], + core.style.comp_font[VP_COMP_ACTIVE] ); active = new; @@ -216,7 +216,7 @@ static GList* completion_update(GList* completion, GList* active, gboolean back) /* allow to chenge the direction of display */ static void completion_show(gboolean back) { - guint max = vp.config.max_completion_items; + guint max = core.config.max_completion_items; int i = 0; if (back) { vp.comps.active = g_list_last(vp.comps.completions); @@ -232,9 +232,9 @@ static void completion_show(gboolean back) if (vp.comps.active != NULL) { completion_set_color( vp.comps.active->data, - &vp.style.comp_fg[VP_COMP_ACTIVE], - &vp.style.comp_bg[VP_COMP_ACTIVE], - vp.style.comp_font[VP_COMP_ACTIVE] + &core.style.comp_fg[VP_COMP_ACTIVE], + &core.style.comp_bg[VP_COMP_ACTIVE], + core.style.comp_font[VP_COMP_ACTIVE] ); completion_set_entry_text(vp.comps.active->data); gtk_widget_show(vp.gui.compbox); @@ -289,9 +289,9 @@ static Completion* completion_get_new(const char* label, const char* prefix) completion_set_color( c, - &vp.style.comp_fg[VP_COMP_NORMAL], - &vp.style.comp_bg[VP_COMP_NORMAL], - vp.style.comp_font[VP_COMP_NORMAL] + &core.style.comp_fg[VP_COMP_NORMAL], + &core.style.comp_bg[VP_COMP_NORMAL], + core.style.comp_font[VP_COMP_NORMAL] ); GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1, 1); diff --git a/src/hints.c b/src/hints.c index c90ad50..f1df38d 100644 --- a/src/hints.c +++ b/src/hints.c @@ -273,7 +273,7 @@ static void hints_create_for_window(const char* input, Window* win, gulong hintC gulong left = rect.left - 3; gulong top = rect.top - 3; - dom_element_set_style(hint, HINT_STYLE, left, top, vp.style.hint_style); + dom_element_set_style(hint, HINT_STYLE, left, top, core.style.hint_style); char* num = g_strdup_printf("%li", newHint->num); webkit_dom_html_element_set_inner_text(WEBKIT_DOM_HTML_ELEMENT(hint), num, NULL); @@ -281,8 +281,8 @@ static void hints_create_for_window(const char* input, Window* win, gulong hintC g_free(num); /* change the style of the hinted element */ - dom_element_style_set_property(newHint->elem, "background-color", vp.style.hint_bg); - dom_element_style_set_property(newHint->elem, "color", vp.style.hint_fg); + dom_element_style_set_property(newHint->elem, "background-color", core.style.hint_bg); + dom_element_style_set_property(newHint->elem, "color", core.style.hint_fg); webkit_dom_node_append_child(WEBKIT_DOM_NODE(container), WEBKIT_DOM_NODE(hint), NULL); } @@ -310,7 +310,7 @@ static void hints_focus(const gulong num) Hint* hint = hints_get_hint_by_number(vp.hints.focusNum); if (hint) { /* reset previous focused element */ - dom_element_style_set_property(hint->elem, "background-color", vp.style.hint_bg); + dom_element_style_set_property(hint->elem, "background-color", core.style.hint_bg); doc = webkit_dom_node_get_owner_document(WEBKIT_DOM_NODE(hint->elem)); dom_dispatch_mouse_event(doc, hint->elem, "mouseout", 0); @@ -319,7 +319,7 @@ static void hints_focus(const gulong num) hint = hints_get_hint_by_number(num); if (hint) { /* mark new hint as focused */ - dom_element_style_set_property(hint->elem, "background-color", vp.style.hint_bg_focus); + dom_element_style_set_property(hint->elem, "background-color", core.style.hint_bg_focus); doc = webkit_dom_node_get_owner_document(WEBKIT_DOM_NODE(hint->elem)); dom_dispatch_mouse_event(doc, hint->elem, "mouseover", 0); diff --git a/src/history.c b/src/history.c index 7e5f4d4..817005f 100644 --- a/src/history.c +++ b/src/history.c @@ -24,21 +24,19 @@ extern const int COMMAND_HISTORY_SIZE; void history_cleanup(void) { - g_list_free_full(vp.state.history, (GDestroyNotify)g_free); + g_list_free_full(core.behave.history, (GDestroyNotify)g_free); } void history_append(const char* line) { - State *s = &vp.state; - - if (COMMAND_HISTORY_SIZE <= g_list_length(s->history)) { + if (COMMAND_HISTORY_SIZE <= g_list_length(core.behave.history)) { /* if list is too long - remove items from beginning */ - s->history = g_list_delete_link(s->history, g_list_first(s->history)); + core.behave.history = g_list_delete_link(core.behave.history, g_list_first(core.behave.history)); } - s->history = g_list_append(s->history, g_strdup(line)); + core.behave.history = g_list_append(core.behave.history, g_strdup(line)); } void history_rewind(void) { - vp.state.history_pointer = 0; + core.behave.history_pointer = 0; } diff --git a/src/keybind.c b/src/keybind.c index c71ccc0..0e75b1d 100644 --- a/src/keybind.c +++ b/src/keybind.c @@ -33,17 +33,17 @@ static void keybind_free(Keybind* keybind); void keybind_init(void) { - vp.behave.modkeys = g_string_new(""); + core.behave.modkeys = g_string_new(""); g_signal_connect(G_OBJECT(vp.gui.window), "key-press-event", G_CALLBACK(keybind_keypress_callback), NULL); } void keybind_cleanup(void) { - if (vp.behave.keys) { - g_slist_free_full(vp.behave.keys, (GDestroyNotify)keybind_free); + if (core.behave.keys) { + g_slist_free_full(core.behave.keys, (GDestroyNotify)keybind_free); } - if (vp.behave.modkeys) { - g_string_free(vp.behave.modkeys, TRUE); + if (core.behave.modkeys) { + g_string_free(core.behave.modkeys, TRUE); } } @@ -69,11 +69,11 @@ gboolean keybind_add_from_string(char* keys, const char* command, const Mode mod keybind_str_to_keybind(keys, keybind); /* add the keybinding to the list */ - vp.behave.keys = g_slist_prepend(vp.behave.keys, keybind); + core.behave.keys = g_slist_prepend(core.behave.keys, keybind); /* save the modkey also in the modkey string if not exists already */ - if (keybind->modkey && strchr(vp.behave.modkeys->str, keybind->modkey) == NULL) { - g_string_append_c(vp.behave.modkeys, keybind->modkey); + if (keybind->modkey && strchr(core.behave.modkeys->str, keybind->modkey) == NULL) { + g_string_append_c(core.behave.modkeys, keybind->modkey); } return TRUE; @@ -93,10 +93,10 @@ gboolean keybind_remove_from_string(char* str, const Mode mode) GSList* link = keybind_find(keybind.mode, keybind.modkey, keybind.modmask, keybind.keyval); if (link) { - vp.behave.keys = g_slist_delete_link(vp.behave.keys, link); + core.behave.keys = g_slist_delete_link(core.behave.keys, link); } - if (keybind.modkey && strchr(vp.behave.modkeys->str, keybind.modkey) != NULL) { + if (keybind.modkey && strchr(core.behave.modkeys->str, keybind.modkey) != NULL) { /* remove eventually no more used modkeys */ keybind_rebuild_modkeys(); } @@ -111,17 +111,17 @@ static void keybind_rebuild_modkeys(void) { GSList* link; /* remove previous modkeys */ - if (vp.behave.modkeys) { - g_string_free(vp.behave.modkeys, TRUE); - vp.behave.modkeys = g_string_new(""); + if (core.behave.modkeys) { + g_string_free(core.behave.modkeys, TRUE); + core.behave.modkeys = g_string_new(""); } /* regenerate the modekeys */ - for (link = vp.behave.keys; link != NULL; link = link->next) { + for (link = core.behave.keys; link != NULL; link = link->next) { Keybind* keybind = (Keybind*)link->data; /* if not not exists - add it */ - if (keybind->modkey && strchr(vp.behave.modkeys->str, keybind->modkey) == NULL) { - g_string_append_c(vp.behave.modkeys, keybind->modkey); + if (keybind->modkey && strchr(core.behave.modkeys->str, keybind->modkey) == NULL) { + g_string_append_c(core.behave.modkeys, keybind->modkey); } } } @@ -129,7 +129,7 @@ static void keybind_rebuild_modkeys(void) static GSList* keybind_find(int mode, guint modkey, guint modmask, guint keyval) { GSList* link; - for (link = vp.behave.keys; link != NULL; link = link->next) { + for (link = core.behave.keys; link != NULL; link = link->next) { Keybind* keybind = (Keybind*)link->data; if (keybind->keyval == keyval && keybind->modmask == modmask @@ -244,7 +244,7 @@ static gboolean keybind_keypress_callback(WebKitWebView* webview, GdkEventKey* e return TRUE; } - if (strchr(vp.behave.modkeys->str, keyval) && vp.state.modkey != keyval) { + if (strchr(core.behave.modkeys->str, keyval) && vp.state.modkey != keyval) { vp.state.modkey = (char)keyval; vp_update_statusbar(); diff --git a/src/main.c b/src/main.c index 4239db1..7001611 100644 --- a/src/main.c +++ b/src/main.c @@ -31,7 +31,8 @@ /* variables */ static char **args; -VpCore vp; +VpClient vp; +VpCore core; /* callbacks */ static void vp_webview_progress_cb(WebKitWebView* view, GParamSpec* pspec, gboolean download); @@ -80,13 +81,13 @@ static void vp_set_status(const StatusType status); static void vp_webview_progress_cb(WebKitWebView* view, GParamSpec* pspec, gboolean download) { if (download) { - if (vp.net.downloads) { + if (vp.state.downloads) { vp.state.progress = 0; GList* ptr; - for (ptr = vp.net.downloads; ptr; ptr = g_list_next(ptr)) { + for (ptr = vp.state.downloads; ptr; ptr = g_list_next(ptr)) { vp.state.progress += 100 * webkit_download_get_progress(ptr->data); } - vp.state.progress /= g_list_length(vp.net.downloads); + vp.state.progress /= g_list_length(vp.state.downloads); } } else { vp.state.progress = webkit_web_view_get_progress(view) * 100; @@ -364,10 +365,10 @@ static void vp_set_cookie(SoupCookie* cookie) { SoupDate* date; - SoupCookieJar* jar = soup_cookie_jar_text_new(vp.files[FILES_COOKIE], FALSE); + SoupCookieJar* jar = soup_cookie_jar_text_new(core.files[FILES_COOKIE], FALSE); cookie = soup_cookie_copy(cookie); - if (cookie->expires == NULL && vp.config.cookie_timeout) { - date = soup_date_new_from_time_t(time(NULL) + vp.config.cookie_timeout); + if (cookie->expires == NULL && core.config.cookie_timeout) { + date = soup_date_new_from_time_t(time(NULL) + core.config.cookie_timeout); soup_cookie_set_expires(cookie, date); } soup_cookie_jar_add_cookie(jar, cookie); @@ -378,7 +379,7 @@ static const char* vp_get_cookies(SoupURI *uri) { const char* cookie; - SoupCookieJar* jar = soup_cookie_jar_text_new(vp.files[FILES_COOKIE], TRUE); + SoupCookieJar* jar = soup_cookie_jar_text_new(core.files[FILES_COOKIE], TRUE); cookie = soup_cookie_jar_get_cookies(jar, uri, TRUE); g_object_unref(jar); @@ -391,11 +392,11 @@ void vp_clean_up(void) const char* uri = CURRENT_URL(); /* write last URL into file for recreation */ if (uri) { - g_file_set_contents(vp.files[FILES_CLOSED], uri, -1, NULL); + g_file_set_contents(core.files[FILES_CLOSED], uri, -1, NULL); } for (int i = FILES_FIRST; i < FILES_LAST; i++) { - g_free(vp.files[i]); + g_free(core.files[i]); } command_cleanup(); setting_cleanup(); @@ -521,8 +522,8 @@ void vp_update_statusbar(void) } /* show the active downloads */ - if (vp.net.downloads) { - int num = g_list_length(vp.net.downloads); + if (vp.state.downloads) { + int num = g_list_length(vp.state.downloads); g_string_append_printf(status, " %d %s", num, num == 1 ? "download" : "downloads"); } @@ -552,9 +553,9 @@ void vp_update_statusbar(void) void vp_update_status_style(void) { StatusType type = vp.state.status; - vp_set_widget_font(vp.gui.eventbox, &vp.style.status_fg[type], &vp.style.status_bg[type], vp.style.status_font[type]); - vp_set_widget_font(vp.gui.statusbar.left, &vp.style.status_fg[type], &vp.style.status_bg[type], vp.style.status_font[type]); - vp_set_widget_font(vp.gui.statusbar.right, &vp.style.status_fg[type], &vp.style.status_bg[type], vp.style.status_font[type]); + vp_set_widget_font(vp.gui.eventbox, &core.style.status_fg[type], &core.style.status_bg[type], core.style.status_font[type]); + vp_set_widget_font(vp.gui.statusbar.left, &core.style.status_fg[type], &core.style.status_bg[type], core.style.status_font[type]); + vp_set_widget_font(vp.gui.statusbar.right, &core.style.status_fg[type], &core.style.status_bg[type], core.style.status_font[type]); } void vp_echo(const MessageType type, gboolean hide, const char *error, ...) @@ -574,9 +575,9 @@ void vp_echo(const MessageType type, gboolean hide, const char *error, ...) /* set the collors according to message type */ vp_set_widget_font( vp.gui.inputbox, - &vp.style.input_fg[type], - &vp.style.input_bg[type], - vp.style.input_font[type] + &core.style.input_fg[type], + &core.style.input_bg[type], + core.style.input_font[type] ); gtk_entry_set_text(GTK_ENTRY(vp.gui.inputbox), message); if (hide) { @@ -626,7 +627,7 @@ static void vp_read_config(void) } /* read config from config files */ - char **lines = util_get_lines(vp.files[FILES_CONFIG]); + char **lines = util_get_lines(core.files[FILES_CONFIG]); char *line; if (lines) { @@ -670,8 +671,8 @@ static void vp_init_gui(void) gui->inspector = webkit_web_view_get_inspector(gui->webview); /* init soup session */ - vp.net.soup_session = webkit_get_default_session(); - soup_session_remove_feature_by_type(vp.net.soup_session, soup_cookie_jar_get_type()); + core.soup_session = webkit_get_default_session(); + soup_session_remove_feature_by_type(core.soup_session, soup_cookie_jar_get_type()); /* Create a scrollable area */ gui->scroll = gtk_scrolled_window_new(NULL, NULL); @@ -728,14 +729,14 @@ static void vp_init_files(void) { char* path = util_get_config_dir(); - vp.files[FILES_CONFIG] = g_build_filename(path, "config", NULL); - util_create_file_if_not_exists(vp.files[FILES_CONFIG]); + core.files[FILES_CONFIG] = g_build_filename(path, "config", NULL); + util_create_file_if_not_exists(core.files[FILES_CONFIG]); - vp.files[FILES_COOKIE] = g_build_filename(path, "cookies", NULL); - util_create_file_if_not_exists(vp.files[FILES_COOKIE]); + core.files[FILES_COOKIE] = g_build_filename(path, "cookies", NULL); + util_create_file_if_not_exists(core.files[FILES_COOKIE]); - vp.files[FILES_CLOSED] = g_build_filename(path, "closed", NULL); - util_create_file_if_not_exists(vp.files[FILES_CLOSED]); + core.files[FILES_CLOSED] = g_build_filename(path, "closed", NULL); + util_create_file_if_not_exists(core.files[FILES_CLOSED]); g_free(path); } @@ -784,7 +785,7 @@ static void vp_setup_signals(void) NULL ); - g_signal_connect_after(G_OBJECT(vp.net.soup_session), "request-started", G_CALLBACK(vp_new_request_cb), NULL); + g_signal_connect_after(G_OBJECT(core.soup_session), "request-started", G_CALLBACK(vp_new_request_cb), NULL); /* inspector */ g_signal_connect(G_OBJECT(vp.gui.inspector), "inspect-web-view", G_CALLBACK(vp_inspector_new), NULL); @@ -795,8 +796,8 @@ static void vp_setup_signals(void) static void vp_setup_settings(void) { - g_object_set(vp.net.soup_session, "max-conns", SETTING_MAX_CONNS , NULL); - g_object_set(vp.net.soup_session, "max-conns-per-host", SETTING_MAX_CONNS_PER_HOST, NULL); + g_object_set(core.soup_session, "max-conns", SETTING_MAX_CONNS , NULL); + g_object_set(core.soup_session, "max-conns-per-host", SETTING_MAX_CONNS_PER_HOST, NULL); } static gboolean vp_button_relase_cb(WebKitWebView* webview, GdkEventButton* event, gpointer data) @@ -899,7 +900,7 @@ static gboolean vp_download_requested_cb(WebKitWebView* view, WebKitDownload* do } /* prepare the download target path */ - uri = g_strdup_printf("file://%s%c%s", vp.config.download_dir, G_DIR_SEPARATOR, filename); + uri = g_strdup_printf("file://%s%c%s", core.config.download_dir, G_DIR_SEPARATOR, filename); webkit_download_set_destination_uri(download, uri); g_free(uri); @@ -916,7 +917,7 @@ static gboolean vp_download_requested_cb(WebKitWebView* view, WebKitDownload* do } /* prepend the download to the download list */ - vp.net.downloads = g_list_prepend(vp.net.downloads, download); + vp.state.downloads = g_list_prepend(vp.state.downloads, download); /* connect signal handler to check if the download is done */ g_signal_connect(download, "notify::status", G_CALLBACK(vp_download_progress_cp), NULL); @@ -957,7 +958,7 @@ static void vp_download_progress_cp(WebKitDownload* download, GParamSpec* pspec) g_free(file); /* remove the donwload from the list */ - vp.net.downloads = g_list_remove(vp.net.downloads, download); + vp.state.downloads = g_list_remove(vp.state.downloads, download); vp_update_statusbar(); } @@ -1000,7 +1001,7 @@ int main(int argc, char* argv[]) if (argc > 1) { arg.s = g_strdup(argv[argc - 1]); } else { - arg.s = g_strdup(vp.config.home_page); + arg.s = g_strdup(core.config.home_page); } vp_load_uri(&arg); g_free(arg.s); diff --git a/src/main.h b/src/main.h index 41b8c3d..7c80029 100644 --- a/src/main.h +++ b/src/main.h @@ -227,8 +227,7 @@ typedef struct { gboolean is_inspecting; SearchDirection search_dir; char* search_query; - GList* history; - int history_pointer; + GList* downloads; } State; /* behaviour */ @@ -237,13 +236,10 @@ typedef struct { GSList* keys; GString* modkeys; GSList* searchengines; + GList* history; + int history_pointer; } Behaviour; -typedef struct { - SoupSession* soup_session; - GList* downloads; -} Network; - typedef struct { time_t cookie_timeout; int scrollstep; @@ -289,18 +285,22 @@ typedef struct { typedef struct { Gui gui; State state; - Behaviour behave; + Completions comps; + Hints hints; +} VpClient; + +typedef struct { char* files[FILES_LAST]; - Network net; Config config; - Completions comps; Style style; + Behaviour behave; GHashTable* settings; - Hints hints; + SoupSession* soup_session; } VpCore; /* main object */ -extern VpCore vp; +extern VpClient vp; +extern VpCore core; /* functions */ void vp_update_statusbar(void); diff --git a/src/searchengine.c b/src/searchengine.c index 195146b..dca7541 100644 --- a/src/searchengine.c +++ b/src/searchengine.c @@ -27,8 +27,8 @@ static void searchengine_free(Searchengine* se); void searchengine_cleanup(void) { - if (vp.behave.searchengines) { - g_slist_free_full(vp.behave.searchengines, (GDestroyNotify)searchengine_free); + if (core.behave.searchengines) { + g_slist_free_full(core.behave.searchengines, (GDestroyNotify)searchengine_free); } } @@ -43,7 +43,7 @@ gboolean searchengine_add(const char* handle, const char* uri) s->handle = g_strdup(handle); s->uri = g_strdup(uri); - vp.behave.searchengines = g_slist_prepend(vp.behave.searchengines, s); + core.behave.searchengines = g_slist_prepend(core.behave.searchengines, s); return TRUE; } @@ -57,7 +57,7 @@ gboolean searchengine_remove(const char* handle) g_free(s->handle); g_free(s->uri); - vp.behave.searchengines = g_slist_delete_link(vp.behave.searchengines, list); + core.behave.searchengines = g_slist_delete_link(core.behave.searchengines, list); return TRUE; } @@ -79,7 +79,7 @@ char* searchengine_get_uri(const char* handle) static GSList* searchengine_find(const char* handle) { GSList* s; - for (s = vp.behave.searchengines; s != NULL; s = s->next) { + for (s = core.behave.searchengines; s != NULL; s = s->next) { if (!strcmp(((Searchengine*)s->data)->handle, handle)) { return s; } diff --git a/src/setting.c b/src/setting.c index a128beb..8a8a444 100644 --- a/src/setting.c +++ b/src/setting.c @@ -125,12 +125,12 @@ void setting_init(void) { Setting* s; guint i; - vp.settings = g_hash_table_new(g_str_hash, g_str_equal); + core.settings = g_hash_table_new(g_str_hash, g_str_equal); for (i = 0; i < LENGTH(default_settings); i++) { s = &default_settings[i]; /* use alias as key if available */ - g_hash_table_insert(vp.settings, (gpointer)s->alias != NULL ? s->alias : s->name, s); + g_hash_table_insert(core.settings, (gpointer)s->alias != NULL ? s->alias : s->name, s); /* set the default settings */ s->func(s, FALSE); @@ -139,8 +139,8 @@ void setting_init(void) void setting_cleanup(void) { - if (vp.settings) { - g_hash_table_destroy(vp.settings); + if (core.settings) { + g_hash_table_destroy(core.settings); } } @@ -164,7 +164,7 @@ gboolean setting_run(char* name, const char* param) type = SETTING_GET; } - Setting* s = g_hash_table_lookup(vp.settings, name); + Setting* s = g_hash_table_lookup(core.settings, name); if (!s) { vp_echo(VP_MSG_ERROR, TRUE, "Config '%s' not found", name); return FALSE; @@ -352,9 +352,9 @@ static gboolean setting_webkit(const Setting* s, const SettingType type) static gboolean setting_cookie_timeout(const Setting* s, const SettingType type) { if (type == SETTING_GET) { - setting_print_value(s, &vp.config.cookie_timeout); + setting_print_value(s, &core.config.cookie_timeout); } else { - vp.config.cookie_timeout = s->arg.i; + core.config.cookie_timeout = s->arg.i; } return TRUE; @@ -363,9 +363,9 @@ static gboolean setting_cookie_timeout(const Setting* s, const SettingType type) static gboolean setting_scrollstep(const Setting* s, const SettingType type) { if (type == SETTING_GET) { - setting_print_value(s, &vp.config.scrollstep); + setting_print_value(s, &core.config.scrollstep); } else { - vp.config.scrollstep = s->arg.i; + core.config.scrollstep = s->arg.i; } return TRUE; @@ -383,9 +383,9 @@ static gboolean setting_status_color_bg(const Setting* s, const SettingType type } if (type == SETTING_GET) { - setting_print_value(s, &vp.style.status_bg[stype]); + setting_print_value(s, &core.style.status_bg[stype]); } else { - VP_COLOR_PARSE(&vp.style.status_bg[stype], s->arg.s); + VP_COLOR_PARSE(&core.style.status_bg[stype], s->arg.s); vp_update_status_style(); } @@ -404,9 +404,9 @@ static gboolean setting_status_color_fg(const Setting* s, const SettingType type } if (type == SETTING_GET) { - setting_print_value(s, &vp.style.status_fg[stype]); + setting_print_value(s, &core.style.status_fg[stype]); } else { - VP_COLOR_PARSE(&vp.style.status_fg[stype], s->arg.s); + VP_COLOR_PARSE(&core.style.status_fg[stype], s->arg.s); vp_update_status_style(); } @@ -425,13 +425,13 @@ static gboolean setting_status_font(const Setting* s, const SettingType type) } if (type == SETTING_GET) { - setting_print_value(s, vp.style.status_font[stype]); + setting_print_value(s, core.style.status_font[stype]); } else { - if (vp.style.status_font[stype]) { + if (core.style.status_font[stype]) { /* free previous font description */ - pango_font_description_free(vp.style.status_font[stype]); + pango_font_description_free(core.style.status_font[stype]); } - vp.style.status_font[stype] = pango_font_description_from_string(s->arg.s); + core.style.status_font[stype] = pango_font_description_from_string(s->arg.s); vp_update_status_style(); } @@ -441,7 +441,7 @@ static gboolean setting_status_font(const Setting* s, const SettingType type) static gboolean setting_input_style(const Setting* s, const SettingType type) { - Style* style = &vp.style; + Style* style = &core.style; MessageType itype = g_str_has_suffix(s->name, "normal") ? VP_MSG_NORMAL : VP_MSG_ERROR; if (s->type == TYPE_FONT) { @@ -480,15 +480,15 @@ static gboolean setting_input_style(const Setting* s, const SettingType type) static gboolean setting_completion_style(const Setting* s, const SettingType type) { - Style* style = &vp.style; + Style* style = &core.style; CompletionStyle ctype = g_str_has_suffix(s->name, "normal") ? VP_COMP_NORMAL : VP_COMP_ACTIVE; if (s->type == TYPE_INTEGER) { /* max completion items */ if (type == SETTING_GET) { - setting_print_value(s, &vp.config.max_completion_items); + setting_print_value(s, &core.config.max_completion_items); } else { - vp.config.max_completion_items = s->arg.i; + core.config.max_completion_items = s->arg.i; } } else if (s->type == TYPE_FONT) { if (type == SETTING_GET) { @@ -521,7 +521,7 @@ static gboolean setting_completion_style(const Setting* s, const SettingType typ static gboolean setting_hint_style(const Setting* s, const SettingType type) { - Style* style = &vp.style; + Style* style = &core.style; if (!g_strcmp0(s->name, "hint-bg")) { if (type == SETTING_GET) { setting_print_value(s, style->hint_bg); @@ -555,7 +555,7 @@ static gboolean setting_strict_ssl(const Setting* s, const SettingType type) { gboolean value; if (type != SETTING_SET) { - g_object_get(vp.net.soup_session, "ssl-strict", &value, NULL); + g_object_get(core.soup_session, "ssl-strict", &value, NULL); if (type == SETTING_GET) { setting_print_value(s, &value); @@ -565,7 +565,7 @@ static gboolean setting_strict_ssl(const Setting* s, const SettingType type) value = type == SETTING_TOGGLE ? !value : (s->arg.i ? TRUE : FALSE); - g_object_set(vp.net.soup_session, "ssl-strict", value, NULL); + g_object_set(core.soup_session, "ssl-strict", value, NULL); return TRUE; } @@ -574,11 +574,11 @@ static gboolean setting_ca_bundle(const Setting* s, const SettingType type) { if (type == SETTING_GET) { char* value = NULL; - g_object_get(vp.net.soup_session, "ssl-ca-file", &value, NULL); + g_object_get(core.soup_session, "ssl-ca-file", &value, NULL); setting_print_value(s, value); g_free(value); } else { - g_object_set(vp.net.soup_session, "ssl-ca-file", s->arg.s, NULL); + g_object_set(core.soup_session, "ssl-ca-file", s->arg.s, NULL); } return TRUE; @@ -587,9 +587,9 @@ static gboolean setting_ca_bundle(const Setting* s, const SettingType type) static gboolean setting_home_page(const Setting* s, const SettingType type) { if (type == SETTING_GET) { - setting_print_value(s, vp.config.home_page); + setting_print_value(s, core.config.home_page); } else { - OVERWRITE_STRING(vp.config.home_page, s->arg.s); + OVERWRITE_STRING(core.config.home_page, s->arg.s); } return TRUE; @@ -598,20 +598,20 @@ static gboolean setting_home_page(const Setting* s, const SettingType type) static gboolean setting_download_path(const Setting* s, const SettingType type) { if (type == SETTING_GET) { - setting_print_value(s, vp.config.download_dir); + setting_print_value(s, core.config.download_dir); } else { - if (vp.config.download_dir) { - g_free(vp.config.download_dir); - vp.config.download_dir = NULL; + if (core.config.download_dir) { + g_free(core.config.download_dir); + core.config.download_dir = NULL; } /* if path is not absolute create it in the home directory */ if (s->arg.s[0] != '/') { - vp.config.download_dir = g_build_filename(util_get_home_dir(), s->arg.s, NULL); + core.config.download_dir = g_build_filename(util_get_home_dir(), s->arg.s, NULL); } else { - vp.config.download_dir = g_strdup(s->arg.s); + core.config.download_dir = g_strdup(s->arg.s); } /* create the path if it does not exist */ - util_create_dir_if_not_exists(vp.config.download_dir); + util_create_dir_if_not_exists(core.config.download_dir); } return TRUE; @@ -624,7 +624,7 @@ static gboolean setting_proxy(const Setting* s, const SettingType type) /* get the current status */ if (type != SETTING_SET) { - g_object_get(vp.net.soup_session, "proxy-uri", &proxy_uri, NULL); + g_object_get(core.soup_session, "proxy-uri", &proxy_uri, NULL); enabled = (proxy_uri != NULL); if (type == SETTING_GET) { @@ -650,13 +650,13 @@ static gboolean setting_proxy(const Setting* s, const SettingType type) : g_strdup_printf("http://%s", proxy); proxy_uri = soup_uri_new(proxy_new); - g_object_set(vp.net.soup_session, "proxy-uri", proxy_uri, NULL); + g_object_set(core.soup_session, "proxy-uri", proxy_uri, NULL); soup_uri_free(proxy_uri); g_free(proxy_new); } } else { - g_object_set(vp.net.soup_session, "proxy-uri", NULL, NULL); + g_object_set(core.soup_session, "proxy-uri", NULL, NULL); } return TRUE;