From 834eb20101ae4c09875c2f218b4fd9baa0e588e1 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 8 Nov 2008 23:08:55 +0000 Subject: AmigaOS implementation of complete page save. svn path=/trunk/netsurf/; revision=5653 --- !NetSurf/Resources/de/Messages | 1 + !NetSurf/Resources/en/Messages | 1 + !NetSurf/Resources/fr/Messages | 1 + !NetSurf/Resources/it/Messages | 1 + !NetSurf/Resources/nl/Messages | 1 + Makefile.sources | 2 +- amiga/gui.c | 21 +- amiga/gui.h | 2 + amiga/menu.c | 75 ++-- amiga/menu.h | 4 +- amiga/save_complete.c | 821 +++++++++++++++++++++++++++++++++++++++++ amiga/save_complete.h | 32 ++ 12 files changed, 932 insertions(+), 30 deletions(-) create mode 100755 amiga/save_complete.c create mode 100755 amiga/save_complete.h diff --git a/!NetSurf/Resources/de/Messages b/!NetSurf/Resources/de/Messages index ad89fdf50..dad6f16b2 100644 --- a/!NetSurf/Resources/de/Messages +++ b/!NetSurf/Resources/de/Messages @@ -229,6 +229,7 @@ CloseWindow:Close window SaveAs:Save as Source:Source... TextNS:Text... +SaveCompNS:Complete... PDF:PDF... # Edit menu diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages index 878221558..9add2acfb 100644 --- a/!NetSurf/Resources/en/Messages +++ b/!NetSurf/Resources/en/Messages @@ -229,6 +229,7 @@ CloseWindow:Close window SaveAs:Save as Source:Source... TextNS:Text... +SaveCompNS:Complete... PDF:PDF... # Edit menu diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages index d01e30df5..7b7b8fedc 100644 --- a/!NetSurf/Resources/fr/Messages +++ b/!NetSurf/Resources/fr/Messages @@ -229,6 +229,7 @@ CloseWindow:Close window SaveAs:Save as Source:Source... TextNS:Text... +SaveCompNS:Complete... PDF:PDF... # Edit menu diff --git a/!NetSurf/Resources/it/Messages b/!NetSurf/Resources/it/Messages index 9a97aa6c0..398c1fd56 100755 --- a/!NetSurf/Resources/it/Messages +++ b/!NetSurf/Resources/it/Messages @@ -230,6 +230,7 @@ CloseWindow:Chiudi finestra SaveAs:Salva come Source:Sorgente... TextNS:Testo... +SaveCompNS:Complete... PDF:PDF... # Edit menu diff --git a/!NetSurf/Resources/nl/Messages b/!NetSurf/Resources/nl/Messages index fbdc0b23f..3fd30af51 100644 --- a/!NetSurf/Resources/nl/Messages +++ b/!NetSurf/Resources/nl/Messages @@ -229,6 +229,7 @@ CloseWindow:Close window SaveAs:Save as Source:Source... TextNS:Text... +SaveCompNS:Complete... PDF:PDF... # Edit menu diff --git a/Makefile.sources b/Makefile.sources index 97dc1f9ba..a4b94dfcd 100644 --- a/Makefile.sources +++ b/Makefile.sources @@ -90,7 +90,7 @@ S_DEBUG := $(addprefix debug/,$(S_DEBUG)) S_AMIGA := compat.c gui.c tree.c history.c hotlist.c schedule.c \ thumbnail.c misc.c bitmap.c font.c filetype.c utf8.c login.c \ plotters.c object.c menu.c save_pdf.c arexx.c version.c \ - cookies.c context_menu.c clipboard.c + cookies.c context_menu.c clipboard.c save_complete.c fetch_file.c S_AMIGA := $(addprefix amiga/,$(S_AMIGA)) # S_FRAMEBUFFER are sources purely for the framebuffer build diff --git a/amiga/gui.c b/amiga/gui.c index fa221ea73..e42ca3121 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -66,6 +66,7 @@ #include "amiga/cookies.h" #include "amiga/clipboard.h" #include +#include "amiga/save_complete.h" #ifdef WITH_HUBBUB #include @@ -339,6 +340,7 @@ void gui_init(int argc, char** argv) if(!hotlist) ami_hotlist_init(&hotlist); ami_global_history_initialise(); ami_cookies_initialise(); + save_complete_init(); strcpy(&throbberfile,option_theme); AddPart(&throbberfile,"Theme",100); @@ -393,6 +395,7 @@ void gui_init2(int argc, char** argv) long rarray[] = {0}; struct RDArgs *args; STRPTR template = "URL/A"; + STRPTR temp_homepage_url = NULL; enum { @@ -412,7 +415,7 @@ void gui_init2(int argc, char** argv) { if(rarray[A_URL]) { - option_homepage_url = (char *)strdup(rarray[A_URL]); + temp_homepage_url = (char *)strdup(rarray[A_URL]); } FreeArgs(args); } @@ -451,7 +454,15 @@ void gui_init2(int argc, char** argv) TAG_DONE); } - bw = browser_window_create(option_homepage_url, 0, 0, true,false); // curbw = temp + if(temp_homepage_url) + { + bw = browser_window_create(temp_homepage_url, 0, 0, true,false); + free(temp_homepage_url); + } + else + { + bw = browser_window_create(option_homepage_url, 0, 0, true,false); // curbw = temp + } } void ami_handle_msg(void) @@ -1004,6 +1015,8 @@ void ami_switch_tab(struct gui_window_2 *gwin,bool redraw) if(gwin->tabs == 0) return; + gui_window_get_scroll(gwin->bw->window,&gwin->bw->window->scrollx,&gwin->bw->window->scrolly); + GetAttr(CLICKTAB_CurrentNode,gwin->gadgets[GID_TABS],(ULONG *)&tabnode); GetClickTabNodeAttrs(tabnode, TNA_UserData,&gwin->bw, @@ -1014,6 +1027,8 @@ void ami_switch_tab(struct gui_window_2 *gwin,bool redraw) if(redraw) { + gui_window_set_scroll(gwin->bw->window,gwin->bw->window->scrollx,gwin->bw->window->scrolly); + browser_window_update(gwin->bw,false); if(gwin->bw->current_content) @@ -1253,6 +1268,8 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, if(option_new_tab_active) ami_switch_tab(gwin->shared,false); + ami_update_buttons(gwin->shared); + return gwin; } diff --git a/amiga/gui.h b/amiga/gui.h index aecd888c4..926df6dc6 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -118,6 +118,8 @@ struct gui_window int c_x; int c_y; int c_h; + int scrollx; + int scrolly; }; void ami_get_msg(void); diff --git a/amiga/menu.c b/amiga/menu.c index 481438d8c..abb940298 100755 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -36,6 +36,7 @@ #include "amiga/cookies.h" #include #include "amiga/arexx.h" +#include "amiga/save_complete.h" BOOL menualreadyinit; @@ -62,31 +63,32 @@ void ami_init_menulabs(void) menulab[4] = ami_utf8_easy((char *)messages_get("SaveAs")); menulab[5] = ami_utf8_easy((char *)messages_get("Source")); menulab[6] = ami_utf8_easy((char *)messages_get("TextNS")); - menulab[7] = ami_utf8_easy((char *)messages_get("PDF")); - menulab[8] = NM_BARLABEL; - menulab[9] = ami_utf8_easy((char *)messages_get("CloseTab")); - menulab[10] = ami_utf8_easy((char *)messages_get("CloseWindow")); - menulab[11] = NM_BARLABEL; - menulab[12] = ami_utf8_easy((char *)messages_get("Quit")); - menulab[13] = ami_utf8_easy((char *)messages_get("Edit")); - menulab[14] = ami_utf8_easy((char *)messages_get("CopyNS")); - menulab[15] = ami_utf8_easy((char *)messages_get("Paste")); - menulab[16] = ami_utf8_easy((char *)messages_get("SelectAllNS")); - menulab[17] = ami_utf8_easy((char *)messages_get("ClearNS")); - menulab[18] = ami_utf8_easy((char *)messages_get("Browser")); - menulab[19] = ami_utf8_easy((char *)messages_get("HistGlobalNS")); - menulab[20] = ami_utf8_easy((char *)messages_get("ShowCookies")); - menulab[21] = ami_utf8_easy((char *)messages_get("Hotlist")); - menulab[22] = ami_utf8_easy((char *)messages_get("HotlistAdd")); - menulab[23] = ami_utf8_easy((char *)messages_get("HotlistShowNS")); - menulab[24] = NM_BARLABEL; - - menulab[65] = ami_utf8_easy((char *)messages_get("Settings")); - menulab[66] = ami_utf8_easy((char *)messages_get("SnapshotWindow")); - menulab[67] = ami_utf8_easy((char *)messages_get("SettingsSave")); - menulab[68] = ami_utf8_easy((char *)messages_get("ARexx")); - menulab[69] = ami_utf8_easy((char *)messages_get("ARexxExecute")); - menulab[70] = NM_BARLABEL; + menulab[7] = ami_utf8_easy((char *)messages_get("SaveCompNS")); + menulab[8] = ami_utf8_easy((char *)messages_get("PDF")); + menulab[9] = NM_BARLABEL; + menulab[10] = ami_utf8_easy((char *)messages_get("CloseTab")); + menulab[11] = ami_utf8_easy((char *)messages_get("CloseWindow")); + menulab[12] = NM_BARLABEL; + menulab[13] = ami_utf8_easy((char *)messages_get("Quit")); + menulab[14] = ami_utf8_easy((char *)messages_get("Edit")); + menulab[15] = ami_utf8_easy((char *)messages_get("CopyNS")); + menulab[16] = ami_utf8_easy((char *)messages_get("Paste")); + menulab[17] = ami_utf8_easy((char *)messages_get("SelectAllNS")); + menulab[18] = ami_utf8_easy((char *)messages_get("ClearNS")); + menulab[19] = ami_utf8_easy((char *)messages_get("Browser")); + menulab[20] = ami_utf8_easy((char *)messages_get("HistGlobalNS")); + menulab[21] = ami_utf8_easy((char *)messages_get("ShowCookies")); + menulab[22] = ami_utf8_easy((char *)messages_get("Hotlist")); + menulab[23] = ami_utf8_easy((char *)messages_get("HotlistAdd")); + menulab[24] = ami_utf8_easy((char *)messages_get("HotlistShowNS")); + menulab[25] = NM_BARLABEL; + + menulab[AMI_MENU_HOTLIST_MAX] = ami_utf8_easy((char *)messages_get("Settings")); + menulab[AMI_MENU_HOTLIST_MAX+1] = ami_utf8_easy((char *)messages_get("SnapshotWindow")); + menulab[AMI_MENU_HOTLIST_MAX+2] = ami_utf8_easy((char *)messages_get("SettingsSave")); + menulab[AMI_MENU_HOTLIST_MAX+3] = ami_utf8_easy((char *)messages_get("ARexx")); + menulab[AMI_MENU_HOTLIST_MAX+4] = ami_utf8_easy((char *)messages_get("ARexxExecute")); + menulab[AMI_MENU_HOTLIST_MAX+5] = NM_BARLABEL; } struct NewMenu *ami_create_menu(ULONG type) @@ -101,6 +103,7 @@ struct NewMenu *ami_create_menu(ULONG type) { NM_ITEM,0,0,0,0,0,}, // save { NM_SUB,0,"S",0,0,0,}, // save as source { NM_SUB,0,0,0,0,0,}, // save as text + { NM_SUB,0,0,0,0,0,}, // save as complete { NM_SUB,0,0,0,0,0,}, // save as pdf { NM_ITEM,NM_BARLABEL,0,0,0,0,}, { NM_ITEM,0,"K",0,0,0,}, // close tab @@ -356,6 +359,7 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item) bool openwin=false; bool opentab=true; char *temp; + BPTR lock = 0; if(option_force_tabs) { @@ -425,6 +429,27 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item) break; case 2: + if(AslRequestTags(filereq, + ASLFR_TitleText,messages_get("NetSurf"), + ASLFR_Screen,scrn, + ASLFR_DoSaveMode,TRUE, + ASLFR_InitialFile,FilePart(gwin->bw->current_content->url), + TAG_DONE)) + { + strlcpy(&fname,filereq->fr_Drawer,1024); + AddPart(fname,filereq->fr_File,1024); + ami_update_pointer(gwin->win,GUI_POINTER_WAIT); + if(lock = CreateDir(fname)) + { + UnLock(lock); + save_complete(gwin->bw->current_content,fname); + SetComment(fname,gwin->bw->current_content->url); + } + ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT); + } + break; + + case 3: #ifdef WITH_PDF_EXPORT if(AslRequestTags(filereq, ASLFR_TitleText,messages_get("NetSurf"), diff --git a/amiga/menu.h b/amiga/menu.h index d475a3f09..cc666b5f1 100755 --- a/amiga/menu.h +++ b/amiga/menu.h @@ -28,10 +28,10 @@ /* Maximum number of menu items - first value is number of static items * (ie. everything not intially defined as NM_IGNORE) */ -#define AMI_MENU_MAX 31 + AMI_HOTLIST_ITEMS +#define AMI_MENU_MAX 32 + AMI_HOTLIST_ITEMS /* Where the hotlist entries start */ -#define AMI_MENU_HOTLIST 25 +#define AMI_MENU_HOTLIST 26 /* Where the hotlist entries end */ #define AMI_MENU_HOTLIST_MAX AMI_MENU_HOTLIST+AMI_HOTLIST_ITEMS diff --git a/amiga/save_complete.c b/amiga/save_complete.c new file mode 100755 index 000000000..26b55adf5 --- /dev/null +++ b/amiga/save_complete.c @@ -0,0 +1,821 @@ +/* + * Copyright 2004 John M Bell + * Copyright 2004-2007 James Bursa + * Copyright 2008 Chris Young + * + * 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 "utils/config.h" +#include "css/css.h" +#include "render/box.h" +#include "amiga/save_complete.h" +#include "utils/log.h" +#include "utils/url.h" +#include "utils/utils.h" +#include +#include +#include + +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; + htmlParserCtxtPtr parser; + BPTR fh = 0; + + 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_STYLE; i != c->data.html.stylesheet_count; i++) { + struct content *css = c->data.html.stylesheet_content[i]; + char *source; + int source_len; + + if (!css) + continue; + if (save_complete_list_check(css)) + continue; + + if (i != STYLESHEET_STYLE) { + if (!save_complete_list_add(css)) { + warn_user("NoMemory", 0); + return false; + } + } + + if (!save_imported_sheets(css, path)) + return false; + + if (i == STYLESHEET_STYLE) + continue; /* don't save