Begin working on improvements for issue #34

This commit is contained in:
Alex Spataru 2021-11-10 02:25:21 -06:00
parent 1ca799b2a9
commit f5ddd18611
6 changed files with 295 additions and 48 deletions

View File

@ -41,7 +41,7 @@ Window {
// Window radius control
//
property int borderWidth: 2
readonly property int handleSize: radius > 0 ? radius + 5 + shadowMargin : 0
readonly property int handleSize: radius > 0 ? radius + 10 + shadowMargin : 0
readonly property int radius: ((root.visibility === Window.Maximized && maximizeEnabled) || isFullscreen) ? 0 : 10
//

View File

@ -97,13 +97,16 @@ Item {
//
// MQTT settings
//
property alias mqttQos: mqtt.qos
property alias mqttHost: mqtt.host
property alias mqttPort: mqtt.port
property alias mqttUser: mqtt.user
property alias mqttMode: mqtt.mode
property alias mqttTopic: mqtt.topic
property alias mqttRetain: mqtt.retain
property alias mqttVersion: mqtt.version
property alias mqttPassword: mqtt.password
property alias mqttKeepAlive: mqtt.keepAlive
//
// App settings

View File

@ -38,6 +38,9 @@ Control {
property alias password: _password.text
property alias version: _version.currentIndex
property alias mode: _mode.currentIndex
property alias retain: _retain.checked
property alias qos: _qos.currentIndex
property alias keepAlive: _keepAlive.text
//
// React to events from MQTT module
@ -52,7 +55,7 @@ Control {
function onPortChanged() {
if (_port.text.length > 0)
_port.text = Cpp_MQTT_Client.port
_port.text = Cpp_MQTT_Client.port
}
}
@ -67,15 +70,22 @@ Control {
GridLayout {
columns: 2
Layout.fillWidth: true
rowSpacing: app.spacing
rowSpacing: app.spacing / 2
columnSpacing: app.spacing
//
// Version & mode titles
//
Label {
text: qsTr("Version") + ":"
} Label {
text: qsTr("Mode") + ":"
}
//
// MQTT version
//
Label {
text: qsTr("Version") + ":"
} ComboBox {
ComboBox {
id: _version
Layout.fillWidth: true
model: Cpp_MQTT_Client.mqttVersions
@ -89,9 +99,7 @@ Control {
//
// Client mode version
//
Label {
text: qsTr("Mode") + ":"
} ComboBox {
ComboBox {
id: _mode
Layout.fillWidth: true
model: Cpp_MQTT_Client.clientModes
@ -103,14 +111,101 @@ Control {
}
//
// Host
// Spacers
//
Item {
height: app.spacing / 2
} Item {
height: app.spacing / 2
}
//
// QOS Level & Keep Alive
//
Label {
text: qsTr("QOS level") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
} Label {
text: qsTr("Keep alive (s)") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
}
//
// QOS
//
ComboBox {
id: _qos
Layout.fillWidth: true
model: Cpp_MQTT_Client.qosLevels
currentIndex: Cpp_MQTT_Client.qos
onCurrentIndexChanged: {
if (Cpp_MQTT_Client.qos !== currentIndex)
Cpp_MQTT_Client.qos = currentIndex
}
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
}
//
// Keep alive
//
TextField {
id: _keepAlive
Layout.fillWidth: true
placeholderText: Cpp_MQTT_Client.keepAlive
Component.onCompleted: text = Cpp_MQTT_Client.keepAlive
onTextChanged: {
if (Cpp_MQTT_Client.keepAlive !== text && text.length > 0)
Cpp_MQTT_Client.keepAlive = text
if (text.length === 0)
Cpp_MQTT_Client.keepAlive = 1
}
validator: IntValidator {
bottom: 1
top: 65535
}
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
}
//
// Spacers
//
Item {
height: app.spacing / 2
} Item {
height: app.spacing / 2
}
//
// Host & port titles
//
Label {
text: qsTr("Host") + ":"
} TextField {
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
} Label {
text: qsTr("Port") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
}
//
// Host
//
TextField {
id: _host
Layout.fillWidth: true
placeholderText: Cpp_MQTT_Client.defaultHost
@ -131,12 +226,7 @@ Control {
//
// Port
//
Label {
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
text: qsTr("Port") + ":"
} TextField {
TextField {
id: _port
Layout.fillWidth: true
placeholderText: Cpp_MQTT_Client.defaultPort
@ -160,14 +250,33 @@ Control {
}
//
// Topic
// Spacers
//
Item {
height: app.spacing / 2
} Item {
height: app.spacing / 2
}
//
// Topic & retain labels
//
Label {
text: qsTr("Topic") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
text: qsTr("Topic") + ":"
} TextField {
} Label {
text: qsTr("Retain") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
}
//
// Topic
//
TextField {
id: _topic
Layout.fillWidth: true
text: Cpp_MQTT_Client.topic
@ -183,14 +292,51 @@ Control {
}
//
// Username
// Retain checkbox
//
Label {
CheckBox {
id: _retain
Layout.fillWidth: true
text: qsTr("Add retain flag")
Layout.leftMargin: -app.spacing
checked: Cpp_MQTT_Client.retain
onCheckedChanged: {
if (Cpp_MQTT_Client.retain != checked)
Cpp_MQTT_Client.retain = checked
}
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
}
// Spacers
//
Item {
height: app.spacing / 2
} Item {
height: app.spacing / 2
}
//
// Username & password titles
//
Label {
text: qsTr("User") + ":"
} TextField {
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
} Label {
text: qsTr("Password") + ":"
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
}
//
// Username
//
TextField {
id: _user
Layout.fillWidth: true
text: Cpp_MQTT_Client.username
@ -208,12 +354,7 @@ Control {
//
// Password
//
Label {
opacity: enabled ? 1 : 0.5
enabled: !Cpp_MQTT_Client.isConnectedToHost
Behavior on opacity {NumberAnimation{}}
text: qsTr("Password") + ":"
} RowLayout {
RowLayout {
Layout.fillWidth: true
spacing: app.spacing / 2
@ -250,7 +391,7 @@ Control {
//
Item {
Layout.fillHeight: true
Layout.minimumHeight: app.spacing
Layout.minimumHeight: app.spacing * 2
}
//

View File

@ -83,27 +83,27 @@ FramelessWindow.CustomWindow {
//
function showMainWindow() {
// Reset window size for whatever reason
if (width <= 0 || height <= 0) {
width = minimumWidth
height = minimumHeight
if (root.width <= 0 || root.height <= 0) {
root.width = root.minimumWidth
root.height = root.minimumHeight
}
// Startup verifications to ensure that app is displayed inside the screen
if (x < 0 || x >= Screen.desktopAvailableWidth)
x = 100
if (y < 0 || y >= Screen.desktopAvailableHeight)
y = 100
if (root.x < 0 || root.x >= Screen.desktopAvailableWidth)
root.x = 100
if (root.y < 0 || root.y >= Screen.desktopAvailableHeight)
root.y = 100
// Startup verifications to ensure that app fits in current screen
if (width > Screen.desktopAvailableWidth) {
x = 100
width = Screen.desktopAvailableWidth - x
if (root.width > Screen.desktopAvailableWidth) {
root.x = 100
root.width = Screen.desktopAvailableWidth - root.x
}
// Startup verifications to ensure that app fits in current screen
if (height > Screen.desktopAvailableHeight) {
y = 100
height = Screen.desktopAvailableHeight - y
if (root.height > Screen.desktopAvailableHeight) {
root.y = 100
root.height = Screen.desktopAvailableHeight - root.y
}
// Increment app launch count & hide splash screen
@ -116,10 +116,16 @@ FramelessWindow.CustomWindow {
else if (root.isMaximized)
root.showMaximized()
else {
opacity = 0
// Fix maximize not working on first try on macOS
root.opacity = 0
var x = root.x
var y = root.y
var w = root.width
var h = root.height
root.showMaximized()
root.showNormal()
opacity = 1
root.setGeometry(x, y, w,h)
root.opacity = 1
}
// Force active focus
@ -127,11 +133,11 @@ FramelessWindow.CustomWindow {
root.requestUpdate()
// Show donations dialog every 15 launches
if (appLaunchCount % 15 == 0 && !donations.doNotShowAgain)
if (root.appLaunchCount % 15 == 0 && !donations.doNotShowAgain)
app.donations.showAutomatically()
// Ask user if he/she wants to enable automatic updates
if (appLaunchCount == 2 && Cpp_UpdaterEnabled) {
if (root.appLaunchCount == 2 && Cpp_UpdaterEnabled) {
if (Cpp_Misc_Utilities.askAutomaticUpdates()) {
root.automaticUpdates = true
Cpp_Updater.checkForUpdates(Cpp_AppUpdaterUrl)
@ -142,7 +148,7 @@ FramelessWindow.CustomWindow {
}
// Check for updates (if we are allowed)
if (automaticUpdates && Cpp_UpdaterEnabled)
if (root.automaticUpdates && Cpp_UpdaterEnabled)
Cpp_Updater.checkForUpdates(Cpp_AppUpdaterUrl)
}

View File

@ -78,6 +78,22 @@ Client *Client::getInstance()
return CLIENT;
}
/**
* Returns the quality-of-service option, available values:
* - 0: at most once
* - 1: at least once
* - 2: exactly once
*/
quint8 Client::qos() const
{
return m_client.willQos();
}
bool Client::retain() const
{
return m_client.willRetain();
}
/**
* Returns the TCP port number used for the MQTT connection
*/
@ -148,6 +164,14 @@ QString Client::host() const
return m_client.hostName();
}
/**
* Returns the keep-alive timeout interval used by the MQTT client.
*/
quint16 Client::keepAlive() const
{
return m_client.keepAlive();
}
/**
* Returns @c true if the MQTT module is currently performing a DNS lookup of the MQTT
* broker/server domain.
@ -174,6 +198,20 @@ bool Client::isConnectedToHost() const
return m_client.isConnectedToHost();
}
/**
* Returns a list with the available quality-of-service modes.
*/
StringList Client::qosLevels() const
{
// clang-format off
return StringList {
tr("0: At most once"),
tr("1: At least once"),
tr("2: Exactly once")
};
// clang-format on
}
/**
* Returns a list with the available client operation modes.
*/
@ -218,6 +256,28 @@ void Client::disconnectFromHost()
m_client.disconnectFromHost();
}
/**
* Changes the quality of service level of the MQTT client.
*/
void Client::setQos(const quint8 qos)
{
if (qos >= 0 && qos <= 2)
{
m_client.setWillQos(qos);
emit qosChanged();
}
}
/**
* If set to @c true, the @c retain flag shall be appended to the MQTT message so that
* new clients connecting to the broker will immediately receive the last "good" message.
*/
void Client::setRetain(const bool retain)
{
m_client.setWillRetain(retain);
emit retainChanged();
}
/**
* Performs a DNS lookup for the given @a host name
*/
@ -284,6 +344,17 @@ void Client::setPassword(const QString &password)
emit passwordChanged();
}
/**
* Sets the maximum time interval that is permitted to elapse between the point at which
* the Client finishes transmitting one Control Packet and the point it starts sending the
* next packet.
*/
void Client::setKeepAlive(const quint16 keepAlive)
{
m_client.setKeepAlive(keepAlive);
emit keepAliveChanged();
}
/**
* Changes the MQTT version used to connect to the MQTT broker/server
*/

View File

@ -64,10 +64,22 @@ class Client : public QObject
READ port
WRITE setPort
NOTIFY portChanged)
Q_PROPERTY(quint8 qos
READ qos
WRITE setQos
NOTIFY qosChanged)
Q_PROPERTY(QString host
READ host
WRITE setHost
NOTIFY hostChanged)
Q_PROPERTY(bool retain
READ retain
WRITE setRetain
NOTIFY retainChanged)
Q_PROPERTY(quint16 keepAlive
READ keepAlive
WRITE setKeepAlive
NOTIFY keepAliveChanged)
Q_PROPERTY(QString topic
READ topic
WRITE setTopic
@ -100,6 +112,9 @@ class Client : public QObject
Q_PROPERTY(StringList clientModes
READ clientModes
CONSTANT)
Q_PROPERTY(StringList qosLevels
READ qosLevels
CONSTANT)
Q_PROPERTY(quint16 defaultPort
READ defaultPort
CONSTANT)
@ -109,11 +124,14 @@ class Client : public QObject
// clang-format on
signals:
void qosChanged();
void portChanged();
void hostChanged();
void topicChanged();
void retainChanged();
void usernameChanged();
void passwordChanged();
void keepAliveChanged();
void connectedChanged();
void clientModeChanged();
void mqttVersionChanged();
@ -122,6 +140,8 @@ signals:
public:
static Client *getInstance();
quint8 qos() const;
bool retain() const;
quint16 port() const;
QString host() const;
QString topic() const;
@ -129,9 +149,12 @@ public:
int mqttVersion() const;
QString username() const;
QString password() const;
quint16 keepAlive() const;
bool lookupActive() const;
bool isSubscribed() const;
bool isConnectedToHost() const;
StringList qosLevels() const;
StringList clientModes() const;
StringList mqttVersions() const;
@ -142,6 +165,8 @@ public slots:
void connectToHost();
void toggleConnection();
void disconnectFromHost();
void setQos(const quint8 qos);
void setRetain(const bool retain);
void lookup(const QString &host);
void setPort(const quint16 port);
void setHost(const QString &host);
@ -149,6 +174,7 @@ public slots:
void setTopic(const QString &topic);
void setUsername(const QString &username);
void setPassword(const QString &password);
void setKeepAlive(const quint16 keepAlive);
void setMqttVersion(const int versionIndex);
private: