2011-10-15 19:27:56 +04:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2014-10-16 12:55:01 +04:00
|
|
|
#include <proto/asl.h>
|
|
|
|
#include <proto/dos.h>
|
|
|
|
#include <proto/exec.h>
|
|
|
|
#include <proto/icon.h>
|
|
|
|
#include <workbench/icon.h>
|
|
|
|
|
|
|
|
#include "utils/nsoption.h"
|
|
|
|
#include "utils/file.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/fetch.h"
|
2014-11-21 12:20:48 +03:00
|
|
|
#include "desktop/browser.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "desktop/save_complete.h"
|
2014-10-27 03:07:15 +03:00
|
|
|
#include "desktop/save_pdf.h"
|
2014-10-16 12:55:01 +04:00
|
|
|
#include "desktop/save_text.h"
|
|
|
|
#include "desktop/gui_window.h"
|
|
|
|
|
|
|
|
#include "amiga/gui.h"
|
2011-10-15 19:27:56 +04:00
|
|
|
#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"
|
2014-02-11 00:41:09 +04:00
|
|
|
#include "amiga/misc.h"
|
2011-10-15 19:27:56 +04:00
|
|
|
#include "amiga/save_pdf.h"
|
|
|
|
#include "amiga/theme.h"
|
|
|
|
|
|
|
|
static struct Hook aslhookfunc;
|
|
|
|
|
2014-11-09 22:04:56 +03:00
|
|
|
static ULONG ami_file_asl_mime_hook(struct Hook *mh,
|
2011-10-15 19:27:56 +04:00
|
|
|
struct FileRequester *fr, struct AnchorPathOld *ap)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2014-01-23 04:09:59 +04:00
|
|
|
mt = strdup(fetch_filetype(fname));
|
2011-10-15 19:27:56 +04:00
|
|
|
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)
|
|
|
|
{
|
2014-05-27 02:43:36 +04:00
|
|
|
char *temp;
|
2013-02-14 19:09:28 +04:00
|
|
|
nsurl *url;
|
2011-10-15 19:27:56 +04:00
|
|
|
|
|
|
|
if(AslRequestTags(filereq,
|
|
|
|
ASLFR_TitleText, messages_get("NetSurf"),
|
2013-05-25 16:59:42 +04:00
|
|
|
ASLFR_Window, gwin->win,
|
|
|
|
ASLFR_SleepWindow, TRUE,
|
2011-10-15 19:27:56 +04:00
|
|
|
ASLFR_Screen, scrn,
|
|
|
|
ASLFR_DoSaveMode, FALSE,
|
|
|
|
ASLFR_RejectIcons, TRUE,
|
|
|
|
ASLFR_FilterFunc, &aslhookfunc,
|
|
|
|
TAG_DONE))
|
|
|
|
{
|
2014-11-09 22:04:56 +03:00
|
|
|
if((temp = AllocVecTagList(1024, NULL)))
|
2011-10-15 19:27:56 +04:00
|
|
|
{
|
|
|
|
strlcpy(temp, filereq->fr_Drawer, 1024);
|
|
|
|
AddPart(temp, filereq->fr_File, 1024);
|
2013-02-14 19:09:28 +04:00
|
|
|
|
2014-05-27 02:43:36 +04:00
|
|
|
if (netsurf_path_to_nsurl(temp, &url) != NSERROR_OK) {
|
2013-02-14 19:09:28 +04:00
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
} else {
|
2014-11-16 17:54:25 +03:00
|
|
|
browser_window_navigate(gwin->gw->bw,
|
2013-02-14 19:09:28 +04:00
|
|
|
url,
|
|
|
|
NULL,
|
2014-02-11 02:40:04 +04:00
|
|
|
BW_NAVIGATE_HISTORY,
|
2013-02-14 19:09:28 +04:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
|
2011-10-15 19:27:56 +04:00
|
|
|
FreeVec(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static void ami_file_set_type(const char *path, lwc_string *mime_type)
|
|
|
|
{
|
|
|
|
content_type type = content_factory_type_from_mime_type(mime_type);
|
|
|
|
const char *default_type;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case CONTENT_HTML:
|
|
|
|
default_type = "html";
|
|
|
|
break;
|
|
|
|
case CONTENT_CSS:
|
|
|
|
default_type = "css";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default_type = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (default_type != NULL) {
|
|
|
|
struct DiskObject *dobj = NULL;
|
|
|
|
|
|
|
|
dobj = GetIconTags(NULL,ICONGETA_GetDefaultName,default_type,
|
|
|
|
ICONGETA_GetDefaultType,WBPROJECT,
|
|
|
|
TAG_DONE);
|
|
|
|
|
|
|
|
PutIconTags(path, dobj,
|
|
|
|
ICONPUTA_NotifyWorkbench, TRUE, TAG_DONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-15 19:27:56 +04:00
|
|
|
void ami_file_save(int type, char *fname, struct Window *win,
|
2011-10-23 17:15:44 +04:00
|
|
|
struct hlcache_handle *object, struct hlcache_handle *favicon,
|
2013-02-22 23:02:58 +04:00
|
|
|
struct browser_window *bw)
|
2011-10-15 19:27:56 +04:00
|
|
|
{
|
2014-04-06 02:34:51 +04:00
|
|
|
BPTR lock, fh;
|
2011-10-15 19:27:56 +04:00
|
|
|
const char *source_data;
|
|
|
|
ULONG source_size;
|
|
|
|
struct bitmap *bm;
|
|
|
|
|
|
|
|
ami_update_pointer(win, GUI_POINTER_WAIT);
|
|
|
|
|
2014-04-06 02:34:51 +04:00
|
|
|
if(ami_download_check_overwrite(fname, win, 0)) {
|
|
|
|
switch(type) {
|
2011-10-28 01:04:56 +04:00
|
|
|
case AMINS_SAVE_SOURCE:
|
2014-04-06 02:34:51 +04:00
|
|
|
if((source_data = content_get_source_data(object, &source_size))) {
|
|
|
|
BPTR fh;
|
2014-11-09 22:04:56 +03:00
|
|
|
if((fh = FOpen(fname, MODE_NEWFILE,0))) {
|
2011-10-22 18:03:47 +04:00
|
|
|
FWrite(fh, source_data, 1, source_size);
|
2011-10-28 01:04:56 +04:00
|
|
|
FClose(fh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-10-22 18:03:47 +04:00
|
|
|
|
2011-10-28 01:04:56 +04:00
|
|
|
case AMINS_SAVE_TEXT:
|
|
|
|
save_as_text(object, fname);
|
|
|
|
break;
|
2011-10-22 18:03:47 +04:00
|
|
|
|
2011-10-28 01:04:56 +04:00
|
|
|
case AMINS_SAVE_COMPLETE:
|
2014-11-09 22:04:56 +03:00
|
|
|
if((lock = CreateDir(fname))) {
|
2011-10-28 01:04:56 +04:00
|
|
|
UnLock(lock);
|
2012-11-04 03:19:28 +04:00
|
|
|
save_complete(object, fname, ami_file_set_type);
|
2011-10-28 01:04:56 +04:00
|
|
|
amiga_icon_superimpose_favicon(fname, favicon, NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AMINS_SAVE_PDF:
|
2011-10-15 19:27:56 +04:00
|
|
|
#ifdef WITH_PDF_EXPORT
|
2011-10-28 01:04:56 +04:00
|
|
|
if(save_as_pdf(object, fname))
|
|
|
|
amiga_icon_superimpose_favicon(fname, favicon, "pdf");
|
2011-10-15 19:27:56 +04:00
|
|
|
#endif
|
2011-10-28 01:04:56 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case AMINS_SAVE_IFF:
|
2014-04-06 02:34:51 +04:00
|
|
|
if((bm = content_get_bitmap(object))) {
|
2011-12-04 18:55:23 +04:00
|
|
|
bm->url = (char *)nsurl_access(hlcache_handle_get_url(object));
|
2011-10-28 01:04:56 +04:00
|
|
|
bm->title = (char *)content_get_title(object);
|
|
|
|
bitmap_save(bm, fname, 0);
|
|
|
|
}
|
2011-10-15 19:27:56 +04:00
|
|
|
#ifdef WITH_NS_SVG
|
2014-04-06 02:34:51 +04:00
|
|
|
else if(ami_mime_compare(object, "svg") == true) {
|
2011-10-28 01:04:56 +04:00
|
|
|
ami_save_svg(object, fname);
|
|
|
|
}
|
2011-10-15 19:27:56 +04:00
|
|
|
#endif
|
2011-10-28 01:04:56 +04:00
|
|
|
break;
|
2011-10-23 17:15:44 +04:00
|
|
|
|
2011-10-28 01:04:56 +04:00
|
|
|
case AMINS_SAVE_SELECTION:
|
2014-11-09 22:04:56 +03:00
|
|
|
if((source_data = browser_window_get_selection(bw))) {
|
|
|
|
if((fh = FOpen(fname, MODE_NEWFILE,0))) {
|
2013-02-22 23:02:58 +04:00
|
|
|
FWrite(fh, source_data, 1, strlen(source_data));
|
|
|
|
FClose(fh);
|
|
|
|
}
|
2013-05-25 16:59:42 +04:00
|
|
|
free((void *)source_data);
|
2013-02-22 23:02:58 +04:00
|
|
|
}
|
2011-10-28 01:04:56 +04:00
|
|
|
break;
|
2011-10-15 19:27:56 +04:00
|
|
|
}
|
2011-12-04 18:55:23 +04:00
|
|
|
if(object) SetComment(fname, nsurl_access(hlcache_handle_get_url(object)));
|
2011-10-15 19:27:56 +04:00
|
|
|
}
|
2011-10-28 01:04:56 +04:00
|
|
|
|
2011-10-15 19:27:56 +04:00
|
|
|
ami_update_pointer(win, GUI_POINTER_DEFAULT);
|
|
|
|
}
|
|
|
|
|
2011-10-23 17:15:44 +04:00
|
|
|
void ami_file_save_req(int type, struct gui_window_2 *gwin,
|
2013-02-22 23:02:58 +04:00
|
|
|
struct hlcache_handle *object)
|
2011-10-15 19:27:56 +04:00
|
|
|
{
|
2015-01-11 02:49:55 +03:00
|
|
|
char *fname = AllocVecTagList(1024, NULL);
|
2014-10-23 21:42:07 +04:00
|
|
|
char *initial_fname = NULL;
|
|
|
|
|
2014-10-31 03:24:57 +03:00
|
|
|
if(object) {
|
|
|
|
nsurl_nice(hlcache_handle_get_url(object), &initial_fname, true);
|
|
|
|
}
|
2011-10-15 19:27:56 +04:00
|
|
|
|
|
|
|
if(AslRequestTags(savereq,
|
2013-05-25 16:59:42 +04:00
|
|
|
ASLFR_Window, gwin->win,
|
|
|
|
ASLFR_SleepWindow, TRUE,
|
2011-10-15 19:27:56 +04:00
|
|
|
ASLFR_TitleText, messages_get("NetSurf"),
|
|
|
|
ASLFR_Screen, scrn,
|
2014-10-23 21:42:07 +04:00
|
|
|
ASLFR_InitialFile, initial_fname ? initial_fname : "",
|
2011-10-15 19:27:56 +04:00
|
|
|
TAG_DONE))
|
|
|
|
{
|
|
|
|
strlcpy(fname, savereq->fr_Drawer, 1024);
|
|
|
|
AddPart(fname, savereq->fr_File, 1024);
|
|
|
|
|
2014-11-16 17:54:25 +03:00
|
|
|
ami_file_save(type, fname, gwin->win, object, gwin->gw->favicon, gwin->gw->bw);
|
2011-10-15 19:27:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(fname) FreeVec(fname);
|
2014-10-23 21:42:07 +04:00
|
|
|
if(initial_fname) free(initial_fname);
|
2011-10-15 19:27:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2012-03-22 13:34:34 +04:00
|
|
|
ASLFR_InitialDrawer, nsoption_charp(download_dir),
|
2011-10-15 19:27:56 +04:00
|
|
|
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);
|
|
|
|
}
|