]> rtime.felk.cvut.cz Git - coffee/qtwebbrowser.git/blob - src/qml/BrowserWindow.qml
3cf2b15765c8a362542a35bdb2d9b16594a4401c
[coffee/qtwebbrowser.git] / src / qml / BrowserWindow.qml
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtBrowser project.
7 **
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.
16 **
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.
24 **
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.
32 **
33 **
34 ** $QT_END_LICENSE$
35 **
36 ****************************************************************************/
37
38 import QtQuick 2.5
39 import QtWebEngine 1.1
40 import QtWebEngine.experimental 1.0
41
42 import QtQuick.Controls 1.0
43 import QtQuick.Controls.Styles 1.0
44 import QtQuick.Layouts 1.0
45 import QtQuick.Window 2.1
46 import QtQuick.Controls.Private 1.0
47 import Qt.labs.settings 1.0
48 import QtQuick.Dialogs 1.2
49
50 import "assets"
51
52 Item {
53     id: browserWindow
54
55     property Item currentWebView: {
56         return tabView.get(tabView.currentIndex) ? tabView.get(tabView.currentIndex).item.webView : null
57     }
58
59     property int toolBarSize: 80
60     property string uiColor: "#46a2da"
61     property string uiSeparatorColor: "#7ebee5"
62     property string toolBarSeparatorColor: "#a3d1ed"
63     property string buttonPressedColor: "#3f91c4"
64     property string uiHighlightColor: "#fddd5c"
65     property string inactivePagerColor: "#bcbdbe"
66     property string textFieldStrokeColor: "#3882ae"
67     property string placeholderColor: "#a0a1a2"
68     property string iconOverlayColor: "#0e202c"
69     property string iconStrokeColor: "#d6d6d6"
70     property string defaultFontFamily: "Open Sans"
71
72     property int gridViewPageItemCount: 8
73     property int gridViewMaxBookmarks: 3 * gridViewPageItemCount
74     property int tabViewMaxTabs: 10
75     property int animationDuration: 200
76     property int velocityThreshold: 400
77     property int velocityY: 0
78     property real touchY: 0
79     property real touchReference: 0
80     property bool touchGesture: false
81
82     width: 1024
83     height: 600
84     visible: true
85 /*
86     Settings {
87         id : appSettings
88         property alias autoLoadImages: loadImages.checked;
89         property alias javaScriptEnabled: javaScriptEnabled.checked;
90         property alias errorPageEnabled: errorPageEnabled.checked;
91         property alias pluginsEnabled: pluginsEnabled.checked;
92     }
93 */
94     Action {
95         shortcut: "Ctrl+D"
96         onTriggered: {
97             downloadView.visible = !downloadView.visible
98         }
99     }
100
101     Action {
102         id: focus
103         shortcut: "Ctrl+L"
104         onTriggered: {
105             navigation.addressBar.forceActiveFocus();
106             navigation.addressBar.selectAll();
107         }
108     }
109     Action {
110         shortcut: "Ctrl+R"
111         onTriggered: {
112             if (currentWebView)
113                 currentWebView.reload()
114             navigation.addressBar.forceActiveFocus()
115         }
116     }
117     Action {
118         id: newTabAction
119         shortcut: "Ctrl+T"
120         onTriggered: {
121             tabView.get(tabView.currentIndex).item.webView.takeSnapshot()
122             var tab = tabView.createEmptyTab()
123
124             if (!tab)
125                 return
126
127             navigation.addressBar.forceActiveFocus();
128             navigation.addressBar.selectAll();
129             tabView.makeCurrent(tabView.count - 1)
130             navigation.addressBar.forceActiveFocus()
131         }
132     }
133     Action {
134         shortcut: "Ctrl+W"
135         onTriggered: tabView.remove(tabView.currentIndex)
136     }
137
138     UIToolBar {
139         id: tabEditToolBar
140
141         source: "qrc:///newtab"
142         indicator: tabView.count
143
144         anchors {
145             left: parent.left
146             right: parent.right
147             top: navigation.top
148         }
149
150         visible: opacity != 0.0
151         opacity: tabView.viewState == "list" ? 1.0 : 0.0
152         onDoneClicked: tabView.viewState = "page"
153         onOptionClicked: newTabAction.trigger()
154     }
155
156         }
157     }
158     NavigationBar {
159         id: navigation
160
161         anchors {
162             left: parent.left
163             right: parent.right
164         }
165     }
166     PageView {
167         id: tabView
168         interactive: !sslDialog.visible && homeScreen.state == "disabled"
169
170         height: parent.height
171
172         anchors {
173             top: navigation.bottom
174             left: parent.left
175             right: parent.right
176         }
177
178         Component.onCompleted: {
179             var tab = createEmptyTab()
180
181             if (!tab)
182                 return
183
184             navigation.webView = tab.webView
185         }
186         onCurrentIndexChanged: {
187             if (!tabView.get(tabView.currentIndex))
188                 return
189             navigation.webView = tabView.get(tabView.currentIndex).item.webView
190         }
191     }
192
193     QtObject{
194         id: acceptedCertificates
195
196         property var acceptedUrls : []
197
198         function shouldAutoAccept(certificateError){
199             var domain = engine.domainFromString(certificateError.url)
200             return acceptedUrls.indexOf(domain) >= 0
201         }
202     }
203
204     MessageDialog {
205         id: sslDialog
206
207         property var certErrors: []
208         property var currentError: null
209         visible: certErrors.length > 0
210         icon: StandardIcon.Warning
211         standardButtons: StandardButton.No | StandardButton.Yes
212         title: "Server's certificate not trusted"
213         text: "Do you wish to continue?"
214         detailedText: "If you wish so, you may continue with an unverified certificate. " +
215                       "Accepting an unverified certificate means " +
216                       "you may not be connected with the host you tried to connect to.\n" +
217                       "Do you wish to override the security check and continue?"
218         onYes: {
219             var cert = certErrors.shift()
220             var domain = engine.domainFromString(cert.url)
221             acceptedCertificates.acceptedUrls.push(domain)
222             cert.ignoreCertificateError()
223             presentError()
224         }
225         onNo: reject()
226         onRejected: reject()
227
228         function reject(){
229             certErrors.shift().rejectCertificate()
230             presentError()
231         }
232         function enqueue(error){
233             currentError = error
234             certErrors.push(error)
235             presentError()
236         }
237         function presentError(){
238             informativeText = "SSL error from URL\n\n" + currentError.url + "\n\n" + currentError.description + "\n"
239         }
240     }
241
242     HomeScreen {
243         id: homeScreen
244         height: parent.height - toolBarSize
245         anchors {
246             top: navigation.bottom
247             left: parent.left
248             right: parent.right
249         }
250         height: parent.height - toolBarSize
251         anchors {
252             top: navigation.bottom
253             left: parent.left
254             right: parent.right
255         }
256     }
257 }