static const char* vp_get_cookies(SoupURI *uri);
static gboolean vp_hide_message(void);
static void vp_set_status(const StatusType status);
+static void vp_save_url_history(const char* url, const char* title);
static void vp_webview_progress_cb(WebKitWebView* view, GParamSpec* pspec, gboolean download)
{
vp_update_statusbar();
dom_check_auto_insert();
+
+ vp_save_url_history(uri, webkit_web_view_get_title(vp.gui.webview));
break;
case WEBKIT_LOAD_FAILED:
}
}
+static void vp_save_url_history(const char* url, const char* title)
+{
+ FILE* f = NULL;
+ char buf[512] = {0};
+ char* new = NULL;
+ guint max = core.config.max_history_items;
+ f = fopen(core.files[FILES_HISTORY], "r");
+ if (!f) {
+ return;
+ }
+
+ char* title_escaped = g_shell_quote(title ? title : "");
+ char* new_item = g_strdup_printf("%s %s\n", url, title);
+ gint n = strlen(new_item);
+ g_free(title_escaped);
+
+ new = g_new0(char, max * sizeof(buf));
+ /* put the new entry to the top */
+ strncpy(new, new_item, n);
+
+ for (guint i = 1; i < max && fgets(buf, sizeof(buf), f); i++) {
+ if (strncmp(new_item, buf, n) != 0) {
+ strncat(new, buf, sizeof(buf));
+ }
+ }
+ fclose(f);
+
+ f = fopen(core.files[FILES_HISTORY], "w");
+ if (!f) {
+ g_free(new);
+
+ return;
+ }
+ fprintf(f, "%s", new);
+ g_free(new);
+
+ fclose(f);
+}
+
/**
* Set the base modes. All other mode flags like completion can be set directly
* to vp.state.mode.
{NULL, "home-page", TYPE_CHAR, setting_home_page, {.s = "https://github.com/fanglingsu/vimp"}},
{NULL, "download-path", TYPE_CHAR, setting_download_path, {.s = "/tmp/vimp"}},
{NULL, "stylesheet", TYPE_BOOLEAN, setting_user_style, {.i = 1}},
- {NULL, "history-max-items", TYPE_INTEGER, setting_history_max_items, {.i = 100}},
+ {NULL, "history-max-items", TYPE_INTEGER, setting_history_max_items, {.i = 500}},
};