aboutsummaryrefslogtreecommitdiffhomepage
path: root/uzbl.c
diff options
context:
space:
mode:
Diffstat (limited to 'uzbl.c')
-rw-r--r--uzbl.c524
1 files changed, 312 insertions, 212 deletions
diff --git a/uzbl.c b/uzbl.c
index 1cfd1e7..c60487d 100644
--- a/uzbl.c
+++ b/uzbl.c
@@ -1,3 +1,4 @@
+/* -*- c-basic-offset: 4; */
// Original code taken from the example webkit-gtk+ application. see notice below.
// Modified code is licensed under the GPL 3. See LICENSE file.
@@ -30,42 +31,52 @@
#define LENGTH(x) (sizeof x / sizeof x[0])
+#define MAX_BINDINGS 256
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkkeysyms.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/un.h>
#include <webkit/webkit.h>
#include <stdio.h>
#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
-#include <sys/types.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <libsoup/soup.h>
+#include "uzbl.h"
/* housekeeping / internal variables */
-static GtkWidget* main_window;
-static GtkWidget* mainbar;
-static GtkWidget* mainbar_label;
+static GtkWidget* main_window;
+static GtkWidget* mainbar;
+static GtkWidget* mainbar_label;
+static GtkScrollbar* scbar_v; // Horizontal and Vertical Scrollbar
+static GtkScrollbar* scbar_h; // (These are still hidden)
+static GtkAdjustment* bar_v; // Information about document length
+static GtkAdjustment* bar_h; // and scrolling position
static WebKitWebView* web_view;
-static gchar* main_title;
-static gchar selected_url[500] = "\0";
-static gint load_progress;
-static Window xwin = 0;
-static char fifo_path[64];
-static char socket_path[108];
+static gchar* main_title;
+static gchar selected_url[500] = "\0";
+static gint load_progress;
+static Window xwin = 0;
+static char fifo_path[64];
+static char socket_path[108];
+static char executable_path[500];
+static GString* keycmd;
/* state variables (initial values coming from command line arguments but may be changed later) */
-static gchar* instance_name = NULL;
-static gchar* uri = NULL;
-static gboolean verbose = FALSE;
-static gchar* config_file = NULL;
+static gchar* uri = NULL;
+static gchar* config_file = NULL;
static gchar config_file_path[500];
+static gboolean verbose = FALSE;
+static gchar* instance_name = NULL;
/* settings from config: group behaviour */
static gchar* history_handler = NULL;
@@ -78,56 +89,37 @@ static gboolean insert_mode = FALSE;
static gboolean status_top = FALSE;
static gchar* modkey = NULL;
static guint modmask = 0;
-static gchar* home_page = NULL;
-
-/* settings from config: group bindings_internal */
-static GHashTable *internal_bindings;
+static guint http_debug = 0;
-/* settings from config: group bindings_external */
-static GHashTable *external_bindings;
+/* settings from config: group bindings, key -> action */
+static GHashTable* bindings;
-/* command list */
-static GHashTable *commands;
+/* command list: name -> Command */
+static GHashTable* commands;
/* commandline arguments (set initial values for the state variables) */
static GOptionEntry entries[] =
{
- { "uri", 'u', 0, G_OPTION_ARG_STRING, &uri, "Uri to load", NULL },
- { "name", 'n', 0, G_OPTION_ARG_STRING, &instance_name, "Name of the current instance", NULL },
- { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
- { "config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Config file", NULL },
+ { "uri", 'u', 0, G_OPTION_ARG_STRING, &uri, "Uri to load", NULL },
+ { "name", 'n', 0, G_OPTION_ARG_STRING, &instance_name, "Name of the current instance", NULL },
+ { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
+ { "config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Config file", NULL },
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
-/* for internal list of commands */
-typedef struct
-{
- gpointer command;
- void (*func_1_param)(WebKitWebView*);
- void (*func_2_params)(WebKitWebView*, const gchar *);
-} Command;
+typedef void (*Command)(WebKitWebView*, const char *);
/* XDG stuff */
-char *XDG_CONFIG_HOME_default[256];
-char *XDG_CONFIG_DIRS_default = "/etc/xdg";
+static char *XDG_CONFIG_HOME_default[256];
+static char *XDG_CONFIG_DIRS_default = "/etc/xdg";
-static void
-update_title (GtkWindow* window);
-
-static void
-load_uri ( WebKitWebView * web_view, const gchar * uri);
-
-static void
-new_window_load_uri (const gchar * uri);
-
-static void
-go_home ( WebKitWebView * web_view);
-
-static void
-close_uzbl ( WebKitWebView * web_view);
-
-static gboolean
-run_command(const char *command, const char *args);
+/* libsoup stuff - proxy and friends; networking aptions actually */
+static SoupSession *soup_session;
+static SoupLogger *soup_logger;
+static char *proxy_url = NULL;
+static char *useragent = NULL;
+static gint max_conns;
+static gint max_conns_host;
/* --- UTILITY FUNCTIONS --- */
void
@@ -195,28 +187,44 @@ download_cb (WebKitWebView *web_view, GObject *download, gpointer user_data) {
return (FALSE);
}
+/* scroll a bar in a given direction */
static void
-go_back_cb (WebKitWebView* page) {
+scroll (GtkAdjustment* bar, const char *param) {
+ gdouble amount;
+ gchar *end;
+
+ amount = g_ascii_strtod(param, &end);
+
+ if (*end)
+ fprintf(stderr, "found something after double: %s\n", end);
+
+ gtk_adjustment_set_value (bar, gtk_adjustment_get_value(bar)+amount);
+}
+
+static void scroll_vert(WebKitWebView* page, const char *param) {
(void) page;
- webkit_web_view_go_back (web_view);
+
+ scroll(bar_v, param);
}
-static void
-go_forward_cb (WebKitWebView* page) {
+static void scroll_horz(WebKitWebView* page, const char *param) {
(void) page;
- webkit_web_view_go_forward (web_view);
+
+ scroll(bar_h, param);
}
static void
-toggle_status_cb (WebKitWebView* page) {
- (void) page;
+toggle_status_cb (WebKitWebView* page, const char *param) {
+ (void)page;
+ (void)param;
+
if (show_status) {
- gtk_widget_hide(mainbar);
+ gtk_widget_hide(mainbar);
} else {
- gtk_widget_show(mainbar);
+ gtk_widget_show(mainbar);
}
show_status = !show_status;
- update_title (GTK_WINDOW (main_window));
+ update_title();
}
static void
@@ -229,7 +237,7 @@ link_hover_cb (WebKitWebView* page, const gchar* title, const gchar* link, gpoin
if (link) {
strcpy (selected_url, link);
}
- update_title (GTK_WINDOW (main_window));
+ update_title();
}
static void
@@ -240,7 +248,7 @@ title_change_cb (WebKitWebView* web_view, WebKitWebFrame* web_frame, const gchar
if (main_title)
g_free (main_title);
main_title = g_strdup (title);
- update_title (GTK_WINDOW (main_window));
+ update_title();
}
static void
@@ -248,7 +256,7 @@ progress_change_cb (WebKitWebView* page, gint progress, gpointer data) {
(void) page;
(void) data;
load_progress = progress;
- update_title (GTK_WINDOW (main_window));
+ update_title();
}
static void
@@ -277,45 +285,78 @@ log_history_cb () {
timeinfo = localtime ( &rawtime );
strftime (date, 80, "%Y-%m-%d %H:%M:%S", timeinfo);
GString* args = g_string_new ("");
- g_string_printf (args, "'%s' '%s' '%s'", uri, "TODO:page title here", date);
+ g_string_printf (args, "'%s'", date);
run_command(history_handler, args->str);
g_string_free (args, TRUE);
}
}
-
+
+/* VIEW funcs (little webkit wrappers) */
+
+#define VIEWFUNC(name) static void view_##name(WebKitWebView *page, const char *param){(void)param; webkit_web_view_##name(page);}
+VIEWFUNC(reload)
+VIEWFUNC(stop_loading)
+VIEWFUNC(zoom_in)
+VIEWFUNC(zoom_out)
+VIEWFUNC(go_back)
+VIEWFUNC(go_forward)
+#undef VIEWFUNC
+
/* -- command to callback/function map for things we cannot attach to any signals */
-// TODO: reload, home, quit
+// TODO: reload
-static Command cmdlist[] =
+static struct {char *name; Command command;} cmdlist[] =
{
- { "back", &go_back_cb, NULL },
- { "forward", &go_forward_cb, NULL },
- { "refresh", &webkit_web_view_reload, NULL }, //Buggy
- { "stop", &webkit_web_view_stop_loading, NULL },
- { "zoom_in", &webkit_web_view_zoom_in, NULL }, //Can crash (when max zoom reached?).
- { "zoom_out", &webkit_web_view_zoom_out, NULL },
- { "uri", (void *) NULL, &load_uri },
- { "toggle_status", &toggle_status_cb, NULL },
- { "home" , &go_home, NULL },
- { "exit" , &close_uzbl, NULL },
- { NULL, NULL, NULL }
-//{ "get uri", &webkit_web_view_get_uri},
+ { "back", view_go_back },
+ { "forward", view_go_forward },
+ { "scroll_vert", scroll_vert },
+ { "scroll_horz", scroll_horz },
+ { "reload", view_reload, }, //Buggy
+ { "refresh", view_reload, }, /* for convenience, will change */
+ { "stop", view_stop_loading, },
+ { "zoom_in", view_zoom_in, }, //Can crash (when max zoom reached?).
+ { "zoom_out", view_zoom_out, },
+ { "uri", load_uri },
+ { "toggle_status", toggle_status_cb },
+ { "spawn", spawn },
+ { "exit", close_uzbl },
+ { "insert_mode", set_insert_mode }
};
static void
commands_hash(void)
{
- unsigned int i = 0;
- commands = g_hash_table_new(g_str_hash, g_str_equal);
-
- while(cmdlist[i].command != NULL){
- g_hash_table_insert(commands, cmdlist[i].command, &cmdlist[i]);
- i++;
- }
+ unsigned int i;
+ commands = g_hash_table_new(g_str_hash, g_str_equal);
+
+ for (i = 0; i < LENGTH(cmdlist); i++)
+ g_hash_table_insert(commands, cmdlist[i].name, cmdlist[i].command);
}
/* -- CORE FUNCTIONS -- */
+void
+free_action(gpointer act) {
+ Action *action = (Action*)act;
+ g_free(action->name);
+ if (action->param)
+ g_free(action->param);
+ g_free(action);
+}
+
+Action*
+new_action(const gchar *name, const gchar *param) {
+ Action *action = g_new(Action, 1);
+
+ action->name = g_strdup(name);
+ if (param)
+ action->param = g_strdup(param);
+ else
+ action->param = NULL;
+
+ return action;
+}
+
static bool
file_exists (const char * filename) {
FILE *file = fopen (filename, "r");
@@ -326,11 +367,20 @@ file_exists (const char * filename) {
return false;
}
+void
+set_insert_mode(WebKitWebView *page, const gchar *param) {
+ (void)page;
+ (void)param;
+
+ insert_mode = TRUE;
+ update_title();
+}
+
static void
-load_uri (WebKitWebView * web_view, const gchar * uri) {
- if (uri != NULL) {
- GString* newuri = g_string_new (uri);
- if (g_strrstr (uri, "://") == NULL)
+load_uri (WebKitWebView * web_view, const gchar *param) {
+ if (param) {
+ GString* newuri = g_string_new (param);
+ if (g_strrstr (param, "://") == NULL)
g_string_prepend (newuri, "http://");
webkit_web_view_load_uri (web_view, newuri->str);
g_string_free (newuri, TRUE);
@@ -340,33 +390,25 @@ load_uri (WebKitWebView * web_view, const gchar * uri) {
static void
new_window_load_uri (const gchar * uri) {
GString* to_execute = g_string_new ("");
- if (!config_file) {
- g_string_printf (to_execute, "uzbl --uri '%s'", uri);
- } else {
- g_string_printf (to_execute, "uzbl --uri '%s' --config '%s'", uri, config_file);
- }
- printf("Spawning %s\n",to_execute->str);
- if (!g_spawn_command_line_async (to_execute->str, NULL)) {
- if (!config_file) {
- g_string_printf (to_execute, "./uzbl --uri '%s'", uri);
- } else {
- g_string_printf (to_execute, "./uzbl --uri '%s' --config '%s'", uri, config_file);
+ g_string_append_printf (to_execute, "%s --uri '%s'", executable_path, uri);
+ int i;
+ for (i = 0; entries[i].long_name != NULL; i++) {
+ if ((entries[i].arg == G_OPTION_ARG_STRING) && (strcmp(entries[i].long_name,"uri")!=0)) {
+ gchar** str = (gchar**)entries[i].arg_data;
+ if (*str!=NULL) {
+ g_string_append_printf (to_execute, " --%s '%s'", entries[i].long_name, *str);
+ }
}
- printf("Spawning %s\n",to_execute->str);
- g_spawn_command_line_async (to_execute->str, NULL);
}
+ printf("\n%s\n", to_execute->str);
+ g_spawn_command_line_async (to_execute->str, NULL);
g_string_free (to_execute, TRUE);
}
static void
-go_home (WebKitWebView * web_view) {
- if (home_page)
- webkit_web_view_load_uri (web_view, home_page);
-}
-
-static void
-close_uzbl (WebKitWebView * web_view) {
- (void) web_view;
+close_uzbl (WebKitWebView *page, const char *param) {
+ (void)page;
+ (void)param;
gtk_main_quit ();
}
@@ -377,6 +419,7 @@ run_command(const char *command, const char *args) {
GString* to_execute = g_string_new ("");
gboolean result;
g_string_printf (to_execute, "%s '%s' '%i' '%i' '%s' '%s'", command, config_file, (int) getpid() , (int) xwin, fifo_path, socket_path);
+ g_string_append_printf (to_execute, " '%s' '%s'", uri, "TODO title here");
if(args) {
g_string_append_printf (to_execute, " %s", args);
}
@@ -387,35 +430,35 @@ run_command(const char *command, const char *args) {
}
static void
-parse_command(const char *cmd) {
- Command *c = NULL;
- char buffer[512];
- strcpy (buffer, cmd);
- char * saveptr;
- char * command_name = strtok_r (buffer, " ", &saveptr);
- gchar * command_param = strtok_r (NULL, " ,", &saveptr);
-
- if((c = g_hash_table_lookup(commands, command_name)) != NULL){
- if (c->func_2_params != NULL) {
- if (command_param != NULL) {
- printf ("command executing: \"%s %s\"\n", command_name, command_param);
- c->func_2_params (web_view, command_param);
- } else {
- if (c->func_1_param != NULL) {
- printf ("command executing: \"%s\"\n", command_name);
- c->func_1_param (web_view);
- } else
- fprintf (stderr, "command needs a parameter. \"%s\" is not complete\n", command_name);
- }
- } else if (c->func_1_param != NULL) {
- printf ("command executing: \"%s\"\n", command_name);
- c->func_1_param (web_view);
- }
- } else
+spawn(WebKitWebView *web_view, const char *param) {
+ (void)web_view;
+ run_command(param, NULL);
+}
+
+static void
+parse_command(const char *cmd, const char *param) {
+ Command c;
+
+ if ((c = g_hash_table_lookup(commands, cmd)))
+ c(web_view, param);
+ else
fprintf (stderr, "command \"%s\" not understood. ignoring.\n", cmd);
+}
+
+static void
+parse_line(char *line) {
+ gchar **parts;
+
+ g_strstrip(line);
- if(cmd)
- free(cmd);
+ parts = g_strsplit(line, " ", 2);
+
+ if (!parts)
+ return;
+
+ parse_command(parts[0], parts[1]);
+
+ g_strfreev(parts);
}
enum { FIFO, SOCKET};
@@ -449,15 +492,11 @@ build_stream_name(int type) {
static void
control_fifo(GIOChannel *fd) {
gchar *ctl_line;
- gsize ctl_line_length, term_pos;
-
if(!fd)
return;
-
- g_io_channel_read_line(fd, &ctl_line, &ctl_line_length, &term_pos, NULL); //TODO: support partial writes
- ctl_line[term_pos] ='\0';
- parse_command(ctl_line);
-
+ g_io_channel_read_line(fd, &ctl_line, NULL, NULL, NULL);
+ parse_line(ctl_line);
+ g_free(ctl_line);
return;
}
@@ -514,7 +553,7 @@ control_socket(GIOChannel *chan) {
close (clientsock);
ctl_line = estrdup(buffer);
- parse_command (ctl_line);
+ parse_line (ctl_line);
}
return;
@@ -550,7 +589,7 @@ create_socket() {
}
static void
-update_title (GtkWindow* window) {
+update_title (void) {
GString* string_long = g_string_new ("");
GString* string_short = g_string_new ("");
char* iname = NULL;
@@ -566,10 +605,13 @@ update_title (GtkWindow* window) {
free(iname);
}
+ g_string_append_printf(string_long, "%s ", keycmd->str);
if (!always_insert_mode)
g_string_append (string_long, (insert_mode ? "[I] " : "[C] "));
- g_string_append (string_long, main_title);
- g_string_append (string_short, main_title);
+ if (main_title) {
+ g_string_append (string_long, main_title);
+ g_string_append (string_short, main_title);
+ }
g_string_append (string_long, " - Uzbl browser");
g_string_append (string_short, " - Uzbl browser");
if (load_progress < 100)
@@ -583,10 +625,10 @@ update_title (GtkWindow* window) {
gchar* title_short = g_string_free (string_short, FALSE);
if (show_status) {
- gtk_window_set_title (window, title_short);
- gtk_label_set_text(GTK_LABEL(mainbar_label), title_long);
+ gtk_window_set_title (GTK_WINDOW(main_window), title_short);
+ gtk_label_set_text(GTK_LABEL(mainbar_label), title_long);
} else {
- gtk_window_set_title (window, title_long);
+ gtk_window_set_title (GTK_WINDOW(main_window), title_long);
}
g_free (title_long);
@@ -596,38 +638,45 @@ update_title (GtkWindow* window) {
static gboolean
key_press_cb (WebKitWebView* page, GdkEventKey* event)
{
+ //TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
+
(void) page;
- gpointer act;
- gboolean result=FALSE; //TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.
+ Action *action;
+
if (event->type != GDK_KEY_PRESS || event->keyval == GDK_Page_Up || event->keyval == GDK_Page_Down
|| event->keyval == GDK_Up || event->keyval == GDK_Down || event->keyval == GDK_Left || event->keyval == GDK_Right)
- return result;
+ return FALSE;
- //TURN OFF/ON INSERT MODE
- if (!always_insert_mode && ((insert_mode && (event->keyval == GDK_Escape)) || (!insert_mode && (event->string[0] == 'i')))) {
- insert_mode = !insert_mode;
- update_title (GTK_WINDOW (main_window));
+ /* turn off insert mode (if always_insert_mode is not used) */
+ if (insert_mode && (event->keyval == GDK_Escape)) {
+ insert_mode = always_insert_mode;
+ update_title();
return TRUE;
}
- //INTERNAL BINDINGS
- if((act = g_hash_table_lookup(internal_bindings, event->string)) != NULL)
- if (!insert_mode || (event->state == modmask)) {
- parse_command (act);
- result = TRUE;
- }
-
- //EXTERNAL BINDINGS
- if((act = g_hash_table_lookup(external_bindings, event->string)) != NULL)
- if (!insert_mode || (event->state == modmask)) {
- run_command (act, NULL);
- result = TRUE;
- }
-
- if (!result)
- result = (insert_mode ? FALSE : TRUE);
+ if (insert_mode && event->state != modmask)
+ return FALSE;
- return result;
+
+ if (event->keyval == GDK_Escape) {
+ g_string_truncate(keycmd, 0);
+
+ update_title();
+
+ return TRUE;
+ }
+
+ g_string_append(keycmd, event->string);
+
+ if ((action = g_hash_table_lookup(bindings, keycmd->str))) {
+ g_string_truncate(keycmd, 0);
+
+ parse_command(action->name, action->param);
+ }
+
+ update_title();
+
+ return TRUE;
}
static GtkWidget*
@@ -672,23 +721,30 @@ GtkWidget* create_window () {
}
static void
-add_binding (char *binding, char *action, bool internal) {
- g_hash_table_insert(internal ? internal_bindings : external_bindings,
- binding, action);
+add_binding (const gchar *key, const gchar *act) {
+ char **parts = g_strsplit(act, " ", 2);
+ Action *action;
+
+ if (!parts)
+ return;
+
+ action = new_action(parts[0], parts[1]);
+ g_hash_table_insert(bindings, g_strdup(key), action);
+
+ g_strfreev(parts);
}
static void
settings_init () {
GKeyFile* config;
gboolean res = FALSE;
- gchar** keysi = NULL;
- gchar** keyse = NULL;
char *saveptr;
+ gchar** keys = NULL;
if (!config_file) {
const char* XDG_CONFIG_HOME = getenv ("XDG_CONFIG_HOME");
if (! XDG_CONFIG_HOME || ! strcmp (XDG_CONFIG_HOME, "")) {
- XDG_CONFIG_HOME = (char *)XDG_CONFIG_HOME_default;
+ XDG_CONFIG_HOME = (char*)XDG_CONFIG_HOME_default;
}
printf("XDG_CONFIG_HOME: %s\n", XDG_CONFIG_HOME);
@@ -723,9 +779,9 @@ settings_init () {
if (config_file) {
config = g_key_file_new ();
res = g_key_file_load_from_file (config, config_file, G_KEY_FILE_NONE, NULL);
- if(res) {
+ if(res) {
printf ("Config %s loaded\n", config_file);
- } else {
+ } else {
fprintf (stderr, "Config %s loading failed\n", config_file);
}
} else {
@@ -738,16 +794,14 @@ settings_init () {
always_insert_mode = g_key_file_get_boolean (config, "behavior", "always_insert_mode", NULL);
show_status = g_key_file_get_boolean (config, "behavior", "show_status", NULL);
modkey = g_key_file_get_value (config, "behavior", "modkey", NULL);
- keysi = g_key_file_get_keys (config, "bindings_internal", NULL, NULL);
- keyse = g_key_file_get_keys (config, "bindings_external", NULL, NULL);
status_top = g_key_file_get_boolean (config, "behavior", "status_top", NULL);
- home_page = g_key_file_get_value (config, "behavior", "home_page", NULL);
if (! fifo_dir)
- fifo_dir = g_key_file_get_value (config, "behavior", "fifo_dir", NULL);
+ fifo_dir = g_key_file_get_value (config, "behavior", "fifo_dir", NULL);
if (! socket_dir)
socket_dir = g_key_file_get_value (config, "behavior", "socket_dir", NULL);
+ keys = g_key_file_get_keys (config, "bindings", NULL, NULL);
}
-
+
printf ("History handler: %s\n", (history_handler ? history_handler : "disabled"));
printf ("Download manager: %s\n", (download_handler ? download_handler : "disabled"));
printf ("Fifo directory: %s\n", (fifo_dir ? fifo_dir : "/tmp"));
@@ -756,7 +810,6 @@ settings_init () {
printf ("Show status: %s\n", (show_status ? "TRUE" : "FALSE"));
printf ("Status top: %s\n", (status_top ? "TRUE" : "FALSE"));
printf ("Modkey: %s\n", (modkey ? modkey : "disabled"));
- printf ("Home page: %s\n", (home_page ? home_page : "disabled"));
if (! modkey)
modkey = "";
@@ -781,22 +834,55 @@ settings_init () {
if (g_strrstr (modkeyup,"META") != NULL) modmask |= GDK_META_MASK; //the Meta modifier. Since 2.10 */
free (modkeyup);
- if (keysi) {
- int i = 0;
- for (i = 0; keysi[i]; i++) {
- gchar *binding = g_key_file_get_string (config, "bindings_internal", keysi[i], NULL);
- printf ("Action: %s, Binding: %s (internal)\n", g_strdup (keysi[i]), binding);
- add_binding (binding, g_strdup (keysi[i]), true);
+ if (keys) {
+ int i;
+ for (i = 0; keys[i]; i++) {
+ gchar *value = g_key_file_get_string (config, "bindings", keys[i], NULL);
+
+ add_binding(g_strstrip(keys[i]), value);
+ g_free(value);
}
+
+ g_strfreev(keys);
}
- if (keyse) {
- int i = 0;
- for (i = 0; keyse[i]; i++) {
- gchar *binding = g_key_file_get_string (config, "bindings_external", keyse[i], NULL);
- printf ("Action: %s, Binding: %s (external)\n", g_strdup (keyse[i]), binding);
- add_binding (binding, g_strdup (keyse[i]), false);
- }
+
+ /* networking options */
+ proxy_url = g_key_file_get_value (config, "network", "proxy_server", NULL);
+ http_debug = g_key_file_get_integer (config, "network", "http_debug", NULL);
+ useragent = g_key_file_get_value (config, "network", "user-agent", NULL);
+ max_conns = g_key_file_get_integer (config, "network", "max_conns", NULL);
+ max_conns_host = g_key_file_get_integer (config, "network", "max_conns_per_host", NULL);
+
+ if(proxy_url){
+ g_object_set(G_OBJECT(soup_session), SOUP_SESSION_PROXY_URI, soup_uri_new(proxy_url), NULL);
+ }
+
+ if(!(http_debug <= 3)){
+ http_debug = 0;
+ fprintf(stderr, "Wrong http_debug level, ignoring.\n");
+ } else if (http_debug > 0) {
+ soup_logger = soup_logger_new(http_debug, -1);
+ soup_session_add_feature(soup_session, SOUP_SESSION_FEATURE(soup_logger));
+ }
+
+ if(useragent){
+ g_object_set(G_OBJECT(soup_session), SOUP_SESSION_USER_AGENT, useragent, NULL);
+ }
+
+ if(max_conns >= 1){
+ g_object_set(G_OBJECT(soup_session), SOUP_SESSION_MAX_CONNS, max_conns, NULL);
+ }
+
+ if(max_conns_host >= 1){
+ g_object_set(G_OBJECT(soup_session), SOUP_SESSION_MAX_CONNS_PER_HOST, max_conns_host, NULL);
}
+
+ printf("Proxy configured: %s\n", proxy_url ? proxy_url : "none");
+ printf("HTTP logging level: %d\n", http_debug);
+ printf("User-agent: %s\n", useragent? useragent : "default");
+ printf("Maximum connections: %d\n", max_conns ? max_conns : 0);
+ printf("Maximum connections per host: %d\n", max_conns_host ? max_conns_host: 0);
+
}
int
@@ -806,6 +892,7 @@ main (int argc, char* argv[]) {
g_thread_init (NULL);
printf("Uzbl start location: %s\n", argv[0]);
+ strcpy(executable_path,argv[0]);
strcat ((char *) XDG_CONFIG_HOME_default, getenv ("HOME"));
strcat ((char *) XDG_CONFIG_HOME_default, "/.config");
@@ -815,13 +902,15 @@ main (int argc, char* argv[]) {
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_add_group (context, gtk_get_option_group (TRUE));
g_option_context_parse (context, &argc, &argv, &error);
- /* initialize has tables */
- internal_bindings = g_hash_table_new(g_str_hash, g_str_equal);
- external_bindings = g_hash_table_new(g_str_hash, g_str_equal);
+ /* initialize hash table */
+ bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_action);
+
+ soup_session = webkit_get_default_session();
+ keycmd = g_string_new("");
settings_init ();
commands_hash ();
-
+
if (always_insert_mode)
insert_mode = TRUE;
@@ -844,16 +933,27 @@ main (int argc, char* argv[]) {
printf("pid %i\n", getpid ());
printf("name: %s\n", instance_name);
+ scbar_v = (GtkScrollbar*) gtk_vscrollbar_new (NULL);
+ bar_v = gtk_range_get_adjustment((GtkRange*) scbar_v);
+ scbar_h = (GtkScrollbar*) gtk_hscrollbar_new (NULL);
+ bar_h = gtk_range_get_adjustment((GtkRange*) scbar_h);
+ gtk_widget_set_scroll_adjustments ((GtkWidget*) web_view, bar_h, bar_v);
+
if (!show_status)
- gtk_widget_hide(mainbar);
+ gtk_widget_hide(mainbar);
create_fifo ();
create_socket();
gtk_main ();
+ g_string_free(keycmd, TRUE);
+
unlink (socket_path);
unlink (fifo_path);
+
+ g_hash_table_destroy(bindings);
+ g_hash_table_destroy(commands);
return 0;
}