1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(startup): handle autoLogin checkbox with signals

This commit is contained in:
jenli669 2019-06-24 01:37:35 +02:00
parent 8bc6fc9fd8
commit a7b4a09ccb
No known key found for this signature in database
GPG Key ID: 8267F9F7C2BF7E5E
4 changed files with 10 additions and 13 deletions

View File

@ -209,7 +209,8 @@ void Nexus::connectLoginScreen(const LoginScreen& loginScreen)
QObject::connect(&loginScreen, &LoginScreen::createNewProfile, this, &Nexus::onCreateNewProfile); QObject::connect(&loginScreen, &LoginScreen::createNewProfile, this, &Nexus::onCreateNewProfile);
QObject::connect(&loginScreen, &LoginScreen::loadProfile, this, &Nexus::onLoadProfile); QObject::connect(&loginScreen, &LoginScreen::loadProfile, this, &Nexus::onLoadProfile);
// LoginScreen -> Settings // 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 // Settings -> LoginScreen
QObject::connect(settings, &Settings::autoLoginChanged, &loginScreen, QObject::connect(settings, &Settings::autoLoginChanged, &loginScreen,
&LoginScreen::onAutoLoginChanged); &LoginScreen::onAutoLoginChanged);

View File

@ -169,7 +169,7 @@ public:
public slots: public slots:
void saveGlobal(); void saveGlobal();
void sync(); void sync();
void onSetAutoLogin(bool state); void setAutoLogin(bool state);
void updateProfileData(Profile *profile); void updateProfileData(Profile *profile);
signals: signals:
@ -543,7 +543,6 @@ public:
void setShowIdenticons(bool value); void setShowIdenticons(bool value);
bool getAutoLogin() const; bool getAutoLogin() const;
void setAutoLogin(bool state);
void setEnableGroupChatsColor(bool state); void setEnableGroupChatsColor(bool state);
bool getEnableGroupChatsColor() const; bool getEnableGroupChatsColor() const;

View File

@ -56,7 +56,7 @@ LoginScreen::LoginScreen(const QString& initialProfileName, QWidget* parent)
connect(ui->loginPassword, &QLineEdit::returnPressed, this, &LoginScreen::onLogin); connect(ui->loginPassword, &QLineEdit::returnPressed, this, &LoginScreen::onLogin);
connect(ui->newPass, &QLineEdit::textChanged, this, &LoginScreen::onPasswordEdited); connect(ui->newPass, &QLineEdit::textChanged, this, &LoginScreen::onPasswordEdited);
connect(ui->newPassConfirm, &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); connect(ui->importButton, &QPushButton::clicked, this, &LoginScreen::onImportProfile);
reset(initialProfileName); reset(initialProfileName);
@ -232,15 +232,10 @@ void LoginScreen::onPasswordEdited()
ui->passStrengthMeter->setValue(SetPasswordDialog::getPasswordStrength(ui->newPass->text())); ui->passStrengthMeter->setValue(SetPasswordDialog::getPasswordStrength(ui->newPass->text()));
} }
void LoginScreen::onAutoLoginToggled(int state) void LoginScreen::onAutoLoginCheckboxChanged(int state)
{ {
Qt::CheckState cstate = static_cast<Qt::CheckState>(state); auto cstate = static_cast<Qt::CheckState>(state);
if (cstate == Qt::CheckState::Unchecked) emit autoLoginChanged(cstate == Qt::CheckState::Checked);
Settings::getInstance().setAutoLogin(false);
else
Settings::getInstance().setAutoLogin(true);
Settings::getInstance().saveGlobal();
} }
void LoginScreen::retranslateUi() void LoginScreen::retranslateUi()

View File

@ -43,6 +43,7 @@ public:
signals: signals:
void windowStateChanged(Qt::WindowStates states); void windowStateChanged(Qt::WindowStates states);
void autoLoginChanged(bool state);
void createNewProfile(QString name, const QString& pass); void createNewProfile(QString name, const QString& pass);
void loadProfile(QString name, const QString& pass); void loadProfile(QString name, const QString& pass);
@ -52,9 +53,10 @@ protected:
public slots: public slots:
void onProfileLoaded(); void onProfileLoaded();
void onProfileLoadFailed(); void onProfileLoadFailed();
void onAutoLoginChanged(bool state);
private slots: private slots:
void onAutoLoginToggled(int state); void onAutoLoginCheckboxChanged(int state);
void onLoginUsernameSelected(const QString& name); void onLoginUsernameSelected(const QString& name);
void onPasswordEdited(); void onPasswordEdited();
// Buttons to change page // Buttons to change page