diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-05 16:17:51 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-01-08 16:26:38 +0100 |
commit | 0dc0b4be6e9ba07774efedee102a23e89eef8e85 (patch) | |
tree | 2d6c3a9388c5dde159ffbc72fdd6d0bd285741ed /framework/src | |
parent | 772eeaa715551cbb4693ab221ea8fc6dad7e1bb6 (diff) | |
download | kube-0dc0b4be6e9ba07774efedee102a23e89eef8e85.tar.gz kube-0dc0b4be6e9ba07774efedee102a23e89eef8e85.zip |
Composer test
Diffstat (limited to 'framework/src')
-rw-r--r-- | framework/src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | framework/src/domainobjectcontroller.cpp | 109 | ||||
-rw-r--r-- | framework/src/domainobjectcontroller.h | 48 | ||||
-rw-r--r-- | framework/src/frameworkplugin.cpp | 2 |
4 files changed, 160 insertions, 0 deletions
diff --git a/framework/src/CMakeLists.txt b/framework/src/CMakeLists.txt index a5b2f6bc..526fbefe 100644 --- a/framework/src/CMakeLists.txt +++ b/framework/src/CMakeLists.txt | |||
@@ -46,6 +46,7 @@ add_library(kubeframework SHARED | |||
46 | webengineprofile.cpp | 46 | webengineprofile.cpp |
47 | startupcheck.cpp | 47 | startupcheck.cpp |
48 | keyring.cpp | 48 | keyring.cpp |
49 | domainobjectcontroller.cpp | ||
49 | ) | 50 | ) |
50 | target_link_libraries(kubeframework | 51 | target_link_libraries(kubeframework |
51 | sink | 52 | sink |
diff --git a/framework/src/domainobjectcontroller.cpp b/framework/src/domainobjectcontroller.cpp new file mode 100644 index 00000000..eb1fd417 --- /dev/null +++ b/framework/src/domainobjectcontroller.cpp | |||
@@ -0,0 +1,109 @@ | |||
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 "domainobjectcontroller.h" | ||
20 | |||
21 | #include <sink/store.h> | ||
22 | #include <sink/applicationdomaintype.h> | ||
23 | #include <kmime/kmime_message.h> | ||
24 | #include <mailtemplates.h> | ||
25 | |||
26 | using namespace Kube; | ||
27 | |||
28 | DomainObjectController::DomainObjectController(QObject *parent) | ||
29 | : QObject(parent) | ||
30 | { | ||
31 | |||
32 | } | ||
33 | |||
34 | QStringList toStringList(const QVariantList &list) | ||
35 | { | ||
36 | QStringList s; | ||
37 | for (const auto &e : list) { | ||
38 | s << e.toString(); | ||
39 | } | ||
40 | return s; | ||
41 | } | ||
42 | |||
43 | void DomainObjectController::create(const QVariantMap &object) | ||
44 | { | ||
45 | using namespace Sink::ApplicationDomain; | ||
46 | qWarning() << "Creating " << object; | ||
47 | auto type = object["type"].toString(); | ||
48 | if (type == getTypeName<Mail>()) { | ||
49 | auto toAddresses = toStringList(object["to"].toList()); | ||
50 | auto ccAddresses = toStringList(object["cc"].toList()); | ||
51 | auto bccAddresses = toStringList(object["bcc"].toList()); | ||
52 | |||
53 | KMime::Types::Mailbox mb; | ||
54 | mb.fromUnicodeString("identity@example.org"); | ||
55 | auto msg = MailTemplates::createMessage({}, | ||
56 | toAddresses, | ||
57 | ccAddresses, | ||
58 | bccAddresses, | ||
59 | mb, | ||
60 | object["subject"].toString(), | ||
61 | object["body"].toString(), | ||
62 | {}, | ||
63 | {}, | ||
64 | {}, | ||
65 | {}); | ||
66 | |||
67 | Sink::Query query; | ||
68 | query.containsFilter<SinkResource::Capabilities>(ResourceCapabilities::Mail::storage); | ||
69 | query.filter<SinkResource::Account>("account1"); | ||
70 | Sink::Store::fetchAll<SinkResource>(query) | ||
71 | .then([=](const QList<SinkResource::Ptr> &resources) { | ||
72 | if (!resources.isEmpty()) { | ||
73 | auto resourceId = resources[0]->identifier(); | ||
74 | qWarning() << "Using resource " << resourceId << " from account " << resources[0]->getAccount(); | ||
75 | auto mail = ApplicationDomainType::createEntity<Mail>(resourceId); | ||
76 | mail.setMimeMessage(msg->encodedContent(true)); | ||
77 | Sink::Store::create<Mail>(mail).exec(); | ||
78 | monitor(QVariant::fromValue(Mail::Ptr::create(mail))); | ||
79 | } else { | ||
80 | qWarning() << "No resources found."; | ||
81 | } | ||
82 | }).exec(); | ||
83 | } | ||
84 | |||
85 | } | ||
86 | |||
87 | void DomainObjectController::monitor(const QVariant &object) | ||
88 | { | ||
89 | using namespace Sink::ApplicationDomain; | ||
90 | qWarning() << "Monitoring " << object; | ||
91 | auto mail = object.value<Mail::Ptr>(); | ||
92 | Q_ASSERT(mail); | ||
93 | Sink::Query query{*mail}; | ||
94 | query.setFlags(Sink::Query::LiveQuery); | ||
95 | mModel = Sink::Store::loadModel<Mail>(query); | ||
96 | QObject::connect(mModel.data(), &QAbstractItemModel::rowsInserted, [=](const QModelIndex &index, int start, int end) { | ||
97 | for (int i = start; i <= end; i++) { | ||
98 | auto mail = mModel->index(i, 0, QModelIndex()).data(Sink::Store::DomainObjectRole).value<Mail::Ptr>(); | ||
99 | mCurrentObject = QVariant::fromValue(mail); | ||
100 | emit currentObjectChanged(); | ||
101 | break; | ||
102 | } | ||
103 | }); | ||
104 | } | ||
105 | |||
106 | QVariant DomainObjectController::currentObject() const | ||
107 | { | ||
108 | return mCurrentObject; | ||
109 | } | ||
diff --git a/framework/src/domainobjectcontroller.h b/framework/src/domainobjectcontroller.h new file mode 100644 index 00000000..5805c5a8 --- /dev/null +++ b/framework/src/domainobjectcontroller.h | |||
@@ -0,0 +1,48 @@ | |||
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 | #pragma once | ||
20 | |||
21 | #include <QObject> | ||
22 | #include <QVariant> | ||
23 | #include <QAbstractItemModel> | ||
24 | #include <QSharedPointer> | ||
25 | |||
26 | namespace Kube { | ||
27 | |||
28 | class DomainObjectController : public QObject | ||
29 | { | ||
30 | Q_OBJECT | ||
31 | Q_PROPERTY(QVariant currentObject READ currentObject NOTIFY currentObjectChanged) | ||
32 | public: | ||
33 | explicit DomainObjectController(QObject *parent = 0); | ||
34 | |||
35 | QVariant currentObject() const; | ||
36 | |||
37 | Q_INVOKABLE void create(const QVariantMap &object); | ||
38 | Q_INVOKABLE void monitor(const QVariant &object); | ||
39 | |||
40 | signals: | ||
41 | void currentObjectChanged(); | ||
42 | |||
43 | private: | ||
44 | QVariant mCurrentObject; | ||
45 | QSharedPointer<QAbstractItemModel> mModel; | ||
46 | }; | ||
47 | |||
48 | } | ||
diff --git a/framework/src/frameworkplugin.cpp b/framework/src/frameworkplugin.cpp index 1de776a5..f768be1b 100644 --- a/framework/src/frameworkplugin.cpp +++ b/framework/src/frameworkplugin.cpp | |||
@@ -40,6 +40,7 @@ | |||
40 | #include "startupcheck.h" | 40 | #include "startupcheck.h" |
41 | #include "keyring.h" | 41 | #include "keyring.h" |
42 | #include "controller.h" | 42 | #include "controller.h" |
43 | #include "domainobjectcontroller.h" | ||
43 | 44 | ||
44 | #include <QtQml> | 45 | #include <QtQml> |
45 | #include <QQuickImageProvider> | 46 | #include <QQuickImageProvider> |
@@ -133,6 +134,7 @@ void FrameworkPlugin::registerTypes (const char *uri) | |||
133 | qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings"); | 134 | qmlRegisterType<Kube::Settings>(uri, 1, 0, "Settings"); |
134 | 135 | ||
135 | qmlRegisterType<Kube::Fabric::Listener>(uri, 1, 0, "Listener"); | 136 | qmlRegisterType<Kube::Fabric::Listener>(uri, 1, 0, "Listener"); |
137 | qmlRegisterType<Kube::DomainObjectController>(uri, 1, 0, "DomainObjectController"); | ||
136 | qmlRegisterSingletonType<Kube::Fabric::Fabric>(uri, 1, 0, "Fabric", fabric_singletontype_provider); | 138 | qmlRegisterSingletonType<Kube::Fabric::Fabric>(uri, 1, 0, "Fabric", fabric_singletontype_provider); |
137 | 139 | ||
138 | qmlRegisterType<KubeImage>(uri, 1, 0, "KubeImage"); | 140 | qmlRegisterType<KubeImage>(uri, 1, 0, "KubeImage"); |