Warning, /pim/kube/framework/qml/mailpartview/HtmlPart.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 Copyright (C) 2016 Michael Bohlender, <michael.bohlender@kdemail.net>
0003
0004 This program is free software; you can redistribute it and/or modify
0005 it under the terms of the GNU General Public License as published by
0006 the Free Software Foundation; either version 2 of the License, or
0007 (at your option) any later version.
0008
0009 This program is distributed in the hope that it will be useful,
0010 but WITHOUT ANY WARRANTY; without even the implied warranty of
0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012 GNU General Public License for more details.
0013
0014 You should have received a copy of the GNU General Public License along
0015 with this program; if not, write to the Free Software Foundation, Inc.,
0016 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017 */
0018
0019 import QtQuick 2.4
0020 import QtWebEngine 1.4
0021 import QtQuick.Controls 2.2
0022 import QtQuick.Window 2
0023
0024 import org.kube.framework 1.0 as Kube
0025
0026 Item {
0027 id: root
0028 objectName: "htmlPart"
0029 property string content
0030 property bool loaded: false
0031 //We have to give it a minimum size so the html content starts to expand
0032 property int minimumSize: 10
0033 property int contentHeight: minimumSize
0034 property int contentWidth: minimumSize
0035 property string searchString
0036 property bool autoLoadImages: false
0037
0038 onSearchStringChanged: {
0039 htmlView.findText(searchString)
0040 }
0041
0042 Flickable {
0043 id: flickable
0044 anchors.fill: parent
0045
0046
0047 clip: true
0048 boundsBehavior: Flickable.StopAtBounds
0049
0050 ScrollBar.horizontal: Kube.ScrollBar { }
0051
0052 WebEngineView {
0053 id: htmlView
0054 objectName: "htmlView"
0055 anchors.fill: parent
0056
0057 Component.onCompleted: loadHtml(content, "file:///")
0058 onLoadingChanged: {
0059 if (loadRequest.status == WebEngineView.LoadFailedStatus) {
0060 console.warn("Failed to load html content.")
0061 console.warn("Error is ", loadRequest.errorString)
0062 }
0063 root.contentWidth = Math.max(contentsSize.width, minimumSize)
0064
0065 if (loadRequest.status == WebEngineView.LoadSucceededStatus) {
0066 runJavaScript("[document.body.scrollHeight, document.body.scrollWidth, document.documentElement.scrollHeight]", function(result) {
0067 root.contentHeight = Math.min(Math.max(result[0], result[2]), 4000);
0068 root.contentWidth = Math.min(Math.max(result[1], flickable.width), 2000)
0069 root.loaded = true
0070 });
0071 }
0072 }
0073 onLinkHovered: {
0074 console.debug("Link hovered ", hoveredUrl)
0075 }
0076 onNavigationRequested: {
0077 console.debug("Nav request ", request.navigationType, request.url)
0078 if (request.navigationType == WebEngineNavigationRequest.LinkClickedNavigation) {
0079 Qt.openUrlExternally(request.url)
0080 request.action = WebEngineNavigationRequest.IgnoreRequest
0081 }
0082 }
0083 onNewViewRequested: {
0084 console.debug("New view request ", request, request.requestedUrl)
0085 //We ignore requests for new views and open a browser instead
0086 Qt.openUrlExternally(request.requestedUrl)
0087 }
0088 settings {
0089 webGLEnabled: false
0090 touchIconsEnabled: false
0091 spatialNavigationEnabled: false
0092 screenCaptureEnabled: false
0093 pluginsEnabled: false
0094 localStorageEnabled: false
0095 localContentCanAccessRemoteUrls: false
0096 localContentCanAccessFileUrls: false
0097 linksIncludedInFocusChain: false
0098 javascriptEnabled: true
0099 javascriptCanOpenWindows: false
0100 javascriptCanAccessClipboard: false
0101 hyperlinkAuditingEnabled: false
0102 fullScreenSupportEnabled: false
0103 errorPageEnabled: false
0104 //defaultTextEncoding: ???
0105 autoLoadImages: root.autoLoadImages
0106 autoLoadIconsForPage: false
0107 accelerated2dCanvasEnabled: false
0108 //The webview should not steal focus
0109 focusOnNavigationEnabled: false
0110 }
0111 profile {
0112 offTheRecord: true
0113 httpCacheType: WebEngineProfile.NoCache
0114 persistentCookiesPolicy: WebEngineProfile.NoPersistentCookies
0115 }
0116 onContextMenuRequested: function(request) {
0117 request.accepted = true
0118 }
0119 }
0120 }
0121 onContentChanged: {
0122 htmlView.loadHtml(content, "file:///");
0123 }
0124 }