From 56918868664203496199593189f67455dd4f8c38 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Wed, 2 Sep 2015 19:26:26 +0000 Subject: Tox: - show error if profile loading failed - code cleaning - menus uid git-svn-id: http://svn.miranda-ng.org/main/trunk@15158 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_contacts.cpp | 4 ++-- protocols/Tox/src/tox_core.cpp | 2 -- protocols/Tox/src/tox_menus.cpp | 3 +++ protocols/Tox/src/tox_profile.cpp | 6 +++++- protocols/Tox/src/tox_proto.h | 2 ++ protocols/Tox/src/tox_utils.cpp | 27 +++++++++++++++++++++++++++ 6 files changed, 39 insertions(+), 5 deletions(-) (limited to 'protocols/Tox/src') diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index f6e99a5252..d5b166ce75 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -97,7 +97,7 @@ MCONTACT CToxProto::AddContact(const char *address, const char *nick, const char uint32_t CToxProto::GetToxFriendNumber(MCONTACT hContact) { - ToxBinAddress pubKey = ptrA(getStringA(hContact, TOX_SETTINGS_ID)); + ToxBinAddress pubKey(ptrA(getStringA(hContact, TOX_SETTINGS_ID))); TOX_ERR_FRIEND_BY_PUBLIC_KEY error; uint32_t friendNumber = tox_friend_by_public_key(tox, pubKey.GetPubKey(), &error); if (error != TOX_ERR_FRIEND_BY_PUBLIC_KEY_OK) @@ -156,7 +156,7 @@ INT_PTR CToxProto::OnRequestAuth(WPARAM hContact, LPARAM lParam) char *reason = lParam ? (char*)lParam : " "; size_t length = mir_strlen(reason); - ToxBinAddress address = ptrA(getStringA(hContact, TOX_SETTINGS_ID)); + ToxBinAddress address(ptrA(getStringA(hContact, TOX_SETTINGS_ID))); TOX_ERR_FRIEND_ADD addFriendResult; int32_t friendNumber = tox_friend_add(tox, address, (uint8_t*)reason, length, &addFriendResult); diff --git a/protocols/Tox/src/tox_core.cpp b/protocols/Tox/src/tox_core.cpp index fc5527adec..242a2eafa9 100644 --- a/protocols/Tox/src/tox_core.cpp +++ b/protocols/Tox/src/tox_core.cpp @@ -39,8 +39,6 @@ bool CToxProto::InitToxCore() } } - debugLogA(__FUNCTION__": loading tox profile"); - if (LoadToxProfile(options)) { tox_callback_friend_request(tox, OnFriendRequest, this); diff --git a/protocols/Tox/src/tox_menus.cpp b/protocols/Tox/src/tox_menus.cpp index 565a66e4c2..bd342903dd 100644 --- a/protocols/Tox/src/tox_menus.cpp +++ b/protocols/Tox/src/tox_menus.cpp @@ -45,6 +45,7 @@ void CToxProto::InitMenus() mi.flags = CMIF_TCHAR; // Request authorization + SET_UID(mi, 0x36375a1f, 0xc142, 0x4d6e, 0xa6, 0x57, 0xe4, 0x76, 0x5d, 0xbc, 0x59, 0x8e); mi.pszService = MODULE"/RequestAuth"; mi.name.t = LPGENT("Request authorization"); mi.position = CMI_POSITION + CMI_AUTH_REQUEST; @@ -53,6 +54,7 @@ void CToxProto::InitMenus() CreateServiceFunction(mi.pszService, GlobalService<&CToxProto::OnRequestAuth>); // Grant authorization + SET_UID(mi, 0x4c90452a, 0x869a, 0x4a81, 0xaf, 0xa8, 0x28, 0x34, 0xaf, 0x2b, 0x6b, 0x30); mi.pszService = MODULE"/GrantAuth"; mi.name.t = LPGENT("Grant authorization"); mi.position = CMI_POSITION + CMI_AUTH_GRANT; @@ -61,6 +63,7 @@ void CToxProto::InitMenus() CreateServiceFunction(mi.pszService, GlobalService<&CToxProto::OnGrantAuth>); // Start audio call + SET_UID(mi, 0x116cb7fe, 0xce37, 0x429c, 0xb0, 0xa9, 0x7d, 0xe7, 0x70, 0x59, 0xc3, 0x95); mi.pszService = MODULE"/Audio/Call"; mi.name.t = LPGENT("Call"); mi.position = -2000020000 + CMI_AUDIO_CALL; diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index 89f40d75e7..aea5492686 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -32,6 +32,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) FILE *profile = _tfopen(profilePath.c_str(), _T("rb")); if (profile == NULL) { + ShowNotification(TranslateT("Unable to open tox profile"), MB_ICONERROR); debugLogA(__FUNCTION__": failed to open tox profile"); return false; } @@ -49,6 +50,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) if (fread((char*)data, sizeof(char), size, profile) != size) { fclose(profile); + ShowNotification(TranslateT("Unable to read tox profile"), MB_ICONERROR); debugLogA(__FUNCTION__": failed to read tox profile"); mir_free(data); return false; @@ -71,7 +73,8 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) TOX_ERR_DECRYPTION coreDecryptError; if (!tox_pass_decrypt(data, size, (uint8_t*)password, mir_strlen(password), encryptedData, &coreDecryptError)) { - debugLogA(__FUNCTION__": failed to load tox profile (%d)", coreDecryptError); + ShowNotification(TranslateT("Unable to decrypt tox profile"), MB_ICONERROR); + debugLogA(__FUNCTION__": failed to decrypt tox profile (%d)", coreDecryptError); mir_free(data); return false; } @@ -92,6 +95,7 @@ bool CToxProto::LoadToxProfile(Tox_Options *options) if (initError != TOX_ERR_NEW_OK) { debugLogA(__FUNCTION__": failed to load tox profile (%d)", initError); + ShowNotification(ToxErrorToString(initError), TranslateT("Unable to load tox profile"), MB_ICONERROR); mir_free(data); return false; } diff --git a/protocols/Tox/src/tox_proto.h b/protocols/Tox/src/tox_proto.h index 36705265f2..cb33550aa0 100644 --- a/protocols/Tox/src/tox_proto.h +++ b/protocols/Tox/src/tox_proto.h @@ -278,6 +278,8 @@ private: TOX_USER_STATUS MirandaToToxStatus(int status); int ToxToMirandaStatus(TOX_USER_STATUS userstatus); + static TCHAR* ToxErrorToString(TOX_ERR_NEW error); + static void ShowNotification(const TCHAR *message, int flags = 0, MCONTACT hContact = NULL); static void ShowNotification(const TCHAR *caption, const TCHAR *message, int flags = 0, MCONTACT hContact = NULL); diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index b0f2b46b18..223d3b1b70 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -33,6 +33,33 @@ int CToxProto::ToxToMirandaStatus(TOX_USER_STATUS userstatus) return status; } +TCHAR* CToxProto::ToxErrorToString(TOX_ERR_NEW error) +{ + switch (error) + { + case TOX_ERR_NEW_NULL: + return TranslateT("One of the arguments is not valid or "); + case TOX_ERR_NEW_MALLOC: + return TranslateT("Unable to allocate enough memory"); + case TOX_ERR_NEW_PORT_ALLOC: + return TranslateT("Unable to bind to a port"); + case TOX_ERR_NEW_PROXY_BAD_TYPE: + return TranslateT("The proxy type is not valid"); + case TOX_ERR_NEW_PROXY_BAD_HOST: + return TranslateT("The proxy host is not valid"); + case TOX_ERR_NEW_PROXY_BAD_PORT: + return TranslateT("The proxy port is not valid"); + case TOX_ERR_NEW_PROXY_NOT_FOUND: + return TranslateT("The proxy address could not be resolved"); + case TOX_ERR_NEW_LOAD_ENCRYPTED: + return TranslateT("The profile is encrypted"); + case TOX_ERR_NEW_LOAD_BAD_FORMAT: + return TranslateT("The data format is not valid"); + default: + return TranslateT("Unknown error"); + } +} + void CToxProto::ShowNotification(const TCHAR *caption, const TCHAR *message, int flags, MCONTACT hContact) { if (Miranda_Terminated()) -- cgit v1.2.3