Source code of Windows XP (NT5)
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.

2011 lines
60 KiB

  1. #include "private.h"
  2. #include "offl_cpp.h"
  3. #include "propshts.h"
  4. #include "subsmgrp.h"
  5. #include <iehelpid.h>
  6. #include <mluisupp.h>
  7. #define INITGUID
  8. #include <initguid.h>
  9. #include "imnact.h"
  10. #include "helper.h"
  11. void WriteDefaultEmail(LPTSTR szBuf);
  12. void WriteDefaultSMTPServer(LPTSTR szBuf);
  13. const TCHAR c_szDefEmail[] = TEXT("DefaultEmail");
  14. const TCHAR c_szDefServer[] = TEXT("DefaultSMTPServer");
  15. TCHAR c_szHelpFile[] = TEXT("iexplore.hlp");
  16. struct NEWSCHED_DATA
  17. {
  18. SYNCSCHEDULECOOKIE SchedCookie;
  19. TCHAR szSchedName[MAX_PATH];
  20. };
  21. #define MIN_DOWNLOAD_K 50
  22. #define MAX_DOWNLOAD_K UD_MAXVAL
  23. #define DEF_DOWNLOAD_K 500
  24. DWORD aHelpIDs[] = {
  25. // Schedule page
  26. IDC_SCHEDULE_TEXT, IDH_GROUPBOX,
  27. IDC_MANUAL_SYNC, IDH_SUBPROPS_SCHEDTAB_MANUAL_SCHEDULE,
  28. IDC_SCHEDULED_SYNC, IDH_SUBPROPS_SCHEDTAB_CUSTOM_SCHEDULE,
  29. IDC_SCHEDULE_LIST, IDH_SUBPROPS_SCHEDTAB_SCHEDDESC,
  30. IDC_SCHEDULE_NEW, IDH_NEW_OFFLINE_SCHED,
  31. IDC_SCHEDULE_EDIT, IDH_EDIT_OFFLINE_SCHED,
  32. IDC_SCHEDULE_REMOVE, IDH_REMOVE_OFFLINE_SCHED,
  33. // IDC_IDLE_ONLY, IDH_SUBPROPS_SCHED_DONTUPDATE,
  34. // Download page
  35. IDC_CONTENT_GROUPBOX, IDH_GROUPBOX,
  36. IDC_DOWNLOAD_PAGES_LABEL1, IDH_SUBPROPS_RECTAB_ADVOPTS_DOWNLOAD_PAGES_DEEP,
  37. IDC_LEVELS, IDH_SUBPROPS_RECTAB_ADVOPTS_DOWNLOAD_PAGES_DEEP,
  38. IDC_LEVELS_SPIN, IDH_SUBPROPS_RECTAB_ADVOPTS_DOWNLOAD_PAGES_DEEP,
  39. IDC_DOWNLOAD_PAGES_LABEL2, IDH_SUBPROPS_RECTAB_ADVOPTS_DOWNLOAD_PAGES_DEEP,
  40. IDC_FOLLOW_LINKS, IDH_SUBPROPS_RECTAB_ADVOPTS_FOLLOW_LINKS,
  41. IDC_LIMIT_SPACE_CHECK, IDH_SUBPROPS_RECTAB_ADVOPTS_MAX_DOWNLOAD,
  42. IDC_LIMIT_SPACE_EDIT, IDH_SUBPROPS_RECTAB_ADVOPTS_MAX_DOWNLOAD,
  43. IDC_LIMIT_SPACE_SPIN, IDH_SUBPROPS_RECTAB_ADVOPTS_MAX_DOWNLOAD,
  44. IDC_LIMIT_SPACE_TEXT, IDH_SUBPROPS_RECTAB_ADVOPTS_MAX_DOWNLOAD,
  45. IDC_ADVANCED, IDH_SUBPROPS_RECTAB_ADVANCED,
  46. IDC_EMAIL_GROUPBOX, IDH_SUBPROPS_RECTAB_EMAIL_NOTIFICATION,
  47. IDC_EMAIL_NOTIFY, IDH_SUBPROPS_RECTAB_EMAIL_NOTIFICATION,
  48. IDC_EMAIL_ADDRESS_TEXT, IDH_SUBPROPS_RECTAB_MAILOPTS_EMAIL_ADDRESS,
  49. IDC_EMAIL_ADDRESS, IDH_SUBPROPS_RECTAB_MAILOPTS_EMAIL_ADDRESS,
  50. IDC_EMAIL_SERVER_TEXT, IDH_SUBPROPS_RECTAB_MAILOPTS_EMAIL_SERVER,
  51. IDC_EMAIL_SERVER, IDH_SUBPROPS_RECTAB_MAILOPTS_EMAIL_SERVER,
  52. IDC_LOGIN_LABEL, IDH_SUBPROPS_RECTAB_CHANNEL_LOGIN,
  53. IDC_LOGIN, IDH_SUBPROPS_RECTAB_CHANNEL_LOGIN,
  54. IDC_DOWNLOAD_ALL, IDH_CHANNEL_DOWNLOAD_ALL,
  55. IDC_DOWNLOAD_MIN, IDH_CHANNEL_DOWNLOAD_COVER_N_TOC,
  56. // Advanced popup
  57. IDC_ADVANCED_GROUPBOX, IDH_GROUPBOX,
  58. IDC_DOWNLOAD_IMAGES, IDH_SUBPROPS_RECTAB_ADVOPTS_DOWNLOAD_IMAGES,
  59. IDC_DOWNLOAD_MEDIA, IDH_SUBPROPS_RECTAB_ADVOPTS_DOWNLOAD_SOUND,
  60. IDC_DOWNLOAD_APPLETS, IDH_SUBPROPS_RECTAB_ADVOPTS_DOWNLOAD_ACTIVEX,
  61. IDC_DOWNLOAD_ONLY_HTML_LINKS, IDH_SUBPROPS_RECTAB_ADVOPTS_ONLY_HTML_LINKS,
  62. // Login popup
  63. IDC_USERNAME_LABEL, IDH_SUBPROPS_RECTAB_LOGINOPTS_USER_ID,
  64. IDC_USERNAME, IDH_SUBPROPS_RECTAB_LOGINOPTS_USER_ID,
  65. IDC_PASSWORD_LABEL, IDH_SUBPROPS_RECTAB_LOGINOPTS_PASSWORD,
  66. IDC_PASSWORD, IDH_SUBPROPS_RECTAB_LOGINOPTS_PASSWORD,
  67. IDC_PASSWORDCONFIRM_LABEL, IDH_SUBPROPS_RECTAB_LOGINOPTS_PASSWORD_CONFIRM,
  68. IDC_PASSWORDCONFIRM, IDH_SUBPROPS_RECTAB_LOGINOPTS_PASSWORD_CONFIRM,
  69. // New schedule popup
  70. IDC_SCHEDULE_LABEL1, IDH_NEWSCHED_EVERY_AT_TIME,
  71. IDC_SCHEDULE_DAYS, IDH_NEWSCHED_EVERY_AT_TIME,
  72. IDC_SCHEDULE_DAYS_SPIN, IDH_NEWSCHED_EVERY_AT_TIME,
  73. IDC_SCHEDULE_LABEL2, IDH_NEWSCHED_EVERY_AT_TIME,
  74. IDC_SCHEDULE_TIME, IDH_NEWSCHED_EVERY_AT_TIME,
  75. IDC_SCHEDULE_NAME_TEXT, IDH_NEWSCHED_NAME,
  76. IDC_SCHEDULE_NAME, IDH_NEWSCHED_NAME,
  77. IDC_SCHEDULE_LABEL3, IDH_NEWSCHED_EVERY_AT_TIME,
  78. IDC_WIZ_SCHEDULE_AUTOCONNECT, IDH_SUBPROPS_NEW_SCHEDULE_AUTOCONNECT,
  79. // Summary page
  80. IDC_NAME, IDH_SUBPROPS_SUBTAB_SUBSCRIBED_NAME,
  81. IDC_URL_TEXT, IDH_SUBPROPS_SUBTAB_SUBSCRIBED_URL,
  82. IDC_URL, IDH_SUBPROPS_SUBTAB_SUBSCRIBED_URL,
  83. IDC_VISITS_TEXT, IDH_WEBDOC_VISITS,
  84. IDC_VISITS, IDH_WEBDOC_VISITS,
  85. IDC_MAKE_OFFLINE, IDH_MAKE_AVAIL_OFFLINE,
  86. IDC_SUMMARY, IDH_GROUPBOX,
  87. IDC_LAST_SYNC_TEXT, IDH_SUBPROPS_SUBTAB_LAST,
  88. IDC_LAST_SYNC, IDH_SUBPROPS_SUBTAB_LAST,
  89. IDC_DOWNLOAD_SIZE_TEXT, IDH_SUBPROPS_DLSIZE,
  90. IDC_DOWNLOAD_SIZE, IDH_SUBPROPS_DLSIZE,
  91. IDC_DOWNLOAD_RESULT_TEXT, IDH_SUBPROPS_SUBTAB_RESULT,
  92. IDC_DOWNLOAD_RESULT, IDH_SUBPROPS_SUBTAB_RESULT,
  93. // dah end
  94. 0, 0
  95. };
  96. /********************************************************************************
  97. Property sheet helpers
  98. *********************************************************************************/
  99. inline POOEBuf GetBuf(HWND hdlg)
  100. {
  101. POOEBuf pBuf = (POOEBuf) GetWindowLongPtr(hdlg, DWLP_USER);
  102. return pBuf;
  103. }
  104. void EnableControls(HWND hdlg, const int *pIDs, int nIDs, BOOL bEnable)
  105. {
  106. for (int i = 0; i < nIDs; i++)
  107. {
  108. EnableWindow(GetDlgItem(hdlg, *pIDs++), bEnable);
  109. }
  110. }
  111. /********************************************************************************
  112. Summary property sheet code
  113. *********************************************************************************/
  114. inline POOEBuf Summary_GetBuf(HWND hdlg)
  115. {
  116. CSubscriptionMgr *pSubsMgr = (CSubscriptionMgr*) GetWindowLongPtr(hdlg, DWLP_USER);
  117. ASSERT(NULL != pSubsMgr);
  118. return (NULL != pSubsMgr) ? pSubsMgr->m_pBuf : NULL;
  119. }
  120. void Summary_ShowOfflineSummary(HWND hdlg, POOEBuf pBuf, BOOL bShow)
  121. {
  122. static const int offSumIDs[] =
  123. {
  124. IDC_SUMMARY,
  125. IDC_LAST_SYNC_TEXT,
  126. IDC_LAST_SYNC,
  127. IDC_DOWNLOAD_SIZE_TEXT,
  128. IDC_DOWNLOAD_SIZE,
  129. IDC_DOWNLOAD_RESULT,
  130. IDC_DOWNLOAD_RESULT_TEXT,
  131. IDC_FREESPACE_TEXT
  132. };
  133. if (bShow)
  134. {
  135. TCHAR szLastSync[128];
  136. TCHAR szDownloadSize[128];
  137. TCHAR szDownloadResult[128];
  138. MLLoadString(IDS_VALUE_UNKNOWN, szLastSync, ARRAYSIZE(szLastSync));
  139. StrCpyN(szDownloadSize, szLastSync, ARRAYSIZE(szDownloadSize));
  140. StrCpyN(szDownloadResult, szLastSync, ARRAYSIZE(szDownloadResult));
  141. ISubscriptionItem *psi;
  142. if (SUCCEEDED(SubscriptionItemFromCookie(FALSE, &pBuf->m_Cookie, &psi)))
  143. {
  144. enum { spLastSync, spDownloadSize, spDownloadResult };
  145. static const LPCWSTR pProps[] =
  146. {
  147. c_szPropCompletionTime,
  148. c_szPropCrawlActualSize,
  149. c_szPropStatusString
  150. };
  151. VARIANT vars[ARRAYSIZE(pProps)];
  152. if (SUCCEEDED(psi->ReadProperties(ARRAYSIZE(pProps), pProps, vars)))
  153. {
  154. if (VT_DATE == vars[spLastSync].vt)
  155. {
  156. FILETIME ft, ft2;
  157. DWORD dwFlags = FDTF_DEFAULT;
  158. VariantTimeToFileTime(vars[spLastSync].date, ft);
  159. LocalFileTimeToFileTime(&ft, &ft2);
  160. SHFormatDateTime(&ft2, &dwFlags, szLastSync, ARRAYSIZE(szLastSync));
  161. }
  162. if (VT_I4 == vars[spDownloadSize].vt)
  163. {
  164. StrFormatByteSize(vars[spDownloadSize].lVal * 1024,
  165. szDownloadSize, ARRAYSIZE(szDownloadSize));
  166. }
  167. if (VT_BSTR == vars[spDownloadResult].vt)
  168. {
  169. #ifdef UNICODE
  170. wnsprintf(szDownloadResult, ARRAYSIZE(szDownloadResult),
  171. TEXT("%s"), vars[spDownloadResult].bstrVal);
  172. #else
  173. wnsprintf(szDownloadResult, ARRAYSIZE(szDownloadResult),
  174. TEXT("%S"), vars[spDownloadResult].bstrVal);
  175. #endif
  176. }
  177. for (int i = 0; i < ARRAYSIZE(pProps); i++)
  178. {
  179. VariantClear(&vars[i]);
  180. }
  181. }
  182. psi->Release();
  183. }
  184. SetDlgItemText(hdlg, IDC_LAST_SYNC, szLastSync);
  185. SetDlgItemText(hdlg, IDC_DOWNLOAD_SIZE, szDownloadSize);
  186. SetDlgItemText(hdlg, IDC_DOWNLOAD_RESULT, szDownloadResult);
  187. }
  188. for (int i = 0; i < ARRAYSIZE(offSumIDs); i++)
  189. {
  190. ShowWindow(GetDlgItem(hdlg, offSumIDs[i]), bShow ? SW_SHOW : SW_HIDE);
  191. }
  192. }
  193. BOOL Summary_AddPageCallback(HPROPSHEETPAGE hpage, LPARAM lParam)
  194. {
  195. return PropSheet_AddPage((HWND)lParam, hpage) ? TRUE : FALSE;
  196. }
  197. BOOL Summary_OnCommand(HWND hdlg, WORD wNotifyCode, WORD wID, HWND hwndCtl)
  198. {
  199. BOOL bResult = FALSE;
  200. BOOL bChanged = FALSE;
  201. POOEBuf pBuf = Summary_GetBuf(hdlg);
  202. switch (wID)
  203. {
  204. case IDC_MAKE_OFFLINE:
  205. if (BN_CLICKED == wNotifyCode)
  206. {
  207. CSubscriptionMgr *pSubsMgr = (CSubscriptionMgr*) GetWindowLongPtr(hdlg, DWLP_USER);
  208. BOOL bShow = IsDlgButtonChecked(hdlg, IDC_MAKE_OFFLINE);
  209. Summary_ShowOfflineSummary(hdlg, pBuf, bShow);
  210. if (NULL != pSubsMgr)
  211. {
  212. if (bShow)
  213. {
  214. pSubsMgr->AddPages(Summary_AddPageCallback, (LPARAM)GetParent(hdlg));
  215. }
  216. else
  217. {
  218. pSubsMgr->RemovePages(GetParent(hdlg));
  219. }
  220. }
  221. bChanged = TRUE;
  222. }
  223. bResult = TRUE;
  224. break;
  225. }
  226. if (bChanged)
  227. {
  228. PropSheet_Changed(GetParent(hdlg), hdlg);
  229. }
  230. return bResult;
  231. }
  232. BOOL Summary_OnNotify(HWND hdlg, int idCtrl, LPNMHDR pnmh)
  233. {
  234. BOOL bResult = TRUE;
  235. switch (pnmh->code)
  236. {
  237. case PSN_APPLY:
  238. {
  239. CSubscriptionMgr *pSubsMgr = (CSubscriptionMgr*) GetWindowLongPtr(hdlg, DWLP_USER);
  240. POOEBuf pBuf = Summary_GetBuf(hdlg);
  241. ASSERT(NULL != pSubsMgr);
  242. ASSERT(NULL != pBuf);
  243. if ((NULL != pSubsMgr) && (NULL != pBuf))
  244. {
  245. if (IsDlgButtonChecked(hdlg, IDC_MAKE_OFFLINE))
  246. {
  247. pBuf->dwFlags = PROP_WEBCRAWL_ALL;
  248. SaveBufferChange(pBuf, TRUE);
  249. }
  250. else
  251. {
  252. WCHAR wszURL[INTERNET_MAX_URL_LENGTH];
  253. MyStrToOleStrN(wszURL, ARRAYSIZE(wszURL), pBuf->m_URL);
  254. pSubsMgr->DeleteSubscription(wszURL, NULL);
  255. }
  256. }
  257. break;
  258. }
  259. default:
  260. bResult = FALSE;
  261. break;
  262. }
  263. return bResult;
  264. }
  265. BOOL Summary_OnInitDialog(HWND hdlg, HWND hwndFocus, LPARAM lParam)
  266. {
  267. ASSERT(NULL != ((LPPROPSHEETPAGE)lParam));
  268. ASSERT(NULL != ((LPPROPSHEETPAGE)lParam)->lParam);
  269. SetWindowLongPtr(hdlg, DWLP_USER, ((LPPROPSHEETPAGE)lParam)->lParam);
  270. // Now read in values and populate the dialog
  271. POOEBuf pBuf = Summary_GetBuf(hdlg);
  272. ISubscriptionItem *psi;
  273. HICON hicon;
  274. BOOL bSubscribed;
  275. HRESULT hr = SubscriptionItemFromCookie(FALSE, &pBuf->m_Cookie, &psi);
  276. if (SUCCEEDED(hr))
  277. {
  278. bSubscribed = TRUE;
  279. hicon = LoadItemIcon(psi, TRUE);
  280. psi->Release();
  281. }
  282. else
  283. {
  284. bSubscribed = FALSE;
  285. hicon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_WEBDOC));
  286. }
  287. SendDlgItemMessage(hdlg, IDC_ICONEX2, STM_SETICON, (WPARAM)hicon, 0);
  288. if ((!IsHTTPPrefixed(pBuf->m_URL)) ||
  289. (bSubscribed && SHRestricted2(REST_NoRemovingSubscriptions, pBuf->m_URL, 0)) ||
  290. (!bSubscribed && SHRestricted2(REST_NoAddingSubscriptions, pBuf->m_URL, 0)))
  291. {
  292. EnableWindow(GetDlgItem(hdlg, IDC_MAKE_OFFLINE), FALSE);
  293. }
  294. SetDlgItemText(hdlg, IDC_NAME, pBuf->m_Name);
  295. SetDlgItemText(hdlg, IDC_URL, pBuf->m_URL);
  296. CheckDlgButton(hdlg, IDC_MAKE_OFFLINE, bSubscribed);
  297. TCHAR szVisits[256];
  298. BYTE cei[MY_MAX_CACHE_ENTRY_INFO];
  299. LPINTERNET_CACHE_ENTRY_INFO pcei = (LPINTERNET_CACHE_ENTRY_INFO)cei;
  300. DWORD cbcei = sizeof(cei);
  301. if (GetUrlCacheEntryInfo(pBuf->m_URL, pcei, &cbcei))
  302. {
  303. wnsprintf(szVisits, ARRAYSIZE(szVisits), TEXT("%d"),
  304. pcei->dwHitRate);
  305. }
  306. else
  307. {
  308. MLLoadString(IDS_VALUE_UNKNOWN, szVisits,
  309. ARRAYSIZE(szVisits));
  310. }
  311. SetDlgItemText(hdlg, IDC_VISITS, szVisits);
  312. Summary_ShowOfflineSummary(hdlg, pBuf, bSubscribed);
  313. return TRUE;
  314. }
  315. void Summary_OnDestroy(HWND hdlg)
  316. {
  317. POOEBuf pBuf = Summary_GetBuf(hdlg);
  318. if (NULL != pBuf && !(pBuf->m_dwPropSheetFlags & PSF_IS_ALREADY_SUBSCRIBED) &&
  319. IsDlgButtonChecked(hdlg, IDC_MAKE_OFFLINE))
  320. {
  321. SendUpdateRequests(NULL, &pBuf->m_Cookie, 1);
  322. }
  323. }
  324. INT_PTR CALLBACK SummaryPropDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
  325. {
  326. BOOL bHandled = FALSE;
  327. switch (message)
  328. {
  329. case WM_INITDIALOG:
  330. bHandled = Summary_OnInitDialog(hdlg, (HWND)wParam, lParam);
  331. break;
  332. case WM_COMMAND:
  333. bHandled = Summary_OnCommand(hdlg, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
  334. break;
  335. case WM_DESTROY:
  336. Summary_OnDestroy(hdlg);
  337. break;
  338. case WM_NOTIFY:
  339. bHandled = Summary_OnNotify(hdlg, (int)wParam, (LPNMHDR)lParam);
  340. break;
  341. case WM_HELP:
  342. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO) lParam)->hItemHandle, c_szHelpFile,
  343. HELP_WM_HELP, (DWORD_PTR)aHelpIDs);
  344. bHandled = TRUE;
  345. break;
  346. case WM_CONTEXTMENU:
  347. SHWinHelpOnDemandWrap((HWND)wParam, c_szHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)aHelpIDs);
  348. bHandled = TRUE;
  349. break;
  350. }
  351. return bHandled;
  352. }
  353. /********************************************************************************
  354. Schedule property sheet code
  355. *********************************************************************************/
  356. void Sched_EnableScheduleButtons(HWND hdlg)
  357. {
  358. POOEBuf pBuf = GetBuf(hdlg);
  359. ASSERT(pBuf);
  360. BOOL bEditAllowed = !(pBuf->m_dwPropSheetFlags &
  361. (PSF_NO_EDITING_SCHEDULES | PSF_NO_SCHEDULED_UPDATES));
  362. BOOL bEnable = (bEditAllowed) &&
  363. ListView_GetSelectedCount(GetDlgItem(hdlg, IDC_SCHEDULE_LIST));
  364. EnableWindow(GetDlgItem(hdlg, IDC_SCHEDULE_NEW), bEditAllowed);
  365. EnableWindow(GetDlgItem(hdlg, IDC_SCHEDULE_EDIT), bEnable);
  366. // TODO: Don't enable remove for publisher's schedule
  367. EnableWindow(GetDlgItem(hdlg, IDC_SCHEDULE_REMOVE), bEnable);
  368. }
  369. struct SCHED_ENUM_DATA
  370. {
  371. HWND hwndSchedList;
  372. POOEBuf pBuf;
  373. SYNCSCHEDULECOOKIE customSchedule;
  374. BOOL bHasAtLeastOneSchedule;
  375. };
  376. struct SCHED_LIST_DATA
  377. {
  378. SYNCSCHEDULECOOKIE SchedCookie;
  379. BOOL bChecked;
  380. BOOL bStartChecked;
  381. };
  382. inline int SchedList_GetIndex(HWND hwndSchedList, int index)
  383. {
  384. return (index != -1) ? index :
  385. ListView_GetNextItem(hwndSchedList, -1, LVNI_ALL | LVNI_SELECTED);
  386. }
  387. void SchedList_GetName(HWND hwndSchedList, int index, TCHAR *pszSchedName, int cchSchedName)
  388. {
  389. LV_ITEM lvi = {0};
  390. lvi.iItem = SchedList_GetIndex(hwndSchedList, index);
  391. if (lvi.iItem != -1)
  392. {
  393. lvi.mask = LVIF_TEXT;
  394. lvi.pszText = pszSchedName;
  395. lvi.cchTextMax = cchSchedName;
  396. ListView_GetItem(hwndSchedList, &lvi);
  397. }
  398. }
  399. void SchedList_SetName(HWND hwndSchedList, int index, LPTSTR pszSchedName)
  400. {
  401. LV_ITEM lvi = {0};
  402. lvi.iItem = SchedList_GetIndex(hwndSchedList, index);
  403. if (lvi.iItem != -1)
  404. {
  405. lvi.mask = LVIF_TEXT;
  406. lvi.pszText = pszSchedName;
  407. ListView_SetItem(hwndSchedList, &lvi);
  408. }
  409. }
  410. SCHED_LIST_DATA *SchedList_GetData(HWND hwndSchedList, int index)
  411. {
  412. SCHED_LIST_DATA *psld = NULL;
  413. LV_ITEM lvi = {0};
  414. lvi.iItem = SchedList_GetIndex(hwndSchedList, index);
  415. if (lvi.iItem != -1)
  416. {
  417. lvi.mask = LVIF_PARAM;
  418. if (ListView_GetItem(hwndSchedList, &lvi))
  419. {
  420. psld = (SCHED_LIST_DATA *)lvi.lParam;
  421. }
  422. }
  423. return psld;
  424. }
  425. void SchedList_UncheckAll(HWND hwndSchedList)
  426. {
  427. int count = ListView_GetItemCount(hwndSchedList);
  428. for (int i = 0; i < count; i++)
  429. {
  430. SCHED_LIST_DATA *psld = SchedList_GetData(hwndSchedList, i);
  431. if (NULL != psld)
  432. {
  433. psld->bChecked = 0;
  434. ListView_SetItemState(hwndSchedList, i, COMP_UNCHECKED, LVIS_STATEIMAGEMASK);
  435. }
  436. }
  437. }
  438. void SchedList_Select(HWND hwndSchedList, int index)
  439. {
  440. int curIndex = ListView_GetNextItem(hwndSchedList, -1, LVNI_ALL | LVNI_SELECTED);
  441. if (curIndex != index)
  442. {
  443. ListView_SetItemState(hwndSchedList, curIndex, 0, LVIS_SELECTED | LVIS_FOCUSED);
  444. ListView_SetItemState(hwndSchedList, index, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  445. }
  446. }
  447. void SchedList_DeleteData(HWND hwndSchedList, int index, BOOL bDeleteItem)
  448. {
  449. LV_ITEM lvi = {0};
  450. lvi.iItem = SchedList_GetIndex(hwndSchedList, index);
  451. if (lvi.iItem != -1)
  452. {
  453. SCHED_LIST_DATA *psld = SchedList_GetData(hwndSchedList, lvi.iItem);
  454. lvi.mask = LVIF_PARAM;
  455. lvi.lParam = NULL;
  456. if ((NULL != psld) && ListView_SetItem(hwndSchedList, &lvi))
  457. {
  458. delete psld;
  459. }
  460. if (bDeleteItem)
  461. {
  462. ListView_DeleteItem(hwndSchedList, lvi.iItem);
  463. }
  464. }
  465. }
  466. void SchedList_DeleteAllData(HWND hwndSchedList)
  467. {
  468. int count = ListView_GetItemCount(hwndSchedList);
  469. for (int i = 0; i < count; i++)
  470. {
  471. SchedList_DeleteData(hwndSchedList, i, FALSE);
  472. }
  473. }
  474. BOOL Sched_EnumCallback(ISyncSchedule *pSyncSchedule,
  475. SYNCSCHEDULECOOKIE *pSchedCookie,
  476. LPARAM lParam)
  477. {
  478. BOOL bAdded = FALSE;
  479. SCHED_ENUM_DATA *psed = (SCHED_ENUM_DATA *)lParam;
  480. DWORD dwSyncScheduleFlags;
  481. SCHED_LIST_DATA *psld = NULL;
  482. if (SUCCEEDED(pSyncSchedule->GetFlags(&dwSyncScheduleFlags)))
  483. {
  484. // This checks to make sure we only add a publisher's schedule to the
  485. // list if it belongs to this item.
  486. if ((!(dwSyncScheduleFlags & SYNCSCHEDINFO_FLAGS_READONLY)) ||
  487. (*pSchedCookie == psed->customSchedule))
  488. {
  489. psld = new SCHED_LIST_DATA;
  490. if (NULL != psld)
  491. {
  492. WCHAR wszName[MAX_PATH];
  493. DWORD cchName = ARRAYSIZE(wszName);
  494. if (SUCCEEDED(pSyncSchedule->GetScheduleName(&cchName, wszName)))
  495. {
  496. TCHAR szName[MAX_PATH];
  497. MyOleStrToStrN(szName, ARRAYSIZE(szName), wszName);
  498. psld->SchedCookie = *pSchedCookie;
  499. psld->bStartChecked = IsCookieOnSchedule(pSyncSchedule, &psed->pBuf->m_Cookie);
  500. psld->bChecked = psld->bStartChecked;
  501. if (psld->bStartChecked)
  502. {
  503. psed->bHasAtLeastOneSchedule = TRUE;
  504. }
  505. LV_ITEM lvItem = { 0 };
  506. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  507. lvItem.iItem = (*pSchedCookie == psed->customSchedule) ? 0 : 0x7FFFFFFF;
  508. lvItem.lParam = (LPARAM)psld;
  509. lvItem.pszText = szName;
  510. int index = ListView_InsertItem(psed->hwndSchedList, &lvItem);
  511. if (index != -1)
  512. {
  513. ListView_SetItemState(psed->hwndSchedList, index,
  514. psld->bStartChecked ? COMP_CHECKED : COMP_UNCHECKED,
  515. LVIS_STATEIMAGEMASK);
  516. ListView_SetColumnWidth(psed->hwndSchedList, 0, LVSCW_AUTOSIZE);
  517. bAdded = TRUE;
  518. }
  519. }
  520. }
  521. }
  522. }
  523. if (!bAdded)
  524. {
  525. SAFEDELETE(psld);
  526. }
  527. return TRUE;
  528. }
  529. BOOL Sched_FillScheduleList(HWND hdlg, POOEBuf pBuf)
  530. {
  531. SCHED_ENUM_DATA sed;
  532. sed.hwndSchedList = GetDlgItem(hdlg, IDC_SCHEDULE_LIST);
  533. sed.pBuf = pBuf;
  534. sed.customSchedule = GUID_NULL;
  535. ISubscriptionItem *psi;
  536. if (SUCCEEDED(SubscriptionItemFromCookie(FALSE, &pBuf->m_Cookie, &psi)))
  537. {
  538. SUBSCRIPTIONITEMINFO sii;
  539. sii.cbSize = sizeof(SUBSCRIPTIONITEMINFO);
  540. if (SUCCEEDED(psi->GetSubscriptionItemInfo(&sii)))
  541. {
  542. sed.customSchedule = sii.ScheduleGroup;
  543. }
  544. psi->Release();
  545. }
  546. sed.bHasAtLeastOneSchedule = FALSE;
  547. EnumSchedules(Sched_EnumCallback, (LPARAM)&sed);
  548. return sed.bHasAtLeastOneSchedule;
  549. }
  550. BOOL Sched_NewSchedule(HWND hdlg)
  551. {
  552. NEWSCHED_DATA nsd;
  553. INT_PTR nResult = DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_NEW_SCHEDULE),
  554. hdlg, NewScheduleDlgProc, (LPARAM)&nsd);
  555. if (IDOK == nResult)
  556. {
  557. SCHED_LIST_DATA *psld;
  558. LV_FINDINFO lvfi = { 0 };
  559. HWND hwndSchedList = GetDlgItem(hdlg, IDC_SCHEDULE_LIST);
  560. lvfi.flags = LVFI_STRING;
  561. lvfi.psz = nsd.szSchedName;
  562. int index = ListView_FindItem(hwndSchedList, -1, &lvfi);
  563. if (index == -1)
  564. {
  565. psld = new SCHED_LIST_DATA;
  566. if (NULL != psld)
  567. {
  568. psld->SchedCookie = nsd.SchedCookie;
  569. psld->bChecked = TRUE;
  570. psld->bStartChecked = FALSE;
  571. LV_ITEM lvItem = { 0 };
  572. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  573. lvItem.iItem = 0;
  574. lvItem.lParam = (LPARAM)psld;
  575. lvItem.pszText = nsd.szSchedName;
  576. index = ListView_InsertItem(hwndSchedList, &lvItem);
  577. }
  578. }
  579. else
  580. {
  581. psld = SchedList_GetData(hwndSchedList, index);
  582. if (NULL != psld)
  583. {
  584. psld->bChecked = TRUE;
  585. }
  586. }
  587. if (index != -1)
  588. {
  589. ListView_SetItemState(hwndSchedList, index, COMP_CHECKED, LVIS_STATEIMAGEMASK);
  590. ListView_SetColumnWidth(hwndSchedList, 0, LVSCW_AUTOSIZE);
  591. CheckRadioButton(hdlg, IDC_MANUAL_SYNC, IDC_SCHEDULED_SYNC,
  592. IDC_SCHEDULED_SYNC);
  593. SchedList_Select(hwndSchedList, index);
  594. Sched_EnableScheduleButtons(hdlg);
  595. }
  596. }
  597. SendMessage(hdlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hdlg, IDC_SCHEDULE_LIST), TRUE);
  598. return nResult == IDOK;
  599. }
  600. BOOL Sched_EditSchedule(HWND hdlg, POOEBuf pBuf)
  601. {
  602. HRESULT hr;
  603. ISyncScheduleMgr *pSyncScheduleMgr;
  604. ASSERT(NULL != pBuf);
  605. hr = CoInitialize(NULL);
  606. if (SUCCEEDED(hr))
  607. {
  608. hr = CoCreateInstance(CLSID_SyncMgr, NULL, CLSCTX_ALL,
  609. IID_ISyncScheduleMgr, (void **)&pSyncScheduleMgr);
  610. if (SUCCEEDED(hr))
  611. {
  612. HWND hwndSchedList = GetDlgItem(hdlg, IDC_SCHEDULE_LIST);
  613. int index = ListView_GetNextItem(hwndSchedList, -1, LVNI_ALL | LVNI_SELECTED);
  614. SCHED_LIST_DATA *psld = SchedList_GetData(hwndSchedList, index);
  615. if (NULL != psld)
  616. {
  617. ISyncSchedule *pSyncSchedule;
  618. hr = pSyncScheduleMgr->OpenSchedule(&psld->SchedCookie, 0, &pSyncSchedule);
  619. if (SUCCEEDED(hr))
  620. {
  621. if (psld->bChecked)
  622. {
  623. hr = pSyncSchedule->SetItemCheck(CLSID_WebCheckOfflineSync,
  624. &pBuf->m_Cookie,
  625. SYNCMGRITEMSTATE_CHECKED);
  626. }
  627. hr = pSyncSchedule->EditSyncSchedule(hdlg, 0);
  628. if (S_OK == hr)
  629. {
  630. psld->bChecked = IsCookieOnSchedule(pSyncSchedule, &pBuf->m_Cookie);
  631. if (psld->bChecked)
  632. {
  633. CheckRadioButton(hdlg, IDC_MANUAL_SYNC, IDC_SCHEDULED_SYNC,
  634. IDC_SCHEDULED_SYNC);
  635. }
  636. ListView_SetItemState(hwndSchedList, index,
  637. psld->bChecked ? COMP_CHECKED : COMP_UNCHECKED,
  638. LVIS_STATEIMAGEMASK);
  639. }
  640. WCHAR wszScheduleName[MAX_PATH];
  641. DWORD cchScheduleName = ARRAYSIZE(wszScheduleName);
  642. if (SUCCEEDED(pSyncSchedule->GetScheduleName(&cchScheduleName, wszScheduleName)))
  643. {
  644. #ifdef UNICODE
  645. SchedList_SetName(hwndSchedList, index, wszScheduleName);
  646. #else
  647. char szScheduleName[MAX_PATH];
  648. SHUnicodeToAnsi(wszScheduleName, szScheduleName, ARRAYSIZE(szScheduleName));
  649. SchedList_SetName(hwndSchedList, index, wszScheduleName);
  650. #endif
  651. ListView_SetColumnWidth(hwndSchedList, 0, LVSCW_AUTOSIZE);
  652. }
  653. SendMessage(hdlg, WM_NEXTDLGCTL, (WPARAM)hwndSchedList, TRUE);
  654. pSyncSchedule->Release();
  655. }
  656. pSyncScheduleMgr->Release();
  657. }
  658. }
  659. CoUninitialize();
  660. }
  661. // This is not undoable by hitting cancel so don't say we changed.
  662. return FALSE;
  663. }
  664. BOOL Sched_RemoveSchedule(HWND hdlg)
  665. {
  666. HWND hwndSchedList = GetDlgItem(hdlg, IDC_SCHEDULE_LIST);
  667. int index = ListView_GetNextItem(hwndSchedList, -1, LVNI_ALL | LVNI_SELECTED);
  668. if (index >= 0)
  669. {
  670. SCHED_LIST_DATA *psld = SchedList_GetData(GetDlgItem(hdlg, IDC_SCHEDULE_LIST), index);
  671. if (NULL != psld)
  672. {
  673. TCHAR szSchedName[MAX_PATH];
  674. SchedList_GetName(hwndSchedList, index, szSchedName, ARRAYSIZE(szSchedName));
  675. if (WCMessageBox(hdlg, IDS_CONFIRM_SCHEDULE_DELETE,
  676. IDS_SCHEDULE_DELETE_CAPTION, MB_YESNO | MB_ICONQUESTION,
  677. szSchedName) == IDYES)
  678. {
  679. HRESULT hr = CoInitialize(NULL);
  680. if (SUCCEEDED(hr))
  681. {
  682. ISyncScheduleMgr *pSyncScheduleMgr;
  683. hr = CoCreateInstance(CLSID_SyncMgr, NULL, CLSCTX_ALL,
  684. IID_ISyncScheduleMgr, (void **)&pSyncScheduleMgr);
  685. if (SUCCEEDED(hr))
  686. {
  687. hr = pSyncScheduleMgr->RemoveSchedule(&psld->SchedCookie);
  688. ASSERT(SUCCEEDED(hr));
  689. if (SUCCEEDED(hr))
  690. {
  691. SchedList_DeleteData(hwndSchedList, -1, TRUE);
  692. SchedList_Select(hwndSchedList, 0);
  693. }
  694. pSyncScheduleMgr->Release();
  695. }
  696. CoUninitialize();
  697. }
  698. }
  699. SendMessage(hdlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hdlg, IDC_SCHEDULE_LIST), TRUE);
  700. }
  701. }
  702. // This is not undoable by hitting cancel so don't say we changed.
  703. return FALSE;
  704. }
  705. BOOL Sched_OnCommand(HWND hdlg, WORD wNotifyCode, WORD wID, HWND hwndCtl)
  706. {
  707. BOOL bHandled = TRUE;
  708. BOOL bChanged = FALSE;
  709. POOEBuf pBuf = GetBuf(hdlg);
  710. if (NULL != pBuf)
  711. {
  712. switch (wID)
  713. {
  714. case IDC_MANUAL_SYNC:
  715. case IDC_SCHEDULED_SYNC:
  716. // case IDC_IDLE_ONLY:
  717. if (wNotifyCode == BN_CLICKED)
  718. {
  719. bChanged = TRUE;
  720. }
  721. break;
  722. case IDC_SCHEDULE_NEW:
  723. if (wNotifyCode == BN_CLICKED)
  724. {
  725. bChanged = Sched_NewSchedule(hdlg);
  726. }
  727. break;
  728. case IDC_SCHEDULE_EDIT:
  729. if (wNotifyCode == BN_CLICKED)
  730. {
  731. bChanged = Sched_EditSchedule(hdlg, pBuf);
  732. }
  733. break;
  734. case IDC_SCHEDULE_REMOVE:
  735. if (wNotifyCode == BN_CLICKED)
  736. {
  737. bChanged = Sched_RemoveSchedule(hdlg);
  738. }
  739. break;
  740. default:
  741. bHandled = FALSE;
  742. break;
  743. }
  744. }
  745. if (bChanged)
  746. {
  747. PropSheet_Changed(GetParent(hdlg), hdlg);
  748. }
  749. return bHandled;
  750. }
  751. BOOL Sched_Validate(HWND hdlg, POOEBuf pBuf)
  752. {
  753. /*
  754. if (IsDlgButtonChecked(hdlg, IDC_IDLE_ONLY))
  755. {
  756. pBuf->grfTaskTrigger |= TASK_FLAG_START_ONLY_IF_IDLE;
  757. }
  758. else
  759. {
  760. pBuf->grfTaskTrigger &= ~TASK_FLAG_START_ONLY_IF_IDLE;
  761. }
  762. */
  763. if (IsDlgButtonChecked(hdlg, IDC_SCHEDULED_SYNC))
  764. {
  765. HWND hwndSchedList = GetDlgItem(hdlg, IDC_SCHEDULE_LIST);
  766. int count = ListView_GetItemCount(hwndSchedList);
  767. BOOL bHaveASchedule = FALSE;
  768. for (int i = 0; i < count; i++)
  769. {
  770. SCHED_LIST_DATA *psld = SchedList_GetData(hwndSchedList, i);
  771. if (NULL != psld && psld->bChecked)
  772. {
  773. bHaveASchedule = TRUE;
  774. break;
  775. }
  776. }
  777. if (!bHaveASchedule)
  778. {
  779. CheckRadioButton(hdlg, IDC_MANUAL_SYNC, IDC_SCHEDULED_SYNC,
  780. IDC_MANUAL_SYNC);
  781. }
  782. }
  783. return TRUE;
  784. }
  785. BOOL Sched_ApplyProps(HWND hdlg, POOEBuf pBuf)
  786. {
  787. BOOL bResult;
  788. HRESULT hr;
  789. pBuf->dwFlags = PROP_WEBCRAWL_ALL;
  790. bResult = SUCCEEDED(SaveBufferChange(pBuf, TRUE));
  791. if (bResult)
  792. {
  793. if (IsDlgButtonChecked(hdlg, IDC_MANUAL_SYNC))
  794. {
  795. SchedList_UncheckAll(GetDlgItem(hdlg, IDC_SCHEDULE_LIST));
  796. hr = RemoveItemFromAllSchedules(&pBuf->m_Cookie);
  797. ASSERT(SUCCEEDED(hr));
  798. }
  799. else
  800. {
  801. HWND hwndSchedList = GetDlgItem(hdlg, IDC_SCHEDULE_LIST);
  802. int count = ListView_GetItemCount(hwndSchedList);
  803. for (int i = 0; i < count; i++)
  804. {
  805. SCHED_LIST_DATA *psld = SchedList_GetData(hwndSchedList, i);
  806. ASSERT(NULL != psld);
  807. if (NULL != psld)
  808. {
  809. if (psld->bChecked != psld->bStartChecked)
  810. {
  811. if (psld->bChecked)
  812. {
  813. ISubscriptionItem *psi;
  814. if (SUCCEEDED(SubscriptionItemFromCookie(FALSE,
  815. &pBuf->m_Cookie,
  816. &psi)))
  817. {
  818. SYNC_HANDLER_ITEM_INFO shii;
  819. shii.handlerID = CLSID_WebCheckOfflineSync;
  820. shii.itemID = pBuf->m_Cookie;
  821. shii.hIcon = NULL;
  822. MyStrToOleStrN(shii.wszItemName,
  823. ARRAYSIZE(shii.wszItemName),
  824. pBuf->m_Name);
  825. shii.dwCheckState = SYNCMGRITEMSTATE_CHECKED;
  826. AddScheduledItem(&shii, &psld->SchedCookie);
  827. }
  828. }
  829. else
  830. {
  831. RemoveScheduledItem(&pBuf->m_Cookie, &psld->SchedCookie);
  832. }
  833. psld->bStartChecked = psld->bChecked;
  834. }
  835. }
  836. }
  837. }
  838. }
  839. return bResult;
  840. }
  841. BOOL Sched_OnNotify(HWND hdlg, int idCtrl, LPNMHDR pnmh)
  842. {
  843. BOOL bHandled = TRUE;
  844. POOEBuf pBuf = GetBuf(hdlg);
  845. ASSERT(pBuf);
  846. switch (pnmh->code)
  847. {
  848. case PSN_KILLACTIVE:
  849. if (!Sched_Validate(hdlg, pBuf))
  850. {
  851. SetWindowLongPtr(hdlg, DWLP_MSGRESULT, TRUE);
  852. }
  853. break;
  854. case PSN_APPLY:
  855. Sched_ApplyProps(hdlg, pBuf);
  856. break;
  857. case NM_DBLCLK:
  858. if (IDC_SCHEDULE_LIST == pnmh->idFrom)
  859. {
  860. Sched_EditSchedule(hdlg, pBuf);
  861. }
  862. break;
  863. case LVN_ITEMCHANGED:
  864. {
  865. NM_LISTVIEW *pnmlv = (NM_LISTVIEW *)pnmh;
  866. if ((pnmlv->iItem != -1) &&
  867. (pnmlv->uChanged & LVIF_STATE) &&
  868. ((pnmlv->uNewState ^ pnmlv->uOldState) & COMP_CHECKED))
  869. {
  870. SCHED_LIST_DATA *psld = SchedList_GetData(pnmh->hwndFrom, pnmlv->iItem);
  871. if (NULL != psld)
  872. {
  873. psld->bChecked = (pnmlv->uNewState & COMP_CHECKED) ? TRUE : FALSE;
  874. if (psld->bChecked)
  875. {
  876. CheckRadioButton(hdlg, IDC_MANUAL_SYNC, IDC_SCHEDULED_SYNC,
  877. IDC_SCHEDULED_SYNC);
  878. }
  879. PropSheet_Changed(GetParent(hdlg), hdlg);
  880. }
  881. }
  882. if ((pnmlv->uChanged & LVIF_STATE) &&
  883. ((pnmlv->uNewState ^ pnmlv->uOldState) & LVIS_SELECTED))
  884. {
  885. Sched_EnableScheduleButtons(hdlg);
  886. }
  887. break;
  888. }
  889. default:
  890. bHandled = FALSE;
  891. break;
  892. }
  893. return bHandled;
  894. }
  895. void Sched_OnDestroy(HWND hdlg)
  896. {
  897. HWND hwndSchedList = GetDlgItem(hdlg, IDC_SCHEDULE_LIST);
  898. SchedList_DeleteAllData(hwndSchedList);
  899. }
  900. BOOL Sched_OnInitDialog(HWND hdlg, HWND hwndFocus, LPARAM lParam)
  901. {
  902. ASSERT(NULL != ((LPPROPSHEETPAGE)lParam));
  903. ASSERT(NULL != ((LPPROPSHEETPAGE)lParam)->lParam);
  904. SetWindowLongPtr(hdlg, DWLP_USER, ((LPPROPSHEETPAGE)lParam)->lParam);
  905. // Now read in values and populate the dialog
  906. POOEBuf pBuf = (POOEBuf)((LPPROPSHEETPAGE)lParam)->lParam;
  907. /* CheckDlgButton(hdlg, IDC_IDLE_ONLY,
  908. pBuf->grfTaskTrigger & TASK_FLAG_START_ONLY_IF_IDLE ?
  909. 1 : 0);
  910. */
  911. HWND hwndSchedList = GetDlgItem(hdlg, IDC_SCHEDULE_LIST);
  912. ListView_SetExtendedListViewStyle(hwndSchedList, LVS_EX_CHECKBOXES);
  913. LV_COLUMN lvc;
  914. lvc.mask = LVCF_FMT | LVCF_SUBITEM;
  915. lvc.fmt = LVCFMT_LEFT;
  916. lvc.iSubItem = 0;
  917. ListView_InsertColumn(hwndSchedList, 0, &lvc);
  918. // Now handle restrictions
  919. SetPropSheetFlags(pBuf, SHRestricted2W(REST_NoScheduledUpdates, NULL, 0), PSF_NO_SCHEDULED_UPDATES);
  920. SetPropSheetFlags(pBuf, SHRestricted2W(REST_NoEditingScheduleGroups, NULL, 0), PSF_NO_EDITING_SCHEDULES);
  921. BOOL bHasSchedules = Sched_FillScheduleList(hdlg, pBuf);
  922. if (pBuf->m_dwPropSheetFlags & PSF_NO_SCHEDULED_UPDATES)
  923. {
  924. EnableWindow(GetDlgItem(hdlg, IDC_SCHEDULE_LIST), FALSE);
  925. EnableWindow(GetDlgItem(hdlg, IDC_SCHEDULED_SYNC), FALSE);
  926. CheckRadioButton(hdlg, IDC_MANUAL_SYNC, IDC_SCHEDULED_SYNC, IDC_MANUAL_SYNC);
  927. }
  928. else
  929. {
  930. CheckRadioButton(hdlg, IDC_MANUAL_SYNC, IDC_SCHEDULED_SYNC,
  931. bHasSchedules ? IDC_SCHEDULED_SYNC : IDC_MANUAL_SYNC);
  932. }
  933. SchedList_Select(hwndSchedList, 0);
  934. // Finally, do the enable/disable controls thing...
  935. Sched_EnableScheduleButtons(hdlg);
  936. return TRUE;
  937. }
  938. INT_PTR CALLBACK SchedulePropDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
  939. {
  940. BOOL bHandled = FALSE;
  941. switch (message)
  942. {
  943. case WM_INITDIALOG:
  944. bHandled = Sched_OnInitDialog(hdlg, (HWND)wParam, lParam);
  945. break;
  946. case WM_COMMAND:
  947. bHandled = Sched_OnCommand(hdlg, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
  948. break;
  949. case WM_NOTIFY:
  950. bHandled = Sched_OnNotify(hdlg, (int)wParam, (LPNMHDR)lParam);
  951. break;
  952. case WM_DESTROY:
  953. Sched_OnDestroy(hdlg);
  954. // return 0
  955. break;
  956. case WM_HELP:
  957. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO) lParam)->hItemHandle, c_szHelpFile,
  958. HELP_WM_HELP, (DWORD_PTR)aHelpIDs);
  959. bHandled = TRUE;
  960. break;
  961. case WM_CONTEXTMENU:
  962. SHWinHelpOnDemandWrap((HWND)wParam, c_szHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)aHelpIDs);
  963. bHandled = TRUE;
  964. break;
  965. }
  966. return bHandled;
  967. }
  968. /********************************************************************************
  969. Download property sheet code
  970. *********************************************************************************/
  971. void Download_EnableFollowLinks(HWND hdlg)
  972. {
  973. BOOL bTranslate;
  974. int i = GetDlgItemInt(hdlg, IDC_LEVELS, &bTranslate, FALSE);
  975. EnableWindow(GetDlgItem(hdlg, IDC_FOLLOW_LINKS), (bTranslate && i));
  976. }
  977. void Download_EnableLimitSpaceControls(HWND hdlg)
  978. {
  979. static const int IDs[] = { IDC_LIMIT_SPACE_EDIT, IDC_LIMIT_SPACE_SPIN, IDC_LIMIT_SPACE_TEXT };
  980. EnableControls(hdlg, IDs, ARRAYSIZE(IDs), IsDlgButtonChecked(hdlg, IDC_LIMIT_SPACE_CHECK));
  981. }
  982. void Download_EnableEmailControls(HWND hdlg)
  983. {
  984. static const int IDs[] = { IDC_EMAIL_ADDRESS_TEXT, IDC_EMAIL_ADDRESS,
  985. IDC_EMAIL_SERVER_TEXT, IDC_EMAIL_SERVER };
  986. EnableControls(hdlg, IDs, ARRAYSIZE(IDs), IsDlgButtonChecked(hdlg, IDC_EMAIL_NOTIFY));
  987. }
  988. BOOL Download_OnInitDialog(HWND hdlg, HWND hwndFocus, LPARAM lParam)
  989. {
  990. POOEBuf pBuf;
  991. ASSERT(NULL != ((LPPROPSHEETPAGE)lParam));
  992. ASSERT(NULL != ((LPPROPSHEETPAGE)lParam)->lParam);
  993. SetWindowLongPtr(hdlg, DWLP_USER, ((LPPROPSHEETPAGE)lParam)->lParam);
  994. // First do basic control setup
  995. HWND hwndLimitSpin = GetDlgItem(hdlg, IDC_LIMIT_SPACE_SPIN);
  996. SendMessage(hwndLimitSpin, UDM_SETRANGE, 0,
  997. MAKELONG(MAX_DOWNLOAD_K, MIN_DOWNLOAD_K));
  998. UDACCEL ua[] = { {0, 1}, {1, 10}, {2, 100}, {3, 1000} };
  999. SendMessage(hwndLimitSpin, UDM_SETACCEL, ARRAYSIZE(ua), (LPARAM)ua);
  1000. Edit_LimitText(GetDlgItem(hdlg, IDC_LIMIT_SPACE_EDIT), 5);
  1001. // Now read in values and populate the dialog
  1002. pBuf = (POOEBuf)((LPPROPSHEETPAGE)lParam)->lParam;
  1003. SUBSCRIPTIONTYPE subType = GetItemCategory(pBuf);
  1004. switch (subType)
  1005. {
  1006. case SUBSTYPE_CHANNEL:
  1007. case SUBSTYPE_DESKTOPCHANNEL:
  1008. CheckRadioButton(hdlg, IDC_DOWNLOAD_ALL, IDC_DOWNLOAD_MIN,
  1009. pBuf->fChannelFlags & CHANNEL_AGENT_PRECACHE_ALL ?
  1010. IDC_DOWNLOAD_ALL : IDC_DOWNLOAD_MIN);
  1011. break;
  1012. case SUBSTYPE_URL:
  1013. case SUBSTYPE_DESKTOPURL:
  1014. case SUBSTYPE_EXTERNAL:
  1015. {
  1016. HWND hwndLevelsSpin = GetDlgItem(hdlg, IDC_LEVELS_SPIN);
  1017. SendMessage(hwndLevelsSpin, UDM_SETRANGE, 0, MAKELONG(MAX_WEBCRAWL_LEVELS, 0));
  1018. SendMessage(hwndLevelsSpin, UDM_SETPOS, 0, pBuf->m_RecurseLevels);
  1019. CheckDlgButton(hdlg, IDC_FOLLOW_LINKS,
  1020. (pBuf->m_RecurseFlags & WEBCRAWL_LINKS_ELSEWHERE) || (0 == pBuf->m_RecurseLevels)
  1021. ? 1 : 0);
  1022. Download_EnableFollowLinks(hdlg);
  1023. break;
  1024. }
  1025. }
  1026. SendMessage(hwndLimitSpin, UDM_SETPOS, 0, pBuf->m_SizeLimit ? pBuf->m_SizeLimit : DEF_DOWNLOAD_K);
  1027. CheckDlgButton(hdlg, IDC_LIMIT_SPACE_CHECK, pBuf->m_SizeLimit ? 1 : 0);
  1028. CheckDlgButton(hdlg, IDC_EMAIL_NOTIFY, pBuf->bMail ? 1 : 0);
  1029. TCHAR szText[MAX_PATH];
  1030. ReadDefaultEmail(szText, ARRAYSIZE(szText));
  1031. Edit_LimitText(GetDlgItem(hdlg, IDC_EMAIL_ADDRESS), MAX_PATH - 1);
  1032. SetDlgItemText(hdlg, IDC_EMAIL_ADDRESS, szText);
  1033. ReadDefaultSMTPServer(szText, ARRAYSIZE(szText));
  1034. Edit_LimitText(GetDlgItem(hdlg, IDC_EMAIL_SERVER), MAX_PATH - 1);
  1035. SetDlgItemText(hdlg, IDC_EMAIL_SERVER, szText);
  1036. // Now handle restrictions
  1037. if (SHRestricted2W(REST_NoSubscriptionPasswords, NULL, 0))
  1038. {
  1039. EnableWindow(GetDlgItem(hdlg, IDC_LOGIN), FALSE);
  1040. }
  1041. // Finally, do the enable/disable controls thing...
  1042. Download_EnableLimitSpaceControls(hdlg);
  1043. Download_EnableEmailControls(hdlg);
  1044. return TRUE;
  1045. }
  1046. BOOL Download_OnCommand(HWND hdlg, WORD wNotifyCode, WORD wID, HWND hwndCtl)
  1047. {
  1048. BOOL bHandled = TRUE;
  1049. BOOL bChanged = FALSE;
  1050. POOEBuf pBuf = GetBuf(hdlg);
  1051. if (NULL != pBuf)
  1052. {
  1053. switch (wID)
  1054. {
  1055. case IDC_LIMIT_SPACE_EDIT:
  1056. if (wNotifyCode == EN_CHANGE)
  1057. {
  1058. if (pBuf->m_SizeLimit !=
  1059. LOWORD(SendDlgItemMessage(hdlg, IDC_LIMIT_SPACE_SPIN, UDM_GETPOS, 0, 0)))
  1060. {
  1061. bChanged = TRUE;
  1062. }
  1063. }
  1064. else if (wNotifyCode == EN_KILLFOCUS)
  1065. {
  1066. KeepSpinNumberInRange(hdlg, IDC_LIMIT_SPACE_EDIT,
  1067. IDC_LIMIT_SPACE_SPIN,
  1068. MIN_DOWNLOAD_K, MAX_DOWNLOAD_K);
  1069. }
  1070. break;
  1071. case IDC_LEVELS:
  1072. if (wNotifyCode == EN_UPDATE)
  1073. {
  1074. int levels = KeepSpinNumberInRange(hdlg, IDC_LEVELS,
  1075. IDC_LEVELS_SPIN, 0, MAX_WEBCRAWL_LEVELS);
  1076. if (pBuf->m_RecurseLevels != levels)
  1077. {
  1078. bChanged = TRUE;
  1079. }
  1080. Download_EnableFollowLinks(hdlg);
  1081. }
  1082. break;
  1083. case IDC_LIMIT_SPACE_CHECK:
  1084. if (wNotifyCode == BN_CLICKED)
  1085. {
  1086. Download_EnableLimitSpaceControls(hdlg);
  1087. bChanged = TRUE;
  1088. }
  1089. break;
  1090. case IDC_FOLLOW_LINKS:
  1091. if (wNotifyCode == BN_CLICKED)
  1092. {
  1093. bChanged = TRUE;
  1094. }
  1095. break;
  1096. case IDC_EMAIL_NOTIFY:
  1097. if (wNotifyCode == BN_CLICKED)
  1098. {
  1099. Download_EnableEmailControls(hdlg);
  1100. bChanged = TRUE;
  1101. }
  1102. break;
  1103. case IDC_EMAIL_ADDRESS:
  1104. case IDC_EMAIL_SERVER:
  1105. if (wNotifyCode == EN_CHANGE)
  1106. {
  1107. bChanged = TRUE;
  1108. }
  1109. break;
  1110. case IDC_LOGIN:
  1111. if ((wNotifyCode == BN_CLICKED) &&
  1112. (DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_SUBSPROPS_LOGIN),
  1113. hdlg, LoginOptionDlgProc, (LPARAM)pBuf) == IDOK))
  1114. {
  1115. bChanged = TRUE;
  1116. }
  1117. break;
  1118. case IDC_ADVANCED:
  1119. if ((wNotifyCode == BN_CLICKED) &&
  1120. (DialogBoxParam(MLGetHinst(), MAKEINTRESOURCE(IDD_SUBSPROPS_ADVANCED),
  1121. hdlg, AdvancedDownloadDlgProc, (LPARAM)pBuf) == IDOK))
  1122. {
  1123. bChanged = TRUE;
  1124. }
  1125. break;
  1126. default:
  1127. bHandled = FALSE;
  1128. break;
  1129. }
  1130. }
  1131. if (bChanged)
  1132. {
  1133. PropSheet_Changed(GetParent(hdlg), hdlg);
  1134. }
  1135. return bHandled;
  1136. }
  1137. BOOL Download_Validate(HWND hdlg, POOEBuf pBuf)
  1138. {
  1139. pBuf->bMail = IsDlgButtonChecked(hdlg, IDC_EMAIL_NOTIFY);
  1140. if (pBuf->bMail)
  1141. {
  1142. TCHAR szEmail[MAX_PATH];
  1143. TCHAR szServer[MAX_PATH];
  1144. GetDlgItemText(hdlg, IDC_EMAIL_ADDRESS, szEmail, ARRAYSIZE(szEmail));
  1145. GetDlgItemText(hdlg, IDC_EMAIL_SERVER, szServer, ARRAYSIZE(szServer));
  1146. if (!szEmail[0] || !szServer[0])
  1147. {
  1148. SGMessageBox(hdlg, IDS_EMAIL_INCOMPLETE, MB_ICONWARNING);
  1149. return FALSE;
  1150. }
  1151. }
  1152. SUBSCRIPTIONTYPE subType = GetItemCategory(pBuf);
  1153. switch (subType)
  1154. {
  1155. case SUBSTYPE_CHANNEL:
  1156. case SUBSTYPE_DESKTOPCHANNEL:
  1157. pBuf->fChannelFlags &= ~(CHANNEL_AGENT_PRECACHE_SOME | CHANNEL_AGENT_PRECACHE_ALL);
  1158. if (IsDlgButtonChecked(hdlg, IDC_DOWNLOAD_ALL))
  1159. {
  1160. pBuf->fChannelFlags |= CHANNEL_AGENT_PRECACHE_ALL;
  1161. }
  1162. else
  1163. {
  1164. pBuf->fChannelFlags |= CHANNEL_AGENT_PRECACHE_SOME;
  1165. }
  1166. break;
  1167. case SUBSTYPE_URL:
  1168. case SUBSTYPE_DESKTOPURL:
  1169. case SUBSTYPE_EXTERNAL:
  1170. {
  1171. if (IsDlgButtonChecked(hdlg, IDC_FOLLOW_LINKS))
  1172. {
  1173. pBuf->m_RecurseFlags |= WEBCRAWL_LINKS_ELSEWHERE;
  1174. }
  1175. else
  1176. {
  1177. pBuf->m_RecurseFlags &= ~WEBCRAWL_LINKS_ELSEWHERE;
  1178. }
  1179. pBuf->m_RecurseLevels = LOWORD(SendDlgItemMessage(hdlg,
  1180. IDC_LEVELS_SPIN, UDM_GETPOS, 0, 0));
  1181. ASSERT((pBuf->m_RecurseLevels >= 0) &&
  1182. (pBuf->m_RecurseLevels <= MAX_WEBCRAWL_LEVELS));
  1183. }
  1184. }
  1185. pBuf->m_SizeLimit = IsDlgButtonChecked(hdlg, IDC_LIMIT_SPACE_CHECK) ?
  1186. (LONG)SendDlgItemMessage(hdlg, IDC_LIMIT_SPACE_SPIN,
  1187. UDM_GETPOS, 0, 0) :
  1188. 0;
  1189. ASSERT((0 == pBuf->m_SizeLimit) ||
  1190. ((pBuf->m_SizeLimit >= MIN_DOWNLOAD_K) &&
  1191. (pBuf->m_SizeLimit <= MAX_DOWNLOAD_K)));
  1192. return TRUE;
  1193. }
  1194. BOOL Download_ApplyProps(HWND hdlg, POOEBuf pBuf)
  1195. {
  1196. pBuf->dwFlags = PROP_WEBCRAWL_ALL;
  1197. if (IsDlgButtonChecked(hdlg, IDC_EMAIL_NOTIFY))
  1198. {
  1199. TCHAR szText[MAX_PATH];
  1200. GetDlgItemText(hdlg, IDC_EMAIL_ADDRESS, szText, ARRAYSIZE(szText));
  1201. WriteDefaultEmail(szText);
  1202. GetDlgItemText(hdlg, IDC_EMAIL_SERVER, szText, ARRAYSIZE(szText));
  1203. WriteDefaultSMTPServer(szText);
  1204. }
  1205. if (pBuf->bChannel)
  1206. {
  1207. pBuf->dwFlags |= PROP_WEBCRAWL_CHANNELFLAGS;
  1208. }
  1209. return SUCCEEDED(SaveBufferChange(pBuf, TRUE));
  1210. }
  1211. BOOL Download_OnNotify(HWND hdlg, int idCtrl, LPNMHDR pnmh)
  1212. {
  1213. BOOL bHandled = TRUE;
  1214. POOEBuf pBuf = GetBuf(hdlg);
  1215. ASSERT(pBuf);
  1216. switch (pnmh->code)
  1217. {
  1218. case PSN_KILLACTIVE:
  1219. if (!Download_Validate(hdlg, pBuf))
  1220. {
  1221. SetWindowLongPtr(hdlg, DWLP_MSGRESULT, TRUE);
  1222. }
  1223. break;
  1224. case PSN_APPLY:
  1225. Download_ApplyProps(hdlg, pBuf);
  1226. break;
  1227. default:
  1228. bHandled = FALSE;
  1229. break;
  1230. }
  1231. return bHandled;
  1232. }
  1233. INT_PTR CALLBACK DownloadPropDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
  1234. {
  1235. BOOL bHandled = FALSE;
  1236. switch (message)
  1237. {
  1238. case WM_INITDIALOG:
  1239. bHandled = Download_OnInitDialog(hdlg, (HWND)wParam, lParam);
  1240. break;
  1241. case WM_COMMAND:
  1242. bHandled = Download_OnCommand(hdlg, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
  1243. break;
  1244. case WM_NOTIFY:
  1245. bHandled = Download_OnNotify(hdlg, (int)wParam, (LPNMHDR)lParam);
  1246. break;
  1247. case WM_HELP:
  1248. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO) lParam)->hItemHandle, c_szHelpFile,
  1249. HELP_WM_HELP, (DWORD_PTR)aHelpIDs);
  1250. bHandled = TRUE;
  1251. break;
  1252. case WM_CONTEXTMENU:
  1253. SHWinHelpOnDemandWrap((HWND)wParam, c_szHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)aHelpIDs);
  1254. bHandled = TRUE;
  1255. break;
  1256. }
  1257. return bHandled;
  1258. }
  1259. /********************************************************************************
  1260. New schedule popup code
  1261. *********************************************************************************/
  1262. BOOL NewSched_OnCommand(HWND hdlg, WORD wNotifyCode, WORD wID, HWND hwndCtl)
  1263. {
  1264. BOOL bHandled = FALSE;
  1265. switch (wID)
  1266. {
  1267. case IDC_SCHEDULE_DAYS:
  1268. if (wNotifyCode == EN_UPDATE)
  1269. {
  1270. KeepSpinNumberInRange(hdlg, IDC_SCHEDULE_DAYS,
  1271. IDC_SCHEDULE_DAYS_SPIN, 1, 99);
  1272. }
  1273. #ifdef NEWSCHED_AUTONAME
  1274. else if (wNotifyCode == EN_CHANGE)
  1275. {
  1276. NewSched_AutoNameHelper(hdlg);
  1277. }
  1278. #endif
  1279. bHandled = TRUE;
  1280. break;
  1281. case IDOK:
  1282. {
  1283. TASK_TRIGGER trig;
  1284. NEWSCHED_DATA *pnsd = (NEWSCHED_DATA*) GetWindowLongPtr(hdlg, DWLP_USER);
  1285. ASSERT(NULL != pnsd);
  1286. if (NewSched_ResolveNameConflictHelper(hdlg, &trig, &pnsd->SchedCookie))
  1287. {
  1288. NewSched_CreateScheduleHelper(hdlg, &trig, &pnsd->SchedCookie);
  1289. GetDlgItemText(hdlg, IDC_SCHEDULE_NAME,
  1290. pnsd->szSchedName, ARRAYSIZE(pnsd->szSchedName));
  1291. EndDialog(hdlg, IDOK);
  1292. }
  1293. break;
  1294. }
  1295. case IDCANCEL:
  1296. EndDialog(hdlg, IDCANCEL);
  1297. break;
  1298. default:
  1299. break;
  1300. }
  1301. return bHandled;
  1302. }
  1303. #ifdef NEWSCHED_AUTONAME
  1304. BOOL NewSched_OnNotify(HWND hdlg, int idCtrl, LPNMHDR pnmh)
  1305. {
  1306. BOOL bHandled = TRUE;
  1307. switch (pnmh->code)
  1308. {
  1309. case DTN_DATETIMECHANGE:
  1310. NewSched_AutoNameHelper(hdlg);
  1311. break;
  1312. default:
  1313. bHandled = FALSE;
  1314. break;
  1315. }
  1316. return bHandled;
  1317. }
  1318. #endif
  1319. INT_PTR CALLBACK NewScheduleDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
  1320. {
  1321. BOOL bHandled = FALSE;
  1322. switch (message)
  1323. {
  1324. case WM_INITDIALOG:
  1325. {
  1326. SetWindowLongPtr(hdlg, DWLP_USER, lParam);
  1327. NewSched_OnInitDialogHelper(hdlg);
  1328. bHandled = TRUE;
  1329. break;
  1330. }
  1331. case WM_COMMAND:
  1332. bHandled = NewSched_OnCommand(hdlg, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
  1333. break;
  1334. #ifdef NEWSCHED_AUTONAME
  1335. case WM_NOTIFY:
  1336. bHandled = NewSched_OnNotify(hdlg, wParam, (LPNMHDR)lParam);
  1337. break;
  1338. #endif
  1339. case WM_HELP:
  1340. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO) lParam)->hItemHandle, c_szHelpFile,
  1341. HELP_WM_HELP, (DWORD_PTR)aHelpIDs);
  1342. bHandled = TRUE;
  1343. break;
  1344. case WM_CONTEXTMENU:
  1345. SHWinHelpOnDemandWrap((HWND)wParam, c_szHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)aHelpIDs);
  1346. bHandled = TRUE;
  1347. break;
  1348. }
  1349. return bHandled;
  1350. }
  1351. /********************************************************************************
  1352. Advanced properties code
  1353. *********************************************************************************/
  1354. BOOL Advanced_OnInitDialog(HWND hdlg, HWND hwndFocus, LPARAM lParam)
  1355. {
  1356. POOEBuf pBuf;
  1357. ASSERT(NULL != (POOEBuf)lParam);
  1358. SetWindowLongPtr(hdlg, DWLP_USER, lParam);
  1359. pBuf = (POOEBuf)lParam;
  1360. UINT flags = pBuf->m_RecurseFlags;
  1361. CheckDlgButton(hdlg, IDC_DOWNLOAD_IMAGES, flags & WEBCRAWL_GET_IMAGES);
  1362. CheckDlgButton(hdlg, IDC_DOWNLOAD_APPLETS, flags & WEBCRAWL_GET_CONTROLS);
  1363. CheckDlgButton(hdlg, IDC_DOWNLOAD_MEDIA,
  1364. flags & (WEBCRAWL_GET_BGSOUNDS | WEBCRAWL_GET_VIDEOS));
  1365. CheckDlgButton(hdlg, IDC_DOWNLOAD_ONLY_HTML_LINKS, flags & WEBCRAWL_ONLY_LINKS_TO_HTML);
  1366. return TRUE;
  1367. }
  1368. void Advanced_SetFlag(HWND hdlg, POOEBuf pBuf, int ID, LONG flags)
  1369. {
  1370. if (IsDlgButtonChecked(hdlg, ID))
  1371. {
  1372. pBuf->m_RecurseFlags |= flags;
  1373. }
  1374. else
  1375. {
  1376. pBuf->m_RecurseFlags &= ~flags;
  1377. }
  1378. }
  1379. BOOL Advanced_OnCommand(HWND hdlg, WORD wNotifyCode, WORD wID, HWND hwndCtl)
  1380. {
  1381. BOOL bHandled = TRUE;
  1382. POOEBuf pBuf = GetBuf(hdlg);
  1383. ASSERT(pBuf);
  1384. switch (wID)
  1385. {
  1386. case IDOK:
  1387. Advanced_SetFlag(hdlg, pBuf, IDC_DOWNLOAD_IMAGES, WEBCRAWL_GET_IMAGES);
  1388. Advanced_SetFlag(hdlg, pBuf, IDC_DOWNLOAD_APPLETS, WEBCRAWL_GET_CONTROLS);
  1389. Advanced_SetFlag(hdlg, pBuf, IDC_DOWNLOAD_MEDIA,
  1390. WEBCRAWL_GET_BGSOUNDS | WEBCRAWL_GET_VIDEOS);
  1391. Advanced_SetFlag(hdlg, pBuf, IDC_DOWNLOAD_ONLY_HTML_LINKS, WEBCRAWL_ONLY_LINKS_TO_HTML);
  1392. EndDialog(hdlg, IDOK);
  1393. break;
  1394. case IDCANCEL:
  1395. EndDialog(hdlg, IDCANCEL);
  1396. break;
  1397. case IDC_DOWNLOAD_IMAGES:
  1398. case IDC_DOWNLOAD_APPLETS:
  1399. case IDC_DOWNLOAD_MEDIA:
  1400. case IDC_DOWNLOAD_ONLY_HTML_LINKS:
  1401. break;
  1402. default:
  1403. bHandled = FALSE;
  1404. break;
  1405. }
  1406. return bHandled;
  1407. }
  1408. INT_PTR CALLBACK AdvancedDownloadDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
  1409. {
  1410. BOOL bHandled = FALSE;
  1411. switch (message)
  1412. {
  1413. case WM_INITDIALOG:
  1414. bHandled = Advanced_OnInitDialog(hdlg, (HWND)wParam, lParam);
  1415. break;
  1416. case WM_COMMAND:
  1417. bHandled = Advanced_OnCommand(hdlg, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
  1418. break;
  1419. case WM_HELP:
  1420. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO) lParam)->hItemHandle, c_szHelpFile,
  1421. HELP_WM_HELP, (DWORD_PTR)aHelpIDs);
  1422. bHandled = TRUE;
  1423. break;
  1424. case WM_CONTEXTMENU:
  1425. SHWinHelpOnDemandWrap((HWND)wParam, c_szHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)aHelpIDs);
  1426. bHandled = TRUE;
  1427. break;
  1428. }
  1429. return bHandled;
  1430. }
  1431. /********************************************************************************
  1432. Login properties code
  1433. *********************************************************************************/
  1434. BOOL Login_OnInitDialog(HWND hdlg, HWND hwndFocus, LPARAM lParam)
  1435. {
  1436. POOEBuf pBuf;
  1437. ASSERT(NULL != (POOEBuf)lParam);
  1438. SetWindowLongPtr(hdlg, DWLP_USER, lParam);
  1439. pBuf = (POOEBuf)lParam;
  1440. Edit_LimitText(GetDlgItem(hdlg, IDC_USERNAME), ARRAYSIZE(pBuf->username) - 1);
  1441. SetDlgItemText(hdlg, IDC_USERNAME, pBuf->username);
  1442. Edit_LimitText(GetDlgItem(hdlg, IDC_PASSWORD), ARRAYSIZE(pBuf->password) - 1);
  1443. SetDlgItemText(hdlg, IDC_PASSWORD, pBuf->password);
  1444. Edit_LimitText(GetDlgItem(hdlg, IDC_PASSWORDCONFIRM), ARRAYSIZE(pBuf->password) - 1);
  1445. SetDlgItemText(hdlg, IDC_PASSWORDCONFIRM, pBuf->password);
  1446. return TRUE;
  1447. }
  1448. BOOL Login_OnCommand(HWND hdlg, WORD wNotifyCode, WORD wID, HWND hwndCtl)
  1449. {
  1450. BOOL bHandled = TRUE;
  1451. POOEBuf pBuf = GetBuf(hdlg);
  1452. ASSERT(pBuf);
  1453. switch (wID)
  1454. {
  1455. case IDOK:
  1456. {
  1457. TCHAR szUsername[ARRAYSIZE(pBuf->username) + 1];
  1458. TCHAR szPassword[ARRAYSIZE(pBuf->password) + 1];
  1459. TCHAR szPasswordConfirm[ARRAYSIZE(pBuf->password) + 1];
  1460. GetDlgItemText(hdlg, IDC_USERNAME, szUsername, ARRAYSIZE(szUsername));
  1461. GetDlgItemText(hdlg, IDC_PASSWORD, szPassword, ARRAYSIZE(szPassword));
  1462. GetDlgItemText(hdlg, IDC_PASSWORDCONFIRM, szPasswordConfirm, ARRAYSIZE(szPasswordConfirm));
  1463. if (!szUsername[0] && (szPassword[0] || szPasswordConfirm[0]))
  1464. {
  1465. SGMessageBox(hdlg,
  1466. (pBuf->bChannel ? IDS_NEEDCHANNELUSERNAME : IDS_NEEDUSERNAME),
  1467. MB_ICONWARNING);
  1468. }
  1469. else if (szUsername[0] && !szPassword[0])
  1470. {
  1471. SGMessageBox(hdlg,
  1472. (pBuf->bChannel ? IDS_NEEDCHANNELPASSWORD : IDS_NEEDPASSWORD),
  1473. MB_ICONWARNING);
  1474. }
  1475. else if (StrCmp(szPassword, szPasswordConfirm) != 0)
  1476. {
  1477. SGMessageBox(hdlg, IDS_MISMATCHED_PASSWORDS, MB_ICONWARNING);
  1478. }
  1479. else
  1480. {
  1481. StrCpyN(pBuf->username, szUsername, ARRAYSIZE(pBuf->username));
  1482. StrCpyN(pBuf->password, szPassword, ARRAYSIZE(pBuf->password));
  1483. pBuf->dwFlags |= (PROP_WEBCRAWL_UNAME | PROP_WEBCRAWL_PSWD);
  1484. EndDialog(hdlg, IDOK);
  1485. }
  1486. break;
  1487. }
  1488. case IDCANCEL:
  1489. EndDialog(hdlg, IDCANCEL);
  1490. break;
  1491. default:
  1492. bHandled = FALSE;
  1493. break;
  1494. }
  1495. return bHandled;
  1496. }
  1497. INT_PTR CALLBACK LoginOptionDlgProc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
  1498. {
  1499. BOOL bHandled = FALSE;
  1500. switch (message)
  1501. {
  1502. case WM_INITDIALOG:
  1503. bHandled = Login_OnInitDialog(hdlg, (HWND)wParam, lParam);
  1504. break;
  1505. case WM_COMMAND:
  1506. bHandled = Login_OnCommand(hdlg, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
  1507. break;
  1508. case WM_HELP:
  1509. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO) lParam)->hItemHandle, c_szHelpFile,
  1510. HELP_WM_HELP, (DWORD_PTR)aHelpIDs);
  1511. bHandled = TRUE;
  1512. break;
  1513. case WM_CONTEXTMENU:
  1514. SHWinHelpOnDemandWrap((HWND)wParam, c_szHelpFile, HELP_CONTEXTMENU, (DWORD_PTR)aHelpIDs);
  1515. bHandled = TRUE;
  1516. break;
  1517. }
  1518. return bHandled;
  1519. }
  1520. //
  1521. // Read the users default email address and smtp from the Athena Account Mgr
  1522. //
  1523. // Expects lpszEmailAddress and lpszSMTPServer to pt to char buffers of
  1524. // CCHMAX_EMAIL_ADDRESS and CCHMAX_SERVER_NAME size, resp.
  1525. //
  1526. BOOL ReadAthenaMailSettings(LPSTR lpszEmailAddress, LPSTR lpszSMTPServer)
  1527. {
  1528. //
  1529. // This api gets called from threads that haven't used COM before so wrap
  1530. // in CoInitialize/CoUninitialize
  1531. //
  1532. HRESULT hr = CoInitialize(NULL);
  1533. ASSERT(SUCCEEDED(hr));
  1534. //
  1535. // Create an Internet Mail and News Account Manager
  1536. //
  1537. IImnAccountManager * pAccountManager;
  1538. hr = CoCreateInstance(
  1539. CLSID_ImnAccountManager,
  1540. NULL, // no aggregation
  1541. CLSCTX_INPROC_SERVER, // inproc server implemented in webcheck.dll
  1542. IID_IImnAccountManager, //
  1543. (void **)&pAccountManager);
  1544. if (SUCCEEDED(hr)) {
  1545. hr = pAccountManager->Init(NULL);
  1546. if (SUCCEEDED(hr)) {
  1547. //
  1548. // Get the default SMTP account
  1549. //
  1550. IImnAccount * pAccount;
  1551. hr = pAccountManager->GetDefaultAccount(ACCT_MAIL, &pAccount);
  1552. if (hr == S_OK) {
  1553. //
  1554. // Get the SMTP_SERVER name for this account
  1555. //
  1556. if (NULL != lpszSMTPServer)
  1557. {
  1558. hr = pAccount->GetPropSz(
  1559. AP_SMTP_SERVER,
  1560. lpszSMTPServer,
  1561. CCHMAX_SERVER_NAME);
  1562. }
  1563. //
  1564. // Get the Users email address for this account
  1565. //
  1566. if (NULL != lpszEmailAddress)
  1567. {
  1568. hr |= pAccount->GetPropSz(
  1569. AP_SMTP_EMAIL_ADDRESS,
  1570. lpszEmailAddress,
  1571. CCHMAX_EMAIL_ADDRESS);
  1572. }
  1573. pAccount->Release(); // done with IImnAccount
  1574. }
  1575. }
  1576. pAccountManager->Release(); // done with IImnAccountManager
  1577. }
  1578. //
  1579. // This api gets called from threads that haven't used COM before so wrap
  1580. // in CoInitialize/CoUninitialize
  1581. //
  1582. CoUninitialize();
  1583. if (hr == S_OK)
  1584. return TRUE;
  1585. else
  1586. return FALSE;
  1587. }
  1588. void ReadDefaultEmail(LPTSTR szBuf, UINT cch)
  1589. {
  1590. ASSERT(szBuf);
  1591. szBuf[0] = (TCHAR)0;
  1592. if(ReadRegValue(HKEY_CURRENT_USER, c_szRegKey, c_szDefEmail, szBuf, cch * sizeof(TCHAR)))
  1593. return;
  1594. // TODO: Look for eudora/netscape as well
  1595. CHAR szEmailAddress[CCHMAX_EMAIL_ADDRESS];
  1596. if (ReadAthenaMailSettings(szEmailAddress, NULL))
  1597. {
  1598. SHAnsiToTChar(szEmailAddress, szBuf, cch);
  1599. }
  1600. }
  1601. void WriteDefaultEmail(LPTSTR szBuf)
  1602. {
  1603. ASSERT(szBuf);
  1604. WriteRegValue(HKEY_CURRENT_USER, c_szRegKey, c_szDefEmail, szBuf, (lstrlen(szBuf) + 1) * sizeof(TCHAR), REG_SZ);
  1605. }
  1606. void ReadDefaultSMTPServer(LPTSTR szBuf, UINT cch)
  1607. {
  1608. ASSERT(szBuf);
  1609. szBuf[0] = (TCHAR)0;
  1610. if(ReadRegValue(HKEY_CURRENT_USER, c_szRegKey, c_szDefServer, szBuf, cch * sizeof(TCHAR)))
  1611. return;
  1612. // TODO: Look for eudora/netscape as well
  1613. CHAR szSMTPServer[CCHMAX_SERVER_NAME];
  1614. if (ReadAthenaMailSettings(NULL, szSMTPServer))
  1615. {
  1616. SHAnsiToTChar(szSMTPServer, szBuf, cch);
  1617. }
  1618. }
  1619. void WriteDefaultSMTPServer(LPTSTR szBuf)
  1620. {
  1621. ASSERT(szBuf);
  1622. WriteRegValue(HKEY_CURRENT_USER, c_szRegKey, c_szDefServer, szBuf, (lstrlen(szBuf) + 1) * sizeof(TCHAR), REG_SZ);
  1623. }