refactored status bar template symbol definition and setup
authorRobert Manea <gotmor@gmail.com>
Wed, 6 May 2009 09:50:34 +0000 (11:50 +0200)
committerRobert Manea <gotmor@gmail.com>
Wed, 6 May 2009 09:50:34 +0000 (11:50 +0200)
uzbl.c
uzbl.h

diff --git a/uzbl.c b/uzbl.c
index 4dab3c0..16cde01 100644 (file)
--- a/uzbl.c
+++ b/uzbl.c
@@ -410,6 +410,7 @@ close_uzbl (WebKitWebView *page, const char *param) {
     gtk_main_quit ();
 }
 
+/* --Statusbar functions-- */
 static char*
 build_progressbar_ascii(int percent) {
    int width=10;
@@ -431,8 +432,6 @@ build_progressbar_ascii(int percent) {
    return g_string_free(bar, FALSE);
 }
 
-        
-enum { SYM_TITLE, SYM_URI, SYM_NAME, SYM_LOADPRGS, SYM_LOADPRGSBAR};
 static void
 setup_scanner() {
      const GScannerConfig scan_config = {
@@ -480,13 +479,12 @@ setup_scanner() {
      };
 
      uzbl.scan = g_scanner_new(&scan_config);
-
-     /* TODO: move this stuff to an array and use a loop to actually set it */
-     g_scanner_scope_add_symbol(uzbl.scan, 0, "TITLE", (gpointer)SYM_TITLE);
-     g_scanner_scope_add_symbol(uzbl.scan, 0, "URI",   (gpointer)SYM_URI);
-     g_scanner_scope_add_symbol(uzbl.scan, 0, "NAME",   (gpointer)SYM_NAME);
-     g_scanner_scope_add_symbol(uzbl.scan, 0, "LOAD_PROGRESS", (gpointer)SYM_LOADPRGS);
-     g_scanner_scope_add_symbol(uzbl.scan, 0, "LOAD_PROGRESSBAR", (gpointer)SYM_LOADPRGSBAR);
+     while(symp->symbol_name) {
+         g_scanner_scope_add_symbol(uzbl.scan, 0,
+                         symp->symbol_name,
+                         GINT_TO_POINTER(symp->symbol_token));
+         symp++;
+     }
 }
 
 static gchar *
@@ -542,6 +540,7 @@ parse_status_template(const char *template) {
 
      return g_string_free(ret, FALSE);
 }
+/* --End Statusbar functions-- */
 
 
 // make sure to put '' around args, so that if there is whitespace we can still keep arguments together.
diff --git a/uzbl.h b/uzbl.h
index f424110..297a85d 100644 (file)
--- a/uzbl.h
+++ b/uzbl.h
@@ -1,3 +1,17 @@
+/* statusbar symbols */
+enum { SYM_TITLE, SYM_URI, SYM_NAME, SYM_LOADPRGS, SYM_LOADPRGSBAR};
+const struct {
+    gchar *symbol_name;
+    guint symbol_token;
+} symbols[] = {
+    {"NAME",                 SYM_NAME},
+    {"URI",                  SYM_URI},
+    {"TITLE",                SYM_TITLE},
+    {"LOAD_PROGRESS",        SYM_LOADPRGS},
+    {"LOAD_PROGRESSBAR",     SYM_LOADPRGSBAR},
+    {NULL,                   0}
+}, *symp = symbols;
+
 /* status bar elements */
 typedef struct {
     gint           load_progress;