From 00b6cfc57e27f8146d9b41ba8e63038a4f9df70e Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 26 May 2014 23:43:36 +0100 Subject: rework path to url mapping functions to convert from and to nsurl --- gtk/dialogs/source.c | 22 +++++++-------------- gtk/fetch.c | 56 ++-------------------------------------------------- gtk/fetch.h | 2 -- 3 files changed, 9 insertions(+), 71 deletions(-) (limited to 'gtk') diff --git a/gtk/dialogs/source.c b/gtk/dialogs/source.c index c53c67fe4..67cb061be 100644 --- a/gtk/dialogs/source.c +++ b/gtk/dialogs/source.c @@ -26,6 +26,7 @@ #include "utils/messages.h" #include "utils/url.h" #include "utils/utils.h" +#include "utils/file.h" #include "desktop/netsurf.h" #include "desktop/browser_private.h" #include "render/html.h" @@ -263,7 +264,6 @@ void nsgtk_source_tab_init(GtkWindow *parent, struct browser_window *bw) nserror error; nserror r; gchar *filename; - char *fileurl; gint handle; source_data = content_get_source_data(bw->current_content, @@ -301,29 +301,21 @@ void nsgtk_source_tab_init(GtkWindow *parent, struct browser_window *bw) fprintf(f, "%s", ndata); fclose(f); free(ndata); - fileurl = path_to_url(filename); - g_free(filename); - if (fileurl == NULL) { - warn_user(messages_get("NoMemory"), 0); - return; - } /* Open tab */ - error = nsurl_create(fileurl, &url); - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } else { + error = netsurf_path_to_nsurl(filename, &url); + g_free(filename); + if (error == NSERROR_OK) { error = browser_window_create(BW_CREATE_TAB, url, NULL, bw, NULL); nsurl_unref(url); - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } } - free(fileurl); + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); + } } static void nsgtk_source_file_save(GtkWindow *parent, const char *filename, diff --git a/gtk/fetch.c b/gtk/fetch.c index c1857ab48..42ba89839 100644 --- a/gtk/fetch.c +++ b/gtk/fetch.c @@ -25,9 +25,9 @@ #include #include "utils/hashtable.h" -#include "utils/url.h" #include "utils/log.h" #include "utils/filepath.h" +#include "utils/file.h" #include "desktop/gui.h" #include "gtk/gui.h" @@ -226,56 +226,10 @@ const char *fetch_filetype(const char *unix_path) return type; } -char *path_to_url(const char *path) -{ - int urllen; - char *url; - - if (path == NULL) { - return NULL; - } - - urllen = strlen(path) + FILE_SCHEME_PREFIX_LEN + 1; - - url = malloc(urllen); - if (url == NULL) { - return NULL; - } - - if (*path == '/') { - path++; /* file: paths are already absolute */ - } - - snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, path); - - return url; -} - - -static char *url_to_path(const char *url) -{ - char *path; - char *respath; - nserror res; /* result from url routines */ - - res = url_path(url, &path); - if (res != NSERROR_OK) { - return NULL; - } - - res = url_unescape(path, &respath); - free(path); - if (res != NSERROR_OK) { - return NULL; - } - - return respath; -} static nsurl *gui_get_resource_url(const char *path) { char buf[PATH_MAX]; - char *raw; nsurl *url = NULL; /* default.css -> gtkdefault.css */ @@ -288,19 +242,13 @@ static nsurl *gui_get_resource_url(const char *path) path = "favicon.png"; } - raw = path_to_url(filepath_sfind(respaths, buf, path)); - if (raw != NULL) { - nsurl_create(raw, &url); - free(raw); - } + netsurf_path_to_nsurl(filepath_sfind(respaths, buf, path), &url); return url; } static struct gui_fetch_table fetch_table = { .filetype = fetch_filetype, - .path_to_url = path_to_url, - .url_to_path = url_to_path, .get_resource_url = gui_get_resource_url, }; diff --git a/gtk/fetch.h b/gtk/fetch.h index 400a06a35..a095adbf9 100644 --- a/gtk/fetch.h +++ b/gtk/fetch.h @@ -25,6 +25,4 @@ void gtk_fetch_filetype_init(const char *mimefile); void gtk_fetch_filetype_fin(void); const char *fetch_filetype(const char *unix_path); -char *path_to_url(const char *path); - #endif -- cgit v1.2.3