summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--protocols/Tox/res/resource.rc5
-rw-r--r--protocols/Tox/src/resource.h2
-rw-r--r--protocols/Tox/src/tox_contacts.cpp31
-rw-r--r--protocols/Tox/src/tox_options.cpp4
-rw-r--r--protocols/Tox/src/tox_proto.cpp32
5 files changed, 40 insertions, 34 deletions
diff --git a/protocols/Tox/res/resource.rc b/protocols/Tox/res/resource.rc
index 3b801ef909..3bfd8ffac4 100644
--- a/protocols/Tox/res/resource.rc
+++ b/protocols/Tox/res/resource.rc
@@ -130,9 +130,8 @@ 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
+ EDITTEXT IDC_SEARCH,0,4,109,14,ES_AUTOHSCROLL
+ LTEXT "If this field contains tox address (76 hex character), you will be prompted to add it in your friend list. Otherwise, miranda will search this query via toxme.se.",IDC_STATIC,0,20,109,93
END
diff --git a/protocols/Tox/src/resource.h b/protocols/Tox/src/resource.h
index 3ecd31b638..0f9ef1130d 100644
--- a/protocols/Tox/src/resource.h
+++ b/protocols/Tox/src/resource.h
@@ -9,8 +9,6 @@
#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_PROFILE_PATH 1006
#define IDC_SEARCH 1006
diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp
index 0745888dad..c5bc9890b2 100644
--- a/protocols/Tox/src/tox_contacts.cpp
+++ b/protocols/Tox/src/tox_contacts.cpp
@@ -72,7 +72,12 @@ MCONTACT CToxProto::FindContact(const char *clientId)
MCONTACT CToxProto::AddContact(const char *clientId, bool isTemporary)
{
- MCONTACT hContact = FindContact(clientId);
+ std::string toxId = clientId;
+ if (toxId.length() > TOX_CLIENT_ID_SIZE * 2)
+ {
+ toxId.erase(toxId.begin() + TOX_CLIENT_ID_SIZE * 2, toxId.end());
+ }
+ MCONTACT hContact = FindContact(toxId.c_str());
if (!hContact)
{
hContact = (MCONTACT)CallService(MS_DB_CONTACT_ADD, 0, 0);
@@ -84,7 +89,7 @@ MCONTACT CToxProto::AddContact(const char *clientId, bool isTemporary)
db_set_b(hContact, "CList", "Auth", 1);
}
- setString(hContact, TOX_SETTINGS_ID, clientId);
+ setString(hContact, TOX_SETTINGS_ID, toxId.c_str());
DBVARIANT dbv;
if (!getTString(TOX_SETTINGS_GROUP, &dbv))
@@ -131,22 +136,20 @@ void CToxProto::LoadContactList()
void CToxProto::SearchByIdAsync(void* arg)
{
- std::string clientId = mir_utf8encodeT((TCHAR*)arg);
- if (clientId.length() > TOX_CLIENT_ID_SIZE * 2)
- {
- clientId.erase(clientId.begin() + TOX_CLIENT_ID_SIZE * 2, clientId.end());
- }
+ std::string toxId = (char*)arg;
+ toxId.erase(toxId.begin() + TOX_CLIENT_ID_SIZE * 2, toxId.end());
- std::string toxId = clientId;
- MCONTACT hContact = FindContact(clientId.c_str());
+ MCONTACT hContact = FindContact(toxId.c_str());
if (hContact)
{
ShowNotification(TranslateT("Contact already in your contact list"), 0, hContact);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HWND)1, 0);
+ mir_free(arg);
return;
}
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HWND)1, 0);
+ mir_free(arg);
}
void CToxProto::SearchByNameAsync(void* arg)
@@ -161,15 +164,8 @@ void CToxProto::SearchByNameAsync(void* arg)
request.headers[0].szValue = "text/plain; charset=utf-8";
request.headersCount = 1;
- 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 += (char*)arg;
query += "\"}";
request.dataLength = query.length();
@@ -204,4 +200,5 @@ void CToxProto::SearchByNameAsync(void* arg)
mir_free(request.headers);
ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_FAILED, (HANDLE)1, 0);
+ mir_free(arg);
} \ No newline at end of file
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index d8128fc8de..b7754f965b 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -13,6 +13,10 @@ INT_PTR CToxProto::SearchDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lPa
SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
CheckDlgButton(hwnd, IDC_ADDTOLIST, 1);
+
+ //ShowWindow(GetDlgItem(GetParent(hwnd), 1408/*IDC_BYCUSTOM*/), SW_HIDE);
+ //ShowWindow(GetDlgItem(GetParent(hwnd), 1402/*IDC_ADVANCEDGROUP*/), SW_HIDE);
+ SetDlgItemText(GetParent(hwnd), 1408/*IDC_BYCUSTOM*/, TranslateT("Query"));
}
return TRUE;
}
diff --git a/protocols/Tox/src/tox_proto.cpp b/protocols/Tox/src/tox_proto.cpp
index 0c96ffdff9..585ff4496b 100644
--- a/protocols/Tox/src/tox_proto.cpp
+++ b/protocols/Tox/src/tox_proto.cpp
@@ -137,24 +137,23 @@ HANDLE __cdecl CToxProto::SearchByName(const PROTOCHAR* nick, const PROTOCHAR* f
HWND __cdecl CToxProto::SearchAdvanced(HWND owner)
{
- if (IsDlgButtonChecked(owner, IDC_SEARCH_TOXMESE))
- {
- TCHAR address[MAX_PATH];
- GetDlgItemText(owner, IDC_SEARCH, address, SIZEOF(address));
+ std::smatch match;
+ std::regex regex("^\\s*([A-Fa-f0-9]{76})\\s*$");
- ForkThread(&CToxProto::SearchByNameAsync, mir_tstrdup(address));
- }
- else
+ char text[TOX_FRIEND_ADDRESS_SIZE * 2 + 1];
+ GetDlgItemTextA(owner, IDC_SEARCH, text, SIZEOF(text));
+
+ const std::string query = text;
+ if (std::regex_search(query, match, regex))
{
+ std::string clientId = match[1];
+
ADDCONTACTSTRUCT acs = { 0 };
PROTOSEARCHRESULT psr = { 0 };
psr.cbSize = sizeof(psr);
psr.flags = PSR_TCHAR;
-
- TCHAR toxId[TOX_MAX_NAME_LENGTH];
- GetDlgItemText(owner, IDC_SEARCH, toxId, TOX_MAX_NAME_LENGTH);
- psr.id = toxId;
+ psr.id = mir_a2t(query.c_str());
acs.psr = &psr;
acs.szProto = m_szModuleName;
@@ -162,7 +161,16 @@ HWND __cdecl CToxProto::SearchAdvanced(HWND owner)
acs.handleType = HANDLE_SEARCHRESULT;
CallService(MS_ADDCONTACT_SHOW, (WPARAM)owner, (LPARAM)&acs);
- ForkThread(&CToxProto::SearchByIdAsync, mir_tstrdup(toxId));
+ ForkThread(&CToxProto::SearchByIdAsync, mir_strdup(query.c_str()));
+ }
+ else
+ {
+ regex = "^\\s*([A-Za-z]+)(@toxme.se)?\\s*$";
+ if (std::regex_search(query, match, regex))
+ {
+ std::string query = match[1];
+ ForkThread(&CToxProto::SearchByNameAsync, mir_strdup(query.c_str()));
+ }
}
return (HWND)1;