NetSurf
settings.c
Go to the documentation of this file.
1/*
2 * Copyright 2013 Ole Loots <ole@monochrom.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#include <assert.h>
21#include <sys/types.h>
22#include <sys/stat.h>
23#include <fcntl.h>
24#include <time.h>
25#include <limits.h>
26#include <unistd.h>
27#include <string.h>
28#include <stdbool.h>
29#include <cflib.h>
30#include <gem.h>
31
32#include "utils/dirent.h"
33#include "utils/nsoption.h"
34#include "utils/log.h"
35#include "utils/utils.h"
36#include "netsurf/plot_style.h"
37
38#include "atari/gui.h"
39#include "atari/res/netsurf.rsh"
40#include "atari/settings.h"
41#include "atari/deskmenu.h"
42#include "atari/misc.h"
43#include "atari/plot/plot.h"
44#include "atari/bitmap.h"
45#include "atari/findfile.h"
46#include "atari/gemtk/gemtk.h"
47
48extern char options[PATH_MAX];
49extern GRECT desk_area;
50
52static unsigned int tmp_option_disc_cache_size;
53static unsigned int tmp_option_expire_url;
54static unsigned int tmp_option_disc_cache_age;
55static unsigned int tmp_option_font_min_size;
56static unsigned int tmp_option_font_size;
57static unsigned int tmp_option_min_reflow_period;
58static unsigned int tmp_option_max_fetchers;
61
62static int num_locales = 0;
63static char **locales = NULL;
64static short h_aes_win = 0;
65static GUIWIN * settings_guiwin = NULL;
66static OBJECT * dlgtree;
67
68/* Available font engines for the font engine selection popup: */
69static const char *font_engines[] = {
70
71#ifdef WITH_FREETYPE_FONT_DRIVER
72 "freetype",
73#endif
74
75#ifdef WITH_INTERNAL_FONT_DRIVER
76 "internal",
77#endif
78
79#ifdef WITH_VDI_FONT_DRIVER
80 "vdi",
81#endif
82};
83
84/* Available GUI timeouts for the timeout selection popup: */
85static const char *gui_timeouts[] = {
86 "0", "5", "10"
87};
88
89#define OBJ_SELECTED(idx) ((bool)((dlgtree[idx].ob_state & OS_SELECTED)!=0))
90
91#define OBJ_CHECK(idx) (dlgtree[idx].ob_state |= (OS_SELECTED));
92
93#define OBJ_UNCHECK(idx) (dlgtree[idx].ob_state &= ~(OS_SELECTED));
94
95#define OBJ_REDRAW(idx) gemtk_wm_exec_redraw(settings_guiwin, \
96 gemtk_obj_screen_rect(dlgtree, idx));
97
98#define DISABLE_OBJ(idx) (dlgtree[idx].ob_state |= OS_DISABLED); \
99 gemtk_wm_exec_redraw(settings_guiwin, \
100 gemtk_obj_screen_rect(dlgtree, idx));
101
102#define ENABLE_OBJ(idx) (dlgtree[idx].ob_state &= ~(OS_DISABLED)); \
103 gemtk_wm_exec_redraw(settings_guiwin, \
104 gemtk_obj_screen_rect(dlgtree, idx));
105
106#define FORMEVENT(idx) form_event(idx, 0);
107
108#define INPUT_HOMEPAGE_URL_MAX_LEN 44
109#define INPUT_LOCALE_MAX_LEN 6
110#define INPUT_PROXY_HOST_MAX_LEN 31
111#define INPUT_PROXY_USERNAME_MAX_LEN 36
112#define INPUT_PROXY_PASSWORD_MAX_LEN 36
113#define INPUT_PROXY_PORT_MAX_LEN 5
114#define INPUT_MIN_REFLOW_PERIOD_MAX_LEN 4
115#define LABEL_FONT_RENDERER_MAX_LEN 8
116#define LABEL_PATH_MAX_LEN 40
117#define LABEL_ICONSET_MAX_LEN 8
118#define INPUT_TOOLBAR_COLOR_MAX_LEN 6
119
120
121static void display_settings(void);
122static void form_event(int index, int external);
123static void apply_settings(void);
124static void save_settings(void);
125
126
127static void set_text( short idx, char * text, int len )
128{
129 char spare[255];
130
131 if( len > 254 )
132 len = 254;
133 if( text != NULL ) {
134 strncpy(spare, text, 254);
135 } else {
136 strcpy(spare, "");
137 }
138
139 set_string( dlgtree, idx, spare);
140}
141
142
143
144
145/**
146 * Toogle all objects which are directly influenced by other GUI elements
147 * ( like checkbox )
148 */
149static void toggle_objects(void)
150{
151 /* enable / disable (refresh) objects depending on radio button values: */
152 /* Simulate GUI events which trigger refresh of bound elements: */
153 FORMEVENT(SETTINGS_CB_USE_PROXY);
154 FORMEVENT(SETTINGS_CB_PROXY_AUTH);
155 FORMEVENT(SETTINGS_BT_SEL_FONT_RENDERER);
156}
157
158static char **read_locales(void)
159{
160 char buf[PATH_MAX];
161 char tmp_locale[16];
162 char **locales = NULL;
163
164 FILE * fp_locales = NULL;
165
166 atari_find_resource(buf, "languages", "./res/languages");
167
168 fp_locales = fopen(buf, "r");
169
170 if (fp_locales == NULL) {
171 atari_warn_user("Failed to load locales: %s",buf);
172 return(NULL);
173 } else {
174 NSLOG(netsurf, INFO, "Reading locales from: %s...", buf);
175 }
176
177 /* Count items: */
178 num_locales = 0;
179 while (fgets(tmp_locale, 16, fp_locales) != NULL) {
180 num_locales++;
181 }
182
183 locales = malloc(sizeof(char*)*num_locales);
184
185 rewind(fp_locales);
186 int i = 0;
187 while (fgets(tmp_locale, 16, fp_locales) != NULL) {
188 int len = strlen(tmp_locale);
189 tmp_locale[len-1] = 0;
190 len--;
191 locales[i] = malloc(len+1);
192 // do not copy the last \n
193 snprintf(locales[i], 16, "%s", tmp_locale);
194 i++;
195 }
196
197 fclose(fp_locales);
198
199 return(locales);
200}
201
202
203static void save_settings(void)
204{
206 // Save settings
207 nsoption_write( (const char*)&options, NULL, NULL);
208 nsoption_read( (const char*)&options , NULL);
210 form_alert(1, "[1][Some options require an netsurf restart!][OK]");
212}
213
214/* this gets called each time the settings dialog is opened: */
215static void display_settings(void)
216{
217 char spare[255];
218 // read current settings and display them
219
220
221 /* "Browser" tab: */
222 set_text( SETTINGS_EDIT_HOMEPAGE, nsoption_charp(homepage_url),
224
225 if( nsoption_bool(block_advertisements) ) {
226 OBJ_CHECK( SETTINGS_CB_HIDE_ADVERTISEMENT );
227 } else {
228 OBJ_UNCHECK( SETTINGS_CB_HIDE_ADVERTISEMENT );
229 }
230 if( nsoption_bool(target_blank) ) {
231 OBJ_UNCHECK( SETTINGS_CB_DISABLE_POPUP_WINDOWS );
232 } else {
233 OBJ_CHECK( SETTINGS_CB_DISABLE_POPUP_WINDOWS );
234 }
235 if( nsoption_bool(send_referer) ) {
236 OBJ_CHECK( SETTINGS_CB_SEND_HTTP_REFERRER );
237 } else {
238 OBJ_UNCHECK( SETTINGS_CB_SEND_HTTP_REFERRER );
239 }
240 if( nsoption_bool(do_not_track) ) {
241 OBJ_CHECK( SETTINGS_CB_SEND_DO_NOT_TRACK );
242 } else {
243 OBJ_UNCHECK( SETTINGS_CB_SEND_DO_NOT_TRACK );
244 }
245
246 set_text( SETTINGS_BT_SEL_LOCALE,
247 nsoption_charp(accept_language) ? nsoption_charp(accept_language) : (char*)"en",
249
250 sprintf(spare, "%d", nsoption_int(atari_gui_poll_timeout));
251 set_text(SETTINGS_BT_GUI_TOUT, spare, 2);
252
254 snprintf( spare, 255, "%02d", nsoption_int(expire_url) );
255 set_text( SETTINGS_EDIT_HISTORY_AGE, spare, 3);
256
257 /* "Cache" tab: */
258 tmp_option_memory_cache_size = nsoption_int(memory_cache_size) / (1024*1024);
259 snprintf( spare, 255, "%u", tmp_option_memory_cache_size );
260 set_text( SETTINGS_STR_MAX_MEM_CACHE, spare, 4 );
261
262 tmp_option_disc_cache_size = nsoption_int(disc_cache_size) / (1024*1024);
263 snprintf( spare, 255, "%u", tmp_option_disc_cache_size );
264 set_text( SETTINGS_STR_MAX_DISC_CACHE, spare, 4 );
265
266 tmp_option_disc_cache_age = nsoption_int(disc_cache_age);
267 snprintf( spare, 255, "%02u", tmp_option_disc_cache_age );
268 set_text( SETTINGS_EDIT_CACHE_AGE, spare, 3 );
269
270 /* "Paths" tab: */
271 set_text( SETTINGS_EDIT_DOWNLOAD_PATH, nsoption_charp(downloads_path),
273 set_text( SETTINGS_EDIT_HOTLIST_FILE, nsoption_charp(hotlist_file),
275 set_text( SETTINGS_EDIT_CA_BUNDLE, nsoption_charp(ca_bundle),
277 set_text( SETTINGS_EDIT_CA_CERTS_PATH, nsoption_charp(ca_path),
279 set_text( SETTINGS_EDIT_EDITOR, nsoption_charp(atari_editor),
281
282 /* "Rendering" tab: */
283 set_text( SETTINGS_BT_SEL_FONT_RENDERER, nsoption_charp(atari_font_driver),
285 SET_BIT(dlgtree[SETTINGS_CB_TRANSPARENCY].ob_state,
286 OS_SELECTED, nsoption_int(atari_transparency) ? 1 : 0 );
287 SET_BIT(dlgtree[SETTINGS_CB_ENABLE_ANIMATION].ob_state,
288 OS_SELECTED, nsoption_bool(animate_images) ? 1 : 0 );
289 SET_BIT(dlgtree[SETTINGS_CB_FG_IMAGES].ob_state,
290 OS_SELECTED, nsoption_bool(foreground_images) ? 1 : 0 );
291 SET_BIT(dlgtree[SETTINGS_CB_BG_IMAGES].ob_state,
292 OS_SELECTED, nsoption_bool(background_images) ? 1 : 0 );
293
294
295 // TODO: enable this option?
296 /* SET_BIT(dlgtree[SETTINGS_CB_INCREMENTAL_REFLOW].ob_state,
297 OS_SELECTED, nsoption_bool(incremental_reflow) ? 1 : 0 );*/
298
299 SET_BIT(dlgtree[SETTINGS_CB_ANTI_ALIASING].ob_state,
300 OS_SELECTED, nsoption_int(atari_font_monochrom) ? 0 : 1 );
301
302
303 // TODO: activate this option?
304 tmp_option_min_reflow_period = nsoption_int(min_reflow_period);
305 snprintf( spare, 255, "%04u", tmp_option_min_reflow_period );
306 set_text( SETTINGS_EDIT_MIN_REFLOW_PERIOD, spare,
308
309
310 /* "Network" tab: */
311 set_text( SETTINGS_EDIT_PROXY_HOST, nsoption_charp(http_proxy_host),
313 snprintf( spare, 255, "%5d", nsoption_int(http_proxy_port) );
314 set_text( SETTINGS_EDIT_PROXY_PORT, spare,
316
317 set_text( SETTINGS_EDIT_PROXY_USERNAME, nsoption_charp(http_proxy_auth_user),
319 set_text( SETTINGS_EDIT_PROXY_PASSWORD, nsoption_charp(http_proxy_auth_pass),
321 SET_BIT(dlgtree[SETTINGS_CB_USE_PROXY].ob_state,
322 OS_SELECTED, nsoption_bool(http_proxy) ? 1 : 0 );
323 SET_BIT(dlgtree[SETTINGS_CB_PROXY_AUTH].ob_state,
324 OS_SELECTED, nsoption_int(http_proxy_auth) ? 1 : 0 );
325
326 tmp_option_max_cached_fetch_handles = nsoption_int(max_cached_fetch_handles);
327 snprintf( spare, 255, "%2d", nsoption_int(max_cached_fetch_handles) );
328 set_text( SETTINGS_EDIT_MAX_CACHED_CONNECTIONS, spare , 2 );
329
331 snprintf( spare, 255, "%2d", nsoption_int(max_fetchers) );
332 set_text( SETTINGS_EDIT_MAX_FETCHERS, spare , 2 );
333
334 tmp_option_max_fetchers_per_host = nsoption_int(max_fetchers_per_host);
335 snprintf( spare, 255, "%2d", nsoption_int(max_fetchers_per_host) );
336 set_text( SETTINGS_EDIT_MAX_FETCHERS_PER_HOST, spare , 2 );
337
338
339 /* "Style" tab: */
340 tmp_option_font_min_size = nsoption_int(font_min_size);
341 snprintf( spare, 255, "%3d", nsoption_int(font_min_size) );
342 set_text( SETTINGS_EDIT_MIN_FONT_SIZE, spare , 3 );
343
345 snprintf( spare, 255, "%3d", nsoption_int(font_size) );
346 set_text( SETTINGS_EDIT_DEF_FONT_SIZE, spare , 3 );
347
349}
350
351static void handle_filesystem_select_button(short rsc_bt)
352{
353 bool require_path = false;
354 bool is_folder = false;
355 short rsc_te = 0; // The textarea that is bound to the button
356 const char * title = "";
357 const char * path = NULL;
358
359 // TODO: localize String:
360 switch (rsc_bt) {
361
362
363 case SETTINGS_BT_SEL_DOWNLOAD_DIR:
364 title = "Select Download Directory:";
365 rsc_te = SETTINGS_EDIT_DOWNLOAD_PATH;
366 require_path = true;
367 break;
368
369 case SETTINGS_BT_SEL_HOTLIST:
370 title = "Select Hotlist File:";
371 rsc_te = SETTINGS_EDIT_HOTLIST_FILE;
372 break;
373
374 case SETTINGS_BT_SEL_CA_BUNDLE:
375 title = "Select CA Bundle File:";
376 rsc_te = SETTINGS_EDIT_CA_BUNDLE;
377 break;
378
379 case SETTINGS_BT_SEL_CA_CERTS:
380 title = "Select Certs Directory:";
381 rsc_te = SETTINGS_EDIT_CA_CERTS_PATH;
382 require_path = true;
383 break;
384
385 case SETTINGS_BT_SEL_EDITOR:
386 title = "Select Editor Application:";
387 rsc_te = SETTINGS_EDIT_EDITOR;
388 break;
389
390 default:
391 break;
392 };
393
394 assert(rsc_te != 0);
395
396 if (require_path == false) {
397 path = file_select(title, "");
398 if (path != NULL) {
399 gemtk_obj_set_str_safe(dlgtree, rsc_te, path);
400 }
401 }
402 else {
403 do {
404 /* display file selector: */
405 path = file_select(title, "");
406 if (path) {
407 is_folder = is_dir(path);
408 }
409 if ((is_folder == false) && (path != NULL)) {
410 gemtk_msg_box_show(GEMTK_MSG_BOX_ALERT, "Folder Required!");
411 }
412 } while ((is_folder == false) && (path != NULL));
413
414 if ((is_folder == true) && (path != NULL)) {
415 gemtk_obj_set_str_safe(dlgtree, rsc_te, path);
416 }
417 }
418
419 OBJ_UNCHECK(rsc_bt);
420 OBJ_REDRAW(rsc_bt);
421 OBJ_REDRAW(rsc_te);
422}
423
424static void form_event(int index, int external)
425{
426 char spare[255];
427 bool is_button = false;
428 bool checked = OBJ_SELECTED(index);
429 char * tmp;
430 MENU pop_menu, me_data;
431
432 short x, y;
433 int choice;
434
435 switch(index) {
436
437 case SETTINGS_CB_USE_PROXY:
438 if( checked ) {
439 ENABLE_OBJ(SETTINGS_EDIT_PROXY_HOST);
440 ENABLE_OBJ(SETTINGS_EDIT_PROXY_PORT);
441 ENABLE_OBJ(SETTINGS_CB_PROXY_AUTH);
442 } else {
443 DISABLE_OBJ(SETTINGS_EDIT_PROXY_HOST);
444 DISABLE_OBJ(SETTINGS_EDIT_PROXY_PORT);
445 DISABLE_OBJ(SETTINGS_CB_PROXY_AUTH);
446 }
447 FORMEVENT(SETTINGS_CB_PROXY_AUTH);
448 OBJ_REDRAW(SETTINGS_CB_USE_PROXY);
449 break;
450
451 case SETTINGS_CB_PROXY_AUTH:
452 if( checked && OBJ_SELECTED( SETTINGS_CB_USE_PROXY ) ) {
453 ENABLE_OBJ(SETTINGS_EDIT_PROXY_USERNAME);
454 ENABLE_OBJ(SETTINGS_EDIT_PROXY_PASSWORD);
455 } else {
456 DISABLE_OBJ(SETTINGS_EDIT_PROXY_USERNAME);
457 DISABLE_OBJ(SETTINGS_EDIT_PROXY_PASSWORD);
458 }
459 break;
460
461 case SETTINGS_CB_ENABLE_ANIMATION:
462 break;
463
464 case SETTINGS_BT_SEL_FONT_RENDERER:
465 if( external ) {
466 objc_offset(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER, &x, &y);
467 tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER);
468 // point mn_tree tree to font renderer popup:
469 pop_menu.mn_tree = gemtk_obj_create_popup_tree(font_engines,
470 NOF_ELEMENTS(font_engines), tmp, false,
471 -1, -1);
472
473 assert(pop_menu.mn_tree != NULL);
474
475 pop_menu.mn_menu = 0;
476 pop_menu.mn_item = 1;
477 pop_menu.mn_scroll = SCROLL_NO;
478 pop_menu.mn_keystate = 0;
479
480 /* Show the popup: */
481 menu_popup(&pop_menu, x, y, &me_data);
482 choice = me_data.mn_item;
483
484 /* Process selection: */
485 if (choice > 0 && choice <= (short)NOF_ELEMENTS(font_engines)) {
486 get_string(pop_menu.mn_tree, choice, spare);
487 set_text(SETTINGS_BT_SEL_FONT_RENDERER,
488 (char*)&spare[2],
490 OBJ_REDRAW(SETTINGS_BT_SEL_FONT_RENDERER);
491 }
492
493 gemtk_obj_destroy_popup_tree(pop_menu.mn_tree);
494 }
495 tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER);
496 if (strcasecmp(tmp, "freetype") == 0) {
497 ENABLE_OBJ(SETTINGS_CB_ANTI_ALIASING);
498 } else {
499 DISABLE_OBJ(SETTINGS_CB_ANTI_ALIASING);
500 }
501 break;
502
503 case SETTINGS_BT_SEL_LOCALE:
504 objc_offset(dlgtree, SETTINGS_BT_SEL_LOCALE, &x, &y);
505
506 if(num_locales < 1 || locales == NULL){
508 }
509
510 if (num_locales < 1 || locales == NULL) {
511 // point mn_tree tree to states popup:
512 num_locales = 15;
513 pop_menu.mn_tree = gemtk_obj_get_tree(POP_LANGUAGE);
514 pop_menu.mn_item = POP_LANGUAGE_CS;
515 } else {
516 // point mn_tree tree to dynamic list:
517 tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_LOCALE);
518 pop_menu.mn_tree = gemtk_obj_create_popup_tree((const char**)locales,
519 num_locales, tmp, false,
520 -1, 100);
521
522 pop_menu.mn_item = 0;
523 }
524
525 pop_menu.mn_menu = 0;
526 pop_menu.mn_scroll = SCROLL_YES;
527 pop_menu.mn_keystate = 0;
528
529 /* display popup: */
530 menu_popup(&pop_menu, x, y, &me_data);
531
532 /* Process user selection: */
533 choice = me_data.mn_item;
534 if( choice > 0 && choice <= num_locales ) {
535 get_string(pop_menu.mn_tree, choice, spare);
536 set_text(SETTINGS_BT_SEL_LOCALE, (char*)&spare[2], 5);
537 }
538
539 gemtk_obj_destroy_popup_tree(pop_menu.mn_tree);
540
541 OBJ_REDRAW(SETTINGS_BT_SEL_LOCALE);
542 break;
543
544 case SETTINGS_BT_GUI_TOUT:
545 objc_offset(dlgtree, SETTINGS_BT_GUI_TOUT, &x, &y);
546 tmp = gemtk_obj_get_text(dlgtree, SETTINGS_BT_GUI_TOUT);
547 pop_menu.mn_tree = gemtk_obj_create_popup_tree(gui_timeouts,
548 NOF_ELEMENTS(gui_timeouts), tmp, false, -1,
549 100);
550
551 pop_menu.mn_item = 0;
552 pop_menu.mn_menu = 0;
553 pop_menu.mn_scroll = SCROLL_NO;
554 pop_menu.mn_keystate = 0;
555
556 /* Display popup: */
557 menu_popup(&pop_menu, x, y, &me_data);
558
559 /* Process user selection: */
560 choice = me_data.mn_item;
561 if( choice > 0 && choice <= (int)NOF_ELEMENTS(gui_timeouts)) {
562 get_string(pop_menu.mn_tree, choice, spare);
563 set_text(SETTINGS_BT_GUI_TOUT, (char*)&spare[2], 5);
564 }
565
566 gemtk_obj_destroy_popup_tree(pop_menu.mn_tree);
567
568 OBJ_REDRAW(SETTINGS_BT_GUI_TOUT);
569 break;
570
571 case SETTINGS_BT_SEL_DOWNLOAD_DIR:
572 case SETTINGS_BT_SEL_HOTLIST:
573 case SETTINGS_BT_SEL_CA_BUNDLE:
574 case SETTINGS_BT_SEL_CA_CERTS:
575 case SETTINGS_BT_SEL_EDITOR:
577 break;
578
579 case SETTINGS_INC_MEM_CACHE:
580 case SETTINGS_DEC_MEM_CACHE:
581 if( index == SETTINGS_DEC_MEM_CACHE )
583 else
585
590 snprintf( spare, 255, "%02u", tmp_option_memory_cache_size );
591 set_text( SETTINGS_STR_MAX_MEM_CACHE, spare, 5 );
592 is_button = true;
593 OBJ_REDRAW(SETTINGS_STR_MAX_MEM_CACHE);
594 break;
595
596 case SETTINGS_INC_DISC_CACHE:
597 case SETTINGS_DEC_DISC_CACHE:
598 if( index == SETTINGS_DEC_DISC_CACHE )
600 else
602
605 if( tmp_option_disc_cache_size > 9999 )
607 snprintf( spare, 255, "%02u", tmp_option_disc_cache_size );
608 set_text( SETTINGS_STR_MAX_DISC_CACHE, spare, 5 );
609 is_button = true;
610 OBJ_REDRAW(SETTINGS_STR_MAX_DISC_CACHE);
611 break;
612
613 case SETTINGS_INC_CACHE_AGE:
614 case SETTINGS_DEC_CACHE_AGE:
615 if( index == SETTINGS_INC_CACHE_AGE )
617 else
619
622
623 snprintf( spare, 255, "%02u", tmp_option_disc_cache_age );
624 set_text( SETTINGS_EDIT_CACHE_AGE, spare, 2 );
625 is_button = true;
626 OBJ_REDRAW(SETTINGS_EDIT_CACHE_AGE);
627 break;
628
629 case SETTINGS_INC_CACHED_CONNECTIONS:
630 case SETTINGS_DEC_CACHED_CONNECTIONS:
631 if( index == SETTINGS_INC_CACHED_CONNECTIONS )
633 else
637
638 snprintf( spare, 255, "%02u", tmp_option_max_cached_fetch_handles );
639 set_text( SETTINGS_EDIT_MAX_CACHED_CONNECTIONS, spare, 2 );
640 is_button = true;
641 OBJ_REDRAW(SETTINGS_EDIT_MAX_CACHED_CONNECTIONS);
642 break;
643
644 case SETTINGS_INC_MAX_FETCHERS:
645 case SETTINGS_DEC_MAX_FETCHERS:
646 if( index == SETTINGS_INC_MAX_FETCHERS )
648 else
650 if( tmp_option_max_fetchers > 31 )
652
653 snprintf( spare, 255, "%02u", tmp_option_max_fetchers );
654 set_text( SETTINGS_EDIT_MAX_FETCHERS, spare, 2 );
655 is_button = true;
656 OBJ_REDRAW(SETTINGS_EDIT_MAX_FETCHERS);
657 break;
658
659 case SETTINGS_INC_MAX_FETCHERS_PER_HOST:
660 case SETTINGS_DEC_MAX_FETCHERS_PER_HOST:
661 if( index == SETTINGS_INC_MAX_FETCHERS_PER_HOST )
663 else
667
668 snprintf( spare, 255, "%02u", tmp_option_max_fetchers_per_host );
669 set_text( SETTINGS_EDIT_MAX_FETCHERS_PER_HOST, spare, 2 );
670 is_button = true;
671 OBJ_REDRAW(SETTINGS_EDIT_MAX_FETCHERS_PER_HOST);
672 break;
673
674 case SETTINGS_INC_HISTORY_AGE:
675 case SETTINGS_DEC_HISTORY_AGE:
676 if( index == SETTINGS_INC_HISTORY_AGE )
678 else
680
681 if( tmp_option_expire_url > 99 )
683
684 snprintf( spare, 255, "%02u", tmp_option_expire_url );
685 set_text( SETTINGS_EDIT_HISTORY_AGE, spare, 2 );
686 is_button = true;
687 OBJ_REDRAW(SETTINGS_EDIT_HISTORY_AGE);
688 break;
689
690 case SETTINGS_INC_MIN_FONT_SIZE:
691 case SETTINGS_DEC_MIN_FONT_SIZE:
692 if( index == SETTINGS_INC_MIN_FONT_SIZE )
694 else
696
697 if( tmp_option_font_min_size > 500 )
699 if( tmp_option_font_min_size < 10 )
701
702 snprintf( spare, 255, "%03u", tmp_option_font_min_size );
703 set_text( SETTINGS_EDIT_MIN_FONT_SIZE, spare, 3 );
704 is_button = true;
705 OBJ_REDRAW(SETTINGS_EDIT_MIN_FONT_SIZE);
706 break;
707
708 case SETTINGS_INC_DEF_FONT_SIZE:
709 case SETTINGS_DEC_DEF_FONT_SIZE:
710 if( index == SETTINGS_INC_DEF_FONT_SIZE )
712 else
714
715 if( tmp_option_font_size > 999 )
717 if( tmp_option_font_size < 50 )
719
720 snprintf( spare, 255, "%03u", tmp_option_font_size );
721 set_text( SETTINGS_EDIT_DEF_FONT_SIZE, spare, 3 );
722 is_button = true;
723 OBJ_REDRAW(SETTINGS_EDIT_DEF_FONT_SIZE);
724 break;
725
726 case SETTINGS_INC_INCREMENTAL_REFLOW:
727 case SETTINGS_DEC_INCREMENTAL_REFLOW:
728 if( index == SETTINGS_INC_INCREMENTAL_REFLOW )
730 else
732
735
736 snprintf( spare, 255, "%04u", tmp_option_min_reflow_period );
737 set_text( SETTINGS_EDIT_MIN_REFLOW_PERIOD, spare, 4 );
738 is_button = true;
739 OBJ_REDRAW(SETTINGS_EDIT_MIN_REFLOW_PERIOD);
740 break;
741
742 default:
743 break;
744 }
745
746 if( is_button ) {
747 // remove selection indicator from button element:
748 OBJ_UNCHECK(index);
749 OBJ_REDRAW(index);
750 }
751}
752
753
754static void apply_settings(void)
755{
756 /* "Network" tab: */
757 nsoption_set_bool(http_proxy, OBJ_SELECTED(SETTINGS_CB_USE_PROXY));
758 if ( OBJ_SELECTED(SETTINGS_CB_PROXY_AUTH) ) {
760 } else {
762 }
763 nsoption_set_charp(http_proxy_auth_pass,
764 gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_PROXY_PASSWORD));
765 nsoption_set_charp(http_proxy_auth_user,
766 gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_PROXY_USERNAME));
767 nsoption_set_charp(http_proxy_host,
768 gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_PROXY_HOST));
769 nsoption_set_int(http_proxy_port,
770 atoi( gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_PROXY_PORT) ));
771 nsoption_set_int(max_fetchers_per_host,
772 atoi( gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_MAX_FETCHERS_PER_HOST)));
773 nsoption_set_int(max_cached_fetch_handles,
774 atoi( gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_MAX_CACHED_CONNECTIONS)));
775 nsoption_set_int(max_fetchers,
776 atoi( gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_MAX_FETCHERS) ));
777 nsoption_set_bool(foreground_images,
778 OBJ_SELECTED( SETTINGS_CB_FG_IMAGES ));
779 nsoption_set_bool(background_images,
780 OBJ_SELECTED( SETTINGS_CB_BG_IMAGES ));
781
782 /* "Style" tab: */
785
786 /* "Rendering" tab: */
787 nsoption_set_charp(atari_font_driver,
788 gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_FONT_RENDERER));
789 nsoption_set_int(atari_transparency,
790 OBJ_SELECTED(SETTINGS_CB_TRANSPARENCY));
791 nsoption_set_bool(animate_images,
792 OBJ_SELECTED(SETTINGS_CB_ENABLE_ANIMATION));
793 /* nsoption_set_bool(incremental_reflow,
794 OBJ_SELECTED(SETTINGS_CB_INCREMENTAL_REFLOW));*/
796 nsoption_set_int(atari_font_monochrom,
797 !OBJ_SELECTED( SETTINGS_CB_ANTI_ALIASING ));
798
799 /* "Paths" tabs: */
800 nsoption_set_charp(ca_bundle,
801 gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_CA_BUNDLE));
802 nsoption_set_charp(ca_path,
803 gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_CA_CERTS_PATH));
804 nsoption_set_charp(homepage_url,
805 gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_CA_CERTS_PATH));
806 nsoption_set_charp(hotlist_file,
807 gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_HOTLIST_FILE));
808 nsoption_set_charp(atari_editor,
809 gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_EDITOR));
810 nsoption_set_charp(downloads_path,
811 gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_DOWNLOAD_PATH));
812
813 /* "Cache" tab: */
814 tmp_option_memory_cache_size = atoi(gemtk_obj_get_text(dlgtree,
815 SETTINGS_STR_MAX_MEM_CACHE));
816 tmp_option_expire_url = atoi(gemtk_obj_get_text(dlgtree,
817 SETTINGS_EDIT_HISTORY_AGE));
818 tmp_option_disc_cache_size = atoi(gemtk_obj_get_text(dlgtree,
819 SETTINGS_STR_MAX_DISC_CACHE));
820 tmp_option_disc_cache_age = atoi(gemtk_obj_get_text(dlgtree,
821 SETTINGS_EDIT_CACHE_AGE));
822 nsoption_set_int(memory_cache_size,
823 tmp_option_memory_cache_size * (1024*1024));
824
826
827 nsoption_set_int(disc_cache_size, tmp_option_disc_cache_size * (1024*1024));
828
830
831
832 /* "Browser" tab: */
833 nsoption_set_bool(target_blank,
834 !OBJ_SELECTED(SETTINGS_CB_DISABLE_POPUP_WINDOWS));
835 nsoption_set_bool(block_advertisements,
836 OBJ_SELECTED(SETTINGS_CB_HIDE_ADVERTISEMENT));
837 nsoption_set_charp(accept_language,
838 gemtk_obj_get_text(dlgtree, SETTINGS_BT_SEL_LOCALE));
839 nsoption_set_int(atari_gui_poll_timeout,
840 atoi(gemtk_obj_get_text(dlgtree, SETTINGS_BT_GUI_TOUT)));
841 nsoption_set_bool(send_referer,
842 OBJ_SELECTED(SETTINGS_CB_SEND_HTTP_REFERRER));
843 nsoption_set_bool(do_not_track,
844 OBJ_SELECTED(SETTINGS_CB_SEND_DO_NOT_TRACK));
845 nsoption_set_charp(homepage_url,
846 gemtk_obj_get_text(dlgtree, SETTINGS_EDIT_HOMEPAGE));
847}
848
849static short on_aes_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
850{
851 short retval = 0;
852
853 if ((ev_out->emo_events & MU_MESAG) != 0) {
854 // handle message
855 // printf("settings win msg: %d\n", msg[0]);
856 switch (msg[0]) {
857
858
859 case WM_CLOSED:
860 // TODO: this needs to iterate through all gui windows and
861 // check if the rootwin is this window...
863 break;
864
865 case WM_SIZED:
866 gemtk_wm_update_slider(win, GEMTK_WM_VH_SLIDER);
867 break;
868
869 case WM_MOVED:
870 break;
871
872 case WM_TOOLBAR:
873 switch(msg[4]) {
874 case TOOLBAR_SETTINGS_SAVE:
876 break;
877
878 case TOOLBAR_SETTINGS_ABORT:
880 break;
881 default:
882 break;
883 }
884 break;
885
886 case GEMTK_WM_WM_FORM_CLICK:
887 form_event(msg[4], 1);
888 break;
889
890 default:
891 break;
892 }
893 }
894
895 if ((ev_out->emo_events & MU_KEYBD) != 0) {
896 }
897
898 if ((ev_out->emo_events & MU_BUTTON) != 0) {
899 }
900
901 return(retval);
902}
903
905{
906 if (h_aes_win == 0) {
907
908 GRECT curr, area;
909 OBJECT * toolbartree;
910 struct gemtk_wm_scroll_info_s *slid;
911 uint32_t kind = CLOSER | NAME | MOVER | VSLIDE | HSLIDE | UPARROW
912 | DNARROW | LFARROW | RTARROW | SIZER;
913
914 dlgtree = gemtk_obj_get_tree(SETTINGS);
915 toolbartree = gemtk_obj_get_tree(TOOLBAR_SETTINGS);
916 area.g_x = area.g_y = 0;
917 area.g_w = MIN(dlgtree->ob_width, desk_area.g_w);
918 area.g_h = MIN(dlgtree->ob_height, desk_area.g_h);
919 wind_calc_grect(WC_BORDER, kind, &area, &area);
920 h_aes_win = wind_create_grect(kind, &area);
921 wind_set_str(h_aes_win, WF_NAME, "Settings");
922 settings_guiwin = gemtk_wm_add(h_aes_win, GEMTK_WM_FLAG_DEFAULTS,
924 curr.g_w = MIN(dlgtree->ob_width, desk_area.g_w);
925 curr.g_h = MIN(dlgtree->ob_height, desk_area.g_h-64);
926 curr.g_x = 1;
927 curr.g_y = (desk_area.g_h / 2) - (curr.g_h / 2);
928
929 wind_calc_grect(WC_BORDER, kind, &curr, &curr);
930
931 dlgtree->ob_x = curr.g_x;
932 dlgtree->ob_y = curr.g_y;
933
934 /* set current config values: */
936
937 wind_open_grect(h_aes_win, &curr);
938
939 gemtk_wm_set_toolbar(settings_guiwin, toolbartree, 0, 0);
940 gemtk_wm_set_form(settings_guiwin, dlgtree, 0);
941 gemtk_wm_set_scroll_grid(settings_guiwin, 32, 32);
942 gemtk_wm_get_grect(settings_guiwin, GEMTK_WM_AREA_CONTENT, &area);
943
944 slid = gemtk_wm_get_scroll_info(settings_guiwin);
945 gemtk_wm_set_content_units(settings_guiwin,
946 (dlgtree->ob_width/slid->x_unit_px),
947 (dlgtree->ob_height/slid->y_unit_px));
948 gemtk_wm_update_slider(settings_guiwin, GEMTK_WM_VH_SLIDER);
949 }
950}
951
953{
954 NSLOG(netsurf, INFO, "closing");
955 gemtk_wm_remove(settings_guiwin);
956 settings_guiwin = NULL;
957 wind_close(h_aes_win);
958 wind_delete(h_aes_win);
959 h_aes_win = 0;
960 NSLOG(netsurf, INFO, "Done");
961}
962
char * atari_find_resource(char *buf, const char *filename, const char *def)
Definition: findfile.c:80
#define PATH_MAX
Definition: gui.h:31
const char * file_select(const char *title, const char *name)
Show default file selector.
Definition: misc.c:363
nserror atari_warn_user(const char *warning, const char *detail)
Warn the user of an event.
Definition: misc.c:56
void deskmenu_update(void)
Refresh the desk menu, reflecting netsurf current state.
Definition: deskmenu.c:823
directory traversal and entry
#define NOF_ELEMENTS(array)
Definition: search.c:67
Atari bitmap handling implementation.
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
#define MIN(a, b)
Definition: os3support.h:51
plotter style interfaces, generic styles and style colour helpers.
static const char * font_engines[]
Definition: settings.c:69
static unsigned int tmp_option_min_reflow_period
Definition: settings.c:57
static void form_event(int index, int external)
Definition: settings.c:424
static unsigned int tmp_option_max_fetchers
Definition: settings.c:58
static const char * gui_timeouts[]
Definition: settings.c:85
static unsigned tmp_option_memory_cache_size
Definition: settings.c:51
static void toggle_objects(void)
Toogle all objects which are directly influenced by other GUI elements ( like checkbox )
Definition: settings.c:149
static void save_settings(void)
Definition: settings.c:203
static unsigned int tmp_option_max_fetchers_per_host
Definition: settings.c:59
#define DISABLE_OBJ(idx)
Definition: settings.c:98
#define INPUT_PROXY_HOST_MAX_LEN
Definition: settings.c:110
GRECT desk_area
Definition: gui.c:79
char options[PATH_MAX]
Definition: gui.c:91
static short on_aes_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
Definition: settings.c:849
static void set_text(short idx, char *text, int len)
Definition: settings.c:127
static GUIWIN * settings_guiwin
Definition: settings.c:65
static int num_locales
Definition: settings.c:62
static unsigned int tmp_option_disc_cache_size
Definition: settings.c:52
static unsigned int tmp_option_disc_cache_age
Definition: settings.c:54
#define INPUT_PROXY_PORT_MAX_LEN
Definition: settings.c:113
static short h_aes_win
Definition: settings.c:64
void close_settings(void)
Definition: settings.c:952
#define LABEL_FONT_RENDERER_MAX_LEN
Definition: settings.c:115
static unsigned int tmp_option_expire_url
Definition: settings.c:53
#define INPUT_LOCALE_MAX_LEN
Definition: settings.c:109
#define OBJ_UNCHECK(idx)
Definition: settings.c:93
#define ENABLE_OBJ(idx)
Definition: settings.c:102
void open_settings(void)
Definition: settings.c:904
#define INPUT_PROXY_PASSWORD_MAX_LEN
Definition: settings.c:112
static void display_settings(void)
Definition: settings.c:215
#define INPUT_MIN_REFLOW_PERIOD_MAX_LEN
Definition: settings.c:114
static void handle_filesystem_select_button(short rsc_bt)
Definition: settings.c:351
static unsigned int tmp_option_max_cached_fetch_handles
Definition: settings.c:60
#define OBJ_SELECTED(idx)
Definition: settings.c:89
static unsigned int tmp_option_font_min_size
Definition: settings.c:55
static char ** read_locales(void)
Definition: settings.c:158
#define OBJ_REDRAW(idx)
Definition: settings.c:95
#define INPUT_HOMEPAGE_URL_MAX_LEN
Definition: settings.c:108
static OBJECT * dlgtree
Definition: settings.c:66
#define FORMEVENT(idx)
Definition: settings.c:106
#define OBJ_CHECK(idx)
Definition: settings.c:91
#define INPUT_PROXY_USERNAME_MAX_LEN
Definition: settings.c:111
static void apply_settings(void)
Definition: settings.c:754
static unsigned int tmp_option_font_size
Definition: settings.c:56
static char ** locales
Definition: settings.c:63
#define LABEL_PATH_MAX_LEN
Definition: settings.c:116
Interface to utility string handling.
Interface to time operations.
nserror nsoption_read(const char *path, struct nsoption_s *opts)
Read choices file and set them in the passed table.
Definition: nsoption.c:696
nserror nsoption_write(const char *path, struct nsoption_s *opts, struct nsoption_s *defs)
Write options that have changed from the defaults to a file.
Definition: nsoption.c:786
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:331
#define nsoption_int(OPTION)
Get the value of an integer option.
Definition: nsoption.h:313
#define nsoption_set_int(OPTION, VALUE)
set an integer option in the default table
Definition: nsoption.h:348
#define nsoption_set_bool(OPTION, VALUE)
set a boolean option in the default table
Definition: nsoption.h:344
#define nsoption_set_charp(OPTION, VALUE)
set string option in default table
Definition: nsoption.h:372
@ OPTION_HTTP_PROXY_AUTH_NONE
Definition: nsoption.h:86
@ OPTION_HTTP_PROXY_AUTH_BASIC
Definition: nsoption.h:87
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:304
Interface to a number of general purpose functionality.
bool is_dir(const char *path)
Check if a directory exists.
Definition: utils.c:94
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition: plot.c:821
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978