From 2b8653a06a716fda634d71ada0230b2076c3f639 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 24 Oct 2017 10:46:26 +0200 Subject: Only load the login view for accounts that require a keyring --- accounts/maildir/package/metadata.desktop | 1 + components/kube/contents/ui/Kube.qml | 55 +++++++++++++++++++------------ framework/src/accounts/accountfactory.cpp | 2 ++ framework/src/accounts/accountfactory.h | 2 ++ framework/src/keyring.h | 2 +- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/accounts/maildir/package/metadata.desktop b/accounts/maildir/package/metadata.desktop index 1e127fe1..ce922455 100644 --- a/accounts/maildir/package/metadata.desktop +++ b/accounts/maildir/package/metadata.desktop @@ -6,3 +6,4 @@ X-Plasma-MainScript=ui/MaildirAccountSettings.qml X-KDE-ServiceTypes=KPackage/GenericQML Icon=folder Type=Service +X-KDE-Kube-RequiresKeyring=False diff --git a/components/kube/contents/ui/Kube.qml b/components/kube/contents/ui/Kube.qml index ccbec2da..c5726eff 100644 --- a/components/kube/contents/ui/Kube.qml +++ b/components/kube/contents/ui/Kube.qml @@ -50,6 +50,11 @@ Controls2.ApplicationWindow { } } + Kube.AccountFactory { + id: accountFactory + accountId: app.currentAccount + } + //Interval sync Timer { id: intervalSync @@ -251,12 +256,39 @@ Controls2.ApplicationWindow { } Layout.fillWidth: true + function loginIfNecessary() + { + if (!!app.currentAccount && !Kube.Keyring.isUnlocked(app.currentAccount)) { + if (accountFactory.requiresKeyring) { + setLoginView() + } else { + Kube.Keyring.unlock(app.currentAccount) + } + } + } + Kube.Listener { filter: Kube.Messages.componentDone onMessageReceived: { kubeViews.pop(Controls2.StackView.Immediate) - if (!!app.currentAccount && !Kube.Keyring.isUnlocked(app.currentAccount)) { - kubeViews.setLoginView() + loginIfNecessary() + } + } + + onCurrentItemChanged: { + if (currentItem) { + currentItem.forceActiveFocus() + } + } + + Component.onCompleted: { + //Setup the initial item stack + if (!currentItem) { + setMailView() + if (startupCheck.noAccount) { + setAccountsView() + } else { + loginIfNecessary() } } } @@ -304,25 +336,6 @@ Controls2.ApplicationWindow { pushView(composerView, {message: mail, loadAsDraft: openAsDraft}) } - onCurrentItemChanged: { - if (currentItem) { - currentItem.forceActiveFocus() - } - } - - Component.onCompleted: { - //Setup the initial item stack - if (!currentItem) { - setMailView(); - if (startupCheck.noAccount) { - setAccountsView() - } else { - if (!!app.currentAccount && !Kube.Keyring.isUnlocked(app.currentAccount)) { - setLoginView() - } - } - } - } //These items are not visible until pushed onto the stack, so we keep them in resources instead of items resources: [ diff --git a/framework/src/accounts/accountfactory.cpp b/framework/src/accounts/accountfactory.cpp index 9726a2e0..1af07ac6 100644 --- a/framework/src/accounts/accountfactory.cpp +++ b/framework/src/accounts/accountfactory.cpp @@ -67,6 +67,7 @@ void AccountFactory::loadPackage() mLoginUi.clear(); mName.clear(); mIcon.clear(); + mRequiresKeyring = true; emit accountLoaded(); return; } @@ -75,5 +76,6 @@ void AccountFactory::loadPackage() mLoginUi = package.filePath("ui", "Login.qml"); mName = package.metadata().name(); mIcon = package.metadata().iconName(); + mRequiresKeyring = package.metadata().value("X-KDE-Kube-RequiresKeyring", "True").toLower() == "true"; emit accountLoaded(); } diff --git a/framework/src/accounts/accountfactory.h b/framework/src/accounts/accountfactory.h index 21747df5..f49d475c 100644 --- a/framework/src/accounts/accountfactory.h +++ b/framework/src/accounts/accountfactory.h @@ -34,6 +34,7 @@ class AccountFactory : public QObject Q_PROPERTY(QString icon MEMBER mIcon NOTIFY accountLoaded); Q_PROPERTY(QString uiPath MEMBER mUiPath NOTIFY accountLoaded); Q_PROPERTY(QString loginUi MEMBER mLoginUi NOTIFY accountLoaded); + Q_PROPERTY(bool requiresKeyring MEMBER mRequiresKeyring NOTIFY accountLoaded); public: explicit AccountFactory(QObject *parent = Q_NULLPTR); @@ -52,4 +53,5 @@ private: QString mUiPath; QString mLoginUi; QByteArray mAccountType; + bool mRequiresKeyring = true; }; diff --git a/framework/src/keyring.h b/framework/src/keyring.h index df25dbff..5d2c7544 100644 --- a/framework/src/keyring.h +++ b/framework/src/keyring.h @@ -28,7 +28,7 @@ public: Keyring(); static Keyring *instance(); Q_INVOKABLE bool isUnlocked(const QByteArray &accountId); - void unlock(const QByteArray &accountId); + Q_INVOKABLE void unlock(const QByteArray &accountId); private: Q_DISABLE_COPY(Keyring); -- cgit v1.2.3