Merge lp:~rpadovani/webbrowser-app/settings-page into lp:webbrowser-app

Proposed by Riccardo Padovani
Status: Superseded
Proposed branch: lp:~rpadovani/webbrowser-app/settings-page
Merge into: lp:webbrowser-app
Diff against target: 915 lines (+427/-209)
15 files modified
README (+9/-2)
debian/control (+1/-0)
src/app/browserapplication.cpp (+1/-0)
src/app/config.h.in (+1/-3)
src/app/webbrowser/AddressBar.qml (+2/-11)
src/app/webbrowser/Browser.qml (+63/-7)
src/app/webbrowser/CMakeLists.txt (+0/-1)
src/app/webbrowser/SettingsPage.qml (+266/-0)
src/app/webbrowser/searchengine.cpp (+51/-45)
src/app/webbrowser/searchengine.h (+17/-17)
src/app/webbrowser/settings.cpp (+0/-57)
src/app/webbrowser/settings.h (+0/-51)
src/app/webbrowser/urlManagement.js (+12/-0)
src/app/webbrowser/webbrowser-app.cpp (+2/-9)
src/app/webbrowser/webbrowser-app.qml (+2/-6)
To merge this branch: bzr merge lp:~rpadovani/webbrowser-app/settings-page
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+253974@code.launchpad.net

This proposal has been superseded by a proposal from 2015-03-24.

Commit message

Add settings page (clear history, set homepage, open tabs in background, restore previous session)

Description of the change

Add settings page. It still misses the search engine model, so if we want to land this we should hide the searchengine setting.

To post a comment you must log in.
940. By Riccardo Padovani

Added copyright header to urlManagement.js

941. By Riccardo Padovani

Add divider between title and settings page itself

942. By Riccardo Padovani

Improved bad english

943. By Riccardo Padovani

Improve management of historyModel in SettingsPage, expose count property of historyModel

944. By Riccardo Padovani

Add flickable to columns

945. By Riccardo Padovani

Fix rowCount() signal

946. By Riccardo Padovani

Use AbstractButton for back button in the header

947. By Riccardo Padovani

Add test to history model to check count property

948. By Riccardo Padovani

Fix encapsulation

949. By Riccardo Padovani

Move use strict after copyright header

950. By Riccardo Padovani

Avoid useless redrawing of the webview when settings or history are open

951. By Riccardo Padovani

Add separator after the last element

952. By Riccardo Padovani

Add QSignalSpy to count property test in history model

953. By Riccardo Padovani

Add search engine choice

954. By Riccardo Padovani

Add dependency to debian/control, update search engine page

955. By Riccardo Padovani

Merge from upstream

956. By Riccardo Padovani

Merge from lp:~osomon/webbrowser-app/qt-labs-settings

957. By Riccardo Padovani

Fix settings maanagement, hide search engine optinn whene there are < 2 engines

958. By Riccardo Padovani

Split the settings page header in a different component

959. By Riccardo Padovani

Make subpages as separate components to manage them dinamically

960. By Riccardo Padovani

Make divider part of SettingsPageHeader

961. By Riccardo Padovani

Explict bindings of switchs

962. By Riccardo Padovani

Use current search engine name instead of the filename

963. By Riccardo Padovani

Revert blank lines changes

964. By Riccardo Padovani

Improve SettingsPageHeader

965. By Riccardo Padovani

Fix all issues raised in the review (but SettingsPage visibility)

966. By Riccardo Padovani

Address new comments in the review

967. By Riccardo Padovani

Fix CMakeLists.txt

968. By Riccardo Padovani

Address Bill's comments

969. By Riccardo Padovani

Check if a domain is valid in the homepage setting before saving it

970. By Riccardo Padovani

Merge from trunk and resolve conflicts

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README'
--- README 2015-02-27 09:28:41 +0000
+++ README 2015-03-24 15:51:06 +0000
@@ -74,7 +74,7 @@
74webbrowser-app supports a limited set of custom settings, currently not exposed74webbrowser-app supports a limited set of custom settings, currently not exposed
75in the UI. The settings are persisted on disk in the following INI-like file:75in the UI. The settings are persisted on disk in the following INI-like file:
7676
77 $HOME/.config/webbrowser-app/settings.conf77 $HOME/.config/webbrowser-app/webbrowser-app.conf
7878
79The following keys are supported:79The following keys are supported:
8080
@@ -86,4 +86,11 @@
86 the OpenSearch document description format86 the OpenSearch document description format
87 (http://www.opensearch.org/Specifications/OpenSearch/1.1)87 (http://www.opensearch.org/Specifications/OpenSearch/1.1)
8888
89If any of those keys are not specified, the default hardcoded value is used.89 - 'allowOpenInBackgroundTab': whether to offer an option to open a link in a
90 new background tab in the contextual menu. Possible values are "true",
91 "false", and "default" (which resolves to true on desktop and false on
92 mobile).
93
94 - restoreSession: whether to restore the previous browsing session at startup
95 (defaults to true)
96
9097
=== modified file 'debian/control'
--- debian/control 2015-03-02 12:21:27 +0000
+++ debian/control 2015-03-24 15:51:06 +0000
@@ -36,6 +36,7 @@
36 fonts-liberation,36 fonts-liberation,
37 liboxideqt-qmlplugin (>= 1.4),37 liboxideqt-qmlplugin (>= 1.4),
38 libqt5sql5-sqlite,38 libqt5sql5-sqlite,
39 qml-module-qt-labs-settings,
39 qml-module-qtquick2 (>= 5.4) | qtdeclarative5-qtquick2-plugin (>= 5.4),40 qml-module-qtquick2 (>= 5.4) | qtdeclarative5-qtquick2-plugin (>= 5.4),
40 qml-module-qtquick-dialogs | qtdeclarative5-dialogs-plugin,41 qml-module-qtquick-dialogs | qtdeclarative5-dialogs-plugin,
41 qml-module-qtquick-window2 | qtdeclarative5-window-plugin,42 qml-module-qtquick-window2 | qtdeclarative5-window-plugin,
4243
=== modified file 'src/app/browserapplication.cpp'
--- src/app/browserapplication.cpp 2015-03-02 12:21:27 +0000
+++ src/app/browserapplication.cpp 2015-03-24 15:51:06 +0000
@@ -128,6 +128,7 @@
128 QStringList appIdParts =128 QStringList appIdParts =
129 QString::fromUtf8(qgetenv("APP_ID")).split('_');129 QString::fromUtf8(qgetenv("APP_ID")).split('_');
130 QCoreApplication::setApplicationName(appIdParts.first());130 QCoreApplication::setApplicationName(appIdParts.first());
131 QCoreApplication::setOrganizationDomain(QCoreApplication::applicationName());
131 // Get also the the first two components of the app ID: <package>_<app>,132 // Get also the the first two components of the app ID: <package>_<app>,
132 // which is needed by Online Accounts.133 // which is needed by Online Accounts.
133 QString unversionedAppId = QStringList(appIdParts.mid(0, 2)).join('_');134 QString unversionedAppId = QStringList(appIdParts.mid(0, 2)).join('_');
134135
=== modified file 'src/app/config.h.in'
--- src/app/config.h.in 2014-06-30 10:40:59 +0000
+++ src/app/config.h.in 2015-03-24 15:51:06 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright 2013 Canonical Ltd.2 * Copyright 2013-2015 Canonical Ltd.
3 *3 *
4 * This file is part of webbrowser-app.4 * This file is part of webbrowser-app.
5 *5 *
@@ -24,10 +24,8 @@
24#include <QtCore/QString>24#include <QtCore/QString>
2525
26#define APP_ID "webbrowser-app"26#define APP_ID "webbrowser-app"
27#define DEFAULT_HOMEPAGE "http://start.ubuntu.com"
28#define REMOTE_INSPECTOR_PORT 922127#define REMOTE_INSPECTOR_PORT 9221
2928
30#define DEFAULT_SEARCH_ENGINE "google"
31#define DEFAULT_SEARCH_NAME "Google Search"29#define DEFAULT_SEARCH_NAME "Google Search"
32#define DEFAULT_SEARCH_DESC "Use google.com to search the Web"30#define DEFAULT_SEARCH_DESC "Use google.com to search the Web"
33#define DEFAULT_SEARCH_TEMPLATE "https://google.com/search?client=ubuntu&q={searchTerms}&ie=utf-8&oe=utf-8"31#define DEFAULT_SEARCH_TEMPLATE "https://google.com/search?client=ubuntu&q={searchTerms}&ie=utf-8&oe=utf-8"
3432
=== modified file 'src/app/webbrowser/AddressBar.qml'
--- src/app/webbrowser/AddressBar.qml 2015-01-23 10:30:19 +0000
+++ src/app/webbrowser/AddressBar.qml 2015-03-24 15:51:06 +0000
@@ -21,6 +21,7 @@
21import Ubuntu.Components.Popups 1.021import Ubuntu.Components.Popups 1.0
22import com.canonical.Oxide 1.0 as Oxide22import com.canonical.Oxide 1.0 as Oxide
23import ".."23import ".."
24import "urlManagement.js" as UrlManagement
2425
25FocusScope {26FocusScope {
26 id: addressbar27 id: addressbar
@@ -257,16 +258,6 @@
257 return false258 return false
258 }259 }
259260
260 function fixUrl(address) {
261 var url = address
262 if (address.substr(0, 1) == "/") {
263 url = "file://" + address
264 } else if (address.indexOf("://") == -1) {
265 url = "http://" + address
266 }
267 return url
268 }
269
270 function escapeHtmlEntities(query) {261 function escapeHtmlEntities(query) {
271 return query.replace(/\W/, encodeURIComponent)262 return query.replace(/\W/, encodeURIComponent)
272 }263 }
@@ -279,7 +270,7 @@
279 function validate() {270 function validate() {
280 var query = text.trim()271 var query = text.trim()
281 if (internal.looksLikeAUrl(query)) {272 if (internal.looksLikeAUrl(query)) {
282 requestedUrl = internal.fixUrl(query)273 requestedUrl = UrlManagement.fixUrl(query)
283 } else {274 } else {
284 requestedUrl = internal.buildSearchUrl(query)275 requestedUrl = internal.buildSearchUrl(query)
285 }276 }
286277
=== modified file 'src/app/webbrowser/Browser.qml'
--- src/app/webbrowser/Browser.qml 2015-03-20 12:19:51 +0000
+++ src/app/webbrowser/Browser.qml 2015-03-24 15:51:06 +0000
@@ -18,6 +18,7 @@
1818
19import QtQuick 2.019import QtQuick 2.0
20import QtQuick.Window 2.020import QtQuick.Window 2.0
21import Qt.labs.settings 1.0
21import com.canonical.Oxide 1.4 as Oxide22import com.canonical.Oxide 1.4 as Oxide
22import Ubuntu.Components 1.123import Ubuntu.Components 1.1
23import webbrowserapp.private 0.124import webbrowserapp.private 0.1
@@ -29,16 +30,17 @@
29BrowserView {30BrowserView {
30 id: browser31 id: browser
3132
32 property bool restoreSession: true
33
34 currentWebview: tabsModel.currentTab ? tabsModel.currentTab.webview : null33 currentWebview: tabsModel.currentTab ? tabsModel.currentTab.webview : null
3534
36 property var historyModel: (historyModelLoader.status == Loader.Ready) ? historyModelLoader.item : null35 property var historyModel: (historyModelLoader.status == Loader.Ready) ? historyModelLoader.item : null
37 property var bookmarksModel: (bookmarksModelLoader.status == Loader.Ready) ? bookmarksModelLoader.item : null36 property var bookmarksModel: (bookmarksModelLoader.status == Loader.Ready) ? bookmarksModelLoader.item : null
3837
39 property url homepage38 property url homepage: settingsDefaults.homepage
40 property QtObject searchEngine39 property string searchEngine: settingsDefaults.searchEngine
41 property string allowOpenInBackgroundTab40 property string allowOpenInBackgroundTab: settingsDefaults.allowOpenInBackgroundTab
41 property bool restoreSession: settingsDefaults.restoreSession
42
43 property bool newSession: false
4244
43 // XXX: we might want to tweak this value depending45 // XXX: we might want to tweak this value depending
44 // on the form factor and/or the available memory46 // on the form factor and/or the available memory
@@ -78,6 +80,31 @@
78 }80 }
79 ]81 ]
8082
83 Settings {
84 id: settings
85
86 property alias homepage: browser.homepage
87 property alias searchEngine: browser.searchEngine
88 property alias allowOpenInBackgroundTab: browser.allowOpenInBackgroundTab
89 property alias restoreSession: browser.restoreSession
90
91 function restoreDefaults() {
92 browser.homepage = settingsDefaults.homepage
93 browser.searchEngine = settingsDefaults.searchEngine
94 browser.allowOpenInBackgroundTab = settingsDefaults.allowOpenInBackgroundTab
95 browser.restoreSession = settingsDefaults.restoreSession
96 }
97 }
98
99 QtObject {
100 id: settingsDefaults
101
102 readonly property url homepage: "http://start.ubuntu.com"
103 readonly property string searchEngine: "google"
104 readonly property string allowOpenInBackgroundTab: "default"
105 readonly property bool restoreSession: true
106 }
107
81 Item {108 Item {
82 anchors.fill: parent109 anchors.fill: parent
83110
@@ -136,13 +163,18 @@
136 asynchronous: true163 asynchronous: true
137 }164 }
138165
166 SearchEngine {
167 id: searchEngine
168 filename: browser.searchEngine
169 }
170
139 Chrome {171 Chrome {
140 id: chrome172 id: chrome
141173
142 visible: !recentView.visible174 visible: !recentView.visible
143175
144 webview: browser.currentWebview176 webview: browser.currentWebview
145 searchUrl: browser.searchEngine ? browser.searchEngine.template : ""177 searchUrl: searchEngine.urlTemplate
146178
147 function isCurrentUrlBookmarked() {179 function isCurrentUrlBookmarked() {
148 return ((webview && browser.bookmarksModel) ? browser.bookmarksModel.contains(webview.url) : false)180 return ((webview && browser.bookmarksModel) ? browser.bookmarksModel.contains(webview.url) : false)
@@ -210,6 +242,12 @@
210 iconName: "tab-new"242 iconName: "tab-new"
211 enabled: formFactor != "mobile"243 enabled: formFactor != "mobile"
212 onTriggered: browser.openUrlInNewTab("", true)244 onTriggered: browser.openUrlInNewTab("", true)
245 },
246 Action {
247 objectName: "settings"
248 text: i18n.tr("Settings")
249 iconName: "settings"
250 onTriggered: settingsComponent.createObject(settingsContainer)
213 }251 }
214 ]252 ]
215253
@@ -471,6 +509,24 @@
471 }509 }
472 }510 }
473511
512 Item {
513 id: settingsContainer
514
515 visible: children.length > 0
516 anchors.fill: parent
517
518 Component {
519 id: settingsComponent
520
521 SettingsPage {
522 anchors.fill: parent
523 onHistoryRemoved: browser.historyModel.clearAll()
524 onRestoreDefaults: settings.restoreDefaults()
525 onDone: destroy()
526 }
527 }
528 }
529
474 TabsModel {530 TabsModel {
475 id: tabsModel531 id: tabsModel
476532
@@ -783,7 +839,7 @@
783 running: true839 running: true
784 interval: 1840 interval: 1
785 onTriggered: {841 onTriggered: {
786 if (browser.restoreSession) {842 if (!browser.newSession && browser.restoreSession) {
787 session.restore()843 session.restore()
788 }844 }
789 // Sanity check845 // Sanity check
790846
=== modified file 'src/app/webbrowser/CMakeLists.txt'
--- src/app/webbrowser/CMakeLists.txt 2015-02-18 21:37:39 +0000
+++ src/app/webbrowser/CMakeLists.txt 2015-03-24 15:51:06 +0000
@@ -28,7 +28,6 @@
28set(WEBBROWSER_APP_SRC28set(WEBBROWSER_APP_SRC
29 file-operations.cpp29 file-operations.cpp
30 searchengine.cpp30 searchengine.cpp
31 settings.cpp
32 webbrowser-app.cpp31 webbrowser-app.cpp
33)32)
3433
3534
=== added file 'src/app/webbrowser/SettingsPage.qml'
--- src/app/webbrowser/SettingsPage.qml 1970-01-01 00:00:00 +0000
+++ src/app/webbrowser/SettingsPage.qml 2015-03-24 15:51:06 +0000
@@ -0,0 +1,266 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This file is part of webbrowser-app.
5 *
6 * webbrowser-app 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 3.
9 *
10 * webbrowser-app 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
19import QtQuick 2.0
20import Ubuntu.Components 1.1
21import Ubuntu.Components.Popups 1.0
22import Ubuntu.Components.ListItems 1.0 as ListItem
23
24import "urlManagement.js" as UrlManagement
25
26Item {
27 id: settings
28
29 signal historyRemoved()
30 signal restoreDefaults()
31 signal done()
32
33 Rectangle {
34 anchors.fill: parent
35 color: "#f6f6f6"
36 }
37
38 ListItem.Empty {
39 id: title
40 anchors {
41 top: parent.top
42 left: parent.left
43 right: parent.right
44 }
45
46 highlightWhenPressed: false
47
48 Icon {
49 id: backButton
50 name: "back"
51
52 anchors {
53 top: parent.top
54 bottom: parent.bottom
55 left: parent.left
56 margins: units.gu(2)
57 }
58
59 width: height
60
61 MouseArea {
62 anchors.fill: parent
63
64 onClicked: settings.done()
65 }
66 }
67
68 Label {
69 anchors {
70 top: parent.top
71 bottom: parent.bottom
72 left: backButton.right
73 margins: units.gu(2)
74 }
75 text: i18n.tr("Settings")
76 }
77 }
78
79 Column {
80 anchors {
81 top: title.bottom
82 left: parent.left
83 right: parent.right
84 bottom: parent.bottom
85 }
86
87 ListItem.Subtitled {
88 text: i18n.tr("Search engine")
89 subText: browser.searchEngine
90 visible: false
91
92 action: Action {
93 onTriggered: {
94 searchEngineItem.visible = true;
95 }
96 }
97 }
98
99 ListItem.Subtitled {
100 text: i18n.tr("Homepage")
101 subText: browser.homepage
102
103 action: Action {
104 onTriggered: PopupUtils.open(homepageDialog)
105 }
106 }
107
108 ListItem.Standard {
109 text: i18n.tr("Restore old session on startup")
110 highlightWhenPressed: false
111 control: Switch {
112 checked: browser.restoreSession
113 onClicked: browser.restoreSession = checked;
114 }
115 }
116
117 ListItem.Standard {
118 text: i18n.tr("Open new tab in background")
119 highlightWhenPressed: false
120 control: Switch {
121 checked: browser.allowOpenInBackgroundTab
122 onClicked: browser.allowOpenInBackgroundTab = checked;
123 }
124 }
125
126 ListItem.Standard {
127 text: i18n.tr("Privacy")
128
129 action: Action {
130 onTriggered: privacyItem.visible = true;
131 }
132 }
133
134 ListItem.Standard {
135 text: i18n.tr("Reset browser settings")
136 showDivider: false
137 onClicked: {
138 settings.restoreDefaults();
139 }
140 }
141 }
142
143 Item {
144 id: searchEngineItem
145 anchors.fill: parent
146 visible: false
147
148 Rectangle {
149 anchors.fill: parent
150 color: "#f6f6f6"
151 }
152
153 ListView {
154 anchors.fill: parent
155 model: 5
156 delegate: ListItem.Standard {
157 text: index
158 action: Action {
159 onTriggered: {
160 browser.searchEngine = text;
161 searchEngineItem.visible = false;
162 }
163 }
164 }
165 }
166 }
167
168 Item {
169 id: privacyItem
170 anchors.fill: parent
171 visible: false
172
173 Rectangle {
174 anchors.fill: parent
175 color: "#f6f6f6"
176 }
177
178 ListItem.Empty {
179 id: privacyTitle
180 anchors {
181 top: parent.top
182 left: parent.left
183 right: parent.right
184 }
185
186 highlightWhenPressed: false
187
188 Icon {
189 id: privacyBackButton
190 name: "back"
191
192 anchors {
193 top: parent.top
194 bottom: parent.bottom
195 left: parent.left
196 margins: units.gu(2)
197 }
198
199 width: height
200
201 MouseArea {
202 anchors.fill: parent
203
204 onClicked: privacyItem.visible = false;
205 }
206 }
207
208 Label {
209 anchors {
210 top: parent.top
211 bottom: parent.bottom
212 left: privacyBackButton.right
213 margins: units.gu(2)
214 }
215 text: i18n.tr("Privacy")
216 }
217 }
218
219 Column {
220 anchors {
221 top: privacyTitle.bottom
222 left: parent.left
223 right: parent.right
224 bottom: parent.bottom
225 }
226
227 ListItem.Standard {
228 text: i18n.tr("Clear Browsing History")
229 onClicked: {
230 settings.historyRemoved();
231 opacity = 0.5
232 }
233 }
234 }
235 }
236
237 Component {
238 id: homepageDialog
239 Dialog {
240 id: dialogue
241 title: i18n.tr("Homepage")
242
243 TextField {
244 id: homepageTextField
245 text: browser.homepage
246 }
247
248 Button {
249 anchors { left: parent.left; right: parent.right }
250 text: i18n.tr("Cancel")
251 onClicked: PopupUtils.close(dialogue);
252 }
253
254 Button {
255 anchors { left: parent.left; right: parent.right }
256 text: i18n.tr("Save")
257 color: "#3fb24f"
258 onClicked: {
259 browser.homepage = UrlManagement.fixUrl(homepageTextField.text);
260 PopupUtils.close(dialogue);
261 }
262 }
263 }
264 }
265}
266
0267
=== modified file 'src/app/webbrowser/searchengine.cpp'
--- src/app/webbrowser/searchengine.cpp 2014-06-30 11:01:27 +0000
+++ src/app/webbrowser/searchengine.cpp 2015-03-24 15:51:06 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright 2014 Canonical Ltd.2 * Copyright 2014-2015 Canonical Ltd.
3 *3 *
4 * This file is part of webbrowser-app.4 * This file is part of webbrowser-app.
5 *5 *
@@ -17,41 +17,71 @@
17 */17 */
1818
19// local19// local
20#include "config.h"
20#include "searchengine.h"21#include "searchengine.h"
2122
22// Qt23// Qt
23#include <QtCore/QDir>
24#include <QtCore/QFile>24#include <QtCore/QFile>
25#include <QtCore/QStandardPaths>25#include <QtCore/QStandardPaths>
26#include <QtCore/QXmlStreamReader>26#include <QtCore/QXmlStreamReader>
2727
28SearchEngine::SearchEngine(const QString& name, QObject* parent)28SearchEngine::SearchEngine(QObject* parent)
29 : QObject(parent)29 : QObject(parent)
30 , m_name(DEFAULT_SEARCH_NAME)30 , m_name(DEFAULT_SEARCH_NAME)
31 , m_description(DEFAULT_SEARCH_DESC)31 , m_description(DEFAULT_SEARCH_DESC)
32 , m_template(DEFAULT_SEARCH_TEMPLATE)32 , m_template(DEFAULT_SEARCH_TEMPLATE)
33{33{
34 QString searchenginesSubDir("searchengines");34}
35 QString filename = searchenginesSubDir + "/" + name + ".xml";35
36 m_path = QStandardPaths::locate(QStandardPaths::DataLocation, filename);36const QString& SearchEngine::filename() const
37 if (!m_path.isEmpty()) {37{
38 parseOpenSearchDescription();38 return m_filename;
39}
40
41void SearchEngine::setFilename(const QString& filename)
42{
43 if (filename != m_filename) {
44 m_filename = filename;
45 Q_EMIT filenameChanged();
46
47 m_name = DEFAULT_SEARCH_NAME;
48 m_description = DEFAULT_SEARCH_DESC;
49 m_template = DEFAULT_SEARCH_TEMPLATE;
50
51 if (!filename.isEmpty()) {
52 QString filepath = QStandardPaths::locate(QStandardPaths::DataLocation,
53 "searchengines/" + filename + ".xml");
54 if (!filepath.isEmpty()) {
55 QFile file(filepath);
56 if (file.open(QIODevice::ReadOnly)) {
57 // Parse OpenSearch description file
58 // (http://www.opensearch.org/Specifications/OpenSearch/1.1)
59 QXmlStreamReader parser(&file);
60 while (!parser.atEnd()) {
61 parser.readNext();
62 if (parser.isStartElement()) {
63 QStringRef name = parser.name();
64 if (name == "ShortName") {
65 m_name = parser.readElementText();
66 } else if (name == "Description") {
67 m_description = parser.readElementText();
68 } else if (name == "Url") {
69 if (parser.attributes().value("type") == "text/html") {
70 m_template = parser.attributes().value("template").toString();
71 }
72 }
73 }
74 }
75 }
76 }
77 }
78
79 Q_EMIT nameChanged();
80 Q_EMIT descriptionChanged();
81 Q_EMIT urlTemplateChanged();
39 }82 }
40}83}
4184
42SearchEngine::SearchEngine(const SearchEngine& other)
43{
44 m_path = other.m_path;
45 m_name = other.m_name;
46 m_description = other.m_description;
47 m_template = other.m_template;
48}
49
50bool SearchEngine::isValid() const
51{
52 return (!m_name.isEmpty() && !m_template.isEmpty());
53}
54
55const QString& SearchEngine::name() const85const QString& SearchEngine::name() const
56{86{
57 return m_name;87 return m_name;
@@ -66,27 +96,3 @@
66{96{
67 return m_template;97 return m_template;
68}98}
69
70void SearchEngine::parseOpenSearchDescription()
71{
72 QFile file(m_path);
73 if (!file.open(QIODevice::ReadOnly)) {
74 return;
75 }
76 QXmlStreamReader parser(&file);
77 while (!parser.atEnd()) {
78 parser.readNext();
79 if (parser.isStartElement()) {
80 QStringRef name = parser.name();
81 if (name == "ShortName") {
82 m_name = parser.readElementText();
83 } else if (name == "Description") {
84 m_description = parser.readElementText();
85 } else if (name == "Url") {
86 if (parser.attributes().value("type") == "text/html") {
87 m_template = parser.attributes().value("template").toString();
88 }
89 }
90 }
91 }
92}
9399
=== modified file 'src/app/webbrowser/searchengine.h'
--- src/app/webbrowser/searchengine.h 2014-06-30 10:40:59 +0000
+++ src/app/webbrowser/searchengine.h 2015-03-24 15:51:06 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright 2014 Canonical Ltd.2 * Copyright 2014-2015 Canonical Ltd.
3 *3 *
4 * This file is part of webbrowser-app.4 * This file is part of webbrowser-app.
5 *5 *
@@ -19,11 +19,7 @@
19#ifndef __SEARCH_ENGINE_H__19#ifndef __SEARCH_ENGINE_H__
20#define __SEARCH_ENGINE_H__20#define __SEARCH_ENGINE_H__
2121
22// local
23#include "config.h"
24
25// Qt22// Qt
26#include <QtCore/QMetaType>
27#include <QtCore/QObject>23#include <QtCore/QObject>
28#include <QtCore/QString>24#include <QtCore/QString>
2925
@@ -31,28 +27,32 @@
31{27{
32 Q_OBJECT28 Q_OBJECT
3329
34 Q_PROPERTY(QString name READ name CONSTANT)30 Q_PROPERTY(QString filename READ filename WRITE setFilename NOTIFY filenameChanged)
35 Q_PROPERTY(QString description READ description CONSTANT)31 Q_PROPERTY(QString name READ name NOTIFY nameChanged)
36 Q_PROPERTY(QString template READ urlTemplate CONSTANT)32 Q_PROPERTY(QString description READ description NOTIFY descriptionChanged)
33 Q_PROPERTY(QString urlTemplate READ urlTemplate NOTIFY urlTemplateChanged)
3734
38public:35public:
39 SearchEngine(const QString& name=DEFAULT_SEARCH_ENGINE, QObject* parent=0);36 SearchEngine(QObject* parent=0);
40 SearchEngine(const SearchEngine& other);37
4138 const QString& filename() const;
42 bool isValid() const;39 void setFilename(const QString& filename);
40
43 const QString& name() const;41 const QString& name() const;
44 const QString& description() const;42 const QString& description() const;
45 const QString& urlTemplate() const;43 const QString& urlTemplate() const;
4644
45Q_SIGNALS:
46 void filenameChanged() const;
47 void nameChanged() const;
48 void descriptionChanged() const;
49 void urlTemplateChanged() const;
50
47private:51private:
48 QString m_path;52 QString m_filename;
49 QString m_name;53 QString m_name;
50 QString m_description;54 QString m_description;
51 QString m_template;55 QString m_template;
52
53 void parseOpenSearchDescription();
54};56};
5557
56Q_DECLARE_METATYPE(SearchEngine);
57
58#endif // __SEARCH_ENGINE_H__58#endif // __SEARCH_ENGINE_H__
5959
=== removed file 'src/app/webbrowser/settings.cpp'
--- src/app/webbrowser/settings.cpp 2015-02-09 10:16:16 +0000
+++ src/app/webbrowser/settings.cpp 1970-01-01 00:00:00 +0000
@@ -1,57 +0,0 @@
1/*
2 * Copyright 2013-2015 Canonical Ltd.
3 *
4 * This file is part of webbrowser-app.
5 *
6 * webbrowser-app 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 3.
9 *
10 * webbrowser-app 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// local
20#include "settings.h"
21#include "config.h"
22#include "searchengine.h"
23
24// Qt
25#include <QtCore/QSettings>
26
27Settings::Settings(QObject* parent)
28 : QObject(parent)
29 , m_searchengine(NULL)
30{
31 QSettings settings(QCoreApplication::applicationName(), "settings");
32 m_homepage = settings.value("homepage", QUrl(DEFAULT_HOMEPAGE)).toUrl();
33 QString name = settings.value("searchengine", QString(DEFAULT_SEARCH_ENGINE)).toString();
34 m_searchengine = new SearchEngine(name, this);
35 m_allowOpenInBackgroundTab = settings.value("allowOpenInBackgroundTab", "default").toString().toLower();
36 m_restoreSession = settings.value("restoreSession", true).toBool();
37}
38
39const QUrl& Settings::homepage() const
40{
41 return m_homepage;
42}
43
44SearchEngine* Settings::searchEngine() const
45{
46 return m_searchengine;
47}
48
49const QString& Settings::allowOpenInBackgroundTab() const
50{
51 return m_allowOpenInBackgroundTab;
52}
53
54bool Settings::restoreSession() const
55{
56 return m_restoreSession;
57}
580
=== removed file 'src/app/webbrowser/settings.h'
--- src/app/webbrowser/settings.h 2015-02-09 10:16:16 +0000
+++ src/app/webbrowser/settings.h 1970-01-01 00:00:00 +0000
@@ -1,51 +0,0 @@
1/*
2 * Copyright 2013-2015 Canonical Ltd.
3 *
4 * This file is part of webbrowser-app.
5 *
6 * webbrowser-app 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 3.
9 *
10 * webbrowser-app 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#ifndef __SETTINGS_H__
20#define __SETTINGS_H__
21
22// Qt
23#include <QtCore/QObject>
24#include <QtCore/QUrl>
25
26class SearchEngine;
27
28/*
29 * Temporary helper class for read-only settings
30 * until Settings support lands in the SDK.
31 */
32class Settings : public QObject
33{
34 Q_OBJECT
35
36public:
37 Settings(QObject* parent=0);
38
39 const QUrl& homepage() const;
40 SearchEngine* searchEngine() const;
41 const QString& allowOpenInBackgroundTab() const;
42 bool restoreSession() const;
43
44private:
45 QUrl m_homepage;
46 SearchEngine* m_searchengine;
47 QString m_allowOpenInBackgroundTab; //"true" for enabled, "default" for form factor dependend behaviour (currently desktop only), anything else disables the option
48 bool m_restoreSession; // true by default
49};
50
51#endif // __SETTINGS_H__
520
=== added file 'src/app/webbrowser/urlManagement.js'
--- src/app/webbrowser/urlManagement.js 1970-01-01 00:00:00 +0000
+++ src/app/webbrowser/urlManagement.js 2015-03-24 15:51:06 +0000
@@ -0,0 +1,12 @@
1'use strict'
2
3function fixUrl(address) {
4 var url = address
5 if (address.substr(0, 1) == "/") {
6 url = "file://" + address
7 } else if (address.indexOf("://") == -1) {
8 url = "http://" + address
9 }
10 return url
11}
12
013
=== modified file 'src/app/webbrowser/webbrowser-app.cpp'
--- src/app/webbrowser/webbrowser-app.cpp 2015-02-27 09:28:41 +0000
+++ src/app/webbrowser/webbrowser-app.cpp 2015-03-24 15:51:06 +0000
@@ -27,7 +27,6 @@
27#include "history-domainlist-chronological-model.h"27#include "history-domainlist-chronological-model.h"
28#include "limit-proxy-model.h"28#include "limit-proxy-model.h"
29#include "searchengine.h"29#include "searchengine.h"
30#include "settings.h"
31#include "tabs-model.h"30#include "tabs-model.h"
32#include "webbrowser-app.h"31#include "webbrowser-app.h"
3332
@@ -92,16 +91,10 @@
92 qmlRegisterType<TabsModel>(uri, 0, 1, "TabsModel");91 qmlRegisterType<TabsModel>(uri, 0, 1, "TabsModel");
93 qmlRegisterType<BookmarksModel>(uri, 0, 1, "BookmarksModel");92 qmlRegisterType<BookmarksModel>(uri, 0, 1, "BookmarksModel");
94 qmlRegisterSingletonType<FileOperations>(uri, 0, 1, "FileOperations", FileOperations_singleton_factory);93 qmlRegisterSingletonType<FileOperations>(uri, 0, 1, "FileOperations", FileOperations_singleton_factory);
94 qmlRegisterType<SearchEngine>(uri, 0, 1, "SearchEngine");
9595
96 if (BrowserApplication::initialize("webbrowser/webbrowser-app.qml")) {96 if (BrowserApplication::initialize("webbrowser/webbrowser-app.qml")) {
97 Settings settings;97 m_window->setProperty("newSession", m_arguments.contains("--new-session"));
98 SearchEngine* searchEngine = settings.searchEngine();
99 searchEngine->setParent(m_window);
100 m_window->setProperty("homepage", settings.homepage());
101 m_window->setProperty("searchEngine", QVariant::fromValue(searchEngine));
102 m_window->setProperty("allowOpenInBackgroundTab", settings.allowOpenInBackgroundTab());
103 m_window->setProperty("restoreSession", settings.restoreSession() &&
104 !m_arguments.contains("--new-session"));
105 QVariantList urls;98 QVariantList urls;
106 Q_FOREACH(const QUrl& url, this->urls()) {99 Q_FOREACH(const QUrl& url, this->urls()) {
107 urls.append(url);100 urls.append(url);
108101
=== modified file 'src/app/webbrowser/webbrowser-app.qml'
--- src/app/webbrowser/webbrowser-app.qml 2015-01-29 22:25:54 +0000
+++ src/app/webbrowser/webbrowser-app.qml 2015-03-24 15:51:06 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright 2013-2014 Canonical Ltd.2 * Copyright 2013-2015 Canonical Ltd.
3 *3 *
4 * This file is part of webbrowser-app.4 * This file is part of webbrowser-app.
5 *5 *
@@ -23,12 +23,8 @@
23BrowserWindow {23BrowserWindow {
24 id: window24 id: window
2525
26 property alias searchEngine: browser.searchEngine
27 property alias restoreSession: browser.restoreSession
28 property alias allowOpenInBackgroundTab: browser.allowOpenInBackgroundTab
29
30 property alias homepage: browser.homepage
31 property alias urls: browser.initialUrls26 property alias urls: browser.initialUrls
27 property alias newSession: browser.newSession
3228
33 currentWebview: browser.currentWebview29 currentWebview: browser.currentWebview
3430

Subscribers

People subscribed via source and target branches

to status/vote changes: