diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2020-11-27 17:16:09 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2020-12-09 13:52:03 +0300 |
commit | 33dd42b63f2b6464f1d0619bd587e7937cfce208 (patch) | |
tree | e7fc1f8e3042cc82bd62bb7534a3ec63e43256bd /src/gui/accountstate.cpp | |
parent | 4261e0623c1f05f780dbe78d5f8acd5201527537 (diff) |
Implement url update on redirect
Diffstat (limited to 'src/gui/accountstate.cpp')
-rw-r--r-- | src/gui/accountstate.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp index 80728513c..ef3286704 100644 --- a/src/gui/accountstate.cpp +++ b/src/gui/accountstate.cpp @@ -12,6 +12,7 @@ * for more details. */ +#include "application.h" #include "accountstate.h" #include "accountmanager.h" #include "account.h" @@ -19,7 +20,9 @@ #include "creds/httpcredentials.h" #include "logger.h" #include "configfile.h" +#include "settingsdialog.h" +#include <QMessageBox> #include <QSettings> #include <QTimer> #include <qfontmetrics.h> @@ -28,6 +31,26 @@ namespace OCC { Q_LOGGING_CATEGORY(lcAccountState, "gui.account.state", QtInfoMsg) +void AccountState::updateUrlDialog(AccountPtr account, const QUrl &newUrl, std::function<void()> callback) +{ + 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()), + 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, newUrl, account, callback] { + if (diag->clickedButton() == yes) { + account->setUrl(newUrl); + Q_EMIT account->wantsAccountSaved(account.data()); + } + if (callback) { + callback(); + } + }); + diag->show(); +} + AccountState::AccountState(AccountPtr account) : QObject() , _account(account) @@ -48,6 +71,9 @@ AccountState::AccountState(AccountPtr account) this, [this] { checkConnectivity(true); }); + connect(account.data(), &Account::requestUrlUpdate, this, [this](const QUrl &newUrl) { + updateUrlDialog(_account, newUrl, [this] { checkConnectivity(); }); + }); } AccountState::~AccountState() |