-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatAuthWindow.cpp
More file actions
77 lines (69 loc) · 2.33 KB
/
ChatAuthWindow.cpp
File metadata and controls
77 lines (69 loc) · 2.33 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
#include "ChatAuthWindow.h"
#include "ui_ChatAuthWindow.h"
#include "ConnectionProperties.h"
ChatAuthWindow::ChatAuthWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::ChatAuthWindow)
{
ui->setupUi(this);
m_host = "localhost";
m_port = 33033;
setWindowIcon(QIcon("icon.png"));
}
ChatAuthWindow::~ChatAuthWindow()
{
delete ui;
}
void ChatAuthWindow::setConnectionProperty(QString host, quint32 port)
{
m_host = host;
m_port = port;
}
void ChatAuthWindow::on_registerButton_clicked()
{
if(ui->passwordEdit->text() == "" || ui->usernameEdit->text() == "")
{
ui->infLabel->setText("Username and password must be non-empty.");
return;
}
QString username = ui->usernameEdit->text();
QString password = ui->passwordEdit->text();
m_bot = new RegisterBot(m_host, m_port, username, password, true);
connect(m_bot, SIGNAL(errorOccured(QString)), ui->infLabel, SLOT(setText(QString)));
connect(m_bot, SIGNAL(registrationCompleted(bool,QString&)), this, SLOT(registrationHandler(bool,QString&)));
}
void ChatAuthWindow::registrationHandler(bool registrationResult, QString &denialReason)
{
if(!registrationResult)
ui->infLabel->setText(denialReason);
else
{
ui->infLabel->setText("Registration was successful");
m_bot->closeConnection();
delete m_bot;
}
}
void ChatAuthWindow::on_propertiesButton_clicked()
{
ConnectionProperties connection_window;
connect(&connection_window, SIGNAL(properties(QString,quint32)), this, SLOT(setConnectionProperty(QString,quint32)));
connection_window.exec();
}
void ChatAuthWindow::replyClientAuthorized(QTcpSocket *socket)
{
emit authorized(ui->usernameEdit->text(), ui->passwordEdit->text(), socket);
this->hide();
}
void ChatAuthWindow::on_connectButton_clicked()
{
if(ui->passwordEdit->text() == "" || ui->usernameEdit->text() == "")
{
ui->infLabel->setText("Username and password must be non-empty.");
return;
}
QString username = ui->usernameEdit->text();
QString password = ui->passwordEdit->text();
m_bot = new RegisterBot(m_host, m_port, username, password, false);
connect(m_bot, SIGNAL(errorOccured(QString)), ui->infLabel, SLOT(setText(QString)));
connect(m_bot, SIGNAL(authorized(QTcpSocket*)), this, SLOT(replyClientAuthorized(QTcpSocket*)));
}