-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathappregistrationdialog.cpp
More file actions
88 lines (77 loc) · 2.56 KB
/
Copy pathappregistrationdialog.cpp
File metadata and controls
88 lines (77 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "appregistrationdialog.h"
#include "ui_appregistrationdialog.h"
#include <QMessageBox>
#include <QRegularExpression>
#include "style.h"
extern int g_showMessageBox(QWidget* parent, QMessageBox::Icon icon,
QString title, QString text,
QMessageBox::StandardButtons buttons = QMessageBox::Ok,
QMessageBox::StandardButton defaultButton = QMessageBox::NoButton);
AppRegistrationDialog::AppRegistrationDialog(LicenseAgent& agent, QWidget *parent) :
QDialog(parent),
ui(new Ui::AppRegistrationDialog),
m_agent(agent)
{
init();
}
AppRegistrationDialog::AppRegistrationDialog(QString user, QString mail, LicenseAgent& agent, QWidget *parent) :
QDialog(parent),
ui(new Ui::AppRegistrationDialog),
m_agent(agent)
{
init(user, mail);
}
void AppRegistrationDialog::init(QString user, QString mail)
{
ui->setupUi(this);
QString style;
style = Style::dialog();
style += Style::label();
style += Style::lineEdit();
setStyleSheet(style);
style = Style::pushButton();
ui->pushButtonCancel->setStyleSheet(style);
ui->pushButtonOk->setStyleSheet(style);
connect(&m_agent, &LicenseAgent::registered, this, [=](){
accept();
});
connect(&m_agent, &LicenseAgent::networkTimeout, this, [=](){
close();
});
connect(&m_agent, &LicenseAgent::canceled, this, [=](){
reject();
});
connect(ui->pushButtonOk, &QPushButton::clicked, this, [=](){
if (email().isEmpty()) {
g_showMessageBox(this, QMessageBox::Warning, tr(""), tr("Email address should be valid"));
return;
}
QRegularExpression mailREX("\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b");
if (!mailREX.match(email().toUpper()).hasMatch()) {
g_showMessageBox(this, QMessageBox::Warning, "", tr("Wrong email address"));
return;
}
accept();
m_agent.registerApllication(name(), email());
});
connect(ui->pushButtonCancel, &QPushButton::clicked, this, [=](){
reject();
});
if (!mail.isEmpty())
ui->lineEditEmail->setText(mail);
if (!user.isEmpty())
ui->lineEditUserName->setText(user);
}
AppRegistrationDialog::~AppRegistrationDialog()
{
delete ui;
}
void AppRegistrationDialog::accept()
{
if (email().isEmpty()) {
return;
}
QDialog::accept();
}
QString AppRegistrationDialog::name() { return ui->lineEditUserName->text(); }
QString AppRegistrationDialog::email() { return ui->lineEditEmail->text(); }