From 70e91f7164919798bae3ce99fd22928427cfdf0c Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Tue, 4 Apr 2017 02:15:22 +0200 Subject: [PATCH] Improved login usability Locations automatically fast forward to login skipping location selection if just one location is available RsLoginPassView nicer look --- retroshare-qml-app/src/qml.qrc | 1 + retroshare-qml-app/src/qml/Locations.qml | 134 ++++++++++-------- .../src/qml/RsLoginPassView.qml | 64 +++++++-- .../src/qml/icons/emblem-locked.png | Bin 0 -> 2204 bytes 4 files changed, 121 insertions(+), 78 deletions(-) create mode 100644 retroshare-qml-app/src/qml/icons/emblem-locked.png diff --git a/retroshare-qml-app/src/qml.qrc b/retroshare-qml-app/src/qml.qrc index 861577e60..9ba2e57f3 100644 --- a/retroshare-qml-app/src/qml.qrc +++ b/retroshare-qml-app/src/qml.qrc @@ -19,5 +19,6 @@ qml/icons/document-share.png qml/icons/application-menu.png qml/ContactSort.js + qml/icons/emblem-locked.png diff --git a/retroshare-qml-app/src/qml/Locations.qml b/retroshare-qml-app/src/qml/Locations.qml index 57f889a59..1d7b56830 100644 --- a/retroshare-qml-app/src/qml/Locations.qml +++ b/retroshare-qml-app/src/qml/Locations.qml @@ -50,8 +50,10 @@ Item buttonText: "Save" onSubmit: { - var jsonData = { pgp_name: login, ssl_name: login, pgp_password: password } - rsApi.request("/control/create_location/", JSON.stringify(jsonData)) + var jsonData = { pgp_name: login, ssl_name: login, + pgp_password: password } + rsApi.request("/control/create_location/", + JSON.stringify(jsonData)) locationView.state = "selectLocation" } } @@ -72,76 +74,40 @@ Item rsApi.request( "/control/login/", JSON.stringify({id: locationView.sslid}) ) locationView.attemptLogin = true - busyIndicator.running = true attemptTimer.start() } } } ] - function requestLocationsList() { rsApi.request("/control/locations/", "") } - - onFocusChanged: focus && requestLocationsList() - - LibresapiLocalClient + function requestLocationsListCB(par) { - id: rsApi - Component.onCompleted: + var jsonData = JSON.parse(par.response).data + if(jsonData.length === 1) { - openConnection(apiSocketPath) - locationView.requestLocationsList() + // There is only one location so we can jump selecting location + var location = jsonData[0] + loginView.login = location.name + locationView.sslid = location.peer_id + locationView.state = "login" } - onGoodResponseReceived: + else { - var jsonData = JSON.parse(msg) - - - if(jsonData) - { - if(jsonData.data) - { - if(jsonData.data[0] && jsonData.data[0].pgp_id) - { - // if location list update - locationsModel.json = msg - busyIndicator.running = false - } - if (jsonData.data.key_name) - { - if(jsonData.data.want_password) - { - // if Server requested password - var jsonPass = { password: locationView.password } - rsApi.request( "/control/password/", - JSON.stringify(jsonPass) ) - locationView.attemptLogin = false - console.debug("RS core asked for password") - } - else - { - // if Already logged in - bottomButton.enabled = false - bottomButton.text = "Already logged in" - locationView.attemptLogin = false - busyIndicator.running = false - locationView.state = "selectLocation" - locationsListView.enabled = false - console.debug("Already logged in") - } - } - } - } + // There is more then one location to choose from + locationsModel.json = par.response } } + function requestLocationsList() + { rsApi.request("/control/locations/", "", requestLocationsListCB) } - BusyIndicator { id: busyIndicator; anchors.centerIn: parent } + onFocusChanged: focus && requestLocationsList() + Component.onCompleted: requestLocationsList() JSONListModel { id: locationsModel query: "$.data[*]" } - ListView { id: locationsListView @@ -151,22 +117,23 @@ Item model: locationsModel.model delegate: Button { - text: model.name + text: model.name onClicked: { loginView.login = text locationView.sslid = model.id locationView.state = "login" } - } - visible: false + } + visible: false } - Button - { + Button + { id: bottomButton text: "Create new location" anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter onClicked: locationView.state = "createLocation" } @@ -177,19 +144,60 @@ Item anchors.fill: parent } + BusyIndicator + { + id: busyIndicator + anchors.centerIn: parent + running: false + + Connections + { + target: locationView + onAttemptLoginChanged: + if(locationView.attemptLogin) busyIndicator.running = true + } + } + + LibresapiLocalClient + { + id: loginApi + Component.onCompleted: openConnection(apiSocketPath) + onGoodResponseReceived: + { + var jsonData = JSON.parse(msg) + if(jsonData && jsonData.data && jsonData.data.key_name) + { + if(jsonData.data.want_password) + { + // if Server requested password + var jsonPass = { password: locationView.password } + request( "/control/password/", JSON.stringify(jsonPass) ) + locationView.attemptLogin = false + console.debug("RS core asked for password") + } + else + { + // if Already logged in + bottomButton.enabled = false + bottomButton.text = "Unlocking location..." + locationView.attemptLogin = false + locationView.state = "selectLocation" + locationsListView.enabled = false + console.debug("Already logged in") + } + } + } + } Timer { id: attemptTimer - interval: 500 + interval: 1000 repeat: true triggeredOnStart: true onTriggered: { - if(locationView.focus) - locationView.requestLocationsList() - if (locationView.attemptLogin) - rsApi.request("/control/password/", "") + loginApi.request("/control/password/", "") } } } diff --git a/retroshare-qml-app/src/qml/RsLoginPassView.qml b/retroshare-qml-app/src/qml/RsLoginPassView.qml index 8a80b8996..7b2fd3316 100644 --- a/retroshare-qml-app/src/qml/RsLoginPassView.qml +++ b/retroshare-qml-app/src/qml/RsLoginPassView.qml @@ -19,13 +19,12 @@ import QtQuick 2.0 import QtQuick.Layouts 1.3 import QtQuick.Controls 2.0 -import QtQml 2.2 -import org.retroshare.qml_components.LibresapiLocalClient 1.0 +//import QtQml 2.2 Item { id: loginView - property string buttonText: "Login" + property string buttonText: "Unlock" property string login property string password signal submit(string login, string password) @@ -34,19 +33,54 @@ Item { id: inputView width: parent.width - anchors.top: parent.top - anchors.bottom: bottomButton.top + anchors.centerIn: parent - Row { Text {text: "Name:" } TextField { id: nameField; text: loginView.login } } - Row { Text {text: "Password:" } TextField { id: passwordField; text: loginView.password } } - } + Image + { + source: "qrc:/qml/icons/emblem-locked.png" + Layout.alignment: Qt.AlignHCenter + } - Button - { - id: bottomButton - text: loginView.buttonText - anchors.bottom: parent.bottom - anchors.right: parent.right - onClicked: loginView.submit(nameField.text, passwordField.text) + Text + { + text: "Login" + visible: loginView.login.length === 0 + Layout.alignment: Qt.AlignHCenter + anchors.bottom: nameField.top + anchors.bottomMargin: 5 + } + TextField + { + id: nameField; + text: loginView.login + visible: loginView.login.length === 0 + Layout.alignment: Qt.AlignHCenter + } + + Text + { + id: passLabel + text: nameField.visible ? + "Passphrase" : "Enter passphrase for " + loginView.login + Layout.alignment: Qt.AlignHCenter + anchors.bottom: passwordField.top + anchors.bottomMargin: 5 + } + TextField + { + id: passwordField + text: loginView.password + width: passLabel.width + echoMode: TextInput.Password + Layout.alignment: Qt.AlignHCenter + } + + Button + { + id: bottomButton + text: loginView.buttonText + onClicked: loginView.submit(nameField.text, passwordField.text) + Layout.alignment: Qt.AlignHCenter | Qt.AlignBottom + } } } diff --git a/retroshare-qml-app/src/qml/icons/emblem-locked.png b/retroshare-qml-app/src/qml/icons/emblem-locked.png new file mode 100644 index 0000000000000000000000000000000000000000..fb1ec9eb6774562cb15248b81b4008f56c08b37a GIT binary patch literal 2204 zcmd5;_fwMz6MjPvMWjX$0wM~WbVXVMp;ze$(mN^;N(i9^LX|2dbfriWK{<&629X31 zqrjn{2psi<5KelL(3FdR!1w#NGrQ03&NDl+GdsJRX=7!=!zs!M0057fsi7SMale&= zjbZzByoVUTg3>p0;9y8RhhGLG28Ws6LIJ=m`nQ6f-s?|cBt;^PoFnZ+10pfr5&i%M zgHgPL3_|&OhxsdpMg%_CfQbSChlrV>oJy^YkARvvX^qI;dUZ)cnZsEci`i6l)5~ ze}gw|iU|X%OS*vQ>hx`DmIcw07NyoGgp00z4}$C4)vZgagk=>2q!56OIy6S=>XJrTwlc7w{=+EAD*@$ywU-L3=xg=6Id;u z-Gw<`IhJ17C0_o8rb2Waa2+zQT;->6wrZJ;cd7M4%WBtN(015$ZEzO4^|2?b?fi}cd8tmE@Qn3L9)hMJ_G;p^y5f@AZyCau;Q=whLIj^kztB45#2 zuga$z`7J$CMKDUs%V0_P-2Nwc5O^ML8hy~|u#da|+wP1`xlGQr$E``)eTH5bKTuZn ziFdr|J^xdNI;-2zy-Km^b}mMLaUm(;zVKdBTRhKl6}k?4Ie}AnShq9CHmF_QD?Bpp zS2;eG$R(*CMu(VvJXRc2o-t#2plfkRZ;>St_<~oY4IF+F0M)fKs$AE7jS~mafg-;gXQ^odD4Dxl ziG)!0FIbg+BWxLyG5ig3WCSjB2l!NX)%j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