From f4affd9241260833b4cfd2dcbba179aa0420aa00 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Fri, 27 Dec 2024 19:28:31 +0100 Subject: [PATCH] Add automatic login feature I am using .pg_service.conf to define all connection parameters, and .pgpass for the password, thus i never have to input anything to the login form, and want to skip it. However, just in case someday i need to set the connection up differently, i only try to log in automatically on startup, and can go back to the login page by logging out, as usual. --- src/LoginPage.qml | 24 ++++++++++++++++++++++++ src/Main.qml | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/src/LoginPage.qml b/src/LoginPage.qml index 57658ff..4f0d1ae 100644 --- a/src/LoginPage.qml +++ b/src/LoginPage.qml @@ -8,6 +8,7 @@ Page { id: page function saveSettings() { + settings.autoLogIn = autoLogIn.checked; settings.connectOptions = connectOptions.text; settings.databaseName = databaseName.text; settings.hostName = hostName.text; @@ -15,6 +16,12 @@ Page { settings.usePort = usePort.checked; } + function tryAutoLogIn() { + if (autoLogIn.checked) { + loginAction.trigger(); + } + } + title: qsTr("Login") ColumnLayout { @@ -133,6 +140,22 @@ Page { onAccepted: loginAction.trigger() } + + CheckBox { + id: autoLogIn + + Layout.alignment: Qt.AlignRight + Layout.columnSpan: 2 + Mnemonic.label: qsTr("Log in auto&matically") + checked: settings.autoLogIn + text: Mnemonic.richTextLabel + + Shortcut { + sequence: autoLogIn.Mnemonic.sequence + + onActivated: autoLogIn.click() + } + } } } @@ -145,6 +168,7 @@ Page { Settings { id: settings + property bool autoLogIn: false property string connectOptions: "" property string databaseName: "" property string hostName: "" diff --git a/src/Main.qml b/src/Main.qml index e3ea3e5..697932c 100644 --- a/src/Main.qml +++ b/src/Main.qml @@ -9,6 +9,10 @@ ApplicationWindow { visible: true width: 640 + Component.onCompleted: function () { + (pageStack.currentItem as LoginPage)?.tryAutoLogIn(); + } + StackView { id: pageStack