Allow for saving the configuration used by a window opened from a URL.

Note when editing a copy save password works now too.
This commit is contained in:
eelke 2025-03-10 19:08:02 +01:00
parent 05e9b982cd
commit a6be979f8e
7 changed files with 43 additions and 16 deletions

View file

@ -207,13 +207,13 @@ void ConnectionConfigurationWidget::setData(const ConnectionConfig &cfg)
edtPassword->setText(""); edtPassword->setText("");
cmbDbname->setCurrentText(cfg.dbname()); cmbDbname->setCurrentText(cfg.dbname());
//cmbbxSsl->setCurrentIndex(static_cast<int>(cfg.sslMode()));
cmbbxSsl->setCurrentText(cfg.getParameter("sslmode")); cmbbxSsl->setCurrentText(cfg.getParameter("sslmode"));
edtCert->setText(cfg.sslCert()); edtCert->setText(cfg.sslCert());
edtKey->setText(cfg.sslKey()); edtKey->setText(cfg.sslKey());
edtRootCert->setText(cfg.sslRootCert()); edtRootCert->setText(cfg.sslRootCert());
edtCrl->setText(cfg.sslCrl()); edtCrl->setText(cfg.sslCrl());
edtPassword->setText(cfg.password());
encodedPassword = cfg.encodedPassword(); encodedPassword = cfg.encodedPassword();
cbSavePassword->setCheckState( cbSavePassword->setCheckState(
encodedPassword.isEmpty() encodedPassword.isEmpty()
@ -234,7 +234,7 @@ ConnectionConfig ConnectionConfigurationWidget::data() const
cfg.setUser(edtUser->text()); cfg.setUser(edtUser->text());
cfg.setPassword(edtPassword->text()); cfg.setPassword(edtPassword->text());
cfg.setDbname(cmbDbname->currentText()); cfg.setDbname(cmbDbname->currentText());
cfg.setSslMode(static_cast<SslMode>(cmbbxSsl->currentIndex())); cfg.setParameter("sslmode", cmbbxSsl->currentText());
cfg.setSslCert(edtCert->text()); cfg.setSslCert(edtCert->text());
cfg.setSslKey(edtKey->text()); cfg.setSslKey(edtKey->text());
cfg.setSslRootCert(edtRootCert->text()); cfg.setSslRootCert(edtRootCert->text());
@ -248,14 +248,14 @@ QString ConnectionConfigurationWidget::group() const
return cmbbxGroup->currentText(); return cmbbxGroup->currentText();
} }
bool ConnectionConfigurationWidget::savePassword() const bool ConnectionConfigurationWidget::savePasswordEnabled() const
{ {
return cbSavePassword->isChecked() && !edtPassword->text().isEmpty() && passwordChanged; return cbSavePassword->isChecked();
} }
bool ConnectionConfigurationWidget::clearPassword() const bool ConnectionConfigurationWidget::passwordIsChanged() const
{ {
return !cbSavePassword->isChecked(); return passwordChanged;
} }
void ConnectionConfigurationWidget::testConnection() void ConnectionConfigurationWidget::testConnection()

View file

@ -35,8 +35,8 @@ public:
ConnectionConfig data() const; ConnectionConfig data() const;
QString group() const; QString group() const;
bool savePassword() const; bool savePasswordEnabled() const;
bool clearPassword() const; bool passwordIsChanged() const;
public slots: public slots:
void testConnection(); void testConnection();

View file

@ -84,10 +84,14 @@ void ConnectionController::openBackupDlgForConnection(QModelIndex index)
} }
} }
void ConnectionController::createConnection() void ConnectionController::createConnection(ConnectionConfig *init)
{ {
ConnectionConfig cc; ConnectionConfig cc;
cc.setUuid(QUuid::createUuid()); if (init)
{
cc = *init;
cc.setUuid(QUuid());
}
editConfig(cc); editConfig(cc);
} }
@ -104,7 +108,7 @@ void ConnectionController::editCopy(QModelIndex index)
auto config = ConnectionTreeModel::getConfigFromModelIndex(index); auto config = ConnectionTreeModel::getConfigFromModelIndex(index);
if (config) { if (config) {
auto cc = *config; auto cc = *config;
cc.setUuid(QUuid::createUuid()); cc.setUuid(QUuid());
cc.setEncodedPassword({}); // maybe we should decode en reencode? cc.setEncodedPassword({}); // maybe we should decode en reencode?
editConfig(cc); editConfig(cc);
} }
@ -120,10 +124,20 @@ void ConnectionController::saveConnection(ConnectionConfigurationWidget &w)
{ {
auto cc = w.data(); auto cc = w.data();
auto grp = w.group(); auto grp = w.group();
if (w.savePassword()) bool isNew = cc.uuid().isNull();
encryptPassword(cc); if (isNew)
if (w.clearPassword()) {
cc.setUuid(QUuid::createUuid());
}
if (w.savePasswordEnabled())
{
if (isNew || w.passwordIsChanged())
encryptPassword(cc);
}
else
{
cc.setEncodedPassword({}); cc.setEncodedPassword({});
}
m_connectionTreeModel->save(grp, cc); m_connectionTreeModel->save(grp, cc);
} }

View file

@ -43,7 +43,7 @@ public:
/// Starts the form for creating a new conncetion. /// Starts the form for creating a new conncetion.
/// This function returns immidiatly! /// This function returns immidiatly!
void createConnection(); void createConnection(ConnectionConfig *init = nullptr);
/// Starts the form for editing a conncetion. /// Starts the form for editing a conncetion.
/// This function returns immidiatly! /// This function returns immidiatly!
void editConnection(QModelIndex index); void editConnection(QModelIndex index);

View file

@ -443,6 +443,12 @@ void DatabaseWindow::on_actionShow_connection_manager_triggered()
m_masterController->connectionController()->showConnectionManager(); m_masterController->connectionController()->showConnectionManager();
} }
void DatabaseWindow::on_actionSave_connection_triggered()
{
if (m_config.uuid().isNull())
m_masterController->connectionController()->createConnection(&m_config);
}
void DatabaseWindow::on_actionManual_triggered() void DatabaseWindow::on_actionManual_triggered()
{ {
OpenManual(); OpenManual();

View file

@ -105,6 +105,7 @@ private slots:
void on_actionSave_query_as_triggered(); void on_actionSave_query_as_triggered();
void on_actionSave_copy_of_query_as_triggered(); void on_actionSave_copy_of_query_as_triggered();
void on_actionShow_connection_manager_triggered(); void on_actionShow_connection_manager_triggered();
void on_actionSave_connection_triggered();
void on_actionManual_triggered(); void on_actionManual_triggered();

View file

@ -30,7 +30,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1260</width> <width>1260</width>
<height>29</height> <height>21</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -44,6 +44,7 @@
<addaction name="actionSave_query_as"/> <addaction name="actionSave_query_as"/>
<addaction name="actionSave_copy_of_query_as"/> <addaction name="actionSave_copy_of_query_as"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionSave_connection"/>
<addaction name="actionExport_data"/> <addaction name="actionExport_data"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionClose"/> <addaction name="actionClose"/>
@ -331,6 +332,11 @@
<string>Manual</string> <string>Manual</string>
</property> </property>
</action> </action>
<action name="actionSave_connection">
<property name="text">
<string>Save connection</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="resources.qrc"/> <include location="resources.qrc"/>