From 4cff5519ed286aba48420da8b278df1f67c997cf Mon Sep 17 00:00:00 2001 From: Johan Ouwerkerk Date: Wed, 25 Sep 2019 11:17:48 +0200 Subject: [PATCH] Automatically show the "add OTP" form when there are no OTP tokens yet on start up. This is a small UX improvement to make it a little easier to get started with the app. --- src/contents/ui/main.qml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml index ced29e0..1aa904e 100644 --- a/src/contents/ui/main.qml +++ b/src/contents/ui/main.qml @@ -30,7 +30,7 @@ Kirigami.ApplicationWindow { title: "OTP Client" - pageStack.initialPage: mainPageComponent + pageStack.initialPage: accounts.rowCount() > 0 ? mainPageComponent : addPageComponent AccountModel { id: accounts @@ -143,11 +143,26 @@ Kirigami.ApplicationWindow { newAccount.counter = parseInt(counterField.text) newAccount.timeStep = parseInt(timerField.text) newAccount.pinLength = parseInt(pinLengthField.text) + pageStack.pop(); + /* + * Check if the pageStack is now 'empty', which will be the case if + * the starting page was this addPageComponent. + * + * According to Qt docs the StackView 'empty' property is supposed to exist + * and be a bool but in practice it does not appear to work (it is undefined). + * Therefore check the StackView.depth instead. + */ + if (pageStack.depth < 1) { + pageStack.push(mainPageComponent); + } } } Kirigami.FormLayout { id: layout + anchors { + horizontalCenter: parent.horizontalCenter + } Controls.TextField { id: accountName Kirigami.FormData.label: "Account Name:"