summaryrefslogtreecommitdiff
path: root/plugins/NewsAggregator/Src/Options.cpp
blob: 6c14bf876276fddc911d0d906f9a961f6e90a68c (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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
/* 
Copyright (C) 2012 Mataes

This is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this file; see the file license.txt.  If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  
*/

#include "common.h"

INT_PTR CALLBACK DlgProcAddFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, lParam);
			SetWindowText(hwndDlg, TranslateT("Add Feed"));
			SetDlgItemText(hwndDlg, IDC_FEEDURL, _T("http://"));
			SetDlgItemText(hwndDlg, IDC_TAGSEDIT, _T(TAGSDEFAULT));
			SendDlgItemMessage(hwndDlg, IDC_CHECKTIME, EM_LIMITTEXT, 3, 0);
			SetDlgItemInt(hwndDlg, IDC_CHECKTIME, 60, TRUE);
			SendDlgItemMessage(hwndDlg, IDC_TIMEOUT_VALUE_SPIN, UDM_SETRANGE32, 0, 999);	
			Utils_RestoreWindowPositionNoSize(hwndDlg,NULL,MODULE,"AddDlg");
			return TRUE;
		}
		case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
				case IDOK:
					{
						TCHAR str[MAX_PATH];
						if (!GetDlgItemText(hwndDlg, IDC_FEEDTITLE, str, SIZEOF(str)))
						{
							MessageBox(hwndDlg, TranslateT("Enter Feed name"), TranslateT("Error"), MB_OK);
							break;
						}
						else if (!GetDlgItemText(hwndDlg, IDC_FEEDURL, str, SIZEOF(str)) || lstrcmp(str, _T("http://")) == 0)
						{
							MessageBox(hwndDlg, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK);
							break;
						}
						else if (GetDlgItemInt(hwndDlg, IDC_CHECKTIME, false, false) < 0)
						{
							MessageBox(hwndDlg, TranslateT("Enter checking interval"), TranslateT("Error"), MB_OK);
							break;
						}
						else if (!GetDlgItemText(hwndDlg, IDC_TAGSEDIT, str, SIZEOF(str)))
						{
							MessageBox(hwndDlg, TranslateT("Enter message format"), TranslateT("Error"), MB_OK);
							break;
						}
						else
						{
							HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0);
							CallService(MS_PROTO_ADDTOCONTACT, (WPARAM)hContact, (LPARAM)MODULE);
							GetDlgItemText(hwndDlg, IDC_FEEDTITLE, str, SIZEOF(str));
							DBWriteContactSettingTString(hContact, MODULE, "Nick", str);
							HWND hwndList = (HWND)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
							GetDlgItemText(hwndDlg, IDC_FEEDURL, str, SIZEOF(str));
							DBWriteContactSettingTString(hContact, MODULE, "URL", str);
							DBWriteContactSettingByte(hContact, MODULE, "CheckState", 1);
							DBWriteContactSettingDword(hContact, MODULE, "UpdateTime", GetDlgItemInt(hwndDlg, IDC_CHECKTIME, false, false));
							GetDlgItemText(hwndDlg, IDC_TAGSEDIT, str, SIZEOF(str));
							DBWriteContactSettingTString(hContact, MODULE, "MsgFormat", str);
							DBWriteContactSettingWord(hContact, MODULE, "Status", CallProtoService(MODULE, PS_GETSTATUS, 0, 0));
							if (IsDlgButtonChecked(hwndDlg, IDC_USEAUTH))
							{
								DBWriteContactSettingByte(hContact, MODULE, "UseAuth", 1);
								GetDlgItemText(hwndDlg, IDC_LOGIN, str, SIZEOF(str));
								DBWriteContactSettingTString(hContact, MODULE, "Login", str);
								GetDlgItemText(hwndDlg, IDC_PASSWORD, str, SIZEOF(str));
								DBWriteContactSettingTString(hContact, MODULE, "Password", str);
							}
							DeleteAllItems(hwndList);
							UpdateList(hwndList);
						}
					}

				case IDCANCEL:
					DestroyWindow(hwndDlg);
					break;

				case IDC_USEAUTH:
					{
						if (IsDlgButtonChecked(hwndDlg, IDC_USEAUTH))
						{
							EnableWindow(GetDlgItem(hwndDlg, IDC_LOGIN), TRUE);
							EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), TRUE);
						}
						else
						{
							EnableWindow(GetDlgItem(hwndDlg, IDC_LOGIN), FALSE);
							EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), FALSE);
						}
					}
					break;

				case IDC_TAGHELP:
					{
						TCHAR tszTagHelp[1024];
						mir_sntprintf(tszTagHelp, SIZEOF(tszTagHelp), _T("%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s"),
							_T("#<title>#"),			TranslateT("The title of the item."),
							_T("#<description>#"),		TranslateT("The item synopsis."),
							_T("#<link>#"),	TranslateT("The URL of the item."),
							_T("#<author>#"),		TranslateT("Email address of the author of the item."),
							_T("#<comments>#"),				TranslateT("URL of a page for comments relating to the item."),
							_T("#<guid>#"),				TranslateT("A string that uniquely identifies the item."),
							_T("#<category>#"),				TranslateT("Specify one or more categories that the item belongs to.")
						);
						MessageBox(hwndDlg, tszTagHelp, TranslateT("Feed Tag Help"), MB_OK);
					}
					break;

				case IDC_RESET:
					if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Tags Mask Reset"), MB_YESNO | MB_ICONWARNING) == IDYES)
						SetDlgItemText(hwndDlg, IDC_TAGSEDIT, _T(TAGSDEFAULT));
					break;

				case IDC_DISCOVERY:
					{
						EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), FALSE);
						SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Wait..."));
						TCHAR tszURL[MAX_PATH] = {0}, *tszTitle = NULL;
						if (GetDlgItemText(hwndDlg, IDC_FEEDURL, tszURL, SIZEOF(tszURL)) || lstrcmp(tszURL, _T("http://")) != 0)
							tszTitle = CheckFeed(tszURL, hwndDlg);
						else
							MessageBox(hwndDlg, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK);
						SetDlgItemText(hwndDlg, IDC_FEEDTITLE, tszTitle);
						EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), TRUE);
						SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Check Feed"));
					}
					break;
			}
			break;
		}
		case WM_CLOSE:
		{
			DestroyWindow(hwndDlg);
			break;
		}
		case WM_DESTROY:
		{
			Utils_SaveWindowPosition(hwndDlg,NULL,MODULE,"AddDlg");
		}
	}

	return FALSE;
}

INT_PTR CALLBACK DlgProcChangeFeedOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);
			ItemInfo &SelItem = *(ItemInfo*)lParam;
			ItemInfo *nSelItem = new ItemInfo(SelItem);
			SetWindowText(hwndDlg, TranslateT("Change Feed"));
			SendDlgItemMessage(hwndDlg, IDC_CHECKTIME, EM_LIMITTEXT, 3, 0);
			SendDlgItemMessage(hwndDlg, IDC_TIMEOUT_VALUE_SPIN, UDM_SETRANGE32, 0, 999);

			HANDLE hContact = db_find_first();
			while (hContact != NULL)
			{
				if (IsMyContact(hContact))
				{
					DBVARIANT dbNick = {0};
					if (DBGetContactSettingTString(hContact, MODULE, "Nick", &dbNick))
						continue;
					else if (lstrcmp(dbNick.ptszVal, SelItem.nick) == 0)
					{
						DBFreeVariant(&dbNick);
						DBVARIANT dbURL = {0};
						if (DBGetContactSettingTString(hContact, MODULE, "URL", &dbURL))
							continue;
						else if (lstrcmp(dbURL.ptszVal, SelItem.url) == 0)
						{
							DBFreeVariant(&dbURL);
							nSelItem->hContact = hContact;
							SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG)nSelItem);
							SetDlgItemText(hwndDlg, IDC_FEEDURL, SelItem.url);
							SetDlgItemText(hwndDlg, IDC_FEEDTITLE, SelItem.nick);
							SetDlgItemInt(hwndDlg, IDC_CHECKTIME, DBGetContactSettingDword(hContact, MODULE, "UpdateTime", 60), TRUE);
							DBVARIANT dbMsg = {0};
							if (!DBGetContactSettingTString(hContact, MODULE, "MsgFormat", &dbMsg))
							{
								SetDlgItemText(hwndDlg, IDC_TAGSEDIT, dbMsg.ptszVal);
								DBFreeVariant(&dbMsg);
							}
							if (DBGetContactSettingByte(hContact, MODULE, "UseAuth", 0))
							{
								CheckDlgButton(hwndDlg, IDC_USEAUTH, BST_CHECKED);
								EnableWindow(GetDlgItem(hwndDlg, IDC_LOGIN), TRUE);
								EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), TRUE);
								DBVARIANT dbLogin = {0};
								if (!DBGetContactSettingTString(hContact, MODULE, "Login", &dbLogin))
								{
									SetDlgItemText(hwndDlg, IDC_LOGIN, dbLogin.ptszVal);
									DBFreeVariant(&dbLogin);
								}
								DBVARIANT dbPass = {0};
								if (!DBGetContactSettingTString(hContact, MODULE, "Password", &dbPass))
								{
									SetDlgItemText(hwndDlg, IDC_PASSWORD, dbPass.ptszVal);
									DBFreeVariant(&dbPass);
								}
							}
							break;
						}
						DBFreeVariant(&dbURL);
					}
					DBFreeVariant(&dbNick);
				}
				hContact = db_find_next(hContact);
			}
			WindowList_Add(hChangeFeedDlgList,hwndDlg,hContact);
			Utils_RestoreWindowPositionNoSize(hwndDlg,hContact,MODULE,"ChangeDlg");
			return TRUE;
		}
		case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
				case IDOK:
					{
						ItemInfo *SelItem = (ItemInfo*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
						TCHAR str[MAX_PATH];
						if (!GetDlgItemText(hwndDlg, IDC_FEEDTITLE, str, SIZEOF(str)))
						{
							MessageBox(hwndDlg, TranslateT("Enter Feed name"), TranslateT("Error"), MB_OK);
							break;
						}
						else if (!GetDlgItemText(hwndDlg, IDC_FEEDURL, str, SIZEOF(str)) || lstrcmp(str, _T("http://")) == 0)
						{
							MessageBox(hwndDlg, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK);
							break;
						}
						else if (GetDlgItemInt(hwndDlg, IDC_CHECKTIME, false, false) < 0)
						{
							MessageBox(hwndDlg, TranslateT("Enter checking interval"), TranslateT("Error"), MB_OK);
							break;
						}
						else if (!GetDlgItemText(hwndDlg, IDC_TAGSEDIT, str, SIZEOF(str)))
						{
							MessageBox(hwndDlg, TranslateT("Enter message format"), TranslateT("Error"), MB_OK);
							break;
						}
						else
						{
							GetDlgItemText(hwndDlg, IDC_FEEDURL, str, SIZEOF(str));
							DBWriteContactSettingTString(SelItem->hContact, MODULE, "URL", str);
							GetDlgItemText(hwndDlg, IDC_FEEDTITLE, str, SIZEOF(str));
							DBWriteContactSettingTString(SelItem->hContact, MODULE, "Nick", str);
							DBWriteContactSettingDword(SelItem->hContact, MODULE, "UpdateTime", GetDlgItemInt(hwndDlg, IDC_CHECKTIME, false, false));
							GetDlgItemText(hwndDlg, IDC_TAGSEDIT, str, SIZEOF(str));
							DBWriteContactSettingTString(SelItem->hContact, MODULE, "MsgFormat", str);
							if (IsDlgButtonChecked(hwndDlg, IDC_USEAUTH))
							{
								DBWriteContactSettingByte(SelItem->hContact, MODULE, "UseAuth", 1);
								GetDlgItemText(hwndDlg, IDC_LOGIN, str, SIZEOF(str));
								DBWriteContactSettingTString(SelItem->hContact, MODULE, "Login", str);
								GetDlgItemText(hwndDlg, IDC_PASSWORD, str, SIZEOF(str));
								DBWriteContactSettingTString(SelItem->hContact, MODULE, "Password", str);
							}
							DeleteAllItems(SelItem->hwndList);
							UpdateList(SelItem->hwndList);
						}
					}

				case IDCANCEL:
					DestroyWindow(hwndDlg);
					break;

				case IDC_USEAUTH:
					{
						if (IsDlgButtonChecked(hwndDlg, IDC_USEAUTH))
						{
							EnableWindow(GetDlgItem(hwndDlg, IDC_LOGIN), TRUE);
							EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), TRUE);
						}
						else
						{
							EnableWindow(GetDlgItem(hwndDlg, IDC_LOGIN), FALSE);
							EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), FALSE);
						}
						break;
					}

				case IDC_TAGHELP:
					{
						TCHAR tszTagHelp[1024];
						mir_sntprintf(tszTagHelp, SIZEOF(tszTagHelp), _T("%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s"),
							_T("#<title>#"),			TranslateT("The title of the item."),
							_T("#<description>#"),		TranslateT("The item synopsis."),
							_T("#<link>#"),	TranslateT("The URL of the item."),
							_T("#<author>#"),		TranslateT("Email address of the author of the item."),
							_T("#<comments>#"),				TranslateT("URL of a page for comments relating to the item."),
							_T("#<guid>#"),				TranslateT("A string that uniquely identifies the item."),
							_T("#<category>#"),				TranslateT("Specify one or more categories that the item belongs to.")
						);
						MessageBox(hwndDlg, tszTagHelp, TranslateT("Feed Tag Help"), MB_OK);
					}
					break;

				case IDC_RESET:
					if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Tags Mask Reset"), MB_YESNO | MB_ICONWARNING) == IDYES)
						SetDlgItemText(hwndDlg, IDC_TAGSEDIT, _T(TAGSDEFAULT));
					break;

				case IDC_DISCOVERY:
					{
						TCHAR tszURL[MAX_PATH] = {0};
						if (GetDlgItemText(hwndDlg, IDC_FEEDURL, tszURL, SIZEOF(tszURL)) || lstrcmp(tszURL, _T("http://")) != 0)
						{
							EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), FALSE);
							SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Wait..."));
							TCHAR *tszTitle = CheckFeed(tszURL, hwndDlg);
							SetDlgItemText(hwndDlg, IDC_FEEDTITLE, tszTitle);
							EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), TRUE);
							SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Check Feed"));
						}
						else
							MessageBox(hwndDlg, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK);
					}
					break;
			}
			break;
		}

		case WM_CLOSE:
		{
			DestroyWindow(hwndDlg);
			break;
		}

		case WM_DESTROY:
		{
			HANDLE hContact = (HANDLE) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			Utils_SaveWindowPosition(hwndDlg,hContact,MODULE,"ChangeDlg");
			WindowList_Remove(hChangeFeedDlgList,hwndDlg);
			ItemInfo *SelItem = (ItemInfo*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			delete SelItem;
			break;
		}
	}

	return FALSE;
}

INT_PTR CALLBACK DlgProcChangeFeedMenu(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);
			SetWindowText(hwndDlg, TranslateT("Change Feed"));
			SendDlgItemMessage(hwndDlg, IDC_CHECKTIME, UDM_SETRANGE32, 0, 999);

			HANDLE hContact = (HANDLE)lParam;
			WindowList_Add(hChangeFeedDlgList,hwndDlg,hContact);
			Utils_RestoreWindowPositionNoSize(hwndDlg,hContact,MODULE,"ChangeDlg");
			DBVARIANT dbNick = {0};
			if (!DBGetContactSettingTString(hContact, MODULE, "Nick", &dbNick))
			{
				SetDlgItemText(hwndDlg, IDC_FEEDTITLE, dbNick.ptszVal);
				DBFreeVariant(&dbNick);
				DBVARIANT dbURL = {0};
				if (!DBGetContactSettingTString(hContact, MODULE, "URL", &dbURL))
				{
					SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG)lParam);
					SetDlgItemText(hwndDlg, IDC_FEEDURL, dbURL.ptszVal);
					DBFreeVariant(&dbURL);
					SetDlgItemInt(hwndDlg, IDC_CHECKTIME, DBGetContactSettingDword(hContact, MODULE, "UpdateTime", 60), TRUE);
					DBVARIANT dbMsg = {0};
					if (!DBGetContactSettingTString(hContact, MODULE, "MsgFormat", &dbMsg))
					{
						SetDlgItemText(hwndDlg, IDC_TAGSEDIT, dbMsg.ptszVal);
						DBFreeVariant(&dbMsg);
					}
					if (DBGetContactSettingByte(hContact, MODULE, "UseAuth", 0))
					{
						CheckDlgButton(hwndDlg, IDC_USEAUTH, BST_CHECKED);
						EnableWindow(GetDlgItem(hwndDlg, IDC_LOGIN), TRUE);
						EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), TRUE);
						DBVARIANT dbLogin = {0};
						if (!DBGetContactSettingTString(hContact, MODULE, "Login", &dbLogin))
						{
							SetDlgItemText(hwndDlg, IDC_LOGIN, dbLogin.ptszVal);
							DBFreeVariant(&dbLogin);
						}
						DBVARIANT dbPass = {0};
						if (!DBGetContactSettingTString(hContact, MODULE, "Password", &dbPass))
						{
							SetDlgItemText(hwndDlg, IDC_PASSWORD, dbPass.ptszVal);
							DBFreeVariant(&dbPass);
						}
					}
					break;
				}
			}
			return TRUE;
		}
		case WM_COMMAND:
		{
			switch (LOWORD(wParam))
			{
				case IDOK:
					{
						HANDLE hContact = (HANDLE)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
						TCHAR str[MAX_PATH];
						if (!GetDlgItemText(hwndDlg, IDC_FEEDTITLE, str, SIZEOF(str)))
						{
							MessageBox(hwndDlg, TranslateT("Enter Feed name"), TranslateT("Error"), MB_OK);
							break;
						}
						else if (!GetDlgItemText(hwndDlg, IDC_FEEDURL, str, SIZEOF(str)) || lstrcmp(str, _T("http://")) == 0)
						{
							MessageBox(hwndDlg, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK);
							break;
						}
						else if (GetDlgItemInt(hwndDlg, IDC_CHECKTIME, false, false) < 0)
						{
							MessageBox(hwndDlg, TranslateT("Enter checking interval"), TranslateT("Error"), MB_OK);
							break;
						}
						else if (!GetDlgItemText(hwndDlg, IDC_TAGSEDIT, str, SIZEOF(str)))
						{
							MessageBox(hwndDlg, TranslateT("Enter message format"), TranslateT("Error"), MB_OK);
							break;
						}
						else
						{
							GetDlgItemText(hwndDlg, IDC_FEEDURL, str, SIZEOF(str));
							DBWriteContactSettingTString(hContact, MODULE, "URL", str);
							GetDlgItemText(hwndDlg, IDC_FEEDTITLE, str, SIZEOF(str));
							DBWriteContactSettingTString(hContact, MODULE, "Nick", str);
							DBWriteContactSettingDword(hContact, MODULE, "UpdateTime", GetDlgItemInt(hwndDlg, IDC_CHECKTIME, false, false));
							GetDlgItemText(hwndDlg, IDC_TAGSEDIT, str, SIZEOF(str));
							DBWriteContactSettingTString(hContact, MODULE, "MsgFormat", str);
							if (IsDlgButtonChecked(hwndDlg, IDC_USEAUTH))
							{
								DBWriteContactSettingByte(hContact, MODULE, "UseAuth", 1);
								GetDlgItemText(hwndDlg, IDC_LOGIN, str, SIZEOF(str));
								DBWriteContactSettingTString(hContact, MODULE, "Login", str);
								GetDlgItemText(hwndDlg, IDC_PASSWORD, str, SIZEOF(str));
								DBWriteContactSettingTString(hContact, MODULE, "Password", str);
							}
						}
					}

				case IDCANCEL:
					DestroyWindow(hwndDlg);
					break;

				case IDC_USEAUTH:
					{
						if (IsDlgButtonChecked(hwndDlg, IDC_USEAUTH))
						{
							EnableWindow(GetDlgItem(hwndDlg, IDC_LOGIN), TRUE);
							EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), TRUE);
						}
						else
						{
							EnableWindow(GetDlgItem(hwndDlg, IDC_LOGIN), FALSE);
							EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), FALSE);
						}
						break;
					}

				case IDC_TAGHELP:
					{
						TCHAR tszTagHelp[1024];
						mir_sntprintf(tszTagHelp, SIZEOF(tszTagHelp), _T("%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s"),
							_T("#<title>#"),			TranslateT("The title of the item."),
							_T("#<description>#"),		TranslateT("The item synopsis."),
							_T("#<link>#"),	TranslateT("The URL of the item."),
							_T("#<author>#"),		TranslateT("Email address of the author of the item."),
							_T("#<comments>#"),				TranslateT("URL of a page for comments relating to the item."),
							_T("#<guid>#"),				TranslateT("A string that uniquely identifies the item."),
							_T("#<category>#"),				TranslateT("Specify one or more categories that the item belongs to.")
						);
						MessageBox(hwndDlg, tszTagHelp, TranslateT("Feed Tag Help"), MB_OK);
					}
					break;

				case IDC_RESET:
					if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Tags Mask Reset"), MB_YESNO | MB_ICONWARNING) == IDYES)
						SetDlgItemText(hwndDlg, IDC_TAGSEDIT, _T(TAGSDEFAULT));
					break;

				case IDC_DISCOVERY:
					{
						TCHAR tszURL[MAX_PATH] = {0};
						if (GetDlgItemText(hwndDlg, IDC_FEEDURL, tszURL, SIZEOF(tszURL)) || lstrcmp(tszURL, _T("http://")) != 0)
						{
							EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), FALSE);
							SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Wait..."));
							TCHAR *tszTitle = CheckFeed(tszURL, hwndDlg);
							SetDlgItemText(hwndDlg, IDC_FEEDTITLE, tszTitle);
							EnableWindow(GetDlgItem(hwndDlg, IDC_DISCOVERY), TRUE);
							SetDlgItemText(hwndDlg, IDC_DISCOVERY, TranslateT("Check Feed"));
						}
						else
							MessageBox(hwndDlg, TranslateT("Enter Feed URL"), TranslateT("Error"), MB_OK);
					}
					break;
			}
			break;
		}

		case WM_CLOSE:
		{
			DestroyWindow(hwndDlg);
			break;
		}
		case WM_DESTROY:
		{
			HANDLE hContact = (HANDLE) GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			Utils_SaveWindowPosition(hwndDlg,hContact,MODULE,"ChangeDlg");
			WindowList_Remove(hChangeFeedDlgList,hwndDlg);
		}
	}

	return FALSE;
}

INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND hwndList = GetDlgItem(hwndDlg, IDC_FEEDLIST);
	switch (msg)
	{
	case WM_INITDIALOG:
		{
			TranslateDialogDefault(hwndDlg);
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0);
			CreateList(hwndList);
			UpdateList(hwndList);
			CheckDlgButton(hwndDlg, IDC_STARTUPRETRIEVE, db_get_b(NULL, MODULE, "StartupRetrieve", 1));
			return TRUE;
		}

	case WM_COMMAND:
	{
		switch (LOWORD(wParam))
		{
			case IDC_ADD:
				{
					CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDFEED), hwndDlg, DlgProcAddFeedOpts, (LPARAM)hwndList);
				}
				return FALSE;
			case IDC_CHANGE:
				{
					ItemInfo SelItem = {0};
					int sel = ListView_GetSelectionMark(hwndList);
					ListView_GetItemText(hwndList, sel, 0, SelItem.nick, MAX_PATH);
					ListView_GetItemText(hwndList, sel, 1, SelItem.url, MAX_PATH);
					SelItem.hwndList = hwndList;
					SelItem.SelNumber = sel;
					CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDFEED), hwndDlg, DlgProcChangeFeedOpts, (LPARAM)&SelItem);
				}
				return FALSE;
			case IDC_REMOVE:
				{
					if (MessageBox(hwndDlg, TranslateT("Are you sure?"), TranslateT("Contact deleting"), MB_YESNO | MB_ICONWARNING) == IDYES)
					{
						TCHAR nick[MAX_PATH], url[MAX_PATH];
						int sel = ListView_GetSelectionMark(hwndList);
						ListView_GetItemText(hwndList, sel, 0, nick, MAX_PATH);
						ListView_GetItemText(hwndList, sel, 1, url, MAX_PATH);

						HANDLE hContact = db_find_first();
						while (hContact != NULL)
						{
							if(IsMyContact(hContact))
							{
								DBVARIANT dbNick = {0};
								if (DBGetContactSettingTString(hContact, MODULE, "Nick", &dbNick))
									break;
								else if (lstrcmp(dbNick.ptszVal, nick) == 0)
								{
									DBFreeVariant(&dbNick);
									DBVARIANT dbURL = {0};
									if (DBGetContactSettingTString(hContact, MODULE, "URL", &dbURL))
										break;
									else if (lstrcmp(dbURL.ptszVal, url) == 0)
									{
										DBFreeVariant(&dbURL);
										CallService(MS_DB_CONTACT_DELETE, (WPARAM)hContact, 0);
										ListView_DeleteItem(hwndList, sel);
										break;
									}
									DBFreeVariant(&dbURL);
								}
								DBFreeVariant(&dbNick);
							}
							hContact = db_find_next(hContact);
						}
					}
					return FALSE;
				}

			case IDC_STARTUPRETRIEVE:
				SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				break;
		}
		break;
	}
	case WM_NOTIFY:
		{
			NMHDR *hdr = (NMHDR *)lParam;
			switch (hdr->code)
			{
				case PSN_APPLY:
					{
						db_set_b(NULL, MODULE, "StartupRetrieve", IsDlgButtonChecked(hwndDlg, IDC_STARTUPRETRIEVE));
						HANDLE hContact = db_find_first();
						int i = 0;
						while (hContact != NULL)
						{
							if(IsMyContact(hContact))
							{
								DBWriteContactSettingByte(hContact, MODULE, "CheckState", ListView_GetCheckState(hwndList, i));
								if (!ListView_GetCheckState(hwndList, i))
									DBWriteContactSettingByte(hContact, "CList", "Hidden", 1);
								else
									DBDeleteContactSetting(hContact,"CList","Hidden");
								i += 1;
							}
							hContact = db_find_next(hContact);
						}
						break;
					}

				case NM_DBLCLK:
					{
						ItemInfo SelItem = {0};
						int sel = ListView_GetHotItem(hwndList);
						if (sel != -1)
						{
							ListView_GetItemText(hwndList, sel, 0, SelItem.nick, MAX_PATH);
							ListView_GetItemText(hwndList, sel, 1, SelItem.url, MAX_PATH);
							SelItem.hwndList = hwndList;
							SelItem.SelNumber = sel;
							CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_ADDFEED), hwndDlg, DlgProcChangeFeedOpts, (LPARAM)&SelItem);
						}
						break;
					}

			case LVN_ITEMCHANGED:
				{
					NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;
					if (((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK) && !UpdateListFlag)
					{
						SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
					}
					break;
				}
			}
		}
	}//end* switch (msg)
	return FALSE;
}

INT OptInit(WPARAM wParam, LPARAM lParam)
{
	OPTIONSDIALOGPAGE odp = {0};
	odp.cbSize = sizeof(odp);
	odp.position = 100000000;
	odp.hInstance = hInst;
	odp.flags = ODPF_BOLDGROUPS;
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
	odp.pszGroup = LPGEN("Network");
	odp.pszTitle = LPGEN("News Aggregator");
	odp.pfnDlgProc = UpdateNotifyOptsProc;
	Options_AddPage(wParam, &odp);
	return 0;
}