Loading...
Searching...
No Matches
UDPWidget.hpp
1#pragma once
2#include <Device/Protocol/ProtocolSettingsWidget.hpp>
3
4#include <score/widgets/HelpInteraction.hpp>
5
6#include <ossia/network/sockets/configuration.hpp>
7
8#include <QCheckBox>
9#include <QFormLayout>
10#include <QLineEdit>
11#include <QSpinBox>
12namespace Protocols
13{
14
15class UDPWidget : public QWidget
16{
17public:
18 UDPWidget(Device::ProtocolSettingsWidget& proto, QWidget* parent)
19 : QWidget{parent}
20 {
21 auto layout = new QFormLayout{this};
22 layout->setContentsMargins(0, 0, 0, 0);
23
24 m_remotePort = new QSpinBox(this);
25 m_remotePort->setRange(0, 65535);
26 m_remotePort->setValue(9996);
27 score::setHelp(m_remotePort,
28 tr("Port the other software listens on: score sends to it."));
29 proto.checkForChanges(m_remotePort);
30
31 m_localPort = new QSpinBox(this);
32 m_localPort->setRange(0, 65535);
33 m_localPort->setValue(9997);
34 score::setHelp(m_localPort,
35 tr("Port score listens on for messages from the other software."));
36 proto.checkForChanges(m_localPort);
37
38 m_broadcast = new QCheckBox{this};
39 m_broadcast->setCheckState(Qt::Unchecked);
40 score::setHelp(m_broadcast, tr("Broadcast to every device in the IP broadcast range"));
41
42 m_host = new QLineEdit(this);
43 m_host->setText("127.0.0.1");
44
45 layout->addRow(tr("Device listening port"), m_remotePort);
46 layout->addRow(tr("Broadcast"), m_broadcast);
47 layout->addRow(tr("Device host"), m_host);
48 layout->addRow(tr("score listening port"), m_localPort);
49 }
50
51 ossia::net::udp_configuration settings() const noexcept
52 {
53 ossia::net::udp_configuration conf;
54 conf.local = ossia::net::inbound_socket_configuration{
55 .bind = "0.0.0.0", .port = (uint16_t)m_localPort->value()};
56 conf.remote = ossia::net::outbound_socket_configuration{
57 .host = m_host->text().toStdString(),
58 .port = (uint16_t)m_remotePort->value(),
59 .broadcast = m_broadcast->isChecked()};
60 return conf;
61 }
62
63 void setSettings(const ossia::net::udp_configuration& conf)
64 {
65 if(conf.remote)
66 {
67 m_remotePort->setValue(conf.remote->port);
68 m_host->setText(QString::fromStdString(conf.remote->host));
69 m_broadcast->setChecked(conf.remote->broadcast);
70 }
71 if(conf.local)
72 {
73 m_localPort->setValue(conf.local->port);
74 }
75 }
76
77private:
78 QSpinBox* m_localPort{};
79 QSpinBox* m_remotePort{};
80 QCheckBox* m_broadcast{};
81 QLineEdit* m_host{};
82};
83
84}
Definition ProtocolSettingsWidget.hpp:29
Definition UDPWidget.hpp:16