[Vimprobable-users] [PATCH 1/3] Use enum instead of booleans for setting type
Vimprobable is a lean web browser optimised for full keyboard control
Brought to you by:
hanness
From: Raphael N. <rne...@hs...> - 2012-07-18 19:19:20
|
Since settings have only one type it makes more sense to use an enum instead of three different booleans in the Settings struct. Its also easier to add other setting types when using an enum. Finally one could use a switch statement instead of if/else if constructs. --- config.h | 80 +++++++++++++++++++++++++++++------------------------------ main.c | 8 +++--- vimprobable.h | 11 +++++--- 3 Dateien geändert, 52 Zeilen hinzugefügt(+), 47 Zeilen entfernt(-) diff --git a/config.h b/config.h index 7916a10..c7897c6 100644 --- a/config.h +++ b/config.h @@ -168,44 +168,44 @@ static Mouse mouse[] = { /* settings (arguments of :set command) */ static Setting browsersettings[] = { - /* public name, internal variable webkit setting integer value? boolean value? colour value? reload page? */ - { "useragent", useragent, "user-agent", FALSE, FALSE, FALSE, FALSE }, - { "scripts", NULL, "enable-scripts", FALSE, TRUE, FALSE, FALSE }, - { "plugins", NULL, "enable-plugins", FALSE, TRUE, FALSE, FALSE }, - { "pagecache", NULL, "enable-page-cache", FALSE, TRUE, FALSE, FALSE }, - { "java", NULL, "enable-java-applet", FALSE, TRUE, FALSE, FALSE }, - { "images", NULL, "auto-load-images", FALSE, TRUE, FALSE, FALSE }, - { "shrinkimages", NULL, "auto-shrink-images", FALSE, TRUE, FALSE, FALSE }, - { "cursivefont", NULL, "cursive-font-family", FALSE, FALSE, FALSE, FALSE }, - { "defaultencoding", NULL, "default-encoding", FALSE, FALSE, FALSE, FALSE }, - { "defaultfont", NULL, "default-font-family", FALSE, FALSE, FALSE, FALSE }, - { "fontsize", NULL, "default-font-size", TRUE, FALSE, FALSE, FALSE }, - { "monofontsize", NULL, "default-monospace-font-size", TRUE, FALSE, FALSE, FALSE }, - { "caret", NULL, "enable-caret-browsing", FALSE, TRUE, FALSE, FALSE }, - { "fantasyfont", NULL, "fantasy-font-family", FALSE, FALSE, FALSE, FALSE }, - { "minimumfontsize", NULL, "minimum-font-size", TRUE, FALSE, FALSE, FALSE }, - { "monofont", NULL, "monospace-font-family", FALSE, FALSE, FALSE, FALSE }, - { "backgrounds", NULL, "print-backgrounds", FALSE, TRUE, FALSE, FALSE }, - { "sansfont", NULL, "sans-serif-font-family", FALSE, FALSE, FALSE, FALSE }, - { "seriffont", NULL, "serif-font-family", FALSE, FALSE, FALSE, FALSE }, - { "stylesheet", NULL, "user-stylesheet-uri", FALSE, FALSE, FALSE, FALSE }, - { "resizetextareas", NULL, "resizable-text-areas", FALSE, TRUE, FALSE, FALSE }, - { "webinspector", NULL, "enable-developer-extras", FALSE, TRUE, FALSE, FALSE }, - - { "homepage", startpage, "", FALSE, FALSE, FALSE, FALSE }, - { "statusbgcolor", statusbgcolor, "", FALSE, FALSE, TRUE, TRUE }, - { "statuscolor", statuscolor, "", FALSE, FALSE, TRUE, TRUE }, - { "sslbgcolor", sslbgcolor, "", FALSE, FALSE, TRUE, TRUE }, - { "sslcolor", sslcolor, "", FALSE, FALSE, TRUE, TRUE }, - { "acceptlanguage", acceptlanguage, "", FALSE, FALSE, FALSE, FALSE }, - { "defaultsearch", defaultsearch, "", FALSE, FALSE, FALSE, FALSE }, - { "qmark", NULL, "", FALSE, FALSE, FALSE, FALSE }, - { "proxy", NULL, "", FALSE, TRUE, FALSE, FALSE }, - { "scrollbars", NULL, "", FALSE, TRUE, FALSE, FALSE }, - { "statusbar", NULL, "", FALSE, TRUE, FALSE, FALSE }, - { "inputbox", NULL, "", FALSE, TRUE, FALSE, FALSE }, - { "completioncase", NULL, "", FALSE, TRUE, FALSE, FALSE }, - { "escapeinput", NULL, "", FALSE, TRUE, FALSE, FALSE }, - { "strictssl", NULL, "", FALSE, TRUE, FALSE, FALSE }, - { "cabundle", ca_bundle, "", FALSE, FALSE, FALSE, FALSE }, + /* public name, internal variable webkit setting setting type? reload page? */ + { "useragent", useragent, "user-agent", SettingString, FALSE }, + { "scripts", NULL, "enable-scripts", SettingBool, FALSE }, + { "plugins", NULL, "enable-plugins", SettingBool, FALSE }, + { "pagecache", NULL, "enable-page-cache", SettingBool, FALSE }, + { "java", NULL, "enable-java-applet", SettingBool, FALSE }, + { "images", NULL, "auto-load-images", SettingBool, FALSE }, + { "shrinkimages", NULL, "auto-shrink-images", SettingBool, FALSE }, + { "cursivefont", NULL, "cursive-font-family", SettingString, FALSE }, + { "defaultencoding", NULL, "default-encoding", SettingString, FALSE }, + { "defaultfont", NULL, "default-font-family", SettingString, FALSE }, + { "fontsize", NULL, "default-font-size", SettingInt, FALSE }, + { "monofontsize", NULL, "default-monospace-font-size", SettingInt, FALSE }, + { "caret", NULL, "enable-caret-browsing", SettingBool, FALSE }, + { "fantasyfont", NULL, "fantasy-font-family", SettingString, FALSE }, + { "minimumfontsize", NULL, "minimum-font-size", SettingInt, FALSE }, + { "monofont", NULL, "monospace-font-family", SettingString, FALSE }, + { "backgrounds", NULL, "print-backgrounds", SettingBool, FALSE }, + { "sansfont", NULL, "sans-serif-font-family", SettingString, FALSE }, + { "seriffont", NULL, "serif-font-family", SettingString, FALSE }, + { "stylesheet", NULL, "user-stylesheet-uri", SettingString, FALSE }, + { "resizetextareas", NULL, "resizable-text-areas", SettingBool, FALSE }, + { "webinspector", NULL, "enable-developer-extras", SettingBool, FALSE }, + + { "homepage", startpage, "", SettingString, FALSE }, + { "statusbgcolor", statusbgcolor, "", SettingColourval, TRUE }, + { "statuscolor", statuscolor, "", SettingColourval, TRUE }, + { "sslbgcolor", sslbgcolor, "", SettingColourval, TRUE }, + { "sslcolor", sslcolor, "", SettingColourval, TRUE }, + { "acceptlanguage", acceptlanguage, "", SettingString, FALSE }, + { "defaultsearch", defaultsearch, "", SettingString, FALSE }, + { "qmark", NULL, "", SettingString, FALSE }, + { "proxy", NULL, "", SettingBool, FALSE }, + { "scrollbars", NULL, "", SettingBool, FALSE }, + { "statusbar", NULL, "", SettingBool, FALSE }, + { "inputbox", NULL, "", SettingBool, FALSE }, + { "completioncase", NULL, "", SettingBool, FALSE }, + { "escapeinput", NULL, "", SettingBool, FALSE }, + { "strictssl", NULL, "", SettingBool, FALSE }, + { "cabundle", ca_bundle, "", SettingString, FALSE }, }; diff --git a/main.c b/main.c index 20a9925..0fbe472 100644 --- a/main.c +++ b/main.c @@ -1901,7 +1901,7 @@ process_set_line(char *line) { return (process_save_qmark(my_pair.value, webview)); } /* interpret boolean values */ - if (browsersettings[i].boolval) { + if (browsersettings[i].type == SettingBool) { if (strncmp(my_pair.value, "on", 2) == 0 || strncmp(my_pair.value, "true", 4) == 0 || strncmp(my_pair.value, "ON", 2) == 0 || strncmp(my_pair.value, "TRUE", 4) == 0) { boolval = TRUE; } else if (strncmp(my_pair.value, "off", 3) == 0 || strncmp(my_pair.value, "false", 5) == 0 || strncmp(my_pair.value, "OFF", 3) == 0 || strncmp(my_pair.value, "FALSE", 5) == 0) { @@ -1909,7 +1909,7 @@ process_set_line(char *line) { } else { return FALSE; } - } else if (browsersettings[i].colourval) { + } else if (browsersettings[i].type == SettingColourval) { /* interpret as hexadecimal colour */ if (!parse_colour(my_pair.value)) { return FALSE; @@ -1927,9 +1927,9 @@ process_set_line(char *line) { } if (strlen(browsersettings[i].webkit) > 0) { /* activate appropriate webkit setting */ - if (browsersettings[i].boolval) { + if (browsersettings[i].type == SettingBool) { g_object_set((GObject*)settings, browsersettings[i].webkit, boolval, NULL); - } else if (browsersettings[i].intval) { + } else if (browsersettings[i].type == SettingInt) { g_object_set((GObject*)settings, browsersettings[i].webkit, atoi(my_pair.value), NULL); } else { g_object_set((GObject*)settings, browsersettings[i].webkit, my_pair.value, NULL); diff --git a/vimprobable.h b/vimprobable.h index 5a6c2df..fdfab8b 100644 --- a/vimprobable.h +++ b/vimprobable.h @@ -117,13 +117,18 @@ typedef struct { const Arg arg; } Mouse; +typedef enum { + SettingInt, + SettingBool, + SettingColourval, + SettingString +}ESettingType; + typedef struct { char *name; char (*var); char *webkit; - gboolean intval; - gboolean boolval; - gboolean colourval; + ESettingType type; gboolean reload; } Setting; -- 1.7.11.2 |