Remove settings hashmap from global scope.
authorDaniel Carl <danielcarl@gmx.de>
Sun, 7 Apr 2013 18:37:23 +0000 (20:37 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Sun, 7 Apr 2013 18:37:23 +0000 (20:37 +0200)
src/completion.c
src/main.h
src/setting.c
src/setting.h

index 1ef88c4..ddd1111 100644 (file)
@@ -22,6 +22,7 @@
 #include "history.h"
 #include "bookmark.h"
 #include "command.h"
+#include "setting.h"
 
 extern VbCore vb;
 
@@ -80,8 +81,7 @@ gboolean completion_complete(gboolean back)
 
     /* TODO move these decision to a more generic place */
     if (!strncmp(input, ":set ", 5)) {
-        source = g_hash_table_get_keys(vb.settings);
-        source = g_list_sort(source, (GCompareFunc)g_strcmp0);
+        source = g_list_sort(setting_get_all(), (GCompareFunc)g_strcmp0);
         comps.completions = init_completion(
             comps.completions,
             filter_list(tmp, source, (Comp_Func)g_str_has_prefix, &input[5]),
index 0f95554..97f400e 100644 (file)
@@ -285,7 +285,6 @@ typedef struct {
     char            *files[FILES_LAST];
     Config          config;
     Style           style;
-    GHashTable      *settings;
     SoupSession     *session;
 #ifdef HAS_GTK3
     Window          embed;
index bfcf0e4..8ed1886 100644 (file)
@@ -20,6 +20,8 @@
 #include "setting.h"
 #include "util.h"
 
+static GHashTable *settings;
+
 extern VbCore vb;
 
 static Arg *char_to_arg(const char *str, const Type type);
@@ -107,19 +109,24 @@ void setting_init(void)
 {
     Setting *s;
     unsigned int i;
-    vb.settings = g_hash_table_new(g_str_hash, g_str_equal);
+    settings = g_hash_table_new(g_str_hash, g_str_equal);
 
     for (i = 0; i < LENGTH(default_settings); i++) {
         s = &default_settings[i];
         /* use alias as key if available */
-        g_hash_table_insert(vb.settings, (gpointer)s->alias != NULL ? s->alias : s->name, s);
+        g_hash_table_insert(settings, (gpointer)s->alias != NULL ? s->alias : s->name, s);
     }
 }
 
+GList* setting_get_all(void)
+{
+    return g_hash_table_get_keys(settings);
+}
+
 void setting_cleanup(void)
 {
-    if (vb.settings) {
-        g_hash_table_destroy(vb.settings);
+    if (settings) {
+        g_hash_table_destroy(settings);
     }
 }
 
@@ -141,7 +148,7 @@ gboolean setting_run(char *name, const char *param)
         type = SETTING_GET;
     }
 
-    Setting *s = g_hash_table_lookup(vb.settings, name);
+    Setting *s = g_hash_table_lookup(settings, name);
     if (!s) {
         vb_echo(VB_MSG_ERROR, true, "Config '%s' not found", name);
         return false;
index b259860..e670d2a 100644 (file)
@@ -40,6 +40,7 @@ struct _Setting {
 };
 
 void setting_init(void);
+GList* setting_get_all(void);
 void setting_cleanup(void);
 gboolean setting_run(char* name, const char* param);