summaryrefslogtreecommitdiff
path: root/protocols/JabberG/src/jabber_password.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/JabberG/src/jabber_password.cpp')
-rw-r--r--protocols/JabberG/src/jabber_password.cpp118
1 files changed, 57 insertions, 61 deletions
diff --git a/protocols/JabberG/src/jabber_password.cpp b/protocols/JabberG/src/jabber_password.cpp
index 6715ab5605..e81667565c 100644
--- a/protocols/JabberG/src/jabber_password.cpp
+++ b/protocols/JabberG/src/jabber_password.cpp
@@ -26,73 +26,69 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "jabber_iq.h"
#include "jabber_caps.h"
-static INT_PTR CALLBACK JabberChangePasswordDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam);
-
-INT_PTR __cdecl CJabberProto::OnMenuHandleChangePassword(WPARAM, LPARAM)
+class ChangePasswordDlg : public CJabberDlgBase
{
- if (IsWindow(m_hwndJabberChangePassword))
- SetForegroundWindow(m_hwndJabberChangePassword);
- else
- m_hwndJabberChangePassword = CreateDialogParam(g_plugin.getInst(), MAKEINTRESOURCE(IDD_CHANGEPASSWORD), nullptr, JabberChangePasswordDlgProc, (LPARAM)this);
+ CCtrlEdit edtOldPass, edtPass1, edtPass2;
+
+public:
+ ChangePasswordDlg(CJabberProto *_ppro) :
+ CJabberDlgBase(_ppro, IDD_CHANGEPASSWORD),
+ edtOldPass(this, IDC_OLDPASSWD),
+ edtPass1(this, IDC_NEWPASSWD),
+ edtPass2(this, IDC_NEWPASSWD2)
+ {}
- return 0;
-}
+ bool OnInitDialog() override
+ {
+ m_proto->m_hwndJabberChangePassword = m_hwnd;
+ Window_SetIcon_IcoLib(m_hwnd, g_GetIconHandle(IDI_KEYS));
-static INT_PTR CALLBACK JabberChangePasswordDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- CJabberProto *ppro = (CJabberProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
- switch (msg) {
- case WM_INITDIALOG:
- ppro = (CJabberProto*)lParam;
- SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
-
- Window_SetIcon_IcoLib(hwndDlg, g_GetIconHandle(IDI_KEYS));
- TranslateDialogDefault(hwndDlg);
- if (ppro->m_bJabberOnline && ppro->m_ThreadInfo != nullptr) {
+ if (m_proto->m_bJabberOnline && m_proto->m_ThreadInfo != nullptr) {
wchar_t text[1024];
- mir_snwprintf(text, TranslateT("Set New Password for %s@%S"), ppro->m_ThreadInfo->conn.username, ppro->m_ThreadInfo->conn.server);
- SetWindowText(hwndDlg, text);
+ mir_snwprintf(text, TranslateT("Set New Password for %s@%S"), m_proto->m_ThreadInfo->conn.username, m_proto->m_ThreadInfo->conn.server);
+ SetCaption(text);
}
- return TRUE;
- case WM_COMMAND:
- switch (LOWORD(wParam)) {
- case IDOK:
- if (ppro->m_bJabberOnline && ppro->m_ThreadInfo != nullptr) {
- wchar_t newPasswd[512], text[512];
- GetDlgItemText(hwndDlg, IDC_NEWPASSWD, newPasswd, _countof(newPasswd));
- GetDlgItemText(hwndDlg, IDC_NEWPASSWD2, text, _countof(text));
- if (mir_wstrcmp(newPasswd, text)) {
- MessageBox(hwndDlg, TranslateT("New password does not match."), TranslateT("Change Password"), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
- break;
- }
- GetDlgItemText(hwndDlg, IDC_OLDPASSWD, text, _countof(text));
- if (mir_wstrcmp(text, ppro->m_ThreadInfo->conn.password)) {
- MessageBox(hwndDlg, TranslateT("Current password is incorrect."), TranslateT("Change Password"), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
- break;
- }
- ppro->m_ThreadInfo->tszNewPassword = mir_wstrdup(newPasswd);
-
- XmlNodeIq iq(ppro->AddIQ(&CJabberProto::OnIqResultSetPassword, JABBER_IQ_TYPE_SET, _A2T(ppro->m_ThreadInfo->conn.server)));
- HXML q = iq << XQUERY(JABBER_FEAT_REGISTER);
- q << XCHILD(L"username", ppro->m_ThreadInfo->conn.username);
- q << XCHILD(L"password", newPasswd);
- ppro->m_ThreadInfo->send(iq);
- }
- DestroyWindow(hwndDlg);
- break;
- case IDCANCEL:
- DestroyWindow(hwndDlg);
- break;
+ return true;
+ }
+
+ bool OnApply() override
+ {
+ if (!m_proto->m_bJabberOnline || m_proto->m_ThreadInfo == nullptr)
+ return false;
+
+ ptrW newPass1(edtPass1.GetText()), newPass2(edtPass2.GetText());
+ if (mir_wstrcmp(newPass1, newPass2)) {
+ MessageBox(m_hwnd, TranslateT("New password does not match."), TranslateT("Change Password"), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
+ return false;
}
- break;
- case WM_CLOSE:
- DestroyWindow(hwndDlg);
- break;
- case WM_DESTROY:
- ppro->m_hwndJabberChangePassword = nullptr;
- Window_FreeIcon_IcoLib(hwndDlg);
- break;
+
+ if (mir_wstrcmp(ptrW(edtOldPass.GetText()), m_proto->m_ThreadInfo->conn.password)) {
+ MessageBox(m_hwnd, TranslateT("Current password is incorrect."), TranslateT("Change Password"), MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
+ return false;
+ }
+ m_proto->m_ThreadInfo->tszNewPassword = newPass1.detach();
+
+ XmlNodeIq iq(m_proto->AddIQ(&CJabberProto::OnIqResultSetPassword, JABBER_IQ_TYPE_SET, _A2T(m_proto->m_ThreadInfo->conn.server)));
+ HXML q = iq << XQUERY(JABBER_FEAT_REGISTER);
+ q << XCHILD(L"username", m_proto->m_ThreadInfo->conn.username);
+ q << XCHILD(L"password", m_proto->m_ThreadInfo->tszNewPassword);
+ m_proto->m_ThreadInfo->send(iq);
+ return true;
+ }
+
+ void OnDestroy() override
+ {
+ m_proto->m_hwndJabberChangePassword = nullptr;
+ Window_FreeIcon_IcoLib(m_hwnd);
}
+};
- return FALSE;
+INT_PTR __cdecl CJabberProto::OnMenuHandleChangePassword(WPARAM, LPARAM)
+{
+ if (IsWindow(m_hwndJabberChangePassword))
+ SetForegroundWindow(m_hwndJabberChangePassword);
+ else
+ (new ChangePasswordDlg(this))->Show();
+
+ return 0;
}