UI: Update tray menu on password unlock.

This commit is contained in:
Nodir Temirkhodjaev 2021-04-10 15:39:53 +03:00
parent 7ef6df2307
commit 0583b8de84
5 changed files with 27 additions and 23 deletions

View File

@ -105,13 +105,14 @@ void PasswordDialog::setupButtonBox()
QObject::connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
bool PasswordDialog::getPassword(QString &password, UnlockType &unlock, QWidget *parent)
bool PasswordDialog::getPassword(QString &password, UnlockType &unlockType, QWidget *parent)
{
PasswordDialog dialog(parent);
if (dialog.exec() == 0)
return false;
password = dialog.m_editPassword->text();
unlock = static_cast<UnlockType>(dialog.m_comboUnlock->currentIndex());
unlockType = static_cast<UnlockType>(dialog.m_comboUnlock->currentIndex());
return true;
}

View File

@ -21,7 +21,7 @@ public:
explicit PasswordDialog(QWidget *parent = nullptr);
static bool getPassword(QString &password, UnlockType &unlock, QWidget *parent = nullptr);
static bool getPassword(QString &password, UnlockType &unlockType, QWidget *parent = nullptr);
private:
void retranslateUi();

View File

@ -304,6 +304,7 @@ void FortManager::setupTrayIcon()
connect(m_trayIcon, &QSystemTrayIcon::messageClicked, this, &FortManager::onTrayMessageClicked);
connect(this, &FortManager::optWindowChanged, this, &FortManager::updateTrayMenuFlags);
connect(settings(), &FortSettings::passwordUnlocked, this, &FortManager::updateTrayMenuFlags);
connect(confManager(), &ConfManager::confSaved, this, &FortManager::updateTrayMenu);
connect(confManager(), &ConfManager::alertedAppAdded, this, [&] { updateTrayIcon(true); });
@ -634,15 +635,15 @@ bool FortManager::checkPassword()
g_passwordDialogOpened = true;
QString password;
PasswordDialog::UnlockType unlocked = PasswordDialog::UnlockDisabled;
const bool ok = PasswordDialog::getPassword(password, unlocked, m_mainWindow);
PasswordDialog::UnlockType unlockType = PasswordDialog::UnlockDisabled;
const bool ok = PasswordDialog::getPassword(password, unlockType, m_mainWindow);
g_passwordDialogOpened = false;
const bool checked = ok && !password.isEmpty()
&& StringUtil::cryptoHash(password) == settings()->passwordHash();
settings()->setPasswordChecked(checked, checked ? unlocked : PasswordDialog::UnlockDisabled);
settings()->setPasswordChecked(checked, checked ? unlockType : PasswordDialog::UnlockDisabled);
return checked;
}

View File

@ -36,7 +36,7 @@ FortSettings::FortSettings(QObject *parent) :
m_hasService(false),
m_isWindowControl(false),
m_passwordChecked(false),
m_passwordUnlocked(0),
m_passwordUnlockType(0),
m_bulkUpdating(false),
m_bulkIniChanged(false)
{
@ -225,30 +225,34 @@ QString FortSettings::confFilePath() const
return profilePath() + (APP_BASE ".config");
}
void FortSettings::setPasswordChecked(bool checked, bool unlocked)
bool FortSettings::isPasswordRequired()
{
if (m_passwordChecked == checked)
return hasPassword() && !(m_passwordUnlockType != 0 && m_passwordChecked);
}
void FortSettings::setPasswordChecked(bool checked, int unlockType)
{
if (m_passwordChecked == checked && m_passwordUnlockType == unlockType)
return;
m_passwordChecked = checked;
m_passwordUnlocked = unlocked;
m_passwordUnlockType = unlockType;
if (m_passwordUnlockType != 0) {
emit passwordUnlocked();
}
emit iniChanged();
}
void FortSettings::resetCheckedPassword(int unlocked)
void FortSettings::resetCheckedPassword(int unlockType)
{
if (unlocked != 0 && unlocked != m_passwordUnlocked)
if (unlockType != 0 && unlockType != m_passwordUnlockType)
return;
setPasswordChecked(false, 0);
}
bool FortSettings::isPasswordRequired()
{
return hasPassword() && !(m_passwordUnlocked != 0 && m_passwordChecked);
}
void FortSettings::readConfIni(FirewallConf &conf) const
{
m_ini->beginGroup("confFlags");

View File

@ -222,12 +222,9 @@ public:
QString errorMessage() const { return m_errorMessage; }
bool passwordChecked() const { return m_passwordChecked; }
bool passwordUnlocked() const { return m_passwordUnlocked; }
void setPasswordChecked(bool checked, bool unlocked);
void resetCheckedPassword(int unlocked = 0);
bool isPasswordRequired();
void setPasswordChecked(bool checked, int unlockType);
void resetCheckedPassword(int unlockType = 0);
bool confMigrated() const;
bool confCanMigrate(QString &viaVersion) const;
@ -235,6 +232,7 @@ public:
signals:
void iniChanged();
void errorMessageChanged();
void passwordUnlocked();
public slots:
void setupGlobal();
@ -291,7 +289,7 @@ private:
uint m_isWindowControl : 1;
uint m_passwordChecked : 1;
uint m_passwordUnlocked : 3;
uint m_passwordUnlockType : 3;
uint m_bulkUpdating : 1;
uint m_bulkIniChanged : 1;