From 1319ff78c89fd0c34feea187ca3d67058875fbe6 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Fri, 13 Feb 2004 16:09:12 +0000 Subject: [PATCH] [project @ 2004-02-13 16:09:12 by bursa] Clean up and rewrite options code. svn path=/import/netsurf/; revision=536 --- !NetSurf/Resources/en/Templates,fec | Bin 4312 -> 4160 bytes content/fetch.c | 11 +- debug/netsurfd.c | 7 +- debug/optionsd.c | 28 ---- desktop/netsurf.c | 4 +- desktop/options.c | 157 +++++++++++++++++++++ desktop/options.h | 40 +++--- makefile | 8 +- riscos/dialog.c | 182 +++++++++++++++---------- riscos/gui.c | 16 ++- riscos/gui.h | 11 +- riscos/mouseactions.c | 4 +- riscos/options.c | 204 ---------------------------- riscos/options.h | 60 +++----- 14 files changed, 336 insertions(+), 396 deletions(-) delete mode 100644 debug/optionsd.c create mode 100644 desktop/options.c delete mode 100644 riscos/options.c diff --git a/!NetSurf/Resources/en/Templates,fec b/!NetSurf/Resources/en/Templates,fec index 9baecfc61420a2057a6ba44c3eecdf418a96d1f6..16d9d12b194052f2051f2f55a9269ca9bc6e6c89 100644 GIT binary patch delta 1508 zcma)6U1%It6#gdNw8_RzB1ze*t+{O}N+}CTXrXRXNE)${WV6j|Qy+w6cIM9R(Al}; zox9mx6&eIl5WzCwgTCmaqDa{Xf9QkIzVyupAM`FQgfHk!EA58O=Tj%WnFupAKn@c2_@D^W^?bhKx^BLpIgi{2=9DG##ZbwWhV&HA7eY%_VOnb(OQ%ju z<_nQ#&sl-ZeJq{Sh~3?^M|(2H6)esrisJIFYBN$aA}(PbE^rmqC0Q>gP>}-B+Ah$M zX`xi*HNG8I9blQF@h(OArxfrZksf{V7kje&{)5d;hopUkOc{7dOLQFcI6%xMjTedE zOY|%4`)FSx{droa#*sZm*l8lV9J90z6RzK6Hj&Q||9X5d^+NA5aaMdL_1plmg827{ zM&k9<{+E&cjQH<}_R}rHL?t?{t*_HMat+xV#Q$Q%f258sJT+*qHbdX?f?O__#GH2l zT#PuYi8{>{9;v$I5#oj3Yys20FB(koreYEIxve~UT~mZgxb6wP1o?uN!mMgNA^fsM zkMe{<0=Lt9&HwSVv)r}nzDitllAU((e5q7q-Pe4=L{+J9m#oupRYYo=Xk;rRwJa1; z;T5#+?Q0uTPYvJhjuk9QE5v{HA4sDp`I^TYv^CPB^LULb7I2D-&a~)p*ehIN!3wMj z|CgxNf$_-HM7|Jc1F@A}q>8(izB7iU2`q7&du!Zb;}er}GfcQ_JU6j0qeb!e1E)`7 z9@Az0bGo*W)Traw*lGs3x4jVC3X}>K?PJf38)W2C<|xhYWX5RzJaguG;LUG(U{W2k z={o&Opgh~^WJ3H`=8#VB_}RgO)FyV`m!Cb3`A(1Nmi&KIa!rU_i^vu=?S8FAnRZ!D zDrQM;b$;mm!GJvZd+qHwDj8*N-L%C$P$p8QV delta 1607 zcma)6O>7%Q6dwOICFzTUn&1W!vTlVy5Lt3Uky^LN`9Y*gV;kEoK_De-d)B+kddKXJ zdLREN!q_&rhxl5>CB_DiF!uWa|Fxzo zw&?!#cSozVMfxCPKL&hFv>jXMH3I(JF~-(|^=whM9O~mA3^Vq3;BPsGpa8!*!q_Tu zQt?g8lfvzgTIc#sIYj>X(6s`U49n(ghGArKYGfgOqGhSOnL<;#Yi-w(JdQso{d|RJl#X(+a8fC*9F7g|;cb95{-NN4m|sqU~{)O356TUdu)FN&pp5 zh|YdORi;B_lQ;N&SoVO+sD>G3>|4m)7`CY%|5_|@p*Z~Y!UWz;OYo&2mE^&f9Ov{pNV~j(GCAxbo`}k;wHvF zK#t=p)S8tMWe4-Cu*bj2CL)M133=LIkB%*66TgDH4;c&mC*XGi^QFK)4c}Llf56{G zbQAnYz+VDqhW#(1r&brG?8-5=|)#V_F#}lT&POh2n+Mf|f67hHx7iyc^t+-eGS=Qpr@S3Sn1t zocN*T_Fz-I+}4_|@Pll(uU&fvfz5UpFEOJ9{*)k|b zEtsidES1XzMD5+XgXx)4Hi>*~U_9J2V}4;E8lkh)eRH7uKkoUXW9D>RW#p0Z>aJBc z<#e-e@t;}M4Jritr{YYe6zm#QfWFS9=5Q3$73EJ2ojFYxX|5vNehDdP z9kp7O_Igz6iq)ijeFJ@jx*rdvLkM!~*r_Ci*$cSYKdFBU_Al5c!z@wIJ+Cd?+F9}= zbPm2*IsyF_O-9hJ{0>d5(xGKDi!ai}UI*+qr2ptM4Ixq;NL4h{E*c$N>z5)GU_#|{PJ_SA3(|TMbawR@_hR~==XjJN>e3LtxCt7ZmYi(Z9_F5OH nh07)UK%UepEz7R;BHWITMtg&u_|gb{6=vT-cHRiBqXO(7vYp^Q diff --git a/content/fetch.c b/content/fetch.c index ac47b4a46..295324484 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -2,7 +2,7 @@ * This file is part of NetSurf, http://netsurf.sourceforge.net/ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa * Copyright 2003 Phil Mellor */ @@ -291,11 +291,12 @@ struct fetch * fetch_start(char *url, char *referer, assert(code == CURLE_OK); /* use proxy if options dictate this */ - if (OPTIONS.http) - { - code = curl_easy_setopt(fetch->curl_handle, CURLOPT_PROXY, OPTIONS.http_proxy); + if (option_http_proxy && option_http_proxy_host) { + code = curl_easy_setopt(fetch->curl_handle, CURLOPT_PROXY, + option_http_proxy_host); assert(code == CURLE_OK); - code = curl_easy_setopt(fetch->curl_handle, CURLOPT_PROXYPORT, (long)OPTIONS.http_port); + code = curl_easy_setopt(fetch->curl_handle, CURLOPT_PROXYPORT, + (long) option_http_proxy_port); assert(code == CURLE_OK); } diff --git a/debug/netsurfd.c b/debug/netsurfd.c index f26521654..d0e62ebda 100644 --- a/debug/netsurfd.c +++ b/debug/netsurfd.c @@ -2,7 +2,7 @@ * This file is part of NetSurf, http://netsurf.sourceforge.net/ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa */ #include @@ -12,6 +12,7 @@ #include "netsurf/content/cache.h" #include "netsurf/content/content.h" #include "netsurf/content/fetchcache.h" +#include "netsurf/desktop/options.h" #include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" @@ -41,6 +42,7 @@ int main(int argc, char *argv[]) fetch_init(); cache_init(); fetchcache_init(); + options_read("options"); while (1) { puts("=== URL:"); @@ -48,7 +50,7 @@ int main(int argc, char *argv[]) break; url[strlen(url) - 1] = 0; destroyed = 0; - c = fetchcache(url, 0, callback, 0, 0, 100, 1000, false + c = fetchcache(url, 0, callback, 0, 0, 1000, 1000, false #ifdef WITH_POST , 0, 0 #endif @@ -70,6 +72,7 @@ int main(int argc, char *argv[]) content_remove_user(c, callback, 0, 0); } + options_write("options"); cache_quit(); fetch_quit(); diff --git a/debug/optionsd.c b/debug/optionsd.c deleted file mode 100644 index 2490c1f2f..000000000 --- a/debug/optionsd.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * This file is part of NetSurf, http://netsurf.sourceforge.net/ - * Licensed under the GNU General Public License, - * http://www.opensource.org/licenses/gpl-license - * Copyright 2003 James Bursa - */ - -#include "netsurf/desktop/options.h" -#include -#include -#include "netsurf/utils/log.h" -#include "netsurf/utils/utils.h" - -struct options OPTIONS; - -void options_init(struct options* opt) -{ - opt->http = 0; - opt->http_proxy = strdup(""); - opt->http_port = 8080; - opt->use_mouse_gestures = 0; - opt->allow_text_selection = 1; - opt->use_riscos_elements = 1; - opt->show_toolbar = 1; - opt->show_print_preview = 0; - opt->theme = strdup("Default"); -} - diff --git a/desktop/netsurf.c b/desktop/netsurf.c index a35788ba8..724b57415 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -3,7 +3,7 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa */ #include @@ -50,8 +50,6 @@ int main(int argc, char** argv) void netsurf_init(int argc, char** argv) { stdout = stderr; - options_init(&OPTIONS); - options_read(&OPTIONS, NULL); gui_init(argc, argv); fetch_init(); cache_init(); diff --git a/desktop/options.c b/desktop/options.c new file mode 100644 index 000000000..5b1981b6e --- /dev/null +++ b/desktop/options.c @@ -0,0 +1,157 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2003 Phil Mellor + * Copyright 2003 John M Bell + * Copyright 2004 James Bursa + */ + +/** \file + * Option reading and saving (implementation). + * + * Options are stored in the format key:value, one per line. For bool options, + * value is "0" or "1". + */ + +#include +#include +#include +#include "netsurf/desktop/options.h" +#include "netsurf/utils/log.h" +#include "netsurf/utils/utils.h" + +#ifdef riscos +#include "netsurf/riscos/options.h" +#else +#define EXTRA_OPTION_DEFINE +#define EXTRA_OPTION_TABLE +#endif + + +/** An HTTP proxy should be used. */ +bool option_http_proxy = false; +/** Hostname of proxy. */ +char *option_http_proxy_host = 0; +/** Proxy port. */ +int option_http_proxy_port = 8080; +EXTRA_OPTION_DEFINE + + +struct { + const char *key; + enum { OPTION_BOOL, OPTION_INTEGER, OPTION_STRING } type; + void *p; +} option_table[] = { + { "http_proxy", OPTION_BOOL, &option_http_proxy }, + { "http_proxy_host", OPTION_STRING, &option_http_proxy_host }, + { "http_proxy_port", OPTION_INTEGER, &option_http_proxy_port }, + EXTRA_OPTION_TABLE +}; + +#define option_table_entries (sizeof option_table / sizeof option_table[0]) + + +/** + * Read options from a file. + * + * \param path name of file to read options from + * + * Option variables corresponding to lines in the file are updated. Missing + * options are unchanged. If the file fails to open, options are unchanged. + */ + +void options_read(const char *path) +{ + char s[100]; + FILE *fp; + + fp = fopen(path, "r"); + if (!fp) { + LOG(("failed to open file '%s'", path)); + return; + } + + while (fgets(s, 100, fp)) { + char *colon, *value; + unsigned int i; + + if (s[0] == 0 || s[0] == '#') + continue; + colon = strchr(s, ':'); + if (colon == 0) + continue; + s[strlen(s) - 1] = 0; /* remove \n at end */ + *colon = 0; /* terminate key */ + value = colon + 1; + + for (i = 0; i != option_table_entries; i++) { + if (strcasecmp(s, option_table[i].key) != 0) + continue; + + switch (option_table[i].type) { + case OPTION_BOOL: + *((bool *) option_table[i].p) = + value[0] == '1'; + break; + + case OPTION_INTEGER: + *((int *) option_table[i].p) = + atoi(value); + break; + + case OPTION_STRING: + free(*((char **) option_table[i].p)); + *((char **) option_table[i].p) = + strdup(value); + break; + } + break; + } + } + + fclose(fp); +} + + +/** + * Save options to a file. + * + * \param path name of file to write options to + * + * Errors are ignored. + */ + +void options_write(const char *path) +{ + unsigned int i; + FILE *fp; + + fp = fopen(path, "w"); + if (!fp) { + LOG(("failed to open file '%s' for writing", path)); + return; + } + + for (i = 0; i != option_table_entries; i++) { + fprintf(fp, "%s:", option_table[i].key); + switch (option_table[i].type) { + case OPTION_BOOL: + fprintf(fp, "%c", *((bool *) option_table[i].p) ? + '1' : '0'); + break; + + case OPTION_INTEGER: + fprintf(fp, "%i", *((int *) option_table[i].p)); + break; + + case OPTION_STRING: + if (*((char **) option_table[i].p)) + fprintf(fp, "%s", *((char **) option_table[i].p)); + break; + } + fprintf(fp, "\n"); + } + + fclose(fp); +} diff --git a/desktop/options.h b/desktop/options.h index 415279b36..3c2acced9 100644 --- a/desktop/options.h +++ b/desktop/options.h @@ -3,32 +3,32 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor + * Copyright 2004 James Bursa */ +/** \file + * Option reading and saving (interface). + * + * Non-platform specific options can be added by editing this file and + * netsurf/desktop/options.c + * + * Platform specific options should be added in the platform options.h. + * + * The following types of options are supported: + * - bool (OPTION_BOOL) + * - int (OPTION_INTEGER) + * - char* (OPTION_STRING) (must be allocated on heap, may be 0, free before + * assigning a new value) + */ #ifndef _NETSURF_DESKTOP_OPTIONS_H_ #define _NETSURF_DESKTOP_OPTIONS_H_ -struct options; +extern bool option_http_proxy; +extern char *option_http_proxy_host; +extern int option_http_proxy_port; -#include "netsurf/riscos/options.h" - -struct options -{ - /* global options */ - int http; - char* http_proxy; - int http_port; - - /* platform specific options */ - PLATFORM_OPTIONS -}; - -extern struct options OPTIONS; - -void options_init(struct options* opt); -void options_write(struct options*, char* filename); -void options_read(struct options*, char* filename); +void options_read(const char *path); +void options_write(const char *path); #endif - diff --git a/makefile b/makefile index ae5332f8a..6a1872b09 100644 --- a/makefile +++ b/makefile @@ -11,17 +11,17 @@ OBJECTS_COMMON = cache.o content.o fetch.o fetchcache.o other.o \ box.o form.o html.o layout.o textplain.o \ messages.o utils.o translit.o pool.o OBJECTS = $(OBJECTS_COMMON) \ - browser.o loginlist.o netsurf.o \ + browser.o loginlist.o netsurf.o options.o \ htmlinstance.o htmlredraw.o \ 401login.o constdata.o dialog.o download.o frames.o gui.o \ menus.o mouseactions.o \ - options.o textselection.o theme.o window.o \ + textselection.o theme.o window.o \ draw.o gif.o jpeg.o plugin.o png.o sprite.o \ about.o filetype.o font.o uri.o url.o history.o \ version.o OBJECTS_DEBUG = $(OBJECTS_COMMON) \ netsurfd.o \ - optionsd.o filetyped.o fontd.o + options.o filetyped.o fontd.o OBJECTS_DEBUGRO = $(OBJECTS_COMMON) \ netsurfd.o \ constdata.o \ @@ -29,7 +29,7 @@ OBJECTS_DEBUGRO = $(OBJECTS_COMMON) \ draw.o gif.o jpeg.o png.o sprite.o \ about.o filetype.o \ version.o \ - optionsd.o font.o + options.o font.o VPATH = content:css:desktop:render:riscos:utils:debug WARNFLAGS = -W -Wall -Wundef -Wpointer-arith -Wbad-function-cast -Wcast-qual \ -Wcast-align -Wwrite-strings -Wconversion -Wstrict-prototypes \ diff --git a/riscos/dialog.c b/riscos/dialog.c index 19aad8933..6f6cf46d2 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -3,7 +3,7 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa * Copyright 2003 John M Bell */ @@ -32,29 +32,24 @@ wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, ; wimp_menu* theme_menu = NULL; -static struct ro_choices choices; -static struct browser_choices browser_choices; -static struct proxy_choices proxy_choices; -static struct theme_choices theme_choices; - static void ro_gui_dialog_click_config(wimp_pointer *pointer); static void ro_gui_dialog_click_config_br(wimp_pointer *pointer); static void ro_gui_dialog_click_config_prox(wimp_pointer *pointer); static void ro_gui_dialog_click_config_th(wimp_pointer *pointer); -static void set_browser_choices(struct browser_choices* newchoices); -static void get_browser_choices(struct browser_choices* newchoices); -static void set_proxy_choices(struct proxy_choices* newchoices); -static void get_proxy_choices(struct proxy_choices* newchoices); +static void set_browser_choices(void); +static void get_browser_choices(void); +static void set_proxy_choices(void); +static void get_proxy_choices(void); +static void set_theme_choices(void); +static void get_theme_choices(void); static void load_theme_preview(char* thname); -static void set_theme_choices(struct theme_choices* newchoices); -static void get_theme_choices(struct theme_choices* newchoices); /*static void ro_gui_destroy_theme_menu(void);*/ static void ro_gui_build_theme_menu(void); static int file_exists(const char* base, const char* dir, const char* leaf, bits ftype); static void set_icon_state(wimp_w w, wimp_i i, int state); static int get_icon_state(wimp_w w, wimp_i i); -static void set_icon_string(wimp_w w, wimp_i i, char* text); +static void set_icon_string(wimp_w w, wimp_i i, const char *text); static char* get_icon_string(wimp_w w, wimp_i i); static void set_icon_string_i(wimp_w w, wimp_i i, int num); @@ -75,10 +70,9 @@ void ro_gui_dialog_init(void) dialog_config_prox = ro_gui_dialog_create("config_prox"); dialog_config_th = ro_gui_dialog_create("config_th"); - options_to_ro(&OPTIONS, &choices); - set_browser_choices(&choices.browser); - set_proxy_choices(&choices.proxy); - set_theme_choices(&choices.theme); + set_browser_choices(); + set_proxy_choices(); + set_theme_choices(); } @@ -189,8 +183,12 @@ void ro_gui_dialog_click_config(wimp_pointer *pointer) { switch (pointer->i) { case ICON_CONFIG_SAVE: - ro_to_options(&choices, &OPTIONS); - options_write(&OPTIONS, NULL); + get_browser_choices(); + get_proxy_choices(); + get_theme_choices(); + xosfile_create_dir(".WWW", 0); + xosfile_create_dir(".WWW.NetSurf", 0); + options_write(".WWW.NetSurf.Choices"); if (pointer->buttons == wimp_CLICK_SELECT) { ro_gui_dialog_close(dialog_config_br); ro_gui_dialog_close(dialog_config_prox); @@ -204,9 +202,10 @@ void ro_gui_dialog_click_config(wimp_pointer *pointer) ro_gui_dialog_close(dialog_config_prox); ro_gui_dialog_close(dialog_config_th); ro_gui_dialog_close(dialog_config); - } else { - options_to_ro(&OPTIONS, &choices); } + set_browser_choices(); + set_proxy_choices(); + set_theme_choices(); break; case ICON_CONFIG_BROWSER: ro_gui_dialog_open(dialog_config_br); @@ -231,16 +230,13 @@ void ro_gui_dialog_click_config_br(wimp_pointer *pointer) switch (pointer->i) { case ICON_CONFIG_BR_OK: - get_browser_choices(&choices.browser); - get_browser_choices(&browser_choices); if (pointer->buttons == wimp_CLICK_SELECT) ro_gui_dialog_close(dialog_config_br); break; case ICON_CONFIG_BR_CANCEL: if (pointer->buttons == wimp_CLICK_SELECT) ro_gui_dialog_close(dialog_config_br); - else - set_browser_choices(&choices.browser); + set_browser_choices(); break; case ICON_CONFIG_BR_EXPLAIN: bw = create_browser_window(browser_TITLE | browser_TOOLBAR | @@ -264,16 +260,13 @@ void ro_gui_dialog_click_config_prox(wimp_pointer *pointer) { switch (pointer->i) { case ICON_CONFIG_PROX_OK: - get_proxy_choices(&choices.proxy); - get_proxy_choices(&proxy_choices); if (pointer->buttons == wimp_CLICK_SELECT) ro_gui_dialog_close(dialog_config_prox); break; case ICON_CONFIG_PROX_CANCEL: if (pointer->buttons == wimp_CLICK_SELECT) ro_gui_dialog_close(dialog_config_prox); - else - set_proxy_choices(&choices.proxy); + set_proxy_choices(); break; } } @@ -289,16 +282,13 @@ void ro_gui_dialog_click_config_th(wimp_pointer *pointer) switch (pointer->i) { case ICON_CONFIG_TH_OK: - get_theme_choices(&choices.theme); - get_theme_choices(&theme_choices); if (pointer->buttons == wimp_CLICK_SELECT) ro_gui_dialog_close(dialog_config_th); break; case ICON_CONFIG_TH_CANCEL: if (pointer->buttons == wimp_CLICK_SELECT) ro_gui_dialog_close(dialog_config_th); - else - set_theme_choices(&choices.theme); + set_theme_choices(); break; case ICON_CONFIG_TH_NAME: case ICON_CONFIG_TH_PICK: @@ -333,41 +323,91 @@ void ro_gui_dialog_close(wimp_w close) } +/** + * Update the browser choices dialog with the current options. + */ -void set_browser_choices(struct browser_choices* newchoices) +void set_browser_choices(void) { - memcpy(&browser_choices, newchoices, sizeof(struct browser_choices)); - set_icon_state(dialog_config_br, ICON_CONFIG_BR_GESTURES, browser_choices.use_mouse_gestures); - set_icon_state(dialog_config_br, ICON_CONFIG_BR_FORM, browser_choices.use_riscos_elements); - set_icon_state(dialog_config_br, ICON_CONFIG_BR_TEXT, browser_choices.allow_text_selection); - set_icon_state(dialog_config_br, ICON_CONFIG_BR_TOOLBAR, browser_choices.show_toolbar); - set_icon_state(dialog_config_br, ICON_CONFIG_BR_PREVIEW, browser_choices.show_print_preview); + set_icon_state(dialog_config_br, ICON_CONFIG_BR_GESTURES, + option_use_mouse_gestures); + set_icon_state(dialog_config_br, ICON_CONFIG_BR_TEXT, + option_allow_text_selection); + set_icon_state(dialog_config_br, ICON_CONFIG_BR_TOOLBAR, + option_show_toolbar); } -void get_browser_choices(struct browser_choices* newchoices) + +/** + * Set the current options to the settings in the browser choices dialog. + */ + +void get_browser_choices(void) { - newchoices->use_mouse_gestures = get_icon_state(dialog_config_br, ICON_CONFIG_BR_GESTURES); - newchoices->use_riscos_elements = get_icon_state(dialog_config_br, ICON_CONFIG_BR_FORM); - newchoices->allow_text_selection = get_icon_state(dialog_config_br, ICON_CONFIG_BR_TEXT); - newchoices->show_toolbar = get_icon_state(dialog_config_br, ICON_CONFIG_BR_TOOLBAR); - newchoices->show_print_preview = get_icon_state(dialog_config_br, ICON_CONFIG_BR_PREVIEW); + option_use_mouse_gestures = get_icon_state(dialog_config_br, + ICON_CONFIG_BR_GESTURES); + option_allow_text_selection = get_icon_state(dialog_config_br, + ICON_CONFIG_BR_TEXT); + option_show_toolbar = get_icon_state(dialog_config_br, + ICON_CONFIG_BR_TOOLBAR); } -void set_proxy_choices(struct proxy_choices* newchoices) + +/** + * Update the proxy choices dialog with the current options. + */ + +void set_proxy_choices(void) { - memcpy(&proxy_choices, newchoices, sizeof(struct proxy_choices)); - set_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP, proxy_choices.http); - set_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST, proxy_choices.http_proxy); - set_icon_string_i(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT, proxy_choices.http_port); + set_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP, + option_http_proxy); + set_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST, + option_http_proxy_host); + set_icon_string_i(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT, + option_http_proxy_port); } -void get_proxy_choices(struct proxy_choices* newchoices) + +/** + * Set the current options to the settings in the proxy choices dialog. + */ + +void get_proxy_choices(void) { - newchoices->http = get_icon_state(dialog_config_prox, ICON_CONFIG_PROX_HTTP); - strncpy(newchoices->http_proxy, get_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPHOST), 255); - newchoices->http_port = atoi(get_icon_string(dialog_config_prox, ICON_CONFIG_PROX_HTTPPORT)); + option_http_proxy = get_icon_state(dialog_config_prox, + ICON_CONFIG_PROX_HTTP); + free(option_http_proxy_host); + option_http_proxy_host = strdup(get_icon_string(dialog_config_prox, + ICON_CONFIG_PROX_HTTPHOST)); + option_http_proxy_port = atoi(get_icon_string(dialog_config_prox, + ICON_CONFIG_PROX_HTTPPORT)); } + +/** + * Update the theme choices dialog with the current options. + */ + +void set_theme_choices(void) +{ + set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, + option_theme ? option_theme : "Default"); + load_theme_preview(option_theme ? option_theme : "Default"); +} + + +/** + * Set the current options to the settings in the theme choices dialog. + */ + +void get_theme_choices(void) +{ + free(option_theme); + option_theme = strdup(get_icon_string(dialog_config_th, + ICON_CONFIG_TH_NAME)); +} + + osspriteop_area* theme_preview = NULL; void load_theme_preview(char* thname) @@ -469,18 +509,6 @@ void ro_gui_redraw_config_th(wimp_draw* redraw) } -void set_theme_choices(struct theme_choices* newchoices) -{ - memcpy(&theme_choices, newchoices, sizeof(struct theme_choices)); - set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme_choices.name); - load_theme_preview(theme_choices.name); -} - -void get_theme_choices(struct theme_choices* newchoices) -{ - strncpy(newchoices->name, get_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME), 255); -} - /** * Construct or update theme_menu by scanning THEMES_DIR. @@ -527,7 +555,7 @@ void ro_gui_build_theme_menu(void) theme_menu = xrealloc(theme_menu, wimp_SIZEOF_MENU(i + 1)); theme_menu->entries[i].menu_flags = 0; - if (strcmp(info.name, theme_choices.name) == 0) + if (option_theme && strcmp(info.name, option_theme) == 0) theme_menu->entries[i].menu_flags |= wimp_MENU_TICKED; theme_menu->entries[i].sub_menu = wimp_NO_SUB_MENU; theme_menu->entries[i].icon_flags = wimp_ICON_TEXT | @@ -554,9 +582,8 @@ void ro_gui_build_theme_menu(void) void ro_gui_theme_menu_selection(char *theme) { - strcpy(theme_choices.name, theme); - set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme_choices.name); - load_theme_preview(theme_choices.name); + set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme); + load_theme_preview(theme); wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_NAME, 0, 0); wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_PREVIEW, 0, 0); @@ -598,14 +625,23 @@ int get_icon_state(wimp_w w, wimp_i i) return (ic.icon.flags & wimp_ICON_SELECTED) != 0; } -void set_icon_string(wimp_w w, wimp_i i, char* text) + +/** + * Set the contents of an icon to a string. + * + * \param w window handle + * \param i icon handle + * \param text string (copied) + */ + +void set_icon_string(wimp_w w, wimp_i i, const char *text) { wimp_icon_state ic; ic.w = w; ic.i = i; wimp_get_icon_state(&ic); strncpy(ic.icon.data.indirected_text.text, text, - (unsigned int)ic.icon.data.indirected_text.size); + (unsigned int)ic.icon.data.indirected_text.size); } char* get_icon_string(wimp_w w, wimp_i i) diff --git a/riscos/gui.c b/riscos/gui.c index 961d2c927..d24c55167 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -3,7 +3,7 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa * Copyright 2003 John M Bell */ @@ -33,6 +33,7 @@ #endif #include "netsurf/riscos/constdata.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/options.h" #ifdef WITH_PLUGIN #include "netsurf/riscos/plugin.h" #endif @@ -140,18 +141,19 @@ void gui_init(int argc, char** argv) if (getenv("NetSurf$Start_URI_Handler")) xwimp_start_task("Desktop", 0); - if (OPTIONS.theme) { + options_read("Choices:WWW.NetSurf.Choices"); + + if (option_theme) { snprintf(theme_fname, sizeof(theme_fname), - ".Themes.%s", OPTIONS.theme); + ".Themes.%s", option_theme); /* check if theme directory exists */ if (!is_dir(theme_fname)) { - free(OPTIONS.theme); - OPTIONS.theme = strdup("Default"); + free(option_theme); + option_theme = 0; sprintf(theme_fname, ".Themes.Default"); } } else { - OPTIONS.theme = strdup("Default"); - sprintf(theme_fname, ".Themes.Default"); + strcpy(theme_fname, ".Themes.Default"); } ro_theme_load(theme_fname); diff --git a/riscos/gui.h b/riscos/gui.h index dab34561d..96c1e9fc0 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -3,7 +3,7 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa */ #ifndef _NETSURF_RISCOS_GUI_H_ @@ -184,12 +184,9 @@ void ro_gui_history_click(wimp_pointer *pointer); #define ICON_CONFIG_BR_OK 0 #define ICON_CONFIG_BR_CANCEL 1 #define ICON_CONFIG_BR_EXPLAIN 2 -#define ICON_CONFIG_BR_DEFAULT 3 -#define ICON_CONFIG_BR_FORM 4 -#define ICON_CONFIG_BR_GESTURES 5 -#define ICON_CONFIG_BR_TEXT 6 -#define ICON_CONFIG_BR_TOOLBAR 7 -#define ICON_CONFIG_BR_PREVIEW 8 +#define ICON_CONFIG_BR_GESTURES 3 +#define ICON_CONFIG_BR_TEXT 4 +#define ICON_CONFIG_BR_TOOLBAR 5 #define ICON_CONFIG_PROX_OK 0 #define ICON_CONFIG_PROX_CANCEL 1 diff --git a/riscos/mouseactions.c b/riscos/mouseactions.c index 9c7f76ea6..2fa00d946 100644 --- a/riscos/mouseactions.c +++ b/riscos/mouseactions.c @@ -11,8 +11,8 @@ #include "netsurf/utils/config.h" #include "netsurf/desktop/browser.h" -#include "netsurf/desktop/options.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/options.h" #include "netsurf/utils/log.h" typedef enum { @@ -34,7 +34,7 @@ void ro_gui_mouse_action(gui_window *g) { int x, y; mouseaction ma = mouseaction_NONE; - if (OPTIONS.use_mouse_gestures) + if (option_use_mouse_gestures) ma = ro_gui_try_mouse_action(); if (ma == mouseaction_NONE) { diff --git a/riscos/options.c b/riscos/options.c deleted file mode 100644 index a1c096777..000000000 --- a/riscos/options.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * This file is part of NetSurf, http://netsurf.sourceforge.net/ - * Licensed under the GNU General Public License, - * http://www.opensource.org/licenses/gpl-license - * Copyright 2003 Phil Mellor - * Copyright 2003 John M Bell - */ - -#include "netsurf/desktop/options.h" -#include -#include -#include "oslib/messagetrans.h" -#include "oslib/osfile.h" -#include "netsurf/utils/log.h" -#include "netsurf/utils/utils.h" - -struct options OPTIONS; -static char* lookup(messagetrans_control_block* cb, const char* token, const char* deflt); -static int lookup_yesno(messagetrans_control_block* cb, const char* token, const char* deflt); -static int lookup_i(messagetrans_control_block* cb, const char* token, const char* deflt); -static const char* yesno(int q); - -char* lookup(messagetrans_control_block* cb, const char* token, const char* deflt) -{ - int used; - char buffer[256]; - - LOG(("Looking up token '%s'",token)); - - messagetrans_lookup(cb, token, buffer, 256, 0,0,0,0, &used); - if (used > 0) - { - return strdup(buffer); - } - else - return strdup(deflt); -} - -int lookup_yesno(messagetrans_control_block* cb, const char* token, const char* deflt) -{ - char* find; - LOG(("yesno token '%s' (default '%s')", token, deflt)); - find = lookup(cb, token, deflt); - if (strcmp(find, "Y") == 0) - { - xfree(find); - return -1; - } - xfree(find); - return 0; -} - -int lookup_i(messagetrans_control_block* cb, const char* token, const char* deflt) -{ - char* find = lookup(cb, token, deflt); - int ret = atoi(find); - xfree(find); - return ret; -} - -const char* yesno(int q) -{ - if (q) - return "Y"; - else - return "N"; -} - -static const char * const WRITE_DIR = ".WWW.NetSurf"; - -void options_write(struct options* opt, char* filename) -{ - char* fn; - FILE* f; - - fn = xcalloc(strlen(WRITE_DIR) + (filename == 0 ? 7 : strlen(filename)) + 10, - sizeof(char)); - sprintf(fn, "%s.%s", WRITE_DIR, filename == 0 ? "Choices" : filename); - - xosfile_create_dir(".WWW", 0); - xosfile_create_dir(WRITE_DIR, 0); - - LOG(("filename: %s", fn)); - - f = fopen(fn, "w"); - if (f != NULL) - { - fprintf(f, "# General options - for any platform\n# Proxy\n"); - fprintf(f, "USE_HTTP:%s\n", yesno(opt->http)); - fprintf(f, "HTTP_PROXY:%s\n", opt->http_proxy); - fprintf(f, "HTTP_PORT:%d\n", opt->http_port); - - fprintf(f, "\n# RISC OS specific options\n# Browser\n"); - fprintf(f, "RO_MOUSE_GESTURES:%s\n", yesno(opt->use_mouse_gestures)); - fprintf(f, "RO_TEXT_SELECTION:%s\n", yesno(opt->allow_text_selection)); - fprintf(f, "RO_FORM_ELEMENTS:%s\n", yesno(opt->use_riscos_elements)); - fprintf(f, "RO_SHOW_TOOLBAR:%s\n", yesno(opt->show_toolbar)); - fprintf(f, "RO_SHOW_PRINT:%s\n", yesno(opt->show_print_preview)); - fprintf(f, "\n# Theme\n"); - fprintf(f, "RO_THEME:%s\n", opt->theme); - } - else - LOG(("Couldn't open Choices file")); - - fclose(f); - xfree(fn); -} - -void options_init(struct options* opt) -{ - opt->http = 0; - opt->http_proxy = strdup(""); - opt->http_port = 8080; - opt->use_mouse_gestures = 0; - opt->allow_text_selection = 1; - opt->use_riscos_elements = 1; - opt->show_toolbar = 1; - opt->show_print_preview = 0; - opt->theme = strdup("Default"); -} - -void options_read(struct options* opt, char* filename) -{ - messagetrans_control_block cb; - messagetrans_file_flags flags; - char* data; - char* fn; - int size; - - fn = xcalloc(20 + (filename == 0 ? 7 : strlen(filename)), sizeof(char)); - sprintf(fn, "Choices:WWW.NetSurf.%s", filename == 0 ? "Choices" : filename); - - LOG(("Getting file info")); - if (xmessagetrans_file_info(fn, &flags, &size) != NULL) - return; - - /* catch empty choices file - this is a kludge but should work */ - if (size <= 10) { - - LOG(("Empty Choices file - using defaults")); - options_init(opt); - return; - } - - LOG(("Allocating %d bytes", size)); - data = xcalloc((unsigned int)size, sizeof(char)); - messagetrans_open_file(&cb, fn, data); - - opt->http = lookup_yesno(&cb, "USE_HTTP", "N"); - xfree(opt->http_proxy); - opt->http_proxy = lookup(&cb, "HTTP_PROXY", ""); - opt->http_port = lookup_i(&cb, "HTTP_PORT", "8080"); - - opt->use_mouse_gestures = lookup_yesno(&cb, "RO_MOUSE_GESTURES", "N"); - opt->allow_text_selection = lookup_yesno(&cb, "RO_TEXT_SELECTION", "Y"); - opt->use_riscos_elements = lookup_yesno(&cb, "RO_FORM_ELEMENTS", "Y"); - opt->show_toolbar = lookup_yesno(&cb, "RO_SHOW_TOOLBAR", "Y"); - opt->show_print_preview = lookup_yesno(&cb, "RO_SHOW_PRINT", "N"); - - xfree(opt->theme); - opt->theme = lookup(&cb, "RO_THEME", "Default"); - messagetrans_close_file(&cb); - xfree(data); - xfree(fn); -} - -void options_to_ro(struct options* opt, struct ro_choices* ro) -{ - ro->browser.use_mouse_gestures = opt->use_mouse_gestures; - ro->browser.allow_text_selection = opt->allow_text_selection; - ro->browser.use_riscos_elements = opt->use_riscos_elements; - ro->browser.show_toolbar = opt->show_toolbar; - ro->browser.show_print_preview = opt->show_print_preview; - - ro->proxy.http = opt->http; - if (opt->http_proxy != NULL) - strcpy(ro->proxy.http_proxy, opt->http_proxy); - else - strcpy(ro->proxy.http_proxy, ""); - ro->proxy.http_port = opt->http_port; - - if (opt->theme != NULL) - strcpy(ro->theme.name, opt->theme); - else - strcpy(ro->theme.name, "Default"); -} - -void ro_to_options(struct ro_choices* ro, struct options* opt) -{ - opt->use_mouse_gestures = ro->browser.use_mouse_gestures; - opt->allow_text_selection = ro->browser.allow_text_selection; - opt->use_riscos_elements = ro->browser.use_riscos_elements; - opt->show_toolbar = ro->browser.show_toolbar; - opt->show_print_preview = ro->browser.show_print_preview; - - opt->http = ro->proxy.http; - xfree(opt->http_proxy); - opt->http_proxy = strdup(ro->proxy.http_proxy); - opt->http_port = ro->proxy.http_port; - - xfree(opt->theme); - opt->theme = strdup(ro->theme.name); -} - diff --git a/riscos/options.h b/riscos/options.h index 6615edec5..368e1964c 100644 --- a/riscos/options.h +++ b/riscos/options.h @@ -3,6 +3,11 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor + * Copyright 2004 James Bursa + */ + +/** \file + * RISC OS specific options. */ #ifndef _NETSURF_RISCOS_OPTIONS_H_ @@ -10,48 +15,21 @@ #include "netsurf/desktop/options.h" -#define PLATFORM_OPTIONS \ - int use_mouse_gestures;\ - int allow_text_selection;\ - int use_riscos_elements;\ - int show_toolbar;\ - int show_print_preview;\ - \ - char* theme; +extern int option_use_mouse_gestures; +extern int option_allow_text_selection; +extern int option_show_toolbar; +extern char *option_theme; -/* choices made easier for the dialogue boxes. only used by the interface */ +#define EXTRA_OPTION_DEFINE \ +int option_use_mouse_gestures = false;\ +int option_allow_text_selection = true;\ +int option_show_toolbar = true;\ +char *option_theme = 0; -struct browser_choices -{ - int use_mouse_gestures; - int allow_text_selection; - int use_riscos_elements; - int show_toolbar; - int show_print_preview; -} ; - -struct proxy_choices -{ - int http; - char http_proxy[256]; - int http_port; -} ; - -struct theme_choices -{ - char name[256]; -}; - -struct ro_choices -{ - struct browser_choices browser; - struct proxy_choices proxy; - struct theme_choices theme; -}; - -void options_to_ro(struct options* opt, struct ro_choices* ro); -void ro_to_options(struct ro_choices* ro, struct options* opt); +#define EXTRA_OPTION_TABLE \ +{ "use_mouse_gestures", OPTION_BOOL, &option_use_mouse_gestures },\ +{ "allow_text_selection", OPTION_BOOL, &option_allow_text_selection },\ +{ "show_toolbar", OPTION_BOOL, &option_show_toolbar },\ +{ "theme", OPTION_STRING, &option_theme } #endif - -