diff options
author | Vincent Sanders <vince@kyllikki.org> | 2014-01-22 23:19:57 +0000 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2014-01-23 00:00:18 +0000 |
commit | 047569339406f2be1637ae4cee5dd0c9a9c2328f (patch) | |
tree | 3d3909b4bc3d27cd7a9e146d32539ce752b33310 /desktop | |
parent | 4684e9665d2ddff50f4a8e9a16d73224d2617180 (diff) | |
download | netsurf-047569339406f2be1637ae4cee5dd0c9a9c2328f.tar.gz netsurf-047569339406f2be1637ae4cee5dd0c9a9c2328f.tar.bz2 |
create table for fetcher operations and move all operations into it
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/gui.h | 84 | ||||
-rw-r--r-- | desktop/gui_factory.c | 59 | ||||
-rw-r--r-- | desktop/save_complete.c | 6 |
3 files changed, 111 insertions, 38 deletions
diff --git a/desktop/gui.h b/desktop/gui.h index 5252737f9..724355d10 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -280,23 +280,17 @@ struct gui_clipboard_table { void (*set)(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles); }; -/** Graphical user interface browser misc function table - * - * function table implementing GUI interface to miscelaneous browser - * functionality +/** + * function table for fetcher operations */ -struct gui_browser_table { +struct gui_fetch_table { /* Mandantory entries */ /** - * called to let the frontend update its state and run any - * I/O operations. - */ - void (*poll)(bool active); - - /** * Return the filename part of a full path * + * @note used in curl fetcher + * * \param path full path and filename * \return filename (will be freed with free()) */ @@ -305,6 +299,8 @@ struct gui_browser_table { /** * Add a path component/filename to an existing path * + * @note used in save complete and file fetcher + * * \param path buffer containing path + free space * \param length length of buffer "path" * \param newpart string containing path component to add to path @@ -312,23 +308,25 @@ struct gui_browser_table { */ bool (*path_add_part)(char *path, int length, const char *newpart); - /* Optional entries */ - - /** called to allow the gui to cleanup */ - void (*quit)(void); - /** - * set gui display of a retrieved favicon representing the - * search provider + * Determine the MIME type of a local file. * - * \param ico may be NULL for local calls; then access current - * cache from search_web_ico() + * @note used in file fetcher + * + * \param unix_path Unix style path to file on disk + * \return Pointer to MIME type string (should not be freed) - + * invalidated on next call to fetch_filetype. */ - void (*set_search_ico)(hlcache_handle *ico); + const char *(*filetype)(const char *unix_path); + + + /* Optional entries */ /** * Callback to translate resource to full url. * + * @note used in resource fetcher + * * Transforms a resource: path into a full URL. The returned URL * is used as the target for a redirect. The caller takes ownership of * the returned nsurl including unrefing it when finished with it. @@ -340,6 +338,47 @@ struct gui_browser_table { nsurl* (*get_resource_url)(const char *path); /** + * Find a MIME type for a local file + * + * @note used in file fetcher + * + * \param ro_path RISC OS style path to file on disk + * \return MIME type string (on heap, caller should free), or NULL + */ + char *(*mimetype)(const char *ro_path); + +}; + +/** Graphical user interface browser misc function table + * + * function table implementing GUI interface to miscelaneous browser + * functionality + */ +struct gui_browser_table { + /* Mandantory entries */ + + /** + * called to let the frontend update its state and run any + * I/O operations. + */ + void (*poll)(bool active); + + + /* Optional entries */ + + /** called to allow the gui to cleanup */ + void (*quit)(void); + + /** + * set gui display of a retrieved favicon representing the + * search provider + * + * \param ico may be NULL for local calls; then access current + * cache from search_web_ico() + */ + void (*set_search_ico)(hlcache_handle *ico); + + /** * core has no fetcher for url */ void (*launch_url)(const char *url); @@ -380,6 +419,9 @@ struct gui_table { /** Clipboard table */ struct gui_clipboard_table *clipboard; + + /** Fetcher table */ + struct gui_fetch_table *fetch; }; diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c index 104f4906d..06b5383ba 100644 --- a/desktop/gui_factory.c +++ b/desktop/gui_factory.c @@ -289,18 +289,53 @@ static nserror verify_clipboard_register(struct gui_clipboard_table *gct) return NSERROR_OK; } +static nsurl *gui_default_get_resource_url(const char *path) +{ + return NULL; +} -static void gui_default_quit(void) +static char *gui_default_mimetype(const char *path) { + return strdup(guit->fetch->filetype(path)); } -static void gui_default_set_search_ico(hlcache_handle *ico) +/** verify fetch table is valid */ +static nserror verify_fetch_register(struct gui_fetch_table *gft) { + /* check table is present */ + if (gft == NULL) { + return NSERROR_BAD_PARAMETER; + } + + /* check the mandantory fields are set */ + if (gft->filename_from_path == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gft->path_add_part == NULL) { + return NSERROR_BAD_PARAMETER; + } + if (gft->filetype == NULL) { + return NSERROR_BAD_PARAMETER; + } + + + /* fill in the optional entries with defaults */ + if (gft->get_resource_url == NULL) { + gft->get_resource_url = gui_default_get_resource_url; + } + if (gft->mimetype == NULL) { + gft->mimetype = gui_default_mimetype; + } + + return NSERROR_OK; } -static nsurl *gui_default_get_resource_url(const char *path) +static void gui_default_quit(void) +{ +} + +static void gui_default_set_search_ico(hlcache_handle *ico) { - return NULL; } static void gui_default_launch_url(const char *url) @@ -340,13 +375,6 @@ static nserror verify_browser_register(struct gui_browser_table *gbt) if (gbt->poll == NULL) { return NSERROR_BAD_PARAMETER; } - if (gbt->filename_from_path == NULL) { - return NSERROR_BAD_PARAMETER; - } - if (gbt->path_add_part == NULL) { - return NSERROR_BAD_PARAMETER; - } - /* fill in the optional entries with defaults */ if (gbt->quit == NULL) { @@ -355,9 +383,6 @@ static nserror verify_browser_register(struct gui_browser_table *gbt) if (gbt->set_search_ico == NULL) { gbt->set_search_ico = gui_default_set_search_ico; } - if (gbt->get_resource_url == NULL) { - gbt->get_resource_url = gui_default_get_resource_url; - } if (gbt->launch_url == NULL) { gbt->launch_url = gui_default_launch_url; } @@ -414,6 +439,12 @@ nserror gui_factory_register(struct gui_table *gt) return err; } + /* fetch table */ + err = verify_fetch_register(gt->fetch); + if (err != NSERROR_OK) { + return err; + } + /* download table */ if (gt->download == NULL) { /* set default download table */ diff --git a/desktop/save_complete.c b/desktop/save_complete.c index bd2ed4dea..da87a65fe 100644 --- a/desktop/save_complete.c +++ b/desktop/save_complete.c @@ -148,7 +148,7 @@ static bool save_complete_save_buffer(save_complete_ctx *ctx, char fullpath[PATH_MAX]; strncpy(fullpath, ctx->path, sizeof fullpath); - error = guit->browser->path_add_part(fullpath, sizeof fullpath, leafname); + error = guit->fetch->path_add_part(fullpath, sizeof fullpath, leafname); if (error == false) { warn_user("NoMemory", NULL); return false; @@ -1049,7 +1049,7 @@ static bool save_complete_save_html_document(save_complete_ctx *ctx, else snprintf(filename, sizeof filename, "%p", c); - error = guit->browser->path_add_part(fullpath, sizeof fullpath, filename); + error = guit->fetch->path_add_part(fullpath, sizeof fullpath, filename); if (error == false) { warn_user("NoMemory", NULL); return false; @@ -1126,7 +1126,7 @@ static bool save_complete_inventory(save_complete_ctx *ctx) char fullpath[PATH_MAX]; strncpy(fullpath, ctx->path, sizeof fullpath); - error = guit->browser->path_add_part(fullpath, sizeof fullpath, "Inventory"); + error = guit->fetch->path_add_part(fullpath, sizeof fullpath, "Inventory"); if (error == false) { warn_user("NoMemory", NULL); return false; |