From 77633ec5799b374a1899d05ae69a2e5f978f2a7c Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Fri, 3 Apr 2015 20:53:10 +0000 Subject: Steam: moved to core ui git-svn-id: http://svn.miranda-ng.org/main/trunk@12594 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Steam/Steam_12.vcxproj | 1 + protocols/Steam/Steam_12.vcxproj.filters | 7 +- protocols/Steam/res/Resource.rc | 23 +- protocols/Steam/src/Steam/authorization.h | 2 +- protocols/Steam/src/common.h | 4 +- protocols/Steam/src/resource.h | 2 + protocols/Steam/src/steam_account.cpp | 34 +- protocols/Steam/src/steam_dialogs.cpp | 652 +++++++++--------------------- protocols/Steam/src/steam_dialogs.h | 137 +++++++ protocols/Steam/src/steam_events.cpp | 18 +- protocols/Steam/src/steam_options.h | 29 ++ protocols/Steam/src/steam_proto.h | 29 +- protocols/Steam/src/version.h | 2 +- 13 files changed, 426 insertions(+), 514 deletions(-) create mode 100644 protocols/Steam/src/steam_dialogs.h create mode 100644 protocols/Steam/src/steam_options.h diff --git a/protocols/Steam/Steam_12.vcxproj b/protocols/Steam/Steam_12.vcxproj index 325b031a0f..02b74b1588 100644 --- a/protocols/Steam/Steam_12.vcxproj +++ b/protocols/Steam/Steam_12.vcxproj @@ -205,6 +205,7 @@ + diff --git a/protocols/Steam/Steam_12.vcxproj.filters b/protocols/Steam/Steam_12.vcxproj.filters index d1cfed825f..8dd369638a 100644 --- a/protocols/Steam/Steam_12.vcxproj.filters +++ b/protocols/Steam/Steam_12.vcxproj.filters @@ -57,7 +57,7 @@ Source Files - + Source Files @@ -110,6 +110,9 @@ Header Files\Steam + + Header Files + @@ -123,7 +126,7 @@ Resource Files\Icon - + Resource Files\Icon diff --git a/protocols/Steam/res/Resource.rc b/protocols/Steam/res/Resource.rc index 66d4075412..c01563d92d 100644 --- a/protocols/Steam/res/Resource.rc +++ b/protocols/Steam/res/Resource.rc @@ -7,7 +7,7 @@ // // Generated from the TEXTINCLUDE 2 resource. // -#include "afxres.h" +#include "winres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS @@ -17,7 +17,7 @@ #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUD) LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT -#pragma code_page(1250) +#pragma code_page(1251) #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// @@ -32,7 +32,7 @@ END 2 TEXTINCLUDE BEGIN - "#include ""afxres.h""\r\n" + "#include ""winres.h""\r\n" "\0" END @@ -141,6 +141,19 @@ BEGIN PUSHBUTTON "Block",IDC_BLOCK,230,206,68,13,WS_DISABLED END +IDD_PASSWORD_EDITOR DIALOGEX 0, 0, 209, 75 +STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW | WS_EX_APPWINDOW +CAPTION "Enter password" +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + EDITTEXT 102,7,24,197,12,ES_PASSWORD | ES_AUTOHSCROLL + CONTROL "Save password",IDC_SAVEPERMANENTLY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,40,197,12 + DEFPUSHBUTTON "OK",IDOK,101,56,50,14 + PUSHBUTTON "Cancel",IDCANCEL,154,56,50,14 + LTEXT "Enter the password to continue.",IDC_STATIC,7,5,197,18 +END + ///////////////////////////////////////////////////////////////////////////// // @@ -195,6 +208,10 @@ BEGIN TOPMARGIN, 7 BOTTOMMARGIN, 223 END + + IDD_PASSWORD_EDITOR, DIALOG + BEGIN + END END #endif // APSTUDIO_INVOKED diff --git a/protocols/Steam/src/Steam/authorization.h b/protocols/Steam/src/Steam/authorization.h index e72eef1a11..047b408b05 100644 --- a/protocols/Steam/src/Steam/authorization.h +++ b/protocols/Steam/src/Steam/authorization.h @@ -44,7 +44,7 @@ namespace SteamWebApi char data[1024]; mir_snprintf(data, SIZEOF(data), - "username=%s&password=%s&captchagid=%s&captcha_text=%s&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&rsatimestamp=%s", + "username=%s&password=%s&emailauth=&captchagid=%s&captcha_text=%s&oauth_client_id=3638BFB1&oauth_scope=read_profile write_profile read_client write_client&rsatimestamp=%s", ptrA(mir_urlEncode(username)), ptrA(mir_urlEncode(password)), captchaId, diff --git a/protocols/Steam/src/common.h b/protocols/Steam/src/common.h index 086879e365..d39881dbd2 100644 --- a/protocols/Steam/src/common.h +++ b/protocols/Steam/src/common.h @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -28,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -51,6 +52,7 @@ extern HANDLE hExtraXStatus; #include "Steam\steam.h" +#include "steam_dialogs.h" #include "steam_proto.h" #endif //_COMMON_H_ \ No newline at end of file diff --git a/protocols/Steam/src/resource.h b/protocols/Steam/src/resource.h index ec80b9a7ce..e2b1aa120d 100644 --- a/protocols/Steam/src/resource.h +++ b/protocols/Steam/src/resource.h @@ -9,6 +9,8 @@ #define IDD_IGNORE_LIST 21 #define IDI_STEAM 100 #define IDI_GAMING 101 +#define IDD_PASSWORD_EDITOR 107 +#define IDC_SAVEPERMANENTLY 108 #define IDD_CAPTCHA 118 #define IDD_GUARD 119 #define IDC_SN 1001 diff --git a/protocols/Steam/src/steam_account.cpp b/protocols/Steam/src/steam_account.cpp index 01adca1cf6..2ed21e78dc 100644 --- a/protocols/Steam/src/steam_account.cpp +++ b/protocols/Steam/src/steam_account.cpp @@ -104,18 +104,18 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg) node = json_get(root, "emaildomain"); ptrA emailDomain(mir_utf8encodeW(ptrT(json_as_string(node)))); - GuardParam guard; - mir_strncpy(guard.domain, emailDomain, SIZEOF(guard.domain)); - - if (DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_GUARD), NULL, CSteamProto::GuardProc, (LPARAM)&guard) != IDOK) + CSteamGuardDialog guardDialog(this, emailDomain); + if (!guardDialog.DoModal()) + { return; + } ptrA username(mir_utf8encodeW(getWStringA("Username"))); ptrA password(getStringA("EncryptedPassword")); ptrA timestamp(getStringA("RsaTimestamp")); PushRequest( - new SteamWebApi::AuthorizationRequest(username, password, timestamp, guard.code), + new SteamWebApi::AuthorizationRequest(username, password, timestamp, ptrA(guardDialog.GetGuardCode())), &CSteamProto::OnAuthorization); return; } @@ -130,34 +130,22 @@ void CSteamProto::OnAuthorization(const NETLIBHTTPREQUEST *response, void *arg) NETLIBHTTPREQUEST *response = request->Send(m_hNetlibUser); delete request; - CaptchaParam captcha = { 0 }; - captcha.size = response->dataLength; - captcha.data = (BYTE*)mir_alloc(captcha.size); - memcpy(captcha.data, response->pData, captcha.size); - - CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); - - int res = DialogBoxParam( - g_hInstance, - MAKEINTRESOURCE(IDD_CAPTCHA), - NULL, - CSteamProto::CaptchaProc, - (LPARAM)&captcha); - - mir_free(captcha.data); - - if (res != 1) + CSteamCaptchaDialog captchaDialog(this, (BYTE*)response->pData, response->dataLength); + if (!captchaDialog.DoModal()) { + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); SetStatus(ID_STATUS_OFFLINE); return; } + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); + ptrA username(mir_utf8encodeW(getWStringA("Username"))); ptrA password(getStringA("EncryptedPassword")); ptrA timestamp(getStringA("RsaTimestamp")); PushRequest( - new SteamWebApi::AuthorizationRequest(username, password, timestamp, captchaId, captcha.text), + new SteamWebApi::AuthorizationRequest(username, password, timestamp, captchaId, ptrA(captchaDialog.GetCaptchaText())), &CSteamProto::OnAuthorization); return; } diff --git a/protocols/Steam/src/steam_dialogs.cpp b/protocols/Steam/src/steam_dialogs.cpp index 023045da6e..238230fe1e 100644 --- a/protocols/Steam/src/steam_dialogs.cpp +++ b/protocols/Steam/src/steam_dialogs.cpp @@ -1,488 +1,234 @@ #include "common.h" -INT_PTR CALLBACK CSteamProto::GuardProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +CSteamPasswordEditor::CSteamPasswordEditor(CSteamProto *proto) : + CSuper(proto, IDD_PASSWORD_EDITOR, NULL, false), m_ok(this, IDOK), + m_password(this, IDC_PASSWORD), m_savePermanently(this, IDC_SAVEPERMANENTLY) { - GuardParam *guard = (GuardParam*)GetWindowLongPtr(hwnd, GWLP_USERDATA); + m_ok.OnClick = Callback(this, &CSteamPasswordEditor::OnOk); +} - switch (message) - { - case WM_INITDIALOG: - TranslateDialogDefault(hwnd); - { - guard = (GuardParam*)lParam; - SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); - // load steam icon - char iconName[100]; - mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, "main"); - SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon(iconName, 16)); - SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon(iconName, 32)); - } - Utils_RestoreWindowPosition(hwnd, NULL, "STEAM", "GuardWindow"); - return TRUE; +void CSteamPasswordEditor::OnInitDialog() +{ + char iconName[100]; + mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, "main"); + SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon(iconName, 16)); + SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon(iconName, 32)); - case WM_CLOSE: - Skin_ReleaseIcon((HICON)SendMessage(hwnd, WM_SETICON, ICON_BIG, 0)); - Skin_ReleaseIcon((HICON)SendMessage(hwnd, WM_SETICON, ICON_SMALL, 0)); - Utils_SaveWindowPosition(hwnd, NULL, "STEAM", "GuardWindow"); - EndDialog(hwnd, 0); - break; + SendMessage(m_password.GetHwnd(), EM_LIMITTEXT, 64, 0); - case WM_COMMAND: - { - switch (LOWORD(wParam)) - { - case IDC_GETDOMAIN: - CallService(MS_UTILS_OPENURL, 0, (LPARAM)guard->domain); - SetFocus(GetDlgItem(hwnd, IDC_TEXT)); - break; - - case IDOK: - GetDlgItemTextA(hwnd, IDC_TEXT, guard->code, sizeof(guard->code)); - EndDialog(hwnd, IDOK); - break; - - case IDCANCEL: - EndDialog(hwnd, IDCANCEL); - break; - } - } - break; - } + Utils_RestoreWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "PasswordWindow"); +} + +void CSteamPasswordEditor::OnOk(CCtrlButton*) +{ + if (m_savePermanently.Enabled()) + m_proto->setTString("Password", m_password.GetText()); + if (m_proto->password != NULL) + mir_free(m_proto->password); + m_proto->password = m_password.GetText(); - return FALSE; + EndDialog(m_hwnd, 1); } -INT_PTR CALLBACK CSteamProto::CaptchaProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +void CSteamPasswordEditor::OnClose() { - CaptchaParam *captcha = (CaptchaParam*)GetWindowLongPtr(hwnd, GWLP_USERDATA); + Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "PasswordWindow"); +} - switch (message) - { - case WM_INITDIALOG: - TranslateDialogDefault(hwnd); - { - captcha = (CaptchaParam*)lParam; - SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); - } - return TRUE; - - case WM_CLOSE: - EndDialog(hwnd, 0); - break; - - case WM_PAINT: - { - FI_INTERFACE *fei = 0; - - INT_PTR result = CALLSERVICE_NOTFOUND; - if (ServiceExists(MS_IMG_GETINTERFACE)) - result = CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&fei); - - if (fei == NULL || result != S_OK) { - MessageBox(0, TranslateT("Fatal error, image services not found. Avatar services will be disabled."), TranslateT("Avatar Service"), MB_OK); - return 0; - } - - FIMEMORY *stream = fei->FI_OpenMemory(captcha->data, captcha->size); - FREE_IMAGE_FORMAT fif = fei->FI_GetFileTypeFromMemory(stream, 0); - FIBITMAP *bitmap = fei->FI_LoadFromMemory(fif, stream, 0); - fei->FI_CloseMemory(stream); - - PAINTSTRUCT ps; - HDC hDC = BeginPaint(hwnd, &ps); - - //SetStretchBltMode(hDC, COLORONCOLOR); - StretchDIBits( - hDC, - 11, 11, - fei->FI_GetWidth(bitmap) - 13, - fei->FI_GetHeight(bitmap), - 0, 0, - fei->FI_GetWidth(bitmap), - fei->FI_GetHeight(bitmap), - fei->FI_GetBits(bitmap), - fei->FI_GetInfo(bitmap), - DIB_RGB_COLORS, SRCCOPY); - - fei->FI_Unload(bitmap); - //fei->FI_DeInitialise(); - - EndPaint(hwnd, &ps); - } - return 0; - - case WM_COMMAND: - { - switch(LOWORD(wParam)) - { - case IDOK: - GetDlgItemTextA(hwnd, IDC_TEXT, captcha->text, sizeof(captcha->text)); - EndDialog(hwnd, IDOK); - break; - - case IDCANCEL: - EndDialog(hwnd, IDCANCEL); - break; - } - } - break; - } +///////////////////////////////////////////////////////////////////////////////// - return FALSE; +CSteamGuardDialog::CSteamGuardDialog(CSteamProto *proto, char *domain) : + CSuper(proto, IDD_GUARD, NULL, false), m_ok(this, IDOK), + m_text(this, IDC_TEXT), m_link(this, IDC_GETDOMAIN, domain) +{ + mir_strcpy(m_domain, domain); + m_ok.OnClick = Callback(this, &CSteamGuardDialog::OnOk); } -INT_PTR CALLBACK CSteamProto::MainOptionsProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +void CSteamGuardDialog::OnInitDialog() { - CSteamProto *proto = (CSteamProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA); + char iconName[100]; + mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, "main"); + SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon(iconName, 16)); + SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon(iconName, 32)); - switch (message) - { - case WM_INITDIALOG: - TranslateDialogDefault(hwnd); - { - proto = (CSteamProto*)lParam; - SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); - - ptrW username(proto->getWStringA("Username")); - SetDlgItemText(hwnd, IDC_USERNAME, username); - - ptrA password(proto->getStringA("Password")); - SetDlgItemTextA(hwnd, IDC_PASSWORD, password); - - ptrW groupName(proto->getWStringA("DefaultGroup")); - SetDlgItemText(hwnd, IDC_GROUP, groupName); - SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, 64, 0); - - BOOL biggerAvatars = proto->getBool("UseBigAvatars", false); - CheckDlgButton(hwnd, IDC_BIGGER_AVATARS, biggerAvatars ? BST_CHECKED : BST_UNCHECKED); - - if (proto->IsOnline()) - { - EnableWindow(GetDlgItem(hwnd, IDC_USERNAME), FALSE); - EnableWindow(GetDlgItem(hwnd, IDC_PASSWORD), FALSE); - } - } - return TRUE; - - case WM_COMMAND: - { - switch(LOWORD(wParam)) - { - case IDC_USERNAME: - if ((HWND)lParam == GetFocus()) - { - EnableWindow(GetDlgItem(hwnd, IDC_USERNAME), !proto->IsOnline()); - if (HIWORD(wParam) != EN_CHANGE) return 0; - proto->delSetting("SteamID"); - proto->delSetting("Cookies"); - proto->delSetting("TokenSecret"); - wchar_t username[128]; - GetDlgItemText(hwnd, IDC_USERNAME, username, SIZEOF(username)); - SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); - } - break; - - case IDC_PASSWORD: - if ((HWND)lParam == GetFocus()) - { - EnableWindow(GetDlgItem(hwnd, IDC_PASSWORD), !proto->IsOnline()); - if (HIWORD(wParam) != EN_CHANGE) return 0; - proto->delSetting("Cookie"); - proto->delSetting("TokenSecret"); - char password[128]; - GetDlgItemTextA(hwnd, IDC_PASSWORD, password, SIZEOF(password)); - SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); - } - break; - - case IDC_GROUP: - { - if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) - return 0; - SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); - } - break; - - default: - SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0); - break; - } - } - break; - - case WM_NOTIFY: - if (reinterpret_cast(lParam)->code == PSN_APPLY) - { - if (!proto->IsOnline()) - { - wchar_t username[128]; - GetDlgItemText(hwnd, IDC_USERNAME, username, SIZEOF(username)); - proto->setWString("Username", username); - - char password[128]; - GetDlgItemTextA(hwnd, IDC_PASSWORD, password, SIZEOF(password)); - proto->setString("Password", password); - } - - wchar_t groupName[128]; - GetDlgItemText(hwnd, IDC_GROUP, groupName, SIZEOF(groupName)); - if (groupName[0] != '\0') - { - proto->setWString(NULL, "DefaultGroup", groupName); - Clist_CreateGroup(0, groupName); - } - else - proto->delSetting(NULL, "DefaultGroup"); - - BOOL biggerAvatars = IsDlgButtonChecked(hwnd, IDC_BIGGER_AVATARS); - proto->setByte("UseBigAvatars", biggerAvatars); - - return TRUE; - } - break; - } + SendMessage(m_text.GetHwnd(), EM_LIMITTEXT, 5, 0); + + Utils_RestoreWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "GuardWindow"); +} + +void CSteamGuardDialog::OnOk(CCtrlButton*) +{ + EndDialog(m_hwnd, 1); +} + +void CSteamGuardDialog::OnClose() +{ + Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "GuardWindow"); +} + +char * CSteamGuardDialog::GetGuardCode() +{ + return m_text.GetTextA(); +} + +///////////////////////////////////////////////////////////////////////////////// + +CSteamCaptchaDialog::CSteamCaptchaDialog(CSteamProto *proto, BYTE *captchaImage, int captchaImageSize) : + CSuper(proto, IDD_GUARD, NULL, false), + m_ok(this, IDOK), m_text(this, IDC_TEXT) +{ + m_captchaImageSize = captchaImageSize; + m_captchaImage = (BYTE*)mir_alloc(captchaImageSize); + memcpy(m_captchaImage, captchaImage, captchaImageSize); + m_ok.OnClick = Callback(this, &CSteamCaptchaDialog::OnOk); +} + +CSteamCaptchaDialog::~CSteamCaptchaDialog() +{ + mir_free(m_captchaImage); +} - return FALSE; +void CSteamCaptchaDialog::OnInitDialog() +{ + char iconName[100]; + mir_snprintf(iconName, SIZEOF(iconName), "%s_%s", MODULE, "main"); + SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon(iconName, 16)); + SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon(iconName, 32)); + + SendMessage(m_text.GetHwnd(), EM_LIMITTEXT, 5, 0); + + Utils_RestoreWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "CaptchaWindow"); } -static WNDPROC oldWndProc = NULL; +void CSteamCaptchaDialog::OnOk(CCtrlButton*) +{ + EndDialog(m_hwnd, 1); +} -LRESULT CALLBACK CSteamProto::BlockListOptionsSubProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +void CSteamCaptchaDialog::OnClose() { - if (msg == WM_LBUTTONDOWN) + Utils_SaveWindowPosition(m_hwnd, NULL, m_proto->m_szModuleName, "CaptchaWindow"); +} + +INT_PTR CSteamCaptchaDialog::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (msg == WM_PAINT) { - LVHITTESTINFO hi; - hi.pt.x = LOWORD(lParam); hi.pt.y = HIWORD(lParam); - ListView_SubItemHitTest(hwnd, &hi); - if (hi.iSubItem == 1) - { - LVITEM lvi = { 0 }; - lvi.mask = LVIF_IMAGE | LVIF_PARAM; - lvi.stateMask = -1; - lvi.iItem = hi.iItem; - if (ListView_GetItem(hwnd, &lvi)) - { - /*ContactParam *param = (ContactParam *)lvi.lParam; - - if (param->contact->SetBlocked(false)) - { - SEString data; - param->contact->GetIdentity(data); - ptrW sid(mir_utf8decodeW(data)); - - MCONTACT hContact = param->ppro->GetContactBySid(sid); - if (db_get_b(hContact, param->ppro->m_szModuleName, "IsSkypeOut", 0) > 0) - db_set_w(hContact, param->ppro->m_szModuleName, "Status", ID_STATUS_ONTHEPHONE); - - ListView_DeleteItem(hwnd, lvi.iItem); - - int nItem = ::SendDlgItemMessage(GetParent(hwnd), IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)sid); - SendDlgItemMessage(GetParent(hwnd), IDC_CONTACTS, CB_SETITEMDATA, nItem, hContact); - }*/ - } + FI_INTERFACE *fei = 0; + + INT_PTR result = CALLSERVICE_NOTFOUND; + if (ServiceExists(MS_IMG_GETINTERFACE)) + result = CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&fei); + + if (fei == NULL || result != S_OK) { + MessageBox(0, TranslateT("Fatal error, image services not found. Avatar services will be disabled."), TranslateT("Avatar Service"), MB_OK); + return 0; } + + FIMEMORY *stream = fei->FI_OpenMemory(m_captchaImage, m_captchaImageSize); + FREE_IMAGE_FORMAT fif = fei->FI_GetFileTypeFromMemory(stream, 0); + FIBITMAP *bitmap = fei->FI_LoadFromMemory(fif, stream, 0); + fei->FI_CloseMemory(stream); + + PAINTSTRUCT ps; + HDC hDC = BeginPaint(m_hwnd, &ps); + + //SetStretchBltMode(hDC, COLORONCOLOR); + StretchDIBits( + hDC, + 11, 11, + fei->FI_GetWidth(bitmap) - 13, + fei->FI_GetHeight(bitmap), + 0, 0, + fei->FI_GetWidth(bitmap), + fei->FI_GetHeight(bitmap), + fei->FI_GetBits(bitmap), + fei->FI_GetInfo(bitmap), + DIB_RGB_COLORS, SRCCOPY); + + fei->FI_Unload(bitmap); + //fei->FI_DeInitialise(); + + EndPaint(m_hwnd, &ps); + + return FALSE; } + CSuper::DlgProc(msg, wParam, lParam); +} - return CallWindowProc(oldWndProc, hwnd, msg, wParam, lParam); +char * CSteamCaptchaDialog::GetCaptchaText() +{ + return m_text.GetTextA(); } -INT_PTR CALLBACK CSteamProto::BlockListOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +///////////////////////////////////////////////////////////////////////////////// + +CSteamOptionsMain::CSteamOptionsMain(CSteamProto *proto, int idDialog, HWND hwndParent) + : CSuper(proto, idDialog, hwndParent, false), + m_username(this, IDC_USERNAME), m_password(this, IDC_PASSWORD), + m_group(this, IDC_GROUP), m_biggerAvatars(this, IDC_BIGGER_AVATARS) { - CSteamProto *ppro = (CSteamProto*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + CreateLink(m_username, "Username", _T("")); + CreateLink(m_password, "Password", _T("")); + CreateLink(m_group, "DefaultGroup", _T("Steam")); + CreateLink(m_biggerAvatars, "UseBigAvatars", FALSE); +} - switch (msg) - { - case WM_INITDIALOG: - if (lParam) - { - ppro = (CSteamProto*)lParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam); - - TranslateDialogDefault(hwndDlg); - - HWND hwndList = ::GetDlgItem(hwndDlg, IDC_LIST); - { // IDC_BM_LIST setup - oldWndProc = (WNDPROC)SetWindowLongPtr(hwndList, GWLP_WNDPROC, (LONG_PTR)BlockListOptionsSubProc); - - HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0); - //ImageList_AddIconFromIconLib(hIml, "Skype_contact"); - //ImageList_AddIconFromIconLib(hIml, "Skype_delete"); - ListView_SetImageList(hwndList, hIml, LVSIL_SMALL); - - LVCOLUMN lvc = { 0 }; - lvc.mask = LVCF_WIDTH | LVCF_TEXT; - //lvc.fmt = LVCFMT_JUSTIFYMASK; - lvc.pszText = TranslateT("Name"); - lvc.cx = 220; // width of column in pixels - ListView_InsertColumn(hwndList, 0, &lvc); - //lvc.fmt = LVCFMT_RIGHT; - lvc.pszText = L""; - lvc.cx = 32 - GetSystemMetrics(SM_CXVSCROLL); // width of column in pixels - ListView_InsertColumn(hwndList, 1, &lvc); - - SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP); - - if (!ppro->IsOnline()) - { - EnableWindow(hwndList, FALSE); - EnableWindow(::GetDlgItem(hwndDlg, IDC_CONTACTS), FALSE); - } - } - - if (ppro->IsOnline()) - { - /*SEString data; - ContactGroupRef blockedList; - ppro->GetHardwiredContactGroup(ContactGroup::CONTACTS_BLOCKED_BY_ME, blockedList); - - CContact::Refs contacts; - blockedList->GetContacts(contacts); - for (size_t i = 0; i < contacts.size(); i++) - { - auto contact = contacts[i]; - - ptrW sid(::mir_utf8decodeW(contact->GetSid())); - - LVITEM lvi = { 0 }; - lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; - lvi.iItem = (int)i; - lvi.iImage = 0; - lvi.lParam = (LPARAM)new ContactParam(contact, ppro); - lvi.pszText = sid; - int iRow = ListView_InsertItem(hwndList, &lvi); - - if (iRow != -1) - { - lvi.iItem = iRow; - lvi.mask = LVIF_IMAGE; - lvi.iSubItem = 1; - lvi.iImage = 1; - ListView_SetItem(hwndList, &lvi); - } - }*/ - - /*int nItem = 0; - MCONTACT hContact = NULL; - - EnterCriticalSection(&ppro->contact_search_lock); - - for (hContact = ::db_find_first(ppro->m_szModuleName); hContact && !ppro->isChatRoom(hContact); hContact = ::db_find_next(hContact, ppro->m_szModuleName)) - { - ptrW sid(::db_get_wsa(hContact, ppro->m_szModuleName, SKYPE_SETTINGS_SID)); - - ContactRef contact; - ppro->GetContact((char *)_T2A(sid), contact); - if (!contacts.contains(contact)) - { - nItem = ::SendDlgItemMessage(hwndDlg, IDC_CONTACTS, CB_ADDSTRING, 0, (LPARAM)sid); - ::SendDlgItemMessage(hwndDlg, IDC_CONTACTS, CB_SETITEMDATA, nItem, hContact); - } - } - - LeaveCriticalSection(&ppro->contact_search_lock);*/ - } +void CSteamOptionsMain::OnInitDialog() +{ + CSuper::OnInitDialog(); - } - break; + SendMessage(m_username.GetHwnd(), EM_LIMITTEXT, 64, 0); + SendMessage(m_password.GetHwnd(), EM_LIMITTEXT, 64, 0); + SendMessage(m_group.GetHwnd(), EM_LIMITTEXT, 64, 0); +} + +void CSteamOptionsMain::OnApply() +{ + TCHAR *group = m_group.GetText(); + if (mir_tstrlen(group) > 0 && Clist_GroupExists(group)) + Clist_CreateGroup(0, group); - case WM_COMMAND: + if (m_proto->IsOnline()) { - switch (LOWORD(wParam)) - { - case IDC_CONTACTS: - EnableWindow(GetDlgItem(hwndDlg, IDC_BLOCK), TRUE); - break; - - case IDC_BLOCK: - { - int i = ::SendDlgItemMessage(hwndDlg, IDC_CONTACTS, CB_GETCURSEL, 0, 0); - - MCONTACT hContact = (MCONTACT)::SendDlgItemMessage(hwndDlg, IDC_CONTACTS, CB_GETITEMDATA, i, 0); - if (!hContact) - break; - - ptrA steamId(ppro->getStringA(hContact, "SteamID")); - - /*SEString data; - ContactRef contact; - if (!ppro->GetContact((char *)_T2A(sid), contact) || !contact) - break; - - BlockParam param(hContact, ppro); - if (::DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_BLOCK), NULL, CSkypeProto::SkypeBlockProc, (LPARAM)¶m) != IDOK) - break; - - contact->SetBlocked(true, param.abuse); - if (::db_get_b(hContact, ppro->m_szModuleName, "IsSkypeOut", 0) > 0) - ::db_set_w(hContact, ppro->m_szModuleName, "Status", ID_STATUS_OFFLINE); - - if (param.remove) - { - contact->SetBuddyStatus(false); - ppro->contactList.remove_val(contact); - ::CallService(MS_DB_CONTACT_DELETE, wParam, 0); - } - - if (contact->SetBlocked(true)) - { - LVITEM lvi = { 0 }; - lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM; - lvi.iItem = (int)i; - lvi.iImage = 0; - lvi.lParam = (LPARAM)new ContactParam(contact, ppro); - lvi.pszText = sid; - int iRow = ListView_InsertItem(::GetDlgItem(hwndDlg, IDC_LIST), &lvi); - - if (iRow != -1) - { - lvi.iItem = iRow; - lvi.mask = LVIF_IMAGE; - lvi.iSubItem = 1; - lvi.iImage = 1; - ListView_SetItem(::GetDlgItem(hwndDlg, IDC_LIST), &lvi); - } - ::SendDlgItemMessage(hwndDlg, IDC_CONTACTS, CB_DELETESTRING, i, 0); - }*/ - } - break; - } + // may be we should show message box with warning? + m_proto->SetStatus(ID_STATUS_OFFLINE); } - break; - - case WM_NOTIFY: - if (reinterpret_cast(lParam)->code == PSN_APPLY && !ppro->IsOnline()) - { - return TRUE; - } - break; - - switch (LOWORD(wParam)) - { - case IDC_LIST: - if (((LPNMHDR)lParam)->code == NM_DBLCLK) - { - HWND hwndList = ::GetDlgItem(hwndDlg, IDC_BM_LIST); - int iItem = ListView_GetNextItem(hwndList, -1, LVNI_ALL | LVNI_SELECTED); - if (iItem < 0) break; - LVITEM lvi = { 0 }; - lvi.mask = LVIF_PARAM | LVIF_GROUPID; - lvi.stateMask = -1; - lvi.iItem = iItem; - if (ListView_GetItem(hwndList, &lvi)) - { - /*SEString data; - if (lvi.iGroupId == 1) - { - ContactParam *param = (ContactParam *)lvi.lParam; - - param->contact->GetIdentity(data); - ptrW sid(::mir_utf8decodeW(data)); - ::CallService(MS_MSG_SENDMESSAGE, (WPARAM)ppro->GetContactBySid(sid), 0); - }*/ - } - } - } - break; + if (m_username.IsChanged()) + { + m_proto->delSetting("SteamID"); + m_proto->delSetting("Cookies"); + m_proto->delSetting("TokenSecret"); + } + if (m_password.IsChanged()) + { + m_proto->delSetting("Cookie"); + m_proto->delSetting("TokenSecret"); } - return FALSE; +} + +///////////////////////////////////////////////////////////////////////////////// + +CSteamOptionsBlockList::CSteamOptionsBlockList(CSteamProto *proto) + : CSuper(proto, IDD_OPT_BLOCK_LIST, NULL, false), m_list(this, IDC_LIST), + m_contacts(this, IDC_CONTACTS), m_add(this, IDC_BLOCK) +{ + m_add.OnClick = Callback(this, &CSteamOptionsBlockList::OnBlock); +} + +void CSteamOptionsBlockList::OnInitDialog() +{ + m_list.SetExtendedListViewStyle(LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP); + + HIMAGELIST hIml = m_list.CreateImageList(LVSIL_SMALL); + //ImageList_AddIcon_Icolib(hIml, m_proto->LoadIconEx("group")); + //ImageList_AddIcon_Icolib(hIml, LoadSkinnedIcon(SKINICON_EVENT_URL)); + + m_list.AddColumn(0, TranslateT("Name"), 220); + m_list.AddColumn(1, _T(""), 32 - GetSystemMetrics(SM_CXVSCROLL)); +} + +void CSteamOptionsBlockList::OnBlock(CCtrlButton*) +{ } \ No newline at end of file diff --git a/protocols/Steam/src/steam_dialogs.h b/protocols/Steam/src/steam_dialogs.h new file mode 100644 index 0000000000..dd919fa365 --- /dev/null +++ b/protocols/Steam/src/steam_dialogs.h @@ -0,0 +1,137 @@ +#ifndef _STEAM_DIALOGS_H_ +#define _STEAM_DIALOGS_H_ + +class CSteamDlgBase : public CProtoDlgBase +{ +private: + typedef CProtoDlgBase CSuper; + +protected: + __inline CSteamDlgBase(CSteamProto *proto, int idDialog, HWND parent, bool show_label = true) : + CSuper(proto, idDialog, parent, show_label) { } +}; + +///////////////////////////////////////////////////////////////////////////////// + +class CSteamPasswordEditor : public CSteamDlgBase +{ +private: + typedef CSteamDlgBase CSuper; + + CCtrlEdit m_password; + CCtrlCheck m_savePermanently; + + CCtrlButton m_ok; + +protected: + void OnInitDialog(); + void OnOk(CCtrlButton*); + void OnClose(); + +public: + CSteamPasswordEditor(CSteamProto *proto); +}; + +///////////////////////////////////////////////////////////////////////////////// + +class CSteamGuardDialog : public CSteamDlgBase +{ +private: + typedef CSteamDlgBase CSuper; + + char m_domain[32]; + + CCtrlEdit m_text; + CCtrlButton m_ok; + CCtrlHyperlink m_link; + +protected: + void OnInitDialog(); + void OnOk(CCtrlButton*); + void OnClose(); + +public: + CSteamGuardDialog(CSteamProto *proto, char *domain); + + char *GetGuardCode(); +}; + +///////////////////////////////////////////////////////////////////////////////// + +class CSteamCaptchaDialog : public CSteamDlgBase +{ +private: + typedef CSteamDlgBase CSuper; + + BYTE *m_captchaImage; + int m_captchaImageSize; + + CCtrlEdit m_text; + CCtrlButton m_ok; + +protected: + void OnInitDialog(); + void OnOk(CCtrlButton*); + void OnClose(); + + INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam); + +public: + CSteamCaptchaDialog(CSteamProto *proto, BYTE *captchaImage, int captchaImageSize); + ~CSteamCaptchaDialog(); + + char *GetCaptchaText(); +}; + +///////////////////////////////////////////////////////////////////////////////// + +class CSteamOptionsMain : public CSteamDlgBase +{ +private: + typedef CSteamDlgBase CSuper; + + CCtrlEdit m_username; + CCtrlEdit m_password; + CCtrlEdit m_group; + + CCtrlCheck m_biggerAvatars; + +protected: + CSteamOptionsMain(CSteamProto *proto, int idDialog, HWND hwndParent = NULL); + + void OnInitDialog(); + void OnApply(); + +public: + static CDlgBase *CreateAccountManagerPage(void *param, HWND owner) + { + CSteamOptionsMain *page = new CSteamOptionsMain((CSteamProto*)param, IDD_ACCMGR, owner); + page->Show(); + return page; + } + + static CDlgBase *CreateOptionsPage(void *param) { return new CSteamOptionsMain((CSteamProto*)param, IDD_OPT_MAIN); } +}; + +//////////////////////////////////////////////////////////////////////////////// + +class CSteamOptionsBlockList : public CSteamDlgBase +{ +private: + typedef CSteamDlgBase CSuper; + + CCtrlListView m_list; + CCtrlCombo m_contacts; + CCtrlButton m_add; + +protected: + CSteamOptionsBlockList(CSteamProto *proto); + + void OnInitDialog(); + void OnBlock(CCtrlButton*); + +public: + static CDlgBase *CreateOptionsPage(void *param) { return new CSteamOptionsBlockList((CSteamProto*)param); } +}; + +#endif //_STEAM_DIALOGS_H_ \ No newline at end of file diff --git a/protocols/Steam/src/steam_events.cpp b/protocols/Steam/src/steam_events.cpp index c03fc3bb91..bbf707886e 100644 --- a/protocols/Steam/src/steam_events.cpp +++ b/protocols/Steam/src/steam_events.cpp @@ -31,12 +31,7 @@ int CSteamProto::OnPreShutdown(WPARAM, LPARAM) INT_PTR CSteamProto::OnAccountManagerInit(WPARAM wParam, LPARAM lParam) { - return (int)CreateDialogParam( - g_hInstance, - MAKEINTRESOURCE(IDD_ACCMGR), - (HWND)lParam, - CSteamProto::MainOptionsProc, - (LPARAM)this); + return (INT_PTR)(CSteamOptionsMain::CreateAccountManagerPage(this, (HWND)lParam))->GetHwnd(); } int CSteamProto::OnOptionsInit(void *obj, WPARAM wParam, LPARAM lParam) @@ -48,18 +43,23 @@ int CSteamProto::OnOptionsInit(void *obj, WPARAM wParam, LPARAM lParam) OPTIONSDIALOGPAGE odp = { sizeof(odp) }; odp.hInstance = g_hInstance; odp.pszTitle = title; - odp.dwInitParam = LPARAM(obj); odp.flags = ODPF_BOLDGROUPS; odp.pszGroup = LPGEN("Network"); odp.pszTab = LPGEN("Account"); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_MAIN); - odp.pfnDlgProc = MainOptionsProc; + odp.pfnDlgProc = CSteamOptionsMain::DynamicDlgProc; + odp.dwInitParam = (LPARAM)&instance->SteamMainOptionsParam; + instance->SteamMainOptionsParam.create = CSteamOptionsMain::CreateOptionsPage; + instance->SteamMainOptionsParam.param = instance; Options_AddPage(wParam, &odp); odp.pszTab = LPGEN("Blocked contacts"); odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_BLOCK_LIST); - odp.pfnDlgProc = BlockListOptionsProc; + odp.pfnDlgProc = CSteamOptionsMain::DynamicDlgProc; + odp.dwInitParam = (LPARAM)&instance->SteamBlockListOptionsParam; + instance->SteamBlockListOptionsParam.create = CSteamOptionsBlockList::CreateOptionsPage; + instance->SteamBlockListOptionsParam.param = instance; Options_AddPage(wParam, &odp); mir_free(title); diff --git a/protocols/Steam/src/steam_options.h b/protocols/Steam/src/steam_options.h new file mode 100644 index 0000000000..86bd7a183e --- /dev/null +++ b/protocols/Steam/src/steam_options.h @@ -0,0 +1,29 @@ +#ifndef _SKYPE_OPTIONS_H_ +#define _SKYPE_OPTIONS_H_ + +class CSkypeOptionsMain : public CSkypeDlgBase +{ +private: + typedef CSkypeDlgBase CSuper; + + CCtrlEdit m_skypename; + CCtrlEdit m_password; + CCtrlEdit m_group; + +protected: + CSkypeOptionsMain(CSkypeProto *proto, int idDialog, HWND hwndParent = NULL); + + void OnInitDialog(); + void OnApply(); + +public: + static CDlgBase *CreateAccountManagerPage(void *param, HWND owner) + { + CSkypeOptionsMain *page = new CSkypeOptionsMain((CSkypeProto*)param, IDD_ACCOUNT_MANAGER, owner); + page->Show(); + } + + static CDlgBase *CreateMainOptionsPage(void *param) { return new CSkypeOptionsMain((CSkypeProto*)param, IDD_OPTIONS_MAIN); } +}; + +#endif //_SKYPE_OPTIONS_H_ \ No newline at end of file diff --git a/protocols/Steam/src/steam_proto.h b/protocols/Steam/src/steam_proto.h index 34560349e8..0c06e708ca 100644 --- a/protocols/Steam/src/steam_proto.h +++ b/protocols/Steam/src/steam_proto.h @@ -11,20 +11,6 @@ struct PasswordParam char timestamp[16]; }; - -struct GuardParam -{ - char code[10]; - char domain[32]; -}; - -struct CaptchaParam -{ - BYTE *data; - size_t size; - char text[10]; -}; - struct SendAuthParam { MCONTACT hContact; @@ -118,6 +104,9 @@ struct QueueItem class CSteamProto : public PROTO { + friend CSteamPasswordEditor; + friend CSteamOptionsMain; + public: // PROTO_INTERFACE CSteamProto(const char *protoName, const wchar_t *userName); @@ -154,6 +143,7 @@ public: static void UninitMenus(); protected: + TCHAR *password; bool isTerminated; time_t m_idleTS; HANDLE m_evRequestsQueue, m_hQueueThread; @@ -256,6 +246,10 @@ protected: void OnInitStatusMenu(); + // options + CSteamDlgBase::CreateParam SteamMainOptionsParam; + CSteamDlgBase::CreateParam SteamBlockListOptionsParam; + // avatars TCHAR* GetAvatarFilePath(MCONTACT hContact); bool GetDbAvatarInfo(PROTO_AVATAR_INFORMATIONT &pai); @@ -290,13 +284,6 @@ protected: static void CSteamProto::ShowNotification(const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); static void CSteamProto::ShowNotification(const wchar_t *caption, const wchar_t *message, int flags = 0, MCONTACT hContact = NULL); - // dialog procs - static INT_PTR CALLBACK GuardProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); - static INT_PTR CALLBACK CaptchaProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); - static INT_PTR CALLBACK MainOptionsProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); - static LRESULT CALLBACK BlockListOptionsSubProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); - static INT_PTR CALLBACK BlockListOptionsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); - // helpers inline int IdleSeconds() { // Based on idle time we report Steam server will mark us as online/away/snooze diff --git a/protocols/Steam/src/version.h b/protocols/Steam/src/version.h index 007f994986..fb21edaeb0 100644 --- a/protocols/Steam/src/version.h +++ b/protocols/Steam/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0 #define __MINOR_VERSION 11 #define __RELEASE_NUM 3 -#define __BUILD_NUM 1 +#define __BUILD_NUM 2 #include -- cgit v1.2.3