Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHannah von Reth <hannah.vonreth@owncloud.com>2021-05-21 13:24:42 +0300
committerHannah von Reth <vonreth@kde.org>2021-05-26 18:11:27 +0300
commitf37bf34ed261337298291bfeb3493678f7a6326c (patch)
tree6961d816f6d6d45ef2c40ef3404adf243ffcbd39 /src
parentd13a07cecb604018213e84926998d9499f5bd948 (diff)
Ensure we only get one url update dialog.
Fixes: #8645
Diffstat (limited to 'src')
-rw-r--r--src/gui/accountmanager.h4
-rw-r--r--src/gui/accountstate.cpp48
-rw-r--r--src/gui/accountstate.h5
-rw-r--r--src/gui/owncloudsetupwizard.cpp4
4 files changed, 37 insertions, 24 deletions
diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h
index 41232127e..1676ab2df 100644
--- a/src/gui/accountmanager.h
+++ b/src/gui/accountmanager.h
@@ -69,6 +69,10 @@ public:
* Return the account state pointer for an account identified by its display name
*/
AccountStatePtr account(const QUuid uuid);
+ AccountStatePtr account(const AccountPtr &acc)
+ {
+ return account(acc->uuid());
+ }
/**
* Delete the AccountState
diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp
index 46b89d810..6f782bec4 100644
--- a/src/gui/accountstate.cpp
+++ b/src/gui/accountstate.cpp
@@ -32,41 +32,44 @@ namespace OCC {
Q_LOGGING_CATEGORY(lcAccountState, "gui.account.state", QtInfoMsg)
-void AccountState::updateUrlDialog(AccountPtr account, const QUrl &newUrl, std::function<void()> callback)
+void AccountState::updateUrlDialog(const QUrl &newUrl)
{
- auto accept = [=](bool accepted) {
- if (accepted) {
- account->setUrl(newUrl);
- Q_EMIT account->wantsAccountSaved(account.data());
- }
- if (callback) {
- callback();
- }
+ // guard to prevent multiple dialogs
+ if (_updateUrlDialog) {
+ return;
+ }
+ auto accept = [=] {
+ _account->setUrl(newUrl);
+ Q_EMIT _account->wantsAccountSaved(_account.data());
+ Q_EMIT urlUpdated();
};
+
// the urls are identical, previous versions of owncloud cropped the /
auto newPath = newUrl.path();
if (newPath.endsWith(QLatin1Char('/'))) {
newPath.truncate(1);
}
- if (newPath == account->url().path()) {
+ if (newPath == _account->url().path()) {
auto tmp = newUrl;
tmp.setPath(QString());
- if (tmp == account->url()) {
+ if (tmp == _account->url()) {
// silently accept the /
- accept(true);
+ accept();
return;
}
}
- auto diag = new QMessageBox(QMessageBox::Warning, tr("Url update requested for %1").arg(account->displayName()),
- tr("The url for %1 changed from %2 to %3, do you want to accept the changed url?").arg(account->displayName(), account->url().toString(), newUrl.toString()),
+ _updateUrlDialog = new QMessageBox(QMessageBox::Warning, tr("Url update requested for %1").arg(_account->displayName()),
+ tr("The url for %1 changed from %2 to %3, do you want to accept the changed url?").arg(_account->displayName(), _account->url().toString(), newUrl.toString()),
QMessageBox::NoButton, ocApp()->gui()->settingsDialog());
- diag->setAttribute(Qt::WA_DeleteOnClose);
- auto yes = diag->addButton(tr("Change url permanently to %1").arg(newUrl.toString()), QMessageBox::AcceptRole);
- diag->addButton(tr("Reject"), QMessageBox::RejectRole);
- QObject::connect(diag, &QMessageBox::finished, account.data(), [diag, yes, accept] {
- accept(diag->clickedButton() == yes);
+ _updateUrlDialog->setAttribute(Qt::WA_DeleteOnClose);
+ auto yes = _updateUrlDialog->addButton(tr("Change url permanently to %1").arg(newUrl.toString()), QMessageBox::AcceptRole);
+ _updateUrlDialog->addButton(tr("Reject"), QMessageBox::RejectRole);
+ connect(_updateUrlDialog, &QMessageBox::finished, _account.data(), [yes, accept, this] {
+ if (_updateUrlDialog->clickedButton() == yes) {
+ accept();
+ }
});
- diag->show();
+ _updateUrlDialog->show();
}
AccountState::AccountState(AccountPtr account)
@@ -90,8 +93,9 @@ AccountState::AccountState(AccountPtr account)
this, [this] {
checkConnectivity(true);
});
- connect(account.data(), &Account::requestUrlUpdate, this, [this](const QUrl &newUrl) {
- updateUrlDialog(_account, newUrl, [this] { checkConnectivity(); });
+ connect(account.data(), &Account::requestUrlUpdate, this, &AccountState::updateUrlDialog);
+ connect(this, &AccountState::urlUpdated, this, [this] {
+ checkConnectivity(false);
});
}
diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h
index 82d678d89..86a69d79b 100644
--- a/src/gui/accountstate.h
+++ b/src/gui/accountstate.h
@@ -26,6 +26,7 @@
#include <memory>
class QSettings;
+class QMessageBox;
namespace OCC {
@@ -44,7 +45,6 @@ class AccountState : public QObject, public QSharedData
Q_PROPERTY(AccountPtr account MEMBER _account)
public:
- static void updateUrlDialog(AccountPtr account, const QUrl &url, std::function<void()> callback = {});
enum State {
/// Not even attempting to connect, most likely because the
/// user explicitly signed out or cancelled a credential dialog.
@@ -134,6 +134,7 @@ public:
* was not so long ago.
*/
void tagLastSuccessfullETagRequest(const QDateTime &tp);
+ void updateUrlDialog(const QUrl &url);
public slots:
/// Triggers a ping to the server to update state and
@@ -147,6 +148,7 @@ private:
signals:
void stateChanged(State state);
void isConnectedChanged();
+ void urlUpdated();
protected Q_SLOTS:
void slotConnectionValidatorResult(ConnectionValidator::Status status, const QStringList &errors);
@@ -163,6 +165,7 @@ private:
bool _waitingForNewCredentials;
QDateTime _timeOfLastETagCheck;
QPointer<ConnectionValidator> _connectionValidator;
+ QPointer<QMessageBox> _updateUrlDialog;
/**
* Starts counting when the server starts being back up after 503 or
diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp
index a6ac9bd7e..3e4b3290b 100644
--- a/src/gui/owncloudsetupwizard.cpp
+++ b/src/gui/owncloudsetupwizard.cpp
@@ -194,7 +194,9 @@ void OwncloudSetupWizard::slotFoundServer(const QUrl &url, const QJsonObject &in
if (url.scheme() == QLatin1String("https") && oldUrl.host() == url.host()) {
_ocWizard->account()->setUrl(url);
} else {
- AccountState::updateUrlDialog(_ocWizard->account(), url, [this] { slotDetermineAuthType(); });
+ auto accountState = AccountManager::instance()->account(_ocWizard->account());
+ connect(accountState.data(), &AccountState::urlUpdated, this, &OwncloudSetupWizard::slotDetermineAuthType);
+ accountState->updateUrlDialog(url);
return;
}
}