From cb2b1a35e14031f15155243aee12fc862cb65ebf Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 22 Feb 2017 14:19:43 +0100 Subject: Fixed kolabnow account setup page. The account plugin supplies the configuration UI, the application supplies the scaffolding. That way we ensure the application doens't contain any account specific code and account configurations are free to offer specialized UI's that work best for them. We're not currently using a standardized controller, but if we did those controllers would have to live with the plugin, not the framework or the components. --- .../contents/ui/KolabnowAccountSettings.qml | 122 ++++++++--------- components/accounts/contents/ui/AccountWizard.qml | 76 ++--------- .../accounts/contents/ui/AccountWizardPage.qml | 144 +++++++++++++++++++++ components/package/contents/ui/AccountSwitcher.qml | 20 +-- components/package/contents/ui/EditAccount.qml | 138 ++++++++++++++++++++ .../package/contents/ui/EditAccountDialog.qml | 20 +-- framework/accounts/accountfactory.cpp | 6 + framework/accounts/accountfactory.h | 4 +- framework/domain/settings/accountsettings.cpp | 48 +++++-- framework/domain/settings/accountsettings.h | 5 + 10 files changed, 401 insertions(+), 182 deletions(-) create mode 100644 components/accounts/contents/ui/AccountWizardPage.qml create mode 100644 components/package/contents/ui/EditAccount.qml diff --git a/accounts/kolabnow/package/contents/ui/KolabnowAccountSettings.qml b/accounts/kolabnow/package/contents/ui/KolabnowAccountSettings.qml index 753762b7..46d197fa 100644 --- a/accounts/kolabnow/package/contents/ui/KolabnowAccountSettings.qml +++ b/accounts/kolabnow/package/contents/ui/KolabnowAccountSettings.qml @@ -1,5 +1,6 @@ /* 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 @@ -17,7 +18,7 @@ */ import QtQuick 2.4 -import QtQuick.Controls 1.4 +import QtQuick.Controls 1.4 as Controls import QtQuick.Layouts 1.1 import org.kde.kirigami 1.0 as Kirigami @@ -25,127 +26,108 @@ import org.kde.kirigami 1.0 as Kirigami import org.kube.framework.settings 1.0 as KubeSettings import org.kube.accounts.kolabnow 1.0 as KolabnowAccount - Item { property string accountId + property string heading: "Connect your KolabNOW account" + property string subheadline: "To let Kube access your account, fill in email address, username, password and give the account a title that will be displayed inside Kube." KolabnowAccount.KolabnowSettings { - id: kolabnowSettings - accountIdentifier: accountId + id: kolabnowSettings + accountIdentifier: accountId + accountType: "kolabnow" + } + + function save(){ + kolabnowSettings.save() } - anchors.fill: parent + function remove(){ + kolabnowSettings.remove() + } Item { anchors { fill: parent - margins: Kirigami.Units.largeSpacing * 2 - } - - Kirigami.Heading { - id: heading - text: "Connect your KOLABNOW account" - - color: Kirigami.Theme.highlightColor - } - - Label { - id: subHeadline - - anchors { - left: heading.left - top: heading.bottom - } - - width: parent.width - - text: "To let Kube access your KOLABNOW account, fill in email address and password and give the account a title that will be displayed inside Kube." - //TODO wait for kirgami theme disabled text color - opacity: 0.5 - wrapMode: Text.Wrap } - GridLayout { anchors { - top:subHeadline.bottom - bottom: parent.bottom - left: parent.left - right: parent.right - topMargin: Kirigami.Units.largeSpacing - bottomMargin: Kirigami.Units.largeSpacing * 2 + fill: parent } - columns: 2 columnSpacing: Kirigami.Units.largeSpacing rowSpacing: Kirigami.Units.largeSpacing - Kirigami.Label { + Controls.Label { text: "Title of Account" Layout.alignment: Qt.AlignRight } - TextField { + Controls.TextField { Layout.fillWidth: true - + placeholderText: "E.g. \"Work\", \"Home\" that will be displayed in Kube as name" text: kolabnowSettings.accountName - placeholderText: "KOLABNOW" onTextChanged: { kolabnowSettings.accountName = text } } - Kirigami.Label { - text: "Email address" + Controls.Label { + text: "Name" Layout.alignment: Qt.AlignRight } - TextField { + Controls.TextField { Layout.fillWidth: true - - text: kolabnowSettings.emailAddress + placeholderText: "Your name" + text: kolabnowSettings.userName onTextChanged: { - kolabnowSettings.emailAddress = text + kolabnowSettings.userName = text } } - Kirigami.Label { - text: "Password" + Controls.Label { + text: "Email address" Layout.alignment: Qt.AlignRight } - TextField { + Controls.TextField { Layout.fillWidth: true - text: kolabnowSettings.imapPassword - onTextChanged: { - kolabnowSettings.imapPassword = text - kolabnowSettings.smtpPassword = text + text: kolabnowSettings.emailAddress + onTextChanged: { + kolabnowSettings.emailAddress = text } + placeholderText: "Your email address" } - Label { - text: "" + Controls.Label { + text: "Password" + Layout.alignment: Qt.AlignRight } - Item { + RowLayout { Layout.fillWidth: true - Button { - text: "Delete" + Controls.TextField { + id: pwField + Layout.fillWidth: true - onClicked: { - kolabnowSettings.remove() - root.closeDialog() + placeholderText: "Password of your email account" + text: kolabnowSettings.imapPassword + onTextChanged: { + kolabnowSettings.imapPassword = text + kolabnowSettings.smtpPassword = text } - } - Button { - anchors.right: parent.right - - text: "Save" + echoMode: TextInput.Password + } + Controls.CheckBox { + text: "Show Password" onClicked: { - focus: true - kolabnowSettings.save() - root.closeDialog() + if(pwField.echoMode == TextInput.Password) { + pwField.echoMode = TextInput.Normal; + } else { + pwField.echoMode = TextInput.Password; + } } } } diff --git a/components/accounts/contents/ui/AccountWizard.qml b/components/accounts/contents/ui/AccountWizard.qml index 8cc90acb..ffc3f5da 100644 --- a/components/accounts/contents/ui/AccountWizard.qml +++ b/components/accounts/contents/ui/AccountWizard.qml @@ -51,47 +51,15 @@ Controls2.Popup { spacing: Kirigami.Units.largeSpacing - Controls2.Button { - - Layout.fillWidth: true - - text: "kolabnow account" - - onClicked: { - stack.push(kolabnow) - } - } - - Controls2.Button { - - Layout.fillWidth: true - - text: "gmail account" - - onClicked: { - stack.push(gmail) - } - } - - Controls2.Button { - - Layout.fillWidth: true - - text: "imap account" - - onClicked: { - stack.push(imap) - } - } - - Controls2.Button { - - Layout.fillWidth: true - - text: "maildir archive" - - onClicked: { - stack.push(maildir) + Repeater { + //TODO replace by model of available accounts + model: ["kolabnow", "imap", "maildir"] + delegate: Controls2.Button { + Layout.fillWidth: true + text: modelData +" account" + onClicked: { + stack.push(wizardPage.createObject(app, {accountType:modelData})) + } } } } @@ -99,30 +67,8 @@ Controls2.Popup { } Component { - id: kolabnow - - CreateKolabNow { - } - } - - Component { - id: gmail - - CreateGmail { - } - } - - Component { - id: imap - - CreateImap { - } - } - - Component { - id: maildir - - CreateMaildir { + id: wizardPage + AccountWizardPage { } } } diff --git a/components/accounts/contents/ui/AccountWizardPage.qml b/components/accounts/contents/ui/AccountWizardPage.qml new file mode 100644 index 00000000..967bd4ab --- /dev/null +++ b/components/accounts/contents/ui/AccountWizardPage.qml @@ -0,0 +1,144 @@ +/* + * 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.7 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 as Controls +import QtQuick.Controls 2.0 as Controls2 +import org.kde.kirigami 1.0 as Kirigami + +import org.kube.framework.accounts 1.0 as KubeAccounts + +Item { + id: root + property string accountType + + KubeAccounts.AccountFactory { + id: accountFactory + accountType: root.accountType + } + + Controls.ToolButton { + iconName: "go-previous" + tooltip: "go back" + onClicked: { + stack.pop() + } + } + + //Item to avoid anchors conflict with stack + Item { + + anchors { + fill: parent + margins: Kirigami.Units.largeSpacing * 2 + } + + Kirigami.Heading { + id: heading + text: loader.item.heading + color: Kirigami.Theme.highlightColor + } + + Kirigami.Label { + id: subHeadline + + anchors { + left: heading.left + top: heading.bottom + } + + width: parent.width + text: loader.item.subheadline + color: Kirigami.Theme.disabledTextColor + wrapMode: Text.Wrap + } + + Item { + id: accountEdit + anchors { + top:subHeadline.bottom + left: parent.left + right: parent.right + topMargin: Kirigami.Units.largeSpacing * 2 + } + + Loader { + id: loader + anchors.fill: parent + source: accountFactory.uiPath + } + } + + Item { + id: spacer + Layout.fillHeight: true + anchors { + top:accountEdit.bottom + bottom: footer.top + left: parent.left + right: parent.right + } + } + + //This is where we should place the account wizard ui + GridLayout { + id: footer + anchors { + bottom: parent.bottom + left: parent.left + right: parent.right + topMargin: Kirigami.Units.largeSpacing * 2 + } + + columns: 2 + columnSpacing: Kirigami.Units.largeSpacing + rowSpacing: Kirigami.Units.largeSpacing + + Item { + Layout.fillHeight: true + } + + Kirigami.Label { + text: "" + } + + Item { + Layout.fillWidth: true + + Controls.Button { + text: "Discard" + + onClicked: { + popup.close() + } + } + + Controls.Button { + anchors.right: parent.right + text: "Save" + onClicked: { + loader.item.save() + popup.close() + } + } + } + } + } +} diff --git a/components/package/contents/ui/AccountSwitcher.qml b/components/package/contents/ui/AccountSwitcher.qml index eb5702e0..48bb2c1b 100644 --- a/components/package/contents/ui/AccountSwitcher.qml +++ b/components/package/contents/ui/AccountSwitcher.qml @@ -72,14 +72,11 @@ Controls.ToolButton { width: parent.width Controls2.Button { - - anchors { left: parent.left bottom: parent.bottom } - //iconName: "view-refresh" text: "Sync" enabled: folderController.synchronizeAction.enabled @@ -160,15 +157,6 @@ Controls.ToolButton { Layout.fillHeight: true - KubeAccounts.AccountFactory { - id: accountFactory - accountId: model.accountId - } - - // Kirigami.Icon { - // source: model.icon - // } - Controls2.Label { text: model.name } @@ -191,20 +179,14 @@ Controls.ToolButton { text: "edit" onClicked: { - editAccountComponent.createObject(app) + editAccountComponent.createObject(app, {accountId:model.accountId}) popup.close() } Component { id: editAccountComponent - KubeComponents.EditAccountDialog { - id: editAccount - anchors.fill: parent - - accountId: accountFactory.accountId - uiSource: accountFactory.uiPath } } } diff --git a/components/package/contents/ui/EditAccount.qml b/components/package/contents/ui/EditAccount.qml new file mode 100644 index 00000000..e3e049fa --- /dev/null +++ b/components/package/contents/ui/EditAccount.qml @@ -0,0 +1,138 @@ +/* + * 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.7 +import QtQuick.Layouts 1.1 +import QtQuick.Controls 1.4 as Controls +import QtQuick.Controls 2.0 as Controls2 +import org.kde.kirigami 1.0 as Kirigami + +import org.kube.framework.accounts 1.0 as KubeAccounts + +Item { + id: root + property string accountId + + KubeAccounts.AccountFactory { + id: accountFactory + accountId: root.accountId + } + + Item { + + anchors { + fill: parent + margins: Kirigami.Units.largeSpacing * 2 + } + + Kirigami.Heading { + id: heading + text: loader.item.heading + color: Kirigami.Theme.highlightColor + } + + Kirigami.Label { + id: subHeadline + + anchors { + left: heading.left + top: heading.bottom + } + + width: parent.width + text: loader.item.subheadline + color: Kirigami.Theme.disabledTextColor + wrapMode: Text.Wrap + } + + Item { + id: accountEdit + anchors { + top:subHeadline.bottom + bottom: spacer.top + left: parent.left + right: parent.right + topMargin: Kirigami.Units.largeSpacing * 2 + } + + Loader { + id: loader + anchors.fill: parent + source: accountFactory.uiPath + onLoaded: item.accountId = root.accountId + } + } + + Item { + id: spacer + Layout.fillHeight: true + anchors { + top:accountEdit.bottom + bottom: footer.top + left: parent.left + right: parent.right + } + } + + //This is where we should place the account wizard ui + GridLayout { + id: footer + anchors { + top:spacer.bottom + bottom: parent.bottom + left: parent.left + right: parent.right + topMargin: Kirigami.Units.largeSpacing * 2 + } + + columns: 2 + columnSpacing: Kirigami.Units.largeSpacing + rowSpacing: Kirigami.Units.largeSpacing + + Item { + Layout.fillHeight: true + } + + Kirigami.Label { + text: "" + } + + Item { + Layout.fillWidth: true + + Controls.Button { + text: "Discard" + + onClicked: { + dialog.closeDialog() + } + } + + Controls.Button { + anchors.right: parent.right + text: "Save" + onClicked: { + loader.item.save() + dialog.closeDialog() + } + } + } + } + } +} diff --git a/components/package/contents/ui/EditAccountDialog.qml b/components/package/contents/ui/EditAccountDialog.qml index 19349f38..a7461640 100644 --- a/components/package/contents/ui/EditAccountDialog.qml +++ b/components/package/contents/ui/EditAccountDialog.qml @@ -21,28 +21,18 @@ import QtQuick.Layouts 1.1 import org.kde.kirigami 1.0 as Kirigami -import org.kube.framework.settings 1.0 as KubeSettings -import org.kube.framework.domain 1.0 as KubeFramework import org.kube.components 1.0 as KubeComponents KubeComponents.OverlayDialog { - id: root + id: dialog - property variant uiSource property variant accountId + EditAccount { + accountId: dialog.accountId - Item { - id: dialog anchors.centerIn: parent - height: root.height * 0.8 - width: root.width * 0.8 - - Loader { - anchors.fill: parent - - source: root.uiSource - onLoaded: item.accountId = root.accountId - } + height: dialog.height * 0.8 + width: dialog.width * 0.8 } } diff --git a/framework/accounts/accountfactory.cpp b/framework/accounts/accountfactory.cpp index c590e4b6..9dbb402b 100644 --- a/framework/accounts/accountfactory.cpp +++ b/framework/accounts/accountfactory.cpp @@ -50,6 +50,12 @@ void AccountFactory::setAccountId(const QString &accountId) }).exec(); } +void AccountFactory::setAccountType(const QString &type) +{ + mAccountType = type.toLatin1(); + loadPackage(); +} + void AccountFactory::loadPackage() { auto package = KPackage::PackageLoader::self()->loadPackage("KPackage/GenericQML", "org.kube.accounts." + mAccountType); diff --git a/framework/accounts/accountfactory.h b/framework/accounts/accountfactory.h index 047454ae..b57854e5 100644 --- a/framework/accounts/accountfactory.h +++ b/framework/accounts/accountfactory.h @@ -23,12 +23,13 @@ #include /** - * A factory to instantiate accountp plugins. + * A factory to instantiate account-plugins. */ class AccountFactory : public QObject { Q_OBJECT Q_PROPERTY(QString accountId MEMBER mAccountId WRITE setAccountId); + Q_PROPERTY(QString accountType MEMBER mAccountType WRITE setAccountType); Q_PROPERTY(QString name MEMBER mName READ name NOTIFY accountLoaded); Q_PROPERTY(QString icon MEMBER mIcon NOTIFY accountLoaded); Q_PROPERTY(QString uiPath MEMBER mUiPath NOTIFY accountLoaded); @@ -36,6 +37,7 @@ public: explicit AccountFactory(QObject *parent = Q_NULLPTR); void setAccountId(const QString &); + void setAccountType(const QString &); QString name() const; signals: diff --git a/framework/domain/settings/accountsettings.cpp b/framework/domain/settings/accountsettings.cpp index d7c8c1c0..16791a7f 100644 --- a/framework/domain/settings/accountsettings.cpp +++ b/framework/domain/settings/accountsettings.cpp @@ -34,6 +34,15 @@ AccountSettings::AccountSettings(QObject *parent) { } +void AccountSettings::setAccountType(const QByteArray &type) +{ + mAccountType = type; +} + +QByteArray AccountSettings::accountType() const +{ + return mAccountType; +} void AccountSettings::setAccountIdentifier(const QByteArray &id) { @@ -134,18 +143,32 @@ QValidator *AccountSettings::smtpServerValidator() const void AccountSettings::saveAccount() { - qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier; - Q_ASSERT(!mAccountIdentifier.isEmpty()); - SinkAccount account(mAccountIdentifier); - account.setAccountType("imap"); - account.setName(mName); - account.setIcon(mIcon); - Q_ASSERT(!account.identifier().isEmpty()); - Store::modify(account) - .onError([](const KAsync::Error &error) { - qWarning() << "Error while creating account: " << error.errorMessage;; - }) - .exec(); + if (mAccountIdentifier.isEmpty()) { + auto account = ApplicationDomainType::createEntity(); + mAccountIdentifier = account.identifier(); + Q_ASSERT(!mAccountType.isEmpty()); + account.setAccountType(mAccountType); + account.setName(mName); + account.setIcon(mIcon); + Store::create(account) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while creating account: " << error.errorMessage;; + }) + .exec(); + } else { + qDebug() << "Saving account " << mAccountIdentifier << mMailtransportIdentifier; + Q_ASSERT(!mAccountIdentifier.isEmpty()); + SinkAccount account(mAccountIdentifier); + account.setAccountType(mAccountType); + account.setName(mName); + account.setIcon(mIcon); + Q_ASSERT(!account.identifier().isEmpty()); + Store::modify(account) + .onError([](const KAsync::Error &error) { + qWarning() << "Error while creating account: " << error.errorMessage;; + }) + .exec(); + } } void AccountSettings::loadAccount() @@ -153,6 +176,7 @@ void AccountSettings::loadAccount() Q_ASSERT(!mAccountIdentifier.isEmpty()); Store::fetchOne(Query().filter(mAccountIdentifier)) .then([this](const SinkAccount &account) { + mAccountType = account.getAccountType().toLatin1(); mIcon = account.getIcon(); mName = account.getName(); emit changed(); diff --git a/framework/domain/settings/accountsettings.h b/framework/domain/settings/accountsettings.h index 08215a32..f0cecf9b 100644 --- a/framework/domain/settings/accountsettings.h +++ b/framework/domain/settings/accountsettings.h @@ -25,6 +25,7 @@ class AccountSettings : public QObject { Q_OBJECT Q_PROPERTY(QByteArray accountIdentifier READ accountIdentifier WRITE setAccountIdentifier) + Q_PROPERTY(QByteArray accountType READ accountType WRITE setAccountType) Q_PROPERTY(QString icon MEMBER mIcon NOTIFY changed) Q_PROPERTY(QString accountName MEMBER mName NOTIFY changed) @@ -50,6 +51,9 @@ public: void setAccountIdentifier(const QByteArray &); QByteArray accountIdentifier() const; + void setAccountType(const QByteArray &); + QByteArray accountType() const; + void setPath(const QUrl &); QUrl path() const; @@ -87,6 +91,7 @@ protected: void removeIdentity(); QByteArray mAccountIdentifier; + QByteArray mAccountType; QString mIcon; QString mName; -- cgit v1.2.3