From e2f86e32a295cddacc6053936933150d1e7c665b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 18 Aug 2018 10:55:08 +0200 Subject: A generic account. This is intended to eventually replace the protocol specific accounts. The account is used to group together several protocols to one logical service, and thus it makes sense to set it up as one. --- CMakeLists.txt | 2 +- accounts/CMakeLists.txt | 1 + accounts/generic/CMakeLists.txt | 23 +++++ accounts/generic/accountplugin.cpp | 29 ++++++ accounts/generic/accountplugin.h | 31 ++++++ accounts/generic/qml/AccountSettings.qml | 157 +++++++++++++++++++++++++++++++ accounts/generic/qml/Login.qml | 60 ++++++++++++ accounts/generic/qmldir | 3 + accounts/generic/settings.cpp | 55 +++++++++++ accounts/generic/settings.h | 33 +++++++ accounts/kolabnow/kolabnowsettings.cpp | 1 + 11 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 accounts/generic/CMakeLists.txt create mode 100644 accounts/generic/accountplugin.cpp create mode 100644 accounts/generic/accountplugin.h create mode 100644 accounts/generic/qml/AccountSettings.qml create mode 100644 accounts/generic/qml/Login.qml create mode 100644 accounts/generic/qmldir create mode 100644 accounts/generic/settings.cpp create mode 100644 accounts/generic/settings.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f3fcb3b..d07269d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ cmake_policy(SET CMP0063 NEW) option(EXPERIMENTAL_VIEWS "Install experimental views" OFF) #Do not enable this unless you actually distribute a custom extension. option(ENABLE_EXTENSION "Enable custom kube extensions" OFF) -set(AVAILABLE_ACCOUNT_PLUGINS "kolabnow" "imap" "maildir" "gmail" CACHE STRING "List of enabled account plugins (provide as semicolon separated string)" ) +set(AVAILABLE_ACCOUNT_PLUGINS "kolabnow" "imap" "maildir" "gmail" "generic" CACHE STRING "List of enabled account plugins (provide as semicolon separated string)" ) include(CPack) include(FeatureSummary) diff --git a/accounts/CMakeLists.txt b/accounts/CMakeLists.txt index bf116942..76a11c54 100644 --- a/accounts/CMakeLists.txt +++ b/accounts/CMakeLists.txt @@ -13,3 +13,4 @@ add_subdirectory(maildir) add_subdirectory(imap) add_subdirectory(kolabnow) add_subdirectory(gmail) +add_subdirectory(generic) diff --git a/accounts/generic/CMakeLists.txt b/accounts/generic/CMakeLists.txt new file mode 100644 index 00000000..f609c2e1 --- /dev/null +++ b/accounts/generic/CMakeLists.txt @@ -0,0 +1,23 @@ +project(kube-accounts-generic) + +find_package(Qt5 REQUIRED NO_MODULE COMPONENTS Core Quick Qml) + +find_package(Sink CONFIG REQUIRED) +find_package(KAsync CONFIG REQUIRED) + +set(SRCS + settings.cpp + accountplugin.cpp +) + +add_library(genericaccountplugin SHARED ${SRCS}) +target_link_libraries(genericaccountplugin + sink + frameworkplugin + Qt5::Core + Qt5::Quick + Qt5::Qml +) + +install(TARGETS genericaccountplugin DESTINATION ${QML_INSTALL_DIR}/org/kube/accounts/generic) +install_qml_account(generic) diff --git a/accounts/generic/accountplugin.cpp b/accounts/generic/accountplugin.cpp new file mode 100644 index 00000000..ef1d0af7 --- /dev/null +++ b/accounts/generic/accountplugin.cpp @@ -0,0 +1,29 @@ +/* + 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 "accountplugin.h" + +#include "settings.h" + +#include + +void AccountPlugin::registerTypes (const char *uri) +{ + Q_ASSERT(uri == QLatin1String("org.kube.accounts.generic")); + qmlRegisterType(uri, 1, 0, "Settings"); +} diff --git a/accounts/generic/accountplugin.h b/accounts/generic/accountplugin.h new file mode 100644 index 00000000..9b1bb931 --- /dev/null +++ b/accounts/generic/accountplugin.h @@ -0,0 +1,31 @@ +/* + 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 + +class AccountPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + virtual void registerTypes(const char *uri); +}; diff --git a/accounts/generic/qml/AccountSettings.qml b/accounts/generic/qml/AccountSettings.qml new file mode 100644 index 00000000..c75a526c --- /dev/null +++ b/accounts/generic/qml/AccountSettings.qml @@ -0,0 +1,157 @@ +/* + 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.generic 1.0 as GenericAccount + +Item { + + property string accountId + property string heading: qsTr("Connect your account") + property string subheadline: qsTr("To let Kube access your account, fill in email address, username and the relevant server addresses. For information about the server details, please contact your email provider.") + property bool valid: true + implicitHeight: grid.implicitHeight + + GenericAccount.Settings { + id: settings + accountIdentifier: accountId + accountType: "generic" + } + + function save(){ + settings.save() + } + + function remove(){ + settings.remove() + } + GridLayout { + id: grid + anchors.fill: parent + columns: 2 + columnSpacing: Kube.Units.largeSpacing + rowSpacing: Kube.Units.largeSpacing + + Kube.Label { + text: qsTr("Name") + Layout.alignment: Qt.AlignRight + } + Kube.RequiredTextField { + Layout.fillWidth: true + placeholderText: qsTr("Your name") + text: settings.userName + onTextChanged: { + settings.userName = text + } + } + + Kube.Label { + text: qsTr("Email address") + Layout.alignment: Qt.AlignRight + } + Kube.RequiredTextField { + Layout.fillWidth: true + + text: settings.emailAddress + onTextChanged: { + settings.emailAddress = text + settings.accountName = text + } + placeholderText: qsTr("Your email address") + } + Kube.Label { + text: qsTr("Username") + Layout.alignment: Qt.AlignRight + } + Kube.RequiredTextField { + Layout.fillWidth: true + + text: settings.imapUsername + onTextChanged: { + settings.imapUsername = text + settings.smtpUsername = text + settings.carddavUsername = text + settings.caldavUsername = text + } + placeholderText: qsTr("Your username for server access.") + } + + Kube.Label { + text: qsTr("IMAP address") + Layout.alignment: Qt.AlignRight + } + Kube.RequiredTextField { + id: imapServer + + Layout.fillWidth: true + + placeholderText: "imaps://mainserver.example.net:993" + text: settings.imapServer + onTextChanged: { + settings.imapServer = text + } + validator: settings.imapServerValidator + } + + Kube.Label { + text: qsTr("SMTP address") + Layout.alignment: Qt.AlignRight + } + Kube.RequiredTextField { + Layout.fillWidth: true + + placeholderText: "smtps://mainserver.example.net:587" + text: settings.smtpServer + onTextChanged: { + settings.smtpServer = text + } + validator: settings.smtpServerValidator + } + + Kube.Label { + text: qsTr("CardDAV address") + Layout.alignment: Qt.AlignRight + } + Kube.RequiredTextField { + Layout.fillWidth: true + + placeholderText: "https://mainserver.example.net" + text: settings.carddavServer + onTextChanged: { + settings.carddavServer = text + } + } + + Kube.Label { + text: qsTr("CalDAV address") + Layout.alignment: Qt.AlignRight + } + Kube.RequiredTextField { + Layout.fillWidth: true + + placeholderText: "https://mainserver.example.net" + text: settings.caldavServer + onTextChanged: { + settings.caldavServer = text + } + } + } +} diff --git a/accounts/generic/qml/Login.qml b/accounts/generic/qml/Login.qml new file mode 100644 index 00000000..7b5b4221 --- /dev/null +++ b/accounts/generic/qml/Login.qml @@ -0,0 +1,60 @@ +/* + 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.generic 1.0 as GenericAccount + +Item { + property alias accountId: settings.accountIdentifier + property string heading: qsTr("Login") + property string subheadline: settings.accountName + property bool valid: pwField.acceptableInput + + GenericAccount.Settings { + id: settings + accountType: "generic" + } + + function login(){ + 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 account") + } + } +} diff --git a/accounts/generic/qmldir b/accounts/generic/qmldir new file mode 100644 index 00000000..ad052cac --- /dev/null +++ b/accounts/generic/qmldir @@ -0,0 +1,3 @@ +module org.kube.accounts.generic + +plugin genericaccountplugin diff --git a/accounts/generic/settings.cpp b/accounts/generic/settings.cpp new file mode 100644 index 00000000..3f0277b3 --- /dev/null +++ b/accounts/generic/settings.cpp @@ -0,0 +1,55 @@ +/* + 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 "settings.h" + +Settings::Settings(QObject *parent) + : AccountSettings(parent) +{ +} + +void Settings::load() +{ + loadAccount(); + loadImapResource(); + loadMailtransportResource(); + loadCardDavResource(); + loadCalDavResource(); + loadIdentity(); +} + +void Settings::save() +{ + saveAccount(); + saveImapResource(); + saveMailtransportResource(); + saveCardDavResource(); + saveCalDavResource(); + saveIdentity(); +} + +void Settings::remove() +{ + removeResource(mMailtransportIdentifier); + removeResource(mImapIdentifier); + removeResource(mCardDavIdentifier); + removeResource(mCalDavIdentifier); + removeIdentity(); + removeAccount(); +} + diff --git a/accounts/generic/settings.h b/accounts/generic/settings.h new file mode 100644 index 00000000..65f2f359 --- /dev/null +++ b/accounts/generic/settings.h @@ -0,0 +1,33 @@ +/* + 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 + +class Settings : public AccountSettings +{ + Q_OBJECT + +public: + Settings(QObject *parent = 0); + + Q_INVOKABLE virtual void load() Q_DECL_OVERRIDE; + Q_INVOKABLE virtual void save() Q_DECL_OVERRIDE; + Q_INVOKABLE virtual void remove() Q_DECL_OVERRIDE; +}; diff --git a/accounts/kolabnow/kolabnowsettings.cpp b/accounts/kolabnow/kolabnowsettings.cpp index 6f1f6502..8411b5e5 100644 --- a/accounts/kolabnow/kolabnowsettings.cpp +++ b/accounts/kolabnow/kolabnowsettings.cpp @@ -29,6 +29,7 @@ void KolabnowSettings::load() loadImapResource(); loadMailtransportResource(); loadCardDavResource(); + loadCalDavResource(); loadIdentity(); } -- cgit v1.2.3