-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathconnform.cpp
55 lines (49 loc) · 1.45 KB
/
connform.cpp
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
#include "connform.h"
#include "ui_connform.h"
ConnForm::ConnForm(QWidget *parent) :
MqttForm(parent),
ui(new Ui::ConnForm)
{
ui->setupUi(this);
ui->disconnButton->setEnabled(false);
}
ConnForm::~ConnForm()
{
delete ui;
}
void ConnForm::onConnect()
{
QString clientId = ui->leClientId->text();
QString username = ui->leUser->text();
QString passwd = ui->lePasswd->text();
QString willtopic = ui->leWillTopic->text();
QString willmsg = ui->teWillMsg->toPlainText();
QMQTT::Will *will;
if(!_client->isConnected()) {
_client->setHost(ui->leHost->text());
_client->setPort(ui->sbPort->value());
_client->setKeepAlive(ui->sbKeepalive->value());
_client->setCleansess(ui->cbCleanSess->isChecked());
if(!clientId.isEmpty()) _client->setClientId(clientId);
if(!username.isEmpty()) _client->setUsername(username);
if(!passwd.isEmpty()) _client->setPassword(passwd);
//FIXME: this api is not good
if(!willtopic.isEmpty() && !willmsg.isEmpty()) {
will = new QMQTT::Will(willtopic, willmsg);
_client->setWill(will);
}
_client->connect();
}
}
void ConnForm::onDisconnect()
{
if(_client->isConnected()) {
//TODO: FIX LATER
_client->disconnect();
}
}
void ConnForm::updateUiStatus()
{
ui->connButton->setEnabled(!_client->isConnected());
ui->disconnButton->setEnabled(_client->isConnected());
}