summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--applications/kube/main.cpp42
-rw-r--r--components/mailviewer/contents/ui/HtmlContent.qml3
-rw-r--r--framework/src/CMakeLists.txt4
-rw-r--r--framework/src/frameworkplugin.cpp9
-rw-r--r--framework/src/webengineprofile.cpp52
-rw-r--r--framework/src/webengineprofile.h28
6 files changed, 114 insertions, 24 deletions
diff --git a/applications/kube/main.cpp b/applications/kube/main.cpp
index ad7bac88..115e7b0d 100644
--- a/applications/kube/main.cpp
+++ b/applications/kube/main.cpp
@@ -1,3 +1,22 @@
1/*
2 Copyright (c) 2017 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
1#include <QApplication> 20#include <QApplication>
2#include <QQmlApplicationEngine> 21#include <QQmlApplicationEngine>
3 22
@@ -6,7 +25,6 @@
6#include <QQuickImageProvider> 25#include <QQuickImageProvider>
7#include <QIcon> 26#include <QIcon>
8#include <QtWebEngine> 27#include <QtWebEngine>
9#include <QDesktopServices>
10 28
11#include <QDebug> 29#include <QDebug>
12 30
@@ -48,32 +66,11 @@ public:
48 } 66 }
49}; 67};
50 68
51class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
52{
53 Q_OBJECT
54public:
55 WebUrlRequestInterceptor(QObject *p = Q_NULLPTR) : QWebEngineUrlRequestInterceptor{p}
56 {}
57
58 void interceptRequest(QWebEngineUrlRequestInfo &info)
59 {
60 qDebug() << info.requestMethod() << info.requestUrl() << info.resourceType() << info.navigationType();
61 const bool isNavigationRequest = info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame;
62 if (isNavigationRequest) {
63 QDesktopServices::openUrl(info.requestUrl());
64 info.block(true);
65 }
66 //TODO handle mailto to open a composer
67 }
68};
69
70int main(int argc, char *argv[]) 69int main(int argc, char *argv[])
71{ 70{
72 QApplication app(argc, argv); 71 QApplication app(argc, argv);
73 72
74 QtWebEngine::initialize(); 73 QtWebEngine::initialize();
75 WebUrlRequestInterceptor *wuri = new WebUrlRequestInterceptor();
76 QQuickWebEngineProfile::defaultProfile()->setRequestInterceptor(wuri);
77 QIcon::setThemeName("kube"); 74 QIcon::setThemeName("kube");
78 75
79 auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.components.kube"); 76 auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.components.kube");
@@ -84,4 +81,3 @@ int main(int argc, char *argv[])
84 return app.exec(); 81 return app.exec();
85} 82}
86 83
87#include "main.moc"
diff --git a/components/mailviewer/contents/ui/HtmlContent.qml b/components/mailviewer/contents/ui/HtmlContent.qml
index f864ad02..946bbe37 100644
--- a/components/mailviewer/contents/ui/HtmlContent.qml
+++ b/components/mailviewer/contents/ui/HtmlContent.qml
@@ -21,6 +21,8 @@ import QtQuick.Controls 1.3
21//TODO import QtWebEngine 1.4 21//TODO import QtWebEngine 1.4
22import QtWebEngine 1.3 22import QtWebEngine 1.3
23 23
24import org.kube.framework 1.0 as Kube
25
24Item { 26Item {
25 id: root 27 id: root
26 property string content 28 property string content
@@ -66,6 +68,7 @@ Item {
66 autoLoadIconsForPage: false 68 autoLoadIconsForPage: false
67 accelerated2dCanvasEnabled: false 69 accelerated2dCanvasEnabled: false
68 } 70 }
71 profile: Kube.WebEngineProfile
69 //TODO Disable the context menu (depends on webengine 1.4) 72 //TODO Disable the context menu (depends on webengine 1.4)
70 // onContextMenuRequested: function(request) { 73 // onContextMenuRequested: function(request) {
71 // request.accepted = true 74 // request.accepted = true
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt
index 86145d5a..1ac9d3c2 100644
--- a/framework/src/CMakeLists.txt
+++ b/framework/src/CMakeLists.txt
@@ -1,5 +1,5 @@
1 1
2find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Quick Qml WebEngineWidgets Test) 2find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Quick Qml WebEngineWidgets Test WebEngine)
3find_package(KF5Mime "4.87.0" CONFIG REQUIRED) 3find_package(KF5Mime "4.87.0" CONFIG REQUIRED)
4find_package(Sink CONFIG REQUIRED) 4find_package(Sink CONFIG REQUIRED)
5find_package(KAsync CONFIG REQUIRED) 5find_package(KAsync CONFIG REQUIRED)
@@ -43,6 +43,7 @@ set(SRCS
43 kubeimage.cpp 43 kubeimage.cpp
44 clipboardproxy.cpp 44 clipboardproxy.cpp
45 krecursivefilterproxymodel.cpp 45 krecursivefilterproxymodel.cpp
46 webengineprofile.cpp
46) 47)
47 48
48add_library(frameworkplugin SHARED ${SRCS}) 49add_library(frameworkplugin SHARED ${SRCS})
@@ -54,6 +55,7 @@ target_link_libraries(frameworkplugin
54 Qt5::Qml 55 Qt5::Qml
55 Qt5::WebEngineWidgets 56 Qt5::WebEngineWidgets
56 Qt5::Test 57 Qt5::Test
58 Qt5::WebEngine
57 KF5::Codecs 59 KF5::Codecs
58 KF5::Contacts 60 KF5::Contacts
59 KF5::Package 61 KF5::Package
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp
index 33bc8cbc..f5cd2cf5 100644
--- a/framework/src/frameworkplugin.cpp
+++ b/framework/src/frameworkplugin.cpp
@@ -35,6 +35,7 @@
35#include "fabric.h" 35#include "fabric.h"
36#include "kubeimage.h" 36#include "kubeimage.h"
37#include "clipboardproxy.h" 37#include "clipboardproxy.h"
38#include "webengineprofile.h"
38 39
39#include <QtQml> 40#include <QtQml>
40 41
@@ -45,6 +46,13 @@ static QObject *fabric_singletontype_provider(QQmlEngine *engine, QJSEngine *scr
45 return new Kube::Fabric::Fabric; 46 return new Kube::Fabric::Fabric;
46} 47}
47 48
49static QObject *webengineprofile_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
50{
51 Q_UNUSED(engine)
52 Q_UNUSED(scriptEngine)
53 return new WebEngineProfile;
54}
55
48void FrameworkPlugin::registerTypes (const char *uri) 56void FrameworkPlugin::registerTypes (const char *uri)
49{ 57{
50 qmlRegisterType<FolderListModel>(uri, 1, 0, "FolderListModel"); 58 qmlRegisterType<FolderListModel>(uri, 1, 0, "FolderListModel");
@@ -67,4 +75,5 @@ void FrameworkPlugin::registerTypes (const char *uri)
67 75
68 qmlRegisterType<KubeImage>(uri, 1, 0, "KubeImage"); 76 qmlRegisterType<KubeImage>(uri, 1, 0, "KubeImage");
69 qmlRegisterType<ClipboardProxy>(uri, 1, 0, "Clipboard"); 77 qmlRegisterType<ClipboardProxy>(uri, 1, 0, "Clipboard");
78 qmlRegisterSingletonType<WebEngineProfile>(uri, 1, 0, "WebEngineProfile", webengineprofile_singletontype_provider);
70} 79}
diff --git a/framework/src/webengineprofile.cpp b/framework/src/webengineprofile.cpp
new file mode 100644
index 00000000..d63bacb3
--- /dev/null
+++ b/framework/src/webengineprofile.cpp
@@ -0,0 +1,52 @@
1
2/*
3 Copyright (c) 2017 Christian Mollekopf <mollekopf@kolabsys.com>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#include "webengineprofile.h"
22
23#include <QWebEngineUrlRequestInterceptor>
24#include <QDebug>
25#include <QDesktopServices>
26
27class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor
28{
29 Q_OBJECT
30public:
31 WebUrlRequestInterceptor(QObject *p = Q_NULLPTR) : QWebEngineUrlRequestInterceptor{p}
32 {}
33
34 void interceptRequest(QWebEngineUrlRequestInfo &info) Q_DECL_OVERRIDE
35 {
36 qDebug() << info.requestMethod() << info.requestUrl() << info.resourceType() << info.navigationType();
37 const bool isNavigationRequest = info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame;
38 if (isNavigationRequest) {
39 QDesktopServices::openUrl(info.requestUrl());
40 info.block(true);
41 }
42 //TODO handle mailto to open a composer
43 }
44};
45
46WebEngineProfile::WebEngineProfile(QObject *parent)
47 : QQuickWebEngineProfile(parent)
48{
49 setRequestInterceptor(new WebUrlRequestInterceptor(this));
50}
51
52#include "webengineprofile.moc"
diff --git a/framework/src/webengineprofile.h b/framework/src/webengineprofile.h
new file mode 100644
index 00000000..16cea88b
--- /dev/null
+++ b/framework/src/webengineprofile.h
@@ -0,0 +1,28 @@
1/*
2 Copyright (c) 2017 Christian Mollekopf <mollekopf@kolabsys.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#include <QQuickWebEngineProfile>
21
22class WebEngineProfile : public QQuickWebEngineProfile
23{
24 Q_OBJECT
25public:
26 WebEngineProfile(QObject *parent = nullptr);
27};
28