summaryrefslogtreecommitdiffstats
path: root/src/schemes/about/preferences.c
blob: 1637ee4fa7272d28ff53a3e866a8795ff640b329 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
 * about:preferences
 *
 * Copyright (C) 2017  Patrick McDermott
 *
 * This file is part of Marquee.
 *
 * Marquee is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Marquee is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Marquee.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "paths.h"

#include <glib.h>
#include <webkit2/webkit2.h>

#include "../../application.h"
#include "../../config/config.h"
#include "../../i18n.h"
#include "../../utils/html.h"
#include "../about.h"

static void
save_pref(gchar *key, gchar *value, MqConfig *config)
{
	if (key[0] != '_') {
		mq_config_set(config, key, value);
	}
}

#define GEN_BOOL(NAME, LABEL) mq_html_input_checkbox(NAME, LABEL, \
	mq_config_get_boolean(config, NAME))
#define GEN_INT( NAME, LABEL, MIN, STEP, MAX) mq_html_input_number_i( \
	NAME, LABEL, MIN, STEP, MAX, mq_config_get_integer(config, NAME))
#define GEN_DBL( NAME, LABEL, MIN, STEP, MAX) mq_html_input_number_d( \
	NAME, LABEL, MIN, STEP, MAX, mq_config_get_double(config, NAME))
#define GEN_STR( NAME, LABEL) mq_html_input_text(NAME, LABEL, \
	mq_config_get_string(config, NAME), FALSE)
#define GEN_STRL(NAME, LABEL) mq_html_input_text(NAME, LABEL, \
	mq_config_get_string(config, NAME), FALSE)
#define GEN_SLCT(NAME, LABEL, ...) mq_html_input_select(NAME, LABEL, \
	mq_config_get_string(config, NAME), NULL, NULL, __VA_ARGS__, NULL)

static gchar *
gen_page_general(MqConfig *config)
{
	return mq_html_container("div", NULL,
		mq_html_h3(_("Web Browsing")),
		GEN_SLCT("tabs.new",
			_("New tab page"),
			"home",  _("Home page"),
			"blank", _("Blank page")),
		GEN_STR ("tabs.home",
			_("Home page")),
		GEN_BOOL("tabs.background",
			_("Open new tabs in the background")),
		GEN_BOOL("tabs.warn-on-close",
			_("Warn when closing multiple tabs or windows")),

		mq_html_h3(_("Navigation and Accessibility")),
		GEN_BOOL("navigation.smooth-scrolling",
			_("Enable smooth scrolling")),
		GEN_BOOL("navigation.tabbing",
			_("Enable tabbing navigation (cycling focus by tab "
				"key)")),
		GEN_BOOL("navigation.caret",
			_("Enable caret (text cursor) navigation")),
		GEN_BOOL("navigation.spatial",
			_("Enable spatial navigation between elements by arrow "
				"keys")),

		mq_html_h3(_("Spell Checking")),
		GEN_BOOL("spell.enable",
			_("Enable spell checking")),
		GEN_STRL("spell.langs",
			_("Spell checking languages")),

		mq_html_h3(_("Miscellaneous")),
		GEN_BOOL("display.textarea.resize.enable",
			_("Enable resizable text areas")),
		GEN_BOOL("devtools.enable",
			_("Enable developer tools")),

		mq_html_h3(_("Compatibility")),
		GEN_STR ("compatibility.user-agent",
			_("User agent identity")),
		GEN_BOOL("compatibility.quirks",
			_("Enable site-specific quirks")),
		NULL);
}

static gchar *
gen_page_display(MqConfig *config)
{
	return mq_html_container("div", NULL,
		mq_html_h3(_("Fonts")),
		GEN_STR ("font.family.default",
			_("Default font family")),
		GEN_STR ("font.family.monospace",
			_("Default monospace font family")),
		GEN_STR ("font.family.serif",
			_("Default serif font family")),
		GEN_STR ("font.family.sans-serif",
			_("Default sans-serif font family")),
		GEN_STR ("font.family.cursive",
			_("Cursive font family")),
		GEN_STR ("font.family.fantasy",
			_("Fantasy font family")),
		GEN_STR ("font.family.pictograph",
			_("Pictograph font family")),
		GEN_INT ("font.size.default",
			_("Default font size"), 5, 1, 72),
		GEN_INT ("font.size.monospace-default",
			_("Default monospace font size"), 5, 1, 72),
		GEN_INT ("font.size.minimum",
			_("Minimum font size"), 0, 1, 72),

		mq_html_h3(_("Languages")),
		GEN_STRL("intl.accept-languages",
			_("Preferred Web site languages")),
		GEN_STR ("intl.default-charset",
			_("Default character set")),

		mq_html_h3(_("Zoom")),
		GEN_DBL ("zoom.default",
			_("Default zoom level"), 0.00, 0.10, 10.00),
		GEN_BOOL("zoom.text-only",
			_("Zoom text only")),
		NULL);
}

static gchar *
gen_page_permissions(MqConfig *config)
{
	return mq_html_container("div", NULL,
		mq_html_h3(_("General")),
		GEN_BOOL("permissions.images.auto-load",
			_("Automatically load images")),
		GEN_BOOL("permissions.images.favicons.override",
			_("Always load icons irrespective of automatic image "
				"loading")),
		GEN_BOOL("permissions.java.enable",
			_("Enable Java")),
		GEN_BOOL("permissions.javascript.enable",
			_("Enable JavaScript")),
		GEN_BOOL("permissions.plugins.enable",
			_("Enable plugins")),

		mq_html_h3(_("JavaScript")),
		GEN_BOOL("permissions.javascript.open-windows",
			_("Allow JavaScript to open windows")),
		GEN_BOOL("permissions.javascript.fullscreen",
			_("Allow JavaScript to display elements fullscreen")),
		GEN_BOOL("permissions.javascript.modal-dialogs",
			_("Allow JavaScript to show modal dialogs")),
		GEN_BOOL("permissions.javascript.clipboard",
			_("Allow JavaScript to access the clipboard")),

		mq_html_h3(_("Data Storage")),
		GEN_BOOL("permissions.javascript.database",
			_("Enable Web database")),
		GEN_BOOL("permissions.javascript.storage",
			_("Enable Web storage")),
		GEN_BOOL("permissions.appcache",
			_("Enable application cache")),

		mq_html_h3(_("Graphics and Multimedia")),
		GEN_BOOL("canvas.acceleration.enable",
			_("Enable hardware-accelerated 2-D canvas drawing")),
		GEN_BOOL("permissions.javascript.webgl",
			_("Enable JavaScript WebGL 3-D graphics rendering")),
		GEN_BOOL("permissions.javascript.audio",
			_("Allow JavaScript to process and synthesize audio")),
		GEN_BOOL("media.autoplay",
			_("Enable automatic media playback and loading")),
		GEN_BOOL("media.force-fullscreen",
			_("Force media to play fullscreen")),
		GEN_BOOL("permissions.javascript.mediastream.enable",
			_("Allow JavaScript to access audio and video devices")
			),
		GEN_BOOL("permissions.javascript.mediasource.enable",
			_("Allow JavaScript to generate media streams")),
		NULL);
}

static gchar *
gen_page_sec_and_priv(MqConfig *config)
{
	return mq_html_container("div", NULL,
		mq_html_h3(_("History")),
		GEN_BOOL("privacy.private-browsing.enabled",
			_("Enable private prowsing (disables history, cache, "
				"and form auto-filling)")),
		GEN_BOOL("privacy.remember.history",
			_("Remember browsing history")),
		GEN_BOOL("privacy.remember.downloads",
			_("Remember download history")),

		mq_html_h3(_("Cookies")),
		GEN_SLCT("cookies.accept",
			_("Accept cookies"),
			"always",         _("Always"),
			"never",          _("Never"),
			"no-third-party", _("No third-party")),

		mq_html_h3(_("Security")),
		GEN_BOOL("security.xss-auditor.enable",
			_("Attempt to detect and block cross-site scripting "
				"attacks")),

		mq_html_h3(_("Network")),
		GEN_BOOL("dns.prefetch.enable",
			_("Prefetch domain name resolutions for better "
				"performance")),
		NULL);
}

#undef GEN_BOOL
#undef GEN_INT
#undef GEN_DBL
#undef GEN_STR
#undef GEN_STRL

void
mq_about_preferences_response(MqApplication *application, GHashTable *query,
	WebKitURISchemeRequest *request)
{
	MqConfig *config;
	gchar    *document;

	config = mq_application_get_config(application);

	if (query) {
		g_hash_table_foreach(query, (GHFunc) save_pref, config);
		mq_config_save(config);
		mq_about_redirect(request, "mq-about:preferences");
	} else {
		document = mq_html_document(_("Preferences"), NULL, NULL,
			mq_html_form(NULL, _("Save"), NULL, _("Cancel"),
				mq_html_notebook(FALSE, "notebook1", 0,
					gen_page_general(config),
					_("General"),
					gen_page_display(config),
					_("Display"),
					gen_page_permissions(config),
					_("Permissions"),
					gen_page_sec_and_priv(config),
					_("Security and Privacy"),
					NULL),
				NULL),
			NULL);
		mq_about_response(request, document);
	}
}