summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk/gtk_gui.c4
-rw-r--r--gtk/gtk_schedule.c73
-rw-r--r--makefile1
3 files changed, 74 insertions, 4 deletions
diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c
index 644c0fe37..51919c67f 100644
--- a/gtk/gtk_gui.c
+++ b/gtk/gtk_gui.c
@@ -226,10 +226,6 @@ void gui_401login_open(struct browser_window *bw, struct content *c,
void gui_cert_verify(struct browser_window *bw, struct content *c,
const struct ssl_cert_info *certs, unsigned long num) {}
-void schedule(int t, void (*callback)(void *p), void *p) {}
-void schedule_remove(void (*callback)(void *p), void *p) {}
-void schedule_run(void) {}
-
void global_history_add(struct url_content *data) {}
utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len,
diff --git a/gtk/gtk_schedule.c b/gtk/gtk_schedule.c
new file mode 100644
index 000000000..61c46e5bc
--- /dev/null
+++ b/gtk/gtk_schedule.c
@@ -0,0 +1,73 @@
+/*
+ * 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 2006 Daniel Silverstone <dsilvers@digital-scurf.org>
+ */
+
+#include <glib.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "netsurf/desktop/browser.h"
+
+typedef struct {
+ void (*callback)(void *);
+ void *p;
+ int die;
+} _nsgtkcallback;
+
+static GList *callbacks;
+
+static gboolean ns_generic_gtk_callback(gpointer data)
+{
+ _nsgtkcallback *cb = (_nsgtkcallback*)(data);
+ if(cb->die) {
+ /* We got removed before we got fired off */
+ fprintf(stderr, "Callback %p(%p) died before run\n",
+ cb->callback, cb->p);
+ free(cb);
+ return FALSE;
+ }
+ fprintf(stderr, "Calling %p(%p)\n", cb->callback, cb->p);
+ cb->callback(cb->p);
+ callbacks = g_list_remove(callbacks, cb);
+ free(cb);
+ return FALSE;
+}
+
+void schedule_remove(void (*callback)(void *p), void *p)
+{
+ _nsgtkcallback *cb;
+ GList *l;
+ l = callbacks;
+ while(l) {
+ cb = (_nsgtkcallback*)(l->data);
+ if(cb->callback == callback && cb->p == p) {
+ l = callbacks = g_list_remove(callbacks, cb);
+ cb->die = 1;
+ fprintf(stderr, "Callback %p(%p) scheduled for removal\n",
+ cb->callback, cb->p);
+
+ } else
+ l = g_list_next(l);
+ }
+}
+
+void schedule(int t, void (*callback)(void *p), void *p)
+{
+ _nsgtkcallback *cb = (_nsgtkcallback*)malloc(sizeof(_nsgtkcallback));
+ schedule_remove(callback, p);
+ cb->callback = callback;
+ cb->p = p;
+ cb->die = 0;
+ callbacks = g_list_prepend(callbacks, cb);
+ g_timeout_add(t * 10, ns_generic_gtk_callback, cb);
+ fprintf(stderr, "Scheduled a callback to %p(%p) for %d CS\n", callback, p, t);
+}
+
+void schedule_run(void)
+{
+ /* Nothing to do, the running is done via the gtk mainloop of joy */
+}
+
diff --git a/makefile b/makefile
index f4b15ddf1..a2b4a6235 100644
--- a/makefile
+++ b/makefile
@@ -65,6 +65,7 @@ OBJECTS_GTK += filetyped.o # debug/
OBJECTS_GTK += browser.o netsurf.o selection.o textinput.o \
version.o # desktop/
OBJECTS_GTK += font_pango.o gtk_bitmap.o gtk_gui.o \
+ gtk_schedule.o \
gtk_plotters.o gtk_treeview.o gtk_window.o # gtk/