kopia lustrzana https://gitlab.com/eliggett/wfview
Lots of fixes to server setup table
rodzic
73dec8ce40
commit
dc46913c3f
|
@ -313,9 +313,9 @@ void udpServer::controlReceived()
|
|||
{
|
||||
QByteArray usercomp;
|
||||
passcode(user.username, usercomp);
|
||||
QByteArray passcomp;
|
||||
passcode(user.password, passcomp);
|
||||
if (!strcmp(in->username, usercomp.constData()) && !strcmp(in->password, passcomp.constData()))
|
||||
//QByteArray passcomp;
|
||||
//passcode(user.password, passcomp);
|
||||
if (!strcmp(in->username, usercomp.constData()) && !strcmp(in->password, (const char *)user.password.constData()))
|
||||
{
|
||||
current->isAuthenticated = true;
|
||||
current->user = user;
|
||||
|
|
|
@ -2,11 +2,15 @@
|
|||
#include "ui_udpserversetup.h"
|
||||
#include "logcategories.h"
|
||||
|
||||
extern void passcode(QString in,QByteArray& out);
|
||||
|
||||
udpServerSetup::udpServerSetup(QWidget* parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::udpServerSetup)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
addUserLine("", "", 0); // Create a blank row if we never receive config.
|
||||
|
||||
// Get any stored config information from the main form.
|
||||
SERVERCONFIG config;
|
||||
emit serverConfig(config,false); // Just send blank server config.
|
||||
|
@ -29,43 +33,22 @@ void udpServerSetup::receiveServerConfig(SERVERCONFIG conf)
|
|||
|
||||
int row = 0;
|
||||
|
||||
for (int i = 0; i < ui->usersTable->rowCount(); i++)
|
||||
{
|
||||
ui->usersTable->removeRow(i);
|
||||
}
|
||||
|
||||
foreach (SERVERUSER user, conf.users)
|
||||
{
|
||||
if (user.username != "" && user.password != "")
|
||||
{
|
||||
if (ui->usersTable->rowCount() <= row) {
|
||||
ui->usersTable->insertRow(ui->usersTable->rowCount());
|
||||
}
|
||||
ui->usersTable->setItem(row, 0, new QTableWidgetItem(user.username));
|
||||
ui->usersTable->setItem(row, 1, new QTableWidgetItem(user.password));
|
||||
QComboBox* comboBox = new QComboBox();
|
||||
comboBox->insertItems(0, { "Full User","Full with no TX","Monitor only" });
|
||||
comboBox->setCurrentIndex(user.userType);
|
||||
ui->usersTable->setCellWidget(row, 2, comboBox);
|
||||
addUserLine(user.username, user.password, user.userType);
|
||||
row++;
|
||||
}
|
||||
}
|
||||
// Delete any rows no longer needed
|
||||
int count=0;
|
||||
|
||||
for (count = row; count <= ui->usersTable->rowCount(); count++)
|
||||
{
|
||||
if (count == conf.users.count()) {
|
||||
ui->usersTable->insertRow(ui->usersTable->rowCount());
|
||||
QComboBox* comboBox = new QComboBox();
|
||||
comboBox->insertItems(0, { "Full User","Full with no TX","Monitor only" });
|
||||
ui->usersTable->setCellWidget(count, 2, comboBox);
|
||||
}
|
||||
else if (count > conf.users.count()) {
|
||||
ui->usersTable->removeRow(count);
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
ui->usersTable->insertRow(ui->usersTable->rowCount());
|
||||
QComboBox* comboBox = new QComboBox();
|
||||
comboBox->insertItems(0, { "Full User","Full with no TX","Monitor only" });
|
||||
ui->usersTable->setCellWidget(count, 2, comboBox);
|
||||
if (row == 0) {
|
||||
addUserLine("", "", 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -83,11 +66,12 @@ void udpServerSetup::accept()
|
|||
|
||||
for (int row = 0; row < ui->usersTable->model()->rowCount(); row++)
|
||||
{
|
||||
if (ui->usersTable->item(row, 0) != NULL && ui->usersTable->item(row, 1) != NULL)
|
||||
if (ui->usersTable->item(row, 0) != NULL)
|
||||
{
|
||||
SERVERUSER user;
|
||||
user.username = ui->usersTable->item(row, 0)->text();
|
||||
user.password = ui->usersTable->item(row, 1)->text();
|
||||
QLineEdit* password = (QLineEdit*)ui->usersTable->cellWidget(row, 1);
|
||||
user.password = password->text();
|
||||
QComboBox* comboBox = (QComboBox*)ui->usersTable->cellWidget(row, 2);
|
||||
user.userType = comboBox->currentIndex();
|
||||
config.users.append(user);
|
||||
|
@ -106,13 +90,38 @@ void udpServerSetup::accept()
|
|||
void udpServerSetup::on_usersTable_cellClicked(int row, int col)
|
||||
{
|
||||
qInfo() << "Clicked on " << row << "," << col;
|
||||
if (row == ui->usersTable->model()->rowCount() - 1 && ui->usersTable->item(row, 0) != NULL && ui->usersTable->item(row, 1) != NULL) {
|
||||
ui->usersTable->insertRow(ui->usersTable->rowCount());
|
||||
QComboBox* comboBox = new QComboBox();
|
||||
comboBox->insertItems(0, { "Full User","Full with no TX","Monitor only" });
|
||||
userTypes.append(comboBox);
|
||||
ui->usersTable->setCellWidget(ui->usersTable->rowCount() - 1, 2, comboBox);
|
||||
|
||||
if (row == ui->usersTable->model()->rowCount() - 1 && ui->usersTable->item(row, 0) != NULL) {
|
||||
addUserLine(" ", " ", 0);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
|
@ -42,6 +42,7 @@ public:
|
|||
|
||||
private slots:
|
||||
void on_usersTable_cellClicked(int row, int col);
|
||||
void onPasswordChanged();
|
||||
|
||||
public slots:
|
||||
void receiveServerConfig(SERVERCONFIG conf);
|
||||
|
@ -53,6 +54,7 @@ private:
|
|||
Ui::udpServerSetup* ui;
|
||||
void accept();
|
||||
QList<QComboBox*> userTypes;
|
||||
void addUserLine(const QString &user, const QString &pass, const int &type);
|
||||
};
|
||||
|
||||
#endif // UDPSERVER_H
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>440</width>
|
||||
<height>351</height>
|
||||
<height>361</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
|
Ładowanie…
Reference in New Issue