Perform DNS lookups automatically

This commit is contained in:
Alex Spataru 2021-04-01 01:06:56 -05:00
parent e87648294f
commit 93482e8e82
10 changed files with 25 additions and 94 deletions

View File

@ -19,7 +19,7 @@ on:
#--------------------------------------------------------------------------------
env:
VERSION: "1.0.20"
VERSION: "1.0.21"
EXECUTABLE: "SerialStudio"
APPLICATION: "Serial Studio"
QMAKE_PROJECT: "Serial-Studio.pro"

View File

@ -36,7 +36,6 @@ Control {
property alias topic: _topic.text
property alias user: _user.text
property alias password: _password.text
property alias dnsAddress: _addrLookup.text
property alias version: _version.currentIndex
property alias mode: _mode.currentIndex
@ -237,46 +236,6 @@ Control {
Layout.minimumHeight: app.spacing
}
//
// Address lookup
//
Label {
text: qsTr("DNS lookup") + ": "
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
} RowLayout {
Layout.fillWidth: true
spacing: app.spacing / 2
TextField {
id: _addrLookup
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
Layout.alignment: Qt.AlignVCenter
onAccepted: Cpp_MQTT_Client.lookup(text)
placeholderText: qsTr("Enter address (e.g. google.com)")
enabled: !Cpp_MQTT_Client.isConnectedToHost &&
!Cpp_MQTT_Client.lookupActive
Behavior on opacity {NumberAnimation{}}
}
Button {
icon.color: palette.text
opacity: enabled ? 1 : 0.5
Layout.maximumWidth: height
Layout.alignment: Qt.AlignVCenter
icon.source: "qrc:/icons/search.svg"
onClicked: Cpp_MQTT_Client.lookup(_addrLookup.text)
enabled: _addrLookup.text.length > 0 &&
!Cpp_MQTT_Client.isConnectedToHost &&
!Cpp_MQTT_Client.lookupActive
Behavior on opacity {NumberAnimation{}}
}
}
//
// Spacer
//

View File

@ -32,8 +32,7 @@ Control {
// Access to properties
//
property alias port: _portText.text
property alias address: _ipText.text
property alias addressLookup: _addrLookup.text
property alias address: _address.text
property alias socketType: _typeCombo.currentIndex
//
@ -80,9 +79,9 @@ Control {
opacity: enabled ? 1 : 0.5
enabled: !Cpp_IO_Manager.connected
Behavior on opacity {NumberAnimation{}}
text: qsTr("IP Address") + ":"
text: qsTr("Host") + ":"
} TextField {
id: _ipText
id: _address
Layout.fillWidth: true
placeholderText: Cpp_IO_Network.defaultHost
text: Cpp_IO_Network.host
@ -133,43 +132,6 @@ Control {
Layout.minimumHeight: app.spacing
}
//
// Address lookup
//
Label {
text: qsTr("DNS lookup") + ": "
opacity: enabled ? 1 : 0.5
enabled: !Cpp_IO_Manager.connected
Behavior on opacity {NumberAnimation{}}
} RowLayout {
Layout.fillWidth: true
spacing: app.spacing / 2
TextField {
id: _addrLookup
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
Layout.alignment: Qt.AlignVCenter
enabled: !Cpp_IO_Manager.connected && !Cpp_IO_Network.lookupActive
onAccepted: Cpp_IO_Network.lookup(text)
placeholderText: qsTr("Enter address (e.g. google.com)")
Behavior on opacity {NumberAnimation{}}
}
Button {
icon.color: palette.text
opacity: enabled ? 1 : 0.5
Layout.maximumWidth: height
Layout.alignment: Qt.AlignVCenter
icon.source: "qrc:/icons/search.svg"
onClicked: Cpp_IO_Network.lookup(_addrLookup.text)
enabled: _addrLookup.text.length > 0 && !Cpp_IO_Manager.connected && !Cpp_IO_Network.lookupActive
Behavior on opacity {NumberAnimation{}}
}
}
//
// Spacer
//

View File

@ -63,7 +63,6 @@ Control {
property alias port: network.port
property alias address: network.address
property alias socketType: network.socketType
property alias addressLookup: network.addressLookup
//
// MQTT settings
@ -75,7 +74,6 @@ Control {
property alias mqttTopic: mqtt.topic
property alias mqttVersion: mqtt.version
property alias mqttPassword: mqtt.password
property alias mqttDnsAddress: mqtt.dnsAddress
//
// App settings

View File

@ -19,7 +19,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.20</string>
<string>1.0.21</string>
<key>LSHasLocalizedDisplayName</key>
<true/>
<key>NSPrincipalClass</key>

View File

@ -29,7 +29,7 @@ Unicode True
!define DESCRIPTION "Dashboard software for serial port devices"
!define VERSIONMAJOR 1
!define VERSIONMINOR 0
!define VERSIONBUILD 20
!define VERSIONBUILD 21
!define MUI_ABORTWARNING
!define INSTALL_DIR "$PROGRAMFILES64\${APPNAME}"
!define MUI_FINISHPAGE_RUN

View File

@ -27,7 +27,7 @@
#include <QString>
// clang-format off
#define APP_VERSION "1.0.20"
#define APP_VERSION "1.0.21"
#define APP_DEVELOPER "Alex Spataru"
#define APP_NAME "Serial Studio"
#define APP_ICON ":/images/icon.png"

View File

@ -33,6 +33,7 @@ static Network *INSTANCE = nullptr;
*/
Network::Network()
{
m_hostExists = false;
m_lookupActive = false;
setHost("");
@ -110,7 +111,7 @@ int Network::socketTypeIndex() const
*/
bool Network::configurationOk() const
{
return port() > 0 && !QHostAddress(host()).isNull();
return port() > 0 && m_hostExists;
}
/**
@ -210,6 +211,17 @@ void Network::setPort(const quint16 port)
*/
void Network::setHost(const QString &host)
{
// Check if host name exists
if (QHostAddress(host).isNull()) {
m_hostExists = false;
lookup(host);
}
// Host is an IP address, host should exist
else
m_hostExists = true;
// Change host
m_host = host;
emit hostChanged();
}
@ -271,12 +283,11 @@ void Network::lookupFinished(const QHostInfo &info)
auto addresses = info.addresses();
if (addresses.count() >= 1)
{
setHost(addresses.first().toString());
m_hostExists = true;
emit hostChanged();
return;
}
}
Misc::Utilities::showMessageBox(tr("IP address lookup error"), info.errorString());
}
/**

View File

@ -111,6 +111,7 @@ private:
private:
QString m_host;
quint16 m_port;
bool m_hostExists;
bool m_lookupActive;
QIODevice *m_device;
QTcpSocket m_tcpSocket;

View File

@ -150,7 +150,7 @@ QString Client::password() const
*/
QString Client::host() const
{
return m_client.host().toString();
return m_client.hostName();
}
/**
@ -247,7 +247,7 @@ void Client::setPort(const quint16 port)
*/
void Client::setHost(const QString &host)
{
m_client.setHost(QHostAddress(host));
m_client.setHostName(host);
emit hostChanged();
}