diff options
author | Tobias Weimer <wishmaster51@googlemail.com> | 2015-10-17 14:58:29 +0000 |
---|---|---|
committer | Tobias Weimer <wishmaster51@googlemail.com> | 2015-10-17 14:58:29 +0000 |
commit | 6f9167b69872efc9c6d14daa8987d0ab51a5408e (patch) | |
tree | 8234a47381bc6efd2aeb91dd7ebdabadacf6594f /plugins/MirOTR | |
parent | 201d4c2175aab1032564893022e618098e81225d (diff) |
MirOTR:
- Fixed Apply button in options
- Fixed per contact policy (fixes #1070)
- Other bug fixes
git-svn-id: http://svn.miranda-ng.org/main/trunk@15568 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/MirOTR')
-rw-r--r-- | plugins/MirOTR/src/dialogs.cpp | 198 | ||||
-rw-r--r-- | plugins/MirOTR/src/options.cpp | 32 | ||||
-rw-r--r-- | plugins/MirOTR/src/utils.cpp | 6 |
3 files changed, 113 insertions, 123 deletions
diff --git a/plugins/MirOTR/src/dialogs.cpp b/plugins/MirOTR/src/dialogs.cpp index f2401f10d7..2af5c8fd56 100644 --- a/plugins/MirOTR/src/dialogs.cpp +++ b/plugins/MirOTR/src/dialogs.cpp @@ -12,7 +12,7 @@ typedef std::map<HANDLE, SmpData> SmpForContactMap; SmpForContactMap smp_for_contact; -INT_PTR CALLBACK DlgSMPUpdateProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK DlgSMPUpdateProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: { @@ -145,7 +145,7 @@ INT_PTR CALLBACK DlgSMPUpdateProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM return FALSE; } -void SMPInitUpdateDialog(ConnContext *context, bool responder) +static void SMPInitUpdateDialog(ConnContext *context, bool responder) { if (!context) return; SmpData *data = (SmpData*)mir_calloc(sizeof(SmpData)); @@ -155,7 +155,7 @@ void SMPInitUpdateDialog(ConnContext *context, bool responder) CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SMP_PROGRESS), 0, DlgSMPUpdateProc, (LPARAM)data); } -INT_PTR CALLBACK DlgSMPResponseProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK DlgSMPResponseProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_DESTROY: { @@ -231,11 +231,11 @@ INT_PTR CALLBACK DlgSMPResponseProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA // Move window to screen center // Get the owner window and dialog box rectangles. - HWND hwndOwner; RECT rcOwner, rcDlg, rc; - if ((hwndOwner = GetParent(hwndDlg)) == NULL) { + HWND hwndOwner = GetParent(hwndDlg); + if (hwndOwner == NULL) hwndOwner = GetDesktopWindow(); - } + RECT rcOwner, rcDlg, rc; GetWindowRect(hwndOwner, &rcOwner); GetWindowRect(hwndDlg, &rcDlg); CopyRect(&rc, &rcOwner); @@ -259,9 +259,6 @@ INT_PTR CALLBACK DlgSMPResponseProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA SWP_NOSIZE); // end center dialog - - - return TRUE; } @@ -310,7 +307,7 @@ void SMPInitResponseDialog(ConnContext *context, const TCHAR *question) { } */ -INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: @@ -337,11 +334,11 @@ INT_PTR CALLBACK DlgProcSMPInitProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA // Move window to screen center // Get the owner window and dialog box rectangles. - HWND hwndOwner; RECT rcOwner, rcDlg, rc; - if ((hwndOwner = GetParent(hwndDlg)) == NULL) { + HWND hwndOwner = GetParent(hwndDlg); + if (hwndOwner == NULL) hwndOwner = GetDesktopWindow(); - } + RECT rcOwner, rcDlg, rc; GetWindowRect(hwndOwner, &rcOwner); GetWindowRect(hwndDlg, &rcDlg); CopyRect(&rc, &rcOwner); @@ -621,97 +618,90 @@ void SMPDialogReply(ConnContext *context, const char* question) //otr_continue_smp(context, pass, mir_strlen(pass)); } -unsigned int CALLBACK verify_context_thread(void *param); -void VerifyContextDialog(ConnContext* context) -{ - if (!context) return; - CloseHandle((HANDLE)_beginthreadex(0, 0, verify_context_thread, context, 0, 0)); -} - -INT_PTR CALLBACK DlgBoxProcVerifyContext(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK DlgBoxProcVerifyContext(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: - { - if (!lParam) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - SetWindowText(hwndDlg, _T(LANG_OTR_FPVERIFY_TITLE)); - SetDlgItemText(hwndDlg, IDC_STC_SMP_HEAD, _T(LANG_OTR_FPVERIFY_TITLE)); - TranslateDialogDefault(hwndDlg); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - - // Move window to screen center - // Get the owner window and dialog box rectangles. - HWND hwndOwner; RECT rcOwner, rcDlg, rc; - if ((hwndOwner = GetParent(hwndDlg)) == NULL) { - hwndOwner = GetDesktopWindow(); - } - - GetWindowRect(hwndOwner, &rcOwner); - GetWindowRect(hwndDlg, &rcDlg); - CopyRect(&rc, &rcOwner); - - // Offset the owner and dialog box rectangles so that right and bottom - // values represent the width and height, and then offset the owner again - // to discard space taken up by the dialog box. - - OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); - OffsetRect(&rc, -rc.left, -rc.top); - OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); - - // The new position is the sum of half the remaining space and the owner's - // original position. - - SetWindowPos(hwndDlg, - HWND_TOP, - rcOwner.left + (rc.right / 2), - rcOwner.top + (rc.bottom / 2), - 0, 0, // Ignores size arguments. - SWP_NOSIZE); - - // end center dialog - - ConnContext *context = (ConnContext*)lParam; - MCONTACT hContact = (UINT_PTR)context->app_data; - Fingerprint *fp = context->active_fingerprint; - if (!fp) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - TCHAR buff[512]; - if (!fp->trust || fp->trust[0] == '\0') - mir_sntprintf(buff, TranslateT(LANG_OTR_FPVERIFY_DESC), contact_get_nameT(hContact)); - else - mir_sntprintf(buff, TranslateT(LANG_OTR_FPVERIFIED_DESC), contact_get_nameT(hContact)); - - SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); - - unsigned char hash[20]; - lib_cs_lock(); - if (!otrl_privkey_fingerprint_raw(otr_user_state, hash, context->accountname, context->protocol)) { - EndDialog(hwndDlg, IDCANCEL); - return FALSE; - } - otrl_privkey_hash_to_humanT(buff, hash); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_YOUR_PRIVKEY)); - - otrl_privkey_hash_to_humanT(buff, fp->fingerprint); - SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, buff); - SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, TRUE, 0); - SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_CONTACT_FINGERPRINT)); - - EnableWindow(GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE), FALSE); - - ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_SHOWNA); - ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_SHOWNA); - SetFocus(GetDlgItem(hwndDlg, IDCANCEL)); + { + if (!lParam) { + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + SetWindowText(hwndDlg, _T(LANG_OTR_FPVERIFY_TITLE)); + SetDlgItemText(hwndDlg, IDC_STC_SMP_HEAD, _T(LANG_OTR_FPVERIFY_TITLE)); + TranslateDialogDefault(hwndDlg); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + + // Move window to screen center + // Get the owner window and dialog box rectangles. + HWND hwndOwner = GetParent(hwndDlg); + if (hwndOwner == NULL) + hwndOwner = GetDesktopWindow(); + + RECT rcOwner, rcDlg, rc; + GetWindowRect(hwndOwner, &rcOwner); + GetWindowRect(hwndDlg, &rcDlg); + CopyRect(&rc, &rcOwner); + + // Offset the owner and dialog box rectangles so that right and bottom + // values represent the width and height, and then offset the owner again + // to discard space taken up by the dialog box. + + OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); + OffsetRect(&rc, -rc.left, -rc.top); + OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); + + // The new position is the sum of half the remaining space and the owner's + // original position. + + SetWindowPos(hwndDlg, + HWND_TOP, + rcOwner.left + (rc.right / 2), + rcOwner.top + (rc.bottom / 2), + 0, 0, // Ignores size arguments. + SWP_NOSIZE); + + // end center dialog + + ConnContext *context = (ConnContext*)lParam; + MCONTACT hContact = (UINT_PTR)context->app_data; + Fingerprint *fp = context->active_fingerprint; + if (!fp) { + EndDialog(hwndDlg, IDCANCEL); + return FALSE; } - return FALSE; + TCHAR buff[512]; + if (!fp->trust || fp->trust[0] == '\0') + mir_sntprintf(buff, TranslateT(LANG_OTR_FPVERIFY_DESC), contact_get_nameT(hContact)); + else + mir_sntprintf(buff, TranslateT(LANG_OTR_FPVERIFIED_DESC), contact_get_nameT(hContact)); + + SetDlgItemText(hwndDlg, IDC_STC_SMP_INFO, buff); + + unsigned char hash[20]; + lib_cs_lock(); + if (!otrl_privkey_fingerprint_raw(otr_user_state, hash, context->accountname, context->protocol)) { + EndDialog(hwndDlg, IDCANCEL); + return FALSE; + } + otrl_privkey_hash_to_humanT(buff, hash); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD1, buff); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD1, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD1, TranslateT(LANG_YOUR_PRIVKEY)); + + otrl_privkey_hash_to_humanT(buff, fp->fingerprint); + SetDlgItemText(hwndDlg, IDC_EDT_SMP_FIELD2, buff); + SendDlgItemMessage(hwndDlg, IDC_EDT_SMP_FIELD2, EM_SETREADONLY, TRUE, 0); + SetDlgItemText(hwndDlg, IDC_STC_SMP_FIELD2, TranslateT(LANG_CONTACT_FINGERPRINT)); + + EnableWindow(GetDlgItem(hwndDlg, IDC_CBO_SMP_CHOOSE), FALSE); + + ShowWindow(GetDlgItem(hwndDlg, IDOK), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDYES), SW_SHOWNA); + ShowWindow(GetDlgItem(hwndDlg, IDNO), SW_SHOWNA); + SetFocus(GetDlgItem(hwndDlg, IDCANCEL)); + } + return FALSE; case WM_COMMAND: switch (HIWORD(wParam)) { @@ -732,7 +722,7 @@ INT_PTR CALLBACK DlgBoxProcVerifyContext(HWND hwndDlg, UINT msg, WPARAM wParam, return FALSE; } -unsigned int CALLBACK verify_context_thread(void *param) +static unsigned int CALLBACK verify_context_thread(void *param) { Thread_Push(0); @@ -765,3 +755,9 @@ unsigned int CALLBACK verify_context_thread(void *param) Thread_Pop(); return 0; } + +void VerifyContextDialog(ConnContext* context) +{ + if (!context) return; + CloseHandle((HANDLE)_beginthreadex(0, 0, verify_context_thread, context, 0, 0)); +} diff --git a/plugins/MirOTR/src/options.cpp b/plugins/MirOTR/src/options.cpp index 217e535f07..ae2e741ee9 100644 --- a/plugins/MirOTR/src/options.cpp +++ b/plugins/MirOTR/src/options.cpp @@ -21,17 +21,9 @@ void SetFilenames(const TCHAR *path) return; CreateDirectoryTreeT(path); - mir_tstrcpy(g_private_key_filename, path); - mir_tstrcat(g_private_key_filename, _T("\\")); - mir_tstrcat(g_private_key_filename, _T(PRIVATE_KEY_FILENAME)); - - mir_tstrcpy(g_fingerprint_store_filename, path); - mir_tstrcat(g_fingerprint_store_filename, _T("\\")); - mir_tstrcat(g_fingerprint_store_filename, _T(FINGERPRINT_STORE_FILENAME)); - - mir_tstrcpy(g_instag_filename, path); - mir_tstrcat(g_instag_filename, _T("\\")); - mir_tstrcat(g_instag_filename, _T(INSTAG_FILENAME)); + mir_sntprintf(g_private_key_filename, _T("%s\\") _T(PRIVATE_KEY_FILENAME), path); + mir_sntprintf(g_fingerprint_store_filename, _T("%s\\") _T(FINGERPRINT_STORE_FILENAME), path); + mir_sntprintf(g_instag_filename, _T("%s\\") _T(INSTAG_FILENAME), path); } int FoldersChanged(WPARAM wParam, LPARAM lParam) @@ -137,9 +129,11 @@ void ReadPrivkeyFiles() static INT_PTR CALLBACK DlgProcMirOTROpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { + static bool bInit = true; TCHAR *prefix; switch ( msg ) { case WM_INITDIALOG: + bInit = false; TranslateDialogDefault( hwndDlg ); // set default policy radio @@ -170,7 +164,8 @@ static INT_PTR CALLBACK DlgProcMirOTROpts(HWND hwndDlg, UINT msg, WPARAM wParam, prefix = mir_utf8decodeT(options.prefix); SetDlgItemText(hwndDlg, IDC_ED_PREFIX, prefix); mir_free(prefix); - return TRUE; + bInit = true; + return FALSE; case WM_COMMAND: switch ( HIWORD( wParam )) { @@ -187,11 +182,12 @@ static INT_PTR CALLBACK DlgProcMirOTROpts(HWND hwndDlg, UINT msg, WPARAM wParam, case IDC_CHK_AUTOSHOW_VERIFY: case IDC_CHK_ENDOFFLINE: case IDC_CHK_ENDCLOSE: - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + if (bInit) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } break; case EN_CHANGE: - if (LOWORD( wParam ) == IDC_ED_PREFIX && ( HWND )lParam == GetFocus()) + if ((LOWORD( wParam ) == IDC_ED_PREFIX) && bInit) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; } @@ -526,7 +522,6 @@ static INT_PTR CALLBACK DlgProcMirOTROptsContacts(HWND hwndDlg, UINT msg, WPARAM case CBN_SELCHANGE: switch (LOWORD(wParam)) { case IDC_CMB_CONT_POLICY: - MCONTACT hContact = 0; int iUser = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS)); if (iUser == -1) break; int sel = SendDlgItemMessage(hwndDlg, IDC_CMB_CONT_POLICY, CB_GETCURSEL, 0, 0); @@ -546,7 +541,7 @@ static INT_PTR CALLBACK DlgProcMirOTROptsContacts(HWND hwndDlg, UINT msg, WPARAM ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_CONT_CONTACTS), &lvi); ContactPolicyMap* cpm = (ContactPolicyMap*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - hContact = (MCONTACT)lvi.lParam; + MCONTACT hContact = (MCONTACT)lvi.lParam; (*cpm)[hContact].policy = policy; SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; @@ -564,8 +559,8 @@ static INT_PTR CALLBACK DlgProcMirOTROptsContacts(HWND hwndDlg, UINT msg, WPARAM // Using a const_iterator since we are not going to change the values. for (ContactPolicyMap::const_iterator it = cpm->begin(); it != cpm->end(); ++it) { if (!it->first) continue; - if (it->second.policy) db_set_dw(it->first, MODULENAME, "Policy", (DWORD)it->second.policy); - if (it->second.htmlconv) db_set_b(it->first, MODULENAME, "HTMLConv", it->second.htmlconv - 1); + db_set_dw(it->first, MODULENAME, "Policy", (DWORD)it->second.policy); + db_set_b(it->first, MODULENAME, "HTMLConv", it->second.htmlconv); } return TRUE; } @@ -604,7 +599,6 @@ static INT_PTR CALLBACK DlgProcMirOTROptsContacts(HWND hwndDlg, UINT msg, WPARAM (*cp)[hContact].htmlconv = HTMLCONV_ENABLE; ListView_SetItemText(((LPNMHDR)lParam)->hwndFrom, lvi.iItem, 3, TranslateT(LANG_YES)); } - (*cp)[hContact].htmlconv += 1; SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } } diff --git a/plugins/MirOTR/src/utils.cpp b/plugins/MirOTR/src/utils.cpp index f61738deeb..234f21cd1c 100644 --- a/plugins/MirOTR/src/utils.cpp +++ b/plugins/MirOTR/src/utils.cpp @@ -118,14 +118,14 @@ char* contact_get_id(MCONTACT hContact, bool bNameOnError) { } } if (!pszUniqueID && bNameOnError) { - char *name = (char *)pcli->pfnGetContactDisplayName(hContact, 0); - if (name) pszUniqueID = mir_strdup(name); + const TCHAR *name = pcli->pfnGetContactDisplayName(hContact, 0); + if (name) pszUniqueID = mir_t2a(name); } return pszUniqueID; } __inline const TCHAR* contact_get_nameT(MCONTACT hContact) { - return (TCHAR*)pcli->pfnGetContactDisplayName(hContact, 0); + return pcli->pfnGetContactDisplayName(hContact, 0); } TCHAR* ProtoGetNickname(const char* proto) |