Added new files for history and user stylesheets.
authorDaniel Carl <danielcarl@gmx.de>
Sun, 3 Mar 2013 12:36:22 +0000 (13:36 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 3 Mar 2013 12:36:22 +0000 (13:36 +0100)
src/main.c
src/main.h
src/setting.c

index 4906bd9..3874c34 100644 (file)
@@ -409,7 +409,7 @@ void vp_clean_up(void)
         g_file_set_contents(core.files[FILES_CLOSED], uri, -1, NULL);
     }
 
-    for (int i = FILES_FIRST; i < FILES_LAST; i++) {
+    for (int i = 0; i < FILES_LAST; i++) {
         g_free(core.files[i]);
     }
     command_cleanup();
@@ -807,6 +807,12 @@ static void vp_init_files(void)
 
     core.files[FILES_SCRIPT] = g_build_filename(path, "scripts.js", NULL);
 
+    core.files[FILES_HISTORY] = g_build_filename(path, "history", NULL);
+    util_create_file_if_not_exists(core.files[FILES_HISTORY]);
+
+    core.files[FILES_USER_STYLE] = g_build_filename(path, "style.css", NULL);
+    util_create_file_if_not_exists(core.files[FILES_USER_STYLE]);
+
     g_free(path);
 }
 
index 7e152e9..4b5fdd8 100644 (file)
@@ -161,11 +161,12 @@ typedef enum {
 } CompletionStyle;
 
 enum {
-    FILES_FIRST = 0,
-    FILES_CONFIG = 0,
+    FILES_CONFIG,
     FILES_COOKIE,
     FILES_CLOSED,
     FILES_SCRIPT,
+    FILES_HISTORY,
+    FILES_USER_STYLE,
     FILES_LAST
 };
 
@@ -253,6 +254,7 @@ typedef struct {
     guint  max_completion_items;
     char*  home_page;
     char*  download_dir;
+    guint  max_history_items;
 } Config;
 
 typedef struct {
index 38e6898..dcd9c7d 100644 (file)
@@ -36,6 +36,8 @@ static gboolean setting_ca_bundle(const Setting* s, const SettingType type);
 static gboolean setting_home_page(const Setting* s, const SettingType type);
 static gboolean setting_download_path(const Setting* s, const SettingType type);
 static gboolean setting_proxy(const Setting* s, const SettingType type);
+static gboolean setting_user_style(const Setting* s, const SettingType type);
+static gboolean setting_history_max_items(const Setting* s, const SettingType type);
 
 static Setting default_settings[] = {
     /* webkit settings */
@@ -80,7 +82,6 @@ static Setting default_settings[] = {
     {"spelllang", "spell-checking-languages", TYPE_CHAR, setting_webkit, {.s = NULL}},
     {NULL, "tab-key-cycles-through-elements", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
     {"useragent", "user-agent", TYPE_CHAR, setting_webkit, {.s = "vimp/" VERSION " (X11; Linux i686) AppleWebKit/535.22+ Compatible (Safari)"}},
-    {"stylesheet", "user-stylesheet-uri", TYPE_CHAR, setting_webkit, {.s = NULL}},
     {"zoomstep", "zoom-step", TYPE_FLOAT, setting_webkit, {.i = 100000}},
     /* internal variables */
     {NULL, "proxy", TYPE_BOOLEAN, setting_proxy, {.i = 1}},
@@ -118,6 +119,8 @@ static Setting default_settings[] = {
     {NULL, "ca-bundle", TYPE_CHAR, setting_ca_bundle, {.s = "/etc/ssl/certs/ca-certificates.crt"}},
     {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}},
 };
 
 
@@ -661,3 +664,51 @@ static gboolean setting_proxy(const Setting* s, const SettingType type)
 
     return TRUE;
 }
+
+static gboolean setting_user_style(const Setting* s, const SettingType type)
+{
+    gboolean enabled = FALSE;
+    char* uri = NULL;
+    WebKitWebSettings* web_setting = webkit_web_view_get_settings(vp.gui.webview);
+    if (type != SETTING_SET) {
+        g_object_get(web_setting, "user-stylesheet-uri", &uri, NULL);
+        enabled = (uri != NULL);
+
+        if (type == SETTING_GET) {
+            setting_print_value(s, &enabled);
+
+            return TRUE;
+        }
+    }
+
+    if (type == SETTING_TOGGLE) {
+        enabled = !enabled;
+        /* print the new value */
+        setting_print_value(s, &enabled);
+    } else {
+        enabled = s->arg.i;
+    }
+
+    if (enabled) {
+        uri = g_strconcat("file://", core.files[FILES_USER_STYLE], NULL);
+        g_object_set(web_setting, "user-stylesheet-uri", uri, NULL);
+        g_free(uri);
+    } else {
+        g_object_set(web_setting, "user-stylesheet-uri", NULL, NULL);
+    }
+
+    return TRUE;
+}
+
+static gboolean setting_history_max_items(const Setting* s, const SettingType type)
+{
+    if (type == SETTING_GET) {
+        setting_print_value(s, &core.config.max_history_items);
+
+        return TRUE;
+    }
+
+    core.config.max_history_items = s->arg.i;
+
+    return TRUE;
+}