New command allows to push new uri to the beginning of read it later list.
available if PROJECT has been compiled with QUEUE feature.
.TP
.BI "queue-push [" URI ]
-Push \fIURI\fP or if not given
-current URI into the queue.
+Push \fIURI\fP or if not given current URI to the end of the queue.
+.TP
+.BI "queue-unshift [" URI ]
+Push \fIURI\fP or if not given current URI to the beginning of the queue.
.TP
.B queue-pop
Open the oldest queue entry in current browser window and remove it from the
return util_file_append(vb.files[FILES_QUEUE], "%s\n", uri);
}
+/**
+ * Push a uri to the bginning of the queue.
+ *
+ * @uri: URI to put into the queue
+ */
+gboolean bookmark_queue_unshift(const char *uri)
+{
+ return util_file_prepend(vb.files[FILES_QUEUE], "%s\n", uri);
+}
+
/**
* Retrieves the oldest entry from queue.
*
gboolean bookmark_fill_completion(GtkListStore *store, const char *input);
#ifdef FEATURE_QUEUE
gboolean bookmark_queue_push(const char *uri);
+gboolean bookmark_queue_unshift(const char *uri);
char *bookmark_queue_pop(int *item_count);
gboolean bookmark_queue_clear(void);
#endif
{"shellcmd", NULL, command_shellcmd, {0}},
#ifdef FEATURE_QUEUE
{"queue-push", NULL, command_queue, {COMMAND_QUEUE_PUSH}},
+ {"queue-unshift", NULL, command_queue, {COMMAND_QUEUE_UNSHIFT}},
{"queue-pop", NULL, command_queue, {COMMAND_QUEUE_POP}},
{"queue-clear", NULL, command_queue, {COMMAND_QUEUE_CLEAR}},
#endif
}
break;
+ case COMMAND_QUEUE_UNSHIFT:
+ res = bookmark_queue_unshift(arg->s ? arg->s : GET_URI());
+ if (res) {
+ vb_echo(VB_MSG_NORMAL, false, "Pushed to queue");
+ }
+ break;
+
case COMMAND_QUEUE_POP:
if ((uri = bookmark_queue_pop(&count))) {
res = vb_load_uri(&(Arg){VB_TARGET_CURRENT, uri});
#ifdef FEATURE_QUEUE
enum {
COMMAND_QUEUE_PUSH,
+ COMMAND_QUEUE_UNSHIFT,
COMMAND_QUEUE_POP,
COMMAND_QUEUE_CLEAR
};
return false;
}
+/**
+ * Prepend new data to file.
+ *
+ * @file: File to prepend the data
+ * @format: Format string used to process va_list
+ */
+gboolean util_file_prepend(const char *file, const char *format, ...)
+{
+ gboolean res = false;
+ va_list args;
+ char *content;
+ FILE *f;
+
+ content = util_get_file_contents(file, NULL);
+ if ((f = fopen(file, "w"))) {
+ file_lock_set(fileno(f), F_WRLCK);
+
+ va_start(args, format);
+ /* write new content to the file */
+ vfprintf(f, format, args);
+ va_end(args);
+
+ /* append previous file content */
+ fputs(content, f);
+
+ file_lock_set(fileno(f), F_UNLCK);
+ fclose(f);
+
+ res = true;
+ }
+ g_free(content);
+
+ return res;
+}
+
char *util_strcasestr(const char *haystack, const char *needle)
{
unsigned char c1, c2;
GList *util_file_to_unique_list(const char *filename, Util_Content_Func func,
GCompareFunc unique_func, GDestroyNotify free_func, unsigned int max_items);
gboolean util_file_append(const char *file, const char *format, ...);
+gboolean util_file_prepend(const char *file, const char *format, ...);
char* util_strcasestr(const char* haystack, const char* needle);
char *util_str_replace(const char* search, const char* replace, const char* string);
gboolean util_create_tmp_file(const char *content, char **file);