TCPWidget.hpp
1 #pragma once
2 #include <Device/Protocol/ProtocolSettingsWidget.hpp>
3 
4 #include <ossia/network/sockets/configuration.hpp>
5 #include <ossia/protocols/osc/osc_factory.hpp>
6 
7 #include <QComboBox>
8 #include <QFormLayout>
9 #include <QLineEdit>
10 #include <QSpinBox>
11 namespace Protocols
12 {
13 
14 using framing_type = decltype(ossia::net::osc_protocol_configuration::framing);
15 class BasicTCPWidget : public QWidget
16 {
17 public:
18  BasicTCPWidget(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  m_remotePort->setWhatsThis(
28  tr("This is the communication port used for the TCP connection."));
29 
30  m_host = new QLineEdit(this);
31  m_host->setText("127.0.0.1");
32  m_host->setWhatsThis(
33  tr("This is the IP address of the computer the OSC-compatible software is "
34  "located on. You can use 127.0.0.1 if the software runs on the same machine "
35  "than score."));
36 
37  layout->addRow(tr("Port"), m_remotePort);
38  layout->addRow(tr("Host"), m_host);
39  }
40 
41  ossia::net::tcp_configuration settings() const noexcept
42  {
43  ossia::net::tcp_configuration conf;
44  conf.port = m_remotePort->value();
45  conf.host = m_host->text().toStdString();
46  return conf;
47  }
48 
49  void setSettings(const ossia::net::tcp_configuration& conf)
50  {
51  m_remotePort->setValue(conf.port);
52  m_host->setText(QString::fromStdString(conf.host));
53  }
54 
55 private:
56  QSpinBox* m_remotePort{};
57  QLineEdit* m_host{};
58 };
59 
60 class TCPWidget : public QWidget
61 {
62 public:
63  TCPWidget(Device::ProtocolSettingsWidget& proto, QWidget* parent)
64  : QWidget{parent}
65  {
66  auto layout = new QFormLayout{this};
67  layout->setContentsMargins(0, 0, 0, 0);
68 
69  m_remotePort = new QSpinBox(this);
70  m_remotePort->setRange(0, 65535);
71  m_remotePort->setValue(9996);
72  m_remotePort->setWhatsThis(
73  tr("This is the communication port used for the TCP connection."));
74 
75  m_host = new QLineEdit(this);
76  m_host->setText("127.0.0.1");
77  m_host->setWhatsThis(
78  tr("This is the IP address of the computer the OSC-compatible software is "
79  "located on. You can use 127.0.0.1 if the software runs on the same machine "
80  "than score."));
81 
82  m_framing = new QComboBox{this};
83  m_framing->addItems({"Size prefixing", "SLIP"});
84  m_framing->setCurrentIndex(1);
85 
86  layout->addRow(tr("Port"), m_remotePort);
87  layout->addRow(tr("Host"), m_host);
88  layout->addRow(tr("Framing"), m_framing);
89  }
90 
91  framing_type framing() const noexcept
92  {
93  return (framing_type)m_framing->currentIndex();
94  }
95 
96  ossia::net::tcp_configuration settings() const noexcept
97  {
98  ossia::net::tcp_configuration conf;
99  conf.port = m_remotePort->value();
100  conf.host = m_host->text().toStdString();
101  return conf;
102  }
103 
104  void setSettings(
105  const ossia::net::osc_protocol_configuration& c,
106  const ossia::net::tcp_configuration& conf)
107  {
108  m_remotePort->setValue(conf.port);
109  m_framing->setCurrentIndex(c.framing);
110  m_host->setText(QString::fromStdString(conf.host));
111  }
112 
113 private:
114  QSpinBox* m_remotePort{};
115  QComboBox* m_framing{};
116  QLineEdit* m_host{};
117 };
118 }
Definition: ProtocolSettingsWidget.hpp:22
Definition: TCPWidget.hpp:16
Definition: TCPWidget.hpp:61