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. --- framework/accounts/accountfactory.cpp | 6 ++++ framework/accounts/accountfactory.h | 4 ++- framework/domain/settings/accountsettings.cpp | 48 ++++++++++++++++++++------- framework/domain/settings/accountsettings.h | 5 +++ 4 files changed, 50 insertions(+), 13 deletions(-) (limited to 'framework') 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