Show edit locally loading dialog sooner, improve feedback for user
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Fri, 28 Oct 2022 18:22:27 +0000 (20:22 +0200)
committerClaudio Cambra <claudio.cambra@gmail.com>
Sat, 29 Oct 2022 11:32:48 +0000 (13:32 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/editlocallyhandler.cpp
src/gui/editlocallyhandler.h
src/gui/tray/EditFileLocallyLoadingDialog.qml

index 64210a7ff21abc47054d0dc398c8c2b87f063309..74396b20ceab5764a3dd275ea37630e0743d3dc4 100644 (file)
@@ -18,7 +18,6 @@
 #include <QDesktopServices>
 #include <QtConcurrent>
 
-#include "accountmanager.h"
 #include "editlocallymanager.h"
 #include "folder.h"
 #include "folderman.h"
@@ -50,6 +49,10 @@ void EditLocallyHandler::startSetup()
         return;
     }
 
+    // Show the loading dialog but don't show the filename until we have
+    // verified the token
+    Systray::instance()->createEditFileLocallyLoadingDialog({});
+
     // We check the input data locally first, without modifying any state or
     // showing any potentially misleading data to the user
     if (!isTokenValid(_token)) {
@@ -110,6 +113,7 @@ void EditLocallyHandler::remoteTokenCheckResultReceived(const int statusCode)
 
     if (!_tokenVerified) {
         showError(tr("Could not validate the request to open a file from server."), tr("Please try again."));
+        return;
     }
 
     proceedWithSetup();
@@ -149,17 +153,13 @@ void EditLocallyHandler::proceedWithSetup()
 
     _fileName = relPathSplit.last();
 
+    Systray::instance()->destroyEditFileLocallyLoadingDialog();
     Q_EMIT setupFinished();
 }
 
 QString EditLocallyHandler::prefixSlashToPath(const QString &path)
 {
-    auto slashPrefixedPath = path;
-    if (!slashPrefixedPath.startsWith('/')) {
-        slashPrefixedPath.prepend('/');
-    }
-
-    return slashPrefixedPath;
+    return path.startsWith('/') ? path : QChar::fromLatin1('/') + path;
 }
 
 bool EditLocallyHandler::isTokenValid(const QString &token)
@@ -173,12 +173,7 @@ bool EditLocallyHandler::isTokenValid(const QString &token)
     const QRegularExpression tokenRegex("^[a-zA-Z0-9]{128}$");
     const auto regexMatch = tokenRegex.match(token);
 
-    // Means invalid token type received, be cautious with bad token
-    if(!regexMatch.hasMatch()) {
-        return false;
-    }
-
-    return true;
+    return regexMatch.hasMatch();
 }
 
 bool EditLocallyHandler::isRelPathValid(const QString &relPath)
@@ -207,7 +202,7 @@ bool EditLocallyHandler::isRelPathValid(const QString &relPath)
 bool EditLocallyHandler::isRelPathExcluded(const QString &relPath)
 {
     if (relPath.isEmpty()) {
-        return true;
+        return false;
     }
 
     const auto folderMap = FolderMan::instance()->map();
@@ -216,16 +211,17 @@ bool EditLocallyHandler::isRelPathExcluded(const QString &relPath)
         const auto excludedThroughSelectiveSync = folder->journalDb()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, &result);
         for (const auto &excludedPath : excludedThroughSelectiveSync) {
             if (relPath.startsWith(excludedPath)) {
-                return false;
+                return true;
             }
         }
     }
 
-    return true;
+    return false;
 }
 
 void EditLocallyHandler::showError(const QString &message, const QString &informativeText)
 {
+    Systray::instance()->destroyEditFileLocallyLoadingDialog();
     showErrorNotification(message, informativeText);
     // to make sure the error is not missed, show a message box in addition
     showErrorMessageBox(message, informativeText);
index f7b27b71a2fffb97a5a1bffde367c1d0a28eb6e2..05b3076e7b9c18c6f0173a102975e9820202233d 100644 (file)
@@ -49,9 +49,9 @@ signals:
 public slots:
     void startSetup();
     void startEditLocally();
-    void startTokenRemoteCheck();
 
 private slots:
+    void startTokenRemoteCheck();
     void proceedWithSetup();
 
     void showError(const QString &message, const QString &informativeText);
index f7fbe965b3a4932303e599134fc6e4ca3eca56eb..12e8f757b4bb514f28b5b1ed76c3413818bc10c6 100644 (file)
@@ -65,13 +65,14 @@ Window {
             font.pixelSize: root.fontPixelSize
             color: Style.ncTextColor
             horizontalAlignment: Text.AlignHCenter
+            visible: root.fileName !== ""
         }
         Label {
             id: labelMessage
             Layout.alignment: Qt.AlignHCenter
             Layout.fillWidth: true
             Layout.bottomMargin: Style.standardSpacing
-            text: qsTr("Opening for local editing")
+            text: qsTr("Opening file for local editing")
             elide: Text.ElideRight
             font.pixelSize: root.fontPixelSize
             color: Style.ncTextColor