Removes all bookmarks for given \fIURI\fP or if not given the current opened
page.
+.SS Queue
+The queue allows to mark URLs for later reding (something like a read it later
+list). This list is shared between the single instances of PROJECT.
+.TP
+.BI "push [" URI ]
+Push \fIURI\fP or if not given current URI into the queue.
+.TP
+.B pop
+Open the oldest queue entry in current browser window and remove it from the
+queue.
+
.SS Misc
.TP
.B next, n, prev, p
.RS
Holds the bookmarks saved with command `bookmark-add'.
.RE
+.I $XDG_CONFIG_HOME/PROJECT/queue
+.RS
+Holds the read it later queue filled by `hint-push' or `push'.
+.RE
.I $XDG_CONFIG_HOME/PROJECT/scripts.js
.RS
This file can be used to run user scripts, that are injected into every paged
*/
gboolean bookmark_add(const char *uri, const char *title, const char *tags)
{
- FILE *f;
-
- if ((f = fopen(vb.files[FILES_BOOKMARK], "a+"))) {
- file_lock_set(fileno(f), F_WRLCK);
-
- if (tags) {
- fprintf(f, "%s\t%s\t%s\n", uri, title ? title : "", tags);
- } else if (title) {
- fprintf(f, "%s\t%s\n", uri, title);
- } else {
- fprintf(f, "%s\n", uri);
- }
-
- file_lock_set(fileno(f), F_UNLCK);
- fclose(f);
-
- return true;
+ const char *file = vb.files[FILES_BOOKMARK];
+ if (tags) {
+ return util_file_append(file, "%s\t%s\t%s\n", uri, title ? title : "", tags);
+ }
+ if (title) {
+ return util_file_append(file, "%s\t%s\n", uri, title);
}
- return false;
+ return util_file_append(file, "%s\n", uri);
}
gboolean bookmark_remove(const char *uri)
return found;
}
+/**
+ * Push a uri to the end of the queue.
+ *
+ * @uri: URI to put into the queue
+ */
+gboolean bookmark_queue_push(const char *uri)
+{
+ return util_file_append(vb.files[FILES_QUEUE], "%s\n", uri);
+}
+
+/**
+ * Retrieves the oldest entry from queue.
+ * Retruned uri must be freed with g_free.
+ */
+char *bookmark_queue_pop(void)
+{
+ int len, i;
+ char **lines, *uri = NULL;
+
+ lines = util_get_lines(vb.files[FILES_QUEUE]);
+ if (lines && (len = g_strv_length(lines))) {
+ GString *new = g_string_new(NULL);
+
+ uri = g_strdup(lines[0]);
+ /* don't process last empty line */
+ len -= 1;
+ /* skip the first list that should be removed */
+ for (i = 1; i < len; i++) {
+ g_string_append_printf(new, "%s\n", lines[i]);
+ }
+ g_strfreev(lines);
+ g_file_set_contents(vb.files[FILES_QUEUE], new->str, -1, NULL);
+ g_string_free(new, true);
+ }
+ return uri;
+}
+
static GList *load(const char *file)
{
return util_file_to_unique_list(
gboolean bookmark_add(const char *uri, const char *title, const char *tags);
gboolean bookmark_remove(const char *uri);
gboolean bookmark_fill_completion(GtkListStore *store, const char *input);
+gboolean bookmark_queue_push(const char *uri);
+char *bookmark_queue_pop(void);
#endif /* end of include guard: _BOOKMARK_H */
{"descent!", NULL, command_descent, {1}},
{"save", NULL, command_save, {COMMAND_SAVE_CURRENT}},
{"shellcmd", NULL, command_shellcmd, {0}},
+ {"push", NULL, command_queue, {COMMAND_QUEUE_PUSH}},
+ {"pop", NULL, command_queue, {COMMAND_QUEUE_POP}},
};
static void editor_resume(GPid pid, int status, OpenEditorData *data);
if (!arg->i) {
if (bookmark_remove(arg->s ? arg->s : GET_URI())) {
- vb_echo_force(VB_MSG_NORMAL, false, "Bookmark removed");
+ vb_echo_force(VB_MSG_NORMAL, false, " Bookmark removed");
return true;
}
} else if (bookmark_add(GET_URI(), webkit_web_view_get_title(vb.gui.webview), arg->s)) {
- vb_echo_force(VB_MSG_NORMAL, false, "Bookmark added");
+ vb_echo_force(VB_MSG_NORMAL, false, " Bookmark added");
return true;
}
return false;
}
+gboolean command_queue(const Arg *arg)
+{
+ gboolean res = false;
+ char *uri;
+
+ 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;
+ }
+
+ /* pop last added url from queue and open it */
+ if ((uri = bookmark_queue_pop())) {
+ res = vb_load_uri(&(Arg){VB_TARGET_CURRENT, uri});
+ g_free(uri);
+ } else {
+ vb_echo(VB_MSG_NORMAL, false, " Queue is empty");
+ }
+ return res;
+}
+
gboolean command_editor(const Arg *arg)
{
char *file_path = NULL;
COMMAND_SAVE_URI
};
+enum {
+ COMMAND_QUEUE_PUSH,
+ COMMAND_QUEUE_POP
+};
+
typedef gboolean (*Command)(const Arg *arg);
void command_init(void);
gboolean command_descent(const Arg *arg);
gboolean command_save(const Arg *arg);
gboolean command_shellcmd(const Arg *arg);
+gboolean command_queue(const Arg *arg);
#endif /* end of include guard: _COMMAND_H */
*/
void history_add(HistoryType type, const char *value, const char *additional)
{
- FILE *f;
const char *file = get_file_by_type(type);
- if ((f = fopen(file, "a+"))) {
- file_lock_set(fileno(f), F_WRLCK);
- if (additional) {
- fprintf(f, "%s\t%s\n", value, additional);
- } else {
- fprintf(f, "%s\n", value);
- }
-
- file_lock_set(fileno(f), F_UNLCK);
- fclose(f);
+ if (additional) {
+ util_file_append(file, "%s\t%s\n", value, additional);
}
+ util_file_append(file, "%s\n", value);
}
/**
vb.files[FILES_BOOKMARK] = g_build_filename(path, "bookmark", NULL);
util_create_file_if_not_exists(vb.files[FILES_BOOKMARK]);
+ vb.files[FILES_QUEUE] = g_build_filename(path, "queue", NULL);
+ util_create_file_if_not_exists(vb.files[FILES_QUEUE]);
+
vb.files[FILES_SCRIPT] = g_build_filename(path, "scripts.js", NULL);
vb.files[FILES_USER_STYLE] = g_build_filename(path, "style.css", NULL);
FILES_COMMAND,
FILES_SEARCH,
FILES_BOOKMARK,
+ FILES_QUEUE,
FILES_USER_STYLE,
FILES_LAST
} VbFile;
return gl;
}
+/**
+ * Append new data to file.
+ *
+ * @file: File to appen the data
+ * @format: Format string used to process va_list
+ */
+gboolean util_file_append(const char *file, const char *format, ...)
+{
+ va_list args;
+ FILE *f;
+
+ if ((f = fopen(file, "a+"))) {
+ file_lock_set(fileno(f), F_WRLCK);
+
+ va_start(args, format);
+ vfprintf(f, format, args);
+ va_end(args);
+
+ file_lock_set(fileno(f), F_UNLCK);
+ fclose(f);
+
+ return true;
+ }
+ return false;
+}
+
char *util_strcasestr(const char *haystack, const char *needle)
{
unsigned char c1, c2;
char** util_get_lines(const char* filename);
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, ...);
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);