2019-08-24 20:47:32 +02:00
|
|
|
|
#include "ConnectionConfigurationWidget.h"
|
|
|
|
|
|
#include "SslModeModel.h"
|
|
|
|
|
|
#include "ConnectionConfig.h"
|
|
|
|
|
|
#include "ConnectionController.h"
|
|
|
|
|
|
#include "ConnectionListModel.h"
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
#include <QDataWidgetMapper>
|
|
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
|
#include <QFormLayout>
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
#include <QLineEdit>
|
|
|
|
|
|
#include <QPushButton>
|
|
|
|
|
|
#include <QSpinBox>
|
|
|
|
|
|
#include <QComboBox>
|
|
|
|
|
|
#include <QDialog>
|
|
|
|
|
|
|
|
|
|
|
|
#define SET_OBJECT_NAME(var) var->setObjectName(#var)
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *ctrl, const ConnectionConfig &cfg)
|
|
|
|
|
|
{
|
2019-08-27 20:12:00 +02:00
|
|
|
|
auto w = new ConnectionConfigurationWidget(ctrl->getConnectionTreeModel());
|
2019-08-24 20:47:32 +02:00
|
|
|
|
w->setData(cfg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto btn_hbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
|
|
|
|
|
|
//auto btn_test = btn_hbox->addButton(tr("Test"), QDialogButtonBox::ActionRole);
|
|
|
|
|
|
|
|
|
|
|
|
auto vbox = new QVBoxLayout;
|
|
|
|
|
|
vbox->addWidget(w);
|
|
|
|
|
|
vbox->addWidget(btn_hbox);
|
|
|
|
|
|
|
|
|
|
|
|
auto win = new QDialog;
|
|
|
|
|
|
win->setWindowTitle(tr("Edit connection configuration"));
|
|
|
|
|
|
win->setLayout(vbox);
|
2019-09-01 06:43:28 +02:00
|
|
|
|
win->setAttribute( Qt::WA_DeleteOnClose, true );
|
2019-08-24 20:47:32 +02:00
|
|
|
|
|
|
|
|
|
|
win->connect(btn_hbox, &QDialogButtonBox::accepted, [ctrl, w, win] () {
|
2019-08-27 20:12:00 +02:00
|
|
|
|
auto [grp, cc] = w->data();
|
|
|
|
|
|
ctrl->getConnectionTreeModel()->save(grp, cc);
|
2019-08-24 20:47:32 +02:00
|
|
|
|
win->accept();
|
|
|
|
|
|
});
|
2019-09-01 06:43:28 +02:00
|
|
|
|
win->connect(btn_hbox, &QDialogButtonBox::rejected, [win] ()
|
2019-08-24 20:47:32 +02:00
|
|
|
|
{
|
2019-09-01 06:43:28 +02:00
|
|
|
|
win->reject();
|
2019-08-24 20:47:32 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
win->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-27 20:12:00 +02:00
|
|
|
|
ConnectionConfigurationWidget::ConnectionConfigurationWidget(ConnectionTreeModel *connection_model, QWidget *parent)
|
2019-08-24 20:47:32 +02:00
|
|
|
|
: QWidget(parent)
|
|
|
|
|
|
{
|
2019-08-27 20:12:00 +02:00
|
|
|
|
lblGroup = new QLabel;
|
|
|
|
|
|
cmbbxGroup = new QComboBox;
|
|
|
|
|
|
cmbbxGroup->setModel(connection_model);
|
|
|
|
|
|
cmbbxGroup->setModelColumn(0);
|
|
|
|
|
|
// cmbbxGroup->setEditable(true);
|
|
|
|
|
|
// cmbbxGroup->setInsertPolicy(QComboBox::NoInsert);
|
|
|
|
|
|
lblGroup->setBuddy(cmbbxGroup);
|
|
|
|
|
|
|
2019-08-24 20:47:32 +02:00
|
|
|
|
lblName = new QLabel;
|
|
|
|
|
|
SET_OBJECT_NAME(lblName);
|
|
|
|
|
|
edtName = new QLineEdit ;
|
|
|
|
|
|
SET_OBJECT_NAME(edtName);
|
|
|
|
|
|
lblName->setBuddy(edtName);
|
|
|
|
|
|
|
|
|
|
|
|
lblHost = new QLabel;
|
|
|
|
|
|
SET_OBJECT_NAME(lblHost);
|
|
|
|
|
|
edtHost = new QLineEdit;
|
|
|
|
|
|
SET_OBJECT_NAME(edtHost);
|
|
|
|
|
|
lblHost->setBuddy(edtHost);
|
|
|
|
|
|
|
|
|
|
|
|
lblPort = new QLabel;
|
|
|
|
|
|
SET_OBJECT_NAME(lblPort);
|
|
|
|
|
|
spinPort = new QSpinBox;
|
|
|
|
|
|
SET_OBJECT_NAME(spinPort);
|
|
|
|
|
|
spinPort->setRange(1, std::numeric_limits<uint16_t>::max());
|
|
|
|
|
|
lblPort->setBuddy(spinPort);
|
|
|
|
|
|
|
|
|
|
|
|
lblUser = new QLabel;
|
|
|
|
|
|
SET_OBJECT_NAME(lblUser);
|
|
|
|
|
|
edtUser = new QLineEdit;
|
|
|
|
|
|
SET_OBJECT_NAME(edtUser);
|
|
|
|
|
|
lblUser->setBuddy(edtUser);
|
|
|
|
|
|
|
|
|
|
|
|
lblDbName = new QLabel;
|
|
|
|
|
|
SET_OBJECT_NAME(lblDbName);
|
|
|
|
|
|
edtDbname = new QLineEdit;
|
|
|
|
|
|
SET_OBJECT_NAME(edtDbname);
|
|
|
|
|
|
lblDbName->setBuddy(edtDbname);
|
|
|
|
|
|
|
|
|
|
|
|
lblSsl = new QLabel;
|
|
|
|
|
|
SET_OBJECT_NAME(lblSsl);
|
|
|
|
|
|
cmbbxSsl = new QComboBox;
|
|
|
|
|
|
SET_OBJECT_NAME(cmbbxSsl);
|
|
|
|
|
|
cmbbxSsl->setModelColumn(0);
|
|
|
|
|
|
auto ssl_model = new SslModeModel(this);
|
|
|
|
|
|
cmbbxSsl->setModel(ssl_model);
|
|
|
|
|
|
lblSsl->setBuddy(cmbbxSsl);
|
|
|
|
|
|
|
|
|
|
|
|
lblCert = new QLabel;
|
|
|
|
|
|
SET_OBJECT_NAME(lblCert);
|
|
|
|
|
|
edtCert = new QLineEdit;
|
|
|
|
|
|
SET_OBJECT_NAME(edtCert);
|
|
|
|
|
|
lblCert->setBuddy(edtCert);
|
|
|
|
|
|
|
|
|
|
|
|
lblKey = new QLabel;
|
|
|
|
|
|
SET_OBJECT_NAME(lblKey);
|
|
|
|
|
|
edtKey = new QLineEdit;
|
|
|
|
|
|
SET_OBJECT_NAME(edtKey);
|
|
|
|
|
|
lblKey->setBuddy(edtKey);
|
|
|
|
|
|
|
|
|
|
|
|
lblRootCert = new QLabel;
|
|
|
|
|
|
SET_OBJECT_NAME(lblRootCert);
|
|
|
|
|
|
edtRootCert = new QLineEdit;
|
|
|
|
|
|
SET_OBJECT_NAME(edtRootCert);
|
|
|
|
|
|
lblRootCert->setBuddy(edtRootCert);
|
|
|
|
|
|
|
|
|
|
|
|
lblCrl = new QLabel;
|
|
|
|
|
|
SET_OBJECT_NAME(lblCrl);
|
|
|
|
|
|
edtCrl = new QLineEdit;
|
|
|
|
|
|
SET_OBJECT_NAME(edtCrl);
|
|
|
|
|
|
lblCrl->setBuddy(edtCrl);
|
|
|
|
|
|
|
|
|
|
|
|
formLayout = new QFormLayout;
|
|
|
|
|
|
|
2019-08-27 20:12:00 +02:00
|
|
|
|
formLayout->addRow(lblGroup, cmbbxGroup);
|
2019-08-24 20:47:32 +02:00
|
|
|
|
formLayout->addRow(lblName, edtName);
|
|
|
|
|
|
formLayout->addRow(lblHost, edtHost);
|
|
|
|
|
|
formLayout->addRow(lblPort, spinPort);
|
|
|
|
|
|
formLayout->addRow(lblUser, edtUser);
|
|
|
|
|
|
formLayout->addRow(lblDbName, edtDbname);
|
|
|
|
|
|
formLayout->addRow(lblSsl, cmbbxSsl);
|
|
|
|
|
|
formLayout->addRow(lblCert, edtCert);
|
|
|
|
|
|
formLayout->addRow(lblKey, edtKey);
|
|
|
|
|
|
formLayout->addRow(lblRootCert, edtRootCert);
|
|
|
|
|
|
formLayout->addRow(lblCrl, edtCrl);
|
2019-08-27 20:12:00 +02:00
|
|
|
|
setLayout(formLayout);
|
2019-08-24 20:47:32 +02:00
|
|
|
|
|
|
|
|
|
|
retranslateUi();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectionConfigurationWidget::retranslateUi()
|
|
|
|
|
|
{
|
2019-08-27 20:12:00 +02:00
|
|
|
|
lblGroup->setText(QApplication::translate("ConnectionConfigurationWidget", "&Group", nullptr));
|
2019-08-24 20:47:32 +02:00
|
|
|
|
lblName->setText(QApplication::translate("ConnectionConfigurationWidget", "&Name", nullptr));
|
|
|
|
|
|
lblHost->setText(QApplication::translate("ConnectionConfigurationWidget", "&Host", nullptr));
|
|
|
|
|
|
lblPort->setText(QApplication::translate("ConnectionConfigurationWidget", "&Port", nullptr));
|
|
|
|
|
|
lblUser->setText(QApplication::translate("ConnectionConfigurationWidget", "&Username", nullptr));
|
|
|
|
|
|
lblDbName->setText(QApplication::translate("ConnectionConfigurationWidget", "&Database", nullptr));
|
|
|
|
|
|
lblSsl->setText(QApplication::translate("ConnectionConfigurationWidget", "&SSL mode", nullptr));
|
|
|
|
|
|
lblCert->setText(QApplication::translate("ConnectionConfigurationWidget", "&Certificate", nullptr));
|
|
|
|
|
|
lblKey->setText(QApplication::translate("ConnectionConfigurationWidget", "&Key", nullptr));
|
|
|
|
|
|
lblRootCert->setText(QApplication::translate("ConnectionConfigurationWidget", "&Root cert.", nullptr));
|
|
|
|
|
|
lblCrl->setText(QApplication::translate("ConnectionConfigurationWidget", "Revocation &list", nullptr));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectionConfigurationWidget::setData(const ConnectionConfig &cfg)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_uuid = cfg.uuid();
|
|
|
|
|
|
edtName->setText(stdStrToQ(cfg.name()));
|
|
|
|
|
|
edtHost->setText(stdStrToQ(cfg.host()));
|
|
|
|
|
|
spinPort->setValue(cfg.port());
|
|
|
|
|
|
edtUser->setText(stdStrToQ(cfg.user()));
|
|
|
|
|
|
edtDbname->setText(stdStrToQ(cfg.dbname()));
|
|
|
|
|
|
cmbbxSsl->setCurrentIndex(static_cast<int>(cfg.sslMode()));
|
|
|
|
|
|
edtCert->setText(stdStrToQ(cfg.sslCert()));
|
|
|
|
|
|
edtKey->setText(stdStrToQ(cfg.sslKey()));
|
|
|
|
|
|
edtRootCert->setText(stdStrToQ(cfg.sslRootCert()));
|
|
|
|
|
|
edtCrl->setText(stdStrToQ(cfg.sslCrl()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-27 20:12:00 +02:00
|
|
|
|
std::tuple<QString, ConnectionConfig> ConnectionConfigurationWidget::data() const
|
2019-08-24 20:47:32 +02:00
|
|
|
|
{
|
2019-08-27 20:12:00 +02:00
|
|
|
|
QString group;
|
|
|
|
|
|
group = cmbbxGroup->currentText();
|
|
|
|
|
|
|
2019-08-24 20:47:32 +02:00
|
|
|
|
ConnectionConfig cfg;
|
|
|
|
|
|
cfg.setUuid(m_uuid);
|
|
|
|
|
|
cfg.setName(qStrToStd(edtName->text()));
|
|
|
|
|
|
cfg.setHost(qStrToStd(edtHost->text()));
|
|
|
|
|
|
cfg.setPort(static_cast<uint16_t>(spinPort->value()));
|
|
|
|
|
|
cfg.setUser(qStrToStd(edtUser->text()));
|
|
|
|
|
|
cfg.setDbname(qStrToStd(edtDbname->text()));
|
|
|
|
|
|
cfg.setSslMode(static_cast<SslMode>(cmbbxSsl->currentIndex()));
|
|
|
|
|
|
cfg.setSslCert(qStrToStd(edtCert->text()));
|
|
|
|
|
|
cfg.setSslKey(qStrToStd(edtKey->text()));
|
|
|
|
|
|
cfg.setSslRootCert(qStrToStd(edtRootCert->text()));
|
|
|
|
|
|
cfg.setSslCrl(qStrToStd(edtCrl->text()));
|
2019-08-27 20:12:00 +02:00
|
|
|
|
return { group, cfg };
|
2019-08-24 20:47:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|