summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2018-03-21 17:34:05 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2018-03-23 16:32:01 +0100
commit0c881f0c1b77cf8876094e3647d1732210b954d1 (patch)
tree418396b4f2aae86c1cbec2cee9bcd6d36b87dda0 /extensions
parentd0029fbe0a503edcf36e6ad072b87c53ad0715eb (diff)
downloadkube-0c881f0c1b77cf8876094e3647d1732210b954d1.tar.gz
kube-0c881f0c1b77cf8876094e3647d1732210b954d1.zip
An extension mechanism load qml files at generic extension points.
and forward the email via an extension api.
Diffstat (limited to 'extensions')
-rw-r--r--extensions/CMakeLists.txt7
-rw-r--r--extensions/api/CMakeLists.txt12
-rw-r--r--extensions/api/qmldir4
-rw-r--r--extensions/api/src/CMakeLists.txt25
-rw-r--r--extensions/api/src/extensionapi.cpp89
-rw-r--r--extensions/api/src/extensionapi.h30
-rw-r--r--extensions/api/src/extensionapiplugin.cpp42
-rw-r--r--extensions/api/src/extensionapiplugin.h33
-rw-r--r--extensions/fileasexpense/qml/main.qml32
9 files changed, 274 insertions, 0 deletions
diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt
new file mode 100644
index 00000000..b8412096
--- /dev/null
+++ b/extensions/CMakeLists.txt
@@ -0,0 +1,7 @@
1macro(install_extension name extensionpoint)
2 install(DIRECTORY ${name}/qml/ DESTINATION ${QML_INSTALL_DIR}/org/kube/extensions/${extensionpoint}/${name})
3 #install(FILES ${name}/metadata.json DESTINATION ${QML_INSTALL_DIR}/org/kube/extensions/${name})
4endmacro()
5
6add_subdirectory(api)
7install_extension(fileasexpense mailview)
diff --git a/extensions/api/CMakeLists.txt b/extensions/api/CMakeLists.txt
new file mode 100644
index 00000000..82a5c7b0
--- /dev/null
+++ b/extensions/api/CMakeLists.txt
@@ -0,0 +1,12 @@
1include(GenerateExportHeader)
2include(ECMGenerateHeaders)
3include(CMakePackageConfigHelpers)
4
5set(EXTENSIONAPI_INSTALL_DIR ${QML_INSTALL_DIR}/org/kube/extensionapi)
6
7install(DIRECTORY qml/ DESTINATION ${EXTENSIONAPI_INSTALL_DIR})
8install(FILES qmldir DESTINATION ${EXTENSIONAPI_INSTALL_DIR})
9
10add_subdirectory(src)
11
12feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/extensions/api/qmldir b/extensions/api/qmldir
new file mode 100644
index 00000000..405785e5
--- /dev/null
+++ b/extensions/api/qmldir
@@ -0,0 +1,4 @@
1module org.kube.extensionapi
2depends org.kube.framework 1.0
3
4plugin extensionapiplugin
diff --git a/extensions/api/src/CMakeLists.txt b/extensions/api/src/CMakeLists.txt
new file mode 100644
index 00000000..f7e543dc
--- /dev/null
+++ b/extensions/api/src/CMakeLists.txt
@@ -0,0 +1,25 @@
1add_definitions("-Wall -std=c++14 -g")
2set(CMAKE_CXX_VISIBILITY_PRESET default)
3
4find_package(Qt5 COMPONENTS REQUIRED Core Concurrent Quick Qml WebEngineWidgets Test WebEngine Gui)
5find_package(KF5Mime 4.87.0 CONFIG REQUIRED)
6find_package(Sink 0.6.0 CONFIG REQUIRED)
7
8include_directories(../../../framework/src/domain/mime ${KMIME_INCLUDES})
9
10add_library(extensionapiplugin SHARED extensionapiplugin.cpp extensionapi.cpp)
11target_link_libraries(extensionapiplugin
12 kubeframework
13 KF5::Mime
14 sink
15 Qt5::Core
16 Qt5::Quick
17 Qt5::Qml
18 Qt5::WebEngineWidgets
19 Qt5::Test
20 Qt5::WebEngine
21 Qt5::Gui
22)
23install(TARGETS extensionapiplugin DESTINATION ${EXTENSIONAPI_INSTALL_DIR})
24
25feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
diff --git a/extensions/api/src/extensionapi.cpp b/extensions/api/src/extensionapi.cpp
new file mode 100644
index 00000000..3e6689b9
--- /dev/null
+++ b/extensions/api/src/extensionapi.cpp
@@ -0,0 +1,89 @@
1/*
2 Copyright (c) 2018 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#include "extensionapi.h"
20
21#include <mailtemplates.h>
22#include <KMime/KMimeMessage>
23#include <sink/store.h>
24#include <sink/log.h>
25
26#include <QDebug>
27
28static void send(const QByteArray &message, const QByteArray &accountId)
29{
30 using namespace Sink;
31 using namespace Sink::ApplicationDomain;
32
33 Q_ASSERT(!accountId.isEmpty());
34 Query query;
35 query.containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::transport);
36 query.filter<SinkResource::Account>(accountId);
37 auto job = Store::fetchAll<SinkResource>(query)
38 .then([=](const QList<SinkResource::Ptr> &resources) {
39 if (!resources.isEmpty()) {
40 auto resourceId = resources[0]->identifier();
41 SinkLog() << "Sending message via resource: " << resourceId;
42 Mail mail(resourceId);
43 mail.setMimeMessage(message);
44 return Store::create(mail)
45 .then<void>([=] {
46 //Trigger a sync, but don't wait for it.
47 Store::synchronize(Sink::SyncScope{}.resourceFilter(resourceId)).exec();
48 });
49 }
50 SinkWarning() << "Failed to find a mailtransport resource";
51 return KAsync::error<void>(0, "Failed to find a MailTransport resource.");
52 })
53 .then([&] (const KAsync::Error &) {
54 SinkLog() << "Message was sent: ";
55 });
56 job.exec();
57}
58
59static QStringList toStringList(const QVariantList &list)
60{
61 QStringList s;
62 for (const auto &e : list) {
63 s << e.toString();
64 }
65 return s;
66}
67
68Q_INVOKABLE void ExtensionApi::forwardMail(const QVariantMap &map)
69{
70 SinkLog() << "Forwarding mail " << map;
71 auto mailObject = map.value("mail").value<Sink::ApplicationDomain::Mail::Ptr>();
72 Q_ASSERT(mailObject);
73 KMime::Message::Ptr msg(new KMime::Message);
74 msg->setContent(KMime::CRLFtoLF(mailObject->getMimeMessage()));
75 msg->parse();
76
77 MailTemplates::forward(msg, [map] (const KMime::Message::Ptr &fwdMessage) {
78 auto msg = fwdMessage;
79 msg->subject()->fromUnicodeString(map.value("subject").toString(), "utf8");
80 auto list = toStringList(map.value("to").toList());
81 for (const auto &address : list) {
82 KMime::Types::Mailbox mb;
83 mb.fromUnicodeString(address);
84 msg->to()->addAddress(mb);
85 }
86 msg->assemble();
87 send(msg->encodedContent(true), map.value("accountId").toByteArray());
88 });
89}
diff --git a/extensions/api/src/extensionapi.h b/extensions/api/src/extensionapi.h
new file mode 100644
index 00000000..305d1206
--- /dev/null
+++ b/extensions/api/src/extensionapi.h
@@ -0,0 +1,30 @@
1/*
2 Copyright (c) 2018 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#pragma once
21
22#include <QObject>
23
24class ExtensionApi : public QObject
25{
26 Q_OBJECT
27
28public:
29 Q_INVOKABLE void forwardMail(const QVariantMap &map);
30};
diff --git a/extensions/api/src/extensionapiplugin.cpp b/extensions/api/src/extensionapiplugin.cpp
new file mode 100644
index 00000000..3f399e36
--- /dev/null
+++ b/extensions/api/src/extensionapiplugin.cpp
@@ -0,0 +1,42 @@
1/*
2 Copyright (c) 2018 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 "extensionapiplugin.h"
21
22#include "extensionapi.h"
23
24#include <QtQml>
25
26void ExtensionApiPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
27{
28 Q_UNUSED(uri);
29 Q_UNUSED(engine);
30}
31
32static QObject *extensionApiSingleton(QQmlEngine *engine, QJSEngine *scriptEngine)
33{
34 Q_UNUSED(engine)
35 Q_UNUSED(scriptEngine)
36 return new ExtensionApi;
37}
38
39void ExtensionApiPlugin::registerTypes (const char *uri)
40{
41 qmlRegisterSingletonType<ExtensionApi>(uri, 1, 0, "ExtensionApi", extensionApiSingleton);
42}
diff --git a/extensions/api/src/extensionapiplugin.h b/extensions/api/src/extensionapiplugin.h
new file mode 100644
index 00000000..e23e5cc4
--- /dev/null
+++ b/extensions/api/src/extensionapiplugin.h
@@ -0,0 +1,33 @@
1/*
2 Copyright (c) 2018 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#pragma once
21
22#include <QQmlEngine>
23#include <QQmlExtensionPlugin>
24
25class ExtensionApiPlugin : public QQmlExtensionPlugin
26{
27 Q_OBJECT
28 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
29
30public:
31 void registerTypes(const char *uri) Q_DECL_OVERRIDE;
32 void initializeEngine(QQmlEngine *engine, const char *uri) Q_DECL_OVERRIDE;
33};
diff --git a/extensions/fileasexpense/qml/main.qml b/extensions/fileasexpense/qml/main.qml
new file mode 100644
index 00000000..b53951f2
--- /dev/null
+++ b/extensions/fileasexpense/qml/main.qml
@@ -0,0 +1,32 @@
1/*
2 * Copyright (C) 2017 Christian Mollekopf, <mollekopf@kolabsys.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19import QtQuick 2.7
20import org.kube.framework 1.0 as Kube
21import org.kube.extensionapi 1.0
22
23Kube.Button {
24 property variant context: {}
25 visible: true
26 activeFocusOnTab: false
27
28 text: qsTr("File as Expense")
29 onClicked: {
30 ExtensionApi.forwardMail({mail: context.mail, to: ["test1@kolab.org"], subject: "Expense: " + context.subject, accountId: context.accountId})
31 }
32}