* along with this program. If not, see http://www.gnu.org/licenses/.
*/
-#include "config.h"
#include "main.h"
+#include "config.h"
#include "util.h"
#include "command.h"
#include "keybind.h"
+#include "setting.h"
/* variables */
VpCore vp;
static void vp_init_gui(void);
static void vp_init_files(void);
static void vp_set_widget_font(GtkWidget* widget, const gchar* font_definition, const gchar* bg_color, const gchar* fg_color);
-static void vp_setup_settings(void);
static void vp_setup_signals(void);
static gboolean vp_load_uri(const Arg* arg);
#ifdef FEATURE_COOKIE
static gboolean vp_process_input(const char* input)
{
gboolean success;
- gchar* line = g_strdup(input);
+ gchar* line = NULL;
gchar* command = NULL;
gchar** token;
return FALSE;
}
+ line = g_strdup(input);
g_strstrip(line);
/* get a possible command count */
return vp_load_uri(arg);
}
+gboolean vp_set(const Arg* arg)
+{
+ gboolean success;
+ gchar* line = NULL;
+ gchar** token;
+
+ if (!arg->s || !strlen(arg->s)) {
+ return FALSE;
+ }
+
+ line = g_strdup(arg->s);
+ g_strstrip(line);
+
+ /* split the input string into paramete and value part */
+ token = g_strsplit(line, "=", 2);
+ g_free(line);
+
+ if (!token[0]) {
+ /* TODO display current value */
+ g_strfreev(token);
+ return FALSE;
+ }
+ success = setting_run(token[0], token[1] ? token[1] : NULL);
+ g_strfreev(token);
+
+ return success;
+}
+
void vp_update_urlbar(const gchar* uri)
{
gchar* markup;
/* initialize the keybindings */
keybind_init();
+ /* initialize settings */
+ setting_init();
+
vp_read_config();
vp.config.cookie_timeout = 4800;
soup_session_remove_feature_by_type(vp.net.soup_session, soup_cookie_jar_get_type());
#endif
- vp_setup_settings();
-
/* Create a scrollable area */
gui->viewport = gtk_scrolled_window_new(gui->adjust_h, gui->adjust_v);
gtk_scrolled_window_set_policy(
gtk_widget_modify_base(widget, GTK_STATE_NORMAL, bg_color ? &bg : NULL);
}
-static void vp_setup_settings(void)
-{
- WebKitWebSettings *settings = webkit_web_view_get_settings(vp.gui.webview);
-
- g_object_set(G_OBJECT(settings), "user-agent", SETTING_USER_AGENT, NULL);
- webkit_web_view_set_settings(vp.gui.webview, settings);
-}
-
static void vp_setup_signals(void)
{
Gui* gui = &vp.gui;
--- /dev/null
+/**
+ * vimp - a webkit based vim like browser.
+ *
+ * Copyright (C) 2012 Daniel Carl
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see http://www.gnu.org/licenses/.
+ */
+
+#include "setting.h"
+#include "util.h"
+
+static gboolean setting_webkit(const Setting* s);
+
+static Setting default_settings[] = {
+ {"auto-load-images", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"auto-shrink-images", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"cursive-font-family", TYPE_CHAR, setting_webkit, {.s = "serif"}},
+ {"cursive-font-family", TYPE_CHAR, setting_webkit, {.s = "serif"}},
+ {"default-encoding", TYPE_CHAR, setting_webkit, {.s = "utf-8"}},
+ {"default-font-family", TYPE_CHAR, setting_webkit, {.s = "sans-serif"}},
+ {"default-font-size", TYPE_INTEGER, setting_webkit, {.i = 12}},
+ {"default-monospace-font-size", TYPE_INTEGER, setting_webkit, {.i = 10}},
+ {"enable-caret-browsing", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-default-context-menu", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"enable-developer-extras", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-dns-prefetching", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"enable-dom-paste", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-frame-flattening", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-file-access-from-file-uris", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"enable-html5-database", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-html5-local-storage", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-java-applet", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-offline-web-application-cache", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-page-cache", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"enable-plugins", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"enable-private-browsing", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-scripts", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"enable-site-specific-quirks", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-spatial-navigation", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-spell-checking", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enable-universal-access-from-file-uris", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"enable-xss-auditor", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"enforce-96-dpi", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"fantasy-font-family", TYPE_CHAR, setting_webkit, {.s = "serif"}},
+ {"javascript-can-access-clipboard", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"javascript-can-open-windows-automatically", TYPE_BOOLEAN, setting_webkit, {.i = 0}},
+ {"minimum-font-size", TYPE_INTEGER, setting_webkit, {.i = 5}},
+ {"minimum-logical-font-size", TYPE_INTEGER, setting_webkit, {.i = 5}},
+ {"monospace-font-family", TYPE_CHAR, setting_webkit, {.s = "monospace"}},
+ {"print-backgrounds", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"resizable-text-areas", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"sans-serif-font-family", TYPE_CHAR, setting_webkit, {.s = "sans-serif"}},
+ {"serif-font-family", TYPE_CHAR, setting_webkit, {.s = "serif"}},
+ {"spell-checking-languages", TYPE_CHAR, setting_webkit, {.s = NULL}},
+ {"tab-key-cycles-through-elements", TYPE_BOOLEAN, setting_webkit, {.i = 1}},
+ {"user-agent", TYPE_CHAR, setting_webkit, {.s = PROJECT "/" VERSION " (X11; Linux i686) AppleWebKit/535.22+ Compatible (Safari)"}},
+ {"user-stylesheet-uri", TYPE_CHAR, setting_webkit, {.s = NULL}},
+ {"zoom-step", TYPE_DOUBLE, setting_webkit, {.i = 100}},
+};
+
+static GHashTable* settings = NULL;
+
+
+void setting_init(void)
+{
+ Setting* s;
+ guint i;
+ settings = g_hash_table_new(g_str_hash, g_str_equal);
+
+ for (i = 0; i < LENGTH(default_settings); i++) {
+ s = &default_settings[i];
+ g_hash_table_insert(settings, (gpointer)s->name, s);
+
+ /* set the default settings */
+ s->func(s);
+ }
+}
+
+gboolean setting_run(const gchar* name, const gchar* param)
+{
+ gboolean result = FALSE;
+ Setting* s = g_hash_table_lookup(settings, name);
+ if (!s) {
+ return FALSE;
+ }
+
+ if (!param) {
+ return s->func(s);
+ }
+
+ /* if string param is given convert it to the required data type and set
+ * it to the arg of the setting */
+ switch (s->type) {
+ case TYPE_BOOLEAN:
+ s->arg.i = util_atob(param) ? 1 : 0;
+ result = s->func(s);
+ break;
+
+ case TYPE_INTEGER:
+ s->arg.i = g_ascii_strtoull(param, (gchar**)NULL, 10);
+ result = s->func(s);
+ break;
+
+ case TYPE_DOUBLE:
+ s->arg.i = (1000 * g_ascii_strtod(param, (gchar**)NULL));
+ result = s->func(s);
+ break;
+
+ case TYPE_CHAR:
+ case TYPE_COLOR:
+ s->arg.s = g_strdup(param);
+ result = s->func(s);
+ g_free(s->arg.s);
+ break;
+ }
+
+ return result;
+}
+
+static gboolean setting_webkit(const Setting* s)
+{
+ WebKitWebSettings* web_setting = webkit_web_view_get_settings(vp.gui.webview);
+
+ switch (s->type) {
+ case TYPE_BOOLEAN:
+ g_object_set(G_OBJECT(web_setting), s->name, s->arg.i ? TRUE : FALSE, NULL);
+ break;
+
+ case TYPE_INTEGER:
+ g_object_set(G_OBJECT(web_setting), s->name, s->arg.i, NULL);
+ break;
+
+ case TYPE_DOUBLE:
+ g_object_set(G_OBJECT(web_setting), s->name, (s->arg.i / 1000.0), NULL);
+ break;
+
+ case TYPE_CHAR:
+ case TYPE_COLOR:
+ g_object_set(G_OBJECT(web_setting), s->name, s->arg.s, NULL);
+ break;
+ }
+ return TRUE;
+}