diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-05 13:14:56 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-05 13:14:56 +0200 |
commit | a5b1c1c4bd44741a54895c4e84846c045facce70 (patch) | |
tree | cca1263b04351ccc8a964705b0ba06c3a7d47eea /applications/mail/main.cpp | |
parent | d7e3a79c0f3692031c4f039077faa7667bc5d696 (diff) | |
download | kube-a5b1c1c4bd44741a54895c4e84846c045facce70.tar.gz kube-a5b1c1c4bd44741a54895c4e84846c045facce70.zip |
kube-mail is now kube
Diffstat (limited to 'applications/mail/main.cpp')
-rw-r--r-- | applications/mail/main.cpp | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/applications/mail/main.cpp b/applications/mail/main.cpp deleted file mode 100644 index b02c62d2..00000000 --- a/applications/mail/main.cpp +++ /dev/null | |||
@@ -1,72 +0,0 @@ | |||
1 | #include <QApplication> | ||
2 | #include <QQmlApplicationEngine> | ||
3 | |||
4 | #include <QStandardPaths> | ||
5 | #include <KPackage/PackageLoader> | ||
6 | #include <QQuickImageProvider> | ||
7 | #include <QIcon> | ||
8 | #include <QtWebEngine> | ||
9 | #include <QDesktopServices> | ||
10 | |||
11 | #include <QDebug> | ||
12 | |||
13 | class KubeImageProvider : public QQuickImageProvider | ||
14 | { | ||
15 | public: | ||
16 | KubeImageProvider() | ||
17 | : QQuickImageProvider(QQuickImageProvider::Pixmap) | ||
18 | { | ||
19 | } | ||
20 | |||
21 | QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) Q_DECL_OVERRIDE | ||
22 | { | ||
23 | const auto icon = QIcon::fromTheme(id); | ||
24 | auto expectedSize = requestedSize; | ||
25 | if (!icon.availableSizes().contains(requestedSize) && !icon.availableSizes().isEmpty()) { | ||
26 | expectedSize = icon.availableSizes().first(); | ||
27 | } | ||
28 | const auto pixmap = icon.pixmap(expectedSize); | ||
29 | if (size) { | ||
30 | *size = pixmap.size(); | ||
31 | } | ||
32 | return pixmap; | ||
33 | } | ||
34 | }; | ||
35 | |||
36 | class WebUrlRequestInterceptor : public QWebEngineUrlRequestInterceptor | ||
37 | { | ||
38 | Q_OBJECT | ||
39 | public: | ||
40 | WebUrlRequestInterceptor(QObject *p = Q_NULLPTR) : QWebEngineUrlRequestInterceptor{p} | ||
41 | {} | ||
42 | |||
43 | void interceptRequest(QWebEngineUrlRequestInfo &info) | ||
44 | { | ||
45 | qDebug() << info.requestMethod() << info.requestUrl() << info.resourceType() << info.navigationType(); | ||
46 | const bool isNavigationRequest = info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame; | ||
47 | if (isNavigationRequest) { | ||
48 | QDesktopServices::openUrl(info.requestUrl()); | ||
49 | info.block(true); | ||
50 | } | ||
51 | //TODO handle mailto to open a composer | ||
52 | } | ||
53 | }; | ||
54 | |||
55 | int main(int argc, char *argv[]) | ||
56 | { | ||
57 | QApplication app(argc, argv); | ||
58 | |||
59 | QtWebEngine::initialize(); | ||
60 | WebUrlRequestInterceptor *wuri = new WebUrlRequestInterceptor(); | ||
61 | QQuickWebEngineProfile::defaultProfile()->setRequestInterceptor(wuri); | ||
62 | QIcon::setThemeName("kube"); | ||
63 | |||
64 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.components.mail"); | ||
65 | Q_ASSERT(package.isValid()); | ||
66 | QQmlApplicationEngine engine; | ||
67 | engine.addImageProvider(QLatin1String("kube"), new KubeImageProvider); | ||
68 | engine.load(QUrl::fromLocalFile(package.filePath("mainscript"))); | ||
69 | return app.exec(); | ||
70 | } | ||
71 | |||
72 | #include "main.moc" | ||