NetSurf
|
RISC OS download windows implementation. More...
#include <assert.h>
#include <string.h>
#include <time.h>
#include <libwapcaplet/libwapcaplet.h>
#include "oslib/mimemap.h"
#include "oslib/osargs.h"
#include "oslib/osfile.h"
#include "oslib/osfind.h"
#include "oslib/osfscontrol.h"
#include "oslib/osgbpb.h"
#include "oslib/wimp.h"
#include "oslib/wimpspriteop.h"
#include "utils/sys_time.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/nsurl.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "utils/url.h"
#include "utils/corestrings.h"
#include "netsurf/download.h"
#include "desktop/download.h"
#include "riscos/gui.h"
#include "riscos/dialog.h"
#include "riscos/mouse.h"
#include "riscos/save.h"
#include "riscos/query.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
#include "riscos/ucstables.h"
#include "riscos/filetype.h"
Go to the source code of this file.
Data Structures | |
struct | gui_download_window |
context for each download. More... | |
Macros | |
#define | ICON_DOWNLOAD_ICON 0 |
#define | ICON_DOWNLOAD_URL 1 |
#define | ICON_DOWNLOAD_PATH 2 |
#define | ICON_DOWNLOAD_DESTINATION 3 |
#define | ICON_DOWNLOAD_PROGRESS 5 |
#define | ICON_DOWNLOAD_STATUS 6 |
#define | RO_DOWNLOAD_MAX_PATH_LEN 255 |
Enumerations | |
enum | query_reason { QueryRsn_Quit , QueryRsn_Abort , QueryRsn_Overwrite } |
Functions | |
static void | ro_gui_download_drag_end (wimp_dragged *drag, void *data) |
Handle User_Drag_Box event for a drag from a download window. More... | |
static const char * | ro_gui_download_temp_name (struct gui_download_window *dw) |
Returns the pathname of a temporary file for this download. More... | |
static void | ro_gui_download_update_status (struct gui_download_window *dw) |
Update the status text and progress bar. More... | |
static void | ro_gui_download_update_status_wrapper (void *p) |
Wrapper for ro_gui_download_update_status(), suitable for riscos_schedule(). More... | |
static void | ro_gui_download_window_hide_caret (struct gui_download_window *dw) |
Hide the caret but preserve input focus. More... | |
static char * | ro_gui_download_canonicalise (const char *path) |
Return a pathname in canonical form. More... | |
static bool | ro_gui_download_check_space (struct gui_download_window *dw, const char *dest_file, const char *orig_file) |
Check the available space on the medium containing the destination file, taking into account any space currently occupied by the file at its original location. More... | |
static os_error * | ro_gui_download_move (struct gui_download_window *dw, const char *dest_file, const char *src_file) |
Move the downloading file to a new location and continue downloading there. More... | |
static void | ro_gui_download_remember_dir (const char *path) |
Remember the directory containing the given file, for use in further downloads. More... | |
static bool | ro_gui_download_save (struct gui_download_window *dw, const char *file_name, bool force_overwrite) |
Start of save operation, user has specified where the file should be saved. More... | |
static void | ro_gui_download_send_dataload (struct gui_download_window *dw) |
Send DataLoad message in response to DataSaveAck, informing the target application that the transfer is complete. More... | |
static void | ro_gui_download_window_destroy_wrapper (void *p) |
Wrapper for ro_gui_download_window_destroy(), suitable for riscos_schedule(). More... | |
static bool | ro_gui_download_window_destroy (struct gui_download_window *dw, bool quit) |
Close a download window and free any related resources. More... | |
static void | ro_gui_download_close_confirmed (query_id id, enum query_response res, void *p) |
Download aborted, close window and tidy up. More... | |
static void | ro_gui_download_close_cancelled (query_id id, enum query_response res, void *p) |
User has opted to cancel the close, leaving the download to continue. More... | |
static void | ro_gui_download_overwrite_confirmed (query_id id, enum query_response res, void *p) |
Overwrite of existing file confirmed, proceed with the save. More... | |
static void | ro_gui_download_overwrite_cancelled (query_id id, enum query_response res, void *p) |
User has opted not to overwrite the existing file. More... | |
static bool | ro_gui_download_click (wimp_pointer *pointer) |
Handle Mouse_Click events in a download window. More... | |
static bool | ro_gui_download_keypress (wimp_key *key) |
Handler Key_Press events in a download window. More... | |
static void | ro_gui_download_close (wimp_w w) |
Handle closing of download window. More... | |
void | ro_gui_download_init (void) |
Load the download window template. More... | |
static nserror | download_ro_filetype (download_context *ctx, bits *ftype_out) |
Try and find the correct RISC OS filetype from a download context. More... | |
static struct gui_download_window * | gui_download_window_create (download_context *ctx, struct gui_window *gui) |
Create and open a download progress window. More... | |
static void | gui_download_window_error (struct gui_download_window *dw, const char *error_msg) |
Handle failed downloads. More... | |
static nserror | gui_download_window_data (struct gui_download_window *dw, const char *data, unsigned int size) |
Handle received download data. More... | |
static void | gui_download_window_done (struct gui_download_window *dw) |
Handle completed downloads. More... | |
void | ro_gui_download_datasave_ack (wimp_message *message) |
Handle Message_DataSaveAck for a drag from a download window. More... | |
bool | ro_gui_download_prequit (void) |
Respond to PreQuit message, displaying a prompt message if we need the user to confirm the shutdown. More... | |
Variables | |
static struct gui_download_window * | download_window_list = 0 |
List of all download windows. More... | |
static struct gui_download_window * | download_window_current = 0 |
Download window with current save operation. More... | |
static wimp_window * | download_template |
Template for a download window. More... | |
static int | download_progress_width |
Width of progress bar at 100%. More... | |
static int | download_progress_x0 |
Coordinates of progress bar. More... | |
static int | download_progress_y0 |
static int | download_progress_y1 |
static char * | download_dir = NULL |
Current download directory. More... | |
static size_t | download_dir_len |
static const query_callback | close_funcs |
static const query_callback | overwrite_funcs |
static struct gui_download_table | download_table |
struct gui_download_table * | riscos_download_table = &download_table |
RISC OS download windows implementation.
This file implements the interface given by netsurf/download.h for download windows. Each download window has an associated fetch. Downloads start by writing received data to a temporary file. At some point the user chooses a destination (by drag & drop), and the temporary file is then moved to the destination and the download continues until complete.
Definition in file download.c.
#define ICON_DOWNLOAD_DESTINATION 3 |
Definition at line 73 of file download.c.
#define ICON_DOWNLOAD_ICON 0 |
Definition at line 70 of file download.c.
#define ICON_DOWNLOAD_PATH 2 |
Definition at line 72 of file download.c.
#define ICON_DOWNLOAD_PROGRESS 5 |
Definition at line 74 of file download.c.
#define ICON_DOWNLOAD_STATUS 6 |
Definition at line 75 of file download.c.
#define ICON_DOWNLOAD_URL 1 |
Definition at line 71 of file download.c.
#define RO_DOWNLOAD_MAX_PATH_LEN 255 |
Definition at line 77 of file download.c.
enum query_reason |
Enumerator | |
---|---|
QueryRsn_Quit | |
QueryRsn_Abort | |
QueryRsn_Overwrite |
Definition at line 79 of file download.c.
|
static |
Try and find the correct RISC OS filetype from a download context.
Definition at line 222 of file download.c.
References gui_download_window::ctx, download_context_get_mime_type(), download_context_get_url(), gui_download_window::error, NSERROR_OK, NSLOG, nsurl_get_component(), NSURL_PATH, NSURL_SCHEME, path(), ro_filetype_from_unix_path(), ro_warn_user(), gui_download_window::url, and url_unescape().
Referenced by gui_download_window_create().
|
static |
Create and open a download progress window.
ctx | Download context |
gui | The RISCOS gui window to download for. |
Definition at line 287 of file download.c.
References gui_download_window::average_points, gui_download_window::average_rate, gui_download_window::close_confirmed, gui_download_window::ctx, download_context_get_filename(), download_context_get_total_length(), download_context_get_url(), download_dir, download_ro_filetype(), download_template, download_window_list, gui_download_window::error, gui_download_window::file, gui_download_window::file_type, gui_download_window::filename, ICON_DOWNLOAD_DESTINATION, ICON_DOWNLOAD_ICON, ICON_DOWNLOAD_PATH, ICON_DOWNLOAD_STATUS, ICON_DOWNLOAD_URL, gui_download_window::last_received, gui_download_window::last_time, messages_get(), messages_get_errorcode(), gui_download_window::next, NSERROR_BAD_ENCODING, NSERROR_OK, NSLOG, nsoption_bool, nsurl_access(), gui_download_window::path, gui_download_window::prev, gui_download_window::query, QUERY_INVALID, gui_download_window::received, RO_DOWNLOAD_MAX_PATH_LEN, ro_gui_dialog_open(), ro_gui_download_check_space(), ro_gui_download_click(), ro_gui_download_close(), ro_gui_download_keypress(), ro_gui_download_temp_name(), ro_gui_download_update_status(), ro_gui_wimp_event_register_close_window(), ro_gui_wimp_event_register_keypress(), ro_gui_wimp_event_register_mouse_click(), ro_gui_wimp_event_set_user_data(), ro_gui_wimp_sprite_exists(), ro_warn_user(), gui_download_window::saved, gui_download_window::size, gui_download_window::sprite_name, gui_download_window::start_time, gui_download_window::status, text(), gui_download_window::total_size, gui_download_window::url, utf8_to_local_encoding(), and gui_download_window::window.
|
static |
Handle received download data.
dw | download window |
data | pointer to block of data received |
size | size of data |
Definition at line 530 of file download.c.
References gui_download_window::ctx, download_context_abort(), gui_download_window::error, gui_download_window::file, gui_download_window_error(), ICON_DOWNLOAD_DESTINATION, ICON_DOWNLOAD_ICON, ICON_DOWNLOAD_PATH, messages_get(), NSERROR_OK, NSERROR_SAVE_FAILED, NSLOG, gui_download_window::path, gui_download_window::received, ro_gui_download_move(), ro_gui_download_temp_name(), ro_warn_user(), gui_download_window::saved, gui_download_window::size, and gui_download_window::window.
|
static |
Handle completed downloads.
dw | download window |
Definition at line 810 of file download.c.
References gui_download_window::ctx, download_context_destroy(), gui_download_window::file, gui_download_window::file_type, NSLOG, gui_download_window::path, riscos_schedule(), ro_gui_download_send_dataload(), ro_gui_download_update_status(), ro_gui_download_window_destroy_wrapper(), ro_warn_user(), gui_download_window::saved, and gui_download_window::send_dataload.
|
static |
Handle failed downloads.
dw | download window |
error_msg | error message |
Definition at line 475 of file download.c.
References gui_download_window::ctx, download_context_destroy(), gui_download_window::error, ICON_DOWNLOAD_ICON, ICON_DOWNLOAD_PATH, ICON_DOWNLOAD_STATUS, NSLOG, riscos_schedule(), ro_gui_download_update_status_wrapper(), ro_gui_download_window_hide_caret(), ro_warn_user(), gui_download_window::status, and gui_download_window::window.
Referenced by gui_download_window_data(), and ro_gui_download_save().
|
static |
Return a pathname in canonical form.
path | pathnamee to be canonicalised |
Definition at line 1040 of file download.c.
References gui_download_window::error, NSLOG, and path().
Referenced by ro_gui_download_check_space().
|
static |
Check the available space on the medium containing the destination file, taking into account any space currently occupied by the file at its original location.
dw | download window |
dest_file | destination pathname |
orig_file | current pathname, NULL if no existing file |
Definition at line 1085 of file download.c.
References gui_download_window::error, gui_download_window::file, min, NSLOG, ro_gui_download_canonicalise(), and gui_download_window::total_size.
Referenced by gui_download_window_create(), and ro_gui_download_save().
|
static |
Handle Mouse_Click events in a download window.
pointer | block returned by Wimp_Poll |
Definition at line 851 of file download.c.
References download_window_current, gui_download_window::error, ICON_DOWNLOAD_DESTINATION, ICON_DOWNLOAD_ICON, NSLOG, gui_download_window::path, ro_gui_download_drag_end(), ro_gui_drag_icon(), ro_gui_get_icon_string(), ro_gui_wimp_event_get_user_data(), ro_mouse_drag_start(), ro_warn_user(), and gui_download_window::saved.
Referenced by gui_download_window_create().
|
static |
Handle closing of download window.
Definition at line 1479 of file download.c.
References ro_gui_download_window_destroy(), ro_gui_wimp_event_get_user_data(), and gui_download_window::w.
Referenced by gui_download_window_create().
|
static |
User has opted to cancel the close, leaving the download to continue.
Definition at line 1607 of file download.c.
References gui_download_window::query, and QUERY_INVALID.
|
static |
Download aborted, close window and tidy up.
Definition at line 1618 of file download.c.
References gui_download_window::close_confirmed, download_window_list, gui_download_window::query, QUERY_INVALID, gui_download_window::query_rsn, QueryRsn_Quit, riscos_done, ro_gui_download_window_destroy(), ro_gui_download_window_destroy_wrapper(), and ro_gui_prequit().
void ro_gui_download_datasave_ack | ( | wimp_message * | message | ) |
Handle Message_DataSaveAck for a drag from a download window.
message | block returned by Wimp_Poll |
Definition at line 1010 of file download.c.
References gui_download_window::ctx, download_window_current, nsoption_bool, riscos_schedule(), ro_gui_download_save(), ro_gui_download_send_dataload(), ro_gui_download_window_destroy_wrapper(), gui_download_window::save_message, and gui_download_window::send_dataload.
Referenced by ro_msg_datasave_ack().
|
static |
Handle User_Drag_Box event for a drag from a download window.
*drag | block returned by Wimp_Poll |
*data | NULL data to allow use as callback from ro_mouse. |
Definition at line 949 of file download.c.
References download_window_current, gui_download_window::error, gui_download_window::file_type, gui_current_drag_type, GUI_DRAG_DOWNLOAD_SAVE, NSLOG, gui_download_window::path, gui_download_window::received, ro_gui_convert_save_path(), ro_warn_user(), gui_download_window::saved, gui_download_window::total_size, and gui_download_window::window.
Referenced by ro_gui_download_click().
void ro_gui_download_init | ( | void | ) |
Load the download window template.
Definition at line 189 of file download.c.
References download_progress_width, download_progress_x0, download_progress_y0, download_progress_y1, download_template, ICON_DOWNLOAD_PROGRESS, ICON_DOWNLOAD_STATUS, and ro_gui_dialog_load_template().
Referenced by gui_init().
|
static |
Handler Key_Press events in a download window.
key | key press returned by Wimp_Poll |
Definition at line 905 of file download.c.
References gui_download_window::ctx, ICON_DOWNLOAD_PATH, gui_download_window::name, nsoption_bool, gui_download_window::path, riscos_schedule(), ro_gui_convert_save_path(), ro_gui_download_save(), ro_gui_download_window_destroy(), ro_gui_download_window_destroy_wrapper(), ro_gui_get_icon_string(), ro_gui_wimp_event_get_user_data(), ro_warn_user(), gui_download_window::send_dataload, and gui_download_window::window.
Referenced by gui_download_window_create().
|
static |
Move the downloading file to a new location and continue downloading there.
dw | download window |
dest_file | new location |
src_file | old location |
Definition at line 1187 of file download.c.
References gui_download_window::ctx, gui_download_window::error, gui_download_window::file, gui_download_window::file_type, NSLOG, gui_download_window::received, and ro_warn_user().
Referenced by gui_download_window_data(), and ro_gui_download_save().
|
static |
User has opted not to overwrite the existing file.
Definition at line 1642 of file download.c.
References gui_download_window::query, and QUERY_INVALID.
|
static |
Overwrite of existing file confirmed, proceed with the save.
Definition at line 1653 of file download.c.
References gui_download_window::ctx, gui_download_window::query, QUERY_INVALID, riscos_schedule(), ro_gui_download_save(), ro_gui_download_send_dataload(), ro_gui_download_window_destroy_wrapper(), and gui_download_window::save_message.
bool ro_gui_download_prequit | ( | void | ) |
Respond to PreQuit message, displaying a prompt message if we need the user to confirm the shutdown.
Definition at line 1680 of file download.c.
References download_window_list, and ro_gui_download_window_destroy().
Referenced by ro_gui_prequit().
|
static |
Remember the directory containing the given file, for use in further downloads.
path | pathname of downloaded file |
Definition at line 1276 of file download.c.
References download_dir, download_dir_len, and path().
Referenced by ro_gui_download_save().
|
static |
Start of save operation, user has specified where the file should be saved.
dw | download window |
file_name | pathname of destination file & |
force_overwrite | true iff required to overwrite without prompting |
Definition at line 1312 of file download.c.
References gui_download_window::ctx, download_context_abort(), gui_download_window::error, gui_download_window::file, gui_download_window_error(), ICON_DOWNLOAD_DESTINATION, ICON_DOWNLOAD_ICON, ICON_DOWNLOAD_PATH, messages_get(), NSLOG, overwrite_funcs, gui_download_window::path, gui_download_window::query, gui_download_window::query_rsn, query_user(), QueryRsn_Overwrite, gui_download_window::received, ro_gui_download_check_space(), ro_gui_download_move(), ro_gui_download_remember_dir(), ro_gui_download_temp_name(), ro_gui_download_window_hide_caret(), ro_gui_force_redraw_icon(), ro_warn_user(), gui_download_window::save_message, gui_download_window::saved, gui_download_window::send_dataload, and gui_download_window::window.
Referenced by ro_gui_download_datasave_ack(), ro_gui_download_keypress(), and ro_gui_download_overwrite_confirmed().
|
static |
Send DataLoad message in response to DataSaveAck, informing the target application that the transfer is complete.
dw | download window |
Definition at line 1438 of file download.c.
References gui_download_window::error, NSLOG, riscos_schedule(), ro_gui_download_window_destroy_wrapper(), ro_warn_user(), gui_download_window::save_message, and gui_download_window::send_dataload.
Referenced by gui_download_window_done(), ro_gui_download_datasave_ack(), and ro_gui_download_overwrite_confirmed().
|
static |
Returns the pathname of a temporary file for this download.
dw | download window |
Definition at line 211 of file download.c.
Referenced by gui_download_window_create(), gui_download_window_data(), ro_gui_download_save(), and ro_gui_download_window_destroy().
|
static |
Update the status text and progress bar.
dw | download window |
Definition at line 616 of file download.c.
References gui_download_window::average_points, gui_download_window::average_rate, gui_download_window::ctx, download_progress_width, download_progress_x0, download_progress_y0, download_progress_y1, human_friendly_bytesize(), ICON_DOWNLOAD_PROGRESS, ICON_DOWNLOAD_STATUS, gui_download_window::last_received, gui_download_window::last_time, max, messages_get(), NSERROR_BAD_ENCODING, NSERROR_OK, NSLOG, gui_download_window::received, riscos_schedule(), ro_gui_download_update_status_wrapper(), ro_warn_user(), gui_download_window::speed, gui_download_window::start_time, gui_download_window::status, gui_download_window::total_size, utf8_to_local_encoding(), width, and gui_download_window::window.
Referenced by gui_download_window_create(), gui_download_window_done(), and ro_gui_download_update_status_wrapper().
|
static |
Wrapper for ro_gui_download_update_status(), suitable for riscos_schedule().
Definition at line 765 of file download.c.
References ro_gui_download_update_status().
Referenced by gui_download_window_error(), ro_gui_download_update_status(), and ro_gui_download_window_destroy().
|
static |
Close a download window and free any related resources.
dw | download window |
quit | destroying because we're quitting the whole app |
Definition at line 1496 of file download.c.
References gui_download_window::close_confirmed, close_funcs, gui_download_window::ctx, download_context_abort(), download_context_destroy(), download_window_list, gui_download_window::error, gui_download_window::file, gui_download_window::next, NSLOG, gui_download_window::prev, gui_download_window::query, query_close(), QUERY_INVALID, gui_download_window::query_rsn, query_user(), QueryRsn_Abort, QueryRsn_Quit, riscos_schedule(), ro_gui_dialog_open_top(), ro_gui_download_temp_name(), ro_gui_download_update_status_wrapper(), ro_gui_download_window_destroy_wrapper(), ro_gui_query_window_bring_to_front(), ro_gui_wimp_event_finalise(), ro_warn_user(), gui_download_window::saved, and gui_download_window::window.
Referenced by ro_gui_download_close(), ro_gui_download_close_confirmed(), ro_gui_download_keypress(), ro_gui_download_prequit(), and ro_gui_download_window_destroy_wrapper().
|
static |
Wrapper for ro_gui_download_window_destroy(), suitable for riscos_schedule().
Definition at line 1592 of file download.c.
References gui_download_window::close_confirmed, gui_download_window::query, query_close(), QUERY_INVALID, and ro_gui_download_window_destroy().
Referenced by gui_download_window_done(), ro_gui_download_close_confirmed(), ro_gui_download_datasave_ack(), ro_gui_download_keypress(), ro_gui_download_overwrite_confirmed(), ro_gui_download_send_dataload(), and ro_gui_download_window_destroy().
|
static |
Hide the caret but preserve input focus.
dw | download window |
Definition at line 778 of file download.c.
References NSLOG, ro_warn_user(), and gui_download_window::window.
Referenced by gui_download_window_error(), and ro_gui_download_save().
|
static |
Definition at line 172 of file download.c.
Referenced by ro_gui_download_window_destroy().
|
static |
Current download directory.
Definition at line 144 of file download.c.
Referenced by ami_file_req_init(), ami_gui_opts_open(), ami_gui_opts_use(), gui_download_window_create(), and ro_gui_download_remember_dir().
|
static |
Definition at line 145 of file download.c.
Referenced by ro_gui_download_remember_dir().
|
static |
Width of progress bar at 100%.
Definition at line 137 of file download.c.
Referenced by ro_gui_download_init(), and ro_gui_download_update_status().
|
static |
Coordinates of progress bar.
Definition at line 139 of file download.c.
Referenced by ro_gui_download_init(), and ro_gui_download_update_status().
|
static |
Definition at line 140 of file download.c.
Referenced by ro_gui_download_init(), and ro_gui_download_update_status().
|
static |
Definition at line 141 of file download.c.
Referenced by ro_gui_download_init(), and ro_gui_download_update_status().
|
static |
Definition at line 1690 of file download.c.
|
static |
Template for a download window.
Definition at line 134 of file download.c.
Referenced by gui_download_window_create(), and ro_gui_download_init().
|
static |
Download window with current save operation.
Definition at line 131 of file download.c.
Referenced by ro_gui_download_click(), ro_gui_download_datasave_ack(), and ro_gui_download_drag_end().
|
static |
List of all download windows.
Definition at line 129 of file download.c.
Referenced by gui_download_window_create(), ro_gui_download_close_confirmed(), ro_gui_download_prequit(), and ro_gui_download_window_destroy().
|
static |
Definition at line 178 of file download.c.
Referenced by ro_gui_download_save().
struct gui_download_table* riscos_download_table = &download_table |
Definition at line 1697 of file download.c.
Referenced by main().