mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2026-06-09 17:35:39 -04:00
Add network interface selection combo box widget to message_aggregator
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <QtWidgets>
|
||||
#include <QDateTime>
|
||||
#include <QNetworkInterface>
|
||||
#include <QSet>
|
||||
|
||||
#include "DecodesModel.hpp"
|
||||
#include "BeaconsModel.hpp"
|
||||
@@ -37,8 +39,10 @@ MessageAggregatorMainWindow::MessageAggregatorMainWindow ()
|
||||
, decodes_model_ {new DecodesModel {this}}
|
||||
, beacons_model_ {new BeaconsModel {this}}
|
||||
, server_ {new MessageServer {this}}
|
||||
, multicast_group_line_edit_ {new QLineEdit}
|
||||
, log_table_view_ {new QTableView}
|
||||
, port_spin_box_ {new QSpinBox {this}}
|
||||
, multicast_group_line_edit_ {new QLineEdit {this}}
|
||||
, network_interfaces_combo_box_ {new CheckableItemComboBox {this}}
|
||||
, log_table_view_ {new QTableView {this}}
|
||||
, add_call_of_interest_action_ {new QAction {tr ("&Add callsign"), this}}
|
||||
, delete_call_of_interest_action_ {new QAction {tr ("&Delete callsign"), this}}
|
||||
, last_call_of_interest_action_ {new QAction {tr ("&Highlight last only"), this}}
|
||||
@@ -68,16 +72,66 @@ MessageAggregatorMainWindow::MessageAggregatorMainWindow ()
|
||||
auto central_layout = new QVBoxLayout;
|
||||
|
||||
// server details
|
||||
auto port_spin_box = new QSpinBox;
|
||||
port_spin_box->setMinimum (1);
|
||||
port_spin_box->setMaximum (std::numeric_limits<port_type>::max ());
|
||||
port_spin_box_->setMinimum (1);
|
||||
port_spin_box_->setMaximum (std::numeric_limits<port_type>::max ());
|
||||
auto group_box_layout = new QFormLayout;
|
||||
group_box_layout->addRow (tr ("Port number:"), port_spin_box);
|
||||
group_box_layout->addRow (tr ("Port number:"), port_spin_box_);
|
||||
group_box_layout->addRow (tr ("Multicast Group (blank for unicast server):"), multicast_group_line_edit_);
|
||||
group_box_layout->addRow (tr ("Network interfaces:"), network_interfaces_combo_box_);
|
||||
int row;
|
||||
QFormLayout::ItemRole role;
|
||||
group_box_layout->getWidgetPosition (network_interfaces_combo_box_, &row, &role);
|
||||
Q_ASSERT (row >= 0);
|
||||
network_interfaces_form_label_widget_ = static_cast<QLabel *> (group_box_layout->itemAt (row, QFormLayout::LabelRole)->widget ());
|
||||
network_interfaces_form_label_widget_->hide ();
|
||||
network_interfaces_form_label_widget_->buddy ()->hide ();
|
||||
connect (multicast_group_line_edit_, &QLineEdit::editingFinished, [this] {
|
||||
if (multicast_group_line_edit_->text ().size ())
|
||||
{
|
||||
network_interfaces_form_label_widget_->show ();
|
||||
network_interfaces_form_label_widget_->buddy ()->show ();
|
||||
}
|
||||
else
|
||||
{
|
||||
network_interfaces_form_label_widget_->hide ();
|
||||
network_interfaces_form_label_widget_->buddy ()->hide ();
|
||||
}
|
||||
});
|
||||
auto group_box = new QGroupBox {tr ("Server Details")};
|
||||
group_box->setLayout (group_box_layout);
|
||||
central_layout->addWidget (group_box);
|
||||
|
||||
// populate network interface list
|
||||
for (auto const& net_if : QNetworkInterface::allInterfaces ())
|
||||
{
|
||||
auto flags = QNetworkInterface::IsRunning | QNetworkInterface::CanMulticast;
|
||||
if ((net_if.flags () & flags) == flags)
|
||||
{
|
||||
auto is_loopback = net_if.flags () & QNetworkInterface::IsLoopBack;
|
||||
auto item = network_interfaces_combo_box_->addCheckItem (net_if.humanReadableName ()
|
||||
, net_if.name ()
|
||||
, is_loopback ? Qt::Checked : Qt::Unchecked);
|
||||
item->setEnabled (!is_loopback);
|
||||
auto tip = QString {"name(index): %1(%2) - %3"}.arg (net_if.name ()).arg (net_if.index ())
|
||||
.arg (net_if.flags () & QNetworkInterface::IsUp ? "Up" : "Down");
|
||||
auto hw_addr = net_if.hardwareAddress ();
|
||||
if (hw_addr.size ())
|
||||
{
|
||||
tip += QString {"\nhw: %1"}.arg (net_if.hardwareAddress ());
|
||||
}
|
||||
auto aes = net_if.addressEntries ();
|
||||
if (aes.size ())
|
||||
{
|
||||
tip += "\naddresses:";
|
||||
for (auto const& ae : aes)
|
||||
{
|
||||
tip += QString {"\n ip: %1/%2"}.arg (ae.ip ().toString ()).arg (ae.prefixLength ());
|
||||
}
|
||||
}
|
||||
item->setToolTip (tip);
|
||||
}
|
||||
}
|
||||
|
||||
log_table_view_->setModel (log_);
|
||||
log_table_view_->verticalHeader ()->hide ();
|
||||
central_layout->addWidget (log_table_view_);
|
||||
@@ -200,16 +254,34 @@ MessageAggregatorMainWindow::MessageAggregatorMainWindow ()
|
||||
connect (decodes_model_, &DecodesModel::reply, server_, &MessageServer::reply);
|
||||
|
||||
// UI behaviour
|
||||
connect (port_spin_box, static_cast<void (QSpinBox::*)(int)> (&QSpinBox::valueChanged)
|
||||
, [this] (port_type port) {server_->start (port);});
|
||||
connect (multicast_group_line_edit_, &QLineEdit::editingFinished, [this, port_spin_box] () {
|
||||
server_->start (port_spin_box->value (), QHostAddress {multicast_group_line_edit_->text ()});
|
||||
});
|
||||
connect (port_spin_box_, static_cast<void (QSpinBox::*)(int)> (&QSpinBox::valueChanged)
|
||||
, [this] (int /*port*/) {restart_server ();});
|
||||
connect (multicast_group_line_edit_, &QLineEdit::editingFinished, [this] () {restart_server ();});
|
||||
connect (network_interfaces_combo_box_, &QComboBox::currentTextChanged, [this] () {restart_server ();});
|
||||
|
||||
port_spin_box->setValue (2237); // start up in unicast mode
|
||||
port_spin_box_->setValue (2237); // start up in unicast mode
|
||||
show ();
|
||||
}
|
||||
|
||||
void MessageAggregatorMainWindow::restart_server ()
|
||||
{
|
||||
QSet<QString> net_ifs;
|
||||
if (network_interfaces_combo_box_->isVisible ())
|
||||
{
|
||||
auto model = static_cast<QStandardItemModel *> (network_interfaces_combo_box_->model ());
|
||||
for (int row = 0; row < model->rowCount (); ++row)
|
||||
{
|
||||
if (Qt::Checked == model->item (row)->checkState ())
|
||||
{
|
||||
net_ifs << model->item (row)->data ().toString ();
|
||||
}
|
||||
}
|
||||
}
|
||||
server_->start (port_spin_box_->value ()
|
||||
, QHostAddress {multicast_group_line_edit_->text ()}
|
||||
, net_ifs);
|
||||
}
|
||||
|
||||
void MessageAggregatorMainWindow::log_qso (ClientKey const& /*key*/, QDateTime time_off
|
||||
, QString const& dx_call
|
||||
, QString const& dx_grid, Frequency dial_frequency, QString const& mode
|
||||
|
||||
Reference in New Issue
Block a user