summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@theqtcompany.com>2015-08-05 18:06:17 +0200
committerAndras Becsi <andras.becsi@theqtcompany.com>2015-08-12 17:22:04 +0200
commit307a43ada021b99f17c976354f255ff11389d641 (patch)
treeeab82ccf5957b66362d41e1ace8b55701aff211c /src
parent8b7b0d5955dfa6a3d4c573dfe393d2bf765f211f (diff)
Make settings propagate to webViews
This also adds a check for consistency of the loaded settings' index and the default settings to prevent inconsistent states.
Diffstat (limited to 'src')
-rw-r--r--src/engine.cpp5
-rw-r--r--src/engine.h2
-rw-r--r--src/qml/PageView.qml2
-rw-r--r--src/qml/SettingsView.qml78
4 files changed, 52 insertions, 35 deletions
diff --git a/src/engine.cpp b/src/engine.cpp
index fae28f5..b6db85c 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -47,6 +47,11 @@ Engine::Engine(QObject *parent)
{
}
+QString Engine::settingsPath()
+{
+ return m_settings.fileName();
+}
+
QUrl Engine::fromUserInput(const QString& userInput)
{
QFileInfo fileInfo(userInput);
diff --git a/src/engine.h b/src/engine.h
index e905d72..777dd74 100644
--- a/src/engine.h
+++ b/src/engine.h
@@ -77,6 +77,7 @@ class Engine : public QObject {
Q_OBJECT
Q_PROPERTY(QObject * rootWindow READ rootWindow FINAL CONSTANT)
+ Q_PROPERTY(QString settingsPath READ settingsPath FINAL CONSTANT)
QSettings m_settings;
@@ -86,6 +87,7 @@ public:
{
return parent();
}
+ QString settingsPath();
Q_INVOKABLE QUrl fromUserInput(const QString& userInput);
Q_INVOKABLE QString domainFromString(const QString& urlString);
diff --git a/src/qml/PageView.qml b/src/qml/PageView.qml
index 58bdfb8..c4b2603 100644
--- a/src/qml/PageView.qml
+++ b/src/qml/PageView.qml
@@ -121,7 +121,7 @@ Rectangle {
top: permBar.bottom
}
- profile: defaultProfile
+ profile: settingsView.privateBrowsingEnabled ? otrProfile : defaultProfile
enabled: root.interactive
function takeSnapshot() {
diff --git a/src/qml/SettingsView.qml b/src/qml/SettingsView.qml
index e373960..1eeb3a3 100644
--- a/src/qml/SettingsView.qml
+++ b/src/qml/SettingsView.qml
@@ -44,26 +44,21 @@ import Qt.labs.settings 1.0
Rectangle {
id: root
- property bool autoLoadImages: get(0)
- property bool javaScriptDisabled: get(1)
- property bool httpDiskCacheEnabled: get(2)
- property bool pluginsEnabled: get(3)
- property bool privateBrowsingEnabled: get(4)
+ property bool privateBrowsingEnabled: appSettings[0].active
+ property bool httpDiskCacheEnabled: appSettings[1].active
+ property bool autoLoadImages: appSettings[2].active
+ property bool javaScriptDisabled: appSettings[3].active
+ property bool pluginsEnabled: appSettings[4].active
- property var defaultValues: [{ "name": "Auto Load Images", "active": true },
- { "name": "Disable JavaScript", "active": false },
- { "name": "Enable HTTP Disk Cache", "active": true },
- { "name": "Enable Plugins", "active": false },
- { "name": "Private Browsing", "active": false }]
-
- function get(index) {
- var elem = listModel.get(index)
- if (!elem)
- return defaultValues[index].active
- return elem.active
- }
+ property var appSettings: [
+ { "name": "Private Browsing", "active": false, "notify": function(v) { privateBrowsingEnabled = v; } },
+ { "name": "Enable HTTP Disk Cache", "active": true, "notify": function(v) { httpDiskCacheEnabled = v; } },
+ { "name": "Auto Load Images", "active": true, "notify": function(v) { autoLoadImages = v; } },
+ { "name": "Disable JavaScript", "active": false, "notify": function(v) { javaScriptDisabled = v; } },
+ { "name": "Enable Plugins", "active": false, "notify": function(v) { pluginsEnabled = v; } }
+ ]
- state: "enabled"
+ state: "disabled"
states: [
State {
@@ -112,7 +107,7 @@ Rectangle {
font.family: defaultFontFamily
font.pixelSize: 28
text: name
- color: tch.checked ? "black" : "#929495"
+ color: sw.enabled ? "black" : "#929495"
}
Rectangle {
anchors {
@@ -120,11 +115,22 @@ Rectangle {
verticalCenter: parent.verticalCenter
}
Switch {
- id: tch
+ id: sw
+ enabled: {
+ var ok = appSettings[index].name.indexOf("Disk Cache") < 0
+ return ok || !privateBrowsingEnabled
+ }
anchors.centerIn: parent
- checked: active
+ checked: {
+ if (enabled)
+ return active
+ return false
+ }
onClicked: {
+ var setting = appSettings[index]
+ setting.active = checked
listModel.get(index).active = checked
+ setting.notify(checked)
listView.save()
}
style: SwitchStyle {
@@ -149,25 +155,29 @@ Rectangle {
}
}
}
- function save() {
- var list = []
- for (var i = 0; i < listModel.count; ++i) {
- var elem = listModel.get(i)
- list[i] = { "name": elem.name, "active": elem.active }
- }
-
- if (!list.length)
- return
- engine.saveSetting("settings", JSON.stringify(list))
+ function save() {
+ // Do not persist private browsing mode
+ appSettings[0].active = false
+ engine.saveSetting("settings", JSON.stringify(appSettings))
}
Component.onCompleted: {
- var string = engine.restoreSetting("settings", JSON.stringify(defaultValues))
+ var string = engine.restoreSetting("settings", JSON.stringify(appSettings))
var list = JSON.parse(string)
for (var i = 0; i < list.length; ++i) {
- var elem = list[i]
- listModel.append({ "name": elem.name, "active": elem.active })
+ var persistentSetting = list[i]
+ var localSetting = appSettings[i]
+
+ if (localSetting.name !== persistentSetting.name) {
+ console.error("Conflicting configuration layout detected, using default setting!\nIf the problem persists please remove " + engine.settingsPath +" and restart the application.")
+ listModel.append(localSetting)
+ continue
+ }
+
+ listModel.append({ "name": persistentSetting.name, "active": persistentSetting.active })
+ localSetting.active = persistentSetting.active
+ localSetting.notify(persistentSetting.active)
}
listView.forceLayout()
}