I have 3 patches for surf:

config_file_locs: Makes all file and directory locations that surf
writes to into config.def.h variables. The other two patches depend on
this one.

write_bookmarks: Adds a function to append the current URI to a
(compile-time-defined) file. Default config binds it to MODKEY+B.

write_history: Modifies loadcommit to append the current URI to a
(compile-time-defined) file. A config.def.h knob can disable this.

The value of the bookmark and history files (for me anyway) is to feed
them to dmenu and load them into surf that way.

There's no locking when writing the files, so race conditions exist. I
figured I'd wait to see how this was solved for the new cookie
handling rather than doing my own thing.
# HG changeset patch
# User Ray Kohler <ataraxia...@gmail.com>
# Date 1252462667 14400
# Node ID 9819d5a95fb7baf1cc063b0815fc0163efd550c7
# Parent  036c96ee90f5f0cd804b8a3ad854aece5ea018bb
[mq]: write_history

diff --git a/config.def.h b/config.def.h
--- a/config.def.h
+++ b/config.def.h
@@ -2,6 +2,9 @@
 static gchar *progress       = "#FF0000";
 static gchar *progress_trust = "#00FF00";
 
+/* whether to write a history file */
+static const bool write_history = true;
+
 /* persistent files and directories */
 /* this one is relative to home directory */
 static const char *surf_dir        = ".surf";
@@ -9,6 +12,7 @@
 static const char *download_dir    = "dl";
 static const char *cookie_file     = "cookies";
 static const char *bookmark_file   = "bookmarks";
+static const char *history_file    = "history";
 
 #define MODKEY GDK_CONTROL_MASK
 static Key keys[] = {
diff --git a/surf.c b/surf.c
--- a/surf.c
+++ b/surf.c
@@ -299,12 +299,23 @@
 void
 loadcommit(WebKitWebView *view, WebKitWebFrame *f, Client *c) {
 	gchar *uri;
+	const gchar *home, *historypath;
+  FILE *historyfile;
 
 	ignore_once = TRUE;
 	uri = geturi(c);
 	XChangeProperty(dpy, GDK_WINDOW_XID(GTK_WIDGET(c->win)->window), urlprop,
 			XA_STRING, 8, PropModeReplace, (unsigned char *)uri,
 			strlen(uri) + 1);
+
+  if(write_history) {
+    home = g_get_home_dir();
+    historypath = g_build_filename(home, surf_dir, history_file, NULL);
+
+    historyfile = g_fopen(historypath, "a");
+    fprintf(historyfile, "%s\n", uri);
+    fclose(historyfile);
+  }
 }
 
 void
# HG changeset patch
# User Ray Kohler <ataraxia...@gmail.com>
# Date 1252462664 14400
# Node ID 036c96ee90f5f0cd804b8a3ad854aece5ea018bb
# Parent  bfd6b9370ce3b013db5993c8a49fd47836b12286
[mq]: write_bookmarks

diff --git a/config.def.h b/config.def.h
--- a/config.def.h
+++ b/config.def.h
@@ -8,6 +8,7 @@
 /* these are relative to surf_dir */
 static const char *download_dir    = "dl";
 static const char *cookie_file     = "cookies";
+static const char *bookmark_file   = "bookmarks";
 
 #define MODKEY GDK_CONTROL_MASK
 static Key keys[] = {
@@ -27,6 +28,7 @@
     { MODKEY,               GDK_l,      navigate,   { .i = +1 },    BROWSER },
     { MODKEY,               GDK_h,      navigate,   { .i = -1 },    BROWSER },
     { 0,                    GDK_Escape, stop,       { 0 },          BROWSER },
+    { MODKEY,               GDK_B,      savebookmark,   {0},        BROWSER },
     { MODKEY,               GDK_n,      searchtext, { .b = TRUE },  BROWSER|SEARCHBAR },
     { MODKEY,               GDK_N,      searchtext, { .b = FALSE }, BROWSER|SEARCHBAR },
     { 0,                    GDK_Return, searchtext, { .b = TRUE },  SEARCHBAR },
diff --git a/surf.c b/surf.c
--- a/surf.c
+++ b/surf.c
@@ -99,6 +99,7 @@
 static void request(SoupSession *s, SoupMessage *m, Client *c);
 static void reload(Client *c, const Arg *arg);
 static void rereadcookies();
+static void savebookmark(Client *c, const Arg *arg);
 static void setcookie(char *name, char *val, char *dom, char *path, long exp);
 static void setup();
 static void titlechange(WebKitWebView* view, WebKitWebFrame* frame,
@@ -528,6 +529,21 @@
 }
 
 void
+savebookmark(Client *c, const Arg *arg) {
+	const gchar *uri, *home, *bookmarkpath;
+  FILE *bookmarkfile;
+
+	uri = geturi(c);
+
+	home = g_get_home_dir();
+	bookmarkpath = g_build_filename(home, surf_dir, bookmark_file, NULL);
+
+  bookmarkfile = g_fopen(bookmarkpath, "a");
+  fprintf(bookmarkfile, "%s\n", uri);
+  fclose(bookmarkfile);
+}
+
+void
 setcookie(char *name, char *val, char *dom, char *path, long exp) {
 
 }
# HG changeset patch
# User Ray Kohler <ataraxia...@gmail.com>
# Date 1252459391 14400
# Node ID bfd6b9370ce3b013db5993c8a49fd47836b12286
# Parent  9bbedc5f48946677ea0a22446fbb8024dd79c3e5
[mq]: config_file_locs

diff --git a/config.def.h b/config.def.h
--- a/config.def.h
+++ b/config.def.h
@@ -1,6 +1,14 @@
 /* modifier 0 means no modifier */
 static gchar *progress       = "#FF0000";
 static gchar *progress_trust = "#00FF00";
+
+/* persistent files and directories */
+/* this one is relative to home directory */
+static const char *surf_dir        = ".surf";
+/* these are relative to surf_dir */
+static const char *download_dir    = "dl";
+static const char *cookie_file     = "cookies";
+
 #define MODKEY GDK_CONTROL_MASK
 static Key keys[] = {
     /* modifier	            keyval      function    arg             Focus */
diff --git a/surf.c b/surf.c
--- a/surf.c
+++ b/surf.c
@@ -224,7 +224,7 @@
 	c->download = o;
 	home = g_get_home_dir();
 	filename = webkit_download_get_suggested_filename(o);
-	path = g_build_filename(home, ".surf", "dl", 
+	path = g_build_filename(home, surf_dir, download_dir, 
 			filename, NULL);
 	uri = g_strconcat("file://", path, NULL);
 	webkit_download_set_destination_uri(c->download, uri);
@@ -524,7 +524,7 @@
 	const gchar *filename, *home;
 
 	home = g_get_home_dir();
-	filename = g_build_filename(home, ".surf", "cookies", NULL);
+	filename = g_build_filename(home, surf_dir, cookie_file, NULL);
 }
 
 void
@@ -658,14 +658,14 @@
 
 	/* make dirs */
 	home = g_get_home_dir();
-	filename = g_build_filename(home, ".surf", NULL);
+	filename = g_build_filename(home, surf_dir, NULL);
 	g_mkdir_with_parents(filename, 0711);
-	filename = g_build_filename(home, ".surf", "dl", NULL);
+	filename = g_build_filename(home, surf_dir, download_dir, NULL);
 	g_mkdir_with_parents(filename, 0755);
 
 	/* cookie persistance */
 	s = webkit_get_default_session();
-	filename = g_build_filename(home, ".surf", "cookies.jar", NULL);
+	filename = g_build_filename(home, surf_dir, cookie_file, NULL);
 	cookiejar = soup_cookie_jar_text_new(filename, FALSE);
 	soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));
 

Reply via email to