WebView.qml 3.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/***************************************************************************
 *                                                                         *
 *   Copyright 2014-2015 Sebastian Kügler <sebas@kde.org>                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 *                                                                         *
 ***************************************************************************/

import QtQuick 2.3
Jonah Brüchert's avatar
Jonah Brüchert committed
23
import QtQuick.Controls 2.0
24

Jonah Brüchert's avatar
Jonah Brüchert committed
25
import QtWebEngine 1.4
26
27
28
29
30
31
32


WebEngineView {
    id: webEngineView

    property string errorCode: ""
    property string errorString: ""
33
    property string userAgent: "Mozilla/5.0 (Linux; Plasma Mobile, like Android 7.0 ) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36"
34
35
36
37

    width: pageWidth
    height: pageHeight

Jonah Brüchert's avatar
Jonah Brüchert committed
38
    profile.httpUserAgent: userAgent
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

    //Rectangle { color: "yellow"; opacity: 0.3; anchors.fill: parent }
    focus: true
    onLoadingChanged: { // Doesn't work!?!
        //print("Loading: " + loading);
        print("    url: " + loadRequest.url)
        //print("   icon: " + webEngineView.icon)
        //print("  title: " + webEngineView.title)

        /* Handle
        *  - WebEngineView::LoadStartedStatus,
        *  - WebEngineView::LoadStoppedStatus,
        *  - WebEngineView::LoadSucceededStatus and
        *  - WebEngineView::LoadFailedStatus
        */
        var ec = "";
        var es = "";
        //print("Load: " + loadRequest.errorCode + " " + loadRequest.errorString);
        if (loadRequest.status == WebEngineView.LoadStartedStatus) {
            if (contentView.state != "settings") { // Kludge!

                contentView.state = "hidden";
            }
        }
        if (loadRequest.status == WebEngineView.LoadSucceededStatus) {
            // record history, set current page info
            //contentView.state = "hidden"
            //pageInfo.url = webEngineView.url;
            //pageInfo.title = webEngineView.title;
            //pageInfo.icon = webEngineView.icon;
            addHistoryEntry();

        }
        if (loadRequest.status == WebEngineView.LoadFailedStatus) {
            print("Load failed: " + loadRequest.errorCode + " " + loadRequest.errorString);
            ec = loadRequest.errorCode;
            es = loadRequest.errorString;
            contentView.state = "hidden"
        }
        errorCode = ec;
        errorString = es;
    }

//             onLoadProgressChanged: {
//                 if (loadProgress > 50) {
//                     contentView.state = "hidden";
//                 }
//             }
87

88
89
    Component.onCompleted: {
        print("WebView completed.");
Jonah Brüchert's avatar
Jonah Brüchert committed
90
        var settings = webEngineView.settings;
91
92
        print("Settings: " + settings);
    }
93
94
95
96
97

    onIconChanged: {
        if (icon)
            browserManager.history.updateIcon(url, icon)
    }
98
}