move download operations to download table

This commit is contained in:
Vincent Sanders 2014-01-14 16:04:02 +00:00
parent d18c8ed452
commit 8dfe225153
28 changed files with 232 additions and 96 deletions

View File

@ -85,7 +85,7 @@ enum {
int downloads_in_progress = 0;
struct gui_download_window *gui_download_window_create(download_context *ctx,
static struct gui_download_window *gui_download_window_create(download_context *ctx,
struct gui_window *gui)
{
const char *url = download_context_get_url(ctx);
@ -193,7 +193,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx,
return dw;
}
nserror gui_download_window_data(struct gui_download_window *dw,
static nserror gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
APTR va[3];
@ -227,7 +227,7 @@ nserror gui_download_window_data(struct gui_download_window *dw,
return NSERROR_OK;
}
void gui_download_window_error(struct gui_download_window *dw,
static void gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
warn_user("Unwritten","");
@ -242,7 +242,7 @@ void ami_download_window_abort(struct gui_download_window *dw)
gui_download_window_done(dw);
}
void gui_download_window_done(struct gui_download_window *dw)
static void gui_download_window_done(struct gui_download_window *dw)
{
struct dlnode *dln,*dln2 = NULL;
struct browser_window *bw = dw->bw;
@ -432,3 +432,12 @@ BOOL ami_download_check_overwrite(const char *file, struct Window *win, ULONG si
if(res == 1) return TRUE;
else return FALSE;
}
static struct gui_download_table gui_download_table = {
.create = gui_download_window_create,
.data = gui_download_window_data,
.error = gui_download_window_error,
.done = gui_download_window_done,
};
struct gui_download_table *amiga_gui_download_table = &gui_download_table;

View File

@ -23,6 +23,8 @@
#include "amiga/gui.h"
extern struct gui_download_table *amiga_gui_download_table;
struct download_context;
struct gui_download_window;

View File

@ -5185,6 +5185,8 @@ int main(int argc, char** argv)
if (ami_locate_resource(messages, "Messages") == false)
die("Cannot open Messages file");
ami_gui_table.download = amiga_gui_download_table;
ret = netsurf_init(messages, &ami_gui_table);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");

View File

@ -246,8 +246,8 @@ static char * select_filepath( const char * path, const char * filename )
return(ret);
}
struct gui_download_window * gui_download_window_create(download_context *ctx,
struct gui_window *parent)
static struct gui_download_window *
gui_download_window_create(download_context *ctx, struct gui_window *parent)
{
const char *filename;
char *destination;
@ -359,7 +359,7 @@ struct gui_download_window * gui_download_window_create(download_context *ctx,
}
nserror gui_download_window_data(struct gui_download_window *dw,
static nserror gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
@ -415,7 +415,7 @@ nserror gui_download_window_data(struct gui_download_window *dw,
return NSERROR_OK;
}
void gui_download_window_error(struct gui_download_window *dw,
static void gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
LOG(("%s", error_msg));
@ -426,7 +426,7 @@ void gui_download_window_error(struct gui_download_window *dw,
// TODO: change abort to close
}
void gui_download_window_done(struct gui_download_window *dw)
static void gui_download_window_done(struct gui_download_window *dw)
{
OBJECT * tree;
LOG((""));
@ -454,3 +454,13 @@ void gui_download_window_done(struct gui_download_window *dw)
}
gui_window_set_status(input_window, messages_get("Done") );
}
static struct gui_download_table gui_download_table = {
.create = gui_download_window_create,
.data = gui_download_window_data,
.error = gui_download_window_error,
.done = gui_download_window_done,
};
struct gui_download_table *atari_gui_download_table = &gui_download_table;

View File

@ -58,4 +58,6 @@ struct gui_download_window {
bool close_on_finish;
};
struct gui_download_table *atari_gui_download_table;
#endif

View File

@ -1116,6 +1116,9 @@ int main(int argc, char** argv)
/* common initialisation */
LOG(("Initialising core..."));
atari_gui_table.download = nsgtk_gui_download_table;
ret = netsurf_init(messages, atari_gui_table);
if (ret != NSERROR_OK) {
die("NetSurf failed to initialise");

View File

@ -178,7 +178,7 @@ NSDownloadWindow::Failure(const char* error)
}
struct gui_download_window *gui_download_window_create(download_context *ctx,
static struct gui_download_window *gui_download_window_create(download_context *ctx,
struct gui_window *parent)
{
struct gui_download_window *download = (struct gui_download_window*)malloc(sizeof *download);
@ -209,7 +209,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx,
}
nserror gui_download_window_data(struct gui_download_window *dw,
static nserror gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
dw->window->Progress(size);
@ -222,7 +222,7 @@ nserror gui_download_window_data(struct gui_download_window *dw,
}
void gui_download_window_error(struct gui_download_window *dw,
static void gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
dw->window->Failure(error_msg);
@ -232,7 +232,7 @@ void gui_download_window_error(struct gui_download_window *dw,
}
void gui_download_window_done(struct gui_download_window *dw)
static void gui_download_window_done(struct gui_download_window *dw)
{
dw->window->Success();
@ -248,3 +248,12 @@ void gui_download_window_done(struct gui_download_window *dw)
dw->storageLock->Unlock();
}
static struct gui_download_table gui_download_table = {
.create = gui_download_window_create,
.data = gui_download_window_data,
.error = gui_download_window_error,
.done = gui_download_window_done,
};
struct gui_download_table *beos_gui_download_table = &gui_download_table;

View File

@ -16,3 +16,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
struct gui_download_table *beos_gui_download_table;

View File

@ -1111,6 +1111,7 @@ int main(int argc, char** argv)
BPath messages = get_messages_path();
beos_gui_table.window = beos_gui_window_table;
beos_gui_table.download = beos_gui_download_table;
ret = netsurf_init(messages.Path(), &beos_gui_table);
if (ret != NSERROR_OK) {
@ -1152,6 +1153,10 @@ int gui_init_replicant(int argc, char** argv)
/* common initialisation */
BPath messages = get_messages_path();
beos_gui_table.window = beos_gui_window_table;
beos_gui_table.download = beos_gui_download_table;
ret = netsurf_init(messages.Path(), &beos_gui_table);
if (ret != NSERROR_OK) {
// FIXME: must not die when in replicant!

View File

@ -18,6 +18,7 @@
#import <Cocoa/Cocoa.h>
struct gui_download_table *cocoa_gui_download_table;
@interface DownloadWindowController : NSWindowController {
struct download_context *context;
@ -50,3 +51,4 @@
- (void) abort;
@end

View File

@ -327,7 +327,7 @@ static NSString *cocoa_time_string( unsigned seconds )
#pragma mark -
#pragma mark NetSurf interface functions
struct gui_download_window *gui_download_window_create(download_context *ctx,
static struct gui_download_window *gui_download_window_create(download_context *ctx,
struct gui_window *parent)
{
DownloadWindowController * const window = [[DownloadWindowController alloc] initWithContext: ctx];
@ -338,21 +338,21 @@ struct gui_download_window *gui_download_window_create(download_context *ctx,
return (struct gui_download_window *)window;
}
nserror gui_download_window_data(struct gui_download_window *dw,
static nserror gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
DownloadWindowController * const window = (DownloadWindowController *)dw;
return [window receivedData: [NSData dataWithBytes: data length: size]] ? NSERROR_OK : NSERROR_SAVE_FAILED;
}
void gui_download_window_error(struct gui_download_window *dw,
static void gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
DownloadWindowController * const window = (DownloadWindowController *)dw;
[window showError: [NSString stringWithUTF8String: error_msg]];
}
void gui_download_window_done(struct gui_download_window *dw)
static void gui_download_window_done(struct gui_download_window *dw)
{
DownloadWindowController * const window = (DownloadWindowController *)dw;
[window downloadDone];
@ -376,3 +376,12 @@ static void cocoa_unregister_download( DownloadWindowController *download )
[cocoa_all_downloads removeObject: download];
}
static struct gui_download_table gui_download_table = {
.create = gui_download_window_create,
.data = gui_download_window_data,
.error = gui_download_window_error,
.done = gui_download_window_done,
};
struct gui_download_table *cocoa_gui_download_table = &gui_download_table;

View File

@ -203,6 +203,8 @@ int main( int argc, char **argv )
nsoption_commandline(&argc, argv, NULL);
/* common initialisation */
cocoa_gui_table->download = cocoa_gui_download_table;
error = netsurf_init(messages, cocoa_gui_table);
if (error != NSERROR_OK) {
die("NetSurf failed to initialise");

View File

@ -160,7 +160,7 @@ static nserror download_context_process_headers(download_context *ctx)
}
/* Create the frontend window */
ctx->window = gui_download_window_create(ctx, ctx->parent);
ctx->window = guit->download->create(ctx, ctx->parent);
if (ctx->window == NULL) {
free(ctx->filename);
ctx->filename = NULL;
@ -210,7 +210,7 @@ static nserror download_callback(llcache_handle *handle,
if (error == NSERROR_OK) {
/** \todo Lose ugly cast */
error = gui_download_window_data(ctx->window,
error = guit->download->data(ctx->window,
(char *) event->data.data.buf,
event->data.data.len);
if (error != NSERROR_OK)
@ -222,7 +222,7 @@ static nserror download_callback(llcache_handle *handle,
case LLCACHE_EVENT_DONE:
/* There may be no associated window if there was no data or headers */
if (ctx->window != NULL)
gui_download_window_done(ctx->window);
guit->download->done(ctx->window);
else
download_context_destroy(ctx);
@ -230,7 +230,7 @@ static nserror download_callback(llcache_handle *handle,
case LLCACHE_EVENT_ERROR:
if (ctx->window != NULL)
gui_download_window_error(ctx->window, event->data.msg);
guit->download->error(ctx->window, event->data.msg);
else
download_context_destroy(ctx);

View File

@ -244,16 +244,34 @@ struct gui_window_table {
void (*start_selection)(struct gui_window *g);
};
/**
* function table for download windows
*/
struct gui_download_table {
struct gui_download_window *(*create)(download_context *ctx, struct gui_window *parent);
nserror (*data)(struct gui_download_window *dw, const char *data, unsigned int size);
void (*error)(struct gui_download_window *dw, const char *error_msg);
void (*done)(struct gui_download_window *dw);
};
/** Graphical user interface function table
*
* function table implementing GUI interface to browser core
*/
struct gui_table {
/* Mandantory entries */
/* sub tables */
struct gui_window_table *window; /* window sub table */
/** Window sub table */
struct gui_window_table *window;
/** Downlaod sub table */
struct gui_download_table *download;
/* Mandantory entries */
/** called to let the frontend update its state and run any
* I/O operations.
@ -280,17 +298,6 @@ extern struct gui_table *guit; /* the gui vtable */
struct gui_download_window *gui_download_window_create(download_context *ctx,
struct gui_window *parent);
nserror gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size);
void gui_download_window_error(struct gui_download_window *dw,
const char *error_msg);
void gui_download_window_done(struct gui_download_window *dw);
/**
* Callback to translate resource to full url.
*

View File

@ -5,13 +5,6 @@
struct gui_table *guit = NULL;
static void gui_default_quit(void)
{
}
static void gui_default_set_search_ico(hlcache_handle *ico)
{
}
static void gui_default_window_set_title(struct gui_window *g, const char *title)
@ -201,6 +194,68 @@ static nserror verify_window_register(struct gui_window_table *gwt)
return NSERROR_OK;
}
static struct gui_download_window *
gui_default_download_create(download_context *ctx, struct gui_window *parent)
{
return NULL;
}
static nserror gui_default_download_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
return NSERROR_OK;
}
static void gui_default_download_error(struct gui_download_window *dw,
const char *error_msg)
{
}
static void gui_default_download_done(struct gui_download_window *dw)
{
}
static struct gui_download_table default_download_table = {
.create = gui_default_download_create,
.data = gui_default_download_data,
.error = gui_default_download_error,
.done = gui_default_download_done,
};
/** verify download window table is valid */
static nserror verify_download_register(struct gui_download_table *gdt)
{
/* check table is present */
if (gdt == NULL) {
return NSERROR_BAD_PARAMETER;
}
/* all enties are mandantory */
if (gdt->create == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (gdt->data == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (gdt->error == NULL) {
return NSERROR_BAD_PARAMETER;
}
if (gdt->done == NULL) {
return NSERROR_BAD_PARAMETER;
}
return NSERROR_OK;
}
static void gui_default_quit(void)
{
}
static void gui_default_set_search_ico(hlcache_handle *ico)
{
}
nserror gui_factory_register(struct gui_table *gt)
{
nserror err;
@ -220,6 +275,14 @@ nserror gui_factory_register(struct gui_table *gt)
if (err != NSERROR_OK) {
return err;
}
if (gt->download == NULL) {
/* set default download table */
gt->download = &default_download_table;
}
err = verify_download_register(gt->download);
if (err != NSERROR_OK) {
return err;
}
/* check the mandantory fields are set */
if (gt->poll == NULL) {

View File

@ -1766,30 +1766,6 @@ gui_window_remove_caret(struct gui_window *g)
}
}
struct gui_download_window *
gui_download_window_create(download_context *ctx, struct gui_window *parent)
{
return NULL;
}
nserror
gui_download_window_data(struct gui_download_window *dw,
const char *data,
unsigned int size)
{
return NSERROR_OK;
}
void
gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
}
void
gui_download_window_done(struct gui_download_window *dw)
{
}
void
gui_create_form_select_menu(struct browser_window *bw,

View File

@ -712,8 +712,8 @@ static void nsgtk_download_store_create_item (struct gui_download_window *dl)
NSGTK_DOWNLOAD, dl, -1);
}
struct gui_download_window *gui_download_window_create(download_context *ctx,
struct gui_window *gui)
static struct gui_download_window *
gui_download_window_create(download_context *ctx, struct gui_window *gui)
{
const char *url = download_context_get_url(ctx);
unsigned long total_size = download_context_get_total_length(ctx);
@ -797,7 +797,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx,
}
nserror gui_download_window_data(struct gui_download_window *dw,
static nserror gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
g_io_channel_write_chars(dw->write, data, size, NULL, &dw->error);
@ -820,13 +820,13 @@ nserror gui_download_window_data(struct gui_download_window *dw,
}
void gui_download_window_error(struct gui_download_window *dw,
static void gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
}
void gui_download_window_done(struct gui_download_window *dw)
static void gui_download_window_done(struct gui_download_window *dw)
{
g_io_channel_shutdown(dw->write, TRUE, &dw->error);
g_io_channel_unref(dw->write);
@ -845,17 +845,11 @@ void gui_download_window_done(struct gui_download_window *dw)
}
static struct gui_download_table gui_download_table = {
.create = gui_download_window_create,
.data = gui_download_window_data,
.error = gui_download_window_error,
.done = gui_download_window_done,
};
struct gui_download_table *nsgtk_gui_download_table = &gui_download_table;

View File

@ -27,4 +27,6 @@ bool nsgtk_check_for_downloads(GtkWindow *parent);
void nsgtk_download_show(GtkWindow *parent);
void nsgtk_download_add(gchar *url, gchar *destination);
struct gui_download_table *nsgtk_gui_download_table;
#endif

View File

@ -1172,6 +1172,7 @@ int main(int argc, char** argv)
messages = filepath_find(respaths, "Messages");
nsgtk_gui_table.window = nsgtk_gui_window_table;
nsgtk_gui_table.download = nsgtk_gui_download_table;
ret = netsurf_init(messages, &nsgtk_gui_table);
free(messages);

View File

@ -37,6 +37,7 @@ struct gui_window {
};
extern struct gui_window_table *monkey_gui_window_table;
extern struct gui_download_table *monkey_gui_download_table;
struct gui_window *monkey_find_window_by_num(uint32_t win_num);
struct gui_window *monkey_find_window_by_content(hlcache_handle *content);

View File

@ -34,7 +34,7 @@ struct gui_download_window {
static struct gui_download_window *dw_ring = NULL;
struct gui_download_window *
static struct gui_download_window *
gui_download_window_create(download_context *ctx,
struct gui_window *parent)
{
@ -52,7 +52,7 @@ gui_download_window_create(download_context *ctx,
return ret;
}
nserror
static nserror
gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
@ -61,7 +61,7 @@ gui_download_window_data(struct gui_download_window *dw,
return NSERROR_OK;
}
void
static void
gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
@ -69,7 +69,7 @@ gui_download_window_error(struct gui_download_window *dw,
dw->dwin_num, error_msg);
}
void
static void
gui_download_window_done(struct gui_download_window *dw)
{
fprintf(stdout, "DOWNLOAD_WINDOW DONE DWIN %u\n",
@ -77,3 +77,12 @@ gui_download_window_done(struct gui_download_window *dw)
RING_REMOVE(dw_ring, dw);
free(dw);
}
static struct gui_download_table gui_download_table = {
.create = gui_download_window_create,
.data = gui_download_window_data,
.error = gui_download_window_error,
.done = gui_download_window_done,
};
struct gui_download_table *monkey_gui_download_table = &gui_download_table;

View File

@ -153,6 +153,7 @@ main(int argc, char **argv)
messages = filepath_find(respaths, "Messages");
monkey_gui_table.window = monkey_gui_window_table;
monkey_gui_table.download = monkey_gui_download_table;
ret = netsurf_init(messages, &monkey_gui_table);
free(messages);

View File

@ -215,7 +215,7 @@ const char *ro_gui_download_temp_name(struct gui_download_window *dw)
* reported
*/
struct gui_download_window *gui_download_window_create(download_context *ctx,
static struct gui_download_window *gui_download_window_create(download_context *ctx,
struct gui_window *gui)
{
const char *url = download_context_get_url(ctx);
@ -445,7 +445,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx,
* \return NSERROR_OK on success, appropriate error otherwise
*/
nserror gui_download_window_data(struct gui_download_window *dw,
static nserror gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
while (true) {
@ -714,7 +714,7 @@ void ro_gui_download_window_hide_caret(struct gui_download_window *dw)
* \param error_msg error message
*/
void gui_download_window_error(struct gui_download_window *dw,
static void gui_download_window_error(struct gui_download_window *dw,
const char *error_msg)
{
os_error *error;
@ -766,7 +766,7 @@ void gui_download_window_error(struct gui_download_window *dw,
* \param dw download window
*/
void gui_download_window_done(struct gui_download_window *dw)
static void gui_download_window_done(struct gui_download_window *dw)
{
os_error *error;
@ -1631,3 +1631,12 @@ bool ro_gui_download_prequit(void)
}
return true;
}
static struct gui_download_table gui_download_table = {
.create = gui_download_window_create,
.data = gui_download_window_data,
.error = gui_download_window_error,
.done = gui_download_window_done,
};
struct gui_download_table *riscos_gui_download_table = &gui_download_table;

View File

@ -898,6 +898,7 @@ int main(int argc, char** argv)
/* common initialisation */
riscos_gui_table.window = riscos_gui_window_table;
riscos_gui_table.download = riscos_gui_download_table;
ret = netsurf_init(path, &riscos_gui_table);
if (ret != NSERROR_OK) {

View File

@ -123,6 +123,7 @@ const char *ro_gui_default_language(void);
void ro_gui_download_init(void);
void ro_gui_download_datasave_ack(wimp_message *message);
bool ro_gui_download_prequit(void);
extern struct gui_download_table *riscos_gui_download_table;
/* in 401login.c */
void ro_gui_401login_init(void);

View File

@ -45,7 +45,7 @@ static void nsws_download_update_label(void *p);
static void nsws_download_update_progress(void *p);
static void nsws_download_clear_data(struct gui_download_window *w);
struct gui_download_window *
static struct gui_download_window *
gui_download_window_create(download_context *ctx, struct gui_window *gui)
{
if (downloading) {
@ -259,7 +259,8 @@ void nsws_download_clear_data(struct gui_download_window *w)
}
nserror gui_download_window_data(struct gui_download_window *w, const char *data,
static nserror
gui_download_window_data(struct gui_download_window *w, const char *data,
unsigned int size)
{
if ((w == NULL) || (w->file == NULL))
@ -279,13 +280,13 @@ nserror gui_download_window_data(struct gui_download_window *w, const char *data
return NSERROR_OK;
}
void gui_download_window_error(struct gui_download_window *w,
static void gui_download_window_error(struct gui_download_window *w,
const char *error_msg)
{
LOG(("error %s", error_msg));
}
void gui_download_window_done(struct gui_download_window *w)
static void gui_download_window_done(struct gui_download_window *w)
{
if (w == NULL)
return;
@ -295,3 +296,12 @@ void gui_download_window_done(struct gui_download_window *w)
nsws_download_clear_data(w);
}
static struct gui_download_table gui_download_table = {
.create = gui_download_window_create,
.data = gui_download_window_data,
.error = gui_download_window_error,
.done = gui_download_window_done,
};
struct gui_download_table *win32_gui_download_table = &gui_download_table;

View File

@ -60,4 +60,6 @@ struct gui_download_window {
void nsws_download_window_init(struct gui_window *);
struct gui_download_table *win32_gui_download_table;
#endif

View File

@ -154,6 +154,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hLastInstance, LPSTR lpcli, int ncmd)
/* common initialisation */
messages = filepath_find(respaths, "messages");
win32_gui_table->download = nsgtk_gui_download_table;
ret = netsurf_init(messages, win32_gui_table);
free(messages);
if (ret != NSERROR_OK) {