changing some labels in submenu.
[surf.git] / surf.c
diff --git a/surf.c b/surf.c
index 0d05732..49c7c34 100644 (file)
--- a/surf.c
+++ b/surf.c
@@ -73,6 +73,7 @@ static char *progname;
 
 static const char *autouri(Client *c);
 static char *buildpath(const char *path);
+static void changecookie(SoupCookieJar *jar, SoupCookie *o, SoupCookie *n, gpointer p);
 static void cleanup(void);
 static void clipboard(Client *c, const Arg *arg);
 static void context(WebKitWebView *v, GtkMenu *m, Client *c);
@@ -92,6 +93,7 @@ static void itemclick(GtkMenuItem *mi, Client *c);
 static gboolean keypress(GtkWidget *w, GdkEventKey *ev, Client *c);
 static void linkhover(WebKitWebView *v, const char* t, const char* l, Client *c);
 static void loadcommit(WebKitWebView *v, WebKitWebFrame *f, Client *c);
+static void loadfinished(WebKitWebView *v, WebKitWebFrame *f, Client *c);
 static void loadstart(WebKitWebView *v, WebKitWebFrame *f, Client *c);
 static void loaduri(Client *c, const Arg *arg);
 static void navigate(Client *c, const Arg *arg);
@@ -103,10 +105,10 @@ static GdkFilterReturn processx(GdkXEvent *xevent, GdkEvent *event, gpointer d);
 static void print(Client *c, const Arg *arg);
 static void progresschange(WebKitWebView *v, gint p, Client *c);
 static void reload(Client *c, const Arg *arg);
+static void reloadcookie();
 static void sigchld(int unused);
 static void setup(void);
 static void spawn(Client *c, const Arg *arg);
-static void titlechange(WebKitWebView *v, WebKitWebFrame* frame, const char* title, Client *c);
 static void scroll(Client *c, const Arg *arg);
 static void searchtext(Client *c, const Arg *arg);
 static void source(Client *c, const Arg *arg);
@@ -154,6 +156,18 @@ buildpath(const char *path) {
        return apath;
 }
 
+void
+changecookie(SoupCookieJar *jar, SoupCookie *oc, SoupCookie *c, gpointer p) {
+       SoupDate *e;
+
+       if(c && c->expires == NULL) {
+               e = soup_date_new_from_time_t(time(NULL) + sessiontime);
+               c = soup_cookie_copy(c);
+               soup_cookie_set_expires(c, e);
+               soup_cookie_jar_add_cookie(cookiejar, c);
+       }
+}
+
 void
 cleanup(void) {
        while(clients)
@@ -186,8 +200,6 @@ context(WebKitWebView *v, GtkMenu *m, Client *c) {
                if(parent)
                        gtk_container_remove(parent, c->items[i]);
                gtk_menu_shell_append(GTK_MENU_SHELL(m), c->items[i]);
-               g_signal_connect(G_OBJECT(c->items[i]), "activate",
-                               G_CALLBACK(itemclick), c);
                gtk_widget_show(c->items[i]);
        }
 }
@@ -397,8 +409,14 @@ loadcommit(WebKitWebView *view, WebKitWebFrame *f, Client *c) {
                        strlen(uri) + 1);
 }
 
+void
+loadfinished(WebKitWebView *v, WebKitWebFrame *f, Client *c) {
+       reloadcookie();
+}
+
 void
 loadstart(WebKitWebView *view, WebKitWebFrame *f, Client *c) {
+       reloadcookie();
        c->progress = 0;
        update(c);
 }
@@ -452,9 +470,11 @@ newclient(void) {
                die("Cannot malloc!\n");
 
        /* contextmenu */
-       for(i = 0; i < LENGTH(items); i++)
+       for(i = 0; i < LENGTH(items); i++) {
                c->items[i] = gtk_menu_item_new_with_label(items[i].label);
-
+               g_signal_connect(G_OBJECT(c->items[i]), "activate",
+                               G_CALLBACK(itemclick), c);
+       }
 
        /* VBox */
        c->vbox = gtk_vbox_new(FALSE, 0);
@@ -468,6 +488,7 @@ newclient(void) {
        c->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
        g_signal_connect(G_OBJECT(c->view), "title-changed", G_CALLBACK(titlechange), c);
        g_signal_connect(G_OBJECT(c->view), "load-progress-changed", G_CALLBACK(progresschange), c);
+       g_signal_connect(G_OBJECT(c->view), "load-finished", G_CALLBACK(loadfinished), c);
        g_signal_connect(G_OBJECT(c->view), "load-committed", G_CALLBACK(loadcommit), c);
        g_signal_connect(G_OBJECT(c->view), "load-started", G_CALLBACK(loadstart), c);
        g_signal_connect(G_OBJECT(c->view), "hovering-over-link", G_CALLBACK(linkhover), c);
@@ -619,6 +640,16 @@ reload(Client *c, const Arg *arg) {
                 webkit_web_view_reload(c->view);
 }
 
+void
+reloadcookie(void) {
+       SoupSession *s;
+
+       /* This forces the cookie to be written to hdd */
+       s = webkit_get_default_session();
+       soup_session_remove_feature(s, SOUP_SESSION_FEATURE(cookiejar));
+       soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
+} 
+
 void
 scroll(Client *c, const Arg *arg) {
        gdouble v;
@@ -651,7 +682,7 @@ setup(void) {
 
        dpy = GDK_DISPLAY();
        session = webkit_get_default_session();
-       uriprop = XInternAtom(dpy, "_SURF_uri", False);
+       uriprop = XInternAtom(dpy, "_SURF_URI", False);
 
        /* create dirs and files */
        cookiefile = buildpath(cookiefile);
@@ -663,6 +694,7 @@ setup(void) {
        s = webkit_get_default_session();
        cookiejar = soup_cookie_jar_text_new(cookiefile, FALSE);
        soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
+       g_signal_connect(cookiejar, "changed", G_CALLBACK(changecookie), NULL);
 }
 
 void
@@ -718,7 +750,7 @@ spawn(Client *c, const Arg *arg) {
                        close(ConnectionNumber(dpy));
                setsid();
                execvp(((char **)arg->v)[0], (char **)arg->v);
-               fprintf(stderr, "tabbed: execvp %s", ((char **)arg->v)[0]);
+               fprintf(stderr, "surf: execvp %s", ((char **)arg->v)[0]);
                perror(" failed");
                exit(0);
        }