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 | |
parent | d0617d0ad6926c250e29d1a40db93733fa911e5d (diff) | |
download | kube-9bfadc71a4fb694ae3946711d04acdfe009264c0.tar.gz kube-9bfadc71a4fb694ae3946711d04acdfe009264c0.zip |
A factory to load account plugins.
-rw-r--r-- | accounts/maildir/CMakeLists.txt | 7 | ||||
-rw-r--r-- | accounts/maildir/maildiraccountplugin.cpp | 2 | ||||
-rw-r--r-- | accounts/maildir/package/contents/ui/MaildirAccountSettings.qml | 8 | ||||
-rw-r--r-- | accounts/maildir/package/metadata.desktop | 8 | ||||
-rw-r--r-- | accounts/maildir/qmldir | 4 | ||||
-rw-r--r-- | components/package/contents/ui/Settings.qml | 23 | ||||
-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 |
10 files changed, 165 insertions, 14 deletions
diff --git a/accounts/maildir/CMakeLists.txt b/accounts/maildir/CMakeLists.txt index d83ae0be..5307c5b0 100644 --- a/accounts/maildir/CMakeLists.txt +++ b/accounts/maildir/CMakeLists.txt | |||
@@ -22,6 +22,7 @@ find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Quick Test Gui) | |||
22 | set (QT_MIN_VERSION "5.4.0") | 22 | set (QT_MIN_VERSION "5.4.0") |
23 | find_package(Sink CONFIG REQUIRED) | 23 | find_package(Sink CONFIG REQUIRED) |
24 | find_package(KF5Async CONFIG REQUIRED) | 24 | find_package(KF5Async CONFIG REQUIRED) |
25 | find_package(KF5 REQUIRED COMPONENTS Package) | ||
25 | 26 | ||
26 | include_directories(SYSTEM ${KDE_INSTALL_FULL_INCLUDEDIR}/KF5/) | 27 | include_directories(SYSTEM ${KDE_INSTALL_FULL_INCLUDEDIR}/KF5/) |
27 | 28 | ||
@@ -34,7 +35,7 @@ add_library(maildiraccountplugin SHARED ${SRCS}) | |||
34 | qt5_use_modules(maildiraccountplugin Core Quick Qml) | 35 | qt5_use_modules(maildiraccountplugin Core Quick Qml) |
35 | target_link_libraries(maildiraccountplugin sink) | 36 | target_link_libraries(maildiraccountplugin sink) |
36 | 37 | ||
37 | install(TARGETS maildiraccountplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/accounts/maildir) | 38 | kpackage_install_package(package org.kube.accounts.maildir "genericqml") |
38 | install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/accounts/maildir) | ||
39 | install(FILES package/contents/ui/MaildirAccountSettings.qml DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/accounts/maildir) | ||
40 | 39 | ||
40 | install(TARGETS maildiraccountplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/accounts/maildir) | ||
41 | install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kube/accounts/maildir) | ||
diff --git a/accounts/maildir/maildiraccountplugin.cpp b/accounts/maildir/maildiraccountplugin.cpp index 0033613b..2c3c8c4d 100644 --- a/accounts/maildir/maildiraccountplugin.cpp +++ b/accounts/maildir/maildiraccountplugin.cpp | |||
@@ -6,6 +6,6 @@ | |||
6 | 6 | ||
7 | void MaildirAccountPlugin::registerTypes (const char *uri) | 7 | void MaildirAccountPlugin::registerTypes (const char *uri) |
8 | { | 8 | { |
9 | Q_ASSERT(uri == QLatin1String("org.kde.kube.accounts.maildir")); | 9 | Q_ASSERT(uri == QLatin1String("org.kube.accounts.maildir")); |
10 | qmlRegisterType<MaildirSettings>(uri, 1, 0, "MaildirSettings"); | 10 | qmlRegisterType<MaildirSettings>(uri, 1, 0, "MaildirSettings"); |
11 | } | 11 | } |
diff --git a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml index 77cf739f..a2564500 100644 --- a/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml +++ b/accounts/maildir/package/contents/ui/MaildirAccountSettings.qml | |||
@@ -19,14 +19,18 @@ import QtQuick 2.4 | |||
19 | import QtQuick.Controls 1.4 | 19 | import QtQuick.Controls 1.4 |
20 | import QtQuick.Layouts 1.1 | 20 | import QtQuick.Layouts 1.1 |
21 | 21 | ||
22 | import org.kde.kube.settings 1.0 as KubeSettings | 22 | import org.kube.framework.settings 1.0 as KubeSettings |
23 | import org.kde.kube.accounts.maildir 1.0 as MaildirAccount | 23 | import org.kde.kube.accounts.maildir 1.0 as MaildirAccount |
24 | import org.kube.components 1.0 as KubeComponents | ||
24 | 25 | ||
25 | Rectangle { | 26 | Rectangle { |
26 | id: root | 27 | id: root |
27 | property string accountId | 28 | property string accountId |
28 | property string accountName: "Maildir" | 29 | property string accountName: "Maildir" |
29 | 30 | ||
31 | KubeComponents.ColorPalette { | ||
32 | id: colorPalette | ||
33 | } | ||
30 | color: colorPalette.background | 34 | color: colorPalette.background |
31 | 35 | ||
32 | GridLayout { | 36 | GridLayout { |
@@ -82,7 +86,7 @@ Rectangle { | |||
82 | 86 | ||
83 | KubeSettings.Settings { | 87 | KubeSettings.Settings { |
84 | id: accountSettings | 88 | id: accountSettings |
85 | identifier: "account." + modelData | 89 | identifier: "account." + accountId |
86 | property string primaryIdentity: "current" | 90 | property string primaryIdentity: "current" |
87 | } | 91 | } |
88 | KubeSettings.Settings { | 92 | KubeSettings.Settings { |
diff --git a/accounts/maildir/package/metadata.desktop b/accounts/maildir/package/metadata.desktop new file mode 100644 index 00000000..12d444e9 --- /dev/null +++ b/accounts/maildir/package/metadata.desktop | |||
@@ -0,0 +1,8 @@ | |||
1 | [Desktop Entry] | ||
2 | Name=Kube Maildir Accounts Plugin | ||
3 | X-KDE-PluginInfo-Name=org.kube.accounts.maildir | ||
4 | Exec=kpackagelauncherqml -a org.kube.accounts.maildir | ||
5 | X-Plasma-MainScript=ui/MaildirAccountSettings.qml | ||
6 | X-KDE-ServiceTypes=KPackage/GenericQML | ||
7 | Icon=kmail2 | ||
8 | Type=Service | ||
diff --git a/accounts/maildir/qmldir b/accounts/maildir/qmldir index 70ecc786..5e4861c0 100644 --- a/accounts/maildir/qmldir +++ b/accounts/maildir/qmldir | |||
@@ -1,5 +1,3 @@ | |||
1 | module org.kde.kube.accounts.maildir | 1 | module org.kube.accounts.maildir |
2 | |||
3 | AccountSettings 1.0 MaildirAccountSettings.qml | ||
4 | 2 | ||
5 | plugin maildiraccountplugin | 3 | plugin maildiraccountplugin |
diff --git a/components/package/contents/ui/Settings.qml b/components/package/contents/ui/Settings.qml index 6d653c7b..692ddd0a 100644 --- a/components/package/contents/ui/Settings.qml +++ b/components/package/contents/ui/Settings.qml | |||
@@ -19,8 +19,10 @@ import QtQuick 2.4 | |||
19 | import QtQuick.Controls 1.4 | 19 | import QtQuick.Controls 1.4 |
20 | import QtQuick.Layouts 1.1 | 20 | import QtQuick.Layouts 1.1 |
21 | 21 | ||
22 | import org.kde.plasma.core 2.0 as PlasmaCore | ||
23 | |||
22 | import org.kube.framework.settings 1.0 as KubeSettings | 24 | import org.kube.framework.settings 1.0 as KubeSettings |
23 | import org.kde.kube.accounts.maildir 1.0 as Maildir | 25 | import org.kube.framework.domain 1.0 as KubeFramework |
24 | 26 | ||
25 | Rectangle { | 27 | Rectangle { |
26 | id: root | 28 | id: root |
@@ -63,8 +65,23 @@ Rectangle { | |||
63 | spacing: 5 | 65 | spacing: 5 |
64 | Repeater { | 66 | Repeater { |
65 | model: contextSettings.accounts | 67 | model: contextSettings.accounts |
66 | delegate: Maildir.AccountSettings { //This should be retrieved from the accounts plugin: KubeAccounts { identifier: modelData }.settingsUi | 68 | delegate: Rectangle { |
67 | accountId: modelData | 69 | KubeFramework.AccountFactory { |
70 | id: accountFactory | ||
71 | accountId: modelData | ||
72 | } | ||
73 | PlasmaCore.IconItem { | ||
74 | anchors { | ||
75 | verticalCenter: parent.verticalCenter | ||
76 | left: parent.left | ||
77 | // leftMargin: unit.size * 3 | ||
78 | } | ||
79 | source: accountFactory.icon | ||
80 | } | ||
81 | Label { | ||
82 | text: accountFactory.name | ||
83 | } | ||
84 | Loader { source: accountFactory.uiPath } | ||
68 | } | 85 | } |
69 | } | 86 | } |
70 | } | 87 | } |
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 | } |