diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-10 11:57:08 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-10 11:57:08 +0100 |
commit | 9bfadc71a4fb694ae3946711d04acdfe009264c0 (patch) | |
tree | 883c944c166e8b31862ba2a898ab6aed1944b0aa /framework/domain | |
parent | d0617d0ad6926c250e29d1a40db93733fa911e5d (diff) | |
download | kube-9bfadc71a4fb694ae3946711d04acdfe009264c0.tar.gz kube-9bfadc71a4fb694ae3946711d04acdfe009264c0.zip |
A factory to load account plugins.
Diffstat (limited to 'framework/domain')
-rw-r--r-- | framework/domain/CMakeLists.txt | 5 | ||||
-rw-r--r-- | framework/domain/accountfactory.cpp | 72 | ||||
-rw-r--r-- | framework/domain/accountfactory.h | 48 | ||||
-rw-r--r-- | framework/domain/mailplugin.cpp | 2 |
4 files changed, 125 insertions, 2 deletions
diff --git a/framework/domain/CMakeLists.txt b/framework/domain/CMakeLists.txt index 361b816b..10a8c065 100644 --- a/framework/domain/CMakeLists.txt +++ b/framework/domain/CMakeLists.txt | |||
@@ -12,18 +12,19 @@ set(mailplugin_SRCS | |||
12 | mailtransport.cpp | 12 | mailtransport.cpp |
13 | mailtemplates.cpp | 13 | mailtemplates.cpp |
14 | retriever.cpp | 14 | retriever.cpp |
15 | accountfactory.cpp | ||
15 | ) | 16 | ) |
16 | add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") | 17 | add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") |
17 | 18 | ||
18 | find_package(CURL 7.20.0 REQUIRED) | 19 | find_package(CURL 7.20.0 REQUIRED) |
20 | find_package(KF5 REQUIRED COMPONENTS Package) | ||
19 | 21 | ||
20 | include_directories(${CURL_INCLUDE_DIRS}) | 22 | include_directories(${CURL_INCLUDE_DIRS}) |
21 | 23 | ||
22 | add_library(mailplugin SHARED ${mailplugin_SRCS}) | 24 | add_library(mailplugin SHARED ${mailplugin_SRCS}) |
23 | 25 | ||
24 | qt5_use_modules(mailplugin Core Quick Qml WebKitWidgets) | 26 | qt5_use_modules(mailplugin Core Quick Qml WebKitWidgets) |
25 | 27 | target_link_libraries(mailplugin actionplugin settingsplugin sink KF5::Otp KF5::Codecs KF5::Package ${CURL_LIBRARIES}) | |
26 | target_link_libraries(mailplugin actionplugin settingsplugin sink KF5::Otp KF5::Codecs ${CURL_LIBRARIES}) | ||
27 | 28 | ||
28 | install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/framework/domain) | 29 | install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/framework/domain) |
29 | install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kube/framework/domain) | 30 | install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kube/framework/domain) |
diff --git a/framework/domain/accountfactory.cpp b/framework/domain/accountfactory.cpp new file mode 100644 index 00000000..d54f70a2 --- /dev/null +++ b/framework/domain/accountfactory.cpp | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsystems.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 "accountfactory.h" | ||
20 | |||
21 | #include <QQmlComponent> | ||
22 | #include <QQmlEngine> | ||
23 | #include <QDebug> | ||
24 | |||
25 | #include <KPackage/PackageLoader> | ||
26 | |||
27 | AccountFactory::AccountFactory(QObject *parent) | ||
28 | : QObject(parent) | ||
29 | { | ||
30 | |||
31 | } | ||
32 | |||
33 | QString AccountFactory::name() const | ||
34 | { | ||
35 | return "Maildir"; | ||
36 | } | ||
37 | |||
38 | QString AccountFactory::icon() const | ||
39 | { | ||
40 | return "icon"; | ||
41 | } | ||
42 | |||
43 | QVariant AccountFactory::ui() const | ||
44 | { | ||
45 | return createComponent(getAccountType()); | ||
46 | } | ||
47 | |||
48 | QByteArray AccountFactory::getAccountType() const | ||
49 | { | ||
50 | return "maildir"; | ||
51 | } | ||
52 | |||
53 | QString AccountFactory::uiPath() const | ||
54 | { | ||
55 | auto accountType = getAccountType(); | ||
56 | auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + accountType); | ||
57 | Q_ASSERT(package.isValid()); | ||
58 | return package.filePath("mainscript"); | ||
59 | } | ||
60 | |||
61 | QVariant AccountFactory::createComponent(const QByteArray &accountType) const const | ||
62 | { | ||
63 | qWarning() << "Trying to load accounts package " << accountType << mAccountId; | ||
64 | auto engine = qmlEngine(this); | ||
65 | Q_ASSERT(engine); | ||
66 | auto component = new QQmlComponent(engine, QUrl::fromLocalFile(uiPath()), QQmlComponent::PreferSynchronous); | ||
67 | for (const auto &error : component->errors()) { | ||
68 | qWarning() << error.toString(); | ||
69 | } | ||
70 | Q_ASSERT(component->isReady()); | ||
71 | return QVariant::fromValue(component); | ||
72 | } | ||
diff --git a/framework/domain/accountfactory.h b/framework/domain/accountfactory.h new file mode 100644 index 00000000..0c6afe50 --- /dev/null +++ b/framework/domain/accountfactory.h | |||
@@ -0,0 +1,48 @@ | |||
1 | /* | ||
2 | Copyright (c) 2016 Christian Mollekopf <mollekopf@kolabsystems.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 | #include <QVariant> | ||
24 | |||
25 | /** | ||
26 | * A factory to instantiate accountp plugins. | ||
27 | */ | ||
28 | class AccountFactory : public QObject | ||
29 | { | ||
30 | Q_OBJECT | ||
31 | Q_PROPERTY(QString accountId MEMBER mAccountId); | ||
32 | Q_PROPERTY(QString name READ name); | ||
33 | Q_PROPERTY(QString icon READ icon); | ||
34 | Q_PROPERTY(QVariant ui READ ui); | ||
35 | Q_PROPERTY(QString uiPath READ uiPath); | ||
36 | public: | ||
37 | explicit AccountFactory(QObject *parent = Q_NULLPTR); | ||
38 | |||
39 | QString name() const; | ||
40 | QString icon() const; | ||
41 | QVariant ui() const; | ||
42 | QString uiPath() const; | ||
43 | |||
44 | Q_INVOKABLE QVariant createComponent(const QByteArray &accountType) const; | ||
45 | private: | ||
46 | QByteArray getAccountType() const; | ||
47 | QString mAccountId; | ||
48 | }; | ||
diff --git a/framework/domain/mailplugin.cpp b/framework/domain/mailplugin.cpp index c45666c1..dd438114 100644 --- a/framework/domain/mailplugin.cpp +++ b/framework/domain/mailplugin.cpp | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "composercontroller.h" | 25 | #include "composercontroller.h" |
26 | #include "messageparser.h" | 26 | #include "messageparser.h" |
27 | #include "retriever.h" | 27 | #include "retriever.h" |
28 | #include "accountfactory.h" | ||
28 | 29 | ||
29 | #include <QtQml> | 30 | #include <QtQml> |
30 | 31 | ||
@@ -37,4 +38,5 @@ void MailPlugin::registerTypes (const char *uri) | |||
37 | qmlRegisterType<ComposerController>(uri, 1, 0, "ComposerController"); | 38 | qmlRegisterType<ComposerController>(uri, 1, 0, "ComposerController"); |
38 | qmlRegisterType<MessageParser>(uri, 1, 0, "MessageParser"); | 39 | qmlRegisterType<MessageParser>(uri, 1, 0, "MessageParser"); |
39 | qmlRegisterType<Retriever>(uri, 1, 0, "Retriever"); | 40 | qmlRegisterType<Retriever>(uri, 1, 0, "Retriever"); |
41 | qmlRegisterType<AccountFactory>(uri, 1, 0, "AccountFactory"); | ||
40 | } | 42 | } |