From a7b4a09ccb9c209657778cfa7c62757eaae0fe3e Mon Sep 17 00:00:00 2001 From: jenli669 Date: Mon, 24 Jun 2019 01:37:35 +0200 Subject: [PATCH] refactor(startup): handle autoLogin checkbox with signals --- src/nexus.cpp | 3 ++- src/persistence/settings.h | 3 +-- src/widget/loginscreen.cpp | 13 ++++--------- src/widget/loginscreen.h | 4 +++- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/nexus.cpp b/src/nexus.cpp index add239196..256f81449 100644 --- a/src/nexus.cpp +++ b/src/nexus.cpp @@ -209,7 +209,8 @@ void Nexus::connectLoginScreen(const LoginScreen& loginScreen) QObject::connect(&loginScreen, &LoginScreen::createNewProfile, this, &Nexus::onCreateNewProfile); QObject::connect(&loginScreen, &LoginScreen::loadProfile, this, &Nexus::onLoadProfile); // LoginScreen -> Settings - QObject::connect(&loginScreen, &LoginScreen::autoLoginChanged, settings, &Settings::onSetAutoLogin); + QObject::connect(&loginScreen, &LoginScreen::autoLoginChanged, settings, &Settings::setAutoLogin); + QObject::connect(&loginScreen, &LoginScreen::autoLoginChanged, settings, &Settings::saveGlobal); // Settings -> LoginScreen QObject::connect(settings, &Settings::autoLoginChanged, &loginScreen, &LoginScreen::onAutoLoginChanged); diff --git a/src/persistence/settings.h b/src/persistence/settings.h index c8b64798f..5507d6894 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -169,7 +169,7 @@ public: public slots: void saveGlobal(); void sync(); - void onSetAutoLogin(bool state); + void setAutoLogin(bool state); void updateProfileData(Profile *profile); signals: @@ -543,7 +543,6 @@ public: void setShowIdenticons(bool value); bool getAutoLogin() const; - void setAutoLogin(bool state); void setEnableGroupChatsColor(bool state); bool getEnableGroupChatsColor() const; diff --git a/src/widget/loginscreen.cpp b/src/widget/loginscreen.cpp index d8fcf4b12..db3ce69c2 100644 --- a/src/widget/loginscreen.cpp +++ b/src/widget/loginscreen.cpp @@ -56,7 +56,7 @@ LoginScreen::LoginScreen(const QString& initialProfileName, QWidget* parent) connect(ui->loginPassword, &QLineEdit::returnPressed, this, &LoginScreen::onLogin); connect(ui->newPass, &QLineEdit::textChanged, this, &LoginScreen::onPasswordEdited); connect(ui->newPassConfirm, &QLineEdit::textChanged, this, &LoginScreen::onPasswordEdited); - connect(ui->autoLoginCB, &QCheckBox::stateChanged, this, &LoginScreen::onAutoLoginToggled); + connect(ui->autoLoginCB, &QCheckBox::stateChanged, this, &LoginScreen::onAutoLoginCheckboxChanged); connect(ui->importButton, &QPushButton::clicked, this, &LoginScreen::onImportProfile); reset(initialProfileName); @@ -232,15 +232,10 @@ void LoginScreen::onPasswordEdited() ui->passStrengthMeter->setValue(SetPasswordDialog::getPasswordStrength(ui->newPass->text())); } -void LoginScreen::onAutoLoginToggled(int state) +void LoginScreen::onAutoLoginCheckboxChanged(int state) { - Qt::CheckState cstate = static_cast(state); - if (cstate == Qt::CheckState::Unchecked) - Settings::getInstance().setAutoLogin(false); - else - Settings::getInstance().setAutoLogin(true); - - Settings::getInstance().saveGlobal(); + auto cstate = static_cast(state); + emit autoLoginChanged(cstate == Qt::CheckState::Checked); } void LoginScreen::retranslateUi() diff --git a/src/widget/loginscreen.h b/src/widget/loginscreen.h index 4d1065527..53d8d9ea1 100644 --- a/src/widget/loginscreen.h +++ b/src/widget/loginscreen.h @@ -43,6 +43,7 @@ public: signals: void windowStateChanged(Qt::WindowStates states); + void autoLoginChanged(bool state); void createNewProfile(QString name, const QString& pass); void loadProfile(QString name, const QString& pass); @@ -52,9 +53,10 @@ protected: public slots: void onProfileLoaded(); void onProfileLoadFailed(); + void onAutoLoginChanged(bool state); private slots: - void onAutoLoginToggled(int state); + void onAutoLoginCheckboxChanged(int state); void onLoginUsernameSelected(const QString& name); void onPasswordEdited(); // Buttons to change page