UI: Options: Fix password checking.

This commit is contained in:
Nodir Temirkhodjaev 2021-08-07 13:59:30 +03:00
parent 67a779e1ed
commit 4000db08b8
2 changed files with 19 additions and 3 deletions

View File

@ -65,6 +65,11 @@ OptionsPage::OptionsPage(OptionsController *ctrl, QWidget *parent) : OptBasePage
setupUi(); setupUi();
} }
void OptionsPage::setPasswordEdited(bool v)
{
m_passwordEdited = v;
}
void OptionsPage::onAboutToSave() void OptionsPage::onAboutToSave()
{ {
// Startup // Startup
@ -72,8 +77,12 @@ void OptionsPage::onAboutToSave()
saveService(m_cbService->isChecked()); saveService(m_cbService->isChecked());
// Password // Password
if (!settings()->hasPassword() && ini()->hasPassword() && ini()->password().isEmpty()) { if (passwordEdited()) {
m_cbPassword->setChecked(false); if (!settings()->hasPassword() && ini()->hasPassword() && ini()->password().isEmpty()) {
m_cbPassword->setChecked(false);
}
} else if (conf()->iniEdited()) {
ini()->setHasPassword(settings()->hasPassword());
} }
} }
@ -125,6 +134,7 @@ void OptionsPage::saveService(bool isService)
void OptionsPage::onEditResetted() void OptionsPage::onEditResetted()
{ {
setPasswordEdited(false);
retranslateEditPassword(); retranslateEditPassword();
} }
@ -385,13 +395,14 @@ QLayout *OptionsPage::setupPasswordLayout()
auto layout = new QHBoxLayout(); auto layout = new QHBoxLayout();
layout->setSpacing(6); layout->setSpacing(6);
m_cbPassword = ControlUtil::createCheckBox(ini()->hasPassword(), [&](bool checked) { m_cbPassword = ControlUtil::createCheckBox(settings()->hasPassword(), [&](bool checked) {
if (checked) { if (checked) {
m_editPassword->setFocus(); m_editPassword->setFocus();
} else { } else {
m_editPassword->clear(); m_editPassword->clear();
} }
setPasswordEdited(true);
ini()->setHasPassword(checked); ini()->setHasPassword(checked);
ctrl()->setIniEdited(); ctrl()->setIniEdited();
}); });

View File

@ -10,6 +10,9 @@ class OptionsPage : public OptBasePage
public: public:
explicit OptionsPage(OptionsController *ctrl = nullptr, QWidget *parent = nullptr); explicit OptionsPage(OptionsController *ctrl = nullptr, QWidget *parent = nullptr);
bool passwordEdited() const { return m_passwordEdited; }
void setPasswordEdited(bool v);
protected slots: protected slots:
void onAboutToSave() override; void onAboutToSave() override;
void onEditResetted() override; void onEditResetted() override;
@ -45,6 +48,8 @@ private:
void setupNewVersionUpdate(); void setupNewVersionUpdate();
private: private:
bool m_passwordEdited = false;
qint8 m_currentAutoRunMode = 0; qint8 m_currentAutoRunMode = 0;
QGroupBox *m_gbStartup = nullptr; QGroupBox *m_gbStartup = nullptr;