diff options
author | Marco Peereboom <marco@conformal.com> | 2010-12-26 15:04:40 +0000 |
---|---|---|
committer | Marco Peereboom <marco@conformal.com> | 2010-12-26 15:04:40 +0000 |
commit | b7a81e74d0154eb460e90873fc3822897558ef38 (patch) | |
tree | 0c0489e29e6d552f1edd96ec2700a1e95e04d2b0 | |
parent | 53c724480da724b46d54809689171646bda3c43a (diff) | |
download | xombrero-b7a81e74d0154eb460e90873fc3822897558ef38.tar.gz |
Add save tab support.
fix boneheaded typo from edd Sligthly modified diff from Stevan Andjelkovic <stevan@student.chalmers.se>
-rw-r--r-- | xxxterm.1 | 10 | ||||
-rw-r--r-- | xxxterm.c | 77 |
2 files changed, 86 insertions, 1 deletions
diff --git a/xxxterm.1 b/xxxterm.1 index 9f6bfdf..9aa97af 100644 --- a/xxxterm.1 +++ b/xxxterm.1 @@ -287,6 +287,16 @@ The commands and descriptions are listed below: .It Cm qa, qa!, q! Quit .Nm +.It Cm w +Save open tabs. +The tabs will be restored next time +.Nm +is started. +.It Cm wq, wq! +Save open tabs and quit. +The tabs will be restored next time +.Nm +is started. .It Cm fav Show favorites .It Cm favadd diff --git a/xxxterm.c b/xxxterm.c index 0c636ba..c2eaab2 100644 --- a/xxxterm.c +++ b/xxxterm.c @@ -210,6 +210,7 @@ struct karg { #define XT_DIR (".xxxterm") #define XT_CONF_FILE ("xxxterm.conf") #define XT_FAVS_FILE ("favorites") +#define XT_SAVED_TABS_FILE ("saved_tabs") #define XT_CB_HANDLED (TRUE) #define XT_CB_PASSTHROUGH (FALSE) #define XT_DOCTYPE "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>" @@ -952,6 +953,75 @@ quit(struct tab *t, struct karg *args) } int +restore_saved_tabs(void) +{ + char file[PATH_MAX]; + FILE *f; + char *line = NULL; + size_t linelen; + int empty_saved_tabs_file = 1; + + snprintf(file, sizeof file, "%s/%s/%s", + pwd->pw_dir, XT_DIR, XT_SAVED_TABS_FILE); + + if ((f = fopen(file, "r")) == NULL) + return (empty_saved_tabs_file); + + while (!feof(f)) { + line = fparseln(f, &linelen, NULL, NULL, 0); + if (line) { + create_new_tab(line, 1); + empty_saved_tabs_file = 0; + } + free(line); + line = NULL; + } + + fclose(f); + /*remove(file);*/ + + return (empty_saved_tabs_file); +} + +int +save_tabs(struct tab *t, struct karg *args) +{ + char file[PATH_MAX]; + FILE *f; + struct tab *ti; + WebKitWebFrame *frame; + const gchar *uri; + + snprintf(file, sizeof file, "%s/%s/%s", + pwd->pw_dir, XT_DIR, XT_SAVED_TABS_FILE); + + if ((f = fopen(file, "w")) == NULL) { + warn("save_tabs_and_quit"); + return (1); + } + + TAILQ_FOREACH(ti, &tabs, entry) { + frame = webkit_web_view_get_main_frame(ti->wv); + uri = webkit_web_frame_get_uri(frame); + if (uri) + fprintf(f, "%s\n", uri); + } + + fclose(f); + + return (0); +} + +int +save_tabs_and_quit(struct tab *t, struct karg *args) +{ + save_tabs(t, NULL); + quit(t, NULL); + + return (1); +} + +int toggle_js(struct tab *t, struct karg *args) { int es, i; @@ -1141,7 +1211,7 @@ xtp_page_fl(struct tab *t, struct karg *args) t->xtp_meaning = XT_XTP_TAB_MEANING_FL; /* new session key */ - if (!update_favorite_tabs) + if (!updating_fl_tabs) generate_xtp_session_key(&fl_session_key); /* open favorites */ @@ -2239,6 +2309,9 @@ struct cmd { { "q!", 0, quit, {0} }, { "qa", 0, quit, {0} }, { "qa!", 0, quit, {0} }, + { "w", 0, save_tabs, {0} }, + { "wq", 0, save_tabs_and_quit, {0} }, + { "wq!", 0, save_tabs_and_quit, {0} }, { "help", 0, help, {0} }, { "about", 0, about, {0} }, { "stats", 0, stats, {0} }, @@ -3930,6 +4003,8 @@ main(int argc, char *argv[]) create_canvas(); + focus = restore_saved_tabs(); + while (argc) { create_new_tab(argv[0], focus); focus = 0; |