Merge branch 'helmutexp' into robhelmut
[uzbl-mobile] / uzbl.c
diff --git a/uzbl.c b/uzbl.c
index 12bd374..fc8754f 100644 (file)
--- a/uzbl.c
+++ b/uzbl.c
@@ -53,6 +53,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <assert.h>
 #include <poll.h>
 #include <sys/uio.h>
 #include <sys/ioctl.h>
@@ -86,7 +87,7 @@ GOptionEntry entries[] =
 enum ptr_type {TYPE_INT, TYPE_STR, TYPE_FLOAT};
 
 /* associate command names to their properties */
-typedef const struct {
+typedef struct {
     /* TODO: Make this ambiguous void **ptr into a union { char *char_p; int *int_p; float *float_p; } val;
              the PTR() macro is kind of preventing this change at the moment. */
     enum ptr_type type;
@@ -651,7 +652,7 @@ cmd_set_geometry() {
        the above setting and we don't want to end up with
        wrong geometry information
     */
-    retreive_geometry();
+    retrieve_geometry();
 }
 
 void
@@ -834,7 +835,8 @@ struct {const char *key; CommandInfo value;} cmdlist[] =
     { "keycmd_nl",          {keycmd_nl, TRUE}              },
     { "keycmd_bs",          {keycmd_bs, 0}                 },
     { "chain",              {chain, 0}                     },
-    { "print",              {print, TRUE}                  }
+    { "print",              {print, TRUE}                  },
+    { "update_gui",         {update_gui, TRUE}           }
 };
 
 void
@@ -889,6 +891,13 @@ set_var(WebKitWebView *page, GArray *argv, GString *result) {
 }
 
 void
+update_gui(WebKitWebView *page, GArray *argv, GString *result) {
+    (void) page; (void) argv; (void) result;
+
+    update_title();
+}
+
+void
 print(WebKitWebView *page, GArray *argv, GString *result) {
     (void) page; (void) result;
     gchar* buf;
@@ -1834,6 +1843,10 @@ cmd_useragent() {
 
 void
 move_statusbar() {
+    if (!uzbl.gui.scrolled_win &&
+            !uzbl.gui.mainbar)
+        return;
+
     gtk_widget_ref(uzbl.gui.scrolled_win);
     gtk_widget_ref(uzbl.gui.mainbar);
     gtk_container_remove(GTK_CONTAINER(uzbl.gui.vbox), uzbl.gui.scrolled_win);
@@ -1858,6 +1871,7 @@ set_var_value(const gchar *name, gchar *val) {
     uzbl_cmdprop *c = NULL;
     char *endp = NULL;
     char *buf = NULL;
+    char *invalid_chars = "^°!\"§$%&/()=?'`'+~*'#-.:,;@<>| \\{}[]¹²³¼½";
 
     if( (c = g_hash_table_lookup(uzbl.comm.proto_var, name)) ) {
         if(!c->writeable) return FALSE;
@@ -1879,6 +1893,25 @@ set_var_value(const gchar *name, gchar *val) {
 
         /* invoke a command specific function */
         if(c->func) c->func();
+    } else {
+        /* check wether name violates our naming scheme */
+        if(strpbrk(name, invalid_chars)) {
+            if (uzbl.state.verbose)
+                printf("Invalid variable name\n");
+            return FALSE;
+        }
+
+        /* custom vars */
+        c = malloc(sizeof(uzbl_cmdprop));
+        c->type = TYPE_STR;
+        c->dump = 0;
+        c->func = NULL;
+        c->writeable = 1;
+        buf = expand(val, 0);
+        c->ptr.s = malloc(sizeof(char *));
+        *c->ptr.s = buf;
+        g_hash_table_insert(uzbl.comm.proto_var,
+                g_strdup(name), (gpointer) c);
     }
     return TRUE;
 }
@@ -2191,7 +2224,7 @@ configure_event_cb(GtkWidget* window, GdkEventConfigure* event) {
     (void) window;
     (void) event;
 
-    retreive_geometry();
+    retrieve_geometry();
     return FALSE;
 }
 
@@ -2762,7 +2795,7 @@ dump_config() {
 }
 
 void
-retreive_geometry() {
+retrieve_geometry() {
     int w, h, x, y;
     GString *buf = g_string_new("");
 
@@ -2895,7 +2928,7 @@ main (int argc, char* argv[]) {
     if(uzbl.gui.geometry)
         cmd_set_geometry();
     else
-        retreive_geometry();
+        retrieve_geometry();
 
     gchar *uri_override = (uzbl.state.uri ? g_strdup(uzbl.state.uri) : NULL);
     if (argc > 1 && !uzbl.state.uri)