feat(MSALogin): add open page & copy code button

Closes #55
This commit is contained in:
Sefa Eyeoglu 2022-01-19 19:49:43 +01:00
parent 35caa3c21a
commit dd76fb0ec7
No known key found for this signature in database
GPG Key ID: C10411294912A422
2 changed files with 31 additions and 8 deletions

View File

@ -16,15 +16,19 @@
#include "MSALoginDialog.h" #include "MSALoginDialog.h"
#include "ui_MSALoginDialog.h" #include "ui_MSALoginDialog.h"
#include "DesktopServices.h"
#include "minecraft/auth/AccountTask.h" #include "minecraft/auth/AccountTask.h"
#include <QtWidgets/QPushButton> #include <QtWidgets/QPushButton>
#include <QUrl> #include <QUrl>
#include <QApplication>
#include <QClipboard>
MSALoginDialog::MSALoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MSALoginDialog) MSALoginDialog::MSALoginDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MSALoginDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
ui->progressBar->setVisible(false); ui->progressBar->setVisible(false);
ui->actionButton->setVisible(false);
// ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false); // ui->buttonBox->button(QDialogButtonBox::Cancel)->setEnabled(false);
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
@ -81,10 +85,17 @@ void MSALoginDialog::showVerificationUriAndCode(const QUrl& uri, const QString&
QString urlString = uri.toString(); QString urlString = uri.toString();
QString linkString = QString("<a href=\"%1\">%2</a>").arg(urlString, urlString); QString linkString = QString("<a href=\"%1\">%2</a>").arg(urlString, urlString);
ui->label->setText(tr("<p>Please open up %1 in a browser and put in the code <b>%2</b> to proceed with login.</p>").arg(linkString, code)); ui->label->setText(tr("<p>Please open up %1 in a browser and put in the code <b>%2</b> to proceed with login.</p>").arg(linkString, code));
ui->actionButton->setVisible(true);
connect(ui->actionButton, &QPushButton::clicked, [=]() {
DesktopServices::openUrl(uri);
QClipboard* cb = QApplication::clipboard();
cb->setText(code);
});
} }
void MSALoginDialog::hideVerificationUriAndCode() { void MSALoginDialog::hideVerificationUriAndCode() {
m_externalLoginTimer.stop(); m_externalLoginTimer.stop();
ui->actionButton->setVisible(false);
} }
void MSALoginDialog::setUserInputsEnabled(bool enable) void MSALoginDialog::setUserInputsEnabled(bool enable)
@ -110,6 +121,7 @@ void MSALoginDialog::onTaskFailed(const QString &reason)
// Re-enable user-interaction // Re-enable user-interaction
setUserInputsEnabled(true); setUserInputsEnabled(true);
ui->progressBar->setVisible(false); ui->progressBar->setVisible(false);
ui->actionButton->setVisible(false);
} }
void MSALoginDialog::onTaskSucceeded() void MSALoginDialog::onTaskSucceeded()

View File

@ -49,14 +49,25 @@ aaaaa</string>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="orientation"> <item>
<enum>Qt::Horizontal</enum> <widget class="QPushButton" name="actionButton">
</property> <property name="text">
<property name="standardButtons"> <string>Open page and copy code</string>
<set>QDialogButtonBox::Cancel</set> </property>
</property> </widget>
</widget> </item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel</set>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>