Show password set errors in the popup where passwords are set rather than in the...
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 15 Sep 2022 17:55:25 +0000 (19:55 +0200)
committerClaudio Cambra <claudio.cambra@nextcloud.com>
Mon, 31 Oct 2022 17:06:07 +0000 (18:06 +0100)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/filedetails/ShareDelegate.qml
src/gui/filedetails/ShareView.qml
src/gui/filedetails/sharemodel.cpp
src/gui/filedetails/sharemodel.h

index 617e9af880d59367d26c56d9548bc102ad82899d..a7632f712ce9cdfd8a2c7220cf1109d1326250b8 100644 (file)
@@ -21,6 +21,7 @@ import QtGraphicalEffects 1.15
 import com.nextcloud.desktopclient 1.0
 import Style 1.0
 import "../tray"
+import "../"
 
 GridLayout {
     id: root
@@ -87,6 +88,11 @@ GridLayout {
     property bool waitingForPasswordChange: false
     property bool waitingForNoteChange: false
 
+    function showPasswordSetError(message) {
+        passwordErrorBoxLoader.message = message !== "" ?
+                                         message : qsTr("An error occurred setting the share password.");
+    }
+
     function resetNoteField() {
         noteTextEdit.text = note;
         waitingForNoteChange = false;
@@ -468,6 +474,7 @@ GridLayout {
                                  !root.waitingForPasswordProtectEnabledChange
 
                         onAccepted: if(text !== root.password && text !== root.passwordPlaceholder) {
+                            passwordErrorBoxLoader.message = "";
                             root.setPassword(text);
                             root.waitingForPasswordChange = true;
                         }
@@ -482,6 +489,36 @@ GridLayout {
                     }
                 }
 
+                Loader {
+                    id: passwordErrorBoxLoader
+
+                    property string message: ""
+
+                    anchors.left: parent.left
+                    anchors.right: parent.right
+                    height: message !== "" ? implicitHeight : 0
+
+                    active: message !== ""
+                    visible: active
+
+                    sourceComponent: Item {
+                        anchors.top: parent.top
+                        anchors.left: parent.left
+                        anchors.right: parent.right
+                        // Artificially add vertical padding
+                        implicitHeight: passwordErrorBox.implicitHeight + (Style.smallSpacing * 2)
+
+                        ErrorBox {
+                            id: passwordErrorBox
+                            anchors.left: parent.left
+                            anchors.right: parent.right
+                            anchors.verticalCenter: parent.verticalCenter
+
+                            text: passwordErrorBoxLoader.message
+                        }
+                    }
+                }
+
                 CheckBox {
                     id: expireDateEnabledMenuItem
 
index eb8da6f9e6f7b5c3bae9606fed18fe11f0a07566..43ada6d7233d3a64d7dfa9de229e53981bd2ab98 100644 (file)
@@ -202,11 +202,12 @@ ColumnLayout {
                         // password set has failed, meaning we won't be able to easily tell when we
                         // have had a response from the server in QML. So we listen to this signal
                         // directly from the model and do the reset of the password field manually.
-                        function onPasswordSetError(shareId) {
+                        function onPasswordSetError(shareId, errorCode, errorMessage) {
                             if(shareId !== model.shareId) {
                                 return;
                             }
                             shareDelegate.resetPasswordField();
+                            shareDelegate.showPasswordSetError(errorMessage);
                         }
 
                         function onServerError() {
index 3191ff22c8a0e33e977c0763e1191ff5bc51046f..07294fc9356733ac90964d08e58cde6b2bef6fcb 100644 (file)
@@ -388,9 +388,8 @@ void ShareModel::slotAddShare(const SharePtr &share)
     connect(share.data(), &Share::serverError, this, &ShareModel::slotServerError);
     connect(share.data(), &Share::passwordSetError, this, [this, shareId](const int code, const QString &message) {
         _shareIdRecentlySetPasswords.remove(shareId);
-        slotServerError(code, message);
         slotSharePasswordSet(shareId);
-        Q_EMIT passwordSetError(shareId);
+        Q_EMIT passwordSetError(shareId, code, message);
     });
 
     // Passing shareId by reference here will cause crashing, so we pass by value
index aa498974495132a0455f4a0ca6f6302109e339e2..4328aeff1d10bcd423b90b88f03e33e8d8ec71a0 100644 (file)
@@ -107,7 +107,7 @@ signals:
     void hasInitialShareFetchCompletedChanged();
 
     void serverError(const int code, const QString &message);
-    void passwordSetError(const QString &shareId);
+    void passwordSetError(const QString &shareId, const int code, const QString &message);
     void requestPasswordForLinkShare();
     void requestPasswordForEmailSharee(const ShareePtr &sharee);