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