From: Kevin Ottens Date: Tue, 6 Oct 2020 12:01:53 +0000 (+0200) Subject: If askForOptionalPassword is enabled preset a random password X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~22^2~122^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=e78312f094f8101a6eea649972317b6a0d65f66b;p=nextcloud-desktop.git If askForOptionalPassword is enabled preset a random password This is the same approach used on the server side. Turns out I quite like it, this avoids popping up a dialog to the user and since she won't know the password she'll have to set a new one anyway or disable it. Signed-off-by: Kevin Ottens --- diff --git a/src/gui/sharedialog.cpp b/src/gui/sharedialog.cpp index 709766a80..ca30aa4ff 100644 --- a/src/gui/sharedialog.cpp +++ b/src/gui/sharedialog.cpp @@ -25,6 +25,7 @@ #include "configfile.h" #include "theme.h" #include "thumbnailjob.h" +#include "wordlist.h" #include #include @@ -33,6 +34,20 @@ #include #include +namespace { +QString createRandomPassword() +{ + const auto words = OCC::WordList::getRandomWords(10); + + const auto addFirstLetter = [](const QString ¤t, const QString &next) { + return current + next.at(0); + }; + + return std::accumulate(std::cbegin(words), std::cend(words), QString(), addFirstLetter); +} +} + + namespace OCC { static const int thumbnailSize = 40; @@ -303,7 +318,9 @@ void ShareDialog::showSharingUi() void ShareDialog::slotCreateLinkShare() { if(_manager) { - _manager->createLinkShare(_sharePath, QString(), QString()); + const auto askOptionalPassword = _accountState->account()->capabilities().sharePublicLinkAskOptionalPassword(); + const auto password = askOptionalPassword ? createRandomPassword() : QString(); + _manager->createLinkShare(_sharePath, QString(), password); } }