From f25a8fb49abf8a9b7ba5d6f8fbd4c05bd647c1c0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 22 Sep 2017 11:58:47 +0200 Subject: Fixed showing a loginview after the account setup The view managment is starting to become a mess. I guess we'll need something like a state machine in the long run managing the view transitions. --- .../accounts/contents/ui/AccountWizardPage.qml | 22 ++++++++++++-------- components/kube/contents/ui/Kube.qml | 24 ++++++++++++++-------- framework/src/domain/settings/accountsettings.cpp | 12 ++++++++--- framework/src/startupcheck.cpp | 7 ++----- framework/src/startupcheck.h | 7 ++----- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/components/accounts/contents/ui/AccountWizardPage.qml b/components/accounts/contents/ui/AccountWizardPage.qml index 74decf1f..18001419 100644 --- a/components/accounts/contents/ui/AccountWizardPage.qml +++ b/components/accounts/contents/ui/AccountWizardPage.qml @@ -32,6 +32,16 @@ FocusScope { property bool isFirstView: root.Controls2.StackView.index == 0 property bool requireSetup: false + function save() { + if (loader.item.valid) { + loader.item.save() + Kube.Fabric.postMessage(Kube.Messages.synchronize, {"accountId": loader.item.accountIdentifier}); + root.done() + } else { + console.warn("Invalid settings."); + } + } + Kube.AccountFactory { id: accountFactory accountType: root.accountType @@ -47,6 +57,8 @@ FocusScope { } } + Keys.onReturnPressed: save() + //Item to avoid anchors conflict with stack Item { anchors{ @@ -135,15 +147,7 @@ FocusScope { } text: qsTr("Save") - onClicked: { - if (loader.item.valid) { - loader.item.save() - Kube.Fabric.postMessage(Kube.Messages.synchronize, {"accountId": loader.item.accountIdentifier}); - root.done() - } else { - console.warn("Invalid settings."); - } - } + onClicked: save() } } } diff --git a/components/kube/contents/ui/Kube.qml b/components/kube/contents/ui/Kube.qml index 7625c52c..0a92b783 100644 --- a/components/kube/contents/ui/Kube.qml +++ b/components/kube/contents/ui/Kube.qml @@ -47,11 +47,7 @@ Controls2.ApplicationWindow { property variant currentAccount onCurrentAccountChanged: { if (!!currentAccount) { - if (kubeViews.currentItem && !Kube.Keyring.isUnlocked(currentAccount)) { - kubeViews.setLoginView() - } else { - Kube.Fabric.postMessage(Kube.Messages.synchronize, {"accountId": currentAccount}) - } + Kube.Fabric.postMessage(Kube.Messages.synchronize, {"accountId": currentAccount}) } } @@ -66,7 +62,7 @@ Controls2.ApplicationWindow { } Kube.StartupCheck { - onNoAccount: kubeViews.setAccountsView() + id: startupCheck } //Listener @@ -252,7 +248,12 @@ Controls2.ApplicationWindow { Kube.Listener { filter: Kube.Messages.componentDone - onMessageReceived: kubeViews.pop(Controls2.StackView.Immediate) + onMessageReceived: { + kubeViews.pop(Controls2.StackView.Immediate) + if (!!app.currentAccount && !Kube.Keyring.isUnlocked(app.currentAccount)) { + kubeViews.setLoginView() + } + } } ///Replace the current view (we can't go back to the old view, and we destroy the old view) @@ -305,10 +306,15 @@ Controls2.ApplicationWindow { } Component.onCompleted: { + //Setup the initial item stack if (!currentItem) { setMailView(); - if (!!app.currentAccount && !Kube.Keyring.isUnlocked(app.currentAccount)) { - setLoginView() + if (startupCheck.noAccount) { + setAccountsView() + } else { + if (!!app.currentAccount && !Kube.Keyring.isUnlocked(app.currentAccount)) { + setLoginView() + } } } } diff --git a/framework/src/domain/settings/accountsettings.cpp b/framework/src/domain/settings/accountsettings.cpp index c174adfe..acf85522 100644 --- a/framework/src/domain/settings/accountsettings.cpp +++ b/framework/src/domain/settings/accountsettings.cpp @@ -292,7 +292,9 @@ void AccountSettings::saveImapResource() {"server", mImapServer}, {"username", mImapUsername} }); - Kube::AccountKeyring{mAccountIdentifier}.storePassword(mImapIdentifier, mImapPassword); + if (!mImapPassword.isEmpty()) { + Kube::AccountKeyring{mAccountIdentifier}.storePassword(mImapIdentifier, mImapPassword); + } } void AccountSettings::saveCardDavResource() @@ -301,7 +303,9 @@ void AccountSettings::saveCardDavResource() {"server", mCardDavServer}, {"username", mCardDavUsername} }); - Kube::AccountKeyring{mAccountIdentifier}.storePassword(mCardDavIdentifier, mCardDavPassword); + if (!mCardDavPassword.isEmpty()) { + Kube::AccountKeyring{mAccountIdentifier}.storePassword(mCardDavIdentifier, mCardDavPassword); + } } void AccountSettings::saveMaildirResource() @@ -317,7 +321,9 @@ void AccountSettings::saveMailtransportResource() {"server", mSmtpServer}, {"username", mSmtpUsername} }); - Kube::AccountKeyring{mAccountIdentifier}.storePassword(mMailtransportIdentifier, mSmtpPassword); + if (!mSmtpPassword.isEmpty()) { + Kube::AccountKeyring{mAccountIdentifier}.storePassword(mMailtransportIdentifier, mSmtpPassword); + } } void AccountSettings::saveIdentity() diff --git a/framework/src/startupcheck.cpp b/framework/src/startupcheck.cpp index 850be7bb..fa750173 100644 --- a/framework/src/startupcheck.cpp +++ b/framework/src/startupcheck.cpp @@ -23,13 +23,10 @@ StartupCheck::StartupCheck(QObject *parent) : QObject(parent) { - QMetaObject::invokeMethod(this, "check", Qt::QueuedConnection); } -void StartupCheck::check() +bool StartupCheck::noAccount() const { auto accounts = Sink::Store::read({}); - if (accounts.isEmpty()) { - emit noAccount(); - } + return accounts.isEmpty(); } diff --git a/framework/src/startupcheck.h b/framework/src/startupcheck.h index dd79ee04..b8b2e3a0 100644 --- a/framework/src/startupcheck.h +++ b/framework/src/startupcheck.h @@ -21,12 +21,9 @@ class StartupCheck : public QObject { Q_OBJECT + Q_PROPERTY(bool noAccount READ noAccount CONSTANT); public: StartupCheck(QObject *parent = nullptr); -signals: - void noAccount(); - -private Q_SLOTS: - void check(); + bool noAccount() const; }; -- cgit v1.2.3