From f824ab8af4d3d2e34bd59b860b9c6d5568c3bb44 Mon Sep 17 00:00:00 2001 From: John-Mark Bell Date: Sat, 3 Nov 2012 23:19:28 +0000 Subject: Port save complete to libdom. --- amiga/Makefile.target | 2 +- amiga/file.c | 32 +++++++++++++- amiga/save_complete.c | 116 -------------------------------------------------- amiga/save_complete.h | 32 -------------- 4 files changed, 32 insertions(+), 150 deletions(-) delete mode 100755 amiga/save_complete.c delete mode 100755 amiga/save_complete.h (limited to 'amiga') diff --git a/amiga/Makefile.target b/amiga/Makefile.target index c4db9a373..5b11ec018 100644 --- a/amiga/Makefile.target +++ b/amiga/Makefile.target @@ -75,7 +75,7 @@ EXETARGET := NetSurf S_AMIGA := gui.c tree.c history.c hotlist.c schedule.c file.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 \ + cookies.c context_menu.c clipboard.c \ launch.c search.c history_local.c download.c iff_dr2d.c \ sslcert.c gui_options.c print.c theme.c drag.c icon.c system_colour.c \ datatypes.c dt_picture.c dt_anim.c dt_sound.c plugin_hack.c \ diff --git a/amiga/file.c b/amiga/file.c index c2e4f13ad..8157180ec 100644 --- a/amiga/file.c +++ b/amiga/file.c @@ -99,6 +99,36 @@ void ami_file_open(struct gui_window_2 *gwin) } } +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); + } +} + void ami_file_save(int type, char *fname, struct Window *win, struct hlcache_handle *object, struct hlcache_handle *favicon, struct selection *sel) @@ -134,7 +164,7 @@ void ami_file_save(int type, char *fname, struct Window *win, if(lock = CreateDir(fname)) { UnLock(lock); - save_complete(object, fname); + save_complete(object, fname, ami_file_set_type); amiga_icon_superimpose_favicon(fname, favicon, NULL); } break; diff --git a/amiga/save_complete.c b/amiga/save_complete.c deleted file mode 100755 index dad952c0b..000000000 --- a/amiga/save_complete.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2004 John M Bell - * Copyright 2004-2007 James Bursa - * Copyright 2008 Chris Young - * Copyright 2009 Mark Benjamin - * - * 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 "desktop/save_complete.h" -#include "utils/utils.h" -#include -#include -#include "content/content.h" - -/** -* conducts the filesystem save appropriate to the gui -* \param path save path -* \param filename name of file to save -* \param len data length -* \param sourcedata pointer to data to save, NULL when all data in c -* \param type content type -* \return true for success -*/ - -bool save_complete_gui_save(const char *path, const char *filename, size_t len, - const char *sourcedata, lwc_string *mime_type) -{ - content_type type = content_factory_type_from_mime_type(mime_type); - int res; - int namelen; - char deftype[5]; - struct DiskObject *dobj = NULL; - namelen = strlen(path) + strlen(filename) + 2; - char *fullpath = malloc(namelen); - if (!fullpath) { - warn_user("NoMemory", 0); - return false; - } - snprintf(fullpath, namelen, "%s/%s", path, filename); - FILE *f = fopen(fullpath, "w"); - if (f == NULL) - return false; - res = fwrite(sourcedata, len, 1, f); - fclose(f); - switch(type) - { - case CONTENT_HTML: - strcpy(deftype,"html"); - break; - case CONTENT_CSS: - strcpy(deftype,"css"); - break; - default: - free(fullpath); - return true; - break; - } - - dobj = GetIconTags(NULL,ICONGETA_GetDefaultName,deftype, - ICONGETA_GetDefaultType,WBPROJECT, - TAG_DONE); - - PutIconTags(fullpath, dobj, - ICONPUTA_NotifyWorkbench, TRUE, TAG_DONE); - free(fullpath); - if (res != 1) - return false; - return true; -} - -/** -* wrapper for lib function htmlSaveFileFormat; front sets path from -* path + filename in a filesystem-specific way -*/ - -int save_complete_htmlSaveFileFormat(const char *path, const char *filename, - xmlDocPtr cur, const char *encoding, int format) -{ - int ret; - int len = strlen(path) + strlen(filename) + 2; - struct DiskObject *dobj = NULL; - char *fullpath = malloc(len); - if (!fullpath){ - warn_user("NoMemory", 0); - return -1; - } - snprintf(fullpath, len, "%s/%s", path, filename); - ret = htmlSaveFileFormat(fullpath, cur, encoding, format); - dobj = GetIconTags(NULL,ICONGETA_GetDefaultName, "html", - ICONGETA_GetDefaultType,WBPROJECT, - TAG_DONE); - - PutIconTags(fullpath, dobj, - ICONPUTA_NotifyWorkbench, TRUE, TAG_DONE); - - free(fullpath); - return ret; -} - diff --git a/amiga/save_complete.h b/amiga/save_complete.h deleted file mode 100755 index cb6c26643..000000000 --- a/amiga/save_complete.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2004 John M Bell - * Copyright 2008 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 . - */ - -/** \file - * Save HTML document with dependencies (interface). - */ - -#ifndef AMIGA_SAVE_COMPLETE_H -#define AMIGA_SAVE_COMPLETE_H - -#include "content/content.h" - -void save_complete_init(void); -bool save_complete(hlcache_handle *c, const char *path); - -#endif -- cgit v1.2.3