summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xamiga/arexx.c6
-rw-r--r--amiga/bitmap.c26
-rwxr-xr-xamiga/bitmap.h1
-rwxr-xr-xamiga/clipboard.h2
-rwxr-xr-xamiga/context_menu.c24
-rw-r--r--amiga/download.c101
-rwxr-xr-xamiga/download.h16
-rw-r--r--amiga/drag.c16
-rwxr-xr-xamiga/gui_options.c2
-rw-r--r--amiga/iff_dr2d.c2
-rw-r--r--amiga/iff_dr2d.h1
-rwxr-xr-xamiga/menu.c55
-rw-r--r--amiga/options.h2
-rw-r--r--amiga/save_pdf.c2
14 files changed, 188 insertions, 68 deletions
diff --git a/amiga/arexx.c b/amiga/arexx.c
index d5ccce493..02e0e1e23 100755
--- a/amiga/arexx.c
+++ b/amiga/arexx.c
@@ -19,11 +19,11 @@
#include "amiga/os3support.h"
#include "amiga/arexx.h"
-#include "desktop/browser.h"
-#include "desktop/history_core.h"
-#include "amiga/gui.h"
#include "amiga/download.h"
+#include "amiga/gui.h"
#include "amiga/options.h"
+#include "desktop/browser.h"
+#include "desktop/history_core.h"
#include "utils/testament.h"
#include <string.h>
diff --git a/amiga/bitmap.c b/amiga/bitmap.c
index 162eb9d0d..ff07da910 100644
--- a/amiga/bitmap.c
+++ b/amiga/bitmap.c
@@ -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;
+}
diff --git a/amiga/bitmap.h b/amiga/bitmap.h
index d2246d242..e4c31637c 100755
--- a/amiga/bitmap.h
+++ b/amiga/bitmap.h
@@ -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
diff --git a/amiga/clipboard.h b/amiga/clipboard.h
index 7a115b268..f9be4f419 100755
--- a/amiga/clipboard.h
+++ b/amiga/clipboard.h
@@ -18,6 +18,8 @@
#ifndef AMIGA_CLIPBOARD_H
#define AMIGA_CLIPBOARD_H
+#include <stdbool.h>
+
struct bitmap;
struct hlcache_handle;
struct selection;
diff --git a/amiga/context_menu.c b/amiga/context_menu.c
index c67647bad..cdd3df584 100755
--- a/amiga/context_menu.c
+++ b/amiga/context_menu.c
@@ -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;
diff --git a/amiga/download.c b/amiga/download.c
index 469490628..4cf9834f7 100644
--- a/amiga/download.c
+++ b/amiga/download.c
@@ -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->do_DefaultTool = "IconX";
+
+ PutIconTags(fname,dobj,
+ ICONPUTA_NotifyWorkbench,TRUE,
+ TAG_DONE);
+
+ FreeDiskObject(dobj);
+ }
+ FreeVec(linkname);
+ }
+ ami_update_pointer(g->shared->win,GUI_POINTER_DEFAULT);
+ }
+}
- dobj = GetIconTags(NULL,ICONGETA_GetDefaultName,"url",
- ICONGETA_GetDefaultType,WBPROJECT,
- TAG_DONE);
+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;
- dobj->do_DefaultTool = "IconX";
+ if(option_ask_overwrite == false) return TRUE;
- PutIconTags(fname,dobj,
- ICONPUTA_NotifyWorkbench,TRUE,
- TAG_DONE);
+ lock = Lock(file, ACCESS_READ);
- FreeDiskObject(dobj);
- }
- FreeVec(linkname);
- ami_update_pointer(g->shared->win,GUI_POINTER_DEFAULT);
+ 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;
}
diff --git a/amiga/download.h b/amiga/download.h
index b4315c74c..99f11df5a 100755
--- a/amiga/download.h
+++ b/amiga/download.h
@@ -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
diff --git a/amiga/drag.c b/amiga/drag.c
index 038efeed5..77a44dab7 100644
--- a/amiga/drag.c
+++ b/amiga/drag.c
@@ -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
}
diff --git a/amiga/gui_options.c b/amiga/gui_options.c
index 9aa344a5d..4a1d2ee4a 100755
--- a/amiga/gui_options.c
+++ b/amiga/gui_options.c
@@ -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,
diff --git a/amiga/iff_dr2d.c b/amiga/iff_dr2d.c
index 44b3fdae4..dfc152827 100644
--- a/amiga/iff_dr2d.c
+++ b/amiga/iff_dr2d.c
@@ -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))
diff --git a/amiga/iff_dr2d.h b/amiga/iff_dr2d.h
index fcd1f505e..a13817ef0 100644
--- a/amiga/iff_dr2d.h
+++ b/amiga/iff_dr2d.h
@@ -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')
diff --git a/amiga/menu.c b/amiga/menu.c
index 616762721..c39eb94bc 100755
--- a/amiga/menu.c
+++ b/amiga/menu.c
@@ -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;
diff --git a/amiga/options.h b/amiga/options.h
index 086d45c11..93bb1223c 100644
--- a/amiga/options.h
+++ b/amiga/options.h
@@ -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; \
diff --git a/amiga/save_pdf.c b/amiga/save_pdf.c
index c1a6537a8..16592215b 100644
--- a/amiga/save_pdf.c
+++ b/amiga/save_pdf.c
@@ -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;