diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-03 19:01:41 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-01-03 19:01:41 +0100 |
commit | a02c721c4d8ba3c342fcb317f5c779a076571fa4 (patch) | |
tree | 2bb206f9cdc6c82f1379301d10df08f6cfab23fa /applications | |
parent | eef9b8725637f448f9f10ba9851f49c9df4bfe6f (diff) | |
download | kube-a02c721c4d8ba3c342fcb317f5c779a076571fa4.tar.gz kube-a02c721c4d8ba3c342fcb317f5c779a076571fa4.zip |
Intercept link clicks and try to open an external browser.
Diffstat (limited to 'applications')
-rw-r--r-- | applications/mail/main.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/applications/mail/main.cpp b/applications/mail/main.cpp index cb5350a2..9f3003d0 100644 --- a/applications/mail/main.cpp +++ b/applications/mail/main.cpp | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <QQuickImageProvider> | 6 | #include <QQuickImageProvider> |
7 | #include <QIcon> | 7 | #include <QIcon> |
8 | #include <QtWebEngine> | 8 | #include <QtWebEngine> |
9 | #include <QDesktopServices> | ||
9 | 10 | ||
10 | #include <QDebug> | 11 | #include <QDebug> |
11 | 12 | ||
@@ -32,10 +33,30 @@ public: | |||
32 | } | 33 | } |
33 | }; | 34 | }; |
34 | 35 | ||
36 | class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor | ||
37 | { | ||
38 | Q_OBJECT | ||
39 | public: | ||
40 | WebUrlRequestInterceptor(QObject *p = Q_NULLPTR) : QWebEngineUrlRequestInterceptor{} | ||
41 | {} | ||
42 | |||
43 | void interceptRequest(QWebEngineUrlRequestInfo &info) | ||
44 | { | ||
45 | qWarning() << info.requestMethod() << info.requestUrl(); | ||
46 | QDesktopServices::openUrl(info.requestUrl()); | ||
47 | info.block(true); | ||
48 | //TODO handle mailto to open a composer | ||
49 | } | ||
50 | }; | ||
51 | |||
35 | int main(int argc, char *argv[]) | 52 | int main(int argc, char *argv[]) |
36 | { | 53 | { |
37 | QApplication app(argc, argv); | 54 | QApplication app(argc, argv); |
55 | |||
38 | QtWebEngine::initialize(); | 56 | QtWebEngine::initialize(); |
57 | WebUrlRequestInterceptor *wuri = new WebUrlRequestInterceptor(); | ||
58 | QQuickWebEngineProfile::defaultProfile()->setRequestInterceptor(wuri); | ||
59 | |||
39 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.components.mail"); | 60 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.components.mail"); |
40 | Q_ASSERT(package.isValid()); | 61 | Q_ASSERT(package.isValid()); |
41 | QQmlApplicationEngine engine; | 62 | QQmlApplicationEngine engine; |
@@ -43,3 +64,5 @@ int main(int argc, char *argv[]) | |||
43 | engine.load(QUrl::fromLocalFile(package.filePath("mainscript"))); | 64 | engine.load(QUrl::fromLocalFile(package.filePath("mainscript"))); |
44 | return app.exec(); | 65 | return app.exec(); |
45 | } | 66 | } |
67 | |||
68 | #include "main.moc" | ||