From 8ffc24f829fa99cc1c089193aa4b1e67e4f69dfd Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 9 Dec 2013 17:41:17 +0000 Subject: VKontakte: - option added to support server message delivery confirmations; - separate dialog procedure for options; - version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@7110 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/VKontakte/res/resource.rc | 23 +++++---- protocols/VKontakte/src/resource.h | 5 +- protocols/VKontakte/src/version.h | 2 +- protocols/VKontakte/src/vk_options.cpp | 78 +++++++++++++++++++++++++++++-- protocols/VKontakte/src/vk_proto.cpp | 29 ++++++++---- protocols/VKontakte/src/vk_proto.h | 9 ++-- protocols/VKontakte/src/vk_queue.cpp | 6 +-- protocols/VKontakte/vk_10.vcxproj | 3 ++ protocols/VKontakte/vk_10.vcxproj.filters | 5 ++ 9 files changed, 131 insertions(+), 29 deletions(-) (limited to 'protocols/VKontakte') diff --git a/protocols/VKontakte/res/resource.rc b/protocols/VKontakte/res/resource.rc index aa8ad7adee..6f80403b35 100644 --- a/protocols/VKontakte/res/resource.rc +++ b/protocols/VKontakte/res/resource.rc @@ -35,16 +35,19 @@ BEGIN CONTROL "Open VKontakte site",IDC_URL,"Hyperlink",WS_TABSTOP,0,49,174,12 END -IDD_OPT_MAIN DIALOGEX 0, 0, 186, 68 +IDD_OPT_MAIN DIALOGEX 0, 0, 304, 222 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN - LTEXT "E-mail or phone number:",IDC_STATIC,0,0,95,12 - EDITTEXT IDC_LOGIN,96,0,89,12,ES_AUTOHSCROLL - LTEXT "Password:",IDC_STATIC,0,16,94,12 - EDITTEXT IDC_PASSWORD,95,16,90,12,ES_PASSWORD | ES_AUTOHSCROLL - CONTROL "Open VKontakte site",IDC_URL,"Hyperlink",WS_TABSTOP,0,49,174,12 + LTEXT "E-mail or phone number:",IDC_STATIC,51,23,95,12 + EDITTEXT IDC_LOGIN,147,23,89,12,ES_AUTOHSCROLL + LTEXT "Password:",IDC_STATIC,51,39,94,12 + EDITTEXT IDC_PASSWORD,147,39,90,12,ES_PASSWORD | ES_AUTOHSCROLL + CONTROL "Open VKontakte site",IDC_URL,"Hyperlink",WS_TABSTOP,59,55,174,12 + GROUPBOX "Login settings",IDC_STATIC,4,7,293,65 + GROUPBOX "Advanced",IDC_STATIC,4,74,293,143 + CONTROL "Server-side delivery confirmation",IDC_DELIVERY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,87,278,10 END IDD_CAPTCHAFORM DIALOGEX 0, 0, 258, 224 @@ -63,6 +66,7 @@ BEGIN PUSHBUTTON "Cancel",IDCANCEL,200,203,50,14 END + ///////////////////////////////////////////////////////////////////////////// // // Icon @@ -70,7 +74,6 @@ END // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. - IDI_KEYS ICON "key.ico" ///////////////////////////////////////////////////////////////////////////// @@ -87,10 +90,12 @@ BEGIN TOPMARGIN, 7 END - IDD_OPT_MAIN, DIALOG + IDD_OPT_MAIN, DIALOG BEGIN - LEFTMARGIN, 7 + LEFTMARGIN, 4 + RIGHTMARGIN, 297 TOPMARGIN, 7 + BOTTOMMARGIN, 217 END END #endif // APSTUDIO_INVOKED diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h index 4c42557a15..ef19487943 100644 --- a/protocols/VKontakte/src/resource.h +++ b/protocols/VKontakte/src/resource.h @@ -16,15 +16,16 @@ #define IDC_FRAME1 1008 #define IDC_FRAME2 1009 #define IDC_SUBMIT 1010 +#define IDC_DELIVERY 1011 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 #define _APS_NEXT_RESOURCE_VALUE 104 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1011 +#define _APS_NEXT_CONTROL_VALUE 1012 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/VKontakte/src/version.h b/protocols/VKontakte/src/version.h index e6a040d582..d7946b1520 100644 --- a/protocols/VKontakte/src/version.h +++ b/protocols/VKontakte/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 1 #define __RELEASE_NUM 0 -#define __BUILD_NUM 5 +#define __BUILD_NUM 6 #define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM diff --git a/protocols/VKontakte/src/vk_options.cpp b/protocols/VKontakte/src/vk_options.cpp index ae722029c4..2cd9558fa9 100644 --- a/protocols/VKontakte/src/vk_options.cpp +++ b/protocols/VKontakte/src/vk_options.cpp @@ -94,19 +94,91 @@ INT_PTR CVkProto::SvcCreateAccMgrUI(WPARAM wParam, LPARAM lParam) ////////////////////////////////////////////////////////////////////////////// // Options +INT_PTR CALLBACK CVkProto::OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + CVkProto* ppro = (CVkProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + + switch (uMsg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + + ppro = (CVkProto*)lParam; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); + + SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIconByHandle(ppro->m_hProtoIcon, true)); + SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIconByHandle(ppro->m_hProtoIcon)); + { + ptrT tszLogin(ppro->getTStringA("Login")); + if (tszLogin != NULL) + SetDlgItemText(hwndDlg, IDC_LOGIN, tszLogin); + + ptrT tszPassw(ppro->GetUserStoredPassword()); + if (tszPassw != NULL) + SetDlgItemText(hwndDlg, IDC_PASSWORD, tszPassw); + } + CheckDlgButton(hwndDlg, IDC_DELIVERY, ppro->m_bServerDelivery); + return TRUE; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_URL: + CallService(MS_UTILS_OPENURL, 1, (LPARAM)"http://www.vk.com"); + break; + + case IDC_LOGIN: + case IDC_PASSWORD: + if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + + case IDC_DELIVERY: + if (HIWORD(wParam) == BN_CLICKED && (HWND)lParam == GetFocus()) + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + break; + + case WM_NOTIFY: + if (((LPNMHDR)lParam)->code == PSN_APPLY) { + TCHAR str[128]; + GetDlgItemText(hwndDlg, IDC_LOGIN, str, SIZEOF(str)); + ppro->setTString("Login", str); + + GetDlgItemText(hwndDlg, IDC_PASSWORD, str, SIZEOF(str)); + ptrA szRawPasswd(mir_utf8encodeT(str)); + if (szRawPasswd != NULL) + ppro->setString("Password", szRawPasswd); + + ppro->m_bServerDelivery = IsDlgButtonChecked(hwndDlg, IDC_DELIVERY) == BST_CHECKED; + ppro->setByte("ServerDelivery", ppro->m_bServerDelivery); + } + break; + + case WM_CLOSE: + EndDialog(hwndDlg, 0); + break; + + case WM_DESTROY: + Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_GETICON, ICON_BIG, 0)); + Skin_ReleaseIcon((HICON)SendMessage(hwndDlg, WM_GETICON, ICON_SMALL, 0)); + break; + } + + return FALSE; +} + int CVkProto::OnOptionsInit(WPARAM wParam, LPARAM lParam) { - OPTIONSDIALOGPAGE odp = {sizeof(odp)}; + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; odp.hInstance = hInst; odp.ptszTitle = m_tszUserName; odp.dwInitParam = LPARAM(this); odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR | ODPF_DONTTRANSLATE; - odp.position = 1; odp.ptszGroup = LPGENT("Network"); odp.ptszTab = LPGENT("Account"); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MAIN); - odp.pfnDlgProc = VKAccountProc; + odp.pfnDlgProc = &CVkProto::OptionsProc; Options_AddPage(wParam, &odp); return 0; } diff --git a/protocols/VKontakte/src/vk_proto.cpp b/protocols/VKontakte/src/vk_proto.cpp index 12f160d169..1ca293af8f 100644 --- a/protocols/VKontakte/src/vk_proto.cpp +++ b/protocols/VKontakte/src/vk_proto.cpp @@ -49,6 +49,8 @@ CVkProto::CVkProto(const char *szModuleName, const TCHAR *ptszUserName) : db_set_resident(m_szModuleName, "Status"); + m_bServerDelivery = getBool("ServerDelivery", true); + // Set all contacts offline -- in case we crashed SetAllContactStatuses(ID_STATUS_OFFLINE); } @@ -153,23 +155,34 @@ int CVkProto::SendMsg(HANDLE hContact, int flags, const char *msg) { "message", szMsg }, { "access_token", m_szAccessToken } }; - PushAsyncHttpRequest(REQUEST_GET, "/method/messages.send.json", true, &CVkProto::OnSendMessage, SIZEOF(params), params); ULONG msgId = ::InterlockedIncrement(&m_msgId); - ForkThread(&CVkProto::SendMsgAck, new TFakeAckParams(hContact, msgId)); + AsyncHttpRequest *pReq = PushAsyncHttpRequest(REQUEST_GET, "/method/messages.send.json", true, &CVkProto::OnSendMessage, SIZEOF(params), params); + pReq->pData = (char*)hContact; + pReq->pUserInfo = (void*)msgId; + + if (!m_bServerDelivery) + ForkThread(&CVkProto::SendMsgAck, new TFakeAckParams(hContact, msgId)); return msgId; } void CVkProto::OnSendMessage(NETLIBHTTPREQUEST *reply, AsyncHttpRequest *pReq) { + int iResult = ACKRESULT_FAILED; + debugLogA("CVkProto::OnSendMessage %d", reply->resultCode); - if (reply->resultCode != 200) - return; + if (reply->resultCode == 200) { + JSONROOT pRoot; + JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot); + if (pResponse != NULL) { + m_sendIds.insert((HANDLE)json_as_int(pResponse)); + iResult = ACKRESULT_SUCCESS; + } + } - JSONROOT pRoot; - JSONNODE *pResponse = CheckJsonResponse(pReq, reply, pRoot); - if (pResponse != NULL) - m_sendIds.insert((HANDLE)json_as_int(pResponse)); + if (m_bServerDelivery) + ProtoBroadcastAck(pReq->pData, ACKTYPE_MESSAGE, iResult, pReq->pUserInfo, 0); + pReq->pData = NULL; } ////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h index 1f00a1f0d9..9f4d9f29fe 100644 --- a/protocols/VKontakte/src/vk_proto.h +++ b/protocols/VKontakte/src/vk_proto.h @@ -136,7 +136,7 @@ private: CMStringA m_prevUrl; HANDLE m_evRequestsQueue; HANDLE m_hWorkerThread; - bool m_bTerminated; + bool m_bTerminated, m_bServerDelivery; struct Cookie { @@ -155,10 +155,11 @@ private: void InitQueue(); void UninitQueue(); void ExecuteRequest(AsyncHttpRequest*); - bool PushAsyncHttpRequest(int iRequestType, LPCSTR szUrl, bool bSecure, VK_REQUEST_HANDLER pFunc, int nParams = 0, HttpParam *pParams = 0, int iTimeout = 10000); - bool PushAsyncHttpRequest(AsyncHttpRequest*, int iTimeout = 10000); void __cdecl WorkerThread(void*); + AsyncHttpRequest* PushAsyncHttpRequest(int iRequestType, LPCSTR szUrl, bool bSecure, VK_REQUEST_HANDLER pFunc, int nParams = 0, HttpParam *pParams = 0, int iTimeout = 10000); + AsyncHttpRequest* PushAsyncHttpRequest(AsyncHttpRequest*, int iTimeout = 10000); + bool RunCaptchaForm(LPCSTR szUrl, CMStringA&); bool AutoFillForm(char*, CMStringA&, CMStringA&); @@ -194,4 +195,6 @@ private: LIST m_sendIds; bool CheckMid(int msgid); + + static INT_PTR CALLBACK OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); }; diff --git a/protocols/VKontakte/src/vk_queue.cpp b/protocols/VKontakte/src/vk_queue.cpp index 144a54fdf2..f110626011 100644 --- a/protocols/VKontakte/src/vk_queue.cpp +++ b/protocols/VKontakte/src/vk_queue.cpp @@ -55,7 +55,7 @@ LBL_Restart: ///////////////////////////////////////////////////////////////////////////////////////// -bool CVkProto::PushAsyncHttpRequest(int iRequestType, LPCSTR szUrl, bool bSecure, VK_REQUEST_HANDLER pFunc, int nParams, HttpParam *pParams, int iTimeout) +AsyncHttpRequest* CVkProto::PushAsyncHttpRequest(int iRequestType, LPCSTR szUrl, bool bSecure, VK_REQUEST_HANDLER pFunc, int nParams, HttpParam *pParams, int iTimeout) { AsyncHttpRequest *pReq = new AsyncHttpRequest(); pReq->flags = NLHRF_NODUMPHEADERS | NLHRF_DUMPASTEXT | NLHRF_HTTP11 | NLHRF_REDIRECT; @@ -83,7 +83,7 @@ bool CVkProto::PushAsyncHttpRequest(int iRequestType, LPCSTR szUrl, bool bSecure return PushAsyncHttpRequest(pReq, iTimeout); } -bool CVkProto::PushAsyncHttpRequest(AsyncHttpRequest *pReq, int iTimeout) +AsyncHttpRequest* CVkProto::PushAsyncHttpRequest(AsyncHttpRequest *pReq, int iTimeout) { pReq->timeout = iTimeout; { @@ -91,7 +91,7 @@ bool CVkProto::PushAsyncHttpRequest(AsyncHttpRequest *pReq, int iTimeout) m_arRequestsQueue.insert(pReq); } SetEvent(m_evRequestsQueue); - return true; + return pReq; } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/protocols/VKontakte/vk_10.vcxproj b/protocols/VKontakte/vk_10.vcxproj index ab6deb58e8..d77fddaca8 100644 --- a/protocols/VKontakte/vk_10.vcxproj +++ b/protocols/VKontakte/vk_10.vcxproj @@ -198,6 +198,9 @@ + + + diff --git a/protocols/VKontakte/vk_10.vcxproj.filters b/protocols/VKontakte/vk_10.vcxproj.filters index a0612f1dc5..69ca485705 100644 --- a/protocols/VKontakte/vk_10.vcxproj.filters +++ b/protocols/VKontakte/vk_10.vcxproj.filters @@ -68,4 +68,9 @@ Resource Files + + + Resource Files + + \ No newline at end of file -- cgit v1.2.3