diff options
author | Alexander Lantsev <aunsane@gmail.com> | 2014-08-18 20:17:45 +0000 |
---|---|---|
committer | Alexander Lantsev <aunsane@gmail.com> | 2014-08-18 20:17:45 +0000 |
commit | 87204c540590feeba783f40319d4a503b9f325f5 (patch) | |
tree | 60f3cee948264d9edd06958a15bb2e0b333deda1 /protocols/Tox/src/tox_options.cpp | |
parent | 108d975c5775d83357c735541ee5e711c27f092a (diff) |
Tox:
- added profile manager on first run
- reworked options
git-svn-id: http://svn.miranda-ng.org/main/trunk@10231 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/Tox/src/tox_options.cpp')
-rw-r--r-- | protocols/Tox/src/tox_options.cpp | 159 |
1 files changed, 95 insertions, 64 deletions
diff --git a/protocols/Tox/src/tox_options.cpp b/protocols/Tox/src/tox_options.cpp index ccf6ae571e..61df8854e9 100644 --- a/protocols/Tox/src/tox_options.cpp +++ b/protocols/Tox/src/tox_options.cpp @@ -12,18 +12,15 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, proto = (CToxProto*)lParam;
SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
- ptrA username(proto->getStringA("Username"));
- SetDlgItemTextA(hwnd, IDC_USERNAME, username);
+ ptrW nick(proto->getTStringA("Nick"));
+ SetDlgItemText(hwnd, IDC_NAME, nick);
- std::string toxProfilePath = proto->GetToxProfilePath();
- SetDlgItemTextA(hwnd, IDC_DATAPATH, toxProfilePath.c_str());
-
- ptrW groupName(proto->getTStringA(TOX_SETTINGS_GROUP));
- SetDlgItemText(hwnd, IDC_GROUP, groupName);
+ ptrW group(proto->getTStringA(TOX_SETTINGS_GROUP));
+ SetDlgItemText(hwnd, IDC_GROUP, group);
SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, 64, 0);
CheckDlgButton(hwnd, IDC_DISABLE_UDP, proto->getByte("DisableUDP", 0));
- CheckDlgButton(hwnd, IDC_DISABLE_IPV6, proto->getByte("DisableIPv6", 0));
+ CheckDlgButton(hwnd, IDC_DISABLE_IPV6, proto->getByte("DisableIPv6", 1));
}
return TRUE;
@@ -31,57 +28,18 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, {
switch (LOWORD(wParam))
{
- case IDC_USERNAME:
- if ((HWND)lParam == GetFocus())
- {
- if (HIWORD(wParam) != EN_CHANGE) return 0;
- char username[128];
- GetDlgItemTextA(hwnd, IDC_USERNAME, username, SIZEOF(username));
- SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
- }
- break;
-
- case IDC_DATAPATH:
+ case IDC_NAME:
if ((HWND)lParam == GetFocus())
{
if (HIWORD(wParam) != EN_CHANGE) return 0;
- char dataPath[128];
- GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
}
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])
- {
- 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);
- }
break;
case IDC_DISABLE_UDP:
@@ -98,34 +56,107 @@ INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, case WM_NOTIFY:
if (reinterpret_cast<NMHDR*>(lParam)->code == PSN_APPLY)
{
- 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));
+ TCHAR nick[TOX_MAX_NAME_LENGTH];
+ GetDlgItemText(hwnd, IDC_NAME, nick, TOX_MAX_NAME_LENGTH);
+ proto->setTString("Nick", nick);
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));
- if (lstrlen(groupName) > 0)
+ TCHAR group[64];
+ GetDlgItemText(hwnd, IDC_GROUP, group, SIZEOF(group));
+ if (_tcslen(group) > 0)
{
- proto->setWString(NULL, TOX_SETTINGS_GROUP, groupName);
- Clist_CreateGroup(0, groupName);
+ proto->setTString(NULL, TOX_SETTINGS_GROUP, group);
+ Clist_CreateGroup(0, group);
}
else
+ {
proto->delSetting(NULL, TOX_SETTINGS_GROUP);
+ }
+
+ return TRUE;
+ }
+ break;
+ }
+
+ return FALSE;
+}
+
+INT_PTR CALLBACK CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ TCHAR *profilePath = (TCHAR*)GetWindowLongPtr(hwnd, DWL_USER);
- char dataPath[128];
- GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
- if (proto->GetToxProfilePath().compare(dataPath) != 0)
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ TranslateDialogDefault(hwnd);
+ {
+ proto = (CToxProto*)lParam;
+ SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);
+
+ profilePath = (TCHAR*)mir_calloc(sizeof(TCHAR) * MAX_PATH);
+ SetWindowLongPtr(hwnd, DWL_USER, (LONG_PTR)profilePath);
+
+ CheckDlgButton(hwnd, IDC_CREATE_NEW, TRUE);
+ }
+ return TRUE;
+
+ case WM_CLOSE:
+ EndDialog(hwnd, 0);
+ break;
+
+ case WM_DESTROY:
+ mir_free(profilePath);
+ break;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam))
+ {
+ case IDC_USE_EXISTING:
+ EnableWindow(GetDlgItem(hwnd, IDC_PROFILE_PATH), IsDlgButtonChecked(hwnd, IDC_USE_EXISTING));
+ EnableWindow(GetDlgItem(hwnd, IDC_BROWSE_PROFILE), IsDlgButtonChecked(hwnd, IDC_USE_EXISTING));
+ break;
+
+ case IDC_BROWSE_PROFILE:
{
- proto->UninitToxCore();
- proto->setString("DataPath", dataPath);
- proto->InitToxCore();
+ TCHAR filter[MAX_PATH] = { 0 };
+ mir_sntprintf(filter, MAX_PATH, _T("%s\0*.*"), TranslateT("All files (*.*)"));
+
+ OPENFILENAME ofn = { sizeof(ofn) };
+ ofn.hwndOwner = hwnd;
+ ofn.lpstrFilter = filter;
+ ofn.nFilterIndex = 1;
+ ofn.lpstrFile = profilePath;
+ ofn.lpstrTitle = TranslateT("Select tox profile");
+ ofn.nMaxFile = MAX_PATH;
+ ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER;
+
+ if (GetOpenFileName(&ofn) && profilePath)
+ {
+ SetDlgItemText(hwnd, IDC_PROFILE_PATH, profilePath);
+ }
}
+ break;
- return TRUE;
+ case IDOK:
+ {
+ if (IsDlgButtonChecked(hwnd, IDC_USE_EXISTING))
+ {
+ if (profilePath != NULL)
+ {
+ std::tstring toxProfilePath = proto->GetToxProfilePath();
+ CopyFile(profilePath, toxProfilePath.c_str(), FALSE);
+ }
+ }
+ EndDialog(hwnd, 1);
+ }
+ break;
+
+ case IDCANCEL:
+ EndDialog(hwnd, 0);
+ break;
}
break;
}
|