summaryrefslogtreecommitdiff
path: root/protocols/Tox/src/tox_options.cpp
blob: f6e41bff315ebd6b0c9d6f45af05ad2c0cec0822 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "common.h"

INT_PTR CALLBACK CToxProto::MainOptionsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	CToxProto *proto = (CToxProto*)GetWindowLongPtr(hwnd, GWLP_USERDATA);

	switch (uMsg)
	{
	case WM_INITDIALOG:
		TranslateDialogDefault(hwnd);
		{
			proto = (CToxProto*)lParam;
			SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam);

			ptrA username(proto->getStringA("Username"));
			SetDlgItemTextA(hwnd, IDC_USERNAME, username);

			ptrA dataPath(proto->getStringA("DataPath"));
			if (!dataPath)
			{
				char defaultPath[MAX_PATH];
				mir_snprintf(defaultPath, MAX_PATH, "%s\\Tox\\%s.dat", VARS("%miranda_userdata%"), _T2A(proto->m_tszUserName));
				dataPath = mir_strdup(defaultPath);
			}
			SetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath);

			ptrW groupName(proto->getWStringA(NULL, "DefaultGroup"));
			SetDlgItemText(hwnd, IDC_GROUP, groupName);
			SendDlgItemMessage(hwnd, IDC_GROUP, EM_LIMITTEXT, 64, 0);

			/*if (proto->IsOnline())
			{
				EnableWindow(GetDlgItem(hwnd, IDC_USERNAME), FALSE);
				EnableWindow(GetDlgItem(hwnd, IDC_DATAPATH), FALSE);
			}*/
		}
		return TRUE;

	case WM_COMMAND:
	{
		switch (LOWORD(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));
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
			}
			break;

		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));
				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);
				}
			}
			break;

		case IDC_GROUP:
			{
				if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
					return 0;
				SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
			}
			break;
		}
	}
		break;

	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);

				char dataPath[128];
				GetDlgItemTextA(hwnd, IDC_DATAPATH, dataPath, SIZEOF(dataPath));
				proto->setString("DataPath", dataPath);
			}

			wchar_t groupName[128];
			GetDlgItemText(hwnd, IDC_GROUP, groupName, SIZEOF(groupName));
			if (lstrlen(groupName) > 0)
			{
				proto->setWString(NULL, "DefaultGroup", groupName);
				Clist_CreateGroup(0, groupName);
			}
			else
				proto->delSetting(NULL, "DefaultGroup");

			return TRUE;
		}
		break;
	}

	return FALSE;
}