2004-02-26 03:44:42 +03:00
|
|
|
/*
|
|
|
|
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
|
|
|
* Licensed under the GNU General Public License,
|
|
|
|
* http://www.opensource.org/licenses/gpl-license
|
|
|
|
* Copyright 2004 James Bursa <bursa@users.sourceforge.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Save dialog and drag and drop saving (implementation).
|
|
|
|
*/
|
|
|
|
|
2004-04-11 00:04:11 +04:00
|
|
|
#include <ctype.h>
|
2004-03-27 21:47:56 +03:00
|
|
|
#include <errno.h>
|
2004-05-06 04:56:15 +04:00
|
|
|
#include <stdbool.h>
|
2004-03-27 21:47:56 +03:00
|
|
|
#include <stdio.h>
|
2004-02-26 03:44:42 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "oslib/dragasprite.h"
|
2004-03-27 21:47:56 +03:00
|
|
|
#include "oslib/osfile.h"
|
2004-03-28 18:33:52 +04:00
|
|
|
#include "oslib/osspriteop.h"
|
2004-02-26 03:44:42 +03:00
|
|
|
#include "oslib/wimp.h"
|
2004-03-25 03:31:45 +03:00
|
|
|
#include "netsurf/desktop/save_text.h"
|
2004-02-26 03:44:42 +03:00
|
|
|
#include "netsurf/riscos/gui.h"
|
2004-03-27 21:47:56 +03:00
|
|
|
#include "netsurf/riscos/save_complete.h"
|
2004-02-26 03:44:42 +03:00
|
|
|
#include "netsurf/riscos/save_draw.h"
|
2004-03-28 18:33:52 +04:00
|
|
|
#include "netsurf/riscos/thumbnail.h"
|
2004-05-05 20:33:15 +04:00
|
|
|
#include "netsurf/riscos/wimp.h"
|
2004-02-26 03:44:42 +03:00
|
|
|
#include "netsurf/utils/log.h"
|
|
|
|
#include "netsurf/utils/messages.h"
|
2004-07-11 17:05:38 +04:00
|
|
|
#include "netsurf/utils/url.h"
|
2004-02-26 03:44:42 +03:00
|
|
|
#include "netsurf/utils/utils.h"
|
|
|
|
|
2004-07-11 17:05:38 +04:00
|
|
|
static gui_save_type gui_save_current_type;
|
|
|
|
static struct content *gui_save_content = 0;
|
|
|
|
static int gui_save_filetype;
|
2004-05-05 04:02:13 +04:00
|
|
|
|
2004-05-06 04:52:31 +04:00
|
|
|
typedef enum { LINK_ACORN, LINK_ANT, LINK_TEXT } link_format;
|
|
|
|
|
2004-06-06 23:39:17 +04:00
|
|
|
static bool ro_gui_save_complete(struct content *c, char *path);
|
2004-05-05 04:02:13 +04:00
|
|
|
static void ro_gui_save_object_native(struct content *c, char *path);
|
2004-05-06 16:14:47 +04:00
|
|
|
static bool ro_gui_save_link(struct content *c, link_format format, char *path);
|
2004-03-27 21:47:56 +03:00
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
|
2004-07-11 17:05:38 +04:00
|
|
|
/** An entry in gui_save_table. */
|
|
|
|
struct gui_save_table_entry {
|
|
|
|
int filetype;
|
|
|
|
const char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Table of filetypes and default filenames. Must be in sync with
|
|
|
|
* gui_save_type (riscos/gui.h). A filetype of 0 indicates the content should
|
|
|
|
* be used. */
|
|
|
|
struct gui_save_table_entry gui_save_table[] = {
|
|
|
|
/* GUI_SAVE_SOURCE, */ { 0, "SaveSource" },
|
|
|
|
/* GUI_SAVE_DRAW, */ { 0xaff, "SaveDraw" },
|
|
|
|
/* GUI_SAVE_TEXT, */ { 0xfff, "SaveText" },
|
|
|
|
/* GUI_SAVE_COMPLETE, */ { 0xfaf, "SaveComplete" },
|
|
|
|
/* GUI_SAVE_OBJECT_ORIG, */ { 0, "SaveObject" },
|
|
|
|
/* GUI_SAVE_OBJECT_NATIVE, */ { 0xff9, "SaveObject" },
|
|
|
|
/* GUI_SAVE_LINK_URI, */ { 0xf91, "SaveLink" },
|
|
|
|
/* GUI_SAVE_LINK_URL, */ { 0xb28, "SaveLink" },
|
|
|
|
/* GUI_SAVE_LINK_TEXT, */ { 0xfff, "SaveLink" },
|
|
|
|
/* GUI_SAVE_HOTLIST_EXPORT_HTML, */ { 0xfaf, "Hotlist" },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares the save box to reflect gui_save_type and a content, and
|
|
|
|
* opens it.
|
|
|
|
*
|
|
|
|
* \param save_type type of save
|
|
|
|
* \param c content to save
|
|
|
|
* \param sub_menu open dialog as a sub menu, otherwise persistent
|
|
|
|
* \param x x position, for sub_menu true only
|
|
|
|
* \param y y position, for sub_menu true only
|
|
|
|
* \param parent parent window for persistent box, for sub_menu false only
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_save_open(gui_save_type save_type, struct content *c,
|
2004-07-16 20:33:45 +04:00
|
|
|
bool sub_menu, int x, int y, wimp_w parent, bool keypress)
|
2004-07-11 17:05:38 +04:00
|
|
|
{
|
|
|
|
char icon_buf[20];
|
|
|
|
const char *icon = icon_buf;
|
|
|
|
const char *name = "";
|
|
|
|
const char *nice;
|
|
|
|
os_error *error;
|
2004-08-09 20:11:58 +04:00
|
|
|
url_func_result res;
|
2004-07-11 17:05:38 +04:00
|
|
|
|
|
|
|
assert(save_type == GUI_SAVE_HOTLIST_EXPORT_HTML || c);
|
|
|
|
|
|
|
|
gui_save_current_type = save_type;
|
|
|
|
gui_save_content = c;
|
|
|
|
gui_save_filetype = gui_save_table[save_type].filetype;
|
|
|
|
if (!gui_save_filetype)
|
|
|
|
gui_save_filetype = ro_content_filetype(c);
|
|
|
|
|
|
|
|
/* icon */
|
|
|
|
sprintf(icon_buf, "file_%.3x", gui_save_filetype);
|
|
|
|
if (!ro_gui_wimp_sprite_exists(icon_buf))
|
|
|
|
icon = "file_xxx";
|
|
|
|
ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_ICON, icon);
|
|
|
|
|
|
|
|
/* filename */
|
|
|
|
name = gui_save_table[save_type].name;
|
|
|
|
if (c) {
|
2004-08-09 20:11:58 +04:00
|
|
|
if ((res = url_nice(c->url, &nice)) == URL_FUNC_OK)
|
2004-07-11 17:05:38 +04:00
|
|
|
name = nice;
|
|
|
|
}
|
|
|
|
ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, name);
|
|
|
|
|
|
|
|
/* open sub menu or persistent dialog */
|
|
|
|
if (sub_menu) {
|
|
|
|
error = xwimp_create_sub_menu((wimp_menu *) dialog_saveas,
|
|
|
|
x, y);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_create_sub_menu: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
warn_user("MenuError", error->errmess);
|
|
|
|
}
|
|
|
|
} else {
|
2004-07-16 20:33:45 +04:00
|
|
|
ro_gui_dialog_open_persistant(parent, dialog_saveas, !keypress);
|
2004-07-11 17:05:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
/**
|
|
|
|
* Handle clicks in the save dialog.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_save_click(wimp_pointer *pointer)
|
|
|
|
{
|
|
|
|
switch (pointer->i) {
|
2004-07-08 21:28:56 +04:00
|
|
|
case ICON_SAVE_OK:
|
|
|
|
/* Todo: Try save, and report error NoPathError if needed */
|
2004-07-11 04:22:05 +04:00
|
|
|
break;
|
2004-07-08 21:28:56 +04:00
|
|
|
case ICON_SAVE_CANCEL:
|
|
|
|
if (pointer->buttons == wimp_CLICK_SELECT) {
|
|
|
|
xwimp_create_menu((wimp_menu *)-1, 0, 0);
|
2004-07-16 20:33:45 +04:00
|
|
|
ro_gui_dialog_close(pointer->w);
|
2004-07-08 21:28:56 +04:00
|
|
|
} else if (pointer->buttons == wimp_CLICK_ADJUST) {
|
2004-07-11 17:05:38 +04:00
|
|
|
/* ro_gui_menu_prepare_save(gui_save_content); */
|
2004-07-08 21:28:56 +04:00
|
|
|
}
|
|
|
|
break;
|
2004-02-26 03:44:42 +03:00
|
|
|
case ICON_SAVE_ICON:
|
|
|
|
if (pointer->buttons == wimp_DRAG_SELECT) {
|
|
|
|
gui_current_drag_type = GUI_DRAG_SAVE;
|
|
|
|
ro_gui_drag_icon(pointer);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start drag of icon under the pointer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_drag_icon(wimp_pointer *pointer)
|
|
|
|
{
|
|
|
|
char *sprite;
|
|
|
|
os_box box = { pointer->pos.x - 34, pointer->pos.y - 34,
|
|
|
|
pointer->pos.x + 34, pointer->pos.y + 34 };
|
|
|
|
os_error *error;
|
|
|
|
|
|
|
|
if (pointer->i == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sprite = ro_gui_get_icon_string(pointer->w, pointer->i);
|
|
|
|
|
|
|
|
error = xdragasprite_start(dragasprite_HPOS_CENTRE |
|
|
|
|
dragasprite_VPOS_CENTRE |
|
|
|
|
dragasprite_BOUND_POINTER |
|
|
|
|
dragasprite_DROP_SHADOW,
|
|
|
|
(osspriteop_area *) 1, sprite, &box, 0);
|
|
|
|
if (error) {
|
2004-03-27 21:47:56 +03:00
|
|
|
LOG(("xdragasprite_start: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("DragError", error->errmess);
|
2004-02-26 03:44:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle User_Drag_Box event for a drag from the save dialog.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_save_drag_end(wimp_dragged *drag)
|
|
|
|
{
|
2004-03-27 21:47:56 +03:00
|
|
|
char *name;
|
|
|
|
char *dot;
|
2004-02-26 03:44:42 +03:00
|
|
|
wimp_pointer pointer;
|
|
|
|
wimp_message message;
|
|
|
|
|
|
|
|
wimp_get_pointer_info(&pointer);
|
|
|
|
|
2004-03-27 21:47:56 +03:00
|
|
|
name = ro_gui_get_icon_string(dialog_saveas, ICON_SAVE_PATH);
|
|
|
|
dot = strrchr(name, '.');
|
|
|
|
if (dot)
|
|
|
|
name = dot + 1;
|
|
|
|
|
2004-02-26 03:44:42 +03:00
|
|
|
message.your_ref = 0;
|
|
|
|
message.action = message_DATA_SAVE;
|
|
|
|
message.data.data_xfer.w = pointer.w;
|
|
|
|
message.data.data_xfer.i = pointer.i;
|
|
|
|
message.data.data_xfer.pos.x = pointer.pos.x;
|
|
|
|
message.data.data_xfer.pos.y = pointer.pos.y;
|
|
|
|
message.data.data_xfer.est_size = 1000;
|
2004-07-11 17:05:38 +04:00
|
|
|
message.data.data_xfer.file_type = gui_save_filetype;
|
|
|
|
if (gui_save_current_type == GUI_SAVE_COMPLETE) {
|
2004-03-27 21:47:56 +03:00
|
|
|
message.data.data_xfer.file_type = 0x2000;
|
|
|
|
if (name[0] != '!') {
|
|
|
|
message.data.data_xfer.file_name[0] = '!';
|
|
|
|
strncpy(message.data.data_xfer.file_name + 1, name,
|
|
|
|
211);
|
|
|
|
} else {
|
|
|
|
strncpy(message.data.data_xfer.file_name, name, 212);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
strncpy(message.data.data_xfer.file_name, name, 212);
|
|
|
|
message.data.data_xfer.file_name[211] = 0;
|
2004-02-26 03:44:42 +03:00
|
|
|
message.size = 44 + ((strlen(message.data.data_xfer.file_name) + 4) &
|
|
|
|
(~3u));
|
|
|
|
|
|
|
|
wimp_send_message_to_window(wimp_USER_MESSAGE, &message,
|
|
|
|
pointer.w, pointer.i);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Message_DataSaveAck for a drag from the save dialog.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_save_datasave_ack(wimp_message *message)
|
|
|
|
{
|
|
|
|
char *path = message->data.data_xfer.file_name;
|
2004-07-11 17:05:38 +04:00
|
|
|
struct content *c = gui_save_content;
|
2004-03-27 21:47:56 +03:00
|
|
|
os_error *error;
|
2004-05-06 16:14:47 +04:00
|
|
|
|
2004-07-11 17:05:38 +04:00
|
|
|
if (!gui_save_content &&
|
|
|
|
gui_save_current_type != GUI_SAVE_HOTLIST_EXPORT_HTML) {
|
|
|
|
LOG(("unexpected DataSaveAck: gui_save_content not set"));
|
2004-05-06 16:14:47 +04:00
|
|
|
return;
|
|
|
|
}
|
2004-02-26 03:44:42 +03:00
|
|
|
|
|
|
|
ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, path);
|
|
|
|
|
2004-07-11 17:05:38 +04:00
|
|
|
switch (gui_save_current_type) {
|
2004-02-26 03:44:42 +03:00
|
|
|
case GUI_SAVE_SOURCE:
|
2004-05-06 16:14:47 +04:00
|
|
|
error = xosfile_save_stamped(path,
|
|
|
|
ro_content_filetype(c),
|
2004-03-11 05:19:14 +03:00
|
|
|
c->source_data,
|
|
|
|
c->source_data + c->source_size);
|
2004-03-27 21:47:56 +03:00
|
|
|
if (error) {
|
|
|
|
LOG(("xosfile_save_stamped: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("SaveError", error->errmess);
|
2004-05-06 16:14:47 +04:00
|
|
|
return;
|
2004-03-27 21:47:56 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_SAVE_COMPLETE:
|
2004-06-06 23:39:17 +04:00
|
|
|
if (!ro_gui_save_complete(c, path))
|
|
|
|
return;
|
2004-03-06 15:34:47 +03:00
|
|
|
break;
|
2004-02-26 03:44:42 +03:00
|
|
|
|
|
|
|
case GUI_SAVE_DRAW:
|
2004-06-03 01:25:16 +04:00
|
|
|
if (!save_as_draw(c, path))
|
|
|
|
return;
|
2004-02-26 03:44:42 +03:00
|
|
|
break;
|
2004-03-25 02:51:08 +03:00
|
|
|
|
|
|
|
case GUI_SAVE_TEXT:
|
|
|
|
save_as_text(c, path);
|
2004-03-28 18:09:55 +04:00
|
|
|
xosfile_set_type(path, 0xfff);
|
2004-03-25 02:51:08 +03:00
|
|
|
break;
|
2004-05-05 04:02:13 +04:00
|
|
|
|
|
|
|
case GUI_SAVE_OBJECT_ORIG:
|
2004-05-06 16:14:47 +04:00
|
|
|
error = xosfile_save_stamped(path,
|
|
|
|
ro_content_filetype(c),
|
2004-05-05 04:02:13 +04:00
|
|
|
c->source_data,
|
|
|
|
c->source_data + c->source_size);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosfile_save_stamped: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("SaveError", error->errmess);
|
2004-05-06 16:14:47 +04:00
|
|
|
return;
|
2004-05-05 04:02:13 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_SAVE_OBJECT_NATIVE:
|
2004-05-06 16:14:47 +04:00
|
|
|
ro_gui_save_object_native(c, path);
|
|
|
|
break;
|
2004-05-05 04:02:13 +04:00
|
|
|
|
|
|
|
case GUI_SAVE_LINK_URI:
|
2004-05-06 16:14:47 +04:00
|
|
|
if (!ro_gui_save_link(c, LINK_ACORN, path))
|
|
|
|
return;
|
|
|
|
break;
|
2004-05-05 04:02:13 +04:00
|
|
|
|
|
|
|
case GUI_SAVE_LINK_URL:
|
2004-05-06 16:14:47 +04:00
|
|
|
if (!ro_gui_save_link(c, LINK_ANT, path))
|
|
|
|
return;
|
|
|
|
break;
|
2004-05-05 04:02:13 +04:00
|
|
|
|
|
|
|
case GUI_SAVE_LINK_TEXT:
|
2004-05-06 16:14:47 +04:00
|
|
|
if (!ro_gui_save_link(c, LINK_TEXT, path))
|
|
|
|
return;
|
|
|
|
break;
|
2004-07-11 17:05:38 +04:00
|
|
|
case GUI_SAVE_HOTLIST_EXPORT_HTML:
|
2004-07-06 02:17:59 +04:00
|
|
|
ro_gui_hotlist_save_as(path);
|
|
|
|
break;
|
2004-02-26 03:44:42 +03:00
|
|
|
}
|
2004-07-11 04:22:05 +04:00
|
|
|
|
2004-07-10 01:03:26 +04:00
|
|
|
/* Close the save window
|
|
|
|
*/
|
2004-07-12 23:55:49 +04:00
|
|
|
ro_gui_dialog_close(dialog_saveas);
|
2004-02-26 03:44:42 +03:00
|
|
|
|
2004-05-06 16:14:47 +04:00
|
|
|
/* Ack successful save with message_DATA_LOAD */
|
|
|
|
message->action = message_DATA_LOAD;
|
|
|
|
message->your_ref = message->my_ref;
|
|
|
|
error = xwimp_send_message_to_window(wimp_USER_MESSAGE, message,
|
|
|
|
message->data.data_xfer.w, message->data.data_xfer.i, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_send_message_to_window: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("SaveError", error->errmess);
|
2004-05-06 16:14:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
error = xwimp_create_menu(wimp_CLOSE_MENU, 0, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xwimp_create_menu: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("MenuError", error->errmess);
|
2004-05-06 04:56:15 +04:00
|
|
|
}
|
2004-05-06 04:52:31 +04:00
|
|
|
|
2004-07-11 17:05:38 +04:00
|
|
|
gui_save_content = 0;
|
2004-02-26 03:44:42 +03:00
|
|
|
}
|
2004-03-27 21:47:56 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare an application directory and save_complete() to it.
|
2004-06-06 23:39:17 +04:00
|
|
|
*
|
|
|
|
* \param c content of type CONTENT_HTML to save
|
|
|
|
* \param path path to save as
|
|
|
|
* \return true on success, false on error and error reported
|
2004-03-27 21:47:56 +03:00
|
|
|
*/
|
|
|
|
|
2004-03-28 18:33:52 +04:00
|
|
|
#define WIDTH 64
|
|
|
|
#define HEIGHT 64
|
|
|
|
#define SPRITE_SIZE (16 + 44 + ((WIDTH / 2 + 3) & ~3) * HEIGHT / 2)
|
|
|
|
|
2004-06-06 23:39:17 +04:00
|
|
|
bool ro_gui_save_complete(struct content *c, char *path)
|
2004-03-27 21:47:56 +03:00
|
|
|
{
|
2004-04-11 00:04:11 +04:00
|
|
|
char buf[256];
|
2004-03-27 21:47:56 +03:00
|
|
|
FILE *fp;
|
|
|
|
os_error *error;
|
2004-03-28 18:33:52 +04:00
|
|
|
osspriteop_area *area;
|
2004-04-11 00:04:11 +04:00
|
|
|
osspriteop_header *sprite_header;
|
2004-03-28 18:33:52 +04:00
|
|
|
char *appname;
|
2004-04-11 00:04:11 +04:00
|
|
|
unsigned int index;
|
2004-03-27 21:47:56 +03:00
|
|
|
|
2004-03-28 18:33:52 +04:00
|
|
|
/* Create dir */
|
2004-03-27 21:47:56 +03:00
|
|
|
error = xosfile_create_dir(path, 0);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosfile_create_dir: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("SaveError", error->errmess);
|
2004-06-06 23:39:17 +04:00
|
|
|
return false;
|
2004-03-27 21:47:56 +03:00
|
|
|
}
|
|
|
|
|
2004-03-28 18:33:52 +04:00
|
|
|
/* Save !Run file */
|
2004-03-27 21:47:56 +03:00
|
|
|
snprintf(buf, sizeof buf, "%s.!Run", path);
|
|
|
|
fp = fopen(buf, "w");
|
|
|
|
if (!fp) {
|
|
|
|
LOG(("fopen(): errno = %i", errno));
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("SaveError", strerror(errno));
|
2004-06-06 23:39:17 +04:00
|
|
|
return false;
|
2004-03-27 21:47:56 +03:00
|
|
|
}
|
|
|
|
fprintf(fp, "Filer_Run <Obey$Dir>.index\n");
|
|
|
|
fclose(fp);
|
|
|
|
error = xosfile_set_type(buf, 0xfeb);
|
|
|
|
if (error) {
|
|
|
|
LOG(("xosfile_set_type: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("SaveError", error->errmess);
|
2004-06-06 23:39:17 +04:00
|
|
|
return false;
|
2004-03-27 21:47:56 +03:00
|
|
|
}
|
|
|
|
|
2004-05-07 23:14:54 +04:00
|
|
|
/* Create !Sprites */
|
2004-03-28 18:33:52 +04:00
|
|
|
snprintf(buf, sizeof buf, "%s.!Sprites", path);
|
|
|
|
appname = strrchr(path, '.');
|
2004-05-07 23:14:54 +04:00
|
|
|
if (!appname)
|
|
|
|
appname = path;
|
2004-05-05 04:02:13 +04:00
|
|
|
|
2004-04-11 00:04:11 +04:00
|
|
|
area = thumbnail_initialise(34, 34, os_MODE8BPP90X90);
|
2004-05-05 04:02:13 +04:00
|
|
|
if (!area) {
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("NoMemory", 0);
|
2004-06-06 23:39:17 +04:00
|
|
|
return false;
|
2004-04-11 00:04:11 +04:00
|
|
|
}
|
|
|
|
sprite_header = (osspriteop_header *)(area + 1);
|
|
|
|
strncpy(sprite_header->name, appname + 1, 12);
|
|
|
|
|
2004-05-07 23:14:54 +04:00
|
|
|
/* Paint gets confused with uppercase characters */
|
|
|
|
for (index = 0; index < 12; index++)
|
2004-04-11 00:04:11 +04:00
|
|
|
sprite_header->name[index] = tolower(sprite_header->name[index]);
|
2004-03-28 18:33:52 +04:00
|
|
|
thumbnail_create(c, area,
|
|
|
|
(osspriteop_header *) ((char *) area + 16),
|
2004-04-11 00:04:11 +04:00
|
|
|
34, 34);
|
2004-03-28 18:33:52 +04:00
|
|
|
error = xosspriteop_save_sprite_file(osspriteop_NAME, area, buf);
|
2004-03-28 19:21:49 +04:00
|
|
|
free(area);
|
2004-03-28 18:33:52 +04:00
|
|
|
if (error) {
|
2004-05-07 23:14:54 +04:00
|
|
|
LOG(("xosspriteop_save_sprite_file: 0x%x: %s",
|
2004-03-28 18:33:52 +04:00
|
|
|
error->errnum, error->errmess));
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("SaveError", error->errmess);
|
2004-06-06 23:39:17 +04:00
|
|
|
return false;
|
2004-03-28 18:33:52 +04:00
|
|
|
}
|
|
|
|
|
2004-06-06 23:39:17 +04:00
|
|
|
return save_complete(c, path);
|
2004-03-27 21:47:56 +03:00
|
|
|
}
|
2004-05-05 04:02:13 +04:00
|
|
|
|
2004-06-06 23:39:17 +04:00
|
|
|
|
|
|
|
|
2004-05-05 04:02:13 +04:00
|
|
|
void ro_gui_save_object_native(struct content *c, char *path)
|
|
|
|
{
|
|
|
|
os_error *error;
|
|
|
|
osspriteop_area *temp;
|
|
|
|
|
|
|
|
switch (c->type) {
|
|
|
|
case CONTENT_JPEG:
|
|
|
|
error = xosspriteop_save_sprite_file(osspriteop_USER_AREA, c->data.jpeg.sprite_area, path);
|
|
|
|
break;
|
|
|
|
case CONTENT_PNG:
|
|
|
|
error = xosspriteop_save_sprite_file(osspriteop_USER_AREA, c->data.png.sprite_area, path);
|
|
|
|
break;
|
2004-07-16 23:47:03 +04:00
|
|
|
case CONTENT_JNG:
|
|
|
|
case CONTENT_MNG:
|
|
|
|
error = xosspriteop_save_sprite_file(osspriteop_USER_AREA, c->data.mng.sprite_area, path);
|
|
|
|
break;
|
2004-05-05 04:02:13 +04:00
|
|
|
case CONTENT_GIF:
|
|
|
|
/* create sprite area */
|
|
|
|
temp = calloc(c->data.gif.gif->frame_image->size+16,
|
|
|
|
sizeof(char));
|
|
|
|
temp->size = c->data.gif.gif->frame_image->size+16;
|
|
|
|
temp->sprite_count = 1;
|
|
|
|
temp->first = 16;
|
|
|
|
temp->used = c->data.gif.gif->frame_image->size+16;
|
|
|
|
memcpy((char*)temp+16,
|
|
|
|
(char*)c->data.gif.gif->frame_image,
|
|
|
|
c->data.gif.gif->frame_image->size);
|
|
|
|
/* ensure extra words for name are null */
|
|
|
|
memset((char*)temp+24, 0, 8);
|
|
|
|
error = xosspriteop_save_sprite_file(osspriteop_USER_AREA, temp, path);
|
|
|
|
free(temp);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-06 16:14:47 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a link file.
|
|
|
|
*
|
|
|
|
* \param c content to save link to
|
|
|
|
* \param format format of link file
|
|
|
|
* \param path pathname for link file
|
|
|
|
* \return true on success, false on failure and reports the error
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool ro_gui_save_link(struct content *c, link_format format, char *path)
|
2004-05-05 04:02:13 +04:00
|
|
|
{
|
|
|
|
FILE *fp = fopen(path, "w");
|
|
|
|
|
2004-05-06 16:14:47 +04:00
|
|
|
if (!fp) {
|
2004-05-07 23:14:54 +04:00
|
|
|
warn_user("SaveError", strerror(errno));
|
2004-05-06 16:14:47 +04:00
|
|
|
return false;
|
|
|
|
}
|
2004-05-05 04:02:13 +04:00
|
|
|
|
|
|
|
switch (format) {
|
2004-05-06 04:52:31 +04:00
|
|
|
case LINK_ACORN: /* URI */
|
2004-05-05 04:02:13 +04:00
|
|
|
fprintf(fp, "%s\t%s\n", "URI", "100");
|
|
|
|
fprintf(fp, "\t# NetSurf %s\n\n", netsurf_version);
|
2004-05-06 16:14:47 +04:00
|
|
|
fprintf(fp, "\t%s\n", c->url);
|
2004-05-05 04:02:13 +04:00
|
|
|
fprintf(fp, "\t*\n");
|
|
|
|
break;
|
2004-05-06 04:52:31 +04:00
|
|
|
case LINK_ANT: /* URL */
|
|
|
|
case LINK_TEXT: /* Text */
|
2004-05-06 16:14:47 +04:00
|
|
|
fprintf(fp, "%s\n", c->url);
|
2004-05-05 04:02:13 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
switch (format) {
|
2004-05-06 04:52:31 +04:00
|
|
|
case LINK_ACORN: /* URI */
|
2004-05-05 04:02:13 +04:00
|
|
|
xosfile_set_type(path, 0xf91);
|
|
|
|
break;
|
2004-05-06 04:52:31 +04:00
|
|
|
case LINK_ANT: /* URL */
|
2004-05-05 04:02:13 +04:00
|
|
|
xosfile_set_type(path, 0xb28);
|
|
|
|
break;
|
2004-05-06 04:52:31 +04:00
|
|
|
case LINK_TEXT: /* Text */
|
2004-05-05 04:02:13 +04:00
|
|
|
xosfile_set_type(path, 0xfff);
|
|
|
|
break;
|
|
|
|
}
|
2004-05-06 16:14:47 +04:00
|
|
|
|
|
|
|
return true;
|
2004-05-05 04:02:13 +04:00
|
|
|
}
|