From 819c6f545087f6d636a3db5093a285401756036d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 21 Dec 2017 11:25:09 +0100 Subject: A separate accounts module that listens for the account selection, and requests a login if necessary. --- components/kube/qml/Accounts.qml | 42 +++++++++++++++++++++++++++++++++ components/kube/qml/Kube.qml | 38 +++++++---------------------- components/kube/qml/LogView.qml | 2 +- framework/qml/EditAccount.qml | 2 +- framework/qml/InlineAccountSwitcher.qml | 2 +- 5 files changed, 53 insertions(+), 33 deletions(-) create mode 100644 components/kube/qml/Accounts.qml diff --git a/components/kube/qml/Accounts.qml b/components/kube/qml/Accounts.qml new file mode 100644 index 00000000..40a2c70b --- /dev/null +++ b/components/kube/qml/Accounts.qml @@ -0,0 +1,42 @@ +/* + * 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 org.kube.framework 1.0 as Kube + +Item { + + Kube.AccountFactory { + id: accountFactory + } + + Kube.Listener { + filter: Kube.Messages.accountSelection + onMessageReceived: { + accountFactory.accountId = message.accountId + if (!Kube.Keyring.isUnlocked(message.accountId)) { + if (accountFactory.requiresKeyring) { + Kube.Fabric.postMessage(Kube.Messages.requestLogin, {accountId: message.accountId}) + } else { + Kube.Keyring.unlock(message.accountId) + } + } + } + } + +} diff --git a/components/kube/qml/Kube.qml b/components/kube/qml/Kube.qml index 79b18a2f..e7c4f70e 100644 --- a/components/kube/qml/Kube.qml +++ b/components/kube/qml/Kube.qml @@ -1,5 +1,6 @@ /* * Copyright (C) 2017 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 @@ -50,12 +51,6 @@ Controls2.ApplicationWindow { } } - //accountId -> requiresKeyring - Kube.AccountFactory { - id: accountFactory - accountId: !!app.currentAccount ? app.currentAccount : "" - } - //Interval sync Timer { id: intervalSync @@ -70,10 +65,13 @@ Controls2.ApplicationWindow { id: startupCheck } + Accounts { + } + //Listener Kube.Listener { filter: Kube.Messages.accountSelection - onMessageReceived: app.currentAccount = message.account + onMessageReceived: app.currentAccount = message.accountId } Kube.Listener { @@ -109,7 +107,7 @@ Controls2.ApplicationWindow { Kube.Listener { filter: Kube.Messages.requestLogin - onMessageReceived: kubeViews.setLoginView() + onMessageReceived: kubeViews.setLoginView(message.accountId) } Kube.Listener { @@ -126,12 +124,6 @@ Controls2.ApplicationWindow { onActivated: Kube.Fabric.postMessage(Kube.Messages.search, {}) sequence: StandardKey.Find } - Shortcut { - onActivated: { - Kube.Fabric.postMessage(Kube.Messages.unlockKeyring, {accountId: app.currentAccount}) - } - sequence: "Ctrl+l" - } Shortcut { id: syncShortcut sequence: StandardKey.Refresh @@ -262,17 +254,6 @@ 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: { @@ -282,7 +263,6 @@ Controls2.ApplicationWindow { } else { kubeViews.pop(Controls2.StackView.Immediate) } - kubeViews.loginIfNecessary() } } @@ -298,8 +278,6 @@ Controls2.ApplicationWindow { setMailView() if (startupCheck.noAccount) { setAccountsView() - } else { - loginIfNecessary() } } } @@ -333,9 +311,9 @@ Controls2.ApplicationWindow { replaceView(logView) } - function setLoginView() { + function setLoginView(account) { if (currentItem != loginView) { - pushView(loginView, {accountId: currentAccount}) + pushView(loginView, {accountId: account}) } } diff --git a/components/kube/qml/LogView.qml b/components/kube/qml/LogView.qml index 3b0aa2d5..4ae1a67c 100644 --- a/components/kube/qml/LogView.qml +++ b/components/kube/qml/LogView.qml @@ -285,7 +285,7 @@ Controls.SplitView { text: qsTr("Change Password") onClicked: { Kube.Fabric.postMessage(Kube.Messages.componentDone, {}) - Kube.Fabric.postMessage(Kube.Messages.requestLogin, {}) + Kube.Fabric.postMessage(Kube.Messages.requestLogin, {accountId: accountId}) } } } diff --git a/framework/qml/EditAccount.qml b/framework/qml/EditAccount.qml index 872d9d03..2c73617f 100644 --- a/framework/qml/EditAccount.qml +++ b/framework/qml/EditAccount.qml @@ -84,7 +84,7 @@ Item { text: qsTr("Change Password") onClicked: { Kube.Fabric.postMessage(Kube.Messages.componentDone, {}) - Kube.Fabric.postMessage(Kube.Messages.requestLogin, {}) + Kube.Fabric.postMessage(Kube.Messages.requestLogin, {"accountId": loader.item.accountIdentifier}) } } } diff --git a/framework/qml/InlineAccountSwitcher.qml b/framework/qml/InlineAccountSwitcher.qml index de79bc09..746891f9 100644 --- a/framework/qml/InlineAccountSwitcher.qml +++ b/framework/qml/InlineAccountSwitcher.qml @@ -24,7 +24,7 @@ FocusScope { id: root property string currentAccount onCurrentAccountChanged: { - Kube.Fabric.postMessage(Kube.Messages.accountSelection, {"account": currentAccount}); + Kube.Fabric.postMessage(Kube.Messages.accountSelection, {accountId: currentAccount}); } ColumnLayout { -- cgit v1.2.3