Added new command :queue-clear.
authorDaniel Carl <danielcarl@gmx.de>
Thu, 1 Aug 2013 18:29:35 +0000 (20:29 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Thu, 1 Aug 2013 18:29:35 +0000 (20:29 +0200)
doc/vimb.1
src/bookmark.c
src/bookmark.h
src/command.c
src/command.h

index f9733a7..7ddb19e 100644 (file)
@@ -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
index fdb3992..0edac3e 100644 (file)
@@ -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)
index 5aed68b..c94be30 100644 (file)
@@ -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 */
index be89c19..59460f2 100644 (file)
@@ -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;
 }
index 321c76d..3e7672a 100644 (file)
@@ -47,7 +47,8 @@ enum {
 #ifdef FEATURE_QUEUE
 enum {
     COMMAND_QUEUE_PUSH,
-    COMMAND_QUEUE_POP
+    COMMAND_QUEUE_POP,
+    COMMAND_QUEUE_CLEAR
 };
 #endif