diff --git a/accounts/kolabnow/qml/Login.qml b/accounts/kolabnow/qml/Login.qml index 877dd6a9..152cbfa7 100644 --- a/accounts/kolabnow/qml/Login.qml +++ b/accounts/kolabnow/qml/Login.qml @@ -1,61 +1,74 @@ /* Copyright (C) 2016 Michael Bohlender, Copyright (C) 2017 Christian Mollekopf, This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.4 import QtQuick.Layouts 1.1 import org.kube.framework 1.0 as Kube import org.kube.accounts.kolabnow 1.0 as KolabnowAccount Item { property alias accountId: settings.accountIdentifier property string heading: qsTr("Login") property string subheadline: settings.accountName property bool valid: pwField.acceptableInput KolabnowAccount.KolabnowSettings { id: settings accountType: "kolabnow" } function login(){ + extensionPoint.item.storeSecret(accountId, {accountSecret: pwField.text}) settings.login({accountSecret: pwField.text}) } GridLayout { anchors { fill: parent } columns: 2 columnSpacing: Kube.Units.largeSpacing rowSpacing: Kube.Units.largeSpacing Kube.Label { text: qsTr("Password") Layout.alignment: Qt.AlignRight } Kube.PasswordField { id: pwField Layout.fillWidth: true focus: true placeholderText: qsTr("Password of your Kolab Now account") + text: !!extensionPoint.item ? extensionPoint.item.secret.accountSecret : "" + } + Row { + Layout.columnSpan: 2 + Layout.rowSpan: 1 + Kube.ExtensionPoint { + id: extensionPoint + height: Kube.Units.gridUnit + width: Kube.Units.gridUnit + extensionPoint: "extensions/login" + context: {"accountId": settings.accountIdentifier, "accountName": settings.accountName} + } } } } diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index b8412096..2995e7dd 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -1,7 +1,8 @@ macro(install_extension name extensionpoint) install(DIRECTORY ${name}/qml/ DESTINATION ${QML_INSTALL_DIR}/org/kube/extensions/${extensionpoint}/${name}) #install(FILES ${name}/metadata.json DESTINATION ${QML_INSTALL_DIR}/org/kube/extensions/${name}) endmacro() add_subdirectory(api) install_extension(fileasexpense mailview) +install_extension(gpg login) diff --git a/extensions/api/src/extensionapi.cpp b/extensions/api/src/extensionapi.cpp index 3e6689b9..7dfff4ff 100644 --- a/extensions/api/src/extensionapi.cpp +++ b/extensions/api/src/extensionapi.cpp @@ -1,89 +1,103 @@ /* Copyright (c) 2018 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 "extensionapi.h" #include #include #include #include +#include +#include #include static void send(const QByteArray &message, const QByteArray &accountId) { using namespace Sink; using namespace Sink::ApplicationDomain; Q_ASSERT(!accountId.isEmpty()); Query query; query.containsFilter(ResourceCapabilities::Mail::transport); query.filter(accountId); auto job = Store::fetchAll(query) .then([=](const QList &resources) { if (!resources.isEmpty()) { auto resourceId = resources[0]->identifier(); SinkLog() << "Sending message via resource: " << resourceId; Mail mail(resourceId); mail.setMimeMessage(message); return Store::create(mail) .then([=] { //Trigger a sync, but don't wait for it. Store::synchronize(Sink::SyncScope{}.resourceFilter(resourceId)).exec(); }); } SinkWarning() << "Failed to find a mailtransport resource"; return KAsync::error(0, "Failed to find a MailTransport resource."); }) .then([&] (const KAsync::Error &) { SinkLog() << "Message was sent: "; }); job.exec(); } static QStringList toStringList(const QVariantList &list) { QStringList s; for (const auto &e : list) { s << e.toString(); } return s; } Q_INVOKABLE void ExtensionApi::forwardMail(const QVariantMap &map) { SinkLog() << "Forwarding mail " << map; auto mailObject = map.value("mail").value(); Q_ASSERT(mailObject); KMime::Message::Ptr msg(new KMime::Message); msg->setContent(KMime::CRLFtoLF(mailObject->getMimeMessage())); msg->parse(); MailTemplates::forward(msg, [map] (const KMime::Message::Ptr &fwdMessage) { auto msg = fwdMessage; msg->subject()->fromUnicodeString(map.value("subject").toString(), "utf8"); auto list = toStringList(map.value("to").toList()); for (const auto &address : list) { KMime::Types::Mailbox mb; mb.fromUnicodeString(address); msg->to()->addAddress(mb); } msg->assemble(); send(msg->encodedContent(true), map.value("accountId").toByteArray()); }); } + +void ExtensionApi::storeSecret(const QByteArray &accountId, const QVariantMap &secret) +{ + QSettings settings(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QString("/kube/secrets.ini"), QSettings::IniFormat); + settings.setValue(accountId, secret); +} + +void ExtensionApi::loadSecret(const QByteArray &accountId) +{ + QSettings settings(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QString("/kube/secrets.ini"), QSettings::IniFormat); + emit secretAvailable(accountId, settings.value(accountId).value()); +} diff --git a/extensions/api/src/extensionapi.h b/extensions/api/src/extensionapi.h index 305d1206..4208f6c6 100644 --- a/extensions/api/src/extensionapi.h +++ b/extensions/api/src/extensionapi.h @@ -1,30 +1,35 @@ /* Copyright (c) 2018 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 class ExtensionApi : public QObject { Q_OBJECT public: Q_INVOKABLE void forwardMail(const QVariantMap &map); + Q_INVOKABLE void storeSecret(const QByteArray &accountId, const QVariantMap &secret); + Q_INVOKABLE void loadSecret(const QByteArray &accountId); + +signals: + void secretAvailable(const QByteArray &accountId,const QVariantMap &secret); }; diff --git a/extensions/fileasexpense/qml/main.qml b/extensions/fileasexpense/qml/main.qml index b53951f2..38108e74 100644 --- a/extensions/fileasexpense/qml/main.qml +++ b/extensions/fileasexpense/qml/main.qml @@ -1,32 +1,31 @@ /* * Copyright (C) 2017 Christian Mollekopf, * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.7 import org.kube.framework 1.0 as Kube import org.kube.extensionapi 1.0 Kube.Button { - property variant context: {} visible: true activeFocusOnTab: false text: qsTr("File as Expense") onClicked: { ExtensionApi.forwardMail({mail: context.mail, to: ["test1@kolab.org"], subject: "Expense: " + context.subject, accountId: context.accountId}) } } diff --git a/extensions/fileasexpense/qml/main.qml b/extensions/gpg/qml/main.qml similarity index 53% copy from extensions/fileasexpense/qml/main.qml copy to extensions/gpg/qml/main.qml index b53951f2..9f0334f2 100644 --- a/extensions/fileasexpense/qml/main.qml +++ b/extensions/gpg/qml/main.qml @@ -1,32 +1,59 @@ /* * Copyright (C) 2017 Christian Mollekopf, * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.7 import org.kube.framework 1.0 as Kube import org.kube.extensionapi 1.0 -Kube.Button { - property variant context: {} - visible: true - activeFocusOnTab: false +Item { + id: root + property variant secret: null - text: qsTr("File as Expense") - onClicked: { - ExtensionApi.forwardMail({mail: context.mail, to: ["test1@kolab.org"], subject: "Expense: " + context.subject, accountId: context.accountId}) + width: Kube.Units.gridUnit * 4 + height: Kube.Units.gridUnit + + Component.onCompleted: { + loadSecret(context.accountId) + } + + function loadSecret(accountId) { + ExtensionApi.loadSecret(accountId) + } + + function storeSecret(accountId, secret) { + ExtensionApi.storeSecret(accountId, secret) + } + Connections { + target: ExtensionApi + onSecretAvailable: { + root.secret = secret + } } + Row { + anchors.fill: parent + spacing: Kube.Units.smallSpacing + Kube.CheckBox { + activeFocusOnTab: false + checked: false + } + Kube.Label { + text: qsTr("Enable GPG Keyring") + } + } + } diff --git a/framework/qml/ExtensionPoint.qml b/framework/qml/ExtensionPoint.qml index 4f66b20e..60ac287d 100644 --- a/framework/qml/ExtensionPoint.qml +++ b/framework/qml/ExtensionPoint.qml @@ -1,37 +1,39 @@ /* * Copyright (C) 2017 Christian Mollekopf, * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.7 import org.kube.framework 1.0 as Kube Repeater { id: root property alias extensionPoint: extensionModel.extensionPoint property variant context: {} + property Item item: null model: Kube.ExtensionModel { id: extensionModel } Loader { source: root.model.findSource(model.name, "main.qml") + property variant context: root.context onLoaded: { - item.context = root.context + root.item = item } } } diff --git a/framework/src/domain/settings/accountsettings.h b/framework/src/domain/settings/accountsettings.h index ac670a61..f7a40a9b 100644 --- a/framework/src/domain/settings/accountsettings.h +++ b/framework/src/domain/settings/accountsettings.h @@ -1,133 +1,133 @@ /* 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 "kube_export.h" #include #include class KUBE_EXPORT AccountSettings : public QObject { Q_OBJECT - Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier) Q_PROPERTY(QByteArray accountType READ accountType WRITE setAccountType) + Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier NOTIFY changed) Q_PROPERTY(QString icon MEMBER mIcon NOTIFY changed) Q_PROPERTY(QString accountName MEMBER mName NOTIFY changed) Q_PROPERTY(QString userName MEMBER mUsername NOTIFY identityChanged) Q_PROPERTY(QString emailAddress MEMBER mEmailAddress NOTIFY identityChanged) Q_PROPERTY(QString imapServer MEMBER mImapServer NOTIFY imapResourceChanged) Q_PROPERTY(QValidator* imapServerValidator READ imapServerValidator CONSTANT) Q_PROPERTY(QString imapUsername MEMBER mImapUsername NOTIFY imapResourceChanged) Q_PROPERTY(QString smtpServer MEMBER mSmtpServer NOTIFY smtpResourceChanged) Q_PROPERTY(QValidator* smtpServerValidator READ smtpServerValidator CONSTANT) Q_PROPERTY(QString smtpUsername MEMBER mSmtpUsername NOTIFY smtpResourceChanged) Q_PROPERTY(QString carddavServer MEMBER mCardDavServer NOTIFY cardDavResourceChanged) Q_PROPERTY(QString carddavUsername MEMBER mCardDavUsername NOTIFY cardDavResourceChanged) Q_PROPERTY(QString caldavServer MEMBER mCalDavServer NOTIFY calDavResourceChanged) Q_PROPERTY(QString caldavUsername MEMBER mCalDavUsername NOTIFY calDavResourceChanged) Q_PROPERTY(QUrl path READ path WRITE setPath NOTIFY pathChanged) Q_PROPERTY(QValidator* pathValidator READ pathValidator CONSTANT) public: AccountSettings(QObject *parent = 0); void setAccountIdentifier(const QByteArray &); QByteArray accountIdentifier() const; void setAccountType(const QByteArray &); QByteArray accountType() const; void setPath(const QUrl &); QUrl path() const; virtual QValidator *imapServerValidator() const; virtual QValidator *smtpServerValidator() const; virtual QValidator *pathValidator() const; Q_INVOKABLE virtual void load() = 0; Q_INVOKABLE virtual void save() = 0; Q_INVOKABLE virtual void remove() = 0; Q_INVOKABLE void login(const QVariantMap &secrets); signals: void imapResourceChanged(); void smtpResourceChanged(); void identityChanged(); void pathChanged(); void changed(); void cardDavResourceChanged(); void calDavResourceChanged(); protected: void saveAccount(); void saveImapResource(); void saveMaildirResource(); void saveMailtransportResource(); void saveIdentity(); void saveCardDavResource(); void saveCalDavResource(); void loadAccount(); void loadImapResource(); void loadMaildirResource(); void loadMailtransportResource(); void loadIdentity(); void loadCardDavResource(); void loadCalDavResource(); void removeAccount(); void removeResource(const QByteArray &identifier); void removeIdentity(); QByteArray mAccountIdentifier; QByteArray mAccountType; QString mIcon; QString mName; QByteArray mImapIdentifier; QString mImapServer; QString mImapUsername; QByteArray mMaildirIdentifier; QString mPath; QByteArray mMailtransportIdentifier; QString mSmtpServer; QString mSmtpUsername; QByteArray mIdentityIdentifier; QString mUsername; QString mEmailAddress; QByteArray mCardDavIdentifier; QString mCardDavServer; QString mCardDavUsername; QByteArray mCalDavIdentifier; QString mCalDavServer; QString mCalDavUsername; };