2021-02-14 18:32:58 +00:00
|
|
|
#include "udpserversetup.h"
|
|
|
|
#include "ui_udpserversetup.h"
|
2021-02-23 21:21:22 +00:00
|
|
|
#include "logcategories.h"
|
2021-02-14 18:32:58 +00:00
|
|
|
|
2021-06-10 19:30:42 +00:00
|
|
|
extern void passcode(QString in,QByteArray& out);
|
|
|
|
|
2021-02-14 18:32:58 +00:00
|
|
|
udpServerSetup::udpServerSetup(QWidget* parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::udpServerSetup)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2021-06-10 19:30:42 +00:00
|
|
|
addUserLine("", "", 0); // Create a blank row if we never receive config.
|
|
|
|
|
2021-02-16 16:16:46 +00:00
|
|
|
// Get any stored config information from the main form.
|
|
|
|
SERVERCONFIG config;
|
|
|
|
emit serverConfig(config,false); // Just send blank server config.
|
2021-02-14 18:32:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
udpServerSetup::~udpServerSetup()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
2021-02-16 16:16:46 +00:00
|
|
|
|
|
|
|
// Slot to receive config.
|
|
|
|
void udpServerSetup::receiveServerConfig(SERVERCONFIG conf)
|
|
|
|
{
|
2021-05-15 17:53:16 +00:00
|
|
|
qInfo() << "Getting server config";
|
2021-02-16 16:16:46 +00:00
|
|
|
|
|
|
|
ui->enableCheckbox->setChecked(conf.enabled);
|
|
|
|
ui->controlPortText->setText(QString::number(conf.controlPort));
|
|
|
|
ui->civPortText->setText(QString::number(conf.civPort));
|
|
|
|
ui->audioPortText->setText(QString::number(conf.audioPort));
|
|
|
|
|
|
|
|
int row = 0;
|
2021-02-22 00:24:48 +00:00
|
|
|
|
2021-06-10 19:30:42 +00:00
|
|
|
for (int i = 0; i < ui->usersTable->rowCount(); i++)
|
|
|
|
{
|
|
|
|
ui->usersTable->removeRow(i);
|
|
|
|
}
|
|
|
|
|
2021-02-16 16:16:46 +00:00
|
|
|
foreach (SERVERUSER user, conf.users)
|
|
|
|
{
|
2021-02-22 00:24:48 +00:00
|
|
|
if (user.username != "" && user.password != "")
|
|
|
|
{
|
2021-06-10 19:30:42 +00:00
|
|
|
addUserLine(user.username, user.password, user.userType);
|
2021-02-22 00:24:48 +00:00
|
|
|
row++;
|
2021-02-16 16:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-22 00:24:48 +00:00
|
|
|
|
2021-06-10 19:30:42 +00:00
|
|
|
if (row == 0) {
|
|
|
|
addUserLine("", "", 0);
|
2021-05-04 14:55:50 +00:00
|
|
|
}
|
2021-02-16 16:16:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void udpServerSetup::accept()
|
|
|
|
{
|
2021-05-15 17:53:16 +00:00
|
|
|
qInfo() << "Server config stored";
|
2021-02-16 16:16:46 +00:00
|
|
|
SERVERCONFIG config;
|
|
|
|
config.enabled = ui->enableCheckbox->isChecked();
|
|
|
|
config.controlPort = ui->controlPortText->text().toInt();
|
|
|
|
config.civPort = ui->civPortText->text().toInt();
|
|
|
|
config.audioPort = ui->audioPortText->text().toInt();
|
|
|
|
|
|
|
|
config.users.clear();
|
|
|
|
|
|
|
|
for (int row = 0; row < ui->usersTable->model()->rowCount(); row++)
|
|
|
|
{
|
2021-06-10 19:30:42 +00:00
|
|
|
if (ui->usersTable->item(row, 0) != NULL)
|
2021-02-16 20:55:30 +00:00
|
|
|
{
|
|
|
|
SERVERUSER user;
|
|
|
|
user.username = ui->usersTable->item(row, 0)->text();
|
2021-06-10 19:30:42 +00:00
|
|
|
QLineEdit* password = (QLineEdit*)ui->usersTable->cellWidget(row, 1);
|
|
|
|
user.password = password->text();
|
2021-02-22 00:24:48 +00:00
|
|
|
QComboBox* comboBox = (QComboBox*)ui->usersTable->cellWidget(row, 2);
|
|
|
|
user.userType = comboBox->currentIndex();
|
2021-02-16 20:55:30 +00:00
|
|
|
config.users.append(user);
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui->usersTable->removeRow(row);
|
|
|
|
}
|
2021-02-16 16:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
emit serverConfig(config,true);
|
|
|
|
this->hide();
|
|
|
|
}
|
2021-02-16 20:55:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
void udpServerSetup::on_usersTable_cellClicked(int row, int col)
|
|
|
|
{
|
2021-05-15 17:53:16 +00:00
|
|
|
qInfo() << "Clicked on " << row << "," << col;
|
2021-06-10 19:30:42 +00:00
|
|
|
if (row == ui->usersTable->model()->rowCount() - 1 && ui->usersTable->item(row, 0) != NULL) {
|
2021-06-10 21:32:53 +00:00
|
|
|
addUserLine("", "", 0);
|
2021-02-16 20:55:30 +00:00
|
|
|
}
|
2021-06-10 19:30:42 +00:00
|
|
|
}
|
2021-02-16 20:55:30 +00:00
|
|
|
|
2021-06-10 19:30:42 +00:00
|
|
|
void udpServerSetup::onPasswordChanged()
|
|
|
|
{
|
|
|
|
int row = sender()->property("row").toInt();
|
|
|
|
QLineEdit* password = (QLineEdit*)ui->usersTable->cellWidget(row, 1);
|
|
|
|
QByteArray pass;
|
|
|
|
passcode(password->text(), pass);
|
|
|
|
password->setText(pass);
|
|
|
|
qInfo() << "password row" << row << "changed";
|
|
|
|
}
|
|
|
|
|
|
|
|
void udpServerSetup::addUserLine(const QString& user, const QString& pass, const int& type)
|
|
|
|
{
|
|
|
|
ui->usersTable->insertRow(ui->usersTable->rowCount());
|
|
|
|
ui->usersTable->setItem(ui->usersTable->rowCount() - 1, 0, new QTableWidgetItem(user));
|
|
|
|
ui->usersTable->setItem(ui->usersTable->rowCount() - 1, 1, new QTableWidgetItem());
|
|
|
|
ui->usersTable->setItem(ui->usersTable->rowCount() - 1, 2, new QTableWidgetItem());
|
|
|
|
|
|
|
|
QLineEdit* password = new QLineEdit();
|
|
|
|
password->setProperty("row", (int)ui->usersTable->rowCount() - 1);
|
|
|
|
password->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
|
|
|
password->setText(pass);
|
|
|
|
connect(password, SIGNAL(editingFinished()), this, SLOT(onPasswordChanged()));
|
|
|
|
ui->usersTable->setCellWidget(ui->usersTable->rowCount() - 1, 1, password);
|
|
|
|
|
|
|
|
QComboBox* comboBox = new QComboBox();
|
|
|
|
comboBox->insertItems(0, { "Full User","Full with no TX","Monitor only" });
|
|
|
|
comboBox->setCurrentIndex(type);
|
|
|
|
ui->usersTable->setCellWidget(ui->usersTable->rowCount() - 1, 2, comboBox);
|
|
|
|
|
2021-06-10 21:32:53 +00:00
|
|
|
}
|