From 9bfadc71a4fb694ae3946711d04acdfe009264c0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 10 Mar 2016 11:57:08 +0100 Subject: A factory to load account plugins. --- accounts/maildir/CMakeLists.txt | 7 ++- accounts/maildir/maildiraccountplugin.cpp | 2 +- .../package/contents/ui/MaildirAccountSettings.qml | 8 ++- accounts/maildir/package/metadata.desktop | 8 +++ accounts/maildir/qmldir | 4 +- components/package/contents/ui/Settings.qml | 23 ++++++- framework/domain/CMakeLists.txt | 5 +- framework/domain/accountfactory.cpp | 72 ++++++++++++++++++++++ framework/domain/accountfactory.h | 48 +++++++++++++++ framework/domain/mailplugin.cpp | 2 + 10 files changed, 165 insertions(+), 14 deletions(-) create mode 100644 accounts/maildir/package/metadata.desktop create mode 100644 framework/domain/accountfactory.cpp create mode 100644 framework/domain/accountfactory.h 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) set (QT_MIN_VERSION "5.4.0") find_package(Sink CONFIG REQUIRED) find_package(KF5Async CONFIG REQUIRED) +find_package(KF5 REQUIRED COMPONENTS Package) include_directories(SYSTEM ${KDE_INSTALL_FULL_INCLUDEDIR}/KF5/) @@ -34,7 +35,7 @@ add_library(maildiraccountplugin SHARED ${SRCS}) qt5_use_modules(maildiraccountplugin Core Quick Qml) target_link_libraries(maildiraccountplugin sink) -install(TARGETS maildiraccountplugin DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/accounts/maildir) -install(FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/accounts/maildir) -install(FILES package/contents/ui/MaildirAccountSettings.qml DESTINATION ${QML_INSTALL_DIR}/org/kde/kube/accounts/maildir) +kpackage_install_package(package org.kube.accounts.maildir "genericqml") +install(TARGETS maildiraccountplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/accounts/maildir) +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 @@ void MaildirAccountPlugin::registerTypes (const char *uri) { - Q_ASSERT(uri == QLatin1String("org.kde.kube.accounts.maildir")); + Q_ASSERT(uri == QLatin1String("org.kube.accounts.maildir")); qmlRegisterType(uri, 1, 0, "MaildirSettings"); } 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 import QtQuick.Controls 1.4 import QtQuick.Layouts 1.1 -import org.kde.kube.settings 1.0 as KubeSettings +import org.kube.framework.settings 1.0 as KubeSettings import org.kde.kube.accounts.maildir 1.0 as MaildirAccount +import org.kube.components 1.0 as KubeComponents Rectangle { id: root property string accountId property string accountName: "Maildir" + KubeComponents.ColorPalette { + id: colorPalette + } color: colorPalette.background GridLayout { @@ -82,7 +86,7 @@ Rectangle { KubeSettings.Settings { id: accountSettings - identifier: "account." + modelData + identifier: "account." + accountId property string primaryIdentity: "current" } 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 @@ +[Desktop Entry] +Name=Kube Maildir Accounts Plugin +X-KDE-PluginInfo-Name=org.kube.accounts.maildir +Exec=kpackagelauncherqml -a org.kube.accounts.maildir +X-Plasma-MainScript=ui/MaildirAccountSettings.qml +X-KDE-ServiceTypes=KPackage/GenericQML +Icon=kmail2 +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 @@ -module org.kde.kube.accounts.maildir - -AccountSettings 1.0 MaildirAccountSettings.qml +module org.kube.accounts.maildir 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 import QtQuick.Controls 1.4 import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore + import org.kube.framework.settings 1.0 as KubeSettings -import org.kde.kube.accounts.maildir 1.0 as Maildir +import org.kube.framework.domain 1.0 as KubeFramework Rectangle { id: root @@ -63,8 +65,23 @@ Rectangle { spacing: 5 Repeater { model: contextSettings.accounts - delegate: Maildir.AccountSettings { //This should be retrieved from the accounts plugin: KubeAccounts { identifier: modelData }.settingsUi - accountId: modelData + delegate: Rectangle { + KubeFramework.AccountFactory { + id: accountFactory + accountId: modelData + } + PlasmaCore.IconItem { + anchors { + verticalCenter: parent.verticalCenter + left: parent.left + // leftMargin: unit.size * 3 + } + source: accountFactory.icon + } + Label { + text: accountFactory.name + } + Loader { source: accountFactory.uiPath } } } } 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 mailtransport.cpp mailtemplates.cpp retriever.cpp + accountfactory.cpp ) add_definitions(-DMAIL_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data") find_package(CURL 7.20.0 REQUIRED) +find_package(KF5 REQUIRED COMPONENTS Package) include_directories(${CURL_INCLUDE_DIRS}) add_library(mailplugin SHARED ${mailplugin_SRCS}) qt5_use_modules(mailplugin Core Quick Qml WebKitWidgets) - -target_link_libraries(mailplugin actionplugin settingsplugin sink KF5::Otp KF5::Codecs ${CURL_LIBRARIES}) +target_link_libraries(mailplugin actionplugin settingsplugin sink KF5::Otp KF5::Codecs KF5::Package ${CURL_LIBRARIES}) install(TARGETS mailplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/framework/domain) 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 @@ +/* + Copyright (c) 2016 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ +#include "accountfactory.h" + +#include +#include +#include + +#include + +AccountFactory::AccountFactory(QObject *parent) + : QObject(parent) +{ + +} + +QString AccountFactory::name() const +{ + return "Maildir"; +} + +QString AccountFactory::icon() const +{ + return "icon"; +} + +QVariant AccountFactory::ui() const +{ + return createComponent(getAccountType()); +} + +QByteArray AccountFactory::getAccountType() const +{ + return "maildir"; +} + +QString AccountFactory::uiPath() const +{ + auto accountType = getAccountType(); + auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + accountType); + Q_ASSERT(package.isValid()); + return package.filePath("mainscript"); +} + +QVariant AccountFactory::createComponent(const QByteArray &accountType) const const +{ + qWarning() << "Trying to load accounts package " << accountType << mAccountId; + auto engine = qmlEngine(this); + Q_ASSERT(engine); + auto component = new QQmlComponent(engine, QUrl::fromLocalFile(uiPath()), QQmlComponent::PreferSynchronous); + for (const auto &error : component->errors()) { + qWarning() << error.toString(); + } + Q_ASSERT(component->isReady()); + return QVariant::fromValue(component); +} 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 @@ +/* + Copyright (c) 2016 Christian Mollekopf + + This library is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published by + the Free Software Foundation; either version 2 of the License, or (at your + option) any later version. + + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public + License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301, USA. +*/ + +#pragma once + +#include +#include + +/** + * A factory to instantiate accountp plugins. + */ +class AccountFactory : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString accountId MEMBER mAccountId); + Q_PROPERTY(QString name READ name); + Q_PROPERTY(QString icon READ icon); + Q_PROPERTY(QVariant ui READ ui); + Q_PROPERTY(QString uiPath READ uiPath); +public: + explicit AccountFactory(QObject *parent = Q_NULLPTR); + + QString name() const; + QString icon() const; + QVariant ui() const; + QString uiPath() const; + + Q_INVOKABLE QVariant createComponent(const QByteArray &accountType) const; +private: + QByteArray getAccountType() const; + QString mAccountId; +}; 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 @@ #include "composercontroller.h" #include "messageparser.h" #include "retriever.h" +#include "accountfactory.h" #include @@ -37,4 +38,5 @@ void MailPlugin::registerTypes (const char *uri) qmlRegisterType(uri, 1, 0, "ComposerController"); qmlRegisterType(uri, 1, 0, "MessageParser"); qmlRegisterType(uri, 1, 0, "Retriever"); + qmlRegisterType(uri, 1, 0, "AccountFactory"); } -- cgit v1.2.3