#124 SASL configuration. Client implementation not finished.

master
Tomatix 2 years ago
parent 1bb74bf12c
commit 8bae52c9e4
  1. 14
      IConfig/AddServer.cpp
  2. 2
      IConfig/AddServer.h
  3. 29
      IConfig/AddServer.ui
  4. 25
      IConfig/IConfigServers.cpp
  5. 2
      IConfig/IConfigServers.h
  6. 34
      IConfig/IConfigServers.ui
  7. 5
      IConfig/ServerItem.cpp
  8. 4
      IConfig/ServerItem.h
  9. 27
      IConfig/ServerModel.cpp
  10. 8
      IConfig/ServerModel.h
  11. 31
      IConfig/ServerOptionsDelegate.cpp

@ -51,6 +51,11 @@ QString AddServer::password() const
return ui->edPassword->text();
}
QString AddServer::sasl() const
{
return ui->edSASL->text();
}
bool AddServer::ssl() const
{
return ui->chkSSL->isChecked();
@ -81,4 +86,13 @@ void AddServer::on_btnSave_clicked()
void AddServer::on_rdNetwork_toggled(bool checked)
{
ui->edNetwork->setEnabled(!checked);
// Network servers (child servers) uses their parent server's SASL.
// The individual child servers will not have own SASL credentials.
ui->edSASL->setEnabled(!checked && ui->edNetwork->currentIndex() == 0 || checked);
}
void AddServer::on_edNetwork_currentIndexChanged(int index)
{
ui->edSASL->setEnabled(index == 0);
}

@ -25,6 +25,7 @@ public:
QString name() const;
QString address() const;
QString password() const;
QString sasl() const;
bool ssl() const;
bool isServer() const;
int networkIndex() const;
@ -36,6 +37,7 @@ private slots:
void on_btnCancel_clicked();
void on_btnSave_clicked();
void on_rdNetwork_toggled(bool checked);
void on_edNetwork_currentIndexChanged(int index);
private:
Ui::AddServer *ui;

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>365</width>
<height>162</height>
<width>400</width>
<height>200</height>
</rect>
</property>
<property name="windowTitle">
@ -102,7 +102,29 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="edPassword"/>
<widget class="QLineEdit" name="edPassword">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>SASL credential</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="edSASL">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
@ -150,6 +172,7 @@
<tabstop>edAddress</tabstop>
<tabstop>chkSSL</tabstop>
<tabstop>edPassword</tabstop>
<tabstop>edSASL</tabstop>
<tabstop>btnCancel</tabstop>
<tabstop>btnSave</tabstop>
</tabstops>

@ -26,6 +26,7 @@ IConfigServers::IConfigServers(QWidget *parent) :
cf_AltNickame = conf.connection("AltNickname");
cf_Server = conf.connection("Server");
cf_Password = conf.connection("Password");
cf_SASL = conf.connection("SASL");
cf_SSL = conf.connection("SSL").toInt();
ui->edRealName->setText(cf_Realname);
@ -34,25 +35,29 @@ IConfigServers::IConfigServers(QWidget *parent) :
ui->edAltNickname->setText(cf_AltNickame);
ui->edServer->setText(cf_Server);
ui->edServerPassword->setText(cf_Password);
ui->edSASL->setText(cf_SASL);
ui->chkSSL->setChecked(cf_SSL);
ui->servers->setModel(&smodel);
ui->servers->setItemDelegateForColumn(2, &m_serverOptionsDelegate);
ui->servers->setItemDelegateForColumn(3, &m_serverOptionsDelegate);
ui->servers->setItemDelegateForColumn(4, &m_serverOptionsDelegate);
for (const auto& index : smodel.getEditorColumns()) {
ui->servers->openPersistentEditor(index);
}
connect(&smodel, &ServerModel::newEntry,
[this](const QModelIndex& sslIdx, const QModelIndex& passwordIdx) {
[this](const QModelIndex& sslIdx, const QModelIndex& passwordIdx, const QModelIndex& saslIdx) {
ui->servers->openPersistentEditor(sslIdx);
ui->servers->openPersistentEditor(passwordIdx);
ui->servers->openPersistentEditor(saslIdx);
serversModified = true;
});
ui->servers->setColumnWidth(2, 50); // SSL column
ui->servers->setColumnWidth(3, 100); // Password column
ui->servers->setColumnWidth(4, 50); // SASL column
}
IConfigServers::~IConfigServers()
@ -68,6 +73,7 @@ bool IConfigServers::isChanged() const
|| cf_AltNickame != ui->edAltNickname->text()
|| cf_Server != ui->edServer->text()
|| cf_Password != ui->edServerPassword->text()
|| cf_SASL != ui->edSASL->text()
|| cf_SSL != ui->chkSSL->isChecked()
|| serversModified;
}
@ -91,6 +97,7 @@ void IConfigServers::save()
conf.setConnection("AltNickname", ui->edAltNickname->text());
conf.setConnection("Server", ui->edServer->text());
conf.setConnection("Password", ui->edServerPassword->text());
conf.setConnection("SASL", ui->edSASL->text());
conf.setConnection("SSL", QString::number(ui->chkSSL->isChecked()));
cf_Realname = conf.connection("Realname");
@ -99,6 +106,7 @@ void IConfigServers::save()
cf_AltNickame = conf.connection("AltNickname");
cf_Server = conf.connection("Server");
cf_Password = conf.connection("Password");
cf_SASL = conf.connection("SASL");
cf_SSL = conf.connection("SSL").toInt();
if (!smodel.saveToFile())
@ -115,6 +123,7 @@ void IConfigServers::reset()
ui->edAltNickname->setText(cf_AltNickame);
ui->edServer->setText(cf_Server);
ui->edServerPassword->setText(cf_Password);
ui->edSASL->setText(cf_SASL);
if (serversModified) {
smodel.reloadModel();
@ -130,6 +139,11 @@ void IConfigServers::on_btnShowPassword_toggled(bool checked)
ui->edServerPassword->setEchoMode(checked ? QLineEdit::Normal : QLineEdit::Password);
}
void IConfigServers::on_btnShowSASL_toggled(bool checked)
{
ui->edSASL->setEchoMode(checked ? QLineEdit::Normal : QLineEdit::Password);
}
void IConfigServers::on_servers_clicked(const QModelIndex& index)
{
auto* item = static_cast<const ServerItem*>(index.internalPointer());
@ -137,6 +151,11 @@ void IConfigServers::on_servers_clicked(const QModelIndex& index)
ui->edServer->setText( item->address() );
ui->edServerPassword->setText( item->password() );
ui->chkSSL->setChecked( item->ssl() );
if (item->parent())
ui->edSASL->setText(item->parent()->sasl());
else
ui->edSASL->setText(item->sasl());
}
void IConfigServers::on_btnAddServer_clicked()
@ -153,9 +172,9 @@ void IConfigServers::on_btnAddServer_clicked()
connect(addServerDlg, &AddServer::saved,
[this] {
if (addServerDlg->isServer())
smodel.addServer(addServerDlg->name(), addServerDlg->address(), addServerDlg->password(), addServerDlg->ssl(), addServerDlg->networkIndex());
smodel.addServer(addServerDlg->name(), addServerDlg->address(), addServerDlg->password(), addServerDlg->sasl(), addServerDlg->ssl(), addServerDlg->networkIndex());
else
smodel.addNetwork(addServerDlg->name(), addServerDlg->address(), addServerDlg->password(), addServerDlg->ssl());
smodel.addNetwork(addServerDlg->name(), addServerDlg->address(), addServerDlg->password(), addServerDlg->sasl(), addServerDlg->ssl());
});
}
}

@ -33,6 +33,7 @@ public:
private slots:
void on_btnShowPassword_toggled(bool checked);
void on_btnShowSASL_toggled(bool checked);
void on_servers_clicked(const QModelIndex& index);
void on_btnAddServer_clicked();
void on_btnDeleteSelected_clicked();
@ -48,6 +49,7 @@ private:
QString cf_AltNickame;
QString cf_Server;
QString cf_Password;
QString cf_SASL;
bool cf_SSL;
bool serversModified{ false };
};

@ -159,6 +159,40 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QLabel" name="label_7">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>SASL credentials</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="edSASL">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnShowSASL">
<property name="text">
<string>Show</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="chkSSL">
<property name="text">

@ -40,6 +40,11 @@ QString ServerItem::password() const
return m_data[Key::Password].toString();
}
QString ServerItem::sasl() const
{
return m_data[Key::SASL].toString();
}
bool ServerItem::ssl() const
{
return m_data[Key::SSL].toBool();

@ -20,6 +20,7 @@ constexpr auto Name = "Name";
constexpr auto Host = "Host";
constexpr auto Port = "Port";
constexpr auto Password = "Password";
constexpr auto SASL = "SASL";
constexpr auto SSL = "SSL";
}
@ -49,6 +50,9 @@ public:
QString password() const;
void setPassword(const QString& password) { m_data[ServerJsonKey::Password] = password; }
QString sasl() const;
void setSasl(const QString& credentials) { m_data[ServerJsonKey::SASL] = credentials; }
bool ssl() const;
void setSsl(bool enable) { m_data[ServerJsonKey::SSL] = enable; }

@ -15,7 +15,7 @@
#include <QFile>
namespace {
QJsonObject createJsonObject(const QString& name, const QString& address, const QString& password, bool isSsl)
QJsonObject createJsonObject(const QString& name, const QString& address, const QString& password, const QString& sasl, bool isSsl)
{
namespace Key = ServerJsonKey;
@ -36,6 +36,9 @@ QJsonObject createJsonObject(const QString& name, const QString& address, const
obj[Key::SSL] = isSsl;
obj[Key::Password] = password;
if (!sasl.isEmpty())
obj[Key::SASL] = sasl;
return obj;
}
}
@ -55,16 +58,16 @@ bool ServerModel::saveToFile()
if (item.isNetwork()) {
QJsonArray networkServers;
for (auto& child : item.children()) {
QJsonObject server{ createJsonObject(child.name(), child.address(), child.password(), child.ssl()) };
QJsonObject server{ createJsonObject(child.name(), child.address(), child.password(), "", child.ssl()) };
networkServers << server;
}
QJsonObject network{ createJsonObject(item.name(), item.address(), item.password(), item.ssl()) };
QJsonObject network{ createJsonObject(item.name(), item.address(), item.password(), item.sasl(), item.ssl()) };
network[Key::Servers] = networkServers;
networks << network;
}
else {
QJsonObject server{ createJsonObject(item.name(), item.address(), item.password(), item.ssl()) };
QJsonObject server{ createJsonObject(item.name(), item.address(), item.password(), item.sasl(), item.ssl()) };
servers << server;
}
}
@ -151,6 +154,7 @@ QVariant ServerModel::headerData(int section, Qt::Orientation orientation, int r
tr("Name"),
tr("Address"),
"",
"",
""
};
@ -230,7 +234,7 @@ QModelIndex ServerModel::parent(const QModelIndex& index) const
return createIndex(parentItem->row(), 0, parentItem);
}
void ServerModel::addServer(const QString& name, const QString& address, const QString& password, bool isSsl, int networkIdx)
void ServerModel::addServer(const QString& name, const QString& address, const QString& password, const QString& sasl, bool isSsl, int networkIdx)
{
QList<ServerItem>* items{};
ServerItem* parentNetworkItem{};
@ -258,14 +262,15 @@ void ServerModel::addServer(const QString& name, const QString& address, const Q
}
}
const auto obj{ createJsonObject(name, address, password, isSsl) };
const auto obj{ createJsonObject(name, address, password, sasl, isSsl) };
beginInsertRows(modelIdx, pos, pos);
items->insert(pos, ServerItem(obj, pos, parentNetworkItem, false));
endInsertRows();
emit newEntry(
createIndex(pos, 2, &((*items)[pos])), // SSL
createIndex(pos, 3, &((*items)[pos])) // Password
createIndex(pos, 3, &((*items)[pos])), // Password
createIndex(pos, 4, &((*items)[pos])) // SASL
);
/*
@ -288,9 +293,9 @@ void ServerModel::addServer(const QString& name, const QString& address, const Q
});
}
void ServerModel::addNetwork(const QString& name, const QString& address, const QString& password, bool isSsl)
void ServerModel::addNetwork(const QString& name, const QString& address, const QString& password, const QString& sasl, bool isSsl)
{
const auto obj{ createJsonObject(name, address, password, isSsl) };
const auto obj{ createJsonObject(name, address, password, sasl, isSsl) };
const auto idx{ m_items.count() };
beginInsertRows(QModelIndex{}, idx, idx);
@ -299,7 +304,8 @@ void ServerModel::addNetwork(const QString& name, const QString& address, const
emit newEntry(
createIndex(idx, 2, &(m_items.back())), // SSL
createIndex(idx, 3, &(m_items.back())) // Password
createIndex(idx, 3, &(m_items.back())), // Password
createIndex(idx, 4, &(m_items.back())) // SASL
);
}
@ -342,6 +348,7 @@ QList<QModelIndex> ServerModel::getEditorColumns()
for (auto& topItem : m_items) {
indexList << createIndex(topItem.row(), 2, &topItem);
indexList << createIndex(topItem.row(), 3, &topItem);
indexList << createIndex(topItem.row(), 4, &topItem);
if (topItem.isNetwork()) {
auto& items = topItem.children();

@ -40,17 +40,17 @@ public:
int rowCount(const QModelIndex& parent = {}) const override;
int columnCount(const QModelIndex& parent = {}) const override
{
return 4;
return 5;
};
QModelIndex index(int row, int column, const QModelIndex& parent = {}) const override;
QModelIndex parent(const QModelIndex& index) const override;
/// Add a server to the model. networkIdx = -1 means server is not part of a network.
void addServer(const QString& name, const QString& address, const QString& password, bool isSsl, int networkIdx);
void addServer(const QString& name, const QString& address, const QString& password, const QString& sasl, bool isSsl, int networkIdx);
/// Add a network to the model.
void addNetwork(const QString& name, const QString& address, const QString& password, bool isSsl);
void addNetwork(const QString& name, const QString& address, const QString& password, const QString& sasl, bool isSsl);
void deleteEntry(const QModelIndex& index);
@ -59,7 +59,7 @@ public:
QList<QModelIndex> getEditorColumns();
signals:
void newEntry(const QModelIndex& sslIdx, const QModelIndex& passwordIdx);
void newEntry(const QModelIndex& sslIdx, const QModelIndex& passwordIdx, const QModelIndex& saslIdx);
private:
QModelIndex networkIndex(int row, int col = 0);

@ -25,16 +25,18 @@ QWidget* ServerOptionsDelegate::createEditor(QWidget* parent, const QStyleOption
btn->setCheckable(true);
return btn;
}
else if (index.column() == 3) {
auto* btn = new QPushButton(tr("Password"), parent);
auto* item = static_cast<ServerItem*>(index.internalPointer());
auto* btn = new QPushButton(tr("Password"), parent);
connect(btn, &QPushButton::pressed,
[item, parent] {
auto password = QInputDialog::getText(
parent,
tr("Enter password"),
tr("New password for %1:").arg(item->name()),
QLineEdit::Password
tr("Password for %1:").arg(item->name()),
QLineEdit::Password,
item->password()
);
item->setPassword(password);
@ -42,6 +44,29 @@ QWidget* ServerOptionsDelegate::createEditor(QWidget* parent, const QStyleOption
return btn;
}
else if (index.column() == 4) {
auto* item = static_cast<ServerItem*>(index.internalPointer());
if (item->parent()) // Only items with a parent are network servers / child servers. No SASL for them.
return nullptr;
auto* btn = new QPushButton(tr("SASL"), parent);
connect(btn, &QPushButton::pressed,
[item, parent] {
auto password = QInputDialog::getText(
parent,
tr("SASL credentials"),
tr("SASL credentials for %1:").arg(item->name()),
QLineEdit::Password,
item->sasl()
);
item->setSasl(password);
});
return btn;
}
else {
return nullptr;
}

Loading…
Cancel
Save