summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2014-01-14 16:04:02 +0000
committerVincent Sanders <vince@netsurf-browser.org>2014-01-14 16:04:02 +0000
commit8dfe22515312a8ecf4da974feb31b0f5e7f317e5 (patch)
tree163091cfeda5c4cb644e08e7649f70788070a560 /desktop
parentd18c8ed4521714c3fff3cca64685b8192ca0e075 (diff)
downloadnetsurf-8dfe22515312a8ecf4da974feb31b0f5e7f317e5.tar.gz
netsurf-8dfe22515312a8ecf4da974feb31b0f5e7f317e5.tar.bz2
move download operations to download table
Diffstat (limited to 'desktop')
-rw-r--r--desktop/download.c8
-rw-r--r--desktop/gui.h35
-rw-r--r--desktop/gui_factory.c77
3 files changed, 95 insertions, 25 deletions
diff --git a/desktop/download.c b/desktop/download.c
index b775eb18e..98c6b6dd0 100644
--- a/desktop/download.c
+++ b/desktop/download.c
@@ -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);
diff --git a/desktop/gui.h b/desktop/gui.h
index 8d65893d0..50e8c67d9 100644
--- a/desktop/gui.h
+++ b/desktop/gui.h
@@ -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.
*
diff --git a/desktop/gui_factory.c b/desktop/gui_factory.c
index 8ebf3515a..7f76eaccb 100644
--- a/desktop/gui_factory.c
+++ b/desktop/gui_factory.c
@@ -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) {