2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-02-23 13:42:29 +03:00
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include "dialogs/FallbackAuth.h"
|
|
|
|
|
|
|
|
#include "Config.h"
|
|
|
|
#include "MatrixClient.h"
|
|
|
|
|
|
|
|
using namespace dialogs;
|
|
|
|
|
|
|
|
FallbackAuth::FallbackAuth(const QString &authType, const QString &session, QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
setAutoFillBackground(true);
|
|
|
|
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
|
|
|
setWindowModality(Qt::WindowModal);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
2020-02-23 13:42:29 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
auto layout = new QVBoxLayout(this);
|
|
|
|
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
2021-12-28 22:09:08 +03:00
|
|
|
layout->setContentsMargins(conf::modals::WIDGET_MARGIN,
|
|
|
|
conf::modals::WIDGET_MARGIN,
|
|
|
|
conf::modals::WIDGET_MARGIN,
|
|
|
|
conf::modals::WIDGET_MARGIN);
|
2020-02-23 13:42:29 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
auto buttonLayout = new QHBoxLayout();
|
|
|
|
buttonLayout->setSpacing(8);
|
2020-02-23 13:42:29 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
openBtn_ = new QPushButton(tr("Open Fallback in Browser"), this);
|
|
|
|
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
|
|
|
confirmBtn_ = new QPushButton(tr("Confirm"), this);
|
|
|
|
confirmBtn_->setDefault(true);
|
2020-02-23 13:42:29 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
buttonLayout->addStretch(1);
|
|
|
|
buttonLayout->addWidget(openBtn_);
|
|
|
|
buttonLayout->addWidget(cancelBtn_);
|
|
|
|
buttonLayout->addWidget(confirmBtn_);
|
2020-02-23 13:42:29 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QFont font;
|
|
|
|
font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO);
|
2020-02-23 13:42:29 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
auto label = new QLabel(
|
|
|
|
tr("Open the fallback, follow the steps and confirm after completing them."), this);
|
|
|
|
label->setFont(font);
|
2020-02-23 13:42:29 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
layout->addWidget(label);
|
|
|
|
layout->addLayout(buttonLayout);
|
2020-02-23 13:42:29 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
connect(openBtn_, &QPushButton::clicked, [session, authType]() {
|
|
|
|
const auto url = QString("https://%1:%2/_matrix/client/r0/auth/%4/"
|
|
|
|
"fallback/web?session=%3")
|
|
|
|
.arg(QString::fromStdString(http::client()->server()))
|
|
|
|
.arg(http::client()->port())
|
|
|
|
.arg(session)
|
|
|
|
.arg(authType);
|
2020-02-23 13:42:29 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QDesktopServices::openUrl(url);
|
|
|
|
});
|
2020-02-23 13:42:29 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
|
|
|
emit confirmation();
|
|
|
|
emit close();
|
|
|
|
});
|
|
|
|
connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
|
|
|
|
emit cancel();
|
|
|
|
emit close();
|
|
|
|
});
|
2020-02-23 13:42:29 +03:00
|
|
|
}
|