From 9ccf0cee9f4c070146a225fc633591436b1a88eb Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 19 Jun 2015 16:15:24 +0100 Subject: Change GTK resource path to use the users netsurf directory This changes the path used to find resources from containg a hard coded ${HOME}/.netsurf to using the computed path to the users netsurf config. --- gtk/gui.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/gtk/gui.c b/gtk/gui.c index 4986f425f..a5c2fb0a8 100644 --- a/gtk/gui.c +++ b/gtk/gui.c @@ -107,12 +107,41 @@ static void die(const char * const error) * searched for. */ static char ** -nsgtk_init_resource_path(const char *resource_path) +nsgtk_init_resource_path(const char *config_home) { + char *resource_path; + int resource_path_len; const gchar * const *langv; char **pathv; /* resource path string vector */ char **respath; /* resource paths vector */ + if (config_home != NULL) { + resource_path_len = snprintf(NULL, 0, + "%s:${NETSURFRES}:%s:./gtk/res", + config_home, + GTK_RESPATH); + resource_path = malloc(resource_path_len + 1); + if (resource_path == NULL) { + return NULL; + } + snprintf(resource_path, resource_path_len + 1, + "%s:${NETSURFRES}:%s:./gtk/res", + config_home, + GTK_RESPATH); + } else { + resource_path_len = snprintf(NULL, 0, + "${NETSURFRES}:%s:./gtk/res", + GTK_RESPATH); + resource_path = malloc(resource_path_len + 1); + if (resource_path == NULL) { + return NULL; + } + snprintf(resource_path, + resource_path_len + 1, + "${NETSURFRES}:%s:./gtk/res", + GTK_RESPATH); + } + pathv = filepath_path_to_strvec(resource_path); langv = g_get_language_names(); @@ -121,6 +150,8 @@ nsgtk_init_resource_path(const char *resource_path) filepath_free_strvec(pathv); + free(resource_path); + return respath; } @@ -1057,7 +1088,11 @@ int main(int argc, char** argv) nslog_init(nslog_stream_configure, &argc, argv); /* build the common resource path list */ - respaths = nsgtk_init_resource_path("${HOME}/.netsurf/:${NETSURFRES}:"GTK_RESPATH":./gtk/res"); + respaths = nsgtk_init_resource_path(nsgtk_config_home); + if (respaths == NULL) { + fprintf(stderr, "Unable to locate resources\n"); + return 1; + } /* initialise the gtk resource handling */ ret = nsgtk_init_resources(respaths); -- cgit v1.2.3