summaryrefslogtreecommitdiff
path: root/protocols/MRA/src/Mra_options.cpp
blob: b833a7cd22705b74002505132803242d622c245a (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include "stdafx.h"

INT_PTR CALLBACK DlgProcOptsAccount(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	CMraProto *ppro = (CMraProto*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA);
	CMStringW szBuff;

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hWndDlg);
		SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
		ppro = (CMraProto*)lParam;

		if (ppro->mraGetStringW(NULL, "e-mail", szBuff))
			SetDlgItemText(hWndDlg, IDC_LOGIN, szBuff.c_str());

		SetDlgItemText(hWndDlg, IDC_PASSWORD, _T(""));
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_NEW_ACCOUNT_LINK:
			CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)MRA_REGISTER_URL);
			return TRUE;

		case IDC_LOOKUPLINK:
			CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)MRA_FORGOT_PASSWORD_URL);
			return TRUE;
		}
		if ((LOWORD(wParam) == IDC_LOGIN || LOWORD(wParam) == IDC_PASSWORD) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))
			return 0;

		SendMessage(GetParent(hWndDlg), PSM_CHANGED, 0, 0);
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			TCHAR szBuff[MAX_EMAIL_LEN];
			GetDlgItemText(hWndDlg, IDC_LOGIN, szBuff, _countof(szBuff));
			ppro->setTString(NULL, "e-mail", szBuff);

			if (GetDlgItemText(hWndDlg, IDC_PASSWORD, szBuff, _countof(szBuff))) {
				ppro->setTString("Password", szBuff);
				SecureZeroMemory(szBuff, sizeof(szBuff));
			}
			return TRUE;
		}
		break;
	}
	return FALSE;
}

INT_PTR CALLBACK DlgProcAccount(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	CMraProto *ppro = (CMraProto*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA);
	CMStringW szBuff;

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hWndDlg);
		SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
		ppro = (CMraProto*)lParam;

		if (ppro->mraGetStringW(NULL, "e-mail", szBuff))
			SetDlgItemText(hWndDlg, IDC_LOGIN, szBuff.c_str());

		SetDlgItemText(hWndDlg, IDC_PASSWORD, _T(""));
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_NEW_ACCOUNT_LINK:
			CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW | OUF_TCHAR, (LPARAM)MRA_REGISTER_URL);
			return TRUE;
		}
		if (HIWORD(wParam) == EN_CHANGE && (HWND)lParam == GetFocus()) {
			switch (LOWORD(wParam)) {
			case IDC_LOGIN:
			case IDC_PASSWORD:
				SendMessage(GetParent(hWndDlg), PSM_CHANGED, 0, 0);
			}
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			TCHAR szBuff[MAX_EMAIL_LEN];
			GetDlgItemText(hWndDlg, IDC_LOGIN, szBuff, _countof(szBuff));
			ppro->mraSetStringW(NULL, "e-mail", szBuff);

			if (GetDlgItemText(hWndDlg, IDC_PASSWORD, szBuff, _countof(szBuff))) {
				ppro->setTString("Password", szBuff);
				SecureZeroMemory(szBuff, sizeof(szBuff));
			}
			return TRUE;
		}
		break;
	}
	return FALSE;
}

INT_PTR CALLBACK DlgProcOptsConnections(HWND hWndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	CMraProto *ppro = (CMraProto*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA);
	CMStringW szBuff;

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hWndDlg);
		SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
		ppro = (CMraProto*)lParam;

		if (ppro->mraGetStringW(NULL, "Server", szBuff))
			SetDlgItemText(hWndDlg, IDC_SERVER, szBuff.c_str());
		else
			SetDlgItemTextA(hWndDlg, IDC_SERVER, MRA_DEFAULT_SERVER);

		SetDlgItemInt(hWndDlg, IDC_SERVERPORT, ppro->getWord("ServerPort", MRA_DEFAULT_SERVER_PORT), FALSE);
		// if set SSL proxy, setting will ignored

		//CheckDlgButton(hWndDlg, IDC_KEEPALIVE, getByte("keepalive", 0) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hWndDlg, IDC_AUTO_ADD_CONTACTS_TO_SERVER, ppro->getByte("AutoAddContactsToServer", MRA_DEFAULT_AUTO_ADD_CONTACTS_TO_SERVER)) ? BST_CHECKED : BST_UNCHECKED;
		CheckDlgButton(hWndDlg, IDC_AUTO_AUTH_REQ_ON_LOGON, ppro->getByte("AutoAuthRequestOnLogon", MRA_DEFAULT_AUTO_AUTH_REQ_ON_LOGON) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hWndDlg, IDC_AUTO_AUTH_GRAND_IN_CLIST, ppro->getByte("AutoAuthGrandUsersInCList", MRA_DEFAULT_AUTO_AUTH_GRAND_IN_CLIST) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hWndDlg, IDC_AUTO_AUTH_GRAND_NEW_USERS, ppro->getByte("AutoAuthGrandNewUsers", MRA_DEFAULT_AUTO_AUTH_GRAND_NEW_USERS) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hWndDlg, IDC_AUTO_AUTH_ON_WEB_SVCS, ppro->getByte("AutoAuthOnWebServices", MRA_DEFAULT_AUTO_AUTH_ON_WEB_SVCS) ? BST_CHECKED : BST_UNCHECKED);

		CheckDlgButton(hWndDlg, IDC_SLOWSEND, ppro->getByte("SlowSend", MRA_DEFAULT_SLOW_SEND) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hWndDlg, IDC_INCREMENTAL_NEW_MAIL_NOTIFY, ppro->getByte("IncrementalNewMailNotify", MRA_DEFAULT_INC_NEW_MAIL_NOTIFY) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY, ppro->getByte("TrayIconNewMailNotify", MRA_DEFAULT_TRAYICON_NEW_MAIL_NOTIFY) ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY_CLICK_TO_INBOX, ppro->getByte("TrayIconNewMailClkToInbox", MRA_DEFAULT_TRAYICON_NEW_MAIL_CLK_TO_INBOX) ? BST_CHECKED : BST_UNCHECKED);
		EnableWindow(GetDlgItem(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY_CLICK_TO_INBOX), ppro->getByte("TrayIconNewMailNotify", MRA_DEFAULT_TRAYICON_NEW_MAIL_NOTIFY));

		CheckDlgButton(hWndDlg, IDC_RTF_RECEIVE_ENABLE, ppro->getByte("RTFReceiveEnable", MRA_DEFAULT_RTF_RECEIVE_ENABLE) ? BST_CHECKED : BST_UNCHECKED);

		CheckDlgButton(hWndDlg, IDC_RTF_SEND_ENABLE, ppro->getByte("RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE) ? BST_CHECKED : BST_UNCHECKED);
		EnableWindow(GetDlgItem(hWndDlg, IDC_RTF_SEND_SMART), ppro->getByte("RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE));
		EnableWindow(GetDlgItem(hWndDlg, IDC_BUTTON_FONT), ppro->getByte("RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE));
		EnableWindow(GetDlgItem(hWndDlg, IDC_RTF_BGCOLOUR), ppro->getByte("RTFSendEnable", MRA_DEFAULT_RTF_SEND_ENABLE));
		SendDlgItemMessage(hWndDlg, IDC_RTF_BGCOLOUR, CPM_SETCOLOUR, 0, ppro->getDword("RTFBackgroundColour", MRA_DEFAULT_RTF_BACKGROUND_COLOUR));
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_BUTTON_DEFAULT:
			SetDlgItemTextA(hWndDlg, IDC_SERVER, MRA_DEFAULT_SERVER);
			SetDlgItemInt(hWndDlg, IDC_SERVERPORT, MRA_DEFAULT_SERVER_PORT, FALSE);
			break;
		case IDC_TRAYICON_NEW_MAIL_NOTIFY:
			EnableWindow(GetDlgItem(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY_CLICK_TO_INBOX), IsDlgButtonChecked(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY));
			break;
		case IDC_RTF_SEND_ENABLE:
			EnableWindow(GetDlgItem(hWndDlg, IDC_RTF_SEND_SMART), IsDlgButtonChecked(hWndDlg, IDC_RTF_SEND_ENABLE));
			EnableWindow(GetDlgItem(hWndDlg, IDC_BUTTON_FONT), IsDlgButtonChecked(hWndDlg, IDC_RTF_SEND_ENABLE));
			EnableWindow(GetDlgItem(hWndDlg, IDC_RTF_BGCOLOUR), IsDlgButtonChecked(hWndDlg, IDC_RTF_SEND_ENABLE));
			break;
		case IDC_BUTTON_FONT:
			LOGFONT lf = { 0 };
			CHOOSEFONT cf = { 0 };

			cf.lStructSize = sizeof(cf);
			cf.lpLogFont = &lf;
			cf.rgbColors = ppro->getDword("RTFFontColour", MRA_DEFAULT_RTF_FONT_COLOUR);
			cf.Flags = (CF_SCREENFONTS | CF_EFFECTS | CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT);
			if (ppro->mraGetContactSettingBlob(NULL, "RTFFont", &lf, sizeof(LOGFONT), NULL) == FALSE) {
				HDC hDC = GetDC(NULL);// kegl
				lf.lfCharSet = MRA_DEFAULT_RTF_FONT_CHARSET;
				lf.lfHeight = -MulDiv(MRA_DEFAULT_RTF_FONT_SIZE, GetDeviceCaps(hDC, LOGPIXELSY), 72);
				mir_tstrncpy(lf.lfFaceName, MRA_DEFAULT_RTF_FONT_NAME, LF_FACESIZE);
				ReleaseDC(NULL, hDC);
			}

			if (ChooseFont(&cf)) {
				ppro->mraWriteContactSettingBlob(NULL, "RTFFont", &lf, sizeof(LOGFONT));
				ppro->setDword("RTFFontColour", cf.rgbColors);
			}
			break;
		}

		if ((LOWORD(wParam) == IDC_SERVER || LOWORD(wParam) == IDC_SERVERPORT) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return FALSE;
		SendMessage(GetParent(hWndDlg), PSM_CHANGED, 0, 0);
		break;
	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->code) {
		case PSN_APPLY:
			TCHAR szBuff[MAX_PATH];
			GetDlgItemText(hWndDlg, IDC_SERVER, szBuff, _countof(szBuff));
			ppro->mraSetStringW(NULL, "Server", szBuff);
			ppro->setWord("ServerPort", (WORD)GetDlgItemInt(hWndDlg, IDC_SERVERPORT, NULL, FALSE));
			ppro->setByte("AutoAddContactsToServer", IsDlgButtonChecked(hWndDlg, IDC_AUTO_ADD_CONTACTS_TO_SERVER));
			ppro->setByte("AutoAuthRequestOnLogon", IsDlgButtonChecked(hWndDlg, IDC_AUTO_AUTH_REQ_ON_LOGON));
			ppro->setByte("AutoAuthGrandUsersInCList", IsDlgButtonChecked(hWndDlg, IDC_AUTO_AUTH_GRAND_IN_CLIST));
			ppro->setByte("AutoAuthGrandNewUsers", IsDlgButtonChecked(hWndDlg, IDC_AUTO_AUTH_GRAND_NEW_USERS));
			ppro->setByte("AutoAuthOnWebServices", IsDlgButtonChecked(hWndDlg, IDC_AUTO_AUTH_ON_WEB_SVCS));

			ppro->setByte("SlowSend", IsDlgButtonChecked(hWndDlg, IDC_SLOWSEND));
			ppro->setByte("IncrementalNewMailNotify", IsDlgButtonChecked(hWndDlg, IDC_INCREMENTAL_NEW_MAIL_NOTIFY));
			ppro->setByte("TrayIconNewMailNotify", IsDlgButtonChecked(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY));
			ppro->setByte("TrayIconNewMailClkToInbox", IsDlgButtonChecked(hWndDlg, IDC_TRAYICON_NEW_MAIL_NOTIFY_CLICK_TO_INBOX));

			ppro->setByte("RTFReceiveEnable", IsDlgButtonChecked(hWndDlg, IDC_RTF_RECEIVE_ENABLE));
			ppro->setByte("RTFSendEnable", IsDlgButtonChecked(hWndDlg, IDC_RTF_SEND_ENABLE));
			ppro->setDword("RTFBackgroundColour", SendDlgItemMessage(hWndDlg, IDC_RTF_BGCOLOUR, CPM_GETCOLOUR, 0, 0));
			return TRUE;
		}
		break;
	}
	return FALSE;
}

int CMraProto::OnOptionsInit(WPARAM wParam, LPARAM lParam)
{
	OPTIONSDIALOGPAGE odp = { 0 };
	odp.dwInitParam = (LPARAM)this;
	odp.hInstance = g_hInstance;
	odp.ptszTitle = m_tszUserName;
	odp.ptszGroup = LPGENT("Network");
	odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;

	odp.ptszTab = LPGENT("Account");
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_ACCOUNT);
	odp.pfnDlgProc = DlgProcOptsAccount;
	Options_AddPage(wParam, &odp);

	odp.ptszTab = LPGENT("Connections");
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_CONNECTIONS);
	odp.pfnDlgProc = DlgProcOptsConnections;
	Options_AddPage(wParam, &odp);

	odp.ptszTab = LPGENT("Files");
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_FILES);
	odp.pfnDlgProc = MraFilesQueueDlgProcOpts;
	Options_AddPage(wParam, &odp);

	odp.ptszTab = LPGENT("Avatars");
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_AVATRS);
	odp.pfnDlgProc = MraAvatarsQueueDlgProcOpts;
	Options_AddPage(wParam, &odp);

	OnPopupOptInit(wParam, lParam);
	return 0;
}