summaryrefslogtreecommitdiff
path: root/protocols
diff options
context:
space:
mode:
authorSergey Bolhovskoy <elzorfox@ya.ru>2016-03-18 08:39:23 +0000
committerSergey Bolhovskoy <elzorfox@ya.ru>2016-03-18 08:39:23 +0000
commita1728bef4efb06742b792f9f5b4aab48d1d7bb48 (patch)
tree43bb17c0b27f92d47a831cab62a01861b660ac2e /protocols
parentc00fd13ea14bdafd1d18c19fef9df9b3907130a4 (diff)
VKontakte:
add ‘Open in browser’ button to captcha form add hidden option ‘AlwaysOpenCaptchaInBrowser’ (BYTE) git-svn-id: http://svn.miranda-ng.org/main/trunk@16495 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols')
-rw-r--r--protocols/VKontakte/res/resource.rc9
-rw-r--r--protocols/VKontakte/src/misc.cpp44
-rw-r--r--protocols/VKontakte/src/resource.h2
-rw-r--r--protocols/VKontakte/src/vk_captcha.cpp11
-rw-r--r--protocols/VKontakte/src/vk_proto.h3
5 files changed, 64 insertions, 5 deletions
diff --git a/protocols/VKontakte/res/resource.rc b/protocols/VKontakte/res/resource.rc
index e3b426487f..54510e8797 100644
--- a/protocols/VKontakte/res/resource.rc
+++ b/protocols/VKontakte/res/resource.rc
@@ -279,14 +279,15 @@ EXSTYLE WS_EX_CONTROLPARENT
CAPTION "Bots challenge test"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
- EDITTEXT IDC_VALUE,4,203,137,14,ES_AUTOHSCROLL
+ EDITTEXT IDC_VALUE,4,192,155,14,ES_AUTOHSCROLL
CONTROL "",IDC_WHITERECT,"Static",SS_LEFTNOWORDWRAP | WS_GROUP,0,0,258,25
LTEXT "Instruction:",IDC_TITLE,7,7,243,8,NOT WS_GROUP
EDITTEXT IDC_INSTRUCTION,17,16,233,8,ES_MULTILINE | ES_READONLY | NOT WS_BORDER
CONTROL "",IDC_FRAME1,"Static",SS_ETCHEDHORZ,0,26,258,1
- CONTROL "",IDC_FRAME2,"Static",SS_ETCHEDHORZ,0,197,258,1
- DEFPUSHBUTTON "Submit",IDOK,146,203,50,14
- PUSHBUTTON "Cancel",IDCANCEL,200,203,50,14
+ CONTROL "",IDC_FRAME2,"Static",SS_ETCHEDHORZ,0,188,258,1
+ DEFPUSHBUTTON "Submit",IDOK,163,192,46,14
+ PUSHBUTTON "Cancel",IDCANCEL,210,192,43,14
+ PUSHBUTTON "Open in browser",IDOPENBROWSER,163,208,90,14
END
IDD_INVITE DIALOGEX 0, 0, 191, 65
diff --git a/protocols/VKontakte/src/misc.cpp b/protocols/VKontakte/src/misc.cpp
index b9d33b2328..d2731d64e7 100644
--- a/protocols/VKontakte/src/misc.cpp
+++ b/protocols/VKontakte/src/misc.cpp
@@ -1273,4 +1273,48 @@ CMString CVkProto::RemoveBBC(CMString& tszSrc)
}
return tszRes;
+}
+
+CMString CVkProto::SaveImage(HBITMAP hBitmap)
+{
+ TCHAR tszTempDir[MAX_PATH];
+
+ if (!GetEnvironmentVariable(_T("TEMP"), tszTempDir, MAX_PATH))
+ return CMString();
+
+ CMString tszImgFileName(FORMAT, _T("%s\\miranda_captcha.png"), tszTempDir);
+
+ IMGSRVC_INFO isi = { sizeof(isi) };
+ isi.tszName = mir_tstrdup(tszImgFileName);
+ isi.hbm = hBitmap;
+ isi.dwMask = IMGI_HBITMAP;
+ isi.fif = FREE_IMAGE_FORMAT::FIF_PNG;
+
+ if (CallService(MS_IMG_SAVE, (WPARAM)&isi, IMGL_TCHAR))
+ return tszImgFileName;
+
+ return CMString();
+}
+
+void CVkProto::ShowCaptchaInBrowser(HBITMAP hBitmap)
+{
+ CMString tszFHTML = SaveImage(hBitmap);
+
+ if (tszFHTML.IsEmpty())
+ return;
+
+ tszFHTML.Replace(_T(".png"), _T(".html"));
+
+ if (!(GetFileAttributes(tszFHTML) < 0xFFFFFFF)) {
+ FILE *pFile = _tfopen(tszFHTML, _T("w"));
+ if (pFile == NULL)
+ return;
+
+ CMStringA szHTML("<html><body><img src=\"miranda_captcha.png\" /></body></html>");
+ fwrite(szHTML, 1, szHTML.GetLength(), pFile);
+ fclose(pFile);
+ }
+
+ tszFHTML = _T("file://") + tszFHTML;
+ Utils_OpenUrlT(tszFHTML);
} \ No newline at end of file
diff --git a/protocols/VKontakte/src/resource.h b/protocols/VKontakte/src/resource.h
index ea71a9574b..f387c18e32 100644
--- a/protocols/VKontakte/src/resource.h
+++ b/protocols/VKontakte/src/resource.h
@@ -2,6 +2,8 @@
// Âêëþ÷àåìûé ôàéë, ñîçäàííûé â Microsoft Visual C++.
// Èñïîëüçóåòñÿ d:\svn\protocols\VKontakte\res\resource.rc
//
+
+#define IDOPENBROWSER 3
#define IDD_ACCMGRUI 101
#define IDD_CAPTCHAFORM 102
#define IDD_OPT_MAIN 103
diff --git a/protocols/VKontakte/src/vk_captcha.cpp b/protocols/VKontakte/src/vk_captcha.cpp
index f3b6137082..9e7913443d 100644
--- a/protocols/VKontakte/src/vk_captcha.cpp
+++ b/protocols/VKontakte/src/vk_captcha.cpp
@@ -26,6 +26,7 @@ struct CAPTCHA_FORM_PARAMS
HBITMAP bmp;
int w,h;
char Result[100];
+ CVkProto* proto;
};
static INT_PTR CALLBACK CaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -70,6 +71,9 @@ static INT_PTR CALLBACK CaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam
DeleteDC(hdcMem);
EndPaint(hwndDlg, &ps);
+
+ if (params->proto->getBool("AlwaysOpenCaptchaInBrowser", false))
+ params->proto->ShowCaptchaInBrowser(params->bmp);
}
break;
@@ -78,6 +82,10 @@ static INT_PTR CALLBACK CaptchaFormDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam
case IDCANCEL:
EndDialog(hwndDlg, 0);
return TRUE;
+
+ case IDOPENBROWSER:
+ params->proto->ShowCaptchaInBrowser(params->bmp);
+ break;
case IDOK:
GetDlgItemTextA(hwndDlg, IDC_VALUE, params->Result, _countof(params->Result));
@@ -125,10 +133,11 @@ bool CVkProto::RunCaptchaForm(LPCSTR szUrl, CMStringA &result)
memio.fif = FIF_UNKNOWN; /* detect */
param.bmp = (HBITMAP)CallService(MS_IMG_LOADFROMMEM, (WPARAM)&memio);
- BITMAP bmp = {0};
+ BITMAP bmp = { 0 };
GetObject(param.bmp, sizeof(bmp), &bmp);
param.w = bmp.bmWidth;
param.h = bmp.bmHeight;
+ param.proto = this;
int res = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CAPTCHAFORM), NULL, CaptchaFormDlgProc, (LPARAM)&param);
if (res == 0)
return false;
diff --git a/protocols/VKontakte/src/vk_proto.h b/protocols/VKontakte/src/vk_proto.h
index 5cc1c9381b..1a105eed24 100644
--- a/protocols/VKontakte/src/vk_proto.h
+++ b/protocols/VKontakte/src/vk_proto.h
@@ -229,6 +229,9 @@ struct CVkProto : public PROTO<CVkProto>
void SetInvisible(MCONTACT hContact);
CMString RemoveBBC(CMString& tszSrc);
+ CMString SaveImage(HBITMAP hBitmap);
+ void ShowCaptchaInBrowser(HBITMAP hBitmap);
+
//====================================================================================
void RetrieveStatusMsg(const CMString &StatusMsg);