summaryrefslogtreecommitdiff
path: root/protocols/MRA/src/MraAdvancedSearch.cpp
blob: 54b764b1b0edef6adf4618c0d43d1aeec15f422c (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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
#include "stdafx.h"
#include "proto.h"
#include "MraPlaces.h"



struct FieldNames
{
	BYTE dwCode;
	LPWSTR lpszText;
};

static const FieldNames GenderField[] =
{
	{ 1, LPGENW("Male")         },
	{ 2, LPGENW("Female")       },
	{ 0, nullptr                   }
};

static const FieldNames MonthField[] =
{
	{ 1,  LPGENW("January")     },
	{ 2,  LPGENW("February")    },
	{ 3,  LPGENW("March")       },
	{ 4,  LPGENW("April")       },
	{ 5,  LPGENW("May")         },
	{ 6,  LPGENW("June")        },
	{ 7,  LPGENW("July")        },
	{ 8,  LPGENW("August")      },
	{ 9,  LPGENW("September")   },
	{ 10, LPGENW("October")     },
	{ 11, LPGENW("November")    },
	{ 12, LPGENW("December")    },
	{ 0,  nullptr                  }
};

static const FieldNames ZodiakField[] =
{
	{ 1,  LPGENW("Aries")       },
	{ 2,  LPGENW("Taurus")      },
	{ 3,  LPGENW("Gemini")      },
	{ 4,  LPGENW("Cancer")      },
	{ 5,  LPGENW("Leo")         },
	{ 6,  LPGENW("Virgo")       },
	{ 7,  LPGENW("Libra")       },
	{ 8,  LPGENW("Scorpio")     },
	{ 9,  LPGENW("Sagittarius") },
	{ 10, LPGENW("Capricorn")   },
	{ 11, LPGENW("Aquarius")    },
	{ 12, LPGENW("Pisces")      },
	{ 0,  nullptr                  }
};

void ResetComboBox(HWND hWndCombo)
{
	SendMessage(hWndCombo, CB_RESETCONTENT, 0, 0);
	DWORD dwItem = SendMessage(hWndCombo, CB_ADDSTRING, 0, (LPARAM)L"");
	SendMessage(hWndCombo, CB_SETITEMDATA, dwItem, 0);
	SendMessage(hWndCombo, CB_SETCURSEL, dwItem, 0);
}


void InitComboBox(HWND hWndCombo, FieldNames *lpNames)
{
	ResetComboBox(hWndCombo);

	for (size_t i = 0; lpNames[i].lpszText; i++) {
		DWORD dwItem = SendMessage(hWndCombo, CB_ADDSTRING, 0, (LPARAM)TranslateW(lpNames[i].lpszText));
		SendMessage(hWndCombo, CB_SETITEMDATA, dwItem, lpNames[i].dwCode);
	}
}


void InitComboBoxNumders(HWND hWndCombo, DWORD dwStart, DWORD dwEnd)
{
	ResetComboBox(hWndCombo);

	for (DWORD i = dwStart; i <= dwEnd; i++) {
		wchar_t szBuff[MAX_PATH];
		mir_snwprintf(szBuff, L"%lu", i);
		DWORD dwItem = SendMessage(hWndCombo, CB_ADDSTRING, 0, (LPARAM)szBuff);
		SendMessage(hWndCombo, CB_SETITEMDATA, dwItem, i);
	}
}


INT_PTR CALLBACK AdvancedSearchDlgProc(HWND hWndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	CMraProto *ppro = (CMraProto*)GetWindowLongPtr(hWndDlg, GWLP_USERDATA);

	switch (message) {
	case WM_INITDIALOG:
		SetWindowLongPtr(hWndDlg, GWLP_USERDATA, lParam);
		{
			DWORD dwItem;
			WCHAR wszBuff[MAX_PATH];
			SYSTEMTIME stTime;
			GetLocalTime(&stTime);

			ppro = (CMraProto*)lParam;

			HWND hWndCombo = GetDlgItem(hWndDlg, IDC_EMAIL_DOMAIN);
			ResetComboBox(hWndCombo);
			for (size_t i = 0; lpcszMailRuDomains[i]; i++) {
				MultiByteToWideChar(MRA_CODE_PAGE, 0, lpcszMailRuDomains[i], -1, wszBuff, _countof(wszBuff));
				SendMessage(hWndCombo, CB_ADDSTRING, 0, (LPARAM)wszBuff);
			}

			InitComboBox(GetDlgItem(hWndDlg, IDC_GENDER), (FieldNames*)GenderField);
			InitComboBoxNumders(GetDlgItem(hWndDlg, IDC_AGERANGE_FROM), 1, 100);
			InitComboBoxNumders(GetDlgItem(hWndDlg, IDC_AGERANGE_TO), 1, 100);
			InitComboBoxNumders(GetDlgItem(hWndDlg, IDC_BIRTHDAY_DAY), 1, 31);
			InitComboBox(GetDlgItem(hWndDlg, IDC_BIRTHDAY_MONTH), (FieldNames*)MonthField);
			InitComboBoxNumders(GetDlgItem(hWndDlg, IDC_BIRTHDAY_YEAR), 1900, (DWORD)stTime.wYear);
			InitComboBox(GetDlgItem(hWndDlg, IDC_ZODIAK), (FieldNames*)ZodiakField);

			hWndCombo = GetDlgItem(hWndDlg, IDC_COUNTRY);
			ResetComboBox(hWndCombo);
			for (size_t i = 0; mrapPlaces[i].lpszData; i++) {
				if (mrapPlaces[i].dwCityID == 0 && mrapPlaces[i].dwPlaceID == 0) {
					dwItem = SendMessage(hWndCombo, CB_ADDSTRING, 0, (LPARAM)mrapPlaces[i].lpszData);
					SendMessage(hWndCombo, CB_SETITEMDATA, dwItem, mrapPlaces[i].dwCountryID);
				}
			}

			ResetComboBox(GetDlgItem(hWndDlg, IDC_CITY));

			if (ppro->getByte("AdvancedSearchRemember", MRA_DEFAULT_SEARCH_REMEMBER)) {
				SendDlgItemMessage(hWndDlg, IDC_GENDER, CB_SETCURSEL, ppro->getWord("AdvancedSearchGender", 0), 0);
				SendDlgItemMessage(hWndDlg, IDC_AGERANGE_FROM, CB_SETCURSEL, ppro->getWord("AdvancedSearchAgeFrom", 0), 0);
				SendDlgItemMessage(hWndDlg, IDC_AGERANGE_TO, CB_SETCURSEL, ppro->getWord("AdvancedSearchAgeTo", 0), 0);
				SendDlgItemMessage(hWndDlg, IDC_BIRTHDAY_MONTH, CB_SETCURSEL, ppro->getWord("AdvancedSearchBirthDayMonth", 0), 0);
				SendDlgItemMessage(hWndDlg, IDC_BIRTHDAY_DAY, CB_SETCURSEL, ppro->getWord("AdvancedSearchBirthDayDay", 0), 0);

				SendDlgItemMessage(hWndDlg, IDC_ZODIAK, CB_SETCURSEL, ppro->getWord("AdvancedSearchZodiakID", 0), 0);


				SendDlgItemMessage(hWndDlg, IDC_COUNTRY, CB_SETCURSEL, ppro->getWord("AdvancedSearchCountryID", 0), 0);
				SendMessageW(hWndDlg, WM_COMMAND, (WPARAM)MAKELONG(IDC_COUNTRY, CBN_SELCHANGE), (LPARAM)GetDlgItem(hWndDlg, IDC_COUNTRY));

				SendDlgItemMessage(hWndDlg, IDC_STATE, CB_SETCURSEL, ppro->getWord("AdvancedSearchStateID", 0), 0);
				SendMessage(hWndDlg, WM_COMMAND, (WPARAM)MAKELONG(IDC_STATE, CBN_SELCHANGE), (LPARAM)GetDlgItem(hWndDlg, IDC_STATE));

				SendDlgItemMessage(hWndDlg, IDC_CITY, CB_SETCURSEL, ppro->getWord("AdvancedSearchCityID", 0), 0);


				CheckDlgButton(hWndDlg, IDC_ONLINEONLY, ppro->getByte("AdvancedSearchOnlineOnly", FALSE) ? BST_CHECKED : BST_UNCHECKED);
				CheckDlgButton(hWndDlg, IDC_CHK_REMEMBER, BST_CHECKED);
			}
			TranslateDialogDefault(hWndDlg);
		}
		return TRUE;

	case WM_DESTROY:
		ppro->setWord("AdvancedSearchGender", SendDlgItemMessage(hWndDlg, IDC_GENDER, CB_GETCURSEL, 0, 0));
		ppro->setWord("AdvancedSearchAgeFrom", SendDlgItemMessage(hWndDlg, IDC_AGERANGE_FROM, CB_GETCURSEL, 0, 0));
		ppro->setWord("AdvancedSearchAgeTo", SendDlgItemMessage(hWndDlg, IDC_AGERANGE_TO, CB_GETCURSEL, 0, 0));
		ppro->setWord("AdvancedSearchBirthDayMonth", SendDlgItemMessage(hWndDlg, IDC_BIRTHDAY_MONTH, CB_GETCURSEL, 0, 0));
		ppro->setWord("AdvancedSearchBirthDayDay", SendDlgItemMessage(hWndDlg, IDC_BIRTHDAY_DAY, CB_GETCURSEL, 0, 0));

		ppro->setWord("AdvancedSearchZodiakID", SendDlgItemMessage(hWndDlg, IDC_ZODIAK, CB_GETCURSEL, 0, 0));

		ppro->setWord("AdvancedSearchCityID", SendDlgItemMessage(hWndDlg, IDC_CITY, CB_GETCURSEL, 0, 0));
		ppro->setWord("AdvancedSearchStateID", SendDlgItemMessage(hWndDlg, IDC_STATE, CB_GETCURSEL, 0, 0));
		ppro->setWord("AdvancedSearchCountryID", SendDlgItemMessage(hWndDlg, IDC_COUNTRY, CB_GETCURSEL, 0, 0));

		ppro->setByte("AdvancedSearchOnlineOnly", IsDlgButtonChecked(hWndDlg, IDC_ONLINEONLY));
		ppro->setByte("AdvancedSearchRemember", IsDlgButtonChecked(hWndDlg, IDC_CHK_REMEMBER));
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_AGERANGE_FROM:
		case IDC_AGERANGE_TO:
			if (HIWORD(wParam) == CBN_SELCHANGE) {
				if (LOWORD(wParam) == IDC_AGERANGE_FROM) {
					DWORD dwAgeFrom = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_AGERANGE_FROM);
					DWORD dwAgeTo = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_AGERANGE_TO);
					if (dwAgeFrom == 0) dwAgeFrom++;
					InitComboBoxNumders(GetDlgItem(hWndDlg, IDC_AGERANGE_TO), dwAgeFrom, 100);
					SendDlgItemMessage(hWndDlg, IDC_AGERANGE_TO, CB_SETCURSEL, ((dwAgeTo - dwAgeFrom) + 1), 0);
				}
				SendDlgItemMessage(hWndDlg, IDC_BIRTHDAY_YEAR, CB_SETCURSEL, 0, 0);
			}
			break;

		case IDC_BIRTHDAY_DAY:
		case IDC_BIRTHDAY_MONTH:
		case IDC_BIRTHDAY_YEAR:
			if (HIWORD(wParam) == CBN_SELCHANGE) {
				SYSTEMTIME stTime = { 0 };

				stTime.wYear = (WORD)GET_CURRENT_COMBO_DATA(hWndDlg, IDC_BIRTHDAY_YEAR);
				stTime.wMonth = (WORD)GET_CURRENT_COMBO_DATA(hWndDlg, IDC_BIRTHDAY_MONTH);
				stTime.wDay = (WORD)GET_CURRENT_COMBO_DATA(hWndDlg, IDC_BIRTHDAY_DAY);

				DWORD dwAge = GetYears(&stTime);
				SendDlgItemMessage(hWndDlg, IDC_AGERANGE_FROM, CB_SETCURSEL, dwAge, 0);
				SendDlgItemMessage(hWndDlg, IDC_AGERANGE_TO, CB_SETCURSEL, dwAge, 0);
				SendDlgItemMessage(hWndDlg, IDC_ZODIAK, CB_SETCURSEL, 0, 0);
			}
			break;

		case IDC_ZODIAK:
			if (HIWORD(wParam) == CBN_SELCHANGE) {
				SendDlgItemMessage(hWndDlg, IDC_BIRTHDAY_DAY, CB_SETCURSEL, 0, 0);
				SendDlgItemMessage(hWndDlg, IDC_BIRTHDAY_MONTH, CB_SETCURSEL, 0, 0);
				//SendDlgItemMessage(hWndDlg, IDC_BIRTHDAY_YEAR, CB_SETCURSEL, 0, 0);
			}
			break;

		case IDC_COUNTRY:
			if (HIWORD(wParam) == CBN_SELCHANGE) {
				DWORD dwCountryID = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_COUNTRY);
				HWND hWndCombo = GetDlgItem(hWndDlg, IDC_STATE);
				SendMessage(hWndCombo, CB_RESETCONTENT, 0, 0);
				ResetComboBox(GetDlgItem(hWndDlg, IDC_CITY));
				DWORD dwItem = SendMessage(hWndCombo, CB_ADDSTRING, 0, (LPARAM)L"");
				SendMessage(hWndCombo, CB_SETITEMDATA, dwItem, 0);
				SendMessage(hWndCombo, CB_SETCURSEL, dwItem, 0);

				for (size_t i = 0; mrapPlaces[i].lpszData; i++) {
					if (mrapPlaces[i].dwCountryID == dwCountryID && mrapPlaces[i].dwCityID && mrapPlaces[i].dwPlaceID == 0) {
						dwItem = SendMessage(hWndCombo, CB_ADDSTRING, 0, (LPARAM)mrapPlaces[i].lpszData);
						SendMessage(hWndCombo, CB_SETITEMDATA, dwItem, mrapPlaces[i].dwCityID);
					}
				}
			}
			break;

		case IDC_STATE:
			if (HIWORD(wParam) == CBN_SELCHANGE) {
				DWORD dwCountryID = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_COUNTRY);
				DWORD dwStateID = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_STATE);
				HWND hWndCombo = GetDlgItem(hWndDlg, IDC_CITY);
				SendMessage(hWndCombo, CB_RESETCONTENT, 0, 0);
				DWORD dwItem = SendMessage(hWndCombo, CB_ADDSTRING, 0, (LPARAM)L"");
				SendMessage(hWndCombo, CB_SETITEMDATA, dwItem, 0);
				SendMessage(hWndCombo, CB_SETCURSEL, dwItem, 0);

				for (size_t i = 0; mrapPlaces[i].lpszData; i++) {
					if (mrapPlaces[i].dwCountryID == dwCountryID && mrapPlaces[i].dwCityID == dwStateID && mrapPlaces[i].dwPlaceID) {
						dwItem = SendMessage(hWndCombo, CB_ADDSTRING, 0, (LPARAM)mrapPlaces[i].lpszData);
						SendMessage(hWndCombo, CB_SETITEMDATA, dwItem, mrapPlaces[i].dwPlaceID);
					}
				}
			}
		}
	}
	return FALSE;
}

HWND CMraProto::SearchAdvanced(HWND hWndDlg)
{
	DWORD dwRequestFlags = 0;
	char szUser[MAX_PATH], szDomain[MAX_PATH];
	wchar_t wszNickName[MAX_PATH], wszFirstName[MAX_PATH], wszLastName[MAX_PATH];

	size_t dwUserSize = GetDlgItemTextA(hWndDlg, IDC_EMAIL_USER, szUser, _countof(szUser));
	size_t dwDomainSize = GetDlgItemTextA(hWndDlg, IDC_EMAIL_DOMAIN, szDomain, _countof(szDomain));
	if (dwUserSize && dwDomainSize) {
		SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_USER);
		SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DOMAIN);
	}

	size_t dwNickNameSize = GetDlgItemText(hWndDlg, IDC_NICK, wszNickName, _countof(wszNickName));
	if (dwNickNameSize) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_NICKNAME);

	size_t dwFirstNameSize = GetDlgItemText(hWndDlg, IDC_FIRSTNAME, wszFirstName, _countof(wszFirstName));
	if (dwFirstNameSize) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_FIRSTNAME);

	size_t dwLastNameSize = GetDlgItemText(hWndDlg, IDC_LASTNAME, wszLastName, _countof(wszLastName));
	if (dwLastNameSize) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_LASTNAME);

	DWORD dwSex = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_GENDER);
	if (dwSex) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_SEX);

	DWORD dwDate1 = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_AGERANGE_FROM);
	if (dwDate1) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DATE1);

	DWORD dwDate2 = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_AGERANGE_TO);
	if (dwDate2) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_DATE2);

	DWORD dwCityID = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_CITY);
	if (dwCityID == 0) dwCityID = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_STATE);
	if (dwCityID) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_CITY_ID);

	DWORD dwZodiak = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_ZODIAK);
	if (dwZodiak) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_ZODIAC);

	DWORD dwBirthdayMonth = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_BIRTHDAY_MONTH);
	if (dwBirthdayMonth) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_MONTH);

	DWORD dwBirthdayDay = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_BIRTHDAY_DAY);
	if (dwBirthdayMonth) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_BIRTHDAY_DAY);

	DWORD dwCountryID = GET_CURRENT_COMBO_DATA(hWndDlg, IDC_COUNTRY);
	if (dwCountryID) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_COUNTRY_ID);


	DWORD dwOnline = IsDlgButtonChecked(hWndDlg, IDC_ONLINEONLY);
	if (dwOnline) SetBit(dwRequestFlags, MRIM_CS_WP_REQUEST_PARAM_ONLINE);

	return (HWND)MraWPRequestW(NULL, ACKTYPE_SEARCH, dwRequestFlags, szUser, szDomain, wszNickName, wszFirstName, wszLastName, dwSex, dwDate1, dwDate2, dwCityID, dwZodiak, dwBirthdayMonth, dwBirthdayDay, dwCountryID, dwOnline);
}

HWND CMraProto::CreateExtendedSearchUI(HWND owner)
{
	if (g_hInstance && owner)
		return CreateDialogParam(g_hInstance, MAKEINTRESOURCE(IDD_MRAADVANCEDSEARCH), owner, AdvancedSearchDlgProc, (LPARAM)this);

	return nullptr;
}