summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_profile.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-06-04 17:03:28 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-06-04 17:03:28 +0300
commitf531ff887729783a7fe7a3e12ad12f658eefc7b0 (patch)
tree9e1844429448b6527ef7ca87163e44eafce250d8 /protocols/Tox/src/tox_profile.cpp
parent1c2e5d128a7176ae827dda1e2a8fcc64e772a148 (diff)
UI classes:
- CDlgBase::m_bSucceeded variable introduced to check whether IDOK was pressed or not; - unused/useless buttons with id=IDOK or IDCANCEL removed; - brnOk.OnClick replaced with OnApply calls; - unused/useless calls of EndDialog/EndModal removed; - minor code cleaning
Diffstat (limited to 'protocols/Tox/src/tox_profile.cpp')
-rw-r--r--protocols/Tox/src/tox_profile.cpp307
1 files changed, 169 insertions, 138 deletions
diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp
index 2b8ef857c5..d414f75a8d 100644
--- a/protocols/Tox/src/tox_profile.cpp
+++ b/protocols/Tox/src/tox_profile.cpp
@@ -16,6 +16,42 @@ wchar_t* CToxProto::GetToxProfilePath(const wchar_t *accountName)
return profilePath;
}
+/////////////////////////////////////////////////////////////////////////////////////////
+// ENTER PASSWORD
+
+class CToxEnterPasswordDlg : public CToxDlgBase
+{
+ CCtrlEdit m_password;
+
+ CCtrlButton m_ok;
+
+public:
+ CToxEnterPasswordDlg(CToxProto *proto) :
+ CToxDlgBase(proto, IDD_PASSWORD_ENTER),
+ m_password(this, IDC_PASSWORD),
+ m_ok(this, IDOK)
+ {
+ m_password.OnChange = Callback(this, &CToxEnterPasswordDlg::Password_OnChange);
+ }
+
+ bool OnInitDialog() override
+ {
+ m_ok.Disable();
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ m_proto->setWString(TOX_SETTINGS_PASSWORD, pass_ptrW(m_password.GetText()));
+ return true;
+ }
+
+ void Password_OnChange(CCtrlBase *)
+ {
+ m_ok.Enable(GetWindowTextLength(m_password.GetHwnd()) != 0);
+ }
+};
+
static INT_PTR CALLBACK EnterPassword(void *param)
{
CToxProto *proto = (CToxProto*)param;
@@ -163,172 +199,167 @@ INT_PTR CToxProto::OnCopyToxID(WPARAM, LPARAM)
return 0;
}
-INT_PTR CToxProto::OnCreatePassword(WPARAM, LPARAM)
-{
- pass_ptrW password(getWStringA(TOX_SETTINGS_PASSWORD));
- CToxCreatePasswordDlg passwordDlg(this);
- passwordDlg.DoModal();
- return 0;
-}
+/////////////////////////////////////////////////////////////////////////////////////////
+// CREATE PASSWORD
-INT_PTR CToxProto::OnChangePassword(WPARAM, LPARAM)
+class CToxCreatePasswordDlg : public CToxDlgBase
{
- CToxChangePasswordDlg passwordDlg(this);
- passwordDlg.DoModal();
- return 0;
-}
+ CCtrlEdit m_newPassword;
+ CCtrlEdit m_confirmPassword;
+ CCtrlBase m_passwordValidation;
+ CCtrlButton m_ok;
+
+public:
+ CToxCreatePasswordDlg(CToxProto *proto) :
+ CToxDlgBase(proto, IDD_PASSWORD_CREATE),
+ m_ok(this, IDOK),
+ m_newPassword(this, IDC_PASSWORD_NEW),
+ m_confirmPassword(this, IDC_PASSWORD_CONFIRM),
+ m_passwordValidation(this, IDC_PASSWORD_VALIDATION)
+ {
+ m_newPassword.OnChange = Callback(this, &CToxCreatePasswordDlg::Password_OnChange);
+ m_confirmPassword.OnChange = Callback(this, &CToxCreatePasswordDlg::Password_OnChange);
+ }
-INT_PTR CToxProto::OnRemovePassword(WPARAM, LPARAM)
-{
- const wchar_t *message = TranslateT("Removing the password will lead to decryption of the profile.\r\nAre you sure to remove password?");
- int result = MessageBox(nullptr, message, TranslateT("Remove password"), MB_YESNO | MB_ICONQUESTION);
- if (result == IDYES) {
- delSetting(TOX_SETTINGS_PASSWORD);
- SaveToxProfile(m_tox);
+ bool OnInitDialog() override
+ {
+ LOGFONT lf;
+ HFONT hFont = (HFONT)m_passwordValidation.SendMsg(WM_GETFONT, 0, 0);
+ GetObject(hFont, sizeof(lf), &lf);
+ lf.lfWeight = FW_BOLD;
+ m_passwordValidation.SendMsg(WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
+
+ m_ok.Disable();
+ return true;
}
- return 0;
-}
-/* ENTER PASSWORD */
+ bool OnApply() override
+ {
+ m_proto->setWString(TOX_SETTINGS_PASSWORD, pass_ptrW(m_newPassword.GetText()));
+ m_proto->SaveToxProfile(m_proto->m_tox);
+ return true;
+ }
-CToxEnterPasswordDlg::CToxEnterPasswordDlg(CToxProto *proto)
- : CToxDlgBase(proto, IDD_PASSWORD_ENTER),
- m_password(this, IDC_PASSWORD),
- m_ok(this, IDOK)
-{
- m_password.OnChange = Callback(this, &CToxEnterPasswordDlg::Password_OnChange);
- m_ok.OnClick = Callback(this, &CToxEnterPasswordDlg::OnOk);
-}
+ void Password_OnChange(CCtrlBase *)
+ {
+ pass_ptrW newPassword(m_newPassword.GetText());
+ if (mir_wstrlen(newPassword) == 0) {
+ m_ok.Disable();
+ m_passwordValidation.SetText(TranslateT("New password is empty"));
+ return;
+ }
-bool CToxEnterPasswordDlg::OnInitDialog()
-{
- m_ok.Disable();
- return true;
-}
+ pass_ptrW confirmPassword(m_confirmPassword.GetText());
+ if (mir_wstrcmp(newPassword, confirmPassword) != 0) {
+ m_ok.Disable();
+ m_passwordValidation.SetText(TranslateT("New password is not equal to confirmation"));
+ return;
+ }
-void CToxEnterPasswordDlg::Password_OnChange(CCtrlBase*)
-{
- m_ok.Enable(GetWindowTextLength(m_password.GetHwnd()) != 0);
-}
+ m_passwordValidation.SetText(L"");
+ m_ok.Enable();
+ }
+};
-void CToxEnterPasswordDlg::OnOk(CCtrlButton*)
+INT_PTR CToxProto::OnCreatePassword(WPARAM, LPARAM)
{
- m_proto->setWString(TOX_SETTINGS_PASSWORD, pass_ptrW(m_password.GetText()));
- EndDialog(m_hwnd, 1);
+ pass_ptrW password(getWStringA(TOX_SETTINGS_PASSWORD));
+ CToxCreatePasswordDlg(this).DoModal();
+ return 0;
}
-/* CREATE PASSWORD */
+/////////////////////////////////////////////////////////////////////////////////////////
+// CHANGE PASSWORD
-CToxCreatePasswordDlg::CToxCreatePasswordDlg(CToxProto *proto)
- : CToxDlgBase(proto, IDD_PASSWORD_CREATE),
- m_newPassword(this, IDC_PASSWORD_NEW),
- m_confirmPassword(this, IDC_PASSWORD_CONFIRM),
- m_passwordValidation(this, IDC_PASSWORD_VALIDATION),
- m_ok(this, IDOK)
+class CToxChangePasswordDlg : public CToxDlgBase
{
- m_newPassword.OnChange = Callback(this, &CToxCreatePasswordDlg::Password_OnChange);
- m_confirmPassword.OnChange = Callback(this, &CToxCreatePasswordDlg::Password_OnChange);
- m_ok.OnClick = Callback(this, &CToxCreatePasswordDlg::OnOk);
-}
+ CCtrlEdit m_oldPassword;
+
+ CCtrlEdit m_newPassword;
+ CCtrlEdit m_confirmPassword;
+
+ CCtrlBase m_passwordValidation;
+
+ CCtrlButton m_ok;
+
+public:
+ CToxChangePasswordDlg(CToxProto *proto) :
+ CToxDlgBase(proto, IDD_PASSWORD_CHANGE),
+ m_oldPassword(this, IDC_PASSWORD),
+ m_newPassword(this, IDC_PASSWORD_NEW),
+ m_confirmPassword(this, IDC_PASSWORD_CONFIRM),
+ m_passwordValidation(this, IDC_PASSWORD_VALIDATION),
+ m_ok(this, IDOK)
+ {
+ m_oldPassword.OnChange = Callback(this, &CToxChangePasswordDlg::Password_OnChange);
+ m_newPassword.OnChange = Callback(this, &CToxChangePasswordDlg::Password_OnChange);
+ m_confirmPassword.OnChange = Callback(this, &CToxChangePasswordDlg::Password_OnChange);
+ }
-bool CToxCreatePasswordDlg::OnInitDialog()
-{
- LOGFONT lf;
- HFONT hFont = (HFONT)m_passwordValidation.SendMsg(WM_GETFONT, 0, 0);
- GetObject(hFont, sizeof(lf), &lf);
- lf.lfWeight = FW_BOLD;
- m_passwordValidation.SendMsg(WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
-
- m_ok.Disable();
- return true;
-}
+ bool OnInitDialog() override
+ {
+ LOGFONT lf;
+ HFONT hFont = (HFONT)m_passwordValidation.SendMsg(WM_GETFONT, 0, 0);
+ GetObject(hFont, sizeof(lf), &lf);
+ lf.lfWeight = FW_BOLD;
+ m_passwordValidation.SendMsg(WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
-void CToxCreatePasswordDlg::Password_OnChange(CCtrlBase*)
-{
- pass_ptrW newPassword(m_newPassword.GetText());
- if (mir_wstrlen(newPassword) == 0) {
m_ok.Disable();
- m_passwordValidation.SetText(TranslateT("New password is empty"));
- return;
+ return true;
}
- pass_ptrW confirmPassword(m_confirmPassword.GetText());
- if (mir_wstrcmp(newPassword, confirmPassword) != 0) {
- m_ok.Disable();
- m_passwordValidation.SetText(TranslateT("New password is not equal to confirmation"));
- return;
+ bool OnApply() override
+ {
+ m_proto->setWString(TOX_SETTINGS_PASSWORD, pass_ptrW(m_newPassword.GetText()));
+ m_proto->SaveToxProfile(m_proto->m_tox);
+ return true;
}
- m_passwordValidation.SetText(L"");
- m_ok.Enable();
-}
+ void Password_OnChange(CCtrlBase *)
+ {
+ pass_ptrW dbPassword(m_proto->getWStringA(TOX_SETTINGS_PASSWORD));
+ pass_ptrW oldPassword(m_oldPassword.GetText());
+ if (mir_wstrlen(dbPassword) > 0 && mir_wstrcmp(dbPassword, oldPassword) != 0) {
+ m_ok.Disable();
+ m_passwordValidation.SetText(TranslateT("Old password is not valid"));
+ return;
+ }
-void CToxCreatePasswordDlg::OnOk(CCtrlButton*)
-{
- m_proto->setWString(TOX_SETTINGS_PASSWORD, pass_ptrW(m_newPassword.GetText()));
- m_proto->SaveToxProfile(m_proto->m_tox);
- EndDialog(m_hwnd, 1);
-}
+ pass_ptrW newPassword(m_newPassword.GetText());
+ if (mir_wstrlen(newPassword) == 0) {
+ m_ok.Disable();
+ m_passwordValidation.SetText(TranslateT("New password is empty"));
+ return;
+ }
-/* CHANGE PASSWORD */
+ pass_ptrW confirmPassword(m_confirmPassword.GetText());
+ if (mir_wstrcmp(newPassword, confirmPassword) != 0) {
+ m_ok.Disable();
+ m_passwordValidation.SetText(TranslateT("New password is not equal to confirmation"));
+ return;
+ }
-CToxChangePasswordDlg::CToxChangePasswordDlg(CToxProto *proto)
- : CToxDlgBase(proto, IDD_PASSWORD_CHANGE),
- m_oldPassword(this, IDC_PASSWORD),
- m_newPassword(this, IDC_PASSWORD_NEW),
- m_confirmPassword(this, IDC_PASSWORD_CONFIRM),
- m_passwordValidation(this, IDC_PASSWORD_VALIDATION),
- m_ok(this, IDOK)
-{
- m_oldPassword.OnChange = Callback(this, &CToxChangePasswordDlg::Password_OnChange);
- m_newPassword.OnChange = Callback(this, &CToxChangePasswordDlg::Password_OnChange);
- m_confirmPassword.OnChange = Callback(this, &CToxChangePasswordDlg::Password_OnChange);
- m_ok.OnClick = Callback(this, &CToxChangePasswordDlg::OnOk);
-}
+ m_passwordValidation.SetText(L"");
+ m_ok.Enable();
+ }
+};
-bool CToxChangePasswordDlg::OnInitDialog()
+INT_PTR CToxProto::OnChangePassword(WPARAM, LPARAM)
{
- LOGFONT lf;
- HFONT hFont = (HFONT)m_passwordValidation.SendMsg(WM_GETFONT, 0, 0);
- GetObject(hFont, sizeof(lf), &lf);
- lf.lfWeight = FW_BOLD;
- m_passwordValidation.SendMsg(WM_SETFONT, (WPARAM)CreateFontIndirect(&lf), 0);
-
- m_ok.Disable();
- return true;
+ CToxChangePasswordDlg passwordDlg(this);
+ passwordDlg.DoModal();
+ return 0;
}
-void CToxChangePasswordDlg::Password_OnChange(CCtrlBase*)
-{
- pass_ptrW dbPassword(m_proto->getWStringA(TOX_SETTINGS_PASSWORD));
- pass_ptrW oldPassword(m_oldPassword.GetText());
- if (mir_wstrlen(dbPassword) > 0 && mir_wstrcmp(dbPassword, oldPassword) != 0) {
- m_ok.Disable();
- m_passwordValidation.SetText(TranslateT("Old password is not valid"));
- return;
- }
+/////////////////////////////////////////////////////////////////////////////////////////
- pass_ptrW newPassword(m_newPassword.GetText());
- if (mir_wstrlen(newPassword) == 0) {
- m_ok.Disable();
- m_passwordValidation.SetText(TranslateT("New password is empty"));
- return;
- }
-
- pass_ptrW confirmPassword(m_confirmPassword.GetText());
- if (mir_wstrcmp(newPassword, confirmPassword) != 0) {
- m_ok.Disable();
- m_passwordValidation.SetText(TranslateT("New password is not equal to confirmation"));
- return;
- }
-
- m_passwordValidation.SetText(L"");
- m_ok.Enable();
-}
-
-void CToxChangePasswordDlg::OnOk(CCtrlButton*)
+INT_PTR CToxProto::OnRemovePassword(WPARAM, LPARAM)
{
- m_proto->setWString(TOX_SETTINGS_PASSWORD, pass_ptrW(m_newPassword.GetText()));
- m_proto->SaveToxProfile(m_proto->m_tox);
- EndDialog(m_hwnd, 1);
+ const wchar_t *message = TranslateT("Removing the password will lead to decryption of the profile.\r\nAre you sure to remove password?");
+ int result = MessageBox(nullptr, message, TranslateT("Remove password"), MB_YESNO | MB_ICONQUESTION);
+ if (result == IDYES) {
+ delSetting(TOX_SETTINGS_PASSWORD);
+ SaveToxProfile(m_tox);
+ }
+ return 0;
}