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.

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