From: Daniel Carl Date: Thu, 1 Aug 2013 18:29:35 +0000 (+0200) Subject: Added new command :queue-clear. X-Git-Url: https://git.owens.tech/assets/favicon.png/assets/favicon.png/git?a=commitdiff_plain;h=2426343c12b9fd10c80a059b147d3eca5373a974;p=vimb.git Added new command :queue-clear. --- diff --git a/doc/vimb.1 b/doc/vimb.1 index f9733a7..7ddb19e 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -339,8 +339,11 @@ Push \fIURI\fP or if not given current URI into the queue. .TP .B queue-pop -Open the oldest queue entry -in current browser window and remove it from the queue. +Open the oldest queue entry in current browser window and remove it from the +queue. +.TP +.B queue-clear +Removes all entries from queue. .SS Misc .TP diff --git a/src/bookmark.c b/src/bookmark.c index fdb3992..0edac3e 100644 --- a/src/bookmark.c +++ b/src/bookmark.c @@ -192,6 +192,19 @@ char *bookmark_queue_pop(int *item_count) } return uri; } + +/** + * Removes all contents from the queue file. + */ +gboolean bookmark_queue_clear(void) +{ + FILE *f; + if ((f = fopen(vb.files[FILES_QUEUE], "w"))) { + fclose(f); + return true; + } + return false; +} #endif /* FEATURE_QUEUE */ static GList *load(const char *file) diff --git a/src/bookmark.h b/src/bookmark.h index 5aed68b..c94be30 100644 --- a/src/bookmark.h +++ b/src/bookmark.h @@ -26,6 +26,7 @@ gboolean bookmark_fill_completion(GtkListStore *store, const char *input); #ifdef FEATURE_QUEUE gboolean bookmark_queue_push(const char *uri); char *bookmark_queue_pop(int *item_count); +gboolean bookmark_queue_clear(void); #endif #endif /* end of include guard: _BOOKMARK_H */ diff --git a/src/command.c b/src/command.c index be89c19..59460f2 100644 --- a/src/command.c +++ b/src/command.c @@ -127,6 +127,7 @@ static CommandInfo cmd_list[] = { #ifdef FEATURE_QUEUE {"queue-push", NULL, command_queue, {COMMAND_QUEUE_PUSH}}, {"queue-pop", NULL, command_queue, {COMMAND_QUEUE_POP}}, + {"queue-clear", NULL, command_queue, {COMMAND_QUEUE_CLEAR}}, #endif }; @@ -907,20 +908,28 @@ gboolean command_queue(const Arg *arg) vb_set_mode(VB_MODE_NORMAL, false); - if (arg->i == COMMAND_QUEUE_PUSH) { - res = bookmark_queue_push(arg->s ? arg->s : GET_URI()); - if (res) { - vb_echo(VB_MSG_NORMAL, false, "Pushed to queue"); - } - return res; - } + switch (arg->i) { + case COMMAND_QUEUE_PUSH: + res = bookmark_queue_push(arg->s ? arg->s : GET_URI()); + if (res) { + vb_echo(VB_MSG_NORMAL, false, "Pushed to queue"); + } + break; - /* pop last added url from queue and open it */ - if ((uri = bookmark_queue_pop(&count))) { - res = vb_load_uri(&(Arg){VB_TARGET_CURRENT, uri}); - g_free(uri); + case COMMAND_QUEUE_POP: + if ((uri = bookmark_queue_pop(&count))) { + res = vb_load_uri(&(Arg){VB_TARGET_CURRENT, uri}); + g_free(uri); + } + vb_echo(VB_MSG_NORMAL, false, "Queue length %d", count); + break; + + case COMMAND_QUEUE_CLEAR: + if (bookmark_queue_clear()) { + vb_echo(VB_MSG_NORMAL, false, "Queue cleared"); + } + break; } - vb_echo(VB_MSG_NORMAL, false, "Queue length %d", count); return res; } diff --git a/src/command.h b/src/command.h index 321c76d..3e7672a 100644 --- a/src/command.h +++ b/src/command.h @@ -47,7 +47,8 @@ enum { #ifdef FEATURE_QUEUE enum { COMMAND_QUEUE_PUSH, - COMMAND_QUEUE_POP + COMMAND_QUEUE_POP, + COMMAND_QUEUE_CLEAR }; #endif