mirror of https://github.com/Nheko-Reborn/nheko
parent
ff4c16c34f
commit
fedc178827
@ -0,0 +1,63 @@ |
||||
// SPDX-FileCopyrightText: Nheko Contributors |
||||
// |
||||
// SPDX-License-Identifier: GPL-3.0-or-later |
||||
|
||||
import QtQuick |
||||
import QtQuick.Controls |
||||
import im.nheko |
||||
|
||||
ApplicationWindow { |
||||
id: recaptchaRoot |
||||
|
||||
required property ReCaptcha recaptcha |
||||
|
||||
function accept() { |
||||
recaptcha.confirm(); |
||||
recaptchaRoot.close(); |
||||
} |
||||
|
||||
function reject() { |
||||
recaptcha.cancel(); |
||||
recaptchaRoot.close(); |
||||
} |
||||
|
||||
color: palette.window |
||||
title: recaptcha.context |
||||
flags: Qt.Tool | Qt.WindowStaysOnTopHint | Qt.WindowCloseButtonHint | Qt.WindowTitleHint |
||||
height: msg.implicitHeight + footer.implicitHeight |
||||
width: Math.max(msg.implicitWidth, footer.implicitWidth) |
||||
|
||||
Shortcut { |
||||
sequence: StandardKey.Cancel |
||||
onActivated: recaptchaRoot.reject() |
||||
} |
||||
|
||||
Label { |
||||
id: msg |
||||
|
||||
anchors.fill: parent |
||||
padding: 8 |
||||
text: qsTr("Solve the reCAPTCHA and press the confirm button") |
||||
} |
||||
|
||||
footer: DialogButtonBox { |
||||
onAccepted: recaptchaRoot.accept() |
||||
onRejected: recaptchaRoot.reject() |
||||
|
||||
Button { |
||||
text: qsTr("Open reCAPTCHA") |
||||
onClicked: recaptcha.openReCaptcha() |
||||
} |
||||
|
||||
Button { |
||||
text: qsTr("Cancel") |
||||
DialogButtonBox.buttonRole: DialogButtonBox.RejectRole |
||||
} |
||||
|
||||
Button { |
||||
text: qsTr("Confirm") |
||||
DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,28 @@ |
||||
// SPDX-FileCopyrightText: Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "ReCaptcha.h" |
||||
|
||||
#include <QDesktopServices> |
||||
#include <QUrl> |
||||
|
||||
#include "MatrixClient.h" |
||||
|
||||
ReCaptcha::ReCaptcha(const QString &session, const QString &context, QObject *parent) |
||||
: QObject{parent}, |
||||
m_session{session}, |
||||
m_context{context} |
||||
{ |
||||
} |
||||
|
||||
void ReCaptcha::openReCaptcha() |
||||
{ |
||||
const auto url = QString("https://%1:%2/_matrix/client/r0/auth/m.login.recaptcha/" |
||||
"fallback/web?session=%3") |
||||
.arg(QString::fromStdString(http::client()->server())) |
||||
.arg(http::client()->port()) |
||||
.arg(m_session); |
||||
|
||||
QDesktopServices::openUrl(url); |
||||
} |
@ -0,0 +1,32 @@ |
||||
// SPDX-FileCopyrightText: Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once |
||||
|
||||
#include <QQmlEngine> |
||||
|
||||
class ReCaptcha : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
QML_ELEMENT |
||||
QML_UNCREATABLE("") |
||||
|
||||
Q_PROPERTY(QString context MEMBER m_context CONSTANT) |
||||
Q_PROPERTY(QString session MEMBER m_session CONSTANT) |
||||
|
||||
public: |
||||
ReCaptcha(const QString &session, const QString &context, QObject *parent = nullptr); |
||||
|
||||
Q_INVOKABLE void openReCaptcha(); |
||||
Q_INVOKABLE void confirm() { emit confirmation(); } |
||||
Q_INVOKABLE void cancel() { emit cancelled(); } |
||||
|
||||
signals: |
||||
void confirmation(); |
||||
void cancelled(); |
||||
|
||||
private: |
||||
QString m_session; |
||||
QString m_context; |
||||
}; |
@ -1,74 +0,0 @@ |
||||
// SPDX-FileCopyrightText: Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <QDesktopServices> |
||||
#include <QLabel> |
||||
#include <QPushButton> |
||||
#include <QUrl> |
||||
#include <QVBoxLayout> |
||||
|
||||
#include "dialogs/ReCaptcha.h" |
||||
|
||||
#include "Config.h" |
||||
#include "MatrixClient.h" |
||||
|
||||
using namespace dialogs; |
||||
|
||||
ReCaptcha::ReCaptcha(const QString &session, QWidget *parent) |
||||
: QWidget(parent) |
||||
{ |
||||
setAutoFillBackground(true); |
||||
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); |
||||
setWindowModality(Qt::WindowModal); |
||||
setAttribute(Qt::WA_DeleteOnClose, true); |
||||
|
||||
auto layout = new QVBoxLayout(this); |
||||
layout->setSpacing(conf::modals::WIDGET_SPACING); |
||||
layout->setContentsMargins(conf::modals::WIDGET_MARGIN, |
||||
conf::modals::WIDGET_MARGIN, |
||||
conf::modals::WIDGET_MARGIN, |
||||
conf::modals::WIDGET_MARGIN); |
||||
|
||||
auto buttonLayout = new QHBoxLayout(); |
||||
buttonLayout->setContentsMargins(0, 0, 0, 0); |
||||
buttonLayout->setSpacing(8); |
||||
|
||||
openCaptchaBtn_ = new QPushButton(tr("Open reCAPTCHA"), this); |
||||
cancelBtn_ = new QPushButton(tr("Cancel"), this); |
||||
confirmBtn_ = new QPushButton(tr("Confirm"), this); |
||||
confirmBtn_->setDefault(true); |
||||
|
||||
buttonLayout->addStretch(1); |
||||
buttonLayout->addWidget(openCaptchaBtn_); |
||||
buttonLayout->addWidget(cancelBtn_); |
||||
buttonLayout->addWidget(confirmBtn_); |
||||
|
||||
QFont font; |
||||
font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO); |
||||
|
||||
auto label = new QLabel(tr("Solve the reCAPTCHA and press the confirm button"), this); |
||||
label->setFont(font); |
||||
|
||||
layout->addWidget(label); |
||||
layout->addLayout(buttonLayout); |
||||
|
||||
connect(openCaptchaBtn_, &QPushButton::clicked, [session]() { |
||||
const auto url = QString("https://%1:%2/_matrix/client/r0/auth/m.login.recaptcha/" |
||||
"fallback/web?session=%3") |
||||
.arg(QString::fromStdString(http::client()->server())) |
||||
.arg(http::client()->port()) |
||||
.arg(session); |
||||
|
||||
QDesktopServices::openUrl(url); |
||||
}); |
||||
|
||||
connect(confirmBtn_, &QPushButton::clicked, this, [this]() { |
||||
emit confirmation(); |
||||
close(); |
||||
}); |
||||
connect(cancelBtn_, &QPushButton::clicked, this, [this]() { |
||||
emit cancel(); |
||||
close(); |
||||
}); |
||||
} |
@ -1,29 +0,0 @@ |
||||
// SPDX-FileCopyrightText: Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#pragma once |
||||
|
||||
#include <QWidget> |
||||
|
||||
class QPushButton; |
||||
|
||||
namespace dialogs { |
||||
|
||||
class ReCaptcha final : public QWidget |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
public: |
||||
ReCaptcha(const QString &session, QWidget *parent = nullptr); |
||||
|
||||
signals: |
||||
void confirmation(); |
||||
void cancel(); |
||||
|
||||
private: |
||||
QPushButton *openCaptchaBtn_; |
||||
QPushButton *confirmBtn_; |
||||
QPushButton *cancelBtn_; |
||||
}; |
||||
} // dialogs
|
Loading…
Reference in new issue