diff -r 18dd74d2564d config.def.h
--- a/config.def.h Sat Oct 17 13:19:21 2009 +0200
+++ b/config.def.h Tue Oct 20 14:39:33 2009 +0200
@@ -5,6 +5,7 @@
static char *stylefile = ".surf/style.css";
static char *scriptfile = ".surf/script.js";
static char *cookiefile = ".surf/cookies.txt";
+static char *bmarksfile = ".surf/bmarks.txt";
static char *dldir = ".surf/dl";
static time_t sessiontime = 3600;
@@ -41,6 +42,8 @@
{ "New Window", newwindow, { .v = NULL } },
{ "Reload", reload, { .b = FALSE } },
{ "Stop", stop, { 0 } },
+ { "Bookmark it", addbookmark, { 0 } },
+ { "Show bookmarks", showbmarks,{ 0 } },
{ "<===", navigate, { .i = -1 } },
{ "===>", navigate, { .i = +1 } },
};
diff -r 18dd74d2564d surf.c
--- a/surf.c Sat Oct 17 13:19:21 2009 +0200
+++ b/surf.c Tue Oct 20 14:39:33 2009 +0200
@@ -71,6 +71,7 @@
static char winid[64];
static char *progname;
+static void addbookmark(Client *c, const Arg *arg);
static const char *autouri(Client *c);
static char *buildpath(const char *path);
static void changecookie(SoupCookieJar *jar, SoupCookie *o, SoupCookie *n, gpointer p);
@@ -112,6 +113,7 @@
static void scroll(Client *c, const Arg *arg);
static void searchtext(Client *c, const Arg *arg);
static void source(Client *c, const Arg *arg);
+static void showbmarks(Client *c, const Arg *arg);
static void showsearch(Client *c, const Arg *arg);
static void showuri(Client *c, const Arg *arg);
static void stop(Client *c, const Arg *arg);
@@ -126,6 +128,16 @@
/* configuration, allows nested code to access above variables */
#include "config.h"
+void
+addbookmark(Client *c, const Arg *arg) {
+ char *bmark_uri;
+ FILE *f;
+ bmark_uri = geturi(c);
+ f = fopen(bmarksfile, "a+");
+ fprintf(f, "%s\n", geturi(c));
+ fclose(f);
+}
+
const char *
autouri(Client *c) {
if(GTK_WIDGET_HAS_FOCUS(c->uribar))
@@ -172,6 +184,7 @@
cleanup(void) {
while(clients)
destroyclient(clients);
+ g_free(bmarksfile);
g_free(cookiefile);
g_free(dldir);
g_free(scriptfile);
@@ -686,6 +699,7 @@
uriprop = XInternAtom(dpy, "_SURF_URI", False);
/* create dirs and files */
+ bmarksfile = buildpath(bmarksfile);
cookiefile = buildpath(cookiefile);
dldir = buildpath(dldir);
scriptfile = buildpath(scriptfile);
@@ -699,6 +713,23 @@
}
void
+showbmarks(Client *c, const Arg *arg) {
+ /* I wonder if 4 kB is too much or not enough */
+ char html[4096] = "";
+ /* same here. time will tell */
+ char uri[128];
+ FILE *f;
+ stop(c, NULL);
+ f = fopen(bmarksfile, "r");
+ while(fscanf(f, "%127s\n", uri) != EOF) {
+ snprintf(&html[strlen(html)], sizeof(html) - strlen(html),
+ "%s
", uri, uri);
+ }
+ fclose(f);
+ webkit_web_view_load_html_string(c->view, html, "about:bookmarks");
+}
+
+void
showsearch(Client *c, const Arg *arg) {
hideuri(c, NULL);
gtk_widget_show(c->searchbar);