diff options
Diffstat (limited to 'protocols/Tox/src')
| -rw-r--r-- | protocols/Tox/src/tox_account.cpp | 5 | ||||
| -rw-r--r-- | protocols/Tox/src/tox_contacts.cpp | 8 | ||||
| -rw-r--r-- | protocols/Tox/src/tox_events.cpp | 2 | ||||
| -rw-r--r-- | protocols/Tox/src/tox_options.cpp | 92 | ||||
| -rw-r--r-- | protocols/Tox/src/tox_utils.cpp | 4 | 
5 files changed, 48 insertions, 63 deletions
diff --git a/protocols/Tox/src/tox_account.cpp b/protocols/Tox/src/tox_account.cpp index b4871425d2..f78f8b24a2 100644 --- a/protocols/Tox/src/tox_account.cpp +++ b/protocols/Tox/src/tox_account.cpp @@ -41,10 +41,11 @@ void CToxProto::InitToxCore()  	LoadToxData();
 -	std::vector<uint8_t> username(TOX_MAX_NAME_LENGTH);
 +	int size = tox_get_self_name_size(tox);
 +	std::vector<uint8_t> username(size);
  	tox_get_self_name(tox, &username[0]);
  	std::string nick(username.begin(), username.end());
 -	setString("Nick", nick.c_str());
 +	setWString("Nick", ptrW(Utf8DecodeW(nick.c_str())));
  }
  void CToxProto::UninitToxCore()
 diff --git a/protocols/Tox/src/tox_contacts.cpp b/protocols/Tox/src/tox_contacts.cpp index 37a5cc1f11..ea08d4338d 100644 --- a/protocols/Tox/src/tox_contacts.cpp +++ b/protocols/Tox/src/tox_contacts.cpp @@ -105,21 +105,19 @@ void CToxProto::LoadContactList()  		int32_t *friends = (int32_t*)mir_alloc(count * sizeof(int32_t));
  		tox_get_friendlist(tox, friends, count);
  		std::vector<uint8_t> clientId(TOX_CLIENT_ID_SIZE);
 -		std::vector<uint8_t> username(TOX_MAX_NAME_LENGTH);
  		for (uint32_t i = 0; i < count; ++i)
  		{
  			tox_get_client_id(tox, friends[i], &clientId[0]);
  			std::string toxId = DataToHexString(clientId);
 -			debugLogA("CToxProto::SendMsg: friend id is %s", toxId.c_str());
 -			debugLogA("CToxProto::SendMsg: friend number is %d", friends[i]);
 -
  			MCONTACT hContact = AddContact(toxId.c_str());
  			if (hContact)
  			{
 +				int size = tox_get_name_size(tox, friends[i]);
 +				std::vector<uint8_t> username(size);
  				tox_get_name(tox, friends[i], &username[0]);
  				std::string nick(username.begin(), username.end());
 -				setString(hContact, "Nick", nick.c_str());
 +				setWString(hContact, "Nick", ptrW(Utf8DecodeW(nick.c_str())));
  			}
  			//tox_get_last_online
 diff --git a/protocols/Tox/src/tox_events.cpp b/protocols/Tox/src/tox_events.cpp index 84193c059e..10f3c29701 100644 --- a/protocols/Tox/src/tox_events.cpp +++ b/protocols/Tox/src/tox_events.cpp @@ -81,8 +81,6 @@ void CToxProto::OnFriendMessage(Tox *tox, const int friendnumber, const uint8_t  {
  	CToxProto *proto = (CToxProto*)arg;
 -	proto->debugLogA("CToxProto::OnFriendMessage: friend number is %d", friendnumber);
 -
  	std::vector<uint8_t> clientId(TOX_CLIENT_ID_SIZE);
  	tox_get_client_id(tox, friendnumber, &clientId[0]);
  	std::string toxId = proto->DataToHexString(clientId);
 diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index 719d30cbc5..8d60339a62 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -24,14 +24,6 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,  			CheckDlgButton(hwnd, IDC_DISABLE_UDP, proto->getByte("DisableUDP", 0));
  			CheckDlgButton(hwnd, IDC_DISABLE_IPV6, proto->getByte("DisableIPv6", 0));
 -
 -			if (proto->IsOnline())
 -			{
 -				EnableWindow(GetDlgItem(hwnd, IDC_USERNAME), FALSE);
 -				EnableWindow(GetDlgItem(hwnd, IDC_DATAPATH), FALSE);
 -				EnableWindow(GetDlgItem(hwnd, IDC_DISABLE_UDP), FALSE);
 -				EnableWindow(GetDlgItem(hwnd, IDC_DISABLE_IPV6), FALSE);
 -			}
  		}
  		return TRUE;
 @@ -42,7 +34,6 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,  		case IDC_USERNAME:
  			if ((HWND)lParam == GetFocus())
  			{
 -				EnableWindow(GetDlgItem(hwnd, IDC_USERNAME), !proto->IsOnline());
  				if (HIWORD(wParam) != EN_CHANGE) return 0;
  				char username[128];
  				GetDlgItemTextA(hwnd, IDC_USERNAME, username, SIZEOF(username));
 @@ -53,7 +44,6 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,  		case IDC_DATAPATH:
  			if ((HWND)lParam == GetFocus())
  			{
 -				EnableWindow(GetDlgItem(hwnd, IDC_DATAPATH), !proto->IsOnline());
  				if (HIWORD(wParam) != EN_CHANGE) return 0;
  				char dataPath[128];
  				GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
 @@ -62,36 +52,36 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,  			break;
  		case IDC_BROWSE:
 +		{
 +			char dataPath[MAX_PATH];
 +			GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
 +
 +			char filter[MAX_PATH] = "";
 +			mir_snprintf(filter, MAX_PATH, "%s\0*.*\0", Translate("All Files (*.*)"));
 +
 +			OPENFILENAMEA ofn = { 0 };
 +			ofn.lStructSize = sizeof(ofn);
 +			ofn.hwndOwner = 0;
 +			ofn.lpstrFilter = filter;
 +			ofn.nFilterIndex = 1;
 +			ofn.lpstrFile = dataPath;
 +			ofn.lpstrTitle = Translate("Select data file");
 +			ofn.nMaxFile = SIZEOF(dataPath);
 +			ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
 +			if (GetOpenFileNameA(&ofn) && dataPath[0])
  			{
 -				char dataPath[MAX_PATH];
 -				GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
 -
 -				char filter[MAX_PATH] = "";
 -				mir_snprintf(filter, MAX_PATH, "%s\0*.*\0", Translate("All Files (*.*)"));
 -
 -				OPENFILENAMEA ofn = { 0 };
 -				ofn.lStructSize = sizeof(ofn);
 -				ofn.hwndOwner = 0;
 -				ofn.lpstrFilter = filter;
 -				ofn.nFilterIndex = 1;
 -				ofn.lpstrFile = strrchr(dataPath, '\\') + 1;
 -				ofn.lpstrTitle = Translate("Select data file");
 -				ofn.nMaxFile = SIZEOF(dataPath);
 -				ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR;
 -				if (GetOpenFileNameA(&ofn) && dataPath[0])
 -				{
 -					SetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath);
 -					SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
 -				}
 +				SetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath);
 +				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);
 -			}
 +		{
 +			if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
 +				return 0;
 +			SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
 +		}
  			break;
  		case IDC_DISABLE_UDP:
 @@ -108,24 +98,13 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,  	case WM_NOTIFY:
  		if (reinterpret_cast<NMHDR*>(lParam)->code == PSN_APPLY)
  		{
 -			if (!proto->IsOnline())
 -			{
 -				char username[128];
 -				GetDlgItemTextA(hwnd, IDC_USERNAME, username, SIZEOF(username));
 -				proto->setString("Username", username);
 -				tox_set_name(proto->tox, (uint8_t*)&username[0], strlen(username));
 -
 -				proto->UninitToxCore();
 -
 -				char dataPath[128];
 -				GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
 -				proto->setString("DataPath", dataPath);
 -
 -				proto->setByte("DisableUDP", (BYTE)IsDlgButtonChecked(hwnd, IDC_DISABLE_UDP));
 -				proto->setByte("DisableIPv6", (BYTE)IsDlgButtonChecked(hwnd, IDC_DISABLE_IPV6));
 +			char username[128];
 +			GetDlgItemTextA(hwnd, IDC_USERNAME, username, SIZEOF(username));
 +			proto->setString("Username", username);
 +			tox_set_name(proto->tox, (uint8_t*)&username[0], strlen(username));
 -				proto->InitToxCore();
 -			}
 +			proto->setByte("DisableUDP", (BYTE)IsDlgButtonChecked(hwnd, IDC_DISABLE_UDP));
 +			proto->setByte("DisableIPv6", (BYTE)IsDlgButtonChecked(hwnd, IDC_DISABLE_IPV6));
  			wchar_t groupName[128];
  			GetDlgItemText(hwnd, IDC_GROUP, groupName, SIZEOF(groupName));
 @@ -137,6 +116,15 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam,  			else
  				proto->delSetting(NULL, TOX_SETTINGS_GROUP);
 +			char dataPath[128];
 +			GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
 +			if (proto->GetToxProfilePath().compare(dataPath) != 0)
 +			{
 +				proto->UninitToxCore();
 +				proto->setString("DataPath", dataPath);
 +				proto->InitToxCore();
 +			}
 +
  			return TRUE;
  		}
  		break;
 diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index 71efde31d1..7c321ac2c7 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -117,10 +117,10 @@ std::vector<uint8_t> CToxProto::HexStringToData(std::string hex)  std::string CToxProto::DataToHexString(std::vector<uint8_t> data)
  {
  	std::ostringstream oss;
 -	oss << std::setfill('0');
 +	oss << std::hex << std::uppercase << std::setfill('0');
  	for (int i = 0; i < data.size(); i++)
  	{
 -		oss << std::setw(2) << std::hex << std::uppercase << static_cast<int>(data[i]);
 +		oss << std::setw(2) << static_cast<int>(data[i]);
  	}
  	return oss.str();
  }
  | 
