mirror of
https://github.com/nextcloud/desktop.git
synced 2024-12-22 05:34:33 +03:00
8b5f09305c
- Flow2AuthCredsPage: - Remove .ui file and embed Flow2AuthWidget into layout - Flow2AuthWidget: - Make use generic for Flow2AuthCredsPage and WebFlowCredentialsDialog - Fix _errorLabel to render HTML tags instead of dumping them as plain text - Flow2Auth: - Explicitly start auth with startAuth(account) instead of using constructor - Take control of copying the auth link to clipboard - Request a new auth link on copying, to avoid expiry invalidation - Use signals statusChanged() and result() to be more verbose (status, errors) - Change timer invocation and add safety bool's to avoid weird behaviour when the user triggers multiple link-copy calls (fetchNewToken) Signed-off-by: Michael Schuster <michael@schuster.ms>
170 lines
4.7 KiB
C++
170 lines
4.7 KiB
C++
#include "webflowcredentialsdialog.h"
|
|
|
|
#include <QVBoxLayout>
|
|
#include <QLabel>
|
|
|
|
#include "theme.h"
|
|
#include "application.h"
|
|
#include "owncloudgui.h"
|
|
#include "headerbanner.h"
|
|
#include "wizard/owncloudwizardcommon.h"
|
|
#include "wizard/webview.h"
|
|
#include "wizard/flow2authwidget.h"
|
|
|
|
namespace OCC {
|
|
|
|
WebFlowCredentialsDialog::WebFlowCredentialsDialog(Account *account, bool useFlow2, QWidget *parent)
|
|
: QDialog(parent),
|
|
_useFlow2(useFlow2),
|
|
_flow2AuthWidget(nullptr),
|
|
_webView(nullptr)
|
|
{
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
_layout = new QVBoxLayout(this);
|
|
int spacing = _layout->spacing();
|
|
int margin = _layout->margin();
|
|
_layout->setSpacing(0);
|
|
_layout->setMargin(0);
|
|
|
|
if(_useFlow2) {
|
|
_headerBanner = new HeaderBanner(this);
|
|
_layout->addWidget(_headerBanner);
|
|
Theme *theme = Theme::instance();
|
|
_headerBanner->setup(tr("Log in"), theme->wizardHeaderLogo(), theme->wizardHeaderBanner(),
|
|
Qt::AutoText, QString::fromLatin1("color:#fff;"));
|
|
}
|
|
|
|
_containerLayout = new QVBoxLayout(this);
|
|
_containerLayout->setSpacing(spacing);
|
|
_containerLayout->setMargin(margin);
|
|
|
|
_infoLabel = new QLabel();
|
|
_containerLayout->addWidget(_infoLabel);
|
|
|
|
if (_useFlow2) {
|
|
_flow2AuthWidget = new Flow2AuthWidget();
|
|
_containerLayout->addWidget(_flow2AuthWidget);
|
|
|
|
connect(_flow2AuthWidget, &Flow2AuthWidget::authResult, this, &WebFlowCredentialsDialog::slotFlow2AuthResult);
|
|
|
|
// Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
|
|
connect(this, &WebFlowCredentialsDialog::styleChanged, _flow2AuthWidget, &Flow2AuthWidget::slotStyleChanged);
|
|
|
|
// allow Flow2 page to poll on window activation
|
|
connect(this, &WebFlowCredentialsDialog::onActivate, _flow2AuthWidget, &Flow2AuthWidget::slotPollNow);
|
|
|
|
_flow2AuthWidget->startAuth(account);
|
|
} else {
|
|
_webView = new WebView();
|
|
_containerLayout->addWidget(_webView);
|
|
|
|
connect(_webView, &WebView::urlCatched, this, &WebFlowCredentialsDialog::urlCatched);
|
|
}
|
|
|
|
auto app = static_cast<Application *>(qApp);
|
|
connect(app, &Application::isShowingSettingsDialog, this, &WebFlowCredentialsDialog::slotShowSettingsDialog);
|
|
|
|
_errorLabel = new QLabel();
|
|
_errorLabel->hide();
|
|
_containerLayout->addWidget(_errorLabel);
|
|
|
|
WizardCommon::initErrorLabel(_errorLabel);
|
|
|
|
_layout->addLayout(_containerLayout);
|
|
setLayout(_layout);
|
|
|
|
customizeStyle();
|
|
}
|
|
|
|
void WebFlowCredentialsDialog::closeEvent(QCloseEvent* e) {
|
|
Q_UNUSED(e)
|
|
|
|
if (_webView) {
|
|
// Force calling WebView::~WebView() earlier so that _profile and _page are
|
|
// deleted in the correct order.
|
|
_webView->deleteLater();
|
|
_webView = nullptr;
|
|
}
|
|
|
|
if (_flow2AuthWidget) {
|
|
_flow2AuthWidget->resetAuth();
|
|
_flow2AuthWidget->deleteLater();
|
|
_flow2AuthWidget = nullptr;
|
|
}
|
|
|
|
emit onClose();
|
|
}
|
|
|
|
void WebFlowCredentialsDialog::setUrl(const QUrl &url) {
|
|
if (_webView)
|
|
_webView->setUrl(url);
|
|
}
|
|
|
|
void WebFlowCredentialsDialog::setInfo(const QString &msg) {
|
|
_infoLabel->setText(msg);
|
|
}
|
|
|
|
void WebFlowCredentialsDialog::setError(const QString &error) {
|
|
// bring window to top
|
|
slotShowSettingsDialog();
|
|
|
|
if (_useFlow2 && _flow2AuthWidget) {
|
|
_flow2AuthWidget->setError(error);
|
|
return;
|
|
}
|
|
|
|
if (error.isEmpty()) {
|
|
_errorLabel->hide();
|
|
} else {
|
|
_errorLabel->setText(error);
|
|
_errorLabel->show();
|
|
}
|
|
}
|
|
|
|
void WebFlowCredentialsDialog::changeEvent(QEvent *e)
|
|
{
|
|
switch (e->type()) {
|
|
case QEvent::StyleChange:
|
|
case QEvent::PaletteChange:
|
|
case QEvent::ThemeChange:
|
|
customizeStyle();
|
|
|
|
// Notify the other widgets (Dark-/Light-Mode switching)
|
|
emit styleChanged();
|
|
break;
|
|
case QEvent::ActivationChange:
|
|
if(isActiveWindow())
|
|
emit onActivate();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
QDialog::changeEvent(e);
|
|
}
|
|
|
|
void WebFlowCredentialsDialog::customizeStyle()
|
|
{
|
|
// HINT: Customize dialog's own style here, if necessary in the future (Dark-/Light-Mode switching)
|
|
}
|
|
|
|
void WebFlowCredentialsDialog::slotShowSettingsDialog()
|
|
{
|
|
// bring window to top but slightly delay, to avoid being hidden behind the SettingsDialog
|
|
QTimer::singleShot(100, this, [this] {
|
|
ownCloudGui::raiseDialog(this);
|
|
});
|
|
}
|
|
|
|
void WebFlowCredentialsDialog::slotFlow2AuthResult(Flow2Auth::Result r, const QString &errorString, const QString &user, const QString &appPassword)
|
|
{
|
|
if(r == Flow2Auth::LoggedIn) {
|
|
emit urlCatched(user, appPassword, QString());
|
|
} else {
|
|
// bring window to top
|
|
slotShowSettingsDialog();
|
|
}
|
|
}
|
|
|
|
} // namespace OCC
|