Ask for password on password protected link shares
authorRoeland Jago Douma <roeland@famdouma.nl>
Thu, 9 Jan 2020 14:10:01 +0000 (15:10 +0100)
committerMichael Schuster <48932272+misch7@users.noreply.github.com>
Thu, 9 Jan 2020 17:20:32 +0000 (18:20 +0100)
Fixes #1485

This was missed when creating the new share dialog.
Now it pops up with a nice share password dialog to enter for your link
share.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
src/gui/sharedialog.cpp
src/gui/sharedialog.h
src/gui/socketapi.cpp

index 544e0e723022de10efac16772b3e28117d4a7b7f..9609a270ca9525e9b90e28c64c10db087022d373 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <QFileInfo>
 #include <QFileIconProvider>
+#include <QInputDialog>
 #include <QPointer>
 #include <QPushButton>
 #include <QFrame>
@@ -137,6 +138,7 @@ ShareDialog::ShareDialog(QPointer<AccountState> accountState,
         _manager = new ShareManager(accountState->account(), this);
         connect(_manager, &ShareManager::sharesFetched, this, &ShareDialog::slotSharesFetched);
         connect(_manager, &ShareManager::linkShareCreated, this, &ShareDialog::slotAddLinkShareWidget);
+        connect(_manager, &ShareManager::linkShareRequiresPassword, this, &ShareDialog::slotLinkShareRequiresPassword);
     }
 }
 
@@ -302,6 +304,24 @@ void ShareDialog::slotCreateLinkShare()
     _manager->createLinkShare(_sharePath, QString(), QString());
 }
 
+void ShareDialog::slotLinkShareRequiresPassword()
+{
+    bool ok;
+    QString password = QInputDialog::getText(this,
+                                             tr("Password for share required"),
+                                             tr("Please enter a password for your link share:"),
+                                             QLineEdit::Normal,
+                                             QString(),
+                                             &ok);
+
+    if (!ok) {
+        // The dialog was canceled so no need to do anything
+        return;
+    }
+
+    // Try to create the link share again with the newly entered password
+    _manager->createLinkShare(_sharePath, QString(), password);
+}
 
 void ShareDialog::slotDeleteShare()
 {
index 17d156437152774c0f0ee4c82843ba99c22480f3..849dc6ec5daaa7897c9a3b98740bf0e7e3f18199 100644 (file)
@@ -64,6 +64,7 @@ private slots:
     void slotAddLinkShareWidget(const QSharedPointer<LinkShare> &linkShare);
     void slotDeleteShare();
     void slotCreateLinkShare();
+    void slotLinkShareRequiresPassword();
     void slotAdjustScrollWidgetSize();
 
 signals:
index b09973d5b35c6f90e18ba0e2a5041ffe5a0fedd3..a7bc604b597cc53d3d0555d56932e4d11e431ef7 100644 (file)
@@ -49,6 +49,7 @@
 #include <QLocalSocket>
 #include <QStringBuilder>
 #include <QMessageBox>
+#include <QInputDialog>
 
 #include <QClipboard>
 
@@ -477,6 +478,8 @@ public:
             this, &GetOrCreatePublicLinkShare::linkShareCreated);
         connect(&_shareManager, &ShareManager::serverError,
             this, &GetOrCreatePublicLinkShare::serverError);
+        connect(&_shareManager, &ShareManager::linkShareRequiresPassword,
+            this, &GetOrCreatePublicLinkShare::passwordRequired);
     }
 
     void run()
@@ -512,6 +515,24 @@ private slots:
         success(share->getLink().toString());
     }
 
+    void passwordRequired() {
+        bool ok;
+        QString password = QInputDialog::getText(nullptr,
+                                                 tr("Password for share required"),
+                                                 tr("Please enter a password for your link share:"),
+                                                 QLineEdit::Normal,
+                                                 QString(),
+                                                 &ok);
+
+        if (!ok) {
+            // The dialog was canceled so no need to do anything
+            return;
+        }
+
+        // Try to create the link share again with the newly entered password
+        _shareManager.createLinkShare(_localFile, QString(), password);
+    }
+
     void serverError(int code, const QString &message)
     {
         qCWarning(lcPublicLink) << "Share fetch/create error" << code << message;