From 3c9026fef3ebe0e80855b51351b5c1bad05d9f0d Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Thu, 21 Aug 2014 20:25:28 +0000 Subject: Tox: - fixed own nick changing - reworked search/add dialog git-svn-id: http://svn.miranda-ng.org/main/trunk@10268 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/res/resource.rc | 16 ++++++- protocols/Tox/src/common.h | 1 + protocols/Tox/src/resource.h | 9 +++- protocols/Tox/src/tox_contacts.cpp | 36 ++++++++------- protocols/Tox/src/tox_events.cpp | 17 ++++--- protocols/Tox/src/tox_options.cpp | 94 +++++++++++++++++++++++--------------- protocols/Tox/src/tox_proto.cpp | 60 +++++++++++++++--------- protocols/Tox/src/tox_proto.h | 8 ++-- 8 files changed, 154 insertions(+), 87 deletions(-) (limited to 'protocols/Tox') diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc index a3e05e5e83..3b801ef909 100644 --- a/protocols/Tox/res/resource.rc +++ b/protocols/Tox/res/resource.rc @@ -121,10 +121,20 @@ BEGIN LTEXT "Tox profile contains your ID and friend list.\r\nYou may create new profile if you never used tox or use existing profile from other tox client.",IDC_STATIC,7,7,221,33 CONTROL "Create new profile",IDC_CREATE_NEW,"Button",BS_AUTORADIOBUTTON,7,43,221,10 CONTROL "Use existing profile",IDC_USE_EXISTING,"Button",BS_AUTORADIOBUTTON,7,55,221,10 - EDITTEXT IDC_PROFILE_PATH,18,67,191,14,ES_AUTOHSCROLL | WS_DISABLED + EDITTEXT IDC_CREATE_NEW,18,67,191,14,ES_AUTOHSCROLL | WS_DISABLED PUSHBUTTON "...",IDC_BROWSE_PROFILE,212,67,16,14,WS_DISABLED END +IDD_SEARCH DIALOGEX 0, 0, 109, 113 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CONTROL "Search via toxme.se",IDC_SEARCH_TOXMESE,"Button",BS_AUTORADIOBUTTON,0,32,109,10 + EDITTEXT IDC_SEARCH,0,3,109,14,ES_AUTOHSCROLL + CONTROL "Add to friend list",IDC_ADDTOLIST,"Button",BS_AUTORADIOBUTTON,0,20,109,10 +END + ///////////////////////////////////////////////////////////////////////////// // @@ -173,6 +183,10 @@ BEGIN HORZGUIDE, 55 HORZGUIDE, 67 END + + IDD_SEARCH, DIALOG + BEGIN + END END #endif // APSTUDIO_INVOKED diff --git a/protocols/Tox/src/common.h b/protocols/Tox/src/common.h index c039f5fc75..9518d62e3a 100644 --- a/protocols/Tox/src/common.h +++ b/protocols/Tox/src/common.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "tox\tox.h" diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h index d78970c747..3ecd31b638 100644 --- a/protocols/Tox/src/resource.h +++ b/protocols/Tox/src/resource.h @@ -2,15 +2,20 @@ // Microsoft Visual C++ generated include file. // Used by e:\Projects\C++\MirandaNG\protocols\Tox\res\resource.rc // +#define IDD_SEARCH 138 #define IDI_TOX 1000 #define IDD_PROFILE_MANAGER 1001 #define IDC_TOXID 1002 #define IDD_ACCOUNT_MANAGER 1003 #define IDC_CLIPBOARD 1004 #define IDD_OPTIONS_MAIN 1005 +#define IDC_RADIO1 1005 +#define IDC_SEARCH_TOXMESE 1005 #define IDC_CREATE_NEW 1006 -#define IDC_USE_EXISTING 1007 #define IDC_PROFILE_PATH 1006 +#define IDC_SEARCH 1006 +#define IDC_USE_EXISTING 1007 +#define IDC_ADDTOLIST 1007 #define IDC_BROWSE_PROFILE 1009 #define IDC_NAME 1010 #define IDC_GROUP 1011 @@ -23,7 +28,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 102 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1005 +#define _APS_NEXT_CONTROL_VALUE 1008 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 91d62b8907..0745888dad 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -132,18 +132,21 @@ void CToxProto::LoadContactList() void CToxProto::SearchByIdAsync(void* arg) { std::string clientId = mir_utf8encodeT((TCHAR*)arg); - clientId.erase(clientId.begin() + TOX_CLIENT_ID_SIZE * 2, clientId.end()); + if (clientId.length() > TOX_CLIENT_ID_SIZE * 2) + { + clientId.erase(clientId.begin() + TOX_CLIENT_ID_SIZE * 2, clientId.end()); + } std::string toxId = clientId; MCONTACT hContact = FindContact(clientId.c_str()); if (hContact) { ShowNotification(TranslateT("Contact already in your contact list"), 0, hContact); - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0); + ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HWND)1, 0); return; } - ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)1, 0); + ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HWND)1, 0); } void CToxProto::SearchByNameAsync(void* arg) @@ -154,19 +157,23 @@ void CToxProto::SearchByNameAsync(void* arg) request.flags = NLHRF_HTTP11 | NLHRF_SSL | NLHRF_NODUMP; request.headers = (NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)*2); - request.headers[0].szName = mir_strdup("Content-Type"); - request.headers[0].szValue = mir_strdup("text/plain; charset=utf-8"); + request.headers[0].szName = "Content-Type"; + request.headers[0].szValue = "text/plain; charset=utf-8"; request.headersCount = 1; - char data[128]; - ptrA search(mir_utf8encodeT((TCHAR*)arg)); - ptrA searchEncoded(mir_urlEncode(search)); - mir_snprintf(data, SIZEOF(data), "{\"action\":3,\"name\":\"%s\"}", searchEncoded); + std::tstring search = (TCHAR*)arg; + size_t at = search.find('@'); + if (at != std::string::npos) + { + search.erase(search.begin() + at, search.end()); + } + + std::string query = "{\"action\":3,\"name\":\""; + query += ptrA(mir_utf8encodeT(search.c_str())); + query += "\"}"; - request.dataLength = strlen(data); - request.pData = (char*)mir_alloc(request.dataLength + 1); - memcpy(request.pData, data, request.dataLength); - request.pData[request.dataLength] = 0; + request.dataLength = query.length(); + request.pData = (char*)query.c_str(); NETLIBHTTPREQUEST* response = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&request); @@ -194,9 +201,6 @@ void CToxProto::SearchByNameAsync(void* arg) } CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM)response); - mir_free(request.pData); - mir_free(request.headers[0].szName); - mir_free(request.headers[0].szValue); mir_free(request.headers); ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)1, 0); diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 3857267c88..374b2d3ef8 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -4,6 +4,7 @@ int CToxProto::OnAccountLoaded(WPARAM, LPARAM) { HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, this); HookEventObj(ME_PROTO_ACCLISTCHANGED, OnAccountListChanged, this); + HookEventObj(ME_DB_CONTACT_SETTINGCHANGED, OnSettingsChanged, this); InitNetlib(); @@ -89,26 +90,28 @@ int CToxProto::OnContactDeleted(MCONTACT hContact, LPARAM lParam) return 1; } -int CToxProto::OnSettingsChanged(MCONTACT hContact, LPARAM lParam) +int CToxProto::OnSettingsChanged(void *obj, WPARAM hContact, LPARAM lParam) { + CToxProto *proto = (CToxProto*)obj; + DBCONTACTWRITESETTING* dbcws = (DBCONTACTWRITESETTING*)lParam; - if (hContact == NULL && !strcmp(dbcws->szModule, m_szModuleName)) + if (hContact == NULL && !strcmp(dbcws->szModule, proto->m_szModuleName)) { - if (!strcmp(dbcws->szSetting, "Nick")) + if (!strcmp(dbcws->szSetting, "Nick") && dbcws->value.pszVal) { - if (tox_set_name(tox, (uint8_t*)(char*)ptrA(mir_utf8encodeW(dbcws->value.ptszVal)), (uint16_t)_tcslen(dbcws->value.ptszVal))) + if (tox_set_name(proto->tox, (uint8_t*)dbcws->value.pszVal, (uint16_t)strlen(dbcws->value.pszVal))) { - SaveToxData(); + proto->SaveToxData(); } } - if (!strcmp(dbcws->szSetting, "StatusMsg") || !strcmp(dbcws->szSetting, "StatusNote")) + /*if (!strcmp(dbcws->szSetting, "StatusMsg") || !strcmp(dbcws->szSetting, "StatusNote")) { if (tox_set_status_message(tox, (uint8_t*)(char*)ptrA(mir_utf8encodeW(dbcws->value.ptszVal)), (uint16_t)_tcslen(dbcws->value.ptszVal))) { SaveToxData(); } - } + }*/ } return 0; diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 9571014deb..d8128fc8de 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -1,6 +1,26 @@ #include "common.h" -INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CToxProto::SearchDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA); + + switch (uMsg) + { + case WM_INITDIALOG: + TranslateDialogDefault(hwnd); + { + proto = (CToxProto*)lParam; + SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); + + CheckDlgButton(hwnd, IDC_ADDTOLIST, 1); + } + return TRUE; + } + + return FALSE; +} + +INT_PTR CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA); @@ -40,19 +60,19 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, break; case IDC_CLIPBOARD: + { + char toxId[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; + GetDlgItemTextA(hwnd, IDC_TOXID, toxId, SIZEOF(toxId)); + if (OpenClipboard(GetDlgItem(hwnd, IDC_TOXID))) { - char toxId[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; - GetDlgItemTextA(hwnd, IDC_TOXID, toxId, SIZEOF(toxId)); - if (OpenClipboard(GetDlgItem(hwnd, IDC_TOXID))) - { - EmptyClipboard(); - HGLOBAL hMem = GlobalAlloc(GMEM_FIXED, SIZEOF(toxId)); - memcpy(GlobalLock(hMem), toxId, SIZEOF(toxId)); - GlobalUnlock(hMem); - SetClipboardData(CF_TEXT, hMem); - CloseClipboard(); - } + EmptyClipboard(); + HGLOBAL hMem = GlobalAlloc(GMEM_FIXED, SIZEOF(toxId)); + memcpy(GlobalLock(hMem), toxId, SIZEOF(toxId)); + GlobalUnlock(hMem); + SetClipboardData(CF_TEXT, hMem); + CloseClipboard(); } + } break; case IDC_GROUP: @@ -102,7 +122,7 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, return FALSE; } -INT_PTR CALLBACK CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA); TCHAR *profilePath = (TCHAR*)GetWindowLongPtr(hwnd, DWLP_USER); @@ -115,7 +135,7 @@ INT_PTR CALLBACK CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM w proto = (CToxProto*)lParam; SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); - profilePath = (TCHAR*)mir_calloc(sizeof(TCHAR) * MAX_PATH); + profilePath = (TCHAR*)mir_calloc(sizeof(TCHAR)* MAX_PATH); SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)profilePath); CheckDlgButton(hwnd, IDC_CREATE_NEW, TRUE); @@ -139,38 +159,38 @@ INT_PTR CALLBACK CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM w break; case IDC_BROWSE_PROFILE: + { + TCHAR filter[MAX_PATH] = { 0 }; + mir_sntprintf(filter, MAX_PATH, _T("%s\0*.*"), TranslateT("All files (*.*)")); + + OPENFILENAME ofn = { sizeof(ofn) }; + ofn.hwndOwner = hwnd; + ofn.lpstrFilter = filter; + ofn.nFilterIndex = 1; + ofn.lpstrFile = profilePath; + ofn.lpstrTitle = TranslateT("Select tox profile"); + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER; + + if (GetOpenFileName(&ofn) && profilePath) { - TCHAR filter[MAX_PATH] = { 0 }; - mir_sntprintf(filter, MAX_PATH, _T("%s\0*.*"), TranslateT("All files (*.*)")); - - OPENFILENAME ofn = { sizeof(ofn) }; - ofn.hwndOwner = hwnd; - ofn.lpstrFilter = filter; - ofn.nFilterIndex = 1; - ofn.lpstrFile = profilePath; - ofn.lpstrTitle = TranslateT("Select tox profile"); - ofn.nMaxFile = MAX_PATH; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER; - - if (GetOpenFileName(&ofn) && profilePath) - { - SetDlgItemText(hwnd, IDC_PROFILE_PATH, profilePath); - } + SetDlgItemText(hwnd, IDC_PROFILE_PATH, profilePath); } + } break; case IDOK: + { + if (IsDlgButtonChecked(hwnd, IDC_USE_EXISTING)) { - if (IsDlgButtonChecked(hwnd, IDC_USE_EXISTING)) + if (profilePath != NULL) { - if (profilePath != NULL) - { - std::tstring toxProfilePath = proto->GetToxProfilePath(); - CopyFile(profilePath, toxProfilePath.c_str(), FALSE); - } + std::tstring toxProfilePath = proto->GetToxProfilePath(); + CopyFile(profilePath, toxProfilePath.c_str(), FALSE); } - EndDialog(hwnd, 1); } + EndDialog(hwnd, 1); + } break; } diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp index 18af6e9a73..0c96ffdff9 100644 --- a/protocols/Tox/src/tox_proto.cpp +++ b/protocols/Tox/src/tox_proto.cpp @@ -40,7 +40,7 @@ DWORD_PTR __cdecl CToxProto::GetCaps(int type, MCONTACT hContact) switch (type) { case PFLAGNUM_1: - return PF1_IM | PF1_AUTHREQ | PF1_BASICSEARCH | PF1_SEARCHBYEMAIL; + return PF1_IM | PF1_AUTHREQ | PF1_EXTSEARCH; case PFLAGNUM_2: return PF2_ONLINE | PF2_SHORTAWAY | PF2_LIGHTDND; case PFLAGNUM_4: @@ -129,33 +129,54 @@ int __cdecl CToxProto::FileResume(HANDLE hTransfer, int* action, const PROTOCHAR int __cdecl CToxProto::GetInfo(MCONTACT hContact, int infoType) { return 0; } -HANDLE __cdecl CToxProto::SearchBasic(const PROTOCHAR* id) -{ - if (!this->IsOnline()) - { - return 0; - } +HANDLE __cdecl CToxProto::SearchBasic(const PROTOCHAR* id) { return 0; } - ForkThread(&CToxProto::SearchByIdAsync, mir_tstrdup(id)); +HANDLE __cdecl CToxProto::SearchByEmail(const PROTOCHAR* email) { return 0; } - return (HANDLE)1; -} +HANDLE __cdecl CToxProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName) { return 0; } -HANDLE __cdecl CToxProto::SearchByEmail(const PROTOCHAR* email) +HWND __cdecl CToxProto::SearchAdvanced(HWND owner) { - if (!this->IsOnline()) + if (IsDlgButtonChecked(owner, IDC_SEARCH_TOXMESE)) { - return 0; + TCHAR address[MAX_PATH]; + GetDlgItemText(owner, IDC_SEARCH, address, SIZEOF(address)); + + ForkThread(&CToxProto::SearchByNameAsync, mir_tstrdup(address)); } + else + { + ADDCONTACTSTRUCT acs = { 0 }; - ForkThread(&CToxProto::SearchByNameAsync, mir_tstrdup(email)); + PROTOSEARCHRESULT psr = { 0 }; + psr.cbSize = sizeof(psr); + psr.flags = PSR_TCHAR; - return (HANDLE)1; + TCHAR toxId[TOX_MAX_NAME_LENGTH]; + GetDlgItemText(owner, IDC_SEARCH, toxId, TOX_MAX_NAME_LENGTH); + psr.id = toxId; + + acs.psr = &psr; + acs.szProto = m_szModuleName; + + acs.handleType = HANDLE_SEARCHRESULT; + CallService(MS_ADDCONTACT_SHOW, (WPARAM)owner, (LPARAM)&acs); + + ForkThread(&CToxProto::SearchByIdAsync, mir_tstrdup(toxId)); + } + + return (HWND)1; } -HANDLE __cdecl CToxProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* firstName, const PROTOCHAR* lastName) { return 0; } -HWND __cdecl CToxProto::SearchAdvanced(HWND owner) { return 0; } -HWND __cdecl CToxProto::CreateExtendedSearchUI(HWND owner) { return 0; } +HWND __cdecl CToxProto::CreateExtendedSearchUI(HWND owner) +{ + return CreateDialogParam( + g_hInstance, + MAKEINTRESOURCE(IDD_SEARCH), + owner, + SearchDlgProc, + (LPARAM)this); +} int __cdecl CToxProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT*) { return 0; } int __cdecl CToxProto::RecvFile(MCONTACT hContact, PROTOFILEEVENT*) { return 0; } @@ -269,9 +290,6 @@ int __cdecl CToxProto::OnEvent(PROTOEVENTTYPE iEventType, WPARAM wParam, LPARAM case EV_PROTO_ONCONTACTDELETED: return OnContactDeleted(wParam, lParam); - case EV_PROTO_DBSETTINGSCHANGED: - return OnSettingsChanged(wParam, lParam); - case EV_PROTO_ONEXIT: return OnPreShutdown(wParam, lParam); } diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 83f4ef026c..243b4625af 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -99,12 +99,13 @@ private: //events int __cdecl OnAccountLoaded(WPARAM, LPARAM); int __cdecl OnContactDeleted(MCONTACT, LPARAM); - int __cdecl OnSettingsChanged(MCONTACT, LPARAM); int __cdecl OnPreShutdown(WPARAM, LPARAM); + + static int __cdecl OnOptionsInit(void *obj, WPARAM wParam, LPARAM lParam); + static int __cdecl OnSettingsChanged(void *obj, WPARAM wParam, LPARAM lParam); + static int __cdecl OnAccountListChanged(void *obj, WPARAM wParam, LPARAM lParam); INT_PTR __cdecl OnAccountManagerInit(WPARAM, LPARAM); - static int __cdecl OnAccountListChanged(void *obj, WPARAM wParam, LPARAM lParam); - static int __cdecl OnOptionsInit(void *obj, WPARAM wParam, LPARAM lParam); static void OnFriendRequest(Tox *tox, const uint8_t *userId, const uint8_t *message, const uint16_t messageSize, void *arg); static void OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t *message, const uint16_t messageSize, void *arg); @@ -153,6 +154,7 @@ private: void SaveToxData(); // dialogs + static INT_PTR CALLBACK SearchDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); }; -- cgit v1.2.3