From 42091e522147a95062a8a90a05dc197f7e7d41d7 Mon Sep 17 00:00:00 2001 From: Srivats P Date: Fri, 2 Sep 2022 17:15:46 +0530 Subject: [PATCH] Allow user to add a port description If a user description is available, that is shown in the ports window other wise the system determined description is shown. Updates #223 --- client/port.h | 9 ++++++++- client/portconfigdialog.cpp | 9 +++++++++ client/portconfigdialog.ui | 25 +++++++++++++++++++++++-- client/portswindow.cpp | 2 ++ common/protocol.proto | 1 + server/abstractport.cpp | 4 ++++ 6 files changed, 47 insertions(+), 3 deletions(-) diff --git a/client/port.h b/client/port.h index 431791e..35197c3 100644 --- a/client/port.h +++ b/client/port.h @@ -88,8 +88,15 @@ public: { return d.port_id().id(); } const QString name() const { return QString().fromStdString(d.name()); } - const QString description() const + const QString systemDescription() const { return QString().fromStdString(d.description()); } + const QString userDescription() const + { return QString().fromStdString(d.user_description()); } + const QString description() const + { + return userDescription().isEmpty() ? + systemDescription() : userDescription(); + } const QString notes() const { return QString().fromStdString(d.notes()); } const QString userName() const diff --git a/client/portconfigdialog.cpp b/client/portconfigdialog.cpp index a742ab0..00aa415 100644 --- a/client/portconfigdialog.cpp +++ b/client/portconfigdialog.cpp @@ -32,6 +32,8 @@ PortConfigDialog::PortConfigDialog( setupUi(this); + description->setPlaceholderText(portConfig_.description().c_str()); + description->setText(portConfig_.user_description().c_str()); switch(portConfig_.transmit_mode()) { case OstProto::kSequentialTransmit: @@ -80,6 +82,8 @@ void PortConfigDialog::accept() { OstProto::Port pc; + pc.set_user_description(description->text().toStdString()); + if (sequentialStreamsButton->isChecked()) pc.set_transmit_mode(OstProto::kSequentialTransmit); else if (interleavedStreamsButton->isChecked()) @@ -109,6 +113,11 @@ void PortConfigDialog::accept() pc.set_is_tracking_stream_stats(streamStatsButton->isChecked()); // Update fields that have changed, clear the rest + if (pc.user_description() != portConfig_.user_description()) + portConfig_.set_user_description(pc.user_description()); + else + portConfig_.clear_user_description(); + if (pc.transmit_mode() != portConfig_.transmit_mode()) portConfig_.set_transmit_mode(pc.transmit_mode()); else diff --git a/client/portconfigdialog.ui b/client/portconfigdialog.ui index c103c21..920ec1c 100644 --- a/client/portconfigdialog.ui +++ b/client/portconfigdialog.ui @@ -6,14 +6,27 @@ 0 0 - 244 - 257 + 248 + 292 Port Config + + + + Description + + + description + + + + + + @@ -102,6 +115,14 @@ + + description + sequentialStreamsButton + interleavedStreamsButton + reserveButton + exclusiveControlButton + streamStatsButton + diff --git a/client/portswindow.cpp b/client/portswindow.cpp index cdd6bf9..b23093b 100644 --- a/client/portswindow.cpp +++ b/client/portswindow.cpp @@ -614,6 +614,8 @@ void PortsWindow::on_actionPort_Configuration_triggered() // TODO: extend Port::protoDataCopyInto() to accept an optional param // which says copy only modifiable fields //plm->port(current).protoDataCopyInto(&config); + config.set_description(port.systemDescription().toStdString()); + config.set_user_description(port.userDescription().toStdString()); config.set_transmit_mode(port.transmitMode()); config.set_is_tracking_stream_stats(port.trackStreamStats()); config.set_is_exclusive_control(port.hasExclusiveControl()); diff --git a/common/protocol.proto b/common/protocol.proto index d78593a..ca50b15 100644 --- a/common/protocol.proto +++ b/common/protocol.proto @@ -216,6 +216,7 @@ message Port { optional double speed = 10; // in Mbps optional uint32 mtu = 11; + optional string user_description = 12; } message PortConfigList { diff --git a/server/abstractport.cpp b/server/abstractport.cpp index 153ef9a..67f99a6 100644 --- a/server/abstractport.cpp +++ b/server/abstractport.cpp @@ -103,6 +103,10 @@ bool AbstractPort::modify(const OstProto::Port &port) bool ret = true; //! \todo Use reflection to find out which fields are set + if (port.has_user_description()) { + data_.set_user_description(port.user_description()); + } + if (port.has_is_exclusive_control()) { bool val = port.is_exclusive_control();