diff options
author | James Bursa <james@netsurf-browser.org> | 2003-08-28 19:21:27 +0000 |
---|---|---|
committer | James Bursa <james@netsurf-browser.org> | 2003-08-28 19:21:27 +0000 |
commit | cef8c477c396458269a91ee756fc711bed74d0f4 (patch) | |
tree | 342bc9575240e4051c0784a7d88cc5c0990ab5c1 | |
parent | b444025e2837843c26e7ea015bda91f5184d5aa0 (diff) | |
download | netsurf-cef8c477c396458269a91ee756fc711bed74d0f4.tar.gz netsurf-cef8c477c396458269a91ee756fc711bed74d0f4.tar.bz2 |
[project @ 2003-08-28 19:21:27 by bursa]
Start implementing download window.
svn path=/import/netsurf/; revision=255
-rw-r--r-- | !NetSurf/Resources/Templates,fec | bin | 3672 -> 3683 bytes | |||
-rw-r--r-- | !NetSurf/Resources/en/Messages | 3 | ||||
-rw-r--r-- | desktop/browser.c | 46 | ||||
-rw-r--r-- | desktop/gui.h | 13 | ||||
-rw-r--r-- | makefile | 2 | ||||
-rw-r--r-- | riscos/dialog.c | 4 | ||||
-rw-r--r-- | riscos/download.c | 173 | ||||
-rw-r--r-- | riscos/gui.c | 7 | ||||
-rw-r--r-- | riscos/gui.h | 20 |
9 files changed, 256 insertions, 12 deletions
diff --git a/!NetSurf/Resources/Templates,fec b/!NetSurf/Resources/Templates,fec Binary files differindex 27c71822b..77bc61eda 100644 --- a/!NetSurf/Resources/Templates,fec +++ b/!NetSurf/Resources/Templates,fec diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages index 4c8317661..b1764fd95 100644 --- a/!NetSurf/Resources/en/Messages +++ b/!NetSurf/Resources/en/Messages @@ -22,3 +22,6 @@ Back:Back one page Forward:Forward one page Reload:Reload this page +# Download window +Downloaded:Download complete, %lu bytes + diff --git a/desktop/browser.c b/desktop/browser.c index 0782bd6fb..d296ddaea 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -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); static void browser_window_callback(content_msg msg, struct content *c, 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 gui_redraw_gadget2(struct browser_window* bw, struct box* box, struct gui_gadget* g, 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->window = create_gui_browser_window(bw); + bw->window = gui_create_browser_window(bw); return bw; } @@ -274,9 +276,20 @@ void browser_window_callback(content_msg msg, struct content *c, { case CONTENT_MSG_LOADING: if (c->type == CONTENT_OTHER) { + gui_window *download_window; /* TODO: implement downloads */ /* we probably want to open a new window with a save icon and progress bar, * 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; @@ -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) { struct box* c; diff --git a/desktop/gui.h b/desktop/gui.h index 8438e8ee0..a12cb8d5e 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -9,11 +9,11 @@ #ifndef _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; -struct ro_gui_window; -typedef struct ro_gui_window gui_window; +struct gui_window; +typedef struct gui_window gui_window; #include "netsurf/desktop/browser.h" @@ -29,7 +29,8 @@ struct 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_show(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_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_multitask(void); void gui_poll(void); @@ -12,7 +12,7 @@ OBJECTS_COMMON = cache.o content.o fetch.o fetchcache.o other.o \ messages.o utils.o OBJECTS = $(OBJECTS_COMMON) \ 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 OBJECTS_DEBUG = $(OBJECTS_COMMON) \ netsurfd.o \ diff --git a/riscos/dialog.c b/riscos/dialog.c index 99f18e83e..f8df58bb0 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -25,7 +25,7 @@ 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; 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) { - wimp_open_template("<NetSurf$Dir>.Resources.Templates"); dialog_info = ro_gui_dialog_create("info"); dialog_saveas = ro_gui_dialog_create("saveas"); dialog_config = ro_gui_dialog_create("config"); dialog_config_br = ro_gui_dialog_create("config_br"); dialog_config_prox = ro_gui_dialog_create("config_prox"); dialog_config_th = ro_gui_dialog_create("config_th"); - wimp_close_template(); options_to_ro(&OPTIONS, &choices); set_browser_choices(&choices.browser); diff --git a/riscos/download.c b/riscos/download.c new file mode 100644 index 000000000..92d7e0a45 --- /dev/null +++ b/riscos/download.c @@ -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); +} + diff --git a/riscos/gui.c b/riscos/gui.c index f1305d036..cd7067a37 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -37,7 +37,7 @@ const char *__dynamic_da_name = "NetSurf"; char *NETSURF_DIR; -static gui_window *window_list = 0; +gui_window *window_list = 0; int gadget_subtract_x; 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; @@ -915,8 +915,11 @@ void gui_init(int argc, char** argv) LOG(("Using theme '%s' - from '%s'",theme_fname, OPTIONS.theme)); current_theme = ro_theme_create(theme_fname); + wimp_open_template("<NetSurf$Dir>.Resources.Templates"); ro_gui_dialog_init(); + ro_gui_download_init(); ro_gui_menus_init(); + wimp_close_template(); } void ro_gui_throb(void) diff --git a/riscos/gui.h b/riscos/gui.h index 2758272da..9f1f60e39 100644 --- a/riscos/gui.h +++ b/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 struct gui_gadget *current_gadget; extern const char *HOME_URL; +extern gui_window *window_list; -struct ro_gui_window +struct gui_window { gui_window_type type; @@ -36,6 +37,13 @@ struct ro_gui_window int toolbar_width; struct browser_window* bw; } browser; + struct { + wimp_w window; + struct content *content; + bits file_type; + char sprite_name[20]; + char path[256]; + } download; } data; char status[256]; @@ -51,6 +59,7 @@ struct ro_gui_window int old_width; }; + /* in gui.c */ 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_theme_menu_selection(char *theme); +/* in download.c */ +void ro_gui_download_init(void); + /* icon numbers */ #define ICON_CONFIG_SAVE 0 #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_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 |