Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add require configuration on DeviceManager #1014

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 45 additions & 11 deletions qml/DeviceManagerViewer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import StyleManager 1.0
PingPopup {
id: root

enum ConnectionStatus {
Available,
Unavailable,
InvalidConfiguration,
ConfigurationIsRequired
}

closePolicy: Popup.NoAutoClose
onVisibleChanged: {
visible ? DeviceManager.startDetecting() : DeviceManager.stopDetecting();
Expand Down Expand Up @@ -194,6 +201,20 @@ PingPopup {
delegate: Rectangle {
id: rectDelegate

//TODO: Move this logic and variable to C++ somehow
property var connectionStatus: {
if (!connection.isValid())
return DeviceManagerViewer.ConnectionStatus.InvalidConfiguration;

if (connection.deviceType() == PingEnumNamespace.PingDeviceType.PING360 && connection.type() == AbstractLinkNamespace.Udp && connection.isSubnetBroadcast())
return DeviceManagerViewer.ConnectionStatus.ConfigurationIsRequired;

if (available)
return DeviceManagerViewer.ConnectionStatus.Available;

return DeviceManagerViewer.ConnectionStatus.Unavailable;
}

height: 40
width: parent.width
color: buttonMouseArea.containsMouse ? "gainsboro" : "transparent"
Expand All @@ -216,6 +237,7 @@ PingPopup {

anchors.fill: parent
hoverEnabled: true
enabled: rectDelegate.connectionStatus != DeviceManagerViewer.ConnectionStatus.ConfigurationIsRequired
onClicked: {
DeviceManager.connectLink(connection);
}
Expand Down Expand Up @@ -268,7 +290,9 @@ PingPopup {
selected: deviceConfigureMouseArea.containsMouse
Layout.alignment: Qt.AlignRight
visible: {
return connection.deviceType() == PingEnumNamespace.PingDeviceType.PING360 && connection.type() == AbstractLinkNamespace.Udp && !connection.isCompanionPort();
const canBeConfigured = connection.deviceType() == PingEnumNamespace.PingDeviceType.PING360 && connection.type() == AbstractLinkNamespace.Udp && !connection.isCompanionPort();
const configurationRequired = parent.parent.connectionStatus == DeviceManagerViewer.ConnectionStatus.ConfigurationIsRequired;
return canBeConfigured || configurationRequired;
}

MouseArea {
Expand All @@ -292,13 +316,18 @@ PingPopup {
Layout.rightMargin: 5
Layout.alignment: Qt.AlignRight
color: {
if (!available)
switch (rectDelegate.connectionStatus) {
case DeviceManagerViewer.ConnectionStatus.Available:
return "green";
case DeviceManagerViewer.ConnectionStatus.Unavailable:
return "red";

if (!connection.isValid())
case DeviceManagerViewer.ConnectionStatus.InvalidConfiguration:
return "yellow";

return "green";
case DeviceManagerViewer.ConnectionStatus.ConfigurationIsRequired:
return "blue";
default:
return "orange";
}
}
active: true

Expand All @@ -309,13 +338,18 @@ PingPopup {
ToolTip {
visible: parent.containsMouse
text: {
if (!available)
switch (rectDelegate.connectionStatus) {
case DeviceManagerViewer.ConnectionStatus.Available:
return "Device available.";
case DeviceManagerViewer.ConnectionStatus.Unavailable:
return "Device busy or not available.";

if (!connection.isValid())
case DeviceManagerViewer.ConnectionStatus.InvalidConfiguration:
return connection.errorToString();

return "Device available.";
case DeviceManagerViewer.ConnectionStatus.ConfigurationIsRequired:
return "Configuration is required.";
default:
return "Unknown connection status.";
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/link/linkconfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ int LinkConfiguration::udpPort() const

bool LinkConfiguration::isInSubnet() const { return NetworkManager::isIpInSubnet(udpHost()); }

bool LinkConfiguration::isSubnetBroadcast() const { return NetworkManager::isIpSubnetBroadcast(udpHost()); }

bool operator==(const LinkConfiguration& first, const LinkConfiguration& second)
{
auto firstLinkconf = first.configurationStruct();
Expand Down
8 changes: 8 additions & 0 deletions src/link/linkconfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ class LinkConfiguration : public QObject {
*/
bool isInSubnet() const;

/**
* @brief Check if IP has a valid and accessible broadcast IP.
*
* @return true
* @return false
*/
Q_INVOKABLE bool isSubnetBroadcast() const;

/**
* @brief Return link configuration type
*
Expand Down
10 changes: 10 additions & 0 deletions src/network/networkmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ bool NetworkManager::isIpInSubnet(const QString& ip)
return false;
}

bool NetworkManager::isIpSubnetBroadcast(const QString& ip)
{
if (!NetworkManager::isIpInSubnet(ip)) {
qCWarning(NETWORKMANAGER) << "IP address does not have a valid subnet:" << ip;
return false;
}

return ip.endsWith("255");
}

QObject* NetworkManager::qmlSingletonRegister(QQmlEngine* engine, QJSEngine* scriptEngine)
{
Q_UNUSED(engine)
Expand Down
9 changes: 9 additions & 0 deletions src/network/networkmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ class NetworkManager : public QObject {
*/
static bool isIpInSubnet(const QString& ip);

/**
* @brief Check if IP address is a valid broadcast IP in a /24 network.
*
* @param ip
* @return true
* @return false
*/
static bool isIpSubnetBroadcast(const QString& ip);

/**
* @brief Return a pointer of this singleton to the qml register function
*
Expand Down