Some improvements in the LoginPage

This commit is contained in:
Scharel Clemens 2020-01-29 18:36:34 +01:00
parent 369cf2c1e9
commit 601985436d
5 changed files with 196 additions and 45 deletions

View file

@ -1,6 +1,7 @@
import QtQuick 2.2
import Sailfish.Silica 1.0
import Nemo.Configuration 1.0
import harbour.nextcloudnotes.notesapi 1.0
Page {
id: loginPage
@ -29,10 +30,51 @@ Page {
Connections {
target: notesApi
onStatusStatusChanged: {
switch(notesApi.statusStatus) {
case NotesApi.StatusNone:
console.log("Status: none")
break;
case NotesApi.StatusInitiated:
console.log("Status: initiated")
break;
case NotesApi.StatusBusy:
console.log("Status: busy")
apiProgressBar.label = qsTr("Verifying server address")
break;
case NotesApi.StatusFinished:
console.log("Status: finished")
apiProgressBar.label = qsTr("Server address is valid")
break
case NotesApi.StatusError:
console.log("Status: error")
apiProgressBar.label = qsTr("Please enter a valid server address")
break;
}
console.log(notesApi.statusStatus)
}
onLoginStatusChanged: {
console.log(notesApi.loginStatus)
switch(notesApi.statusStatus) {
case NotesApi.StatusNone:
console.log("Login: none")
break;
case NotesApi.StatusInitiated:
console.log("Login: initiated")
apiProgressBar.label = qsTr("Initiating login")
break;
case NotesApi.StatusBusy:
console.log("Login: busy")
apiProgressBar.label = qsTr("Follow the login procedure in the browser")
break;
case NotesApi.StatusFinished:
console.log("Login: finished")
apiProgressBar.label = qsTr("Login successfull")
break
case NotesApi.StatusError:
console.log("Login: error")
apiProgressBar.label = qsTr("Error while loggin in")
break;
}
}
onStatusInstalledChanged: {
if (notesApi.statusInstalled) {
@ -43,11 +85,9 @@ Page {
}
onLoginUrlChanged: {
if (notesApi.loginUrl) {
loginStatus = "flowV2Pending"
Qt.openUrlExternally(notesApi.loginUrl)
}
else {
loginStatus = "flowV2LoggedIn"
console.log("Login successfull")
}
}
@ -79,9 +119,13 @@ Page {
}
ProgressBar {
id: apiProgressBar
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width
indeterminate: notesApi.statusBusy
indeterminate: notesApi.statusStatus === NotesApi.StatusInitiated ||
notesApi.statusStatus === NotesApi.StatusBusy ||
notesApi.loginStatus === NotesApi.StatusInitiated ||
notesApi.loginStatus === NotesApi.StatusBusy
}
Row {
@ -113,17 +157,28 @@ Page {
id: flowv2LoginColumn
width: parent.width
spacing: Theme.paddingLarge
visible: notesApi.statusVersion.split('.')[0] >= 16
visible: opacity !== 0.0
opacity: notesApi.statusStatus === NotesApi.StatusFinished && notesApi.statusVersion.split('.')[0] >= 16 ? 1.0 : 0.0
Behavior on opacity { FadeAnimator {} }
Label {
text: "Flow Login v2"
x: Theme.horizontalPageMargin
}
Button {
id: loginButton
anchors.horizontalCenter: parent.horizontalCenter
property bool pushed: false
text: notesApi.loginBusy ? qsTr("Abort") : qsTr("Login")
onClicked: notesApi.loginBusy ? notesApi.abortFlowV2Login() : notesApi.initiateFlowV2Login()
}
}
Column {
id: legacyLoginColumn
width: parent.width
visible: notesApi.statusVersion.split('.')[0] < 16
visible: opacity !== 0.0
opacity: notesApi.statusStatus === NotesApi.StatusFinished && notesApi.statusVersion.split('.')[0] < 16 ? 1.0 : 0.0
Behavior on opacity { FadeAnimator {} }
Label {
text: "Legacy Login"
x: Theme.horizontalPageMargin
@ -140,7 +195,6 @@ Page {
EnterKey.iconSource: "image://theme/icon-m-enter-next"
EnterKey.onClicked: passwordField.focus = true
}
PasswordField {
id: passwordField
width: parent.width
@ -154,14 +208,6 @@ Page {
}
}
Button {
id: loginButton
anchors.horizontalCenter: parent.horizontalCenter
property bool pushed: false
text: notesApi.loginBusy ? qsTr("Abort") : qsTr("Login")
onClicked: notesApi.loginBusy ? notesApi.abortFlowV2Login() : notesApi.initiateFlowV2Login()
}
/*
TextField {
id: nameField

View file

@ -84,6 +84,7 @@ QString NotesApi::server() const {
void NotesApi::setServer(QString serverUrl) {
QUrl url(serverUrl);
qDebug() << serverUrl << server();
if (serverUrl != server()) {
setScheme(url.scheme());
setHost(url.host());
@ -160,13 +161,13 @@ bool NotesApi::getStatus() {
if (m_statusStatus != RequestStatus::StatusBusy) {
m_statusStatus = RequestStatus::StatusBusy;
emit statusStatusChanged(m_statusStatus);
QUrl url = apiEndpointUrl(m_statusEndpoint);
if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
qDebug() << "POST" << url.toDisplayString();
m_request.setUrl(url);
m_statusReply = m_manager.post(m_request, QByteArray());
return true;
}
}
QUrl url = apiEndpointUrl(m_statusEndpoint);
if (url.isValid() && !url.scheme().isEmpty() && !url.host().isEmpty()) {
qDebug() << "POST" << url.toDisplayString();
m_request.setUrl(url);
m_statusReply = m_manager.post(m_request, QByteArray());
return true;
}
return false;
}
@ -360,12 +361,22 @@ void NotesApi::replyFinished(QNetworkReply *reply) {
qDebug() << "Polling not finished yet" << reply->url().toDisplayString();
}
else {
if (reply == m_loginReply)
if (reply == m_loginReply) {
m_loginReply = NULL;
else if (reply == m_pollReply)
m_loginStatus = RequestStatus::StatusError;
emit loginStatusChanged(m_loginStatus);
}
else if (reply == m_pollReply) {
m_pollReply = NULL;
else if (reply == m_statusReply)
m_loginStatus = RequestStatus::StatusError;
emit loginStatusChanged(m_loginStatus);
}
else if (reply == m_statusReply) {
m_statusReply = NULL;
updateStatus(QJsonObject());
//m_statusStatus = RequestStatus::StatusError;
//emit statusStatusChanged(m_statusStatus);
}
else if (m_notesReplies.contains(reply)) {
m_notesReplies.removeOne(reply);
emit busyChanged(busy());
@ -434,7 +445,10 @@ void NotesApi::updateStatus(const QJsonObject &status) {
m_status_extendedSupport = status.value("extendedSupport").toBool();
emit statusExtendedSupportChanged(m_status_extendedSupport);
}
m_statusStatus = RequestStatus::StatusFinished;
if (status.isEmpty())
m_statusStatus = RequestStatus::StatusError;
else
m_statusStatus = RequestStatus::StatusFinished;
emit statusStatusChanged(m_statusStatus);
}

View file

@ -158,6 +158,34 @@
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Verifying server address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Server address is valid</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Initiating login</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Follow the login procedure in the browser</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Login successfull</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Error while loggin in</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please enter a valid server address</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MITLicense</name>

View file

@ -158,6 +158,34 @@
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Verifying server address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Server address is valid</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Initiating login</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Follow the login procedure in the browser</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Login successfull</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Error while loggin in</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Please enter a valid server address</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>MITLicense</name>

View file

@ -133,57 +133,92 @@
<context>
<name>LoginPage</name>
<message>
<location filename="../qml/pages/LoginPage.qml" line="59"/>
<location filename="../qml/pages/LoginPage.qml" line="42"/>
<source>Verifying server address</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="46"/>
<source>Server address is valid</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="63"/>
<source>Initiating login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="67"/>
<source>Follow the login procedure in the browser</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="71"/>
<source>Login successfull</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="75"/>
<source>Error while loggin in</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="110"/>
<source>Nextcloud Login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="81"/>
<location filename="../qml/pages/LoginPage.qml" line="136"/>
<source>Nextcloud server</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="124"/>
<location filename="../qml/pages/LoginPage.qml" line="190"/>
<source>Username</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="137"/>
<location filename="../qml/pages/LoginPage.qml" line="202"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="150"/>
<location filename="../qml/pages/LoginPage.qml" line="171"/>
<source>Abort</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="150"/>
<location filename="../qml/pages/LoginPage.qml" line="50"/>
<source>Please enter a valid server address</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="171"/>
<source>Login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="189"/>
<location filename="../qml/pages/LoginPage.qml" line="246"/>
<source>Security</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="196"/>
<location filename="../qml/pages/LoginPage.qml" line="253"/>
<source>&lt;strong&gt;CAUTION: Your password will be saved without any encryption on the device!&lt;/strong&gt;&lt;br&gt;Please consider creating a dedicated app password! Open your Nextcloud in a browser and go to &lt;i&gt;Settings&lt;/i&gt; &lt;i&gt;Security&lt;/i&gt;.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="200"/>
<location filename="../qml/pages/LoginPage.qml" line="257"/>
<source>Do not check certificates</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="201"/>
<location filename="../qml/pages/LoginPage.qml" line="258"/>
<source>Enable this option to allow selfsigned certificates</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../qml/pages/LoginPage.qml" line="207"/>
<location filename="../qml/pages/LoginPage.qml" line="264"/>
<source>Allow unencrypted connections</source>
<translation type="unfinished"></translation>
</message>
@ -270,37 +305,37 @@
<context>
<name>NotesApi</name>
<message>
<location filename="../src/notesapi.cpp" line="483"/>
<location filename="../src/notesapi.cpp" line="521"/>
<source>No network connection available</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="486"/>
<location filename="../src/notesapi.cpp" line="524"/>
<source>Failed to communicate with the Nextcloud server</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="489"/>
<location filename="../src/notesapi.cpp" line="527"/>
<source>An error happened while reading from the local storage</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="492"/>
<location filename="../src/notesapi.cpp" line="530"/>
<source>An error happened while writing to the local storage</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="495"/>
<location filename="../src/notesapi.cpp" line="533"/>
<source>An error occured while establishing an encrypted connection</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="498"/>
<location filename="../src/notesapi.cpp" line="536"/>
<source>Could not authenticate to the Nextcloud instance</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/notesapi.cpp" line="501"/>
<location filename="../src/notesapi.cpp" line="539"/>
<source>Unknown error</source>
<translation type="unfinished"></translation>
</message>