diff options
Diffstat (limited to 'src/Main/Forms/VolumePasswordPanel.cpp')
-rw-r--r-- | src/Main/Forms/VolumePasswordPanel.cpp | 97 |
1 files changed, 77 insertions, 20 deletions
diff --git a/src/Main/Forms/VolumePasswordPanel.cpp b/src/Main/Forms/VolumePasswordPanel.cpp index 0d1e6931..08b9b828 100644 --- a/src/Main/Forms/VolumePasswordPanel.cpp +++ b/src/Main/Forms/VolumePasswordPanel.cpp @@ -14,9 +14,9 @@ namespace VeraCrypt { VolumePasswordPanel::VolumePasswordPanel (wxWindow* parent, MountOptions* options, shared_ptr <VolumePassword> password, bool disableTruecryptMode, shared_ptr <KeyfileList> keyfiles, bool enableCache, bool enablePassword, bool enableKeyfiles, bool enableConfirmation, bool enablePkcs5Prf, bool isMountPassword, const wxString &passwordLabel) - : VolumePasswordPanelBase (parent), Keyfiles (new KeyfileList) + : VolumePasswordPanelBase (parent), Keyfiles (new KeyfileList), EnablePimEntry (true) { if (keyfiles) { *Keyfiles = *keyfiles; @@ -54,11 +54,19 @@ namespace VeraCrypt PasswordStaticText->Show (enablePassword); PasswordTextCtrl->Show (enablePassword); DisplayPasswordCheckBox->Show (enablePassword); - VolumePimStaticText->Show (enablePassword && (!enableConfirmation || (enablePkcs5Prf && !isMountPassword))); - VolumePimTextCtrl->Show (enablePassword && (!enableConfirmation || (enablePkcs5Prf && !isMountPassword))); - VolumePimHelpStaticText->Show (enablePassword && (!enableConfirmation || (enablePkcs5Prf && !isMountPassword))); + + EnablePimEntry = enablePassword && (!enableConfirmation || (enablePkcs5Prf && !isMountPassword)); + PimCheckBox->Show (EnablePimEntry); + VolumePimStaticText->Show (false); + VolumePimTextCtrl->Show (false); + VolumePimHelpStaticText->Show (false); + + wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST); // wxFILTER_NUMERIC does not exclude - . , etc. + const wxChar *valArr[] = { L"0", L"1", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9" }; + validator.SetIncludes (wxArrayString (array_capacity (valArr), (const wxChar **) &valArr)); + VolumePimTextCtrl->SetValidator (validator); ConfirmPasswordStaticText->Show (enableConfirmation); ConfirmPasswordTextCtrl->Show (enableConfirmation); @@ -75,14 +83,25 @@ namespace VeraCrypt { TrueCryptModeCheckBox->SetValue (options->TrueCryptMode); if (options->TrueCryptMode) { + PimCheckBox->Enable (false); VolumePimStaticText->Enable (false); VolumePimTextCtrl->Enable (false); VolumePimHelpStaticText->Enable (false); } } + if (EnablePimEntry && options && options->Pim > 0) + { + PimCheckBox->SetValue (true); + PimCheckBox->Show (false); + VolumePimStaticText->Show (true); + VolumePimTextCtrl->Show (true); + VolumePimHelpStaticText->Show (true); + SetVolumePim (options->Pim); + } + if (enablePkcs5Prf) { int index, prfInitialIndex = 0; if (isMountPassword) @@ -224,9 +243,9 @@ namespace VeraCrypt } int VolumePasswordPanel::GetVolumePim () const { - if (VolumePimTextCtrl->IsEnabled ()) + if (VolumePimTextCtrl->IsEnabled () && VolumePimTextCtrl->IsShown ()) { wxString pimStr (VolumePimTextCtrl->GetValue()); long pim = 0; if (pimStr.IsEmpty()) @@ -238,9 +257,21 @@ namespace VeraCrypt } else return 0; } - + + void VolumePasswordPanel::SetVolumePim (int pim) + { + if (pim > 0) + { + VolumePimTextCtrl->SetValue (StringConverter::FromNumber (pim)); + } + else + { + VolumePimTextCtrl->SetValue (wxT("")); + } + } + bool VolumePasswordPanel::GetTrueCryptMode () const { return TrueCryptModeCheckBox->GetValue (); } @@ -378,29 +409,55 @@ namespace VeraCrypt { textCtrl->SetValue (wxString (L'X', textCtrl->GetLineLength(0))); GetPassword (textCtrl); } - - void VolumePasswordPanel::OnPimChanged (wxCommandEvent& event) - { - if (ConfirmPasswordTextCtrl->IsShown()) + + bool VolumePasswordPanel::UpdatePimHelpText (bool pimChanged) + { + bool guiUpdated = false; + if (pimChanged && VolumePimHelpStaticText->GetForegroundColour() != *wxRED) { - if (GetVolumePim() != 0) - { - VolumePimHelpStaticText->SetForegroundColour(*wxRED); - VolumePimHelpStaticText->SetLabel(LangString["PIM_CHANGE_WARNING"]); - } - else - { - VolumePimHelpStaticText->SetForegroundColour(*wxBLACK); - VolumePimHelpStaticText->SetLabel(LangString["IDC_PIM_HELP"]); - } + VolumePimHelpStaticText->SetForegroundColour(*wxRED); + VolumePimHelpStaticText->SetLabel(LangString["PIM_CHANGE_WARNING"]); + guiUpdated = true; + } + if (!pimChanged && VolumePimHelpStaticText->GetForegroundColour() != *wxBLACK) + { + VolumePimHelpStaticText->SetForegroundColour(*wxBLACK); + VolumePimHelpStaticText->SetLabel(LangString["IDC_PIM_HELP"]); + guiUpdated = true; + } + + if (guiUpdated) + { + Layout(); + Fit(); + GetParent()->Layout(); + GetParent()->Fit(); + } + return guiUpdated; + } + + void VolumePasswordPanel::OnUsePimCheckBoxClick( wxCommandEvent& event ) + { + if (EnablePimEntry) + { + PimCheckBox->Show (false); + VolumePimStaticText->Show (true); + VolumePimTextCtrl->Show (true); + VolumePimHelpStaticText->Show (true); + + Layout(); + Fit(); + GetParent()->Layout(); + GetParent()->Fit(); } } void VolumePasswordPanel::OnTrueCryptModeChecked( wxCommandEvent& event ) { bool bEnablePIM = !GetTrueCryptMode (); + PimCheckBox->Enable (bEnablePIM); VolumePimStaticText->Enable (bEnablePIM); VolumePimTextCtrl->Enable (bEnablePIM); VolumePimHelpStaticText->Enable (bEnablePIM); } |