From 355799ce0bbb078237dfc1ae9874bbc5342acbc4 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 17 Dec 2009 23:55:02 +0000 Subject: Merge branches/MarkieB/gtkmain to trunk. svn path=/trunk/netsurf/; revision=9729 --- riscos/gui.c | 2 +- riscos/gui.h | 2 +- riscos/menus.c | 2 +- riscos/save.c | 67 +++- riscos/save_complete.c | 759 --------------------------------------------- riscos/save_complete.h | 32 -- riscos/search.c | 813 ++++++++++++------------------------------------- riscos/searchweb.c | 18 ++ riscos/window.c | 15 + 9 files changed, 303 insertions(+), 1407 deletions(-) delete mode 100644 riscos/save_complete.c delete mode 100644 riscos/save_complete.h create mode 100644 riscos/searchweb.c (limited to 'riscos') diff --git a/riscos/gui.c b/riscos/gui.c index 594488341..3fa95eaca 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -57,6 +57,7 @@ #include "desktop/gui.h" #include "desktop/netsurf.h" #include "desktop/options.h" +#include "desktop/save_complete.h" #include "desktop/tree.h" #include "render/box.h" #include "render/font.h" @@ -76,7 +77,6 @@ #include "riscos/print.h" #include "riscos/query.h" #include "riscos/save.h" -#include "riscos/save_complete.h" #include "riscos/textselection.h" #include "riscos/theme.h" #include "riscos/treeview.h" diff --git a/riscos/gui.h b/riscos/gui.h index 2eaf7cb27..f7ddedd73 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -199,7 +199,7 @@ void ro_gui_debugwin_open(void); /* in search.c */ void ro_gui_search_init(void); -void ro_gui_search_prepare(struct gui_window *g); +void ro_gui_search_prepare(struct browser_window *g); bool ro_gui_search_prepare_menu(void); /* in print.c */ diff --git a/riscos/menus.c b/riscos/menus.c index ab286a1c9..3e6fe7615 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -2284,7 +2284,7 @@ void ro_gui_menu_prepare_action(wimp_w owner, menu_action action, ro_gui_menu_set_entry_shaded(current_menu, action, result); if ((!result) && (windows)) { - ro_gui_search_prepare(g); + ro_gui_search_prepare(g->bw); } if ((t) && (!t->editor) && (t->type == THEME_BROWSER_TOOLBAR)) diff --git a/riscos/save.c b/riscos/save.c index 292c46194..44a2b1835 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -35,7 +35,9 @@ #include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" +#include "content/content.h" #include "desktop/netsurf.h" +#include "desktop/save_complete.h" #include "desktop/save_text.h" #include "desktop/selection.h" #include "image/bitmap.h" @@ -48,7 +50,6 @@ #include "riscos/options.h" #include "riscos/query.h" #include "riscos/save.h" -#include "riscos/save_complete.h" #include "riscos/save_draw.h" #include "riscos/save_pdf.h" #include "riscos/textselection.h" @@ -988,6 +989,70 @@ void ro_gui_save_done(void) gui_save_content = 0; } +/** +* conducts the filesystem save appropriate to the gui +* \param path save path +* \param filename name of file to save +* \param len data length +* \param sourcedata pointer to data to save, NULL when all data in c +* \param type content type +* \return true for success +*/ + +bool save_complete_gui_save(const char *path, const char *filename, size_t len, + const char *sourcedata, content_type type) +{ + char *fullpath; + os_error *error; + int namelen = strlen(path) + strlen(filename) + 2; + int rotype; + fullpath = malloc(namelen); + if (fullpath == NULL) { + warn_user("NoMemory", 0); + return false; + } + snprintf(fullpath, namelen, "%s.%s", path, filename); + rotype = ro_content_filetype_from_type(type); + error = xosfile_save_stamped(fullpath, rotype, (byte *) sourcedata, + (byte *) sourcedata + len); + free(fullpath); + if (error) { + LOG(("xosfile_save_stamped: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("SaveError", error->errmess); + return false; + } + return true; +} + +/** +* wrapper for lib function htmlSaveFileFormat; front sets path from +* path + filename in a filesystem-specific way +*/ + +int save_complete_htmlSaveFileFormat(const char *path, const char *filename, + xmlDocPtr cur, const char *encoding, int format) +{ + os_error *error; + int ret; + int len = strlen(path) + strlen(filename) + 2; + char *fullpath = malloc(len); + if (fullpath == NULL){ + warn_user("NoMemory", 0); + return -1; + } + snprintf(fullpath, len, "%s.%s", path, filename); + ret = htmlSaveFileFormat(fullpath, cur, encoding, format); + error = xosfile_set_type(fullpath, 0xFAF); + if (error) { + LOG(("xosfile_save_stamped: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("SaveError", error->errmess); + return false; + } + free(fullpath); + return ret; +} /** * Prepare an application directory and save_complete() to it. diff --git a/riscos/save_complete.c b/riscos/save_complete.c deleted file mode 100644 index 3ac559784..000000000 --- a/riscos/save_complete.c +++ /dev/null @@ -1,759 +0,0 @@ -/* - * Copyright 2004 John M Bell - * Copyright 2004-2007 James Bursa - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** \file - * Save HTML document with dependencies (implementation). - */ - -#include "utils/config.h" - -#define _GNU_SOURCE /* for strndup */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "oslib/osfile.h" -#include "utils/config.h" -#include "content/content.h" -#include "css/css.h" -#include "render/box.h" -#include "riscos/gui.h" -#include "riscos/save_complete.h" -#include "utils/log.h" -#include "utils/url.h" -#include "utils/utils.h" - -regex_t save_complete_import_re; - -/** An entry in save_complete_list. */ -struct save_complete_entry { - struct content *content; - struct save_complete_entry *next; /**< Next entry in list */ -}; - -/** List of urls seen and saved so far. */ -static struct save_complete_entry *save_complete_list = 0; - -static bool save_complete_html(struct content *c, const char *path, - bool index); -static bool save_imported_sheets(struct content *c, const char *path); -static char * rewrite_stylesheet_urls(const char *source, unsigned int size, - int *osize, const char *base); -static bool rewrite_document_urls(xmlDoc *doc, const char *base); -static bool rewrite_urls(xmlNode *n, const char *base); -static bool rewrite_url(xmlNode *n, const char *attr, const char *base); -static bool save_complete_list_add(struct content *content); -static struct content * save_complete_list_find(const char *url); -static bool save_complete_list_check(struct content *content); -/* static void save_complete_list_dump(void); */ -static bool save_complete_inventory(const char *path); - -/** - * Save an HTML page with all dependencies. - * - * \param c CONTENT_HTML to save - * \param path directory to save to (must exist) - * \return true on success, false on error and error reported - */ - -bool save_complete(struct content *c, const char *path) -{ - bool result; - - result = save_complete_html(c, path, true); - - if (result) - result = save_complete_inventory(path); - - /* free save_complete_list */ - while (save_complete_list) { - struct save_complete_entry *next = save_complete_list->next; - free(save_complete_list); - save_complete_list = next; - } - - return result; -} - - -/** - * Save an HTML page with all dependencies, recursing through imported pages. - * - * \param c CONTENT_HTML to save - * \param path directory to save to (must exist) - * \param index true to save as "index" - * \return true on success, false on error and error reported - */ - -bool save_complete_html(struct content *c, const char *path, bool index) -{ - char spath[256]; - unsigned int i; - xmlDocPtr doc; - os_error *error; - - if (c->type != CONTENT_HTML) - return false; - - if (save_complete_list_check(c)) - return true; - - /* save stylesheets, ignoring the base and adblocking sheets */ - for (i = STYLESHEET_START; i != c->data.html.stylesheet_count; i++) { - struct content *css = c->data.html.stylesheets[i].c; - char *source; - int source_len; - bool is_style; - - if (!css) - continue; - if (save_complete_list_check(css)) - continue; - - is_style = (strcmp(css->url, c->data.html.base_url) == 0); - - if (is_style == false) { - if (!save_complete_list_add(css)) { - warn_user("NoMemory", 0); - return false; - } - } - - if (!save_imported_sheets(css, path)) - return false; - - if (is_style) - continue; /* don't save