From a28f64386e8f308d5a8e57b31b4d00a02cb8caa9 Mon Sep 17 00:00:00 2001 From: Chris Young Date: Sat, 28 Mar 2009 12:50:19 +0000 Subject: Implement a download queue for ARexx-initiated downloads. Working manually, however GummiSurf is causing it to crash for some reason. Split download/save routines off into a new file. svn path=/trunk/netsurf/; revision=6966 --- Makefile.sources | 3 +- amiga/arexx.c | 12 ++- amiga/download.c | 314 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ amiga/download.h | 47 +++++++++ amiga/gui.c | 250 ++----------------------------------------- amiga/gui.h | 17 +-- 6 files changed, 385 insertions(+), 258 deletions(-) create mode 100644 amiga/download.c create mode 100755 amiga/download.h diff --git a/Makefile.sources b/Makefile.sources index 174b9d740..9492e144c 100644 --- a/Makefile.sources +++ b/Makefile.sources @@ -86,7 +86,8 @@ 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 save_complete.c \ - fetch_file.c fetch_mailto.c search.c history_local.c + fetch_file.c fetch_mailto.c search.c history_local.c \ + download.c S_AMIGA := $(addprefix amiga/,$(S_AMIGA)) # S_FRAMEBUFFER are sources purely for the framebuffer build diff --git a/amiga/arexx.c b/amiga/arexx.c index a485c9327..bfa1e4253 100755 --- a/amiga/arexx.c +++ b/amiga/arexx.c @@ -23,6 +23,8 @@ #include "desktop/browser.h" #include "amiga/gui.h" #include +#include +#include "amiga/download.h" const char * const verarexx; const int verver; @@ -109,10 +111,16 @@ void ami_arexx_cleanup(void) STATIC VOID rx_open(struct ARexxCmd *cmd, struct RexxMsg *rxm __attribute__((unused))) { + struct dlnode *dln; + if(cmd->ac_ArgList[2]) { - curbw->window->dlfilename = strdup(cmd->ac_ArgList[2]); - browser_window_download(curbw,(char *)cmd->ac_ArgList[0],NULL); + dln = AllocVec(sizeof(struct dlnode),MEMF_PRIVATE | MEMF_CLEAR); + dln->filename = strdup((char *)cmd->ac_ArgList[2]); + dln->node.ln_Name = strdup((char *)cmd->ac_ArgList[0]); + dln->node.ln_Type = NT_USER; + AddTail(&curbw->window->dllist,dln); + if(!curbw->download) browser_window_download(curbw,(char *)cmd->ac_ArgList[0],NULL); } else if(cmd->ac_ArgList[1]) { diff --git a/amiga/download.c b/amiga/download.c new file mode 100644 index 000000000..e8350425f --- /dev/null +++ b/amiga/download.c @@ -0,0 +1,314 @@ +/* + * Copyright 2008,2009 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 . + */ + +#include +#include +#include +#include +#include + +#include "amiga/download.h" +#include "amiga/object.h" +#include "amiga/options.h" + +#include +#include + +#include +#include +#include +#include + +#include + +void ami_drag_save(struct Window *win); + +struct gui_download_window *gui_download_window_create(const char *url, + const char *mime_type, struct fetch *fetch, + unsigned int total_size, struct gui_window *gui) +{ + char fname[1024]; + struct gui_download_window *dw; + APTR va[3]; + + DebugPrintF("%s\n%lx\n",url,gui); + + if((!IsListEmpty(&gui->dllist)) && (dw->dln = FindName(&gui->dllist,url))) + { + DebugPrintF("%lx node\n",dw->dln); + strcpy(fname,dw->dln->filename); + DebugPrintF("%s fname\n",dw->dln->filename); + free(dw->dln->node.ln_Name); + dw->dln->node.ln_Name = NULL; + } + else + { + if(AslRequestTags(savereq, + ASLFR_TitleText,messages_get("NetSurf"), + ASLFR_Screen,scrn, + ASLFR_InitialFile,FilePart(url), + TAG_DONE)) + { + strlcpy(&fname,savereq->fr_Drawer,1024); + AddPart((STRPTR)&fname,savereq->fr_File,1024); + } + else return NULL; + } + + dw = AllocVec(sizeof(struct gui_download_window),MEMF_PRIVATE | MEMF_CLEAR); + + dw->size = total_size; + dw->downloaded = 0; + dw->bw = gui->shared->bw; + + va[0] = (APTR)dw->downloaded; + va[1] = (APTR)dw->size; + va[2] = 0; + + if(!(dw->fh = FOpen((STRPTR)&fname,MODE_NEWFILE,0))) + { + FreeVec(dw); + return NULL; + } + + SetComment(fname,url); + + dw->objects[OID_MAIN] = WindowObject, + WA_ScreenTitle,nsscreentitle, + WA_Title, url, + WA_Activate, TRUE, + WA_DepthGadget, TRUE, + WA_DragBar, TRUE, + WA_CloseGadget, FALSE, + WA_SizeGadget, TRUE, + WA_CustomScreen,scrn, + WINDOW_IconifyGadget, TRUE, + WINDOW_LockHeight,TRUE, + WINDOW_Position, WPOS_CENTERSCREEN, + WINDOW_ParentGroup, dw->gadgets[GID_MAIN] = VGroupObject, + LAYOUT_AddChild, dw->gadgets[GID_STATUS] = FuelGaugeObject, + GA_ID,GID_STATUS, + GA_Text,messages_get("amiDownload"), + FUELGAUGE_Min,0, + FUELGAUGE_Max,total_size, + FUELGAUGE_Level,0, + FUELGAUGE_Ticks,11, + FUELGAUGE_ShortTicks,TRUE, + FUELGAUGE_VarArgs,va, + FUELGAUGE_Percent,FALSE, + FUELGAUGE_Justification,FGJ_CENTER, + StringEnd, + CHILD_NominalSize,TRUE, + CHILD_WeightedHeight,0, + EndGroup, + EndWindow; + + dw->win = (struct Window *)RA_OpenWindow(dw->objects[OID_MAIN]); + + dw->node = AddObject(window_list,AMINS_DLWINDOW); + dw->node->objstruct = dw; + + return dw; +} + +void gui_download_window_data(struct gui_download_window *dw, const char *data, + unsigned int size) +{ + APTR va[3]; + if(!dw) return; + + FWrite(dw->fh,data,1,size); + + dw->downloaded = dw->downloaded + size; + + va[0] = (APTR)dw->downloaded; + va[1] = (APTR)dw->size; + va[2] = 0; + + if(dw->size) + { + RefreshSetGadgetAttrs(dw->gadgets[GID_STATUS],dw->win,NULL, + FUELGAUGE_Level,dw->downloaded, + GA_Text,messages_get("amiDownload"), + FUELGAUGE_VarArgs,va, + TAG_DONE); + } + else + { + RefreshSetGadgetAttrs(dw->gadgets[GID_STATUS],dw->win,NULL, + FUELGAUGE_Level,dw->downloaded, + GA_Text,messages_get("amiDownloadU"), + FUELGAUGE_VarArgs,va, + TAG_DONE); + } +} + +void gui_download_window_error(struct gui_download_window *dw, + const char *error_msg) +{ + warn_user("Unwritten",""); + gui_download_window_done(dw); +} + +void gui_download_window_done(struct gui_download_window *dw) +{ + struct dlnode *dln,*dln2; + struct browser_window *bw = dw->bw; + bool queuedl = false; + + if(!dw) return; + + bw->download = false; + + if(dln = dw->dln) + { + dln2 = GetSucc(dln); + if(dln != dln2) queuedl = true; + + free(dln->filename); + Remove(dln); + FreeVec(dln); + } + + FClose(dw->fh); + DisposeObject(dw->objects[OID_MAIN]); + DelObject(dw->node); + + if(queuedl) browser_window_download(bw,dln2->node.ln_Name,NULL); +} + +void ami_free_download_list(struct List *dllist) +{ + struct dlnode *node; + struct dlnode *nnode; + + node = (struct dlnode *)GetHead((struct List *)dllist); + + while(nnode=(struct dlnode *)GetSucc((struct dlnode *)node)) + { + free(node->node.ln_Name); + free(node->filename); + Remove(node); + FreeVec(node); + + node=nnode; + } +} + +void gui_drag_save_object(gui_save_type type, struct content *c, + struct gui_window *g) +{ + if(strcmp(option_use_pubscreen,"Workbench")) return; + + gui_window_set_pointer(g,AMI_GUI_POINTER_DRAG); + drag_save_data = c; + drag_save = type; +} + +void gui_drag_save_selection(struct selection *s, struct gui_window *g) +{ + if(strcmp(option_use_pubscreen,"Workbench")) return; + + gui_window_set_pointer(g,AMI_GUI_POINTER_DRAG); + drag_save_data = s; + drag_save = GUI_SAVE_TEXT_SELECTION; +} + +void ami_drag_save(struct Window *win) +{ + ULONG which,type; + char path[1025],dpath[1025]; + + which = WhichWorkbenchObject(NULL,scrn->MouseX,scrn->MouseY, + WBOBJA_Type,&type, + WBOBJA_FullPath,&path, + WBOBJA_FullPathSize,1024, + WBOBJA_DrawerPath,&dpath, + WBOBJA_DrawerPathSize,1024, + TAG_DONE); + + if((which == WBO_DRAWER) || ((which == WBO_ICON) && (type > WBDRAWER))) + { + strcpy(path,dpath); + } + else if(which == WBO_NONE) + { + drag_save = 0; + drag_save_data = NULL; + return; + } + + if(path[0] == '\0') + { + drag_save = 0; + drag_save_data = NULL; + return; + } + + ami_update_pointer(win,GUI_POINTER_WAIT); + + switch(drag_save) + { + case GUI_SAVE_OBJECT_ORIG: // object + case GUI_SAVE_SOURCE: + { + struct content *c = drag_save_data; + BPTR fh = 0; + AddPart(path,c->title,1024); + + if(fh = FOpen(path,MODE_NEWFILE,0)) + { + FWrite(fh,c->source_data,1,c->source_size); + FClose(fh); + SetComment(path,c->url); + } + } + break; + + case GUI_SAVE_TEXT_SELECTION: // selection + AddPart(path,"netsurf_text_file",1024); + selection_save_text((struct selection *)drag_save_data,path); + break; + + case GUI_SAVE_COMPLETE: + { + struct content *c = drag_save_data; + BPTR lock = 0; + + AddPart(path,c->title,1024); + if(lock = CreateDir(path)) + { + UnLock(lock); + save_complete(c,path); + SetComment(path,c->url); + } + } + break; + + case GUI_SAVE_OBJECT_NATIVE: + { + struct content *c = drag_save_data; + bitmap_save(c->bitmap,path,0); + } + break; + } + + drag_save = 0; + drag_save_data = NULL; + ami_update_pointer(win,GUI_POINTER_DEFAULT); +} diff --git a/amiga/download.h b/amiga/download.h new file mode 100755 index 000000000..b6c1f9db6 --- /dev/null +++ b/amiga/download.h @@ -0,0 +1,47 @@ +/* + * Copyright 2008-9 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 . + */ + +#ifndef AMIGA_DOWNLOAD_H +#define AMIGA_DOWNLOAD_H +#include "amiga/gui.h" + +struct dlnode +{ + struct Node node; + char *filename; +}; + +struct gui_download_window { + struct Window *win; + Object *objects[OID_LAST]; + struct Gadget *gadgets[GID_LAST]; + struct nsObject *node; + ULONG pad[5]; + BPTR fh; + uint32 size; + uint32 downloaded; + struct dlnode *dln; + struct browser_window *bw; +}; + +int drag_save; +void *drag_save_data; + +void ami_free_download_list(struct List *dllist); + +#endif diff --git a/amiga/gui.c b/amiga/gui.c index 5e647d843..6868195b7 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -22,6 +22,7 @@ #include "utils/messages.h" #include #include +#include #include "amiga/plotters.h" #include "amiga/schedule.h" #include @@ -38,7 +39,6 @@ #include #include #include -#include #include #include "desktop/selection.h" #include "utils/utf8.h" @@ -73,7 +73,7 @@ #include #include "amiga/history_local.h" #include "amiga/font.h" -#include +#include "amiga/download.h" #ifdef NS_AMIGA_CAIRO #include @@ -89,10 +89,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -120,16 +118,10 @@ ULONG throbber_width,throbber_height,throbber_frames; BOOL rmbtrapped; BOOL locked_screen = FALSE; -int drag_save = 0; -void *drag_save_data = NULL; - extern colour css_scrollbar_fg_colour; extern colour css_scrollbar_bg_colour; extern colour css_scrollbar_arrow_colour; -#define AMI_GUI_POINTER_BLANK GUI_POINTER_PROGRESS+1 -#define AMI_GUI_POINTER_DRAG GUI_POINTER_PROGRESS+2 -#define AMI_LASTPOINTER AMI_GUI_POINTER_DRAG Object *mouseptrobj[AMI_LASTPOINTER+1]; struct BitMap *mouseptrbm[AMI_LASTPOINTER+1]; int mouseptrcurrent=0; @@ -1601,6 +1593,9 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, return NULL; } + NewList(&gwin->dllist); +DebugPrintF("newlist\n"); + /* if(bw->browser_window_type == BROWSER_WINDOW_IFRAME) { @@ -2041,6 +2036,8 @@ void gui_window_destroy(struct gui_window *g) win_destroyed = true; } + ami_free_download_list(&g->dllist); + if(g->shared->tabs > 1) { SetGadgetAttrs(g->shared->gadgets[GID_TABS],g->shared->win,NULL, @@ -2766,239 +2763,6 @@ void gui_window_set_scale(struct gui_window *g, float scale) printf("set scale\n"); } -struct gui_download_window *gui_download_window_create(const char *url, - const char *mime_type, struct fetch *fetch, - unsigned int total_size, struct gui_window *gui) -{ - char fname[1024]; - struct gui_download_window *dw; - APTR va[3]; - - if(gui->dlfilename) - { - strcpy(fname,gui->dlfilename); - free(gui->dlfilename); - gui->dlfilename = NULL; - } - else - { - if(AslRequestTags(savereq, - ASLFR_TitleText,messages_get("NetSurf"), - ASLFR_Screen,scrn, - ASLFR_InitialFile,FilePart(url), - TAG_DONE)) - { - strlcpy(&fname,savereq->fr_Drawer,1024); - AddPart((STRPTR)&fname,savereq->fr_File,1024); - } - else return NULL; - } - - dw = AllocVec(sizeof(struct gui_download_window),MEMF_PRIVATE | MEMF_CLEAR); - - dw->size = total_size; - dw->downloaded = 0; - - va[0] = (APTR)dw->downloaded; - va[1] = (APTR)dw->size; - va[2] = 0; - - if(!(dw->fh = FOpen((STRPTR)&fname,MODE_NEWFILE,0))) - { - FreeVec(dw); - return NULL; - } - - SetComment(fname,url); - - dw->objects[OID_MAIN] = WindowObject, - WA_ScreenTitle,nsscreentitle, - WA_Title, url, - WA_Activate, TRUE, - WA_DepthGadget, TRUE, - WA_DragBar, TRUE, - WA_CloseGadget, FALSE, - WA_SizeGadget, TRUE, - WA_CustomScreen,scrn, - WINDOW_IconifyGadget, TRUE, - WINDOW_LockHeight,TRUE, - WINDOW_Position, WPOS_CENTERSCREEN, - WINDOW_ParentGroup, dw->gadgets[GID_MAIN] = VGroupObject, - LAYOUT_AddChild, dw->gadgets[GID_STATUS] = FuelGaugeObject, - GA_ID,GID_STATUS, - GA_Text,messages_get("amiDownload"), - FUELGAUGE_Min,0, - FUELGAUGE_Max,total_size, - FUELGAUGE_Level,0, - FUELGAUGE_Ticks,11, - FUELGAUGE_ShortTicks,TRUE, - FUELGAUGE_VarArgs,va, - FUELGAUGE_Percent,FALSE, - FUELGAUGE_Justification,FGJ_CENTER, - StringEnd, - CHILD_NominalSize,TRUE, - CHILD_WeightedHeight,0, - EndGroup, - EndWindow; - - dw->win = (struct Window *)RA_OpenWindow(dw->objects[OID_MAIN]); - - dw->node = AddObject(window_list,AMINS_DLWINDOW); - dw->node->objstruct = dw; - - return dw; -} - -void gui_download_window_data(struct gui_download_window *dw, const char *data, - unsigned int size) -{ - APTR va[3]; - if(!dw) return; - - FWrite(dw->fh,data,1,size); - - dw->downloaded = dw->downloaded + size; - - va[0] = (APTR)dw->downloaded; - va[1] = (APTR)dw->size; - va[2] = 0; - - if(dw->size) - { - RefreshSetGadgetAttrs(dw->gadgets[GID_STATUS],dw->win,NULL, - FUELGAUGE_Level,dw->downloaded, - GA_Text,messages_get("amiDownload"), - FUELGAUGE_VarArgs,va, - TAG_DONE); - } - else - { - RefreshSetGadgetAttrs(dw->gadgets[GID_STATUS],dw->win,NULL, - FUELGAUGE_Level,dw->downloaded, - GA_Text,messages_get("amiDownloadU"), - FUELGAUGE_VarArgs,va, - TAG_DONE); - } -} - -void gui_download_window_error(struct gui_download_window *dw, - const char *error_msg) -{ - warn_user("Unwritten",""); - gui_download_window_done(dw); -} - -void gui_download_window_done(struct gui_download_window *dw) -{ - if(!dw) return; - FClose(dw->fh); - DisposeObject(dw->objects[OID_MAIN]); - DelObject(dw->node); -} - -void gui_drag_save_object(gui_save_type type, struct content *c, - struct gui_window *g) -{ - if(strcmp(option_use_pubscreen,"Workbench")) return; - - gui_window_set_pointer(g,AMI_GUI_POINTER_DRAG); - drag_save_data = c; - drag_save = type; -} - -void gui_drag_save_selection(struct selection *s, struct gui_window *g) -{ - if(strcmp(option_use_pubscreen,"Workbench")) return; - - gui_window_set_pointer(g,AMI_GUI_POINTER_DRAG); - drag_save_data = s; - drag_save = GUI_SAVE_TEXT_SELECTION; -} - -void ami_drag_save(struct Window *win) -{ - ULONG which,type; - char path[1025],dpath[1025]; - - which = WhichWorkbenchObject(NULL,scrn->MouseX,scrn->MouseY, - WBOBJA_Type,&type, - WBOBJA_FullPath,&path, - WBOBJA_FullPathSize,1024, - WBOBJA_DrawerPath,&dpath, - WBOBJA_DrawerPathSize,1024, - TAG_DONE); - - if((which == WBO_DRAWER) || ((which == WBO_ICON) && (type > WBDRAWER))) - { - strcpy(path,dpath); - } - else if(which == WBO_NONE) - { - drag_save = 0; - drag_save_data = NULL; - return; - } - - if(path[0] == '\0') - { - drag_save = 0; - drag_save_data = NULL; - return; - } - - ami_update_pointer(win,GUI_POINTER_WAIT); - - switch(drag_save) - { - case GUI_SAVE_OBJECT_ORIG: // object - case GUI_SAVE_SOURCE: - { - struct content *c = drag_save_data; - BPTR fh = 0; - AddPart(path,c->title,1024); - - if(fh = FOpen(path,MODE_NEWFILE,0)) - { - FWrite(fh,c->source_data,1,c->source_size); - FClose(fh); - SetComment(path,c->url); - } - } - break; - - case GUI_SAVE_TEXT_SELECTION: // selection - AddPart(path,"netsurf_text_file",1024); - selection_save_text((struct selection *)drag_save_data,path); - break; - - case GUI_SAVE_COMPLETE: - { - struct content *c = drag_save_data; - BPTR lock = 0; - - AddPart(path,c->title,1024); - if(lock = CreateDir(path)) - { - UnLock(lock); - save_complete(c,path); - SetComment(path,c->url); - } - } - break; - - case GUI_SAVE_OBJECT_NATIVE: - { - struct content *c = drag_save_data; - bitmap_save(c->bitmap,path,0); - } - break; - } - - drag_save = 0; - drag_save_data = NULL; - ami_update_pointer(win,GUI_POINTER_DEFAULT); -} - void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control) { diff --git a/amiga/gui.h b/amiga/gui.h index 52d6179a9..e1968ea50 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -70,20 +70,13 @@ enum OID_LAST }; +#define AMI_GUI_POINTER_BLANK GUI_POINTER_PROGRESS+1 +#define AMI_GUI_POINTER_DRAG GUI_POINTER_PROGRESS+2 +#define AMI_LASTPOINTER AMI_GUI_POINTER_DRAG + struct find_window; struct history_window; -struct gui_download_window { - struct Window *win; - Object *objects[OID_LAST]; - struct Gadget *gadgets[GID_LAST]; - struct nsObject *node; - ULONG pad[5]; - BPTR fh; - uint32 size; - uint32 downloaded; -}; - struct gui_window_2 { struct Window *win; Object *objects[OID_LAST]; @@ -116,8 +109,8 @@ struct gui_window int c_h; int scrollx; int scrolly; - char *dlfilename; struct history_window *hw; + struct List dllist; }; struct gui_globals -- cgit v1.2.3