Make saving of the entered password work to.toStdString
Also when testing a preexisting connection config it will now decode a potential stored password.
This commit is contained in:
parent
c00a0452d1
commit
87cfb84997
6 changed files with 117 additions and 70 deletions
|
|
@ -24,10 +24,11 @@
|
|||
#define SET_OBJECT_NAME(var) var->setObjectName(#var)
|
||||
|
||||
|
||||
void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *ctrl, const ConnectionConfig &cfg)
|
||||
void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *connection_controller, const ConnectionConfig &cfg,
|
||||
std::function<void(ConnectionConfigurationWidget&)> save_func)
|
||||
{
|
||||
try {
|
||||
auto w = new ConnectionConfigurationWidget(ctrl->getConnectionTreeModel());
|
||||
auto w = new ConnectionConfigurationWidget(connection_controller);
|
||||
w->setData(cfg);
|
||||
|
||||
auto btn_hbox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal);
|
||||
|
|
@ -41,12 +42,13 @@ void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *c
|
|||
win->setLayout(vbox);
|
||||
win->setAttribute( Qt::WA_DeleteOnClose, true );
|
||||
|
||||
QObject::connect(btn_hbox, &QDialogButtonBox::accepted, [ctrl, w, win] () {
|
||||
auto cc = w->data();
|
||||
auto grp = w->group();
|
||||
ctrl->getConnectionTreeModel()->save(grp, cc);
|
||||
win->accept();
|
||||
});
|
||||
QObject::connect(btn_hbox, &QDialogButtonBox::accepted, [w, win, save_func] () {
|
||||
// auto cc = w->data();
|
||||
// auto grp = w->group();
|
||||
// connection_controller->getConnectionTreeModel()->save(grp, cc);
|
||||
save_func(*w);
|
||||
win->accept();
|
||||
});
|
||||
QObject::connect(btn_hbox, &QDialogButtonBox::rejected, [win] ()
|
||||
{
|
||||
win->reject();
|
||||
|
|
@ -59,13 +61,14 @@ void ConnectionConfigurationWidget::editExistingInWindow(ConnectionController *c
|
|||
}
|
||||
}
|
||||
|
||||
ConnectionConfigurationWidget::ConnectionConfigurationWidget(ConnectionTreeModel *connection_model, QWidget *parent)
|
||||
ConnectionConfigurationWidget::ConnectionConfigurationWidget(ConnectionController *connection_controller, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_connectionModel(connection_model)
|
||||
, m_connectionController(connection_controller)
|
||||
, m_connectionModel(connection_controller->getConnectionTreeModel())
|
||||
{
|
||||
lblGroup = new QLabel;
|
||||
cmbbxGroup = new QComboBox;
|
||||
cmbbxGroup->setModel(connection_model);
|
||||
cmbbxGroup->setModel(m_connectionModel);
|
||||
cmbbxGroup->setModelColumn(0);
|
||||
lblGroup->setBuddy(cmbbxGroup);
|
||||
|
||||
|
|
@ -202,12 +205,16 @@ void ConnectionConfigurationWidget::setData(const ConnectionConfig &cfg)
|
|||
edtHost->setText(cfg.host());
|
||||
spinPort->setValue(cfg.port());
|
||||
edtUser->setText(cfg.user());
|
||||
edtPassword->setText("");
|
||||
|
||||
cmbDbname->setCurrentText(cfg.dbname());
|
||||
cmbbxSsl->setCurrentIndex(static_cast<int>(cfg.sslMode()));
|
||||
edtCert->setText(cfg.sslCert());
|
||||
edtKey->setText(cfg.sslKey());
|
||||
edtRootCert->setText(cfg.sslRootCert());
|
||||
edtCrl->setText(cfg.sslCrl());
|
||||
|
||||
encodedPassword = cfg.encodedPassword();
|
||||
}
|
||||
|
||||
ConnectionConfig ConnectionConfigurationWidget::data() const
|
||||
|
|
@ -225,6 +232,7 @@ ConnectionConfig ConnectionConfigurationWidget::data() const
|
|||
cfg.setSslKey(edtKey->text());
|
||||
cfg.setSslRootCert(edtRootCert->text());
|
||||
cfg.setSslCrl(edtCrl->text());
|
||||
cfg.setEncodedPassword(encodedPassword); // this could be old, it will be overriden later when there is a new password to save.
|
||||
return cfg;
|
||||
}
|
||||
|
||||
|
|
@ -233,9 +241,20 @@ QString ConnectionConfigurationWidget::group() const
|
|||
return cmbbxGroup->currentText();
|
||||
}
|
||||
|
||||
bool ConnectionConfigurationWidget::savePassword() const
|
||||
{
|
||||
return cbSavePassword->isChecked() && !edtPassword->text().isEmpty();
|
||||
}
|
||||
|
||||
void ConnectionConfigurationWidget::testConnection()
|
||||
{
|
||||
QString password = edtPassword->text();
|
||||
if (password.isEmpty() && !encodedPassword.isEmpty()) {
|
||||
m_connectionController->decodeConnectionPassword(m_uuid, encodedPassword, password);
|
||||
}
|
||||
|
||||
auto cc = data();
|
||||
cc.setPassword(password);
|
||||
QFuture<TestConnectionResult> result = QtConcurrent::run([cc] { return TestConnection(cc); });
|
||||
TestWatcher.setFuture(result);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue