Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1131 lines
36 KiB

  1. #include "private.h"
  2. #include "offl_cpp.h"
  3. #include "helper.h"
  4. #include <mluisupp.h>
  5. #include "apithk.h"
  6. // REARCHITECT: (tnoonan) This whole file needs some cleanup - starting with a base dialog class.
  7. const TCHAR c_szStrEmpty[] = TEXT("");
  8. const TCHAR c_szStrBoot[] = TEXT("boot");
  9. const TCHAR c_szStrScrnSave[] = TEXT("scrnsave.exe");
  10. const TCHAR c_szStrSystemIni[] = TEXT("system.ini");
  11. const TCHAR c_szShowWelcome[] = TEXT("ShowWelcome");
  12. extern BOOL CALLBACK MailOptionDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  13. extern void ReadDefaultEmail(LPTSTR, UINT);
  14. extern BOOL CALLBACK LoginOptionDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  15. extern void ReadDefaultEmail(LPTSTR szBuf, UINT cch);
  16. extern void ReadDefaultSMTPServer(LPTSTR szBuf, UINT cch);
  17. INT_PTR CALLBACK WelcomeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  18. INT_PTR CALLBACK DownloadDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  19. INT_PTR CALLBACK PickScheduleDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  20. INT_PTR CALLBACK NewScheduleWizDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  21. INT_PTR CALLBACK LoginDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  22. #define WIZPAGE_NOINTRO 0x0001
  23. #define WIZPAGE_NODOWNLOAD 0x0002
  24. #define WIZPAGE_NOLOGIN 0x0004
  25. struct WizInfo
  26. {
  27. SUBSCRIPTIONTYPE subType;
  28. POOEBuf pOOE;
  29. DWORD dwExceptFlags;
  30. BOOL bShowWelcome;
  31. BOOL bIsNewSchedule;
  32. NOTIFICATIONCOOKIE newCookie;
  33. };
  34. struct WizPage
  35. {
  36. int nResourceID;
  37. DLGPROC dlgProc;
  38. DWORD dwExceptFlags;
  39. };
  40. const WizPage WizPages[] =
  41. {
  42. { IDD_WIZARD0, WelcomeDlgProc, WIZPAGE_NOINTRO },
  43. { IDD_WIZARD1, DownloadDlgProc, WIZPAGE_NODOWNLOAD },
  44. { IDD_WIZARD2, PickScheduleDlgProc, 0 },
  45. { IDD_WIZARD3, NewScheduleWizDlgProc, 0 },
  46. { IDD_WIZARD4, LoginDlgProc, WIZPAGE_NOLOGIN }
  47. };
  48. // Helper functions
  49. inline BOOL IsDesktop(SUBSCRIPTIONTYPE subType)
  50. {
  51. return (subType == SUBSTYPE_DESKTOPURL) || (subType == SUBSTYPE_DESKTOPCHANNEL);
  52. }
  53. inline BOOL IsChannel(SUBSCRIPTIONTYPE subType)
  54. {
  55. return (subType == SUBSTYPE_CHANNEL) || (subType == SUBSTYPE_DESKTOPCHANNEL);
  56. }
  57. inline DWORD GetShowWelcomeScreen()
  58. {
  59. DWORD dwShowWelcome = TRUE;
  60. ReadRegValue(HKEY_CURRENT_USER, c_szRegKey, c_szShowWelcome, &dwShowWelcome, sizeof(dwShowWelcome));
  61. return dwShowWelcome;
  62. }
  63. inline void SetShowWelcomeScreen(DWORD dwShowWelcome)
  64. {
  65. WriteRegValue(HKEY_CURRENT_USER, c_szRegKey, c_szShowWelcome, &dwShowWelcome, sizeof(DWORD), REG_DWORD);
  66. }
  67. //
  68. // Explanation of logic for the back/next/finish button
  69. //
  70. // Wiz0 - welcome
  71. // Wiz1 - download
  72. // Wiz2 - pick schedule
  73. // Wiz3 - create schedule
  74. // Wiz4 - login
  75. //
  76. // A state machine can be derived to determine the different possibilities.
  77. // The resulting state table is as follows:
  78. //
  79. // Wiz0: Always has next button
  80. //
  81. // Wiz1: Show back if Wiz0 was shown
  82. // Always has next button
  83. //
  84. // Wiz2: Show back if Wiz0 or Wiz1 was shown
  85. // Show next if create new schedule or show login, otherwise show finish
  86. //
  87. // Wiz3: Always has back button
  88. // Show next if show login, otherwise show finish
  89. //
  90. // Wiz4: Always has back button
  91. // Always has finish button
  92. //
  93. void SetWizButtons(HWND hDlg, INT_PTR resID, WizInfo *pwi)
  94. {
  95. DWORD dwButtons;
  96. switch (resID)
  97. {
  98. case IDD_WIZARD0:
  99. dwButtons = PSWIZB_NEXT;
  100. break;
  101. case IDD_WIZARD1:
  102. dwButtons = PSWIZB_NEXT;
  103. if (pwi && !(pwi->dwExceptFlags & WIZPAGE_NOINTRO))
  104. {
  105. dwButtons |= PSWIZB_BACK;
  106. }
  107. break;
  108. case IDD_WIZARD2:
  109. if (pwi && ((!(pwi->dwExceptFlags & WIZPAGE_NODOWNLOAD)) ||
  110. (!(pwi->dwExceptFlags & WIZPAGE_NOINTRO))))
  111. {
  112. dwButtons = PSWIZB_BACK;
  113. }
  114. else
  115. {
  116. dwButtons = 0;
  117. }
  118. dwButtons |= (pwi && (pwi->bIsNewSchedule || (!(pwi->dwExceptFlags & WIZPAGE_NOLOGIN))))
  119. ? PSWIZB_NEXT : PSWIZB_FINISH;
  120. break;
  121. case IDD_WIZARD3:
  122. dwButtons = PSWIZB_BACK |
  123. ((pwi && (!(pwi->dwExceptFlags & WIZPAGE_NOLOGIN))) ? PSWIZB_NEXT : PSWIZB_FINISH);
  124. break;
  125. case IDD_WIZARD4:
  126. dwButtons = PSWIZB_BACK | PSWIZB_FINISH;
  127. break;
  128. default:
  129. dwButtons = 0;
  130. ASSERT(FALSE);
  131. break;
  132. }
  133. PropSheet_SetWizButtons(GetParent(hDlg), dwButtons);
  134. }
  135. HRESULT CreateAndAddPage(PROPSHEETHEADER& psh, PROPSHEETPAGE& psp, int nPageIndex, DWORD dwExceptFlags)
  136. {
  137. HRESULT hr = S_OK;
  138. if (!(WizPages[nPageIndex].dwExceptFlags & dwExceptFlags))
  139. {
  140. psp.pszTemplate = MAKEINTRESOURCE(WizPages[nPageIndex].nResourceID);
  141. psp.pfnDlgProc = WizPages[nPageIndex].dlgProc;
  142. HPROPSHEETPAGE hpage = Whistler_CreatePropertySheetPageW(&psp);
  143. if (NULL != hpage)
  144. {
  145. psh.phpage[psh.nPages++] = hpage;
  146. }
  147. else
  148. {
  149. hr = E_OUTOFMEMORY;
  150. }
  151. }
  152. else
  153. {
  154. hr = S_FALSE;
  155. }
  156. return hr;
  157. }
  158. HRESULT CreateWizard(HWND hwndParent, SUBSCRIPTIONTYPE subType, POOEBuf pOOE)
  159. {
  160. HRESULT hr = S_OK;
  161. UINT i;
  162. HPROPSHEETPAGE hPropPage[ARRAYSIZE(WizPages)];
  163. PROPSHEETPAGE psp = { 0 };
  164. PROPSHEETHEADER psh = { 0 };
  165. WizInfo wi;
  166. ASSERT(NULL != pOOE);
  167. ASSERT((subType >= SUBSTYPE_URL) && (subType <= SUBSTYPE_DESKTOPCHANNEL));
  168. wi.subType = subType;
  169. wi.pOOE = pOOE;
  170. wi.dwExceptFlags = 0;
  171. wi.bShowWelcome = GetShowWelcomeScreen();
  172. wi.bIsNewSchedule = FALSE;
  173. if (FALSE == wi.bShowWelcome)
  174. {
  175. wi.dwExceptFlags |= WIZPAGE_NOINTRO;
  176. }
  177. if (IsDesktop(subType))
  178. {
  179. wi.dwExceptFlags |= WIZPAGE_NODOWNLOAD;
  180. }
  181. if ((pOOE->bChannel && (!pOOE->bNeedPassword)) ||
  182. SHRestricted2W(REST_NoSubscriptionPasswords, NULL, 0))
  183. {
  184. wi.dwExceptFlags |= WIZPAGE_NOLOGIN;
  185. }
  186. // initialize propsheet header.
  187. psh.dwSize = sizeof(PROPSHEETHEADER);
  188. psh.dwFlags = PSH_WIZARD;
  189. psh.hwndParent = hwndParent;
  190. psh.pszCaption = NULL;
  191. psh.hInstance = MLGetHinst();
  192. psh.nPages = 0;
  193. psh.nStartPage = 0;
  194. psh.phpage = hPropPage;
  195. // initialize propsheet page.
  196. psp.dwSize = sizeof(PROPSHEETPAGE);
  197. psp.dwFlags = PSP_DEFAULT;
  198. psp.hInstance = MLGetHinst();
  199. psp.pszIcon = NULL;
  200. psp.pszTitle = NULL;
  201. psp.lParam = (LPARAM)&wi;
  202. for (i = 0; (i < ARRAYSIZE(WizPages)) && (SUCCEEDED(hr)); i++)
  203. {
  204. hr = CreateAndAddPage(psh, psp, i, wi.dwExceptFlags);
  205. }
  206. if (SUCCEEDED(hr))
  207. {
  208. // invoke the property sheet
  209. INT_PTR nResult = PropertySheet(&psh);
  210. if (nResult > 0)
  211. {
  212. SetShowWelcomeScreen(wi.bShowWelcome);
  213. hr = S_OK;
  214. }
  215. else if (nResult == 0)
  216. {
  217. hr = E_ABORT;
  218. }
  219. else
  220. {
  221. hr = E_FAIL;
  222. }
  223. }
  224. else
  225. {
  226. for (i = 0; i < psh.nPages; i++)
  227. {
  228. DestroyPropertySheetPage(hPropPage[i]);
  229. }
  230. }
  231. return hr;
  232. }
  233. //--------------------------------------------------------------------
  234. // Dialog Procs
  235. INT_PTR CALLBACK WelcomeDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  236. {
  237. LPPROPSHEETPAGE lpPropSheet =(LPPROPSHEETPAGE) GetWindowLongPtr(hDlg, DWLP_USER);
  238. WizInfo *pWiz = lpPropSheet ? (WizInfo *)lpPropSheet->lParam : NULL;
  239. NMHDR FAR *lpnm;
  240. BOOL result = FALSE;
  241. switch (message)
  242. {
  243. case WM_INITDIALOG:
  244. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  245. result = TRUE;
  246. break;
  247. case WM_NOTIFY:
  248. lpnm = (NMHDR FAR *)lParam;
  249. switch (lpnm->code)
  250. {
  251. case PSN_SETACTIVE:
  252. ASSERT(NULL != lpPropSheet);
  253. ASSERT(NULL != pWiz);
  254. SetWizButtons(hDlg, (INT_PTR) lpPropSheet->pszTemplate, pWiz);
  255. result = TRUE;
  256. break;
  257. case PSN_KILLACTIVE:
  258. if (pWiz)
  259. {
  260. pWiz->bShowWelcome = !IsDlgButtonChecked(hDlg, IDC_WIZ_DONT_SHOW_INTRO);
  261. result = TRUE;
  262. }
  263. break;
  264. }
  265. break;
  266. }
  267. return result;
  268. }
  269. void EnableLevelsDeep(HWND hwndDlg, BOOL fEnable)
  270. {
  271. ASSERT(hwndDlg != NULL);
  272. EnableWindow(GetDlgItem(hwndDlg,IDC_WIZ_LINKSDEEP_STATIC1), fEnable);
  273. EnableWindow(GetDlgItem(hwndDlg,IDC_WIZ_LINKSDEEP_STATIC2), fEnable);
  274. EnableWindow(GetDlgItem(hwndDlg,IDC_WIZ_LINKSDEEP_EDIT), fEnable);
  275. EnableWindow(GetDlgItem(hwndDlg,IDC_WIZ_LINKSDEEP_SPIN), fEnable);
  276. return;
  277. }
  278. //
  279. // shows or hides the UI for specifying the number "levels deep" to recurse
  280. //
  281. void ShowLevelsDeep(HWND hwndDlg, BOOL fShow)
  282. {
  283. INT nCmdShow = fShow ? SW_SHOW: SW_HIDE;
  284. ASSERT(hwndDlg != NULL);
  285. ShowWindow(GetDlgItem(hwndDlg,IDC_WIZ_LINKSDEEP_STATIC1), nCmdShow);
  286. ShowWindow(GetDlgItem(hwndDlg,IDC_WIZ_LINKSDEEP_STATIC2), nCmdShow);
  287. ShowWindow(GetDlgItem(hwndDlg,IDC_WIZ_LINKSDEEP_EDIT), nCmdShow);
  288. ShowWindow(GetDlgItem(hwndDlg,IDC_WIZ_LINKSDEEP_SPIN), nCmdShow);
  289. }
  290. //
  291. // enables or disables the UI for specifying the number "levels deep" to recurse
  292. //
  293. INT_PTR CALLBACK DownloadDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  294. {
  295. LPPROPSHEETPAGE lpPropSheet =(LPPROPSHEETPAGE) GetWindowLongPtr(hDlg, DWLP_USER);
  296. WizInfo *pWiz = lpPropSheet ? (WizInfo *)lpPropSheet->lParam : NULL;
  297. POOEBuf pBuf = pWiz ? pWiz->pOOE : NULL;
  298. NMHDR FAR *lpnm;
  299. BOOL result = FALSE;
  300. switch (message)
  301. {
  302. case WM_INITDIALOG:
  303. {
  304. TCHAR szBuf[256];
  305. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  306. pWiz = (WizInfo *)((LPPROPSHEETPAGE)lParam)->lParam;
  307. pBuf = pWiz ? pWiz->pOOE : NULL;
  308. SetListViewToString(GetDlgItem (hDlg, IDC_NAME), pBuf->m_Name);
  309. SetListViewToString(GetDlgItem (hDlg, IDC_URL), pBuf->m_URL);
  310. MLLoadString(
  311. (pWiz && IsChannel(pWiz->subType)) ? IDS_WIZ_GET_LINKS_CHANNEL : IDS_WIZ_GET_LINKS_URL,
  312. szBuf, ARRAYSIZE(szBuf));
  313. SetDlgItemText(hDlg, IDC_WIZ_GET_LINKS_TEXT, szBuf);
  314. int checked;
  315. if ((pBuf->bChannel && (pBuf->fChannelFlags & CHANNEL_AGENT_PRECACHE_ALL)) ||
  316. (!pBuf->bChannel && ((pBuf->m_RecurseLevels) > 0)))
  317. {
  318. checked = IDC_WIZ_LINKS_YES;
  319. }
  320. else
  321. {
  322. checked = IDC_WIZ_LINKS_NO;
  323. }
  324. CheckRadioButton(hDlg, IDC_WIZ_LINKS_YES, IDC_WIZ_LINKS_NO, checked);
  325. //
  326. // Initialize the spin control for "levels deep" UI
  327. //
  328. HWND hwndLevelsSpin = GetDlgItem(hDlg,IDC_WIZ_LINKSDEEP_SPIN);
  329. SendMessage(hwndLevelsSpin, UDM_SETRANGE, 0, MAKELONG(MAX_WEBCRAWL_LEVELS, 1));
  330. SendMessage(hwndLevelsSpin, UDM_SETPOS, 0, pBuf->m_RecurseLevels);
  331. ShowLevelsDeep(hDlg,!pBuf->bChannel);
  332. EnableLevelsDeep(hDlg,!pBuf->bChannel && IDC_WIZ_LINKS_YES==checked);
  333. result = TRUE;
  334. break;
  335. }
  336. case WM_COMMAND:
  337. switch (HIWORD(wParam))
  338. {
  339. case BN_CLICKED:
  340. if (!pBuf->bChannel)
  341. switch (LOWORD(wParam))
  342. {
  343. case IDC_WIZ_LINKS_YES:
  344. EnableLevelsDeep(hDlg,TRUE);
  345. break;
  346. case IDC_WIZ_LINKS_NO:
  347. EnableLevelsDeep(hDlg,FALSE);
  348. break;
  349. }
  350. break;
  351. case EN_KILLFOCUS:
  352. //
  353. // This code checks for bogus values in the "levels deep"
  354. // edit control and replaces them with something valid
  355. //
  356. if (LOWORD(wParam)==IDC_WIZ_LINKSDEEP_EDIT)
  357. {
  358. BOOL fTranslated = FALSE;
  359. UINT cLevels = GetDlgItemInt(hDlg,IDC_WIZ_LINKSDEEP_EDIT,&fTranslated,FALSE);
  360. if (!fTranslated || cLevels < 1)
  361. {
  362. SetDlgItemInt(hDlg,IDC_WIZ_LINKSDEEP_EDIT,1,FALSE);
  363. }
  364. else if (cLevels > MAX_WEBCRAWL_LEVELS)
  365. {
  366. SetDlgItemInt(hDlg,IDC_WIZ_LINKSDEEP_EDIT,MAX_WEBCRAWL_LEVELS,FALSE);
  367. }
  368. }
  369. break;
  370. }
  371. break;
  372. case WM_NOTIFY:
  373. lpnm = (NMHDR FAR *)lParam;
  374. switch (lpnm->code)
  375. {
  376. case PSN_SETACTIVE:
  377. ASSERT(NULL != lpPropSheet);
  378. ASSERT(NULL != pWiz);
  379. SetWizButtons(hDlg, (INT_PTR) lpPropSheet->pszTemplate, pWiz);
  380. result = TRUE;
  381. break;
  382. case PSN_KILLACTIVE:
  383. ASSERT(NULL != pBuf);
  384. if (IsDlgButtonChecked(hDlg, IDC_WIZ_LINKS_YES))
  385. {
  386. if (pWiz && IsChannel(pWiz->subType))
  387. {
  388. pBuf->fChannelFlags |= CHANNEL_AGENT_PRECACHE_ALL;
  389. }
  390. else
  391. {
  392. DWORD dwPos = (DWORD)SendDlgItemMessage(hDlg,IDC_WIZ_LINKSDEEP_SPIN,UDM_GETPOS,0,0);
  393. //
  394. // Set the m_RecurseLevels field to the given by the
  395. // spin control. HIWORD(dwPos) indicated errror.
  396. //
  397. if (HIWORD(dwPos))
  398. pBuf->m_RecurseLevels = 1;
  399. else
  400. pBuf->m_RecurseLevels = LOWORD(dwPos);
  401. pBuf->m_RecurseFlags |= WEBCRAWL_LINKS_ELSEWHERE;
  402. }
  403. }
  404. else
  405. {
  406. if (pWiz && IsChannel(pWiz->subType))
  407. {
  408. pBuf->fChannelFlags &= ~CHANNEL_AGENT_PRECACHE_ALL;
  409. pBuf->fChannelFlags |= CHANNEL_AGENT_PRECACHE_SOME;
  410. }
  411. else
  412. {
  413. pBuf->m_RecurseLevels = 0;
  414. pBuf->m_RecurseFlags &= ~WEBCRAWL_LINKS_ELSEWHERE;
  415. }
  416. }
  417. break;
  418. }
  419. break;
  420. }
  421. return result;
  422. }
  423. void HandleScheduleButtons(HWND hDlg, LPPROPSHEETPAGE lpPropSheet, WizInfo *pWiz)
  424. {
  425. ASSERT(NULL != lpPropSheet);
  426. ASSERT(NULL != pWiz);
  427. EnableWindow(GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_LIST),
  428. IsDlgButtonChecked(hDlg, IDC_WIZ_SCHEDULE_EXISTING));
  429. pWiz->bIsNewSchedule = IsDlgButtonChecked(hDlg, IDC_WIZ_SCHEDULE_NEW);
  430. SetWizButtons(hDlg, (INT_PTR) lpPropSheet->pszTemplate, pWiz);
  431. }
  432. struct PICKSCHED_LIST_DATA
  433. {
  434. SYNCSCHEDULECOOKIE SchedCookie;
  435. };
  436. struct PICKSCHED_ENUM_DATA
  437. {
  438. HWND hwndSchedList;
  439. POOEBuf pBuf;
  440. SYNCSCHEDULECOOKIE defSchedule;
  441. SYNCSCHEDULECOOKIE customSchedule;
  442. int *pnDefaultSelection;
  443. BOOL bHasAtLeastOneSchedule:1;
  444. BOOL bFoundCustomSchedule:1;
  445. };
  446. BOOL PickSched_EnumCallback(ISyncSchedule *pSyncSchedule,
  447. SYNCSCHEDULECOOKIE *pSchedCookie,
  448. LPARAM lParam)
  449. {
  450. BOOL bAdded = FALSE;
  451. PICKSCHED_ENUM_DATA *psed = (PICKSCHED_ENUM_DATA *)lParam;
  452. DWORD dwSyncScheduleFlags;
  453. PICKSCHED_LIST_DATA *psld = NULL;
  454. ASSERT(NULL != pSyncSchedule);
  455. if (SUCCEEDED(pSyncSchedule->GetFlags(&dwSyncScheduleFlags)))
  456. {
  457. // This checks to make sure we only add a publisher's schedule to the
  458. // list if it belongs to this item.
  459. if ((!(dwSyncScheduleFlags & SYNCSCHEDINFO_FLAGS_READONLY)) ||
  460. (*pSchedCookie == psed->customSchedule))
  461. {
  462. psld = new PICKSCHED_LIST_DATA;
  463. if (NULL != psld)
  464. {
  465. WCHAR wszName[MAX_PATH];
  466. DWORD cchName = ARRAYSIZE(wszName);
  467. if (SUCCEEDED(pSyncSchedule->GetScheduleName(&cchName, wszName)))
  468. {
  469. TCHAR szName[MAX_PATH];
  470. MyOleStrToStrN(szName, ARRAYSIZE(szName), wszName);
  471. psed->bHasAtLeastOneSchedule = TRUE;
  472. psld->SchedCookie = *pSchedCookie;
  473. int index;
  474. if (*pSchedCookie == psed->customSchedule)
  475. {
  476. index = ComboBox_InsertString(psed->hwndSchedList, 0, szName);
  477. if ((index >= 0) && (psed->defSchedule == GUID_NULL))
  478. {
  479. // Do this always for custom schedules if there
  480. // is no defSchedule set
  481. *psed->pnDefaultSelection = index;
  482. psed->bFoundCustomSchedule = TRUE;
  483. }
  484. }
  485. else
  486. {
  487. index = ComboBox_AddString(psed->hwndSchedList, szName);
  488. }
  489. if (index >= 0)
  490. {
  491. bAdded = (ComboBox_SetItemData(psed->hwndSchedList, index, psld) != CB_ERR);
  492. if ((psed->defSchedule == *pSchedCookie)
  493. ||
  494. ((-1 == *psed->pnDefaultSelection) &&
  495. IsCookieOnSchedule(pSyncSchedule, &psed->pBuf->m_Cookie)))
  496. {
  497. *psed->pnDefaultSelection = index;
  498. }
  499. }
  500. }
  501. }
  502. }
  503. }
  504. if (!bAdded)
  505. {
  506. SAFEDELETE(psld);
  507. }
  508. return TRUE;
  509. }
  510. BOOL PickSched_FillSchedList(HWND hDlg, POOEBuf pBuf, int *pnDefaultSelection)
  511. {
  512. PICKSCHED_ENUM_DATA sed;
  513. sed.hwndSchedList = GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_LIST);
  514. sed.pBuf = pBuf;
  515. sed.customSchedule = GUID_NULL;
  516. sed.pnDefaultSelection = pnDefaultSelection;
  517. sed.bHasAtLeastOneSchedule = FALSE;
  518. sed.bFoundCustomSchedule = FALSE;
  519. sed.defSchedule = pBuf->groupCookie; // usually GUID_NULL, but if the user hits
  520. // customize multiple times, he/she would
  521. // expect it to be highlighted
  522. EnumSchedules(PickSched_EnumCallback, (LPARAM)&sed);
  523. if (!sed.bFoundCustomSchedule && pBuf->bChannel &&
  524. (sizeof(TASK_TRIGGER) == pBuf->m_Trigger.cbTriggerSize))
  525. {
  526. // This item has a custom schedule but it isn't an existing
  527. // schedule (actually, this is the normal case). We now
  528. // have to add a fake entry.
  529. PICKSCHED_LIST_DATA *psld = new PICKSCHED_LIST_DATA;
  530. if (NULL != psld)
  531. {
  532. TCHAR szSchedName[MAX_PATH];
  533. BOOL bAdded = FALSE;
  534. CreatePublisherScheduleName(szSchedName, ARRAYSIZE(szSchedName),
  535. pBuf->m_Name, NULL);
  536. int index = ComboBox_InsertString(sed.hwndSchedList, 0, szSchedName);
  537. if (index >= 0)
  538. {
  539. bAdded = (ComboBox_SetItemData(sed.hwndSchedList, index, psld) != CB_ERR);
  540. sed.bHasAtLeastOneSchedule = TRUE;
  541. *pnDefaultSelection = index;
  542. }
  543. if (!bAdded)
  544. {
  545. delete psld;
  546. }
  547. }
  548. }
  549. return sed.bHasAtLeastOneSchedule;
  550. }
  551. PICKSCHED_LIST_DATA *PickSchedList_GetData(HWND hwndSchedList, int index)
  552. {
  553. PICKSCHED_LIST_DATA *psld = NULL;
  554. if (index < 0)
  555. {
  556. index = ComboBox_GetCurSel(hwndSchedList);
  557. }
  558. if (index >= 0)
  559. {
  560. psld = (PICKSCHED_LIST_DATA *)ComboBox_GetItemData(hwndSchedList, index);
  561. if (psld == (PICKSCHED_LIST_DATA *)CB_ERR)
  562. {
  563. psld = NULL;
  564. }
  565. }
  566. return psld;
  567. }
  568. void PickSchedList_FreeAllData(HWND hwndSchedList)
  569. {
  570. int count = ComboBox_GetCount(hwndSchedList);
  571. for (int i = 0; i < count; i++)
  572. {
  573. PICKSCHED_LIST_DATA *psld = PickSchedList_GetData(hwndSchedList, i);
  574. if (NULL != psld)
  575. {
  576. delete psld;
  577. }
  578. }
  579. }
  580. INT_PTR CALLBACK PickScheduleDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  581. {
  582. LPPROPSHEETPAGE lpPropSheet =(LPPROPSHEETPAGE)GetWindowLongPtr(hDlg, DWLP_USER);
  583. WizInfo *pWiz = lpPropSheet ? (WizInfo *)lpPropSheet->lParam : NULL;
  584. POOEBuf pBuf = pWiz ? pWiz->pOOE : NULL;
  585. NMHDR FAR *lpnm;
  586. BOOL result = FALSE;
  587. switch (message)
  588. {
  589. case WM_INITDIALOG:
  590. {
  591. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  592. lpPropSheet = (LPPROPSHEETPAGE)lParam;
  593. pWiz = (WizInfo *)lpPropSheet->lParam;
  594. int nDefaultSelection = -1;
  595. BOOL bHaveSchedules = PickSched_FillSchedList(hDlg, pWiz->pOOE,
  596. &nDefaultSelection);
  597. BOOL bNoScheduledUpdates = SHRestricted2W(REST_NoScheduledUpdates, NULL, 0);
  598. int defID = IDC_WIZ_SCHEDULE_NONE;
  599. if (!bHaveSchedules)
  600. {
  601. ShowWindow(GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_EXISTING), SW_HIDE);
  602. ShowWindow(GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_LIST), SW_HIDE);
  603. }
  604. else if (!bNoScheduledUpdates)
  605. {
  606. if (-1 == nDefaultSelection)
  607. {
  608. // This item isn't on any schedule yet
  609. nDefaultSelection = 0;
  610. }
  611. else
  612. {
  613. // This item is on at least one schedule
  614. defID = IDC_WIZ_SCHEDULE_EXISTING;
  615. }
  616. ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_LIST),
  617. nDefaultSelection);
  618. }
  619. CheckRadioButton(hDlg, IDC_WIZ_SCHEDULE_NONE, IDC_WIZ_SCHEDULE_EXISTING,
  620. defID);
  621. ASSERT(NULL != lpPropSheet);
  622. ASSERT(NULL != pWiz);
  623. if (bNoScheduledUpdates)
  624. {
  625. EnableWindow(GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_NEW), FALSE);
  626. EnableWindow(GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_EXISTING), FALSE);
  627. EnableWindow(GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_LIST), FALSE);
  628. }
  629. else if (SHRestricted2(REST_NoEditingScheduleGroups, NULL, 0))
  630. {
  631. EnableWindow(GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_NEW), FALSE);
  632. }
  633. HandleScheduleButtons(hDlg, lpPropSheet, pWiz);
  634. result = TRUE;
  635. break;
  636. }
  637. case WM_DESTROY:
  638. PickSchedList_FreeAllData(GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_LIST));
  639. break;
  640. case WM_COMMAND:
  641. switch (LOWORD(wParam))
  642. {
  643. case IDC_WIZ_SCHEDULE_EXISTING:
  644. case IDC_WIZ_SCHEDULE_NEW:
  645. case IDC_WIZ_SCHEDULE_NONE:
  646. ASSERT(NULL != lpPropSheet);
  647. ASSERT(NULL != pWiz);
  648. HandleScheduleButtons(hDlg, lpPropSheet, pWiz);
  649. result = TRUE;
  650. break;
  651. }
  652. break;
  653. case WM_NOTIFY:
  654. lpnm = (NMHDR FAR *)lParam;
  655. switch (lpnm->code)
  656. {
  657. case PSN_SETACTIVE:
  658. ASSERT(NULL != lpPropSheet);
  659. ASSERT(NULL != pWiz);
  660. SetWizButtons(hDlg, (INT_PTR) lpPropSheet->pszTemplate, pWiz);
  661. result = TRUE;
  662. break;
  663. case PSN_WIZNEXT:
  664. case PSN_WIZFINISH:
  665. if (IsDlgButtonChecked(hDlg, IDC_WIZ_SCHEDULE_NONE) && NULL != pBuf)
  666. {
  667. pBuf->groupCookie = NOTFCOOKIE_SCHEDULE_GROUP_MANUAL;
  668. }
  669. else if (IsDlgButtonChecked(hDlg, IDC_WIZ_SCHEDULE_EXISTING))
  670. {
  671. PICKSCHED_LIST_DATA *psld =
  672. PickSchedList_GetData(GetDlgItem(hDlg, IDC_WIZ_SCHEDULE_LIST), -1);
  673. if (NULL != psld && NULL != pBuf)
  674. {
  675. pBuf->groupCookie = psld->SchedCookie;
  676. }
  677. }
  678. result = TRUE;
  679. break;
  680. }
  681. break;
  682. }
  683. return result;
  684. }
  685. BOOL NewSchedWiz_ResolveNameConflict(HWND hDlg, POOEBuf pBuf)
  686. {
  687. BOOL bResult = TRUE;
  688. if (!(pBuf->m_dwPropSheetFlags & PSF_NO_CHECK_SCHED_CONFLICT))
  689. {
  690. bResult = NewSched_ResolveNameConflictHelper(hDlg, &pBuf->m_Trigger,
  691. &pBuf->groupCookie);
  692. }
  693. if (bResult)
  694. {
  695. pBuf->m_dwPropSheetFlags |= PSF_NO_CHECK_SCHED_CONFLICT;
  696. }
  697. return bResult;
  698. }
  699. inline void NewSchedWiz_CreateSchedule(HWND hDlg, POOEBuf pBuf)
  700. {
  701. ASSERT(pBuf->m_dwPropSheetFlags & PSF_NO_CHECK_SCHED_CONFLICT);
  702. NewSched_CreateScheduleHelper(hDlg, &pBuf->m_Trigger,
  703. &pBuf->groupCookie);
  704. }
  705. INT_PTR CALLBACK NewScheduleWizDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  706. {
  707. LPPROPSHEETPAGE lpPropSheet =(LPPROPSHEETPAGE)GetWindowLongPtr(hDlg, DWLP_USER);
  708. WizInfo *pWiz = lpPropSheet ? (WizInfo *)lpPropSheet->lParam : NULL;
  709. POOEBuf pBuf = pWiz ? pWiz->pOOE : NULL;
  710. NMHDR *lpnm;
  711. BOOL result = FALSE;
  712. switch (message)
  713. {
  714. case WM_INITDIALOG:
  715. {
  716. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  717. NewSched_OnInitDialogHelper(hDlg);
  718. pWiz = (WizInfo *)((LPPROPSHEETPAGE)lParam)->lParam;
  719. pBuf = pWiz->pOOE;
  720. pBuf->hwndNewSchedDlg = hDlg;
  721. result = TRUE;
  722. break;
  723. }
  724. case WM_COMMAND:
  725. if (NULL != pBuf)
  726. {
  727. switch (LOWORD(wParam))
  728. {
  729. case IDC_SCHEDULE_DAYS:
  730. if (HIWORD(wParam) == EN_UPDATE)
  731. {
  732. if (LOWORD(wParam) == IDC_SCHEDULE_DAYS)
  733. {
  734. KeepSpinNumberInRange(hDlg, IDC_SCHEDULE_DAYS,
  735. IDC_SCHEDULE_DAYS_SPIN, 1, 99);
  736. pBuf->m_dwPropSheetFlags &= ~PSF_NO_CHECK_SCHED_CONFLICT;
  737. result = TRUE;
  738. }
  739. }
  740. break;
  741. case IDC_SCHEDULE_NAME:
  742. if (HIWORD(wParam) == EN_CHANGE)
  743. {
  744. pBuf->m_dwPropSheetFlags &= ~PSF_NO_CHECK_SCHED_CONFLICT;
  745. result = TRUE;
  746. }
  747. break;
  748. }
  749. }
  750. break;
  751. case WM_NOTIFY:
  752. lpnm = (NMHDR FAR *)lParam;
  753. switch (lpnm->code)
  754. {
  755. case PSN_SETACTIVE:
  756. ASSERT(NULL != lpPropSheet);
  757. ASSERT(NULL != pWiz);
  758. if (!pWiz->bIsNewSchedule)
  759. {
  760. // If the user didn't pick a new schedule, move on
  761. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, -1);
  762. }
  763. else
  764. {
  765. SetWizButtons(hDlg, (INT_PTR) lpPropSheet->pszTemplate, pWiz);
  766. }
  767. result = TRUE;
  768. break;
  769. case PSN_KILLACTIVE:
  770. result = TRUE;
  771. break;
  772. case PSN_WIZNEXT:
  773. if (!NewSchedWiz_ResolveNameConflict(hDlg, pBuf))
  774. {
  775. // Don't proceed
  776. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
  777. }
  778. result = TRUE;
  779. break;
  780. case PSN_WIZFINISH:
  781. if (NewSchedWiz_ResolveNameConflict(hDlg, pBuf))
  782. {
  783. NewSchedWiz_CreateSchedule(hDlg, pBuf);
  784. }
  785. else
  786. {
  787. // Don't proceed
  788. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
  789. }
  790. result = TRUE;
  791. break;
  792. }
  793. break;
  794. }
  795. return result;
  796. }
  797. void Login_EnableControls(HWND hDlg, BOOL bEnable)
  798. {
  799. int IDs[] = {
  800. IDC_USERNAME_LABEL,
  801. IDC_USERNAME,
  802. IDC_PASSWORD_LABEL,
  803. IDC_PASSWORD,
  804. IDC_PASSWORDCONFIRM_LABEL,
  805. IDC_PASSWORDCONFIRM
  806. };
  807. for (int i = 0; i < ARRAYSIZE(IDs); i++)
  808. {
  809. EnableWindow(GetDlgItem(hDlg, IDs[i]), bEnable);
  810. }
  811. }
  812. INT_PTR CALLBACK LoginDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  813. {
  814. LPPROPSHEETPAGE lpPropSheet =(LPPROPSHEETPAGE)GetWindowLongPtr(hDlg, DWLP_USER);
  815. WizInfo *pWiz = lpPropSheet ? (WizInfo *)lpPropSheet->lParam : NULL;
  816. POOEBuf pBuf = pWiz ? pWiz->pOOE : NULL;
  817. NMHDR FAR *lpnm;
  818. BOOL result = FALSE;
  819. switch (message)
  820. {
  821. case WM_INITDIALOG:
  822. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  823. lpPropSheet = (LPPROPSHEETPAGE)lParam;
  824. pWiz = (WizInfo *)lpPropSheet->lParam;
  825. pBuf = pWiz->pOOE;
  826. if (pBuf->bChannel)
  827. {
  828. ShowWindow(GetDlgItem(hDlg, IDC_PASSWORD_NO), SW_HIDE);
  829. ShowWindow(GetDlgItem(hDlg, IDC_PASSWORD_YES), SW_HIDE);
  830. ShowWindow(GetDlgItem(hDlg, IDC_LOGIN_PROMPT_URL), SW_HIDE);
  831. }
  832. else
  833. {
  834. CheckRadioButton(hDlg, IDC_PASSWORD_NO, IDC_PASSWORD_YES,
  835. (((pBuf->username[0] == 0) && (pBuf->password[0] == 0)) ?
  836. IDC_PASSWORD_NO : IDC_PASSWORD_YES));
  837. ShowWindow(GetDlgItem(hDlg, IDC_LOGIN_PROMPT), SW_HIDE);
  838. ShowWindow(GetDlgItem(hDlg, IDC_LOGIN_PROMPT_CHANNEL), SW_HIDE);
  839. }
  840. Edit_LimitText(GetDlgItem(hDlg, IDC_USERNAME), ARRAYSIZE(pBuf->username) - 1);
  841. SetDlgItemText(hDlg, IDC_USERNAME, pBuf->username);
  842. Edit_LimitText(GetDlgItem(hDlg, IDC_PASSWORD), ARRAYSIZE(pBuf->password) - 1);
  843. SetDlgItemText(hDlg, IDC_PASSWORD, pBuf->password);
  844. Edit_LimitText(GetDlgItem(hDlg, IDC_PASSWORDCONFIRM), ARRAYSIZE(pBuf->password) - 1);
  845. SetDlgItemText(hDlg, IDC_PASSWORDCONFIRM, pBuf->password);
  846. Login_EnableControls(hDlg, (IsDlgButtonChecked(hDlg, IDC_PASSWORD_YES) || pBuf->bChannel));
  847. result = TRUE;
  848. break;
  849. case WM_COMMAND:
  850. switch (LOWORD(wParam))
  851. {
  852. case IDC_PASSWORD_YES:
  853. case IDC_PASSWORD_NO:
  854. if (BN_CLICKED == HIWORD(wParam))
  855. {
  856. Login_EnableControls(hDlg, IsDlgButtonChecked(hDlg, IDC_PASSWORD_YES));
  857. result = TRUE;
  858. }
  859. break;
  860. }
  861. break;
  862. case WM_NOTIFY:
  863. lpnm = (NMHDR FAR *)lParam;
  864. switch (lpnm->code)
  865. {
  866. case PSN_SETACTIVE:
  867. ASSERT(NULL != lpPropSheet);
  868. ASSERT(NULL != pWiz);
  869. SetWizButtons(hDlg, (INT_PTR) lpPropSheet->pszTemplate, pWiz);
  870. result = TRUE;
  871. break;
  872. case PSN_WIZFINISH:
  873. {
  874. BOOL bFinishOK = TRUE;
  875. if (pBuf)
  876. {
  877. if (pBuf->bChannel || IsDlgButtonChecked(hDlg, IDC_PASSWORD_YES))
  878. {
  879. TCHAR szUsername[ARRAYSIZE(pBuf->username) + 1];
  880. TCHAR szPassword[ARRAYSIZE(pBuf->password) + 1];
  881. TCHAR szPasswordConfirm[ARRAYSIZE(pBuf->password) + 1];
  882. GetDlgItemText(hDlg, IDC_USERNAME, szUsername, ARRAYSIZE(szUsername));
  883. GetDlgItemText(hDlg, IDC_PASSWORD, szPassword, ARRAYSIZE(szPassword));
  884. GetDlgItemText(hDlg, IDC_PASSWORDCONFIRM, szPasswordConfirm, ARRAYSIZE(szPasswordConfirm));
  885. if (!szUsername[0] && (szPassword[0] || szPasswordConfirm[0]))
  886. {
  887. SGMessageBox(hDlg,
  888. (pBuf->bChannel ? IDS_NEEDCHANNELUSERNAME : IDS_NEEDUSERNAME),
  889. MB_ICONWARNING);
  890. bFinishOK = FALSE;
  891. }
  892. else if (szUsername[0] && !szPassword[0])
  893. {
  894. SGMessageBox(hDlg,
  895. (pBuf->bChannel ? IDS_NEEDCHANNELPASSWORD : IDS_NEEDPASSWORD),
  896. MB_ICONWARNING);
  897. bFinishOK = FALSE;
  898. }
  899. else if (StrCmp(szPassword, szPasswordConfirm) != 0)
  900. {
  901. SGMessageBox(hDlg, IDS_MISMATCHED_PASSWORDS, MB_ICONWARNING);
  902. bFinishOK = FALSE;
  903. }
  904. else
  905. {
  906. StrCpyN(pBuf->username, szUsername, ARRAYSIZE(pBuf->username));
  907. StrCpyN(pBuf->password, szPassword, ARRAYSIZE(pBuf->password));
  908. pBuf->dwFlags |= (PROP_WEBCRAWL_UNAME | PROP_WEBCRAWL_PSWD);
  909. }
  910. }
  911. if (!bFinishOK)
  912. {
  913. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
  914. }
  915. else if (pWiz->bIsNewSchedule)
  916. {
  917. NewSchedWiz_CreateSchedule(pBuf->hwndNewSchedDlg, pBuf);
  918. }
  919. result = TRUE;
  920. }
  921. break;
  922. }
  923. }
  924. }
  925. return result;
  926. }