summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorportix <none@none>2012-06-24 13:41:01 +0200
committerportix <none@none>2012-06-24 13:41:01 +0200
commit606be3129817fa096550734314b7d1ac85b2c02e (patch)
treee36038a1d18b6c42bacbea8133f229cc546fa447 /src
parentd9e78be255c203ed463e70449b02910e8ff23159 (diff)
downloaddwb-606be3129817fa096550734314b7d1ac85b2c02e.zip
Replace dwb.files struct with a char-array, free all paths when in dwb_clean_up
Diffstat (limited to 'src')
-rw-r--r--src/commands.c18
-rw-r--r--src/download.c8
-rw-r--r--src/dwb.c145
-rw-r--r--src/dwb.h46
-rw-r--r--src/html.c4
-rw-r--r--src/scripts.c2
-rw-r--r--src/session.c6
-rw-r--r--src/soup.c12
-rw-r--r--src/util.c2
-rw-r--r--src/view.c2
10 files changed, 125 insertions, 120 deletions
diff --git a/src/commands.c b/src/commands.c
index 4f29320c..0c05de9e 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -204,9 +204,9 @@ 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.cookies_allow, arg->n);
+ 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.cookies_session_allow, arg->n);
+ 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;
@@ -222,7 +222,7 @@ 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.bookmarks, dwb.fc.bookmarks->data, true, -1);
+ 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()));
}
@@ -525,14 +525,14 @@ commands_toggle(Arg *arg, const char *filename, GList **tmp, GList **pers, const
DwbStatus
commands_toggle_plugin_blocker(KeyMap *km, Arg *arg) {
- commands_toggle(arg, dwb.files.plugins_allow, &dwb.fc.tmp_plugins, &dwb.fc.pers_plugins, "Plugins");
+ 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.scripts_allow, &dwb.fc.tmp_scripts, &dwb.fc.pers_scripts, "Scripts");
+ commands_toggle(arg, dwb.files[FILES_SCRIPTS_ALLOW], &dwb.fc.tmp_scripts, &dwb.fc.pers_scripts, "Scripts");
return STATUS_OK;
}/*}}}*/
@@ -605,7 +605,7 @@ commands_execute_userscript(KeyMap *km, Arg *arg) {
return STATUS_ERROR;
if (arg->p) {
- char *path = g_build_filename(dwb.files.userscripts, arg->p, NULL);
+ 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);
@@ -827,7 +827,7 @@ commands_sanitize(KeyMap *km, Arg *arg) {
if (s & SANITIZE_HISTORY) {
dwb_free_list(dwb.fc.history, (void_func)dwb_navigation_free);
dwb.fc.history = NULL;
- remove(dwb.files.history);
+ remove(dwb.files[FILES_HISTORY]);
}
if (s & (SANITIZE_HISTORY | SANITIZE_CACHE)) {
for (GList *gl = dwb.state.views; gl; gl=gl->next) {
@@ -836,7 +836,7 @@ commands_sanitize(KeyMap *km, Arg *arg) {
}
}
if (s & SANITIZE_COOKIES) {
- remove(dwb.files.cookies);
+ remove(dwb.files[FILES_COOKIES]);
}
if (s & (SANITIZE_CACHE | SANITIZE_COOKIES)) {
dwb_soup_clear_cookies();
@@ -845,7 +845,7 @@ commands_sanitize(KeyMap *km, Arg *arg) {
session_clear_session();
}
if (s & (SANITIZE_ALLSESSIONS)) {
- remove(dwb.files.session);
+ remove(dwb.files[FILES_SESSION]);
}
dwb_set_normal_message(dwb.state.fview, true, "Sanitized %s", arg->p ? arg->p : "all");
return STATUS_OK;
diff --git a/src/download.c b/src/download.c
index f2754259..81827283 100644
--- a/src/download.c
+++ b/src/download.c
@@ -80,7 +80,7 @@ download_spawn_external(const char *uri, const char *filename, WebKitDownload *d
GSList *list = g_slist_prepend(NULL, dwb_navigation_new("DWB_URI", uri));
list = g_slist_prepend(list, dwb_navigation_new("DWB_FILENAME", filename));
- list = g_slist_prepend(list, dwb_navigation_new("DWB_COOKIES", dwb.files.cookies));
+ list = g_slist_prepend(list, dwb_navigation_new("DWB_COOKIES", dwb.files[FILES_COOKIES]));
char *proxy = GET_CHAR("proxy-url");
gboolean has_proxy = GET_BOOL("proxy");
@@ -88,7 +88,7 @@ download_spawn_external(const char *uri, const char *filename, WebKitDownload *d
g_free(command);
command = newcommand;
}
- if ( (newcommand = util_string_replace(command, "dwb_cookies", dwb.files.cookies)) ) {
+ if ( (newcommand = util_string_replace(command, "dwb_cookies", dwb.files[FILES_COOKIES])) ) {
g_free(command);
command = newcommand;
}
@@ -241,7 +241,7 @@ download_do_spawn(const char *command, const char *path, const char *mimetype) {
dwb.fc.mimetypes = g_list_delete_link(dwb.fc.mimetypes, list);
}
dwb.fc.mimetypes = g_list_prepend(dwb.fc.mimetypes, n);
- util_file_add_navigation(dwb.files.mimetypes, n, true, -1);
+ util_file_add_navigation(dwb.files[FILES_MIMETYPES], n, true, -1);
}
}/*}}}*/
/* download_spawn(DwbDownload *) {{{*/
@@ -443,7 +443,7 @@ download_start(const char *path) {
/* Remote download; */
else {
if (dwb.state.dl_action == DL_ACTION_EXECUTE) {
- char *cache_name = g_build_filename(dwb.files.cachedir, filename, NULL);
+ char *cache_name = g_build_filename(dwb.files[FILES_CACHEDIR], filename, NULL);
fullpath = g_strconcat("file://", cache_name, NULL);
g_free(cache_name);
_lastaction = DL_ACTION_EXECUTE;
diff --git a/src/dwb.c b/src/dwb.c
index 83356a21..a032dbe1 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -615,7 +615,7 @@ dwb_scheme_handler(GList *gl, WebKitNetworkRequest *request) {
argv[i++] = (char*)uri;
argv[i++] = NULL;
list = g_slist_append(list, dwb_navigation_new("DWB_URI", uri));
- list = g_slist_prepend(list, dwb_navigation_new("DWB_COOKIES", dwb.files.cookies));
+ list = g_slist_prepend(list, dwb_navigation_new("DWB_COOKIES", dwb.files[FILES_COOKIES]));
char *scheme = g_uri_parse_scheme(uri);
if (scheme) {
@@ -974,15 +974,15 @@ dwb_remove_navigation_item(GList **content, const char *line, const char *filena
}
void
dwb_remove_bookmark(const char *line) {
- dwb_remove_navigation_item(&dwb.fc.bookmarks, line, dwb.files.bookmarks);
+ dwb_remove_navigation_item(&dwb.fc.bookmarks, line, dwb.files[FILES_BOOKMARKS]);
}
void
dwb_remove_download(const char *line) {
- dwb_remove_navigation_item(&dwb.fc.downloads, line, dwb.files.bookmarks);
+ dwb_remove_navigation_item(&dwb.fc.downloads, line, dwb.files[FILES_BOOKMARKS]);
}
void
dwb_remove_history(const char *line) {
- dwb_remove_navigation_item(&dwb.fc.history, line, dwb.misc.synctimer <= 0 ? dwb.files.history : NULL);
+ dwb_remove_navigation_item(&dwb.fc.history, line, dwb.misc.synctimer <= 0 ? dwb.files[FILES_HISTORY] : NULL);
}
void
dwb_remove_search_engine(const char *line) {
@@ -992,7 +992,7 @@ dwb_remove_search_engine(const char *line) {
if (item != NULL) {
if (item == dwb.fc.searchengines)
dwb.misc.default_search = dwb.fc.searchengines->next != NULL ? NAVIGATION(dwb.fc.searchengines->next)->second : NULL;
- util_file_remove_line(dwb.files.searchengines, line);
+ util_file_remove_line(dwb.files[FILES_SEARCHENGINES], line);
dwb_navigation_free(item->data);
dwb.fc.searchengines = g_list_delete_link(dwb.fc.searchengines, item);
}
@@ -1009,7 +1009,7 @@ dwb_remove_quickmark(const char *line) {
GList *item = g_list_find_custom(dwb.fc.quickmarks, q, (GCompareFunc)util_quickmark_compare);
dwb_quickmark_free(q);
if (item) {
- util_file_remove_line(dwb.files.quickmarks, line);
+ util_file_remove_line(dwb.files[FILES_QUICKMARKS], line);
dwb.fc.quickmarks = g_list_delete_link(dwb.fc.quickmarks, item);
}
}/*}}}*/
@@ -1023,7 +1023,7 @@ dwb_sync_files(gpointer data) {
Navigation *n = gl->data;
g_string_append_printf(buffer, "%s %s\n", n->first, n->second);
}
- g_file_set_contents(dwb.files.history, buffer->str, -1, NULL);
+ g_file_set_contents(dwb.files[FILES_HISTORY], buffer->str, -1, NULL);
g_string_free(buffer, true);
dwb_soup_sync_cookies();
return true;
@@ -1088,7 +1088,7 @@ dwb_apply_settings(WebSettings *s, const char *key, const char *value, int scope
if (scope == SET_GLOBAL) {
s->arg = s->arg_local;
dwb_set_normal_message(dwb.state.fview, true, "Saved setting %s: %s", s->n.first, value);
- dwb_save_key_value(dwb.files.settings, key, value);
+ dwb_save_key_value(dwb.files[FILES_SETTINGS], key, value);
}
else {
dwb_set_normal_message(dwb.state.fview, true, "Changed %s: %s", s->n.first, s->type == BOOLEAN ? ( s->arg_local.b ? "true" : "false") : value);
@@ -1176,7 +1176,7 @@ dwb_set_key(const char *prop, char *val) {
dwb.keymap = dwb_keymap_add(dwb.keymap, value);
dwb.keymap = g_list_sort(dwb.keymap, (GCompareFunc)util_keymap_sort_second);
- dwb_save_key_value(dwb.files.keys, prop, val);
+ dwb_save_key_value(dwb.files[FILES_KEYS], prop, val);
}/*}}}*/
/* dwb_get_host(WebKitWebView *) {{{*/
@@ -1529,7 +1529,7 @@ dwb_save_searchengine(void) {
Navigation *cn = dwb_get_search_completion_from_navigation(dwb_navigation_dup(n));
dwb.fc.se_completion = g_list_append(dwb.fc.se_completion, cn);
- util_file_add_navigation(dwb.files.searchengines, n, true, -1);
+ util_file_add_navigation(dwb.files[FILES_SEARCHENGINES], n, true, -1);
dwb_set_normal_message(dwb.state.fview, true, "Searchengine saved");
if (dwb.state.search_engine) {
@@ -1869,7 +1869,7 @@ dwb_save_quickmark(const char *key) {
}
dwb.fc.quickmarks = g_list_prepend(dwb.fc.quickmarks, dwb_quickmark_new(uri, title, key));
char *text = g_strdup_printf("%s %s %s", key, uri, title);
- util_file_add(dwb.files.quickmarks, text, true, -1);
+ util_file_add(dwb.files[FILES_QUICKMARKS], text, true, -1);
g_free(text);
dwb_set_normal_message(dwb.state.fview, true, "Added quickmark: %s - %s", key, uri);
@@ -2021,10 +2021,10 @@ dwb_new_window(const char *uri) {
/* dwb_test_userscript (const char *) return: char* (alloc) or NULL {{{*/
static char *
dwb_test_userscript(const char *filename) {
- char *path = g_build_filename(dwb.files.userscripts, filename, NULL);
+ char *path = g_build_filename(dwb.files[FILES_USERSCRIPTS], filename, NULL);
if (g_file_test(path, G_FILE_TEST_IS_REGULAR) ||
- (g_str_has_prefix(filename, dwb.files.userscripts) && g_file_test(filename, G_FILE_TEST_IS_REGULAR) && (path = g_strdup(filename))) ) {
+ (g_str_has_prefix(filename, dwb.files[FILES_USERSCRIPTS]) && g_file_test(filename, G_FILE_TEST_IS_REGULAR) && (path = g_strdup(filename))) ) {
return path;
}
else {
@@ -2651,11 +2651,11 @@ dwb_get_scripts() {
GError *error = NULL;
FILE *f;
- if ( (dir = g_dir_open(dwb.files.userscripts, 0, NULL)) ) {
+ if ( (dir = g_dir_open(dwb.files[FILES_USERSCRIPTS], 0, NULL)) ) {
while ( (filename = (char*)g_dir_read_name(dir)) ) {
gboolean javascript = false;
char buf[11] = {0};
- char *path = g_build_filename(dwb.files.userscripts, filename, NULL);
+ char *path = g_build_filename(dwb.files[FILES_USERSCRIPTS], filename, NULL);
char *realpath;
/* ignore subdirectories */
if (g_file_test(path, G_FILE_TEST_IS_DIR))
@@ -2855,12 +2855,15 @@ dwb_clean_up() {
for (GList *gl = dwb.state.views; gl; gl=gl->next) {
view_clean(gl);
}
+ for (int i=FILES_FIRST; i<FILES_LAST; i++) {
+ g_free(dwb.files[i]);
+ }
dwb_soup_end();
adblock_end();
domain_end();
- util_rmdir(dwb.files.cachedir, true, true);
+ util_rmdir(dwb.files[FILES_CACHEDIR], true, true);
gtk_widget_destroy(dwb.gui.window);
scripts_end();
return true;
@@ -2896,7 +2899,7 @@ dwb_save_keys() {
char *content;
gsize size;
- if (!g_key_file_load_from_file(keyfile, dwb.files.keys, G_KEY_FILE_KEEP_COMMENTS, &error)) {
+ if (!g_key_file_load_from_file(keyfile, dwb.files[FILES_KEYS], G_KEY_FILE_KEEP_COMMENTS, &error)) {
fprintf(stderr, "No keysfile found, creating a new file.\n");
g_clear_error(&error);
}
@@ -2911,7 +2914,7 @@ dwb_save_keys() {
}
}
if ( (content = g_key_file_to_data(keyfile, &size, &error)) ) {
- util_set_file_content(dwb.files.keys, content);
+ util_set_file_content(dwb.files[FILES_KEYS], content);
g_free(content);
}
if (error) {
@@ -2931,7 +2934,7 @@ dwb_save_settings() {
gsize size;
setlocale(LC_NUMERIC, "C");
- if (!g_key_file_load_from_file(keyfile, dwb.files.settings, G_KEY_FILE_KEEP_COMMENTS, &error)) {
+ if (!g_key_file_load_from_file(keyfile, dwb.files[FILES_SETTINGS], G_KEY_FILE_KEEP_COMMENTS, &error)) {
fprintf(stderr, "No settingsfile found, creating a new file.\n");
g_clear_error(&error);
}
@@ -2945,7 +2948,7 @@ dwb_save_settings() {
if (l != NULL)
g_list_free(l);
if ( (content = g_key_file_to_data(keyfile, &size, &error)) ) {
- util_set_file_content(dwb.files.settings, content);
+ util_set_file_content(dwb.files[FILES_SETTINGS], content);
g_free(content);
}
if (error) {
@@ -2978,8 +2981,8 @@ dwb_save_files(gboolean end_session) {
dwb_sync_files(NULL);
/* Save command history */
if (! dwb.misc.private_browsing) {
- dwb_save_list(dwb.fc.navigations, dwb.files.navigation_history, GET_INT("navigation-history-max"));
- dwb_save_list(dwb.fc.commands, dwb.files.command_history, GET_INT("navigation-history-max"));
+ dwb_save_list(dwb.fc.navigations, dwb.files[FILES_NAVIGATION_HISTORY], GET_INT("navigation-history-max"));
+ dwb_save_list(dwb.fc.commands, dwb.files[FILES_COMMAND_HISTORY], GET_INT("navigation-history-max"));
}
/* save session */
if (end_session && GET_BOOL("save-session") && dwb.state.mode != SAVE_SESSION) {
@@ -3145,7 +3148,7 @@ dwb_init_key_map() {
dwb.keymap = NULL;
dwb.override_keys = NULL;
- g_key_file_load_from_file(keyfile, dwb.files.keys, G_KEY_FILE_KEEP_COMMENTS, &error);
+ g_key_file_load_from_file(keyfile, dwb.files[FILES_KEYS], G_KEY_FILE_KEEP_COMMENTS, &error);
if (error) {
fprintf(stderr, "No keyfile found: %s\nUsing default values.\n", error->message);
g_clear_error(&error);
@@ -3191,7 +3194,7 @@ dwb_init_settings() {
dwb.state.web_settings = webkit_web_settings_new();
setlocale(LC_NUMERIC, "C");
- g_file_get_contents(dwb.files.settings, &content, &length, &error);
+ g_file_get_contents(dwb.files[FILES_SETTINGS], &content, &length, &error);
if (error) {
fprintf(stderr, "No settingsfile found: %s\nUsing default values.\n", error->message);
g_clear_error(&error);
@@ -3620,62 +3623,62 @@ dwb_init_files() {
cachedir = g_build_filename(g_get_user_cache_dir(), dwb.misc.name, NULL);
- dwb.files.cachedir = util_check_directory(cachedir);
-
- dwb.files.bookmarks = g_build_filename(profile_path, "bookmarks", NULL);
- dwb_check_create(dwb.files.bookmarks);
- dwb.files.history = g_build_filename(profile_path, "history", NULL);
- dwb_check_create(dwb.files.history);
- dwb.files.quickmarks = g_build_filename(profile_path, "quickmarks", NULL);
- dwb_check_create(dwb.files.quickmarks);
- dwb.files.session = g_build_filename(profile_path, "session", NULL);
- dwb_check_create(dwb.files.session);
- dwb.files.navigation_history = g_build_filename(profile_path, "navigate.history", NULL);
- dwb_check_create(dwb.files.navigation_history);
- dwb.files.command_history = g_build_filename(profile_path, "commands.history", NULL);
- dwb_check_create(dwb.files.command_history);
- dwb.files.searchengines = g_build_filename(path, "searchengines", NULL);
- dwb_check_create(dwb.files.searchengines);
- dwb.files.keys = g_build_filename(path, "keys", NULL);
- dwb.files.settings = g_build_filename(path, "settings", NULL);
- dwb.files.mimetypes = g_build_filename(path, "mimetypes", NULL);
- dwb_check_create(dwb.files.mimetypes);
- dwb.files.cookies = g_build_filename(profile_path, "cookies", NULL);
- dwb_check_create(dwb.files.cookies);
- dwb.files.cookies_allow = g_build_filename(profile_path, "cookies.allow", NULL);
- dwb_check_create(dwb.files.cookies_allow);
- dwb.files.cookies_session_allow = g_build_filename(profile_path, "cookies_session.allow", NULL);
- dwb_check_create(dwb.files.cookies_session_allow);
- dwb.files.scripts_allow = g_build_filename(profile_path, "scripts.allow", NULL);
- dwb_check_create(dwb.files.scripts_allow);
- dwb.files.plugins_allow = g_build_filename(profile_path, "plugins.allow", NULL);
- dwb_check_create(dwb.files.plugins_allow);
- dwb.files.custom_keys = g_build_filename(profile_path, "custom_keys", NULL);
- dwb_check_create(dwb.files.custom_keys);
+ dwb.files[FILES_CACHEDIR] = util_check_directory(cachedir);
+
+ dwb.files[FILES_BOOKMARKS] = g_build_filename(profile_path, "bookmarks", NULL);
+ dwb_check_create(dwb.files[FILES_BOOKMARKS]);
+ dwb.files[FILES_HISTORY] = g_build_filename(profile_path, "history", NULL);
+ dwb_check_create(dwb.files[FILES_HISTORY]);
+ dwb.files[FILES_QUICKMARKS] = g_build_filename(profile_path, "quickmarks", NULL);
+ dwb_check_create(dwb.files[FILES_QUICKMARKS]);
+ dwb.files[FILES_SESSION] = g_build_filename(profile_path, "session", NULL);
+ dwb_check_create(dwb.files[FILES_SESSION]);
+ dwb.files[FILES_NAVIGATION_HISTORY] = g_build_filename(profile_path, "navigate.history", NULL);
+ dwb_check_create(dwb.files[FILES_NAVIGATION_HISTORY]);
+ dwb.files[FILES_COMMAND_HISTORY] = g_build_filename(profile_path, "commands.history", NULL);
+ dwb_check_create(dwb.files[FILES_COMMAND_HISTORY]);
+ dwb.files[FILES_SEARCHENGINES] = g_build_filename(path, "searchengines", NULL);
+ dwb_check_create(dwb.files[FILES_SEARCHENGINES]);
+ dwb.files[FILES_KEYS] = g_build_filename(path, "keys", NULL);
+ dwb.files[FILES_SETTINGS] = g_build_filename(path, "settings", NULL);
+ dwb.files[FILES_MIMETYPES] = g_build_filename(path, "mimetypes", NULL);
+ dwb_check_create(dwb.files[FILES_MIMETYPES]);
+ dwb.files[FILES_COOKIES] = g_build_filename(profile_path, "cookies", NULL);
+ dwb_check_create(dwb.files[FILES_COOKIES]);
+ dwb.files[FILES_COOKIES_ALLOW] = g_build_filename(profile_path, "cookies.allow", NULL);
+ dwb_check_create(dwb.files[FILES_COOKIES_ALLOW]);
+ dwb.files[FILES_COOKIES_SESSION_ALLOW] = g_build_filename(profile_path, "cookies_session.allow", NULL);
+ dwb_check_create(dwb.files[FILES_COOKIES_SESSION_ALLOW]);
+ dwb.files[FILES_SCRIPTS_ALLOW] = g_build_filename(profile_path, "scripts.allow", NULL);
+ dwb_check_create(dwb.files[FILES_SCRIPTS_ALLOW]);
+ dwb.files[FILES_PLUGINS_ALLOW] = g_build_filename(profile_path, "plugins.allow", NULL);
+ dwb_check_create(dwb.files[FILES_PLUGINS_ALLOW]);
+ dwb.files[FILES_CUSTOM_KEYS] = g_build_filename(profile_path, "custom_keys", NULL);
+ dwb_check_create(dwb.files[FILES_CUSTOM_KEYS]);
userscripts = g_build_filename(path, "userscripts", NULL);
- dwb.files.userscripts = util_check_directory(userscripts);
-
- dwb.fc.bookmarks = dwb_init_file_content(dwb.fc.bookmarks, dwb.files.bookmarks, (Content_Func)dwb_navigation_new_from_line);
- dwb.fc.history = dwb_init_file_content(dwb.fc.history, dwb.files.history, (Content_Func)dwb_navigation_new_from_line);
- dwb.fc.quickmarks = dwb_init_file_content(dwb.fc.quickmarks, dwb.files.quickmarks, (Content_Func)dwb_quickmark_new_from_line);
- dwb.fc.searchengines = dwb_init_file_content(dwb.fc.searchengines, dwb.files.searchengines, (Content_Func)dwb_navigation_new_from_line);
- dwb.fc.se_completion = dwb_init_file_content(dwb.fc.se_completion, dwb.files.searchengines, (Content_Func)dwb_get_search_completion);
- dwb.fc.mimetypes = dwb_init_file_content(dwb.fc.mimetypes, dwb.files.mimetypes, (Content_Func)dwb_navigation_new_from_line);
- dwb.fc.navigations = dwb_init_file_content(dwb.fc.navigations, dwb.files.navigation_history, (Content_Func)dwb_return);
- dwb.fc.commands = dwb_init_file_content(dwb.fc.commands, dwb.files.command_history, (Content_Func)dwb_return);
+ dwb.files[FILES_USERSCRIPTS] = util_check_directory(userscripts);
+
+ dwb.fc.bookmarks = dwb_init_file_content(dwb.fc.bookmarks, dwb.files[FILES_BOOKMARKS], (Content_Func)dwb_navigation_new_from_line);
+ dwb.fc.history = dwb_init_file_content(dwb.fc.history, dwb.files[FILES_HISTORY], (Content_Func)dwb_navigation_new_from_line);
+ dwb.fc.quickmarks = dwb_init_file_content(dwb.fc.quickmarks, dwb.files[FILES_QUICKMARKS], (Content_Func)dwb_quickmark_new_from_line);
+ dwb.fc.searchengines = dwb_init_file_content(dwb.fc.searchengines, dwb.files[FILES_SEARCHENGINES], (Content_Func)dwb_navigation_new_from_line);
+ dwb.fc.se_completion = dwb_init_file_content(dwb.fc.se_completion, dwb.files[FILES_SEARCHENGINES], (Content_Func)dwb_get_search_completion);
+ dwb.fc.mimetypes = dwb_init_file_content(dwb.fc.mimetypes, dwb.files[FILES_MIMETYPES], (Content_Func)dwb_navigation_new_from_line);
+ dwb.fc.navigations = dwb_init_file_content(dwb.fc.navigations, dwb.files[FILES_NAVIGATION_HISTORY], (Content_Func)dwb_return);
+ dwb.fc.commands = dwb_init_file_content(dwb.fc.commands, dwb.files[FILES_COMMAND_HISTORY], (Content_Func)dwb_return);
dwb.fc.tmp_scripts = NULL;
dwb.fc.tmp_plugins = NULL;
dwb.fc.downloads = NULL;
- dwb.fc.pers_scripts = dwb_get_simple_list(NULL, dwb.files.scripts_allow);
- dwb.fc.pers_plugins = dwb_get_simple_list(NULL, dwb.files.plugins_allow);
+ dwb.fc.pers_scripts = dwb_get_simple_list(NULL, dwb.files[FILES_SCRIPTS_ALLOW]);
+ dwb.fc.pers_plugins = dwb_get_simple_list(NULL, dwb.files[FILES_PLUGINS_ALLOW]);
if (g_list_last(dwb.fc.searchengines))
dwb.misc.default_search = ((Navigation*)dwb.fc.searchengines->data)->second;
else
dwb.misc.default_search = NULL;
- dwb.fc.cookies_allow = dwb_init_file_content(dwb.fc.cookies_allow, dwb.files.cookies_allow, (Content_Func)dwb_return);
- dwb.fc.cookies_session_allow = dwb_init_file_content(dwb.fc.cookies_session_allow, dwb.files.cookies_session_allow, (Content_Func)dwb_return);
+ dwb.fc.cookies_allow = dwb_init_file_content(dwb.fc.cookies_allow, dwb.files[FILES_COOKIES_ALLOW], (Content_Func)dwb_return);
+ dwb.fc.cookies_session_allow = dwb_init_file_content(dwb.fc.cookies_session_allow, dwb.files[FILES_COOKIES_SESSION_ALLOW], (Content_Func)dwb_return);
g_free(path);
g_free(profile_path);
@@ -3743,7 +3746,7 @@ void
dwb_init_custom_keys(gboolean reload) {
if (reload)
dwb_free_custom_keys();
- char **lines = util_get_lines(dwb.files.custom_keys);
+ char **lines = util_get_lines(dwb.files[FILES_CUSTOM_KEYS]);
if (lines == NULL)
return;
const char *current_line;
diff --git a/src/dwb.h b/src/dwb.h
index 6a296245..e0fe9245 100644
--- a/src/dwb.h
+++ b/src/dwb.h
@@ -191,7 +191,6 @@ typedef struct _Color Color;
typedef struct _Completions Completions;
typedef struct _Dwb Dwb;
typedef struct _FileContent FileContent;
-typedef struct _Files Files;
typedef struct _Font DwbFont;
typedef struct _FunctionMap FunctionMap;
typedef struct _Gui Gui;
@@ -746,26 +745,28 @@ struct _Misc {
int script_signals;
};
-struct _Files {
- const char *bookmarks;
- const char *navigation_history;
- const char *command_history;
- const char *cookies;
- const char *cookies_allow;
- const char *cookies_session_allow;
- const char *download_path;
- const char *history;
- const char *keys;
- const char *mimetypes;
- const char *quickmarks;
- const char *searchengines;
- const char *session;
- const char *settings;
- const char *userscripts;
- const char *scripts_allow;
- const char *plugins_allow;
- const char *cachedir;
- const char *custom_keys;
+enum Files {
+ FILES_FIRST = 0,
+ FILES_BOOKMARKS = 0,
+ FILES_NAVIGATION_HISTORY,
+ FILES_COMMAND_HISTORY,
+ FILES_COOKIES,
+ FILES_COOKIES_ALLOW,
+ FILES_COOKIES_SESSION_ALLOW,
+ FILES_DOWNLOAD_PATH,
+ FILES_HISTORY,
+ FILES_KEYS,
+ FILES_MIMETYPES,
+ FILES_QUICKMARKS,
+ FILES_SEARCHENGINES,
+ FILES_SESSION,
+ FILES_SETTINGS,
+ FILES_USERSCRIPTS,
+ FILES_SCRIPTS_ALLOW,
+ FILES_PLUGINS_ALLOW,
+ FILES_CACHEDIR,
+ FILES_CUSTOM_KEYS,
+ FILES_LAST
};
// TODO implement plugins blocker, script blocker with File struct
typedef struct _File {
@@ -805,7 +806,8 @@ struct _Dwb {
GList *override_keys;
GSList *custom_commands;
GHashTable *settings;
- Files files;
+ //Files files;
+ char *files[FILES_LAST];
FileContent fc;
gpointer *instance;
};
diff --git a/src/html.c b/src/html.c
index 6997f070..285576af 100644
--- a/src/html.c
+++ b/src/html.c
@@ -314,7 +314,7 @@ html_custom_keys_changed_cb(WebKitDOMElement *target, WebKitDOMEvent *e, gpointe
WebKitDOMDocument *doc = webkit_dom_node_get_owner_document(WEBKIT_DOM_NODE(target));
WebKitDOMElement *text_area = webkit_dom_document_get_element_by_id(doc, "dwb_custom_keys_area");
char *value = webkit_dom_html_text_area_element_get_value(WEBKIT_DOM_HTML_TEXT_AREA_ELEMENT(text_area));
- util_set_file_content(dwb.files.custom_keys, value);
+ util_set_file_content(dwb.files[FILES_CUSTOM_KEYS], value);
g_free(value);
dwb_init_custom_keys(true);
dwb_set_normal_message(dwb.state.fview, true, "Custom keys saved");
@@ -369,7 +369,7 @@ html_keys_load_cb(WebKitWebView *wv, GParamSpec *p, HtmlTable *table) {
webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(win), "keydown", G_CALLBACK(html_keydown_cb), true, wv);
WebKitDOMElement *textarea = webkit_dom_document_get_element_by_id(doc, "dwb_custom_keys_area");
WebKitDOMElement *button = webkit_dom_document_get_element_by_id(doc, "dwb_custom_keys_submit");
- char *content = util_get_file_content(dwb.files.custom_keys);
+ char *content = util_get_file_content(dwb.files[FILES_CUSTOM_KEYS]);
if (content != NULL && *content != '\0') {
webkit_dom_html_text_area_element_set_value(WEBKIT_DOM_HTML_TEXT_AREA_ELEMENT(textarea), content);
}
diff --git a/src/scripts.c b/src/scripts.c
index 52441bda..17a1243d 100644
--- a/src/scripts.c
+++ b/src/scripts.c
@@ -847,7 +847,7 @@ data_get_profile(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSVa
/* data_get_cache_dir {{{*/
static JSValueRef
data_get_cache_dir(JSContextRef ctx, JSObjectRef object, JSStringRef js_name, JSValueRef* exception) {
- return js_char_to_value(ctx, dwb.files.cachedir);
+ return js_char_to_value(ctx, dwb.files[FILES_CACHEDIR]);
}/*}}}*/
/* data_get_config_dir {{{*/
diff --git a/src/session.c b/src/session.c
index 4e2caec8..06bb0c52 100644
--- a/src/session.c
+++ b/src/session.c
@@ -35,7 +35,7 @@ typedef struct _SessionTab {
static char **
session_get_groups() {
char **groups = NULL;
- char *content = util_get_file_content(dwb.files.session);
+ char *content = util_get_file_content(dwb.files[FILES_SESSION]);
if (content) {
groups = g_regex_split_simple("^g:", content, G_REGEX_MULTILINE, G_REGEX_MATCH_NOTEMPTY);
g_free(content);
@@ -105,7 +105,7 @@ session_save_file(const char *groupname, const char *content, gboolean mark) {
}
if (!set)
g_string_append_printf(buffer, "g:%s%s\n%s", mark ? "*" : "", groupname, content);
- util_set_file_content(dwb.files.session, buffer->str);
+ util_set_file_content(dwb.files[FILES_SESSION], buffer->str);
g_string_free(buffer, true);
g_free(group);
g_strfreev(groups);
@@ -150,7 +150,7 @@ session_load_webview(GList *gl, char *uri, int last, int lock_status) {
void
session_list() {
char *path = util_build_path();
- dwb.files.session = util_check_directory(g_build_filename(path, dwb.misc.profile, "session", NULL));
+ dwb.files[FILES_SESSION] = util_check_directory(g_build_filename(path, dwb.misc.profile, "session", NULL));
char **content = session_get_groups();
if (content == NULL) {
fprintf(stderr, "No sessions found for profile: %s\n", dwb.misc.profile);
diff --git a/src/soup.c b/src/soup.c
index 1f919769..47f9d753 100644
--- a/src/soup.c
+++ b/src/soup.c
@@ -175,9 +175,9 @@ dwb_soup_get_host_from_request(WebKitNetworkRequest *request) {
/* dwb_soup_save_cookies(cookies) {{{*/
void
dwb_soup_save_cookies(GSList *cookies) {
- int fd = open(dwb.files.cookies, 0);
+ int fd = open(dwb.files[FILES_COOKIES], 0);
flock(fd, LOCK_EX);
- SoupCookieJar *jar = soup_cookie_jar_text_new(dwb.files.cookies, false);
+ SoupCookieJar *jar = soup_cookie_jar_text_new(dwb.files[FILES_COOKIES], false);
for (GSList *l=cookies; l; l=l->next) {
soup_cookie_jar_add_cookie(jar, soup_cookie_copy(l->data));
}
@@ -236,7 +236,7 @@ dwb_soup_get_cookie_store_policy(const char *policy) {
/*dwb_soup_cookie_changed_cb {{{*/
static void
dwb_soup_cookie_changed_cb(SoupCookieJar *jar, SoupCookie *old, SoupCookie *new, gpointer *p) {
- //SoupCookieJar *j = soup_cookie_jar_text_new(dwb.files.cookies, false);
+ //SoupCookieJar *j = soup_cookie_jar_text_new(dwb.files[FILES_COOKIES], false);
if (old) {
soup_cookie_jar_delete_cookie(_persJar, old);
}
@@ -257,10 +257,10 @@ dwb_soup_cookie_changed_cb(SoupCookieJar *jar, SoupCookie *old, SoupCookie *new,
void
dwb_soup_sync_cookies() {
- int fd = open(dwb.files.cookies, 0);
+ int fd = open(dwb.files[FILES_COOKIES], 0);
flock(fd, LOCK_EX);
GSList *all_cookies = soup_cookie_jar_all_cookies(_persJar);
- SoupCookieJar *j = soup_cookie_jar_text_new(dwb.files.cookies, false);
+ SoupCookieJar *j = soup_cookie_jar_text_new(dwb.files[FILES_COOKIES], false);
for (GSList *l = all_cookies; l; l=l->next) {
soup_cookie_jar_add_cookie(j, l->data);
}
@@ -285,7 +285,7 @@ dwb_soup_init_cookies(SoupSession *s) {
//_persJar = soup_cookie_jar_new();
_persJar = soup_cookie_jar_new();
dwb_soup_set_cookie_accept_policy(GET_CHAR("cookies-accept-policy"));
- SoupCookieJar *old_cookies = soup_cookie_jar_text_new(dwb.files.cookies, true);
+ SoupCookieJar *old_cookies = soup_cookie_jar_text_new(dwb.files[FILES_COOKIES], true);
GSList *l = soup_cookie_jar_all_cookies(old_cookies);
for (; l; l=l->next ) {
soup_cookie_jar_add_cookie(_jar, soup_cookie_copy(l->data));
diff --git a/src/util.c b/src/util.c
index 16ab1e2d..6d8b79f1 100644
--- a/src/util.c
+++ b/src/util.c
@@ -31,7 +31,7 @@ util_get_temp_filename(const char *prefix) {
struct timeval t;
gettimeofday(&t, NULL);
char *filename = g_strdup_printf("%s%lu", prefix, t.tv_usec + t.tv_sec*1000000);
- char *cache_path = g_build_filename(dwb.files.cachedir, filename, NULL);
+ char *cache_path = g_build_filename(dwb.files[FILES_CACHEDIR], filename, NULL);
g_free(filename);
return cache_path;
diff --git a/src/view.c b/src/view.c
index 01d9ac90..6eab4991 100644
--- a/src/view.c
+++ b/src/view.c
@@ -668,7 +668,7 @@ view_load_status_cb(WebKitWebView *web, GParamSpec *pspec, GList *gl) {
&& !g_str_has_prefix(uri, "dwb:")
&& (dwb_prepend_navigation(gl, &dwb.fc.history) == STATUS_OK)
&& dwb.misc.sync_interval <= 0) {
- util_file_add_navigation(dwb.files.history, dwb.fc.history->data, false, dwb.misc.history_length);
+ util_file_add_navigation(dwb.files[FILES_HISTORY], dwb.fc.history->data, false, dwb.misc.history_length);
}
dwb_execute_script(webkit_web_view_get_main_frame(web), dwb.misc.scripts_onload, false);
if (dwb.state.auto_insert_mode)