mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-15 05:22:53 +08:00
Add hide/show MQTT password
This commit is contained in:
parent
a8fb35cc49
commit
48e8dc24b5
@ -67,6 +67,21 @@ Control {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Client mode version
|
||||
//
|
||||
Label {
|
||||
text: qsTr("Mode") + ":"
|
||||
} ComboBox {
|
||||
Layout.fillWidth: true
|
||||
model: Cpp_MQTT_Publisher.clientModes
|
||||
currentIndex: Cpp_MQTT_Publisher.clientMode
|
||||
onCurrentIndexChanged: {
|
||||
if (Cpp_MQTT_Publisher.clientMode !== currentIndex)
|
||||
Cpp_MQTT_Publisher.clientMode = currentIndex
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Host
|
||||
//
|
||||
@ -172,19 +187,35 @@ Control {
|
||||
enabled: !Cpp_MQTT_Publisher.isConnectedToHost
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
text: qsTr("Password") + ":"
|
||||
} TextField {
|
||||
id: _password
|
||||
} RowLayout {
|
||||
Layout.fillWidth: true
|
||||
text: Cpp_MQTT_Publisher.password
|
||||
placeholderText: qsTr("MQTT password")
|
||||
onTextChanged: {
|
||||
if (Cpp_MQTT_Publisher.password !== text)
|
||||
Cpp_MQTT_Publisher.password = text
|
||||
spacing: app.spacing / 2
|
||||
|
||||
TextField {
|
||||
id: _password
|
||||
Layout.fillWidth: true
|
||||
echoMode: TextField.PasswordEchoOnEdit
|
||||
text: Cpp_MQTT_Publisher.password
|
||||
placeholderText: qsTr("MQTT password")
|
||||
onTextChanged: {
|
||||
if (Cpp_MQTT_Publisher.password !== text)
|
||||
Cpp_MQTT_Publisher.password = text
|
||||
}
|
||||
|
||||
opacity: enabled ? 1 : 0.5
|
||||
enabled: !Cpp_MQTT_Publisher.isConnectedToHost
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
}
|
||||
|
||||
opacity: enabled ? 1 : 0.5
|
||||
enabled: !Cpp_MQTT_Publisher.isConnectedToHost
|
||||
Behavior on opacity {NumberAnimation{}}
|
||||
Button {
|
||||
checkable: true
|
||||
icon.color: palette.text
|
||||
Layout.maximumWidth: height
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
icon.source: "qrc:/icons/visibility.svg"
|
||||
onCheckedChanged: _password.echoMode = (checked ? TextField.Normal :
|
||||
TextField.PasswordEchoOnEdit)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -652,17 +652,22 @@ QString Console::plainTextStr(const QByteArray &data)
|
||||
*/
|
||||
QString Console::hexadecimalStr(const QByteArray &data)
|
||||
{
|
||||
// Remove line breaks from data
|
||||
QByteArray copy = data;
|
||||
copy.replace("\n", "");
|
||||
copy.replace("\r", "");
|
||||
|
||||
// Convert data to string with dump every ~80 chars
|
||||
QString str;
|
||||
const int characters = 80;
|
||||
for (int i = 0; i < data.length(); ++i)
|
||||
for (int i = 0; i < copy.length(); ++i)
|
||||
{
|
||||
QByteArray line;
|
||||
for (int j = 0; j < qMin(characters, data.length() - i); ++j)
|
||||
line.append(data.at(i + j));
|
||||
for (int j = 0; j < qMin(characters, copy.length() - i); ++j)
|
||||
line.append(copy.at(i + j));
|
||||
|
||||
i += characters;
|
||||
str.append(HexDump(line.data(), line.size()));
|
||||
str.append("\n");
|
||||
}
|
||||
|
||||
// Return string
|
||||
|
@ -32,6 +32,7 @@ static Publisher *INSTANCE = nullptr;
|
||||
Publisher::Publisher()
|
||||
{
|
||||
m_lookupActive = false;
|
||||
m_clientMode = MQTTClientMode::ClientPublisher;
|
||||
|
||||
connect(&m_client, &QMQTT::Client::connected, this, &Publisher::connectedChanged);
|
||||
connect(&m_client, &QMQTT::Client::disconnected, this, &Publisher::connectedChanged);
|
||||
@ -80,6 +81,11 @@ int Publisher::mqttVersion() const
|
||||
}
|
||||
}
|
||||
|
||||
int Publisher::clientMode() const
|
||||
{
|
||||
return m_clientMode;
|
||||
}
|
||||
|
||||
QString Publisher::username() const
|
||||
{
|
||||
return m_client.username();
|
||||
@ -105,6 +111,11 @@ bool Publisher::isConnectedToHost() const
|
||||
return m_client.isConnectedToHost();
|
||||
}
|
||||
|
||||
QStringList Publisher::clientModes() const
|
||||
{
|
||||
return QStringList { tr("Publisher"), tr("Suscriber") };
|
||||
}
|
||||
|
||||
QStringList Publisher::mqttVersions() const
|
||||
{
|
||||
return QStringList { "MQTT 3.1.0", "MQTT 3.1.1" };
|
||||
@ -154,6 +165,12 @@ void Publisher::setHost(const QString &host)
|
||||
emit hostChanged();
|
||||
}
|
||||
|
||||
void Publisher::setClientMode(const int mode)
|
||||
{
|
||||
m_clientMode = (MQTTClientMode)mode;
|
||||
emit clientModeChanged();
|
||||
}
|
||||
|
||||
void Publisher::setTopic(const QString &topic)
|
||||
{
|
||||
m_topic = topic;
|
||||
|
@ -35,6 +35,12 @@
|
||||
|
||||
namespace MQTT
|
||||
{
|
||||
enum MQTTClientMode
|
||||
{
|
||||
ClientPublisher = 0,
|
||||
ClientSubscriber = 1
|
||||
};
|
||||
|
||||
class Publisher : public QObject
|
||||
{
|
||||
// clang-format off
|
||||
@ -55,6 +61,10 @@ class Publisher : public QObject
|
||||
READ mqttVersion
|
||||
WRITE setMqttVersion
|
||||
NOTIFY mqttVersionChanged)
|
||||
Q_PROPERTY(int clientMode
|
||||
READ clientMode
|
||||
WRITE setClientMode
|
||||
NOTIFY clientModeChanged)
|
||||
Q_PROPERTY(QString username
|
||||
READ username
|
||||
WRITE setUsername
|
||||
@ -72,6 +82,9 @@ class Publisher : public QObject
|
||||
Q_PROPERTY(QStringList mqttVersions
|
||||
READ mqttVersions
|
||||
CONSTANT)
|
||||
Q_PROPERTY(QStringList clientModes
|
||||
READ clientModes
|
||||
CONSTANT)
|
||||
Q_PROPERTY(quint16 defaultPort
|
||||
READ defaultPort
|
||||
CONSTANT)
|
||||
@ -87,6 +100,7 @@ signals:
|
||||
void usernameChanged();
|
||||
void passwordChanged();
|
||||
void connectedChanged();
|
||||
void clientModeChanged();
|
||||
void mqttVersionChanged();
|
||||
void lookupActiveChanged();
|
||||
|
||||
@ -96,11 +110,13 @@ public:
|
||||
quint16 port() const;
|
||||
QString host() const;
|
||||
QString topic() const;
|
||||
int clientMode() const;
|
||||
int mqttVersion() const;
|
||||
QString username() const;
|
||||
QString password() const;
|
||||
bool lookupActive() const;
|
||||
bool isConnectedToHost() const;
|
||||
QStringList clientModes() const;
|
||||
QStringList mqttVersions() const;
|
||||
|
||||
quint16 defaultPort() const { return 1883; }
|
||||
@ -114,6 +130,7 @@ public slots:
|
||||
void lookup(const QString &host);
|
||||
void setPort(const quint16 port);
|
||||
void setHost(const QString &host);
|
||||
void setClientMode(const int mode);
|
||||
void setTopic(const QString &topic);
|
||||
void setUsername(const QString &username);
|
||||
void setPassword(const QString &password);
|
||||
@ -134,6 +151,7 @@ private:
|
||||
bool m_lookupActive;
|
||||
QMQTT::Client m_client;
|
||||
QList<JFI_Object> m_jfiList;
|
||||
MQTTClientMode m_clientMode;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user