-static void updatetitle(void);
-static void windestroy(GtkWidget* w, gpointer d);
-static gboolean keypress(GtkWidget* w, GdkEventKey *ev);
-static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gchar* title, gpointer d);
-static void progresschange(WebKitWebView *view, gint p, gpointer d);
-static void loadcommit(WebKitWebView *view, WebKitWebFrame *f, gpointer d);
-static void loadstart(WebKitWebView *view, WebKitWebFrame *f, gpointer d);
-static void loadfinish(WebKitWebView *view, WebKitWebFrame *f, gpointer d);
-static void linkhover(WebKitWebView* page, const gchar* t, const gchar* l, gpointer d);
-static gboolean newwindow(WebKitWebView *view, WebKitWebFrame *f,
- WebKitNetworkRequest *r, WebKitWebNavigationAction *n,
- WebKitWebPolicyDecision *p, gpointer d);
-static gboolean download(WebKitWebView *view, GObject *o, gpointer d);
-static void loaduri(gchar *uri);
-static void loadfile(gchar *f);
-static void setupstdin();
-static gboolean readstdin(GIOChannel *c, GIOCondition con);
+static void proccookies(SoupMessage *m, Client *c);
+static void clipboard(Client *c, const Arg *arg);
+static void destroyclient(Client *c);
+static void destroywin(GtkWidget* w, Client *c);
+static void die(char *str);
+static void download(WebKitDownload *o, GParamSpec *pspec, Client *c);
+static gboolean initdownload(WebKitWebView *view, WebKitDownload *o, Client *c);
+static gchar *geturi(Client *c);
+static void hidesearch(Client *c, const Arg *arg);
+static void hideurl(Client *c, const Arg *arg);
+static gboolean keypress(GtkWidget* w, GdkEventKey *ev, Client *c);
+static void linkhover(WebKitWebView* page, const gchar* t, const gchar* l, Client *c);
+static void loadcommit(WebKitWebView *view, WebKitWebFrame *f, Client *c);
+static void loadstart(WebKitWebView *view, WebKitWebFrame *f, Client *c);
+static void loadfile(Client *c, const gchar *f);
+static void loaduri(Client *c, const Arg *arg);
+static void navigate(Client *c, const Arg *arg);
+static Client *newclient();
+static WebKitWebView *newwindow(WebKitWebView *v, WebKitWebFrame *f, Client *c);
+static void pasteurl(GtkClipboard *clipboard, const gchar *text, gpointer d);
+static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
+static void progresschange(WebKitWebView *view, gint p, Client *c);
+static void request(SoupSession *s, SoupMessage *m, Client *c);
+static void setcookie(char *name, char *val, char *dom, char *path, long exp);
+static void reload(Client *c, const Arg *arg);
+static void setup(void);
+static void titlechange(WebKitWebView* view, WebKitWebFrame* frame,
+ const gchar* title, Client *c);
+static void searchtext(Client *c, const Arg *arg);
+static void showsearch(Client *c, const Arg *arg);
+static void showurl(Client *c, const Arg *arg);
+static void stop(Client *c, const Arg *arg);
+static void titlechange(WebKitWebView* view, WebKitWebFrame* frame, const gchar* title, Client *c);
+static void usage();
+static void updatetitle(Client *c, const gchar *title);
+static void zoompage(Client *c, const Arg *arg);
+
+#include "config.h"
+
+void
+cleanup(void) {
+ while(clients)
+ destroyclient(clients);
+}
+
+void
+proccookies(SoupMessage *m, Client *c) {
+ GSList *l;
+ SoupCookie *co;
+ long t;
+
+ for (l = soup_cookies_from_response(m); l; l = l->next){
+ co = (SoupCookie *)l->data;
+ t = co->expires ? soup_date_to_time_t(co->expires) : 0;
+ setcookie(co->name, co->value, co->domain, co->value, t);
+ }
+ g_slist_free(l);
+}
+
+void
+clipboard(Client *c, const Arg *arg) {
+ gboolean paste = *(gboolean *)arg;
+ if(paste)
+ gtk_clipboard_request_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), pasteurl, c);
+ else
+ gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), webkit_web_view_get_uri(c->view), -1);
+}
+
+void
+destroyclient(Client *c) {
+ Client *p;
+
+ gtk_widget_destroy(GTK_WIDGET(webkit_web_view_new()));
+ gtk_widget_destroy(c->scroll);
+ gtk_widget_destroy(c->urlbar);
+ gtk_widget_destroy(c->searchbar);
+ gtk_widget_destroy(c->vbox);
+ gtk_widget_destroy(c->win);
+ for(p = clients; p && p->next != c; p = p->next);
+ if(p)
+ p->next = c->next;
+ else
+ clients = c->next;
+ free(c);
+ if(clients == NULL)
+ gtk_main_quit();
+}
+
+void
+destroywin(GtkWidget* w, Client *c) {
+ destroyclient(c);
+}
+
+void
+die(char *str) {
+ fputs(str, stderr);
+ exit(EXIT_FAILURE);
+}
+
+void
+download(WebKitDownload *o, GParamSpec *pspec, Client *c) {
+ WebKitDownloadStatus status;
+
+ status = webkit_download_get_status(c->download);
+ if(status == WEBKIT_DOWNLOAD_STATUS_STARTED || status == WEBKIT_DOWNLOAD_STATUS_CREATED) {
+ c->progress = (int)(webkit_download_get_progress(c->download)*100);
+ }
+ updatetitle(c, NULL);
+}