mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-23 23:09:39 +03:00
[project @ 2003-08-28 19:21:27 by bursa]
Start implementing download window. svn path=/import/netsurf/; revision=255
This commit is contained in:
parent
b444025e28
commit
cef8c477c3
Binary file not shown.
@ -22,3 +22,6 @@ Back:Back one page
|
|||||||
Forward:Forward one page
|
Forward:Forward one page
|
||||||
Reload:Reload this page
|
Reload:Reload this page
|
||||||
|
|
||||||
|
# Download window
|
||||||
|
Downloaded:Download complete, %lu bytes
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ static void browser_window_follow_link(struct browser_window* bw,
|
|||||||
unsigned long click_x, unsigned long click_y, int click_type);
|
unsigned long click_x, unsigned long click_y, int click_type);
|
||||||
static void browser_window_callback(content_msg msg, struct content *c,
|
static void browser_window_callback(content_msg msg, struct content *c,
|
||||||
void *p1, void *p2, const char *error);
|
void *p1, void *p2, const char *error);
|
||||||
|
static void download_window_callback(content_msg msg, struct content *c,
|
||||||
|
void *p1, void *p2, const char *error);
|
||||||
static void clear_radio_gadgets(struct browser_window* bw, struct box* box, struct gui_gadget* group);
|
static void clear_radio_gadgets(struct browser_window* bw, struct box* box, struct gui_gadget* group);
|
||||||
static void gui_redraw_gadget2(struct browser_window* bw, struct box* box, struct gui_gadget* g,
|
static void gui_redraw_gadget2(struct browser_window* bw, struct box* box, struct gui_gadget* g,
|
||||||
unsigned long x, unsigned long y);
|
unsigned long x, unsigned long y);
|
||||||
@ -166,7 +168,7 @@ struct browser_window* create_browser_window(int flags, int width, int height)
|
|||||||
|
|
||||||
bw->url = NULL;
|
bw->url = NULL;
|
||||||
|
|
||||||
bw->window = create_gui_browser_window(bw);
|
bw->window = gui_create_browser_window(bw);
|
||||||
|
|
||||||
return bw;
|
return bw;
|
||||||
}
|
}
|
||||||
@ -274,9 +276,20 @@ void browser_window_callback(content_msg msg, struct content *c,
|
|||||||
{
|
{
|
||||||
case CONTENT_MSG_LOADING:
|
case CONTENT_MSG_LOADING:
|
||||||
if (c->type == CONTENT_OTHER) {
|
if (c->type == CONTENT_OTHER) {
|
||||||
|
gui_window *download_window;
|
||||||
/* TODO: implement downloads */
|
/* TODO: implement downloads */
|
||||||
/* we probably want to open a new window with a save icon and progress bar,
|
/* we probably want to open a new window with a save icon and progress bar,
|
||||||
* and transfer content_loading to it */
|
* and transfer content_loading to it */
|
||||||
|
assert(bw->loading_content == c);
|
||||||
|
|
||||||
|
/* create download window and add content to it */
|
||||||
|
download_window = gui_create_download_window(c);
|
||||||
|
content_add_user(c, download_window_callback, download_window, 0);
|
||||||
|
|
||||||
|
/* remove content from browser window */
|
||||||
|
bw->loading_content = 0;
|
||||||
|
content_remove_user(c, browser_window_callback, bw, 0);
|
||||||
|
browser_window_stop_throbber(bw);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -347,6 +360,37 @@ void browser_window_callback(content_msg msg, struct content *c,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void download_window_callback(content_msg msg, struct content *c,
|
||||||
|
void *p1, void *p2, const char *error)
|
||||||
|
{
|
||||||
|
gui_window *download_window = p1;
|
||||||
|
|
||||||
|
switch (msg) {
|
||||||
|
case CONTENT_MSG_STATUS:
|
||||||
|
gui_download_window_update_status(download_window);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONTENT_MSG_DONE:
|
||||||
|
gui_download_window_done(download_window);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONTENT_MSG_ERROR:
|
||||||
|
gui_download_window_error(download_window, error);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONTENT_MSG_READY:
|
||||||
|
/* not possible for CONTENT_OTHER */
|
||||||
|
assert(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CONTENT_MSG_LOADING:
|
||||||
|
case CONTENT_MSG_REDIRECT:
|
||||||
|
/* not possible at this point, handled above */
|
||||||
|
assert(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void clear_radio_gadgets(struct browser_window* bw, struct box* box, struct gui_gadget* group)
|
void clear_radio_gadgets(struct browser_window* bw, struct box* box, struct gui_gadget* group)
|
||||||
{
|
{
|
||||||
struct box* c;
|
struct box* c;
|
||||||
|
@ -9,11 +9,11 @@
|
|||||||
#ifndef _NETSURF_DESKTOP_GUI_H_
|
#ifndef _NETSURF_DESKTOP_GUI_H_
|
||||||
#define _NETSURF_DESKTOP_GUI_H_
|
#define _NETSURF_DESKTOP_GUI_H_
|
||||||
|
|
||||||
typedef enum { GUI_BROWSER_WINDOW } gui_window_type;
|
typedef enum { GUI_BROWSER_WINDOW, GUI_DOWNLOAD_WINDOW } gui_window_type;
|
||||||
typedef enum { SAFE, UNSAFE } gui_safety;
|
typedef enum { SAFE, UNSAFE } gui_safety;
|
||||||
|
|
||||||
struct ro_gui_window;
|
struct gui_window;
|
||||||
typedef struct ro_gui_window gui_window;
|
typedef struct gui_window gui_window;
|
||||||
|
|
||||||
#include "netsurf/desktop/browser.h"
|
#include "netsurf/desktop/browser.h"
|
||||||
|
|
||||||
@ -29,7 +29,8 @@ struct gui_message
|
|||||||
|
|
||||||
typedef struct gui_message gui_message;
|
typedef struct gui_message gui_message;
|
||||||
|
|
||||||
gui_window* create_gui_browser_window(struct browser_window* bw);
|
gui_window *gui_create_browser_window(struct browser_window *bw);
|
||||||
|
gui_window *gui_create_download_window(struct content *content);
|
||||||
void gui_window_destroy(gui_window* g);
|
void gui_window_destroy(gui_window* g);
|
||||||
void gui_window_show(gui_window* g);
|
void gui_window_show(gui_window* g);
|
||||||
void gui_window_hide(gui_window* g);
|
void gui_window_hide(gui_window* g);
|
||||||
@ -44,6 +45,10 @@ void gui_window_set_title(gui_window* g, char* title);
|
|||||||
|
|
||||||
void gui_window_message(gui_window* g, gui_message* msg);
|
void gui_window_message(gui_window* g, gui_message* msg);
|
||||||
|
|
||||||
|
void gui_download_window_update_status(gui_window *g);
|
||||||
|
void gui_download_window_done(gui_window *g);
|
||||||
|
void gui_download_window_error(gui_window *g, const char *error);
|
||||||
|
|
||||||
void gui_init(int argc, char** argv);
|
void gui_init(int argc, char** argv);
|
||||||
void gui_multitask(void);
|
void gui_multitask(void);
|
||||||
void gui_poll(void);
|
void gui_poll(void);
|
||||||
|
2
makefile
2
makefile
@ -12,7 +12,7 @@ OBJECTS_COMMON = cache.o content.o fetch.o fetchcache.o other.o \
|
|||||||
messages.o utils.o
|
messages.o utils.o
|
||||||
OBJECTS = $(OBJECTS_COMMON) \
|
OBJECTS = $(OBJECTS_COMMON) \
|
||||||
browser.o netsurf.o \
|
browser.o netsurf.o \
|
||||||
dialog.o gif.o gui.o jpeg.o menus.o png.o theme.o plugin.o \
|
dialog.o download.o gif.o gui.o jpeg.o menus.o png.o theme.o plugin.o \
|
||||||
options.o filetype.o font.o uri.o
|
options.o filetype.o font.o uri.o
|
||||||
OBJECTS_DEBUG = $(OBJECTS_COMMON) \
|
OBJECTS_DEBUG = $(OBJECTS_COMMON) \
|
||||||
netsurfd.o \
|
netsurfd.o \
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
|
|
||||||
wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br,
|
wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br,
|
||||||
dialog_config_prox, dialog_config_th;
|
dialog_config_prox, dialog_config_th, download_template;
|
||||||
wimp_menu* theme_menu = NULL;
|
wimp_menu* theme_menu = NULL;
|
||||||
|
|
||||||
static struct ro_choices choices;
|
static struct ro_choices choices;
|
||||||
@ -62,14 +62,12 @@ static void set_icon_string_i(wimp_w w, wimp_i i, int num);
|
|||||||
|
|
||||||
void ro_gui_dialog_init(void)
|
void ro_gui_dialog_init(void)
|
||||||
{
|
{
|
||||||
wimp_open_template("<NetSurf$Dir>.Resources.Templates");
|
|
||||||
dialog_info = ro_gui_dialog_create("info");
|
dialog_info = ro_gui_dialog_create("info");
|
||||||
dialog_saveas = ro_gui_dialog_create("saveas");
|
dialog_saveas = ro_gui_dialog_create("saveas");
|
||||||
dialog_config = ro_gui_dialog_create("config");
|
dialog_config = ro_gui_dialog_create("config");
|
||||||
dialog_config_br = ro_gui_dialog_create("config_br");
|
dialog_config_br = ro_gui_dialog_create("config_br");
|
||||||
dialog_config_prox = ro_gui_dialog_create("config_prox");
|
dialog_config_prox = ro_gui_dialog_create("config_prox");
|
||||||
dialog_config_th = ro_gui_dialog_create("config_th");
|
dialog_config_th = ro_gui_dialog_create("config_th");
|
||||||
wimp_close_template();
|
|
||||||
|
|
||||||
options_to_ro(&OPTIONS, &choices);
|
options_to_ro(&OPTIONS, &choices);
|
||||||
set_browser_choices(&choices.browser);
|
set_browser_choices(&choices.browser);
|
||||||
|
173
riscos/download.c
Normal file
173
riscos/download.c
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
/*
|
||||||
|
* 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 2003 James Bursa <bursa@users.sourceforge.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "oslib/mimemap.h"
|
||||||
|
#include "oslib/wimp.h"
|
||||||
|
#include "oslib/wimpspriteop.h"
|
||||||
|
#include "netsurf/desktop/gui.h"
|
||||||
|
#include "netsurf/riscos/gui.h"
|
||||||
|
#include "netsurf/utils/log.h"
|
||||||
|
#include "netsurf/utils/messages.h"
|
||||||
|
#include "netsurf/utils/utils.h"
|
||||||
|
|
||||||
|
|
||||||
|
static wimp_window *download_template;
|
||||||
|
|
||||||
|
|
||||||
|
static void ro_gui_download_leaf(const char *url, char *leaf);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the download window template.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void ro_gui_download_init(void)
|
||||||
|
{
|
||||||
|
char name[] = "download";
|
||||||
|
int context, window_size, data_size;
|
||||||
|
char *data;
|
||||||
|
|
||||||
|
/* find required buffer sizes */
|
||||||
|
context = wimp_load_template(wimp_GET_SIZE, 0, 0, wimp_NO_FONTS,
|
||||||
|
name, 0, &window_size, &data_size);
|
||||||
|
assert(context != 0);
|
||||||
|
|
||||||
|
download_template = xcalloc((unsigned int) window_size, 1);
|
||||||
|
data = xcalloc((unsigned int) data_size, 1);
|
||||||
|
|
||||||
|
/* load */
|
||||||
|
wimp_load_template(download_template, data, data + data_size,
|
||||||
|
wimp_NO_FONTS, name, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and open a download progress window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
gui_window *gui_create_download_window(struct content *content)
|
||||||
|
{
|
||||||
|
gui_window *g = xcalloc(1, sizeof(gui_window));
|
||||||
|
os_error *e;
|
||||||
|
|
||||||
|
assert(content->type == CONTENT_OTHER);
|
||||||
|
|
||||||
|
g->type = GUI_DOWNLOAD_WINDOW;
|
||||||
|
g->data.download.content = content;
|
||||||
|
|
||||||
|
/* convert MIME type to RISC OS file type */
|
||||||
|
e = xmimemaptranslate_mime_type_to_filetype(content->mime_type,
|
||||||
|
&(g->data.download.file_type));
|
||||||
|
if (e)
|
||||||
|
g->data.download.file_type = 0xffd;
|
||||||
|
|
||||||
|
/* fill in download window icons */
|
||||||
|
download_template->icons[ICON_DOWNLOAD_URL].data.indirected_text.text =
|
||||||
|
content->url;
|
||||||
|
download_template->icons[ICON_DOWNLOAD_URL].data.indirected_text.size =
|
||||||
|
strlen(content->url) + 1;
|
||||||
|
strncpy(g->status, content->status_message, 256);
|
||||||
|
download_template->icons[ICON_DOWNLOAD_STATUS].data.indirected_text.text =
|
||||||
|
g->status;
|
||||||
|
download_template->icons[ICON_DOWNLOAD_STATUS].data.indirected_text.size =
|
||||||
|
256;
|
||||||
|
sprintf(g->data.download.sprite_name, "Sfile_%x",
|
||||||
|
g->data.download.file_type);
|
||||||
|
e = xwimpspriteop_select_sprite(g->data.download.sprite_name + 1, 0);
|
||||||
|
if (e)
|
||||||
|
strcpy(g->data.download.sprite_name, "Sfile_xxx");
|
||||||
|
download_template->icons[ICON_DOWNLOAD_ICON].data.indirected_text.validation =
|
||||||
|
g->data.download.sprite_name;
|
||||||
|
ro_gui_download_leaf(content->url, g->data.download.path);
|
||||||
|
download_template->icons[ICON_DOWNLOAD_PATH].data.indirected_text.text =
|
||||||
|
g->data.download.path;
|
||||||
|
download_template->icons[ICON_DOWNLOAD_PATH].data.indirected_text.size =
|
||||||
|
256;
|
||||||
|
|
||||||
|
/* create and open the download window */
|
||||||
|
g->data.download.window = wimp_create_window(download_template);
|
||||||
|
ro_gui_dialog_open(g->data.download.window);
|
||||||
|
|
||||||
|
g->next = window_list;
|
||||||
|
window_list = g;
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a friendly RISC OS leaf name for a URL.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void ro_gui_download_leaf(const char *url, char *leaf)
|
||||||
|
{
|
||||||
|
char *slash;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
/* take url from last / to first non-RISC OS character, eg. '.' */
|
||||||
|
slash = strrchr(url, '/');
|
||||||
|
if (!slash) {
|
||||||
|
strcpy(leaf, "download");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
len = strspn(slash + 1, "0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||||
|
"abcdefghijklmnopqrstuvwxyz"); /* over-paranoid */
|
||||||
|
if (40 < len)
|
||||||
|
len = 40;
|
||||||
|
strncpy(leaf, slash + 1, len);
|
||||||
|
leaf[len] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh the status icon in the download window.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void gui_download_window_update_status(gui_window *g)
|
||||||
|
{
|
||||||
|
strncpy(g->status, g->data.download.content->status_message, 256);
|
||||||
|
wimp_set_icon_state(g->data.download.window,
|
||||||
|
ICON_DOWNLOAD_STATUS, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle failed downloads.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void gui_download_window_error(gui_window *g, const char *error)
|
||||||
|
{
|
||||||
|
g->data.download.content = 0;
|
||||||
|
|
||||||
|
/* place error message in status icon in red */
|
||||||
|
strncpy(g->status, error, 256);
|
||||||
|
wimp_set_icon_state(g->data.download.window,
|
||||||
|
ICON_DOWNLOAD_STATUS,
|
||||||
|
wimp_COLOUR_RED << wimp_ICON_FG_COLOUR_SHIFT,
|
||||||
|
wimp_ICON_FG_COLOUR);
|
||||||
|
|
||||||
|
/* grey out file and pathname icons */
|
||||||
|
wimp_set_icon_state(g->data.download.window,
|
||||||
|
ICON_DOWNLOAD_ICON, wimp_ICON_SHADED, 0);
|
||||||
|
wimp_set_icon_state(g->data.download.window,
|
||||||
|
ICON_DOWNLOAD_PATH, wimp_ICON_SHADED, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle completed downloads.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void gui_download_window_done(gui_window *g)
|
||||||
|
{
|
||||||
|
snprintf(g->status, 256, messages_get("Downloaded"),
|
||||||
|
g->data.download.content->data.other.length);
|
||||||
|
wimp_set_icon_state(g->data.download.window,
|
||||||
|
ICON_DOWNLOAD_STATUS, 0, 0);
|
||||||
|
}
|
||||||
|
|
@ -37,7 +37,7 @@
|
|||||||
const char *__dynamic_da_name = "NetSurf";
|
const char *__dynamic_da_name = "NetSurf";
|
||||||
|
|
||||||
char *NETSURF_DIR;
|
char *NETSURF_DIR;
|
||||||
static gui_window *window_list = 0;
|
gui_window *window_list = 0;
|
||||||
|
|
||||||
int gadget_subtract_x;
|
int gadget_subtract_x;
|
||||||
int gadget_subtract_y;
|
int gadget_subtract_y;
|
||||||
@ -170,7 +170,7 @@ int window_y_units(int scr_units, wimp_window_state* win)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gui_window* create_gui_browser_window(struct browser_window* bw)
|
gui_window *gui_create_browser_window(struct browser_window *bw)
|
||||||
{
|
{
|
||||||
struct wimp_window window;
|
struct wimp_window window;
|
||||||
|
|
||||||
@ -915,8 +915,11 @@ void gui_init(int argc, char** argv)
|
|||||||
LOG(("Using theme '%s' - from '%s'",theme_fname, OPTIONS.theme));
|
LOG(("Using theme '%s' - from '%s'",theme_fname, OPTIONS.theme));
|
||||||
current_theme = ro_theme_create(theme_fname);
|
current_theme = ro_theme_create(theme_fname);
|
||||||
|
|
||||||
|
wimp_open_template("<NetSurf$Dir>.Resources.Templates");
|
||||||
ro_gui_dialog_init();
|
ro_gui_dialog_init();
|
||||||
|
ro_gui_download_init();
|
||||||
ro_gui_menus_init();
|
ro_gui_menus_init();
|
||||||
|
wimp_close_template();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ro_gui_throb(void)
|
void ro_gui_throb(void)
|
||||||
|
20
riscos/gui.h
20
riscos/gui.h
@ -23,9 +23,10 @@ extern wimp_menu *current_menu, *iconbar_menu, *browser_menu,
|
|||||||
extern int current_menu_x, current_menu_y, iconbar_menu_height;
|
extern int current_menu_x, current_menu_y, iconbar_menu_height;
|
||||||
extern struct gui_gadget *current_gadget;
|
extern struct gui_gadget *current_gadget;
|
||||||
extern const char *HOME_URL;
|
extern const char *HOME_URL;
|
||||||
|
extern gui_window *window_list;
|
||||||
|
|
||||||
|
|
||||||
struct ro_gui_window
|
struct gui_window
|
||||||
{
|
{
|
||||||
gui_window_type type;
|
gui_window_type type;
|
||||||
|
|
||||||
@ -36,6 +37,13 @@ struct ro_gui_window
|
|||||||
int toolbar_width;
|
int toolbar_width;
|
||||||
struct browser_window* bw;
|
struct browser_window* bw;
|
||||||
} browser;
|
} browser;
|
||||||
|
struct {
|
||||||
|
wimp_w window;
|
||||||
|
struct content *content;
|
||||||
|
bits file_type;
|
||||||
|
char sprite_name[20];
|
||||||
|
char path[256];
|
||||||
|
} download;
|
||||||
} data;
|
} data;
|
||||||
|
|
||||||
char status[256];
|
char status[256];
|
||||||
@ -51,6 +59,7 @@ struct ro_gui_window
|
|||||||
int old_width;
|
int old_width;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* in gui.c */
|
/* in gui.c */
|
||||||
void ro_gui_copy_selection(gui_window* g);
|
void ro_gui_copy_selection(gui_window* g);
|
||||||
|
|
||||||
@ -67,6 +76,9 @@ void ro_gui_dialog_close(wimp_w close);
|
|||||||
void ro_gui_redraw_config_th(wimp_draw* redraw);
|
void ro_gui_redraw_config_th(wimp_draw* redraw);
|
||||||
void ro_gui_theme_menu_selection(char *theme);
|
void ro_gui_theme_menu_selection(char *theme);
|
||||||
|
|
||||||
|
/* in download.c */
|
||||||
|
void ro_gui_download_init(void);
|
||||||
|
|
||||||
/* icon numbers */
|
/* icon numbers */
|
||||||
#define ICON_CONFIG_SAVE 0
|
#define ICON_CONFIG_SAVE 0
|
||||||
#define ICON_CONFIG_CANCEL 1
|
#define ICON_CONFIG_CANCEL 1
|
||||||
@ -100,4 +112,10 @@ void ro_gui_theme_menu_selection(char *theme);
|
|||||||
#define ICON_CONFIG_TH_GET 8
|
#define ICON_CONFIG_TH_GET 8
|
||||||
#define ICON_CONFIG_TH_MANAGE 9
|
#define ICON_CONFIG_TH_MANAGE 9
|
||||||
|
|
||||||
|
#define ICON_DOWNLOAD_URL 0
|
||||||
|
#define ICON_DOWNLOAD_STATUS 1
|
||||||
|
#define ICON_DOWNLOAD_ICON 2
|
||||||
|
#define ICON_DOWNLOAD_PATH 3
|
||||||
|
#define ICON_DOWNLOAD_ABORT 4
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user