summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hofmann <scm@uninformativ.de>2014-06-15 15:36:21 +0200
committerPeter Hofmann <scm@uninformativ.de>2014-06-15 15:41:21 +0200
commit2a7ab6c528f8545a49893c5e6e6398f05c130787 (patch)
tree0d682c42362a1d237a2622ffc6abb6757ddbd24a
parent7b4ea207feaaa9f4ad821bba0140eed61cf07002 (diff)
downloadlariza-2a7ab6c528f8545a49893c5e6e6398f05c130787.tar.gz
User configuration using environment variables
I think of these options (language, download dir, zoom) as user settings. The user does not change them all the time. He sets them once and for all in his shell rc. "-e" and friends, however, are considered runtime settings. "THIS TIME, I want my browser to debug all requests!"
-rw-r--r--browser.c55
1 files changed, 44 insertions, 11 deletions
diff --git a/browser.c b/browser.c
index 5828061..81ddf99 100644
--- a/browser.c
+++ b/browser.c
@@ -12,10 +12,6 @@
#include <webkit/webkit.h>
-#define DOWNLOAD_DIR "/tmp/tmp"
-#define LANGUAGE "en-US"
-
-
static void adblock(WebKitWebView *, WebKitWebFrame *, WebKitWebResource *,
WebKitNetworkRequest *, WebKitNetworkResponse *, gpointer);
static void adblock_load(void);
@@ -35,6 +31,7 @@ static gboolean download_request(WebKitWebView *, WebKitWebFrame *,
WebKitWebPolicyDecision *, gpointer);
static gboolean download_wget(WebKitWebView *, WebKitDownload *, gpointer);
static gchar *ensure_url_scheme(const gchar *);
+static void grab_environment_configuration(void);
static void hover_web_view(WebKitWebView *, gchar *, gchar *, gpointer);
static gboolean key_location(GtkWidget *, GdkEvent *, gpointer);
static gboolean key_web_view(GtkWidget *, GdkEvent *, gpointer);
@@ -56,11 +53,13 @@ struct Client
};
+static gchar *accepted_language = "en-US";
static GSList *adblock_patterns = NULL;
static gint clients = 0;
static gboolean cooperative_alone = TRUE;
static gboolean cooperative_instances = TRUE;
static int cooperative_pipe_fp = 0;
+static gchar *download_dir = "/tmp";
static Window embed = 0;
static gchar *first_uri = NULL;
static gdouble global_zoom = 1.0;
@@ -237,8 +236,8 @@ client_new(const gchar *uri)
if (!language_is_set)
{
- g_object_set(webkit_get_default_session(), "accept-language", LANGUAGE,
- NULL);
+ g_object_set(webkit_get_default_session(), "accept-language",
+ accepted_language, NULL);
language_is_set = TRUE;
}
@@ -397,7 +396,7 @@ download_wget(WebKitWebView *web_view, WebKitDownload *download, gpointer data)
uri = webkit_download_get_uri(download);
if (fork() == 0)
{
- chdir(DOWNLOAD_DIR);
+ chdir(download_dir);
if (embed == 0)
ret = execlp("xterm", "xterm", "-hold", "-e", "wget", uri, NULL);
else
@@ -442,6 +441,41 @@ ensure_url_scheme(const gchar *t)
}
void
+grab_environment_configuration(void)
+{
+ gchar *u, *v;
+ const gchar *e;
+
+ u = g_ascii_strup(__NAME__, -1);
+
+ v = g_strdup_printf("%s_ACCEPTED_LANGUAGE", u);
+ e = g_getenv(v);
+ if (e != NULL)
+ {
+ accepted_language = g_strdup(e);
+ }
+ g_free(v);
+
+ v = g_strdup_printf("%s_DOWNLOAD_DIR", u);
+ e = g_getenv(v);
+ if (e != NULL)
+ {
+ download_dir = g_strdup(e);
+ }
+ g_free(v);
+
+ v = g_strdup_printf("%s_ZOOM", u);
+ e = g_getenv(v);
+ if (e != NULL)
+ {
+ global_zoom = atof(e);
+ }
+ g_free(v);
+
+ g_free(u);
+}
+
+void
hover_web_view(WebKitWebView *web_view, gchar *title, gchar *uri,
gpointer data)
{
@@ -684,13 +718,12 @@ main(int argc, char **argv)
gtk_init(&argc, &argv);
- while ((opt = getopt(argc, argv, "z:e:rCT")) != -1)
+ grab_environment_configuration();
+
+ while ((opt = getopt(argc, argv, "e:rCT")) != -1)
{
switch (opt)
{
- case 'z':
- global_zoom = atof(optarg);
- break;
case 'e':
embed = atol(optarg);
tabbed_automagic = FALSE;