1 /*
2 * Copyright 2005 Richard Wilson <info@tinct.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 #include <stdbool.h>
20 #include <oslib/hourglass.h>
21
22 #include "utils/nsoption.h"
23 #include "utils/filename.h"
24 #include "utils/messages.h"
25
26 #include "riscos/gui.h"
27 #include "riscos/wimp.h"
28 #include "riscos/wimp_event.h"
29 #include "riscos/configure.h"
30 #include "riscos/configure/configure.h"
31 #include "riscos/dialog.h"
32
33
34 #define CACHE_MEMORY_SIZE 3
35 #define CACHE_MEMORY_DEC 4
36 #define CACHE_MEMORY_INC 5
37 #define CACHE_DISC_SIZE 10
38 #define CACHE_DISC_DEC 11
39 #define CACHE_DISC_INC 12
40 #define CACHE_DISC_EXPIRE 15
41 #define CACHE_DISC_EXPIRE_DEC 16
42 #define CACHE_DISC_EXPIRE_INC 17
43 #define CACHE_DEFAULT_BUTTON 19
44 #define CACHE_CANCEL_BUTTON 20
45 #define CACHE_OK_BUTTON 21
46
47 static bool ro_gui_options_cache_click(wimp_pointer *pointer);
48 static bool ro_gui_options_cache_ok(wimp_w w);
49
ro_gui_options_cache_initialise(wimp_w w)50 bool ro_gui_options_cache_initialise(wimp_w w)
51 {
52 /* set the current values */
53 ro_gui_set_icon_decimal(w, CACHE_MEMORY_SIZE,
54 (nsoption_int(memory_cache_size) * 10) >> 20, 1);
55 ro_gui_set_icon_decimal(w, CACHE_DISC_SIZE,
56 (int) ((nsoption_uint(disc_cache_size)) >> 20), 0);
57 ro_gui_set_icon_decimal(w, CACHE_DISC_EXPIRE,
58 (nsoption_int(disc_cache_age)), 0);
59
60 /* initialise all functions for a newly created window */
61 ro_gui_wimp_event_register_numeric_field(w, CACHE_MEMORY_SIZE,
62 CACHE_MEMORY_INC, CACHE_MEMORY_DEC, 0, 640, 1, 1);
63 ro_gui_wimp_event_register_numeric_field(w, CACHE_DISC_SIZE,
64 CACHE_DISC_INC, CACHE_DISC_DEC, 0, 4095, 1, 0);
65 ro_gui_wimp_event_register_numeric_field(w, CACHE_DISC_EXPIRE,
66 CACHE_DISC_EXPIRE_INC, CACHE_DISC_EXPIRE_DEC, 1, 3650,
67 1, 0);
68 ro_gui_wimp_event_register_mouse_click(w, ro_gui_options_cache_click);
69 ro_gui_wimp_event_register_cancel(w, CACHE_CANCEL_BUTTON);
70 ro_gui_wimp_event_register_ok(w, CACHE_OK_BUTTON,
71 ro_gui_options_cache_ok);
72 ro_gui_wimp_event_set_help_prefix(w, "HelpCacheConfig");
73 ro_gui_wimp_event_memorise(w);
74 return true;
75
76 }
77
ro_gui_options_cache_click(wimp_pointer * pointer)78 bool ro_gui_options_cache_click(wimp_pointer *pointer)
79 {
80 switch (pointer->i) {
81 case CACHE_DEFAULT_BUTTON:
82 /* set the default values */
83 ro_gui_set_icon_decimal(pointer->w, CACHE_MEMORY_SIZE,
84 120, 1);
85 ro_gui_set_icon_decimal(pointer->w, CACHE_DISC_SIZE,
86 1024, 0);
87 ro_gui_set_icon_decimal(pointer->w, CACHE_DISC_EXPIRE,
88 28, 0);
89 return true;
90 }
91 return false;
92 }
93
ro_gui_options_cache_ok(wimp_w w)94 bool ro_gui_options_cache_ok(wimp_w w)
95 {
96 nsoption_set_int(memory_cache_size,
97 (((ro_gui_get_icon_decimal(w,
98 CACHE_MEMORY_SIZE, 1) + 1) << 20) - 1) / 10);
99 nsoption_set_uint(disc_cache_size,
100 (uint) (ro_gui_get_icon_decimal(w,
101 CACHE_DISC_SIZE, 0) << 20));
102 nsoption_set_int(disc_cache_age,
103 ro_gui_get_icon_decimal(w, CACHE_DISC_EXPIRE, 0));
104
105 ro_gui_save_options();
106 return true;
107 }
108