/
SettingsPage.qml
397 lines (342 loc) · 16.2 KB
/
SettingsPage.qml
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/****************************************************************************
**
** Copyright (c) 2013 - 2021 Jolla Ltd.
** Copyright (c) 2020 - 2021 Open Mobile Platform LLC.
**
****************************************************************************/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
import QtQuick 2.6
import Sailfish.Silica 1.0
import Sailfish.Browser 1.0
import Nemo.Configuration 1.0
import com.jolla.settings.system 1.0
import Sailfish.WebEngine 1.0
import Sailfish.Pickers 1.0
import "components"
Page {
id: page
readonly property int _textSwitchIconCenter: Math.round((permissionIcon.width - Theme.itemSizeExtraSmall) / 2.0)
function removeProtocolTypeFromUri(uri) {
if (uri.length === 0)
return uri
return uri.replace(/(^\w+:|^)\/\//, '')
}
SilicaFlickable {
anchors.fill: parent
contentHeight: contentColumn.height
Column {
id: contentColumn
width: parent.width
spacing: Theme.paddingMedium
bottomPadding: Theme.paddingLarge
PageHeader {
//% "Settings"
title: qsTrId("sailfish_browser-he-settings")
}
BrowserComboBox {
id: homePage
readonly property bool _homePageBlank: homePageConfig.value === "about:blank"
//: Label for home page text field
//% "Home Page"
label: qsTrId("settings_browser-la-home_page")
//% "Start view"
value: _homePageBlank ? qsTrId("sailfish_browser-la-start_view") : removeProtocolTypeFromUri(homePageConfig.value)
currentIndex: _homePageBlank
? 0 // For start view (blank)
: 1 // For web page
iconSource: "image://theme/icon-m-home"
on_HomePageBlankChanged: currentIndex = _homePageBlank ? 0 : 1
menu: ContextMenu {
MenuItem {
//% "Start view"
text: qsTrId("sailfish_browser-me-start_view")
onClicked: homePageConfig.value = "about:blank"
}
MenuItem {
readonly property string site: removeProtocolTypeFromUri(homePageConfig.value)
property string title: {
if (homePage._homePageBlank || site === "") {
//: Shown when site is empty
//% "Web page"
return qsTrId("sailfish_browser-me-web_page_empty")
} else {
//: Instead of %1 site address will be displayed
//% "Web page %1"
qsTrId("sailfish_browser-me-web_page").arg(site)
}
}
textFormat: Text.StyledText
color: highlighted ? Theme.highlightColor : Theme.primaryColor
text: Theme.highlightText(title, site, Theme.highlightColor)
onClicked: {
pageStack.animatorPush(Qt.resolvedUrl("components/AddHomePageDialog.qml"),
{homePageConfig: homePageConfig})
}
}
}
}
BrowserComboBox {
id: searchEngine
//: Label for combobox that sets search engine used in browser
//% "Search with"
label: qsTrId("settings_browser-la-search_with")
iconSource: "image://theme/icon-m-search"
menu: ContextMenu {
Repeater {
model: SearchEngineModel
delegate: SearchEngineMenuItem {
text: title
//: Shown on Settings -> Search engine for user installable search services
//% "Tap to install"
description: status == SearchEngineModel.Available ? qsTrId("settings_browser-la-tap_to_install") : ""
onClicked: {
if (title !== searchEngineConfig.value) {
if (status == SearchEngineModel.Available) {
SearchEngineModel.install(title)
} else {
searchEngineConfig.value = title
}
}
}
Component.onCompleted: {
if (text && (text === searchEngineConfig.value)) {
searchEngine.currentIndex = index
}
}
}
}
}
}
SectionHeader {
//: Section Header for Privacy settings
//% "Privacy"
text: qsTrId("settings_browser-sh-privacy")
}
TextSwitch {
//: Label for text switch that makes all tabs closed upon closing browser application
//% "Close all tabs on exit"
text: qsTrId("settings_browser-la-close_all_tabs")
//% "When Browser is started next time, selected home page will be loaded"
description: qsTrId("settings_browser-la-close_all_tabs_description")
checked: closeAllTabsConfig.value
// Margins adjusted to align with other items on the page
leftMargin: Theme.horizontalPageMargin + Theme.paddingLarge + _textSwitchIconCenter
_label.anchors.leftMargin: Theme.paddingMedium + _textSwitchIconCenter
onCheckedChanged: closeAllTabsConfig.value = checked
}
TextSwitch {
checked: WebEngineSettings.doNotTrack
//: Tell sites that I do not want to be tracked.
//% "Do not track"
text: qsTrId("settings_browser-la-tracking")
//: Tell sites that I do not want to be tracked.
//% "Tell sites that I do not want to be tracked"
description: qsTrId("settings_browser-la-tracking_description")
// Margins adjusted to align with other items on the page
leftMargin: Theme.horizontalPageMargin + Theme.paddingLarge + _textSwitchIconCenter
_label.anchors.leftMargin: Theme.paddingMedium + _textSwitchIconCenter
onCheckedChanged: WebEngineSettings.doNotTrack = checked
}
TextSwitch {
//: Label for text switch that enables JavaScript globally for all tabs
//% "Enable JavaScript"
text: qsTrId("settings_browser-la-enable_javascript")
description: WebEngineSettings.javascriptEnabled ?
//% "Allowed (recommended)"
qsTrId("settings_browser-la-enabled_javascript_description") :
//% "Blocked, some sites may not work correctly"
qsTrId("settings_browser-la-disable_javascript_description")
checked: WebEngineSettings.javascriptEnabled
// Margins adjusted to align with other items on the page
leftMargin: Theme.horizontalPageMargin + Theme.paddingLarge + _textSwitchIconCenter
_label.anchors.leftMargin: Theme.paddingMedium + _textSwitchIconCenter
onCheckedChanged: WebEngineSettings.javascriptEnabled = checked;
}
BackgroundItem {
width: parent.width
contentHeight: Theme.itemSizeMedium
Row {
width: parent.width - 2*Theme.horizontalPageMargin
x: Theme.horizontalPageMargin
spacing: Theme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
Icon {
id: loginsIcon
source: "image://theme/icon-m-keys"
}
Label {
width: parent.width - parent.spacing - loginsIcon.width
//: The label for the button for accessing password management
//% "Passwords"
text: qsTrId("settings_browser-la-passwords")
anchors.verticalCenter: loginsIcon.verticalCenter
}
}
onClicked: pageStack.push("LoginsPage.qml")
}
BackgroundItem {
width: parent.width
contentHeight: Theme.itemSizeMedium
Row {
width: parent.width - 2*Theme.horizontalPageMargin
x: Theme.horizontalPageMargin
spacing: Theme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
Icon {
id: permissionIcon
source: "image://theme/icon-m-browser-permissions"
}
Label {
width: parent.width - parent.spacing - permissionIcon.width
//% "Permissions"
text: qsTrId("settings_browser-la-permissions")
anchors.verticalCenter: permissionIcon.verticalCenter
}
}
onClicked: pageStack.push("PermissionPage.qml")
}
BackgroundItem {
width: parent.width
contentHeight: Theme.itemSizeMedium
Row {
width: parent.width - 2*Theme.horizontalPageMargin
x: Theme.horizontalPageMargin
spacing: Theme.paddingMedium
anchors.verticalCenter: parent.verticalCenter
Icon {
id: clearBrowsingDataIcon
source: "image://theme/icon-m-delete"
}
Label {
width: parent.width - parent.spacing - clearBrowsingDataIcon.width
//: The label for the button for accessing clear browsing data page
//% "Clear browsing data"
text: qsTrId("settings_browser-la-clear-browsing-data")
anchors.verticalCenter: clearBrowsingDataIcon.verticalCenter
}
}
onClicked: pageStack.push("PrivacySettingsPage.qml", { previousPage: page })
}
SectionHeader {
//: Section Header for Downloads settings
//% "Downloads"
text: qsTrId("settings_browser-la-downloads")
}
BrowserComboBox {
//% "Save destination"
label: qsTrId("settings_browser-la-save_destination")
iconSource: "image://theme/icon-m-downloads"
value: {
if (WebEngineSettings.useDownloadDir) {
//% "Download to %1"
return qsTrId("sailfish_browser-me-download_to").arg(WebEngineSettings.downloadDir.split("/").pop())
} else {
//% "Always ask"
return qsTrId("sailfish_browser-me-always_ask")
}
}
currentIndex: WebEngineSettings.useDownloadDir
? 0 // for selection a download folder
: 1 // for always ask
description: {
if (WebEngineSettings.useDownloadDir) {
//% "Downloaded files will be saved to %1 folder"
return qsTrId("sailfish_browser-me-will_be_saved_to_download").arg(WebEngineSettings.downloadDir)
} else {
//% "You will be asked where to save files"
return qsTrId("sailfish_browser-me-you_will_be_asked_where_to_save_files")
}
}
menu: ContextMenu {
MenuItem {
//% "Select a download folder"
text: qsTrId("sailfish_browser-me-select_download_folder")
onClicked: {
WebEngineSettings.useDownloadDir = true
// If the user will reject, choose download path as default
WebEngineSettings.downloadDir = StandardPaths.download
pageStack.animatorPush(folderPickerPage)
}
}
MenuItem {
//% "Always ask"
text: qsTrId("sailfish_browser-me-always_ask")
onClicked: WebEngineSettings.useDownloadDir = false
}
}
}
SectionHeader {
//: Section Header for Appearance settings
//% "Appearance"
text: qsTrId("settings_browser-la-appearance")
}
BrowserComboBox {
//% "Preferred color scheme"
label: qsTrId("settings_browser-la-color_scheme")
iconSource: "image://theme/icon-m-night"
currentIndex: WebEngineSettings.colorScheme
//% "The website style to use when available"
description: qsTrId("sailfish_browser-me-website_color_scheme")
menu: ContextMenu {
MenuItem {
//: Option to prefer a website's light color scheme
//% "Light"
text: qsTrId("sailfish_browser-me-prefers_light_mode")
onClicked: WebEngineSettings.colorScheme = WebEngineSettings.PrefersLightMode
}
MenuItem {
//: Option to prefer a website's dark color scheme
//% "Dark"
text: qsTrId("sailfish_browser-me-prefers_dark_mode")
onClicked: WebEngineSettings.colorScheme = WebEngineSettings.PrefersDarkMode
}
MenuItem {
//: Option for the website's color scheme to match the ambience
//% "Match ambience"
text: qsTrId("sailfish_browser-me-follow_ambience")
onClicked: WebEngineSettings.colorScheme = WebEngineSettings.FollowsAmbience
}
}
}
}
}
ConfigurationValue {
id: closeAllTabsConfig
key: "/apps/sailfish-browser/settings/close_all_tabs"
defaultValue: false
}
ConfigurationValue {
id: searchEngineConfig
key: "/apps/sailfish-browser/settings/search_engine"
defaultValue: "Google"
}
ConfigurationValue {
id: homePageConfig
key: "/apps/sailfish-browser/settings/home_page"
defaultValue: "http://jolla.com/"
}
Notice {
id: searchInstalledNotice
duration: 3000
verticalOffset: -Theme.paddingLarge
}
Connections {
target: SearchEngineModel
onInstalled: {
//% "%1 search installed"
searchInstalledNotice.text = qsTrId("sailfish_browser-la-search_installed").arg(title)
searchInstalledNotice.show()
}
}
Component {
id: folderPickerPage
FolderPickerPage {
showSystemFiles: false
//% "Download to"
dialogTitle: qsTrId("sailfish_browser-ti-download-to")
onSelectedPathChanged: WebEngineSettings.downloadDir = selectedPath
}
}
}