mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-11 05:19:18 +03:00
Move non-requester user file operations to file.c
svn path=/trunk/netsurf/; revision=13065
This commit is contained in:
parent
c3fafd63f8
commit
6959a30b26
47
amiga/drag.c
47
amiga/drag.c
@ -31,19 +31,16 @@
|
||||
#endif
|
||||
#include <workbench/icon.h>
|
||||
|
||||
#include "amiga/bitmap.h"
|
||||
#include "amiga/clipboard.h"
|
||||
#include "amiga/download.h"
|
||||
#include "amiga/drag.h"
|
||||
#include "amiga/file.h"
|
||||
#include "amiga/filetype.h"
|
||||
#include "amiga/options.h"
|
||||
#include "amiga/icon.h"
|
||||
#include "amiga/iff_dr2d.h"
|
||||
#include "amiga/theme.h"
|
||||
|
||||
#include "desktop/selection.h"
|
||||
#include "desktop/save_complete.h"
|
||||
|
||||
#include "amiga/bitmap.h"
|
||||
|
||||
#include "utils/errors.h"
|
||||
#include "utils/log.h"
|
||||
@ -156,17 +153,7 @@ void ami_drag_save(struct Window *win)
|
||||
BPTR fh = 0;
|
||||
AddPart(path, content_get_title(c), 1024);
|
||||
|
||||
if(!ami_download_check_overwrite(path, win, 0))
|
||||
break;
|
||||
|
||||
if(fh = FOpen(path,MODE_NEWFILE,0))
|
||||
{
|
||||
if((source_data = content_get_source_data(c, &source_size)))
|
||||
FWrite(fh, source_data, 1, source_size);
|
||||
|
||||
FClose(fh);
|
||||
SetComment(path, nsurl_access(content_get_url(c)));
|
||||
}
|
||||
ami_file_save(AMINS_SAVE_SOURCE, path, win, c, NULL);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -183,39 +170,17 @@ void ami_drag_save(struct Window *win)
|
||||
BPTR lock = 0;
|
||||
|
||||
AddPart(path, content_get_title(c), 1024);
|
||||
if(!ami_download_check_overwrite(path, win, 0))
|
||||
break;
|
||||
|
||||
if(lock = CreateDir(path))
|
||||
{
|
||||
UnLock(lock);
|
||||
save_complete(c,path);
|
||||
SetComment(path, nsurl_access(content_get_url(c)));
|
||||
}
|
||||
amiga_icon_superimpose_favicon(path, drag_save_gui->favicon, NULL);
|
||||
ami_file_save(AMINS_SAVE_COMPLETE, path, win, c, drag_save_gui->favicon);
|
||||
}
|
||||
break;
|
||||
|
||||
case GUI_SAVE_OBJECT_NATIVE:
|
||||
{
|
||||
hlcache_handle *c = drag_save_data;
|
||||
struct bitmap *bm;
|
||||
|
||||
AddPart(path, content_get_title(c), 1024);
|
||||
if(bm = content_get_bitmap(c))
|
||||
{
|
||||
bm->url = (char *)nsurl_access(content_get_url(c));
|
||||
bm->title = (char *)content_get_title(c);
|
||||
if(bitmap_save(bm, path, 0))
|
||||
SetComment(path, nsurl_access(content_get_url(c)));
|
||||
}
|
||||
#ifdef WITH_NS_SVG
|
||||
else if(ami_mime_compare(c, "svg") == true)
|
||||
{
|
||||
if(ami_save_svg(c, path))
|
||||
SetComment(path, nsurl_access(content_get_url(c)));
|
||||
}
|
||||
#endif
|
||||
|
||||
ami_file_save(AMINS_SAVE_IFF, path, win, c, NULL);
|
||||
}
|
||||
break;
|
||||
|
||||
|
204
amiga/file.c
Normal file
204
amiga/file.c
Normal file
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Copyright 2011 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "amiga/bitmap.h"
|
||||
#include "amiga/download.h"
|
||||
#include "amiga/file.h"
|
||||
#include "amiga/filetype.h"
|
||||
#include "amiga/icon.h"
|
||||
#include "amiga/iff_dr2d.h"
|
||||
#include "amiga/options.h"
|
||||
#include "amiga/save_pdf.h"
|
||||
#include "amiga/theme.h"
|
||||
|
||||
#include "content/content.h"
|
||||
#include "content/fetch.h"
|
||||
|
||||
#include "desktop/browser.h"
|
||||
#include "desktop/options.h"
|
||||
#include "desktop/save_complete.h"
|
||||
#include "desktop/save_pdf/pdf_plotters.h"
|
||||
#include "desktop/save_text.h"
|
||||
|
||||
#include "utils/messages.h"
|
||||
#include "utils/url.h"
|
||||
|
||||
#include <proto/asl.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/exec.h>
|
||||
|
||||
static struct Hook aslhookfunc;
|
||||
|
||||
static const ULONG ami_file_asl_mime_hook(struct Hook *mh,
|
||||
struct FileRequester *fr, struct AnchorPathOld *ap)
|
||||
{
|
||||
BPTR file = 0;
|
||||
char buffer[10];
|
||||
char fname[1024];
|
||||
BOOL ret = FALSE;
|
||||
char *mt = NULL;
|
||||
lwc_string *lwc_mt = NULL;
|
||||
lwc_error lerror;
|
||||
content_type ct;
|
||||
|
||||
if(ap->ap_Info.fib_DirEntryType > 0) return(TRUE);
|
||||
|
||||
strcpy(fname,fr->fr_Drawer);
|
||||
AddPart(fname,ap->ap_Info.fib_FileName,1024);
|
||||
|
||||
mt = fetch_mimetype(fname);
|
||||
lerror = lwc_intern_string(mt, strlen(mt), &lwc_mt);
|
||||
if (lerror != lwc_error_ok)
|
||||
return FALSE;
|
||||
|
||||
ct = content_factory_type_from_mime_type(lwc_mt);
|
||||
lwc_string_unref(lwc_mt);
|
||||
|
||||
if(ct != CONTENT_NONE) ret = TRUE;
|
||||
|
||||
free(mt);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ami_file_open(struct gui_window_2 *gwin)
|
||||
{
|
||||
char *temp, *temp2;
|
||||
|
||||
if(AslRequestTags(filereq,
|
||||
ASLFR_TitleText, messages_get("NetSurf"),
|
||||
ASLFR_Screen, scrn,
|
||||
ASLFR_DoSaveMode, FALSE,
|
||||
ASLFR_RejectIcons, TRUE,
|
||||
ASLFR_FilterFunc, &aslhookfunc,
|
||||
TAG_DONE))
|
||||
{
|
||||
if(temp = AllocVec(1024,MEMF_PRIVATE | MEMF_CLEAR))
|
||||
{
|
||||
strlcpy(temp, filereq->fr_Drawer, 1024);
|
||||
AddPart(temp, filereq->fr_File, 1024);
|
||||
temp2 = path_to_url(temp);
|
||||
browser_window_go(gwin->bw, temp2, NULL, true);
|
||||
free(temp2);
|
||||
FreeVec(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ami_file_save(int type, char *fname, struct Window *win,
|
||||
struct hlcache_handle *object, struct hlcache_handle *favicon)
|
||||
{
|
||||
BPTR lock = 0;
|
||||
const char *source_data;
|
||||
ULONG source_size;
|
||||
struct bitmap *bm;
|
||||
BPTR fh=0;
|
||||
|
||||
ami_update_pointer(win, GUI_POINTER_WAIT);
|
||||
|
||||
if(ami_download_check_overwrite(fname, win, 0))
|
||||
{
|
||||
if(fh = FOpen(fname, MODE_NEWFILE,0))
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case AMINS_SAVE_SOURCE:
|
||||
if((source_data = content_get_source_data(object, &source_size)))
|
||||
FWrite(fh, source_data, 1, source_size);
|
||||
break;
|
||||
|
||||
case AMINS_SAVE_COMPLETE:
|
||||
if(lock = CreateDir(fname))
|
||||
{
|
||||
UnLock(lock);
|
||||
save_complete(object, fname);
|
||||
amiga_icon_superimpose_favicon(fname, favicon, NULL);
|
||||
}
|
||||
break;
|
||||
|
||||
case AMINS_SAVE_TEXT:
|
||||
save_as_text(object, fname);
|
||||
break;
|
||||
|
||||
case AMINS_SAVE_PDF:
|
||||
#ifdef WITH_PDF_EXPORT
|
||||
if(save_as_pdf(object, fname))
|
||||
amiga_icon_superimpose_favicon(fname, favicon, "pdf");
|
||||
#endif
|
||||
break;
|
||||
|
||||
case AMINS_SAVE_IFF:
|
||||
if((bm = content_get_bitmap(object)))
|
||||
{
|
||||
bm->url = (char *)nsurl_access(content_get_url(object));
|
||||
bm->title = (char *)content_get_title(object);
|
||||
bitmap_save(bm, fname, 0);
|
||||
}
|
||||
#ifdef WITH_NS_SVG
|
||||
else if(ami_mime_compare(object, "svg") == true)
|
||||
{
|
||||
ami_save_svg(object, fname);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
FClose(fh);
|
||||
SetComment(fname, nsurl_access(content_get_url(object)));
|
||||
}
|
||||
}
|
||||
ami_update_pointer(win, GUI_POINTER_DEFAULT);
|
||||
}
|
||||
|
||||
void ami_file_save_req(int type, struct gui_window_2 *gwin, struct hlcache_handle *object)
|
||||
{
|
||||
char *fname = AllocVec(1024, MEMF_CLEAR | MEMF_PRIVATE);
|
||||
|
||||
if(AslRequestTags(savereq,
|
||||
ASLFR_TitleText, messages_get("NetSurf"),
|
||||
ASLFR_Screen, scrn,
|
||||
ASLFR_InitialFile, FilePart(nsurl_access(content_get_url(object))),
|
||||
TAG_DONE))
|
||||
{
|
||||
strlcpy(fname, savereq->fr_Drawer, 1024);
|
||||
AddPart(fname, savereq->fr_File, 1024);
|
||||
|
||||
ami_file_save(type, fname, gwin->win, object, gwin->bw->window->favicon);
|
||||
}
|
||||
|
||||
if(fname) FreeVec(fname);
|
||||
}
|
||||
|
||||
void ami_file_req_init(void)
|
||||
{
|
||||
filereq = (struct FileRequester *)AllocAslRequest(ASL_FileRequest, NULL);
|
||||
savereq = (struct FileRequester *)AllocAslRequestTags(ASL_FileRequest,
|
||||
ASLFR_DoSaveMode, TRUE,
|
||||
ASLFR_RejectIcons, TRUE,
|
||||
ASLFR_InitialDrawer, option_download_dir,
|
||||
TAG_DONE);
|
||||
|
||||
aslhookfunc.h_Entry = (void *)&ami_file_asl_mime_hook;
|
||||
aslhookfunc.h_SubEntry = NULL;
|
||||
aslhookfunc.h_Data = NULL;
|
||||
}
|
||||
|
||||
void ami_file_req_free(void)
|
||||
{
|
||||
FreeAslRequest(filereq);
|
||||
FreeAslRequest(savereq);
|
||||
}
|
42
amiga/file.h
Normal file
42
amiga/file.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2011 Chris Young <chris@unsatisfactorysoftware.co.uk>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "amiga/gui.h"
|
||||
|
||||
struct hlcache_object;
|
||||
|
||||
struct FileRequester *filereq;
|
||||
struct FileRequester *savereq;
|
||||
|
||||
enum {
|
||||
AMINS_SAVE_SOURCE,
|
||||
AMINS_SAVE_TEXT,
|
||||
AMINS_SAVE_COMPLETE,
|
||||
AMINS_SAVE_PDF,
|
||||
AMINS_SAVE_IFF,
|
||||
};
|
||||
|
||||
|
||||
void ami_file_req_init(void);
|
||||
void ami_file_req_free(void);
|
||||
|
||||
void ami_file_open(struct gui_window_2 *gwin);
|
||||
void ami_file_save_req(int type, struct gui_window_2 *gwin,
|
||||
struct hlcache_handle *object);
|
||||
void ami_file_save(int type, char *fname, struct Window *win,
|
||||
struct hlcache_handle *object, struct hlcache_handle *favicon);
|
@ -1426,7 +1426,7 @@ void ami_handle_msg(void)
|
||||
break;
|
||||
|
||||
case 's':
|
||||
ami_file_save_source(gwin, gwin->bw->current_content);
|
||||
ami_file_save_req(AMINS_SAVE_SOURCE, gwin, gwin->bw->current_content);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
|
@ -431,6 +431,8 @@ void amiga_icon_superimpose_favicon(char *path, struct hlcache_handle *icon, cha
|
||||
struct ColorRegister *pal1;
|
||||
struct ColorRegister *pal2;
|
||||
|
||||
if(icon == NULL) return;
|
||||
|
||||
if(!type)
|
||||
{
|
||||
dobj = GetIconTags(NULL,
|
||||
|
Loading…
Reference in New Issue
Block a user