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::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);

View File

@ -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;

View File

@ -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<Qt::CheckState>(state);
if (cstate == Qt::CheckState::Unchecked)
Settings::getInstance().setAutoLogin(false);
else
Settings::getInstance().setAutoLogin(true);
Settings::getInstance().saveGlobal();
auto cstate = static_cast<Qt::CheckState>(state);
emit autoLoginChanged(cstate == Qt::CheckState::Checked);
}
void LoginScreen::retranslateUi()

View File

@ -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