From 2a618df7b4688a6c0d6ca0b9a7d4b297325dcfc5 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 20 Sep 2014 10:55:30 +0000 Subject: code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@10535 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/WhatsApp/res/whatsapp.rc | 4 +- protocols/WhatsApp/src/dialogs.cpp | 104 ++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 54 deletions(-) (limited to 'protocols/WhatsApp') diff --git a/protocols/WhatsApp/res/whatsapp.rc b/protocols/WhatsApp/res/whatsapp.rc index e556992dff..4a7e91ace3 100644 --- a/protocols/WhatsApp/res/whatsapp.rc +++ b/protocols/WhatsApp/res/whatsapp.rc @@ -88,8 +88,8 @@ BEGIN LTEXT "Nickname",IDC_STATIC,6,43,48,12 EDITTEXT IDC_NICK,60,42,119,12,ES_AUTOHSCROLL LTEXT "SMS code",IDC_STATIC,6,62,47,8 - EDITTEXT IDC_PW,60,60,20,12,ES_AUTOHSCROLL - EDITTEXT IDC_PW2,92,60,20,12,ES_AUTOHSCROLL + EDITTEXT IDC_PW,60,60,20,12,ES_AUTOHSCROLL | ES_NUMBER + EDITTEXT IDC_PW2,92,60,20,12,ES_AUTOHSCROLL | ES_NUMBER PUSHBUTTON "Request code",IDC_BUTTON_REQUEST_CODE,13,80,81,18 PUSHBUTTON "Register code",IDC_BUTTON_REGISTER,98,80,81,18 CONTROL "Use SSL connection (443 port)",IDC_SSL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,5,108,173,10 diff --git a/protocols/WhatsApp/src/dialogs.cpp b/protocols/WhatsApp/src/dialogs.cpp index f2b1c94025..6914855e78 100644 --- a/protocols/WhatsApp/src/dialogs.cpp +++ b/protocols/WhatsApp/src/dialogs.cpp @@ -3,59 +3,59 @@ #define szAskSendSms LPGEN("An SMS with registration-code will be sent to your mobile phone.\nNotice that you are not able to use the real WhatsApp and this plugin simultaneously!\nContinue?") #define szPasswordSet LPGEN("Your password has been set automatically. You can proceed with login now") -INT_PTR CALLBACK WhatsAppAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) +INT_PTR CALLBACK WhatsAppAccountProc(HWND hwndDlg, UINT message, WPARAM wparam, LPARAM lparam) { WhatsAppProto *proto; switch (message) { case WM_INITDIALOG: - TranslateDialogDefault(hwnd); + TranslateDialogDefault(hwndDlg); proto = reinterpret_cast(lparam); - SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam); - SendDlgItemMessage(hwnd, IDC_PW, EM_LIMITTEXT, 3, 0); - SendDlgItemMessage(hwnd, IDC_PW2, EM_LIMITTEXT, 3, 0); - CheckDlgButton(hwnd, IDC_SSL, db_get_b(NULL, proto->ModuleName(), WHATSAPP_KEY_SSL, 0)); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lparam); + SendDlgItemMessage(hwndDlg, IDC_PW, EM_LIMITTEXT, 3, 0); + SendDlgItemMessage(hwndDlg, IDC_PW2, EM_LIMITTEXT, 3, 0); + CheckDlgButton(hwndDlg, IDC_SSL, db_get_b(NULL, proto->ModuleName(), WHATSAPP_KEY_SSL, 0)); DBVARIANT dbv; if (!db_get_s(0, proto->ModuleName(), WHATSAPP_KEY_CC, &dbv, DBVT_ASCIIZ)) { - SetDlgItemTextA(hwnd, IDC_CC, dbv.pszVal); + SetDlgItemTextA(hwndDlg, IDC_CC, dbv.pszVal); db_free(&dbv); } if (!db_get_s(0, proto->ModuleName(), WHATSAPP_KEY_LOGIN, &dbv, DBVT_ASCIIZ)) { - SetDlgItemTextA(hwnd, IDC_LOGIN, dbv.pszVal); + SetDlgItemTextA(hwndDlg, IDC_LOGIN, dbv.pszVal); db_free(&dbv); } if (!db_get_s(0, proto->ModuleName(), WHATSAPP_KEY_NICK, &dbv, DBVT_ASCIIZ)) { - SetDlgItemTextA(hwnd, IDC_NICK, dbv.pszVal); + SetDlgItemTextA(hwndDlg, IDC_NICK, dbv.pszVal); db_free(&dbv); } - EnableWindow(GetDlgItem(hwnd, IDC_PW), FALSE); - EnableWindow(GetDlgItem(hwnd, IDC_PW2), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_PW), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_PW2), FALSE); if (!proto->isOffline()) { - SendDlgItemMessage(hwnd, IDC_CC, EM_SETREADONLY, 1, 0); - SendDlgItemMessage(hwnd, IDC_LOGIN, EM_SETREADONLY, 1, 0); - SendDlgItemMessage(hwnd, IDC_NICK, EM_SETREADONLY, 1, 0); - SendDlgItemMessage(hwnd, IDC_PW, EM_SETREADONLY, 1, 0); - SendDlgItemMessage(hwnd, IDC_PW2, EM_SETREADONLY, 1, 0); - EnableWindow(GetDlgItem(hwnd, IDC_SSL), FALSE); + SendDlgItemMessage(hwndDlg, IDC_CC, EM_SETREADONLY, 1, 0); + SendDlgItemMessage(hwndDlg, IDC_LOGIN, EM_SETREADONLY, 1, 0); + SendDlgItemMessage(hwndDlg, IDC_NICK, EM_SETREADONLY, 1, 0); + SendDlgItemMessage(hwndDlg, IDC_PW, EM_SETREADONLY, 1, 0); + SendDlgItemMessage(hwndDlg, IDC_PW2, EM_SETREADONLY, 1, 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_SSL), FALSE); } return TRUE; case WM_COMMAND: if (LOWORD(wparam) == IDC_BUTTON_REQUEST_CODE || LOWORD(wparam) == IDC_BUTTON_REGISTER) { - proto = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); + proto = reinterpret_cast(GetWindowLongPtr(hwndDlg, GWLP_USERDATA)); string password; char cc[5]; - GetDlgItemTextA(hwnd, IDC_CC, cc, sizeof(cc)); + GetDlgItemTextA(hwndDlg, IDC_CC, cc, sizeof(cc)); char number[128]; - GetDlgItemTextA(hwnd, IDC_LOGIN, number, sizeof(number)); + GetDlgItemTextA(hwndDlg, IDC_LOGIN, number, sizeof(number)); if (LOWORD(wparam) == IDC_BUTTON_REQUEST_CODE) { if (IDYES == MessageBox(NULL, TranslateT(szAskSendSms), PRODUCT_NAME, MB_YESNO)) { @@ -65,23 +65,23 @@ INT_PTR CALLBACK WhatsAppAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPA proto->setString(WHATSAPP_KEY_PASS, password.c_str()); } else { - EnableWindow(GetDlgItem(hwnd, IDC_PW), TRUE); // unblock sms code entry field - EnableWindow(GetDlgItem(hwnd, IDC_PW2), TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_PW), TRUE); // unblock sms code entry field + EnableWindow(GetDlgItem(hwndDlg, IDC_PW2), TRUE); } } } } else if (LOWORD(wparam) == IDC_BUTTON_REGISTER) { - char code[100], str[10]; - GetDlgItemTextA(hwnd, IDC_PW, code, sizeof(code)); - GetDlgItemTextA(hwnd, IDC_PW2, str, sizeof(str)); - strcat(code, str); - - if (strlen(code) != 6) { + HWND hwnd1 = GetDlgItem(hwndDlg, IDC_PW), hwnd2 = GetDlgItem(hwndDlg, IDC_PW2); + if (GetWindowTextLength(hwnd1) != 3 || GetWindowTextLength(hwnd2) != 3) { MessageBox(NULL, TranslateT("Please correctly specify your registration code received by SMS"), PRODUCT_NAME, MB_ICONEXCLAMATION); return TRUE; } + char code[10]; + GetWindowTextA(hwnd1, code, 4); + GetWindowTextA(hwnd2, code + 3, 4); + if (proto->Register(REG_STATE_REG_CODE, string(cc), string(number), string(code), password)) { proto->setString(WHATSAPP_KEY_PASS, password.c_str()); MessageBox(NULL, TranslateT(szPasswordSet), PRODUCT_NAME, MB_ICONWARNING); @@ -97,26 +97,26 @@ INT_PTR CALLBACK WhatsAppAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPA case IDC_SSL: case IDC_PW: case IDC_PW2: - SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } } break; case WM_NOTIFY: if (reinterpret_cast(lparam)->code == PSN_APPLY) { - proto = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); + proto = reinterpret_cast(GetWindowLongPtr(hwndDlg, GWLP_USERDATA)); char str[128]; - GetDlgItemTextA(hwnd, IDC_CC, str, sizeof(str)); + GetDlgItemTextA(hwndDlg, IDC_CC, str, sizeof(str)); db_set_s(0, proto->ModuleName(), WHATSAPP_KEY_CC, str); - GetDlgItemTextA(hwnd, IDC_LOGIN, str, sizeof(str)); + GetDlgItemTextA(hwndDlg, IDC_LOGIN, str, sizeof(str)); db_set_s(0, proto->ModuleName(), WHATSAPP_KEY_LOGIN, str); - GetDlgItemTextA(hwnd, IDC_NICK, str, sizeof(str)); + GetDlgItemTextA(hwndDlg, IDC_NICK, str, sizeof(str)); db_set_s(0, proto->ModuleName(), WHATSAPP_KEY_NICK, str); - db_set_b(0, proto->ModuleName(), WHATSAPP_KEY_SSL, IsDlgButtonChecked(hwnd, IDC_SSL)); + db_set_b(0, proto->ModuleName(), WHATSAPP_KEY_SSL, IsDlgButtonChecked(hwndDlg, IDC_SSL)); return TRUE; } break; @@ -126,57 +126,57 @@ INT_PTR CALLBACK WhatsAppAccountProc(HWND hwnd, UINT message, WPARAM wparam, LPA return FALSE; } -INT_PTR CALLBACK WhatsAppInputBoxProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) +INT_PTR CALLBACK WhatsAppInputBoxProc(HWND hwndDlg, UINT message, WPARAM wparam, LPARAM lparam) { input_box* ib; switch (message) { case WM_INITDIALOG: - TranslateDialogDefault(hwnd); + TranslateDialogDefault(hwndDlg); ib = reinterpret_cast(lparam); - SetWindowLongPtr(hwnd, GWLP_USERDATA, lparam); - SendDlgItemMessage(hwnd, IDC_VALUE, EM_LIMITTEXT, ib->limit, 0); - SetDlgItemText(hwnd, IDC_VALUE, ib->defaultValue.c_str()); - SetDlgItemText(hwnd, IDC_TEXT, ib->text.c_str()); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lparam); + SendDlgItemMessage(hwndDlg, IDC_VALUE, EM_LIMITTEXT, ib->limit, 0); + SetDlgItemText(hwndDlg, IDC_VALUE, ib->defaultValue.c_str()); + SetDlgItemText(hwndDlg, IDC_TEXT, ib->text.c_str()); - SetWindowText(hwnd, ib->title.c_str()); + SetWindowText(hwndDlg, ib->title.c_str()); - EnableWindow(GetDlgItem(hwnd, IDC_OK), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_OK), FALSE); return TRUE; case WM_COMMAND: if (LOWORD(wparam) == IDC_VALUE && HIWORD(wparam) == EN_CHANGE) { - ib = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); - size_t len = SendDlgItemMessage(hwnd, IDC_VALUE, WM_GETTEXTLENGTH, 0, 0); + ib = reinterpret_cast(GetWindowLongPtr(hwndDlg, GWLP_USERDATA)); + size_t len = SendDlgItemMessage(hwndDlg, IDC_VALUE, WM_GETTEXTLENGTH, 0, 0); TCHAR str[4]; mir_sntprintf(str, 4, TEXT("%d"), ib->limit - len); - //SetDlgItemText(hwnd,IDC_CHARACTERS,str); + //SetDlgItemText(hwndDlg,IDC_CHARACTERS,str); - EnableWindow(GetDlgItem(hwnd, IDC_OK), len > 0); + EnableWindow(GetDlgItem(hwndDlg, IDC_OK), len > 0); return TRUE; } if (LOWORD(wparam) == IDC_OK) { - ib = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); + ib = reinterpret_cast(GetWindowLongPtr(hwndDlg, GWLP_USERDATA)); TCHAR* value = new TCHAR[ib->limit + 1]; - GetDlgItemText(hwnd, IDC_VALUE, value, ib->limit + 1); - ShowWindow(hwnd, SW_HIDE); + GetDlgItemText(hwndDlg, IDC_VALUE, value, ib->limit + 1); + ShowWindow(hwndDlg, SW_HIDE); input_box_ret* ret = new input_box_ret; ret->userData = ib->userData; ret->value = mir_utf8encodeT(value); delete value; ib->proto->ForkThread(ib->thread, ret); - EndDialog(hwnd, wparam); + EndDialog(hwndDlg, wparam); delete ib; return TRUE; } if (LOWORD(wparam) == IDC_CANCEL) { - EndDialog(hwnd, wparam); - ib = reinterpret_cast(GetWindowLongPtr(hwnd, GWLP_USERDATA)); + EndDialog(hwndDlg, wparam); + ib = reinterpret_cast(GetWindowLongPtr(hwndDlg, GWLP_USERDATA)); delete ib; return TRUE; } -- cgit v1.2.3