From 591fc6380f5610588661cdbb8097f0f1ac3a16fb Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Sat, 18 Jun 2016 12:51:36 +0000 Subject: Tox: attempt to fix nickname setting git-svn-id: http://svn.miranda-ng.org/main/trunk@17006 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_core.cpp | 26 ++++++++++++++++++++++---- protocols/Tox/src/tox_options.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 5 deletions(-) (limited to 'protocols/Tox/src') diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp index 0188265f18..b535597a0e 100644 --- a/protocols/Tox/src/tox_core.cpp +++ b/protocols/Tox/src/tox_core.cpp @@ -91,13 +91,31 @@ bool CToxProto::InitToxCore(CToxThread *toxThread) ToxHexAddress address(data); setString(TOX_SETTINGS_ID, address); - uint8_t nick[TOX_MAX_NAME_LENGTH] = { 0 }; + TOX_ERR_SET_INFO error; + + /*uint8_t nick[TOX_MAX_NAME_LENGTH] = { 0 }; tox_self_get_name(toxThread->Tox(), nick); - setTString("Nick", ptrT(Utf8DecodeT((char*)nick))); + setTString("Nick", ptrT(Utf8DecodeT((char*)nick)));*/ + + ptrA nick(mir_utf8encodeT(ptrT(getTStringA("Nick")))); + tox_self_set_name(toxThread->Tox(), (uint8_t*)(char*)nick, mir_strlen(nick), &error); + if (error != TOX_ERR_SET_INFO_OK) + { + debugLogA(__FUNCTION__": failed to set self name (%d)", error); + return NULL; + } - uint8_t statusMessage[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 }; + /*uint8_t statusMessage[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 }; tox_self_get_status_message(toxThread->Tox(), statusMessage); - setTString("StatusMsg", ptrT(Utf8DecodeT((char*)statusMessage))); + setTString("StatusMsg", ptrT(Utf8DecodeT((char*)statusMessage)));*/ + + ptrA statusMessage(mir_utf8encodeT(ptrT(getTStringA("StatusMsg")))); + tox_self_set_status_message(toxThread->Tox(), (uint8_t*)(char*)statusMessage, mir_strlen(statusMessage), &error); + if (error != TOX_ERR_SET_INFO_OK) + { + debugLogA(__FUNCTION__": failed to set self status message (%d)", error); + return NULL; + } return true; } diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index b6cad21929..887ebe88ab 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -127,7 +127,37 @@ void CToxOptionsMain::ProfileImport_OnClick(CCtrlButton*) if (mir_tstrcmpi(profilePath, defaultProfilePath) != 0) CopyFile(profilePath, defaultProfilePath, FALSE); - m_profileCreate.OnClick(&m_profileCreate); + Tox_Options *options = NULL; + tox_options_default(options); + if (m_proto->LoadToxProfile(options)) + { + CToxThread toxThread(options); + + uint8_t data[TOX_ADDRESS_SIZE]; + tox_self_get_address(toxThread.Tox(), data); + ToxHexAddress address(data); + m_proto->setString(TOX_SETTINGS_ID, address); + + m_toxAddress.Enable(); + m_toxAddress.SetTextA(address); + + uint8_t nick[TOX_MAX_NAME_LENGTH] = { 0 }; + tox_self_get_name(toxThread.Tox(), nick); + ptrT nickname(Utf8DecodeT((char*)nick)); + m_proto->setTString("Nick", nickname); + m_nickname.SetText(nickname); + + uint8_t statusMessage[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 }; + tox_self_get_status_message(toxThread.Tox(), statusMessage); + m_proto->setTString("StatusMsg", ptrT(Utf8DecodeT((char*)statusMessage))); + + ShowWindow(m_profileCreate.GetHwnd(), FALSE); + ShowWindow(m_profileImport.GetHwnd(), FALSE); + + ShowWindow(m_toxAddressCopy.GetHwnd(), TRUE); + ShowWindow(m_profileExport.GetHwnd(), TRUE); + } + tox_options_free(options); } void CToxOptionsMain::ProfileExport_OnClick(CCtrlButton*) -- cgit v1.2.3