diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmark.c | 13 | ||||
-rw-r--r-- | src/bookmark.h | 1 | ||||
-rw-r--r-- | src/command.c | 33 | ||||
-rw-r--r-- | src/command.h | 3 |
4 files changed, 37 insertions, 13 deletions
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 |