-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathconnform.cpp
88 lines (82 loc) · 2.91 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
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
/**
* Copyright (C) 2013-2017 Feng Lee <[email protected]>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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();
// New API do not use.
//QMQTT::Will *will;
if(!_client->isConnectedToHost()) {
//changes
//API: void setHost(const QHostAddress& host);
QHostAddress hostAdd(ui->leHost->text());
_client->setHost(hostAdd);
_client->setPort(ui->sbPort->value());
_client->setKeepAlive(ui->sbKeepalive->value());
//changes
//API: void setCleanSession(const bool cleansess);;
_client->setCleanSession(ui->cbCleanSess->isChecked());
if(!clientId.isEmpty()) _client->setClientId(clientId);
if(!username.isEmpty()) _client->setUsername(username);
if(!passwd.isEmpty()) _client->setPassword(passwd.toUtf8());
//Use directly setWillTopic and setWillMessage.
if(!willtopic.isEmpty() && !willmsg.isEmpty()) {
//New
//API: void setWillTopic(const QString& willTopic);
//API: void setWillQos(const quint8 willQos);
//API: void setWillRetain(const bool willRetain);
//API: void setWillMessage(const QString& willMessage);
_client->setWillTopic(willtopic);
_client->setWillMessage(willmsg.toUtf8());
}
//changes
//API: void connectToHost();
_client->connectToHost();
}
}
void ConnForm::onDisconnect()
{
//changes
//API: bool isConnectedToHost() const;
if(_client->isConnectedToHost()) {
//change disconnected() to disconnectFromHost()
_client->disconnectFromHost();
}
}
void ConnForm::updateUiStatus()
{
//changes
//API: bool isConnectedToHost() const;
ui->connButton->setEnabled(!_client->isConnectedToHost());
ui->disconnButton->setEnabled(_client->isConnectedToHost());
}