Implement ask overwrite

svn path=/trunk/netsurf/; revision=12135
This commit is contained in:
Chris Young 2011-03-26 10:33:58 +00:00
parent 2c55af59de
commit 14d6826685
14 changed files with 186 additions and 66 deletions

View File

@ -19,11 +19,11 @@
#include "amiga/os3support.h"
#include "amiga/arexx.h"
#include "amiga/download.h"
#include "amiga/gui.h"
#include "amiga/options.h"
#include "desktop/browser.h"
#include "desktop/history_core.h"
#include "amiga/gui.h"
#include "amiga/download.h"
#include "amiga/options.h"
#include "utils/testament.h"
#include <string.h>

View File

@ -20,6 +20,7 @@
#include "assert.h"
#include "amiga/bitmap.h"
#include "amiga/download.h"
#include <proto/exec.h>
#include <proto/Picasso96API.h>
#ifdef __amigaos4__
@ -137,6 +138,8 @@ bool bitmap_save(void *bitmap, const char *path, unsigned flags)
int err = 0;
Object *dto = NULL;
if(!ami_download_check_overwrite(path, NULL)) return false;
if(dto = ami_datatype_object_from_bitmap(bitmap))
{
err = SaveDTObjectA(dto, NULL, NULL, path, DTWM_IFF, FALSE, NULL);
@ -418,3 +421,26 @@ struct BitMap *ami_getcachenativebm(struct bitmap *bitmap,int width,int height,s
return tbm;
}
APTR ami_colormap_to_clut(struct ColorMap *cmap)
{
int i;
UBYTE *clut = AllocVec(256 * 4, MEMF_PRIVATE | MEMF_CLEAR);
ULONG colour[3 * 256];
if(!clut) return NULL;
/* Get the palette from the ColorMap */
GetRGB32(cmap, 0, 256, (ULONG *)&colour);
/* convert it to a table of ARGB values */
for(i = 0; i < 1024; i += 4)
{
clut[i] = (0xff << 24) |
((colour[i] & 0xff000000) >> 8) |
((colour[i + 1] & 0xff000000) >> 16) |
((colour[i + 2] & 0xff000000) >> 24);
}
return clut;
}

View File

@ -41,4 +41,5 @@ struct bitmap {
struct BitMap *ami_getcachenativebm(struct bitmap *bitmap,int width,int height,struct BitMap *friendbm);
Object *ami_datatype_object_from_bitmap(struct bitmap *bitmap);
APTR ami_colormap_to_clut(struct ColorMap *cmap);
#endif

View File

@ -18,6 +18,8 @@
#ifndef AMIGA_CLIPBOARD_H
#define AMIGA_CLIPBOARD_H
#include <stdbool.h>
struct bitmap;
struct hlcache_handle;
struct selection;

View File

@ -499,13 +499,18 @@ static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved
strlcpy(&fname,savereq->fr_Drawer,1024);
AddPart(fname,savereq->fr_File,1024);
ami_update_pointer(gwin->win,GUI_POINTER_WAIT);
if(fh = FOpen(fname,MODE_NEWFILE,0))
{
if((source_data = content_get_source_data(object, &source_size)))
FWrite(fh, source_data, 1, source_size);
FClose(fh);
SetComment(fname, content_get_url(object));
if(ami_download_check_overwrite(fname, gwin->win))
{
if(fh = FOpen(fname,MODE_NEWFILE,0))
{
if((source_data =
content_get_source_data(object, &source_size)))
FWrite(fh, source_data, 1, source_size);
FClose(fh);
SetComment(fname, content_get_url(object));
}
}
ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
}
@ -529,15 +534,16 @@ static uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved
{
bm->url = content_get_url(object);
bm->title = content_get_title(object);
bitmap_save(bm, fname, 0);
if(bitmap_save(bm, fname, 0))
SetComment(fname, content_get_url(object));
}
#ifdef WITH_NS_SVG
else if(content_get_type(object) == CONTENT_SVG)
{
ami_save_svg(object,fname);
if(ami_save_svg(object,fname))
SetComment(fname, content_get_url(object));
}
#endif
SetComment(fname, content_get_url(object));
ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
}
break;

View File

@ -38,6 +38,7 @@
#include "amiga/bitmap.h"
#include "amiga/iff_dr2d.h"
#include "amiga/theme.h"
#include "amiga/utf8.h"
#include "desktop/download.h"
#include "desktop/selection.h"
@ -60,6 +61,20 @@
#include <reaction/reaction_macros.h>
struct gui_download_window {
struct nsObject *node;
struct Window *win;
Object *objects[GID_LAST];
BPTR fh;
uint32 size;
uint32 downloaded;
struct dlnode *dln;
struct browser_window *bw;
struct download_context *ctx;
char *url;
char fname[1024];
};
struct gui_download_window *gui_download_window_create(download_context *ctx,
struct gui_window *gui)
{
@ -87,8 +102,16 @@ struct gui_download_window *gui_download_window_create(download_context *ctx,
{
strlcpy(&dw->fname,savereq->fr_Drawer,1024);
AddPart((STRPTR)&dw->fname,savereq->fr_File,1024);
if(!ami_download_check_overwrite(dw->fname, gui->shared->win))
{
FreeVec(dw);
return NULL;
}
}
else
{
}
else return NULL;
}
dw->size = total_size;
@ -302,27 +325,69 @@ gui_window_save_link(struct gui_window *g, const char *url, const char *title)
strlcpy(&fname,savereq->fr_Drawer,1024);
AddPart(fname,savereq->fr_File,1024);
ami_update_pointer(g->shared->win,GUI_POINTER_WAIT);
if(fh = FOpen(fname,MODE_NEWFILE,0))
if(ami_download_check_overwrite(fname, g->shared->win))
{
openurlstring = ASPrintf("openurl \"%s\"\n",url);
FWrite(fh,openurlstring,1,strlen(openurlstring));
FClose(fh);
FreeVec(openurlstring);
SetComment(fname,url);
if(fh = FOpen(fname,MODE_NEWFILE,0))
{
/* TODO: Should be URLOpen on OS4.1 */
openurlstring = ASPrintf("openurl \"%s\"\n",url);
FWrite(fh,openurlstring,1,strlen(openurlstring));
FClose(fh);
FreeVec(openurlstring);
SetComment(fname,url);
dobj = GetIconTags(NULL,ICONGETA_GetDefaultName,"url",
ICONGETA_GetDefaultType,WBPROJECT,
TAG_DONE);
dobj = GetIconTags(NULL,ICONGETA_GetDefaultName,"url",
ICONGETA_GetDefaultType,WBPROJECT,
TAG_DONE);
dobj->do_DefaultTool = "IconX";
dobj->do_DefaultTool = "IconX";
PutIconTags(fname,dobj,
ICONPUTA_NotifyWorkbench,TRUE,
TAG_DONE);
PutIconTags(fname,dobj,
ICONPUTA_NotifyWorkbench,TRUE,
TAG_DONE);
FreeDiskObject(dobj);
FreeDiskObject(dobj);
}
FreeVec(linkname);
}
FreeVec(linkname);
ami_update_pointer(g->shared->win,GUI_POINTER_DEFAULT);
}
}
BOOL ami_download_check_overwrite(const char *file, struct Window *win)
{
/* Return TRUE if file can be (over-)written */
int res = 0;
BPTR lock = 0;
if(option_ask_overwrite == false) return TRUE;
lock = Lock(file, ACCESS_READ);
if(lock)
{
UnLock(lock);
char *utf8text = ami_utf8_easy(messages_get("OverwriteFile"));
char *utf8gadget1 = ami_utf8_easy(messages_get("DontReplace"));
char *utf8gadget2 = ami_utf8_easy(messages_get("Replace"));
char *utf8gadgets = ASPrintf("%s|%s", utf8gadget1, utf8gadget2);
free(utf8gadget1);
free(utf8gadget2);
res = TimedDosRequesterTags(TDR_ImageType, TDRIMAGE_WARNING,
TDR_TitleString, messages_get("NetSurf"),
TDR_FormatString, utf8text,
TDR_GadgetString, utf8gadgets,
TDR_Window, win,
TAG_DONE);
if(utf8text) free(utf8text);
if(utf8gadgets) FreeVec(utf8gadgets);
}
else return TRUE;
if(res == 0) return TRUE;
else return FALSE;
}

View File

@ -24,6 +24,7 @@
#include "amiga/gui.h"
struct download_context;
struct gui_download_window;
struct dlnode
{
@ -31,21 +32,8 @@ struct dlnode
char *filename;
};
struct gui_download_window {
struct nsObject *node;
struct Window *win;
Object *objects[GID_LAST];
BPTR fh;
uint32 size;
uint32 downloaded;
struct dlnode *dln;
struct browser_window *bw;
struct download_context *ctx;
char *url;
char fname[1024];
};
void ami_download_window_abort(struct gui_download_window *dw);
BOOL ami_download_window_event(struct gui_download_window *dw);
void ami_free_download_list(struct List *dllist);
BOOL ami_download_check_overwrite(const char *file, struct Window *win);
#endif

View File

@ -31,10 +31,12 @@
#endif
#include <workbench/icon.h>
#include "amiga/clipboard.h"
#include "amiga/download.h"
#include "amiga/drag.h"
#include "amiga/filetype.h"
#include "amiga/options.h"
#include "amiga/icon.h"
#include "amiga/iff_dr2d.h"
#include "amiga/theme.h"
@ -154,6 +156,9 @@ void ami_drag_save(struct Window *win)
BPTR fh = 0;
AddPart(path, content_get_title(c), 1024);
if(!ami_download_check_overwrite(path, win))
break;
if(fh = FOpen(path,MODE_NEWFILE,0))
{
if((source_data = content_get_source_data(c, &source_size)))
@ -167,6 +172,8 @@ void ami_drag_save(struct Window *win)
case GUI_SAVE_TEXT_SELECTION: // selection
AddPart(path,"netsurf_text_file",1024);
if(!ami_download_check_overwrite(path, win))
break;
selection_save_text((struct selection *)drag_save_data,path);
break;
@ -176,6 +183,9 @@ void ami_drag_save(struct Window *win)
BPTR lock = 0;
AddPart(path, content_get_title(c), 1024);
if(!ami_download_check_overwrite(path, win))
break;
if(lock = CreateDir(path))
{
UnLock(lock);
@ -197,12 +207,14 @@ void ami_drag_save(struct Window *win)
{
bm->url = content_get_url(c);
bm->title = content_get_title(c);
bitmap_save(bm, path, 0);
if(bitmap_save(bm, path, 0))
SetComment(path, content_get_url(c));
}
#ifdef WITH_NS_SVG
else if(content_get_type(c) == CONTENT_SVG)
{
ami_save_svg(c, path);
if(ami_save_svg(c, path))
SetComment(path, content_get_url(c));
}
#endif
}

View File

@ -1047,7 +1047,7 @@ void ami_gui_opts_open(void)
GA_RelVerify, TRUE,
GA_Disabled, TRUE,
GA_Text, gadlab[GID_OPTS_OVERWRITE],
GA_Selected, FALSE, //option_ask_overwrite,
GA_Selected, option_ask_overwrite,
CheckBoxEnd,
LAYOUT_AddChild, gow->objects[GID_OPTS_NOTIFY] = CheckBoxObject,
GA_ID, GID_OPTS_NOTIFY,

View File

@ -307,6 +307,8 @@ bool ami_save_svg(struct hlcache_handle *c,char *filename)
char *source_data;
ULONG source_size;
if(!ami_download_check_overwrite(filename, NULL)) return false;
if(iffh = AllocIFF())
{
if(iffh->iff_Stream = Open(filename,MODE_NEWFILE))

View File

@ -24,6 +24,7 @@
#include <stdbool.h>
#ifndef AMIGA_DR2D_STANDALONE
#include "content/content.h"
#include "amiga/download.h"
#endif
#define ID_DR2D MAKE_ID('D','R','2','D')

View File

@ -534,12 +534,17 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
strlcpy(&fname,savereq->fr_Drawer,1024);
AddPart(fname,savereq->fr_File,1024);
ami_update_pointer(gwin->win,GUI_POINTER_WAIT);
if(fh = FOpen(fname,MODE_NEWFILE,0))
if(ami_download_check_overwrite(fname, gwin->win))
{
if((source_data = content_get_source_data(gwin->bw->current_content, &source_size)))
FWrite(fh,source_data, 1, source_size);
FClose(fh);
SetComment(fname, content_get_url(gwin->bw->current_content));
if(fh = FOpen(fname,MODE_NEWFILE,0))
{
if((source_data =
content_get_source_data(gwin->bw->current_content, &source_size)))
FWrite(fh,source_data, 1, source_size);
FClose(fh);
SetComment(fname, content_get_url(gwin->bw->current_content));
}
}
ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
}
@ -555,8 +560,12 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
strlcpy(&fname,savereq->fr_Drawer,1024);
AddPart(fname,savereq->fr_File,1024);
ami_update_pointer(gwin->win,GUI_POINTER_WAIT);
save_as_text(gwin->bw->current_content,fname);
SetComment(fname,content_get_url(gwin->bw->current_content));
if(ami_download_check_overwrite(fname, gwin->win))
{
save_as_text(gwin->bw->current_content,fname);
SetComment(fname,content_get_url(gwin->bw->current_content));
}
ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
}
break;
@ -571,13 +580,16 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
strlcpy(&fname,savereq->fr_Drawer,1024);
AddPart(fname,savereq->fr_File,1024);
ami_update_pointer(gwin->win,GUI_POINTER_WAIT);
if(lock = CreateDir(fname))
if(ami_download_check_overwrite(fname, gwin->win))
{
UnLock(lock);
save_complete(gwin->bw->current_content,fname);
SetComment(fname,content_get_url(gwin->bw->current_content));
ami_superimpose_favicon(fname,
gwin->bw->window->favicon, NULL);
if(lock = CreateDir(fname))
{
UnLock(lock);
save_complete(gwin->bw->current_content,fname);
SetComment(fname,content_get_url(gwin->bw->current_content));
ami_superimpose_favicon(fname,
gwin->bw->window->favicon, NULL);
}
}
ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
}
@ -594,10 +606,12 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
strlcpy(&fname,savereq->fr_Drawer,1024);
AddPart(fname,savereq->fr_File,1024);
ami_update_pointer(gwin->win,GUI_POINTER_WAIT);
save_as_pdf(gwin->bw->current_content,fname);
SetComment(fname, content_get_url(gwin->bw->current_content));
ami_superimpose_favicon(fname,
gwin->bw->window->favicon, "pdf");
if(save_as_pdf(gwin->bw->current_content,fname))
{
SetComment(fname, content_get_url(gwin->bw->current_content));
ami_superimpose_favicon(fname,
gwin->bw->window->favicon, "pdf");
}
ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
}
#endif
@ -617,15 +631,16 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
{
bm->url = content_get_url(gwin->bw->current_content);
bm->title = content_get_title(gwin->bw->current_content);
bitmap_save(bm, fname, 0);
if(bitmap_save(bm, fname, 0))
SetComment(fname, content_get_url(gwin->bw->current_content));
}
#ifdef WITH_NS_SVG
else if(content_get_type(gwin->bw->current_content) == CONTENT_SVG)
{
ami_save_svg(gwin->bw->current_content,fname);
if(ami_save_svg(gwin->bw->current_content,fname))
SetComment(fname, content_get_url(gwin->bw->current_content));
}
#endif
SetComment(fname, content_get_url(gwin->bw->current_content));
ami_update_pointer(gwin->win,GUI_POINTER_DEFAULT);
}
break;

View File

@ -90,7 +90,7 @@ char *option_download_dir = 0; \
bool option_download_notify = false; \
bool option_faster_scroll = true; \
bool option_scale_quality = false; \
bool option_ask_overwrite = false; \
bool option_ask_overwrite = true; \
int option_printer_unit = 0; \
int option_print_scale = 100; \
bool option_startup_no_window = false; \

View File

@ -44,6 +44,8 @@ bool save_as_pdf(struct hlcache_handle *c, const char *path)
{
struct print_settings *psettings;
if(!ami_download_check_overwrite(path, NULL)) return false;
psettings = print_make_settings(PRINT_OPTIONS, path, &haru_nsfont);
if (psettings == NULL)
return false;