summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_options.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Tox/src/tox_options.cpp')
-rw-r--r--protocols/Tox/src/tox_options.cpp177
1 files changed, 59 insertions, 118 deletions
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp
index bf4aeea940..71353d3263 100644
--- a/protocols/Tox/src/tox_options.cpp
+++ b/protocols/Tox/src/tox_options.cpp
@@ -5,23 +5,33 @@ CToxOptionsMain::CToxOptionsMain(CToxProto *proto, int idDialog)
m_toxAddress(this, IDC_TOXID), m_toxAddressCopy(this, IDC_CLIPBOARD),
m_profileCreate(this, IDC_PROFILE_NEW), m_profileImport(this, IDC_PROFILE_IMPORT),
m_profileExport(this, IDC_PROFILE_EXPORT), m_nickname(this, IDC_NAME),
- m_password(this, IDC_PASSWORD), m_group(this, IDC_GROUP),
- m_enableUdp(this, IDC_ENABLE_UDP), m_enableIPv6(this, IDC_ENABLE_IPV6),
+ m_passwordCreate(this, IDC_PASSWORD_CREATE), m_passwordChange(this, IDC_PASSWORD_CHANGE),
+ m_passwordRemove(this, IDC_PASSWORD_REMOVE), m_group(this, IDC_GROUP),
+ m_enableUdp(this, IDC_ENABLE_UDP), m_enableUdpHolePunching(this, IDC_ENABLE_HOLEPUNCHING),
+ m_enableIPv6(this, IDC_ENABLE_IPV6), m_enableLocalDiscovery(this, IDC_ENABLE_LOCALDISCOVERY),
m_maxConnectRetries(this, IDC_MAXCONNECTRETRIES), m_maxConnectRetriesSpin(this, IDC_MAXCONNECTRETRIESSPIN),
m_maxReconnectRetries(this, IDC_MAXRECONNECTRETRIES), m_maxReconnectRetriesSpin(this, IDC_MAXRECONNECTRETRIESSPIN)
{
CreateLink(m_toxAddress, TOX_SETTINGS_ID, L"");
CreateLink(m_nickname, "Nick", L"");
- CreateLink(m_password, "Password", L"");
CreateLink(m_group, TOX_SETTINGS_GROUP, L"Tox");
CreateLink(m_enableUdp, "EnableUDP", DBVT_BYTE, TRUE);
+ CreateLink(m_enableUdpHolePunching, "EnableUDPHolePunching", DBVT_BYTE, TRUE);
CreateLink(m_enableIPv6, "EnableIPv6", DBVT_BYTE, FALSE);
+ CreateLink(m_enableLocalDiscovery, "EnableLocalDiscovery", DBVT_BYTE, FALSE);
if (idDialog == IDD_OPTIONS_MAIN) {
CreateLink(m_maxConnectRetries, "MaxConnectRetries", DBVT_BYTE, TOX_MAX_CONNECT_RETRIES);
CreateLink(m_maxReconnectRetries, "MaxReconnectRetries", DBVT_BYTE, TOX_MAX_RECONNECT_RETRIES);
}
+ m_passwordCreate.OnClick = Callback(this, &CToxOptionsMain::PasswordCreate_OnClick);
+ m_passwordChange.OnClick = Callback(this, &CToxOptionsMain::PasswordChange_OnClick);
+ m_passwordRemove.OnClick = Callback(this, &CToxOptionsMain::PasswordRemove_OnClick);
+
+ m_enableUdp.OnChange = Callback(this, &CToxOptionsMain::EnableUdp_OnClick);
+ m_enableUdpHolePunching.Enable(m_enableUdp.GetState());
+
m_toxAddressCopy.OnClick = Callback(this, &CToxOptionsMain::ToxAddressCopy_OnClick);
m_profileCreate.OnClick = Callback(this, &CToxOptionsMain::ProfileCreate_OnClick);
m_profileImport.OnClick = Callback(this, &CToxOptionsMain::ProfileImport_OnClick);
@@ -36,17 +46,26 @@ void CToxOptionsMain::OnInitDialog()
if (CToxProto::IsFileExists(profilePath)) {
m_toxAddress.Enable();
- ShowWindow(m_profileCreate.GetHwnd(), FALSE);
- ShowWindow(m_profileImport.GetHwnd(), FALSE);
+ m_profileCreate.Hide();
+ m_profileImport.Hide();
- ShowWindow(m_toxAddressCopy.GetHwnd(), TRUE);
- ShowWindow(m_profileExport.GetHwnd(), TRUE);
+ m_toxAddressCopy.Show();
+ m_profileExport.Show();
}
- SendMessage(m_toxAddress.GetHwnd(), EM_LIMITTEXT, TOX_ADDRESS_SIZE * 2, 0);
- SendMessage(m_nickname.GetHwnd(), EM_LIMITTEXT, TOX_MAX_NAME_LENGTH, 0);
- SendMessage(m_password.GetHwnd(), EM_LIMITTEXT, 32, 0);
- SendMessage(m_group.GetHwnd(), EM_LIMITTEXT, 64, 0);
+ m_passwordCreate.Enable(m_proto->IsOnline());
+ m_passwordChange.Enable(m_proto->IsOnline());
+ m_passwordRemove.Enable(m_proto->IsOnline());
+
+ pass_ptrW password(m_proto->getWStringA(TOX_SETTINGS_PASSWORD));
+ bool passwordExists = mir_wstrlen(password) > 0;
+ m_passwordCreate.Show(!passwordExists);
+ m_passwordChange.Show(passwordExists);
+ m_passwordRemove.Show(passwordExists);
+
+ m_toxAddress.SetMaxLength(TOX_ADDRESS_SIZE * 2);
+ m_nickname.SetMaxLength(TOX_MAX_NAME_LENGTH);
+ m_group.SetMaxLength(64);
m_maxConnectRetriesSpin.SetRange(255, 1);
m_maxConnectRetriesSpin.SetPosition(m_proto->getByte("MaxConnectRetries", TOX_MAX_CONNECT_RETRIES));
@@ -54,6 +73,31 @@ void CToxOptionsMain::OnInitDialog()
m_maxReconnectRetriesSpin.SetPosition(m_proto->getByte("MaxReconnectRetries", TOX_MAX_RECONNECT_RETRIES));
}
+void CToxOptionsMain::PasswordCreate_OnClick(CCtrlButton*)
+{
+ m_proto->OnCreatePassword(0, 0);
+}
+
+void CToxOptionsMain::PasswordChange_OnClick(CCtrlButton*)
+{
+ m_proto->OnChangePassword(0, 0);
+}
+
+void CToxOptionsMain::PasswordRemove_OnClick(CCtrlButton*)
+{
+ m_proto->OnRemovePassword(0, 0);
+ pass_ptrW password(m_proto->getWStringA(TOX_SETTINGS_PASSWORD));
+ bool passwordExists = mir_wstrlen(password) > 0;
+ m_passwordCreate.Show(!passwordExists);
+ m_passwordChange.Show(passwordExists);
+ m_passwordRemove.Show(passwordExists);
+}
+
+void CToxOptionsMain::EnableUdp_OnClick(CCtrlBase*)
+{
+ m_enableUdpHolePunching.Enable(m_enableUdp.GetState());
+}
+
void CToxOptionsMain::ToxAddressCopy_OnClick(CCtrlButton*)
{
char *toxAddress = m_toxAddress.GetTextA();
@@ -94,7 +138,6 @@ void CToxOptionsMain::ProfileCreate_OnClick(CCtrlButton*)
m_toxAddress.SetTextA(ptrA(m_proto->getStringA(TOX_SETTINGS_ID)));
m_nickname.SetText(ptrW(m_proto->getWStringA("Nick")));
- m_password.SetText(ptrW(m_proto->getWStringA("Password")));
ShowWindow(m_profileCreate.GetHwnd(), FALSE);
ShowWindow(m_profileImport.GetHwnd(), FALSE);
@@ -189,8 +232,8 @@ void CToxOptionsMain::ProfileExport_OnClick(CCtrlButton*)
void CToxOptionsMain::OnApply()
{
ptrW group(m_group.GetText());
- if (mir_wstrcmp(group, m_proto->wszGroup)) {
- m_proto->wszGroup = mir_wstrdup(group);
+ if (mir_wstrcmp(group, m_proto->m_defaultGroup)) {
+ m_proto->m_defaultGroup = mir_wstrdup(group);
Clist_GroupCreate(0, group);
}
@@ -198,111 +241,9 @@ void CToxOptionsMain::OnApply()
CallProtoService(m_proto->m_szModuleName, PS_SETMYNICKNAME, SMNN_UNICODE, (LPARAM)ptrW(m_nickname.GetText()));
// todo: add checkbox
- m_proto->setWString("Password", pass_ptrT(m_password.GetText()));
-
- m_proto->SaveToxProfile(m_proto->toxThread->Tox());
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////////
-
-CToxOptionsMultimedia::CToxOptionsMultimedia(CToxProto *proto)
- : CToxDlgBase(proto, IDD_OPTIONS_MULTIMEDIA, false),
- m_audioInput(this, IDC_AUDIOINPUT),
- m_audioOutput(this, IDC_AUDIOOUTPUT)
-{}
-
-void CToxOptionsMultimedia::EnumDevices(CCtrlCombo &combo, IMMDeviceEnumerator *pEnumerator, EDataFlow dataFlow, const char* setting)
-{
- LPWSTR pwszDefID = nullptr;
- ptrW wszDefID(m_proto->getWStringA(setting));
- if (wszDefID != NULL) {
- size_t len = mir_wstrlen(wszDefID) + 1;
- pwszDefID = (LPWSTR)CoTaskMemAlloc(len * 2);
- mir_wstrncpy(pwszDefID, wszDefID, len);
- }
- else {
- CComPtr<IMMDevice> pDevice = nullptr;
- if (FAILED(pEnumerator->GetDefaultAudioEndpoint(dataFlow, eConsole, &pDevice))) return;
- if (FAILED(pDevice->GetId(&pwszDefID))) return;
- }
-
- CComPtr<IMMDeviceCollection> pDevices = nullptr;
- EXIT_ON_ERROR(pEnumerator->EnumAudioEndpoints(dataFlow, DEVICE_STATE_ACTIVE, &pDevices));
-
- UINT count;
- EXIT_ON_ERROR(pDevices->GetCount(&count));
-
- for (UINT i = 0; i < count; i++) {
- CComPtr<IMMDevice> pDevice = nullptr;
- EXIT_ON_ERROR(pDevices->Item(i, &pDevice));
-
- CComPtr<IPropertyStore> pProperties = nullptr;
- EXIT_ON_ERROR(pDevice->OpenPropertyStore(STGM_READ, &pProperties));
-
- PROPVARIANT varName;
- PropVariantInit(&varName);
- EXIT_ON_ERROR(pProperties->GetValue(PKEY_Device_FriendlyName, &varName));
-
- LPWSTR pwszID = nullptr;
- EXIT_ON_ERROR(pDevice->GetId(&pwszID));
- combo.InsertString(varName.pwszVal, i, (LPARAM)mir_wstrdup(pwszID));
- if (mir_wstrcmpi(pwszID, pwszDefID) == 0)
- combo.SetCurSel(i);
- CoTaskMemFree(pwszID);
-
- PropVariantClear(&varName);
- }
-
-Exit:
- CoTaskMemFree(pwszDefID);
-}
-
-void CToxOptionsMultimedia::OnInitDialog()
-{
- CToxDlgBase::OnInitDialog();
-
- CComPtr<IMMDeviceEnumerator> pEnumerator = nullptr;
- if (FAILED(CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator)))
- return;
-
- EnumDevices(m_audioInput, pEnumerator, eCapture, "AudioInputDeviceID");
- EnumDevices(m_audioOutput, pEnumerator, eRender, "AudioOutputDeviceID");
-}
-
-void CToxOptionsMultimedia::OnApply()
-{
- int i = m_audioInput.GetCurSel();
- if (i == -1)
- m_proto->delSetting("AudioInputDeviceID");
- else {
- wchar_t* data = (wchar_t*)m_audioInput.GetItemData(i);
- m_proto->setWString("AudioInputDeviceID", data);
- }
-
- i = m_audioOutput.GetCurSel();
- if (i == -1)
- m_proto->delSetting("AudioOutputDeviceID");
- else {
- wchar_t* data = (wchar_t*)m_audioOutput.GetItemData(i);
- m_proto->setWString("AudioOutputDeviceID", data);
- }
-}
-
-void CToxOptionsMultimedia::OnDestroy()
-{
- int count = m_audioInput.GetCount();
- for (int i = 0; i < count; i++) {
- wchar_t* data = (wchar_t*)m_audioInput.GetItemData(i);
- mir_free(data);
-
- }
-
- count = m_audioOutput.GetCount();
- for (int i = 0; i < count; i++) {
- wchar_t* data = (wchar_t*)m_audioOutput.GetItemData(i);
- mir_free(data);
+ //m_proto->setWString("Password", pass_ptrW(m_password.GetText()));
+ m_proto->SaveToxProfile(m_proto->m_toxThread->Tox());
}
}