1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the QtBrowser project.
8 ** $QT_BEGIN_LICENSE:GPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 2 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.GPLv2 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU General Public License version 2 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 3.0 as published by the Free Software
28 ** Foundation and appearing in the file LICENSE.GPL included in the
29 ** packaging of this file. Please review the following information to
30 ** ensure the GNU General Public License version 3.0 requirements will be
31 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ****************************************************************************/
39 import QtQuick.Layouts 1.0
40 import QtQuick.Controls 1.4
41 import QtQuick.Controls.Styles 1.4
42 import Qt.labs.settings 1.0
47 property bool privateBrowsingEnabled: appSettings[0].active
48 property bool httpDiskCacheEnabled: appSettings[1].active
49 property bool autoLoadImages: appSettings[2].active
50 property bool javaScriptDisabled: appSettings[3].active
51 property bool pluginsEnabled: appSettings[4].active
53 property var appSettings: [
54 { "name": "Private Browsing", "active": false, "notify": function(v) { privateBrowsingEnabled = v; } },
55 { "name": "Enable HTTP Disk Cache", "active": true, "notify": function(v) { httpDiskCacheEnabled = v; } },
56 { "name": "Auto Load Images", "active": true, "notify": function(v) { autoLoadImages = v; } },
57 { "name": "Disable JavaScript", "active": false, "notify": function(v) { javaScriptDisabled = v; } },
58 { "name": "Enable Plugins", "active": false, "notify": function(v) { pluginsEnabled = v; } }
68 anchors.top: navigation.bottom
71 target: settingsToolBar
79 anchors.top: root.parent.bottom
82 target: settingsToolBar
88 transitions: Transition {
89 AnchorAnimation { duration: animationDuration; easing.type : Easing.InSine }
99 rightMargin: leftMargin
102 delegate: Rectangle {
106 anchors.verticalCenter: parent.verticalCenter
107 font.family: defaultFontFamily
110 color: sw.enabled ? "black" : "#929495"
115 verticalCenter: parent.verticalCenter
120 var ok = appSettings[index].name.indexOf("Disk Cache") < 0
121 return ok || !privateBrowsingEnabled
123 anchors.centerIn: parent
130 var setting = appSettings[index]
131 setting.active = checked
132 listModel.get(index).active = checked
133 setting.notify(checked)
142 border.color: control.checked ? "#5caa14" : "#9b9b9b"
150 border.color: control.checked ? "#5caa14" : "#9b9b9b"
151 color: control.checked ? "#5cff14" : "white"
160 // Do not persist private browsing mode
161 appSettings[0].active = false
162 engine.saveSetting("settings", JSON.stringify(appSettings))
165 Component.onCompleted: {
166 var string = engine.restoreSetting("settings", JSON.stringify(appSettings))
167 var list = JSON.parse(string)
168 for (var i = 0; i < list.length; ++i) {
169 var persistentSetting = list[i]
170 var localSetting = appSettings[i]
172 if (localSetting.name !== persistentSetting.name) {
173 console.error("Conflicting configuration layout detected, using default setting!\nIf the problem persists please remove " + engine.settingsPath +" and restart the application.")
174 listModel.append(localSetting)
178 listModel.append({ "name": persistentSetting.name, "active": persistentSetting.active })
179 localSetting.active = persistentSetting.active
180 localSetting.notify(persistentSetting.active)
182 listView.forceLayout()
184 Component.onDestruction: save()