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.

853 lines
25 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998.
  5. //
  6. // File: autosync.cpp
  7. //
  8. // Contents: Offline AutoSync class
  9. //
  10. // Classes: CAutoSyncPage
  11. //
  12. // Notes:
  13. //
  14. // History: 14-Nov-97 SusiA Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "precomp.h"
  18. extern OSVERSIONINFOA g_OSVersionInfo;
  19. extern LANGID g_LangIdSystem; // LangId of system we are running on.
  20. extern HINSTANCE g_hmodThisDll; // Handle to this DLL itself.
  21. /*
  22. Both the Logon and Idle pages in the settings dialog share this class
  23. for performance reasons. i.e. don't have to enum handlers and setup
  24. ras combo twice. If we ever need to sepcify the difference between settings
  25. to handlers for logon/logoff and Idle then these would have to be separated
  26. */
  27. // initializes the specified hwnd.
  28. BOOL CAutoSyncPage::InitializeHwnd(HWND hwnd,SYNCTYPE syncType,DWORD dwDefaultConnection)
  29. {
  30. HRESULT hr;
  31. HWND hwndRasCombo;
  32. HWND hwndList;
  33. HIMAGELIST himage;
  34. LV_COLUMN columnInfo;
  35. WORD wHandlerID;
  36. CListView **ppListView = NULL;
  37. BOOL fShowRasEntriesInCombo;
  38. UINT ImageListflags;
  39. Assert(hwnd == m_hwndAutoSync || hwnd == m_hwndIdle);
  40. // make sure main class is initialized.
  41. if (FALSE == Initialize(hwnd,dwDefaultConnection))
  42. {
  43. return FALSE;
  44. }
  45. // Setup the Ras combo
  46. // !!!Must be done before Initializing the Handler queue.
  47. smBoolChk(hwndRasCombo = GetDlgItem(hwnd,IDC_AUTOUPDATECOMBO));
  48. // don't show ras entries in combo if this is an AutoSync and
  49. // on Win9x platform.
  50. if ( VER_PLATFORM_WIN32_WINDOWS == g_OSVersionInfo.dwPlatformId)
  51. {
  52. fShowRasEntriesInCombo = FALSE;
  53. }
  54. else
  55. {
  56. fShowRasEntriesInCombo = TRUE;
  57. }
  58. m_pRas->FillRasCombo(hwndRasCombo,FALSE,fShowRasEntriesInCombo);
  59. // now initialize the handler which will create queue
  60. // if necessary and fill in the values for the specified syncType
  61. smBoolChk(InitializeHandler(hwnd,syncType));
  62. Assert(m_HndlrQueue);
  63. // If initialization was successfull, read in connection info
  64. // based on th type.
  65. if ( FAILED(m_HndlrQueue->InitSyncSettings(syncType,hwndRasCombo)))
  66. {
  67. return FALSE;
  68. }
  69. hr = m_HndlrQueue->FindFirstHandlerInState (HANDLERSTATE_PREPAREFORSYNC,&wHandlerID);
  70. while (hr == S_OK)
  71. {
  72. m_HndlrQueue->ReadSyncSettingsPerConnection(syncType,wHandlerID);
  73. hr = m_HndlrQueue->FindNextHandlerInState(wHandlerID,HANDLERSTATE_PREPAREFORSYNC,
  74. &wHandlerID);
  75. }
  76. //initialize the item list and style
  77. smBoolChk(hwndList = GetDlgItem(hwnd,IDC_AUTOUPDATELIST));
  78. ppListView = (syncType == SYNCTYPE_AUTOSYNC) ? &m_pItemListViewAutoSync : &m_pItemListViewIdle;
  79. if (hwndList)
  80. {
  81. *ppListView = new CListView(hwndList,hwnd,IDC_AUTOUPDATELIST,WM_NOTIFYLISTVIEWEX);
  82. }
  83. if (NULL == *ppListView)
  84. {
  85. return FALSE;
  86. }
  87. (*ppListView)->SetExtendedListViewStyle(LVS_EX_CHECKBOXES
  88. | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP );
  89. ImageListflags = ILC_COLOR | ILC_MASK;
  90. if (IsHwndRightToLeft(hwnd))
  91. {
  92. ImageListflags |= ILC_MIRROR;
  93. }
  94. // create an imagelist
  95. himage = ImageList_Create( GetSystemMetrics(SM_CXSMICON),
  96. GetSystemMetrics(SM_CYSMICON),ImageListflags,5,20);
  97. if (himage)
  98. {
  99. (*ppListView)->SetImageList(himage,LVSIL_SMALL);
  100. }
  101. // Insert the Proper columns
  102. columnInfo.mask = LVCF_FMT | LVCF_WIDTH;
  103. columnInfo.fmt = LVCFMT_LEFT;
  104. columnInfo.cx = CalcListViewWidth(hwndList,260);
  105. (*ppListView)->InsertColumn(0,&columnInfo);
  106. smBoolChk(ShowItemsOnThisConnection(hwnd,syncType,dwDefaultConnection));
  107. ShowWindow(hwnd, SW_SHOWNORMAL );
  108. UpdateWindow(hwnd);
  109. return TRUE;
  110. }
  111. //+-------------------------------------------------------------------------------
  112. //
  113. // FUNCTION: BOOL CAutoSyncPage::Initialize(DWORD dwDefaultConnection)
  114. //
  115. // PURPOSE: initialization for the autosync page
  116. //
  117. // RETURN VALUE: return TRUE if we process it ok.
  118. //
  119. // HISTORY: 01-01-98 SusiA Created.
  120. //
  121. //+-------------------------------------------------------------------------------
  122. BOOL CAutoSyncPage::Initialize(HWND hwnd ,DWORD dwDefaultConnection )
  123. {
  124. if (m_fInitialized)
  125. return TRUE;
  126. //Remove Logoff on all but NT5.
  127. if ((VER_PLATFORM_WIN32_WINDOWS == g_OSVersionInfo.dwPlatformId) ||
  128. (g_OSVersionInfo.dwMajorVersion < 5))
  129. {
  130. TCHAR pszStaticText[MAX_PATH + 1];
  131. LoadString(g_hmodThisDll, IDS_LOGON_TEXT,pszStaticText, MAX_PATH);
  132. Static_SetText(GetDlgItem(hwnd, IDC_STATIC2), pszStaticText);
  133. //Hide logoff check box
  134. HWND hwndLogoffCheck = GetDlgItem(hwnd, IDC_AUTOLOGOFF);
  135. Button_SetCheck(hwndLogoffCheck,FALSE);
  136. ShowWindow(hwndLogoffCheck, SW_HIDE);
  137. }
  138. // Initialize Ras Combo box
  139. m_pRas= new CRasUI();
  140. if (NULL == m_pRas || FALSE == m_pRas->Initialize())
  141. {
  142. if (m_pRas)
  143. {
  144. delete m_pRas;
  145. m_pRas = NULL;
  146. }
  147. return FALSE;
  148. }
  149. m_fInitialized = TRUE;
  150. return TRUE;
  151. }
  152. //+-------------------------------------------------------------------------------
  153. //
  154. // FUNCTION: BOOL CAutoSyncPage::InitializeHandler()
  155. //
  156. // PURPOSE: initialization for the autosync page
  157. //
  158. // RETURN VALUE: return TRUE if we process it ok.
  159. //
  160. // HISTORY: 01-01-98 SusiA Created.
  161. //
  162. //+-------------------------------------------------------------------------------
  163. BOOL CAutoSyncPage::InitializeHandler(HWND hwnd,SYNCTYPE /* SyncType */)
  164. {
  165. SCODE sc = S_OK;
  166. TCHAR lpName[MAX_PATH];
  167. DWORD cbName = MAX_PATH;
  168. HKEY hkSyncMgr;
  169. CLSID clsid;
  170. WORD wHandlerID;
  171. HWND hwndRasCombo;
  172. Assert(hwnd == m_hwndAutoSync || hwnd == m_hwndIdle);
  173. if (NULL == (hwndRasCombo = GetDlgItem(hwnd,IDC_AUTOUPDATECOMBO)) )
  174. {
  175. return FALSE;
  176. }
  177. if (NULL == m_HndlrQueue) // if queue is already initialized, just return.
  178. {
  179. m_HndlrQueue = new CHndlrQueue(QUEUETYPE_SETTINGS);
  180. if (NULL == m_HndlrQueue)
  181. {
  182. return FALSE;
  183. }
  184. // loop through the reg getting the handlers and trying to
  185. // create them.
  186. if (hkSyncMgr = RegGetHandlerTopLevelKey(KEY_READ))
  187. {
  188. DWORD dwIndex = 0;
  189. while ( ERROR_SUCCESS == RegEnumKey(hkSyncMgr,dwIndex,
  190. lpName,cbName) )
  191. {
  192. if (NOERROR == CLSIDFromString(lpName,&clsid) )
  193. {
  194. if (NOERROR == m_HndlrQueue->AddHandler(clsid, &wHandlerID))
  195. {
  196. m_HndlrQueue->CreateServer(wHandlerID,&clsid);
  197. }
  198. }
  199. dwIndex++;
  200. }
  201. RegCloseKey(hkSyncMgr);
  202. }
  203. // Initialize the items.
  204. sc = m_HndlrQueue->FindFirstHandlerInState(HANDLERSTATE_INITIALIZE,&wHandlerID);
  205. while (sc == S_OK)
  206. {
  207. m_HndlrQueue->Initialize(wHandlerID,0,SYNCMGRFLAG_SETTINGS,0,NULL);
  208. sc = m_HndlrQueue->FindNextHandlerInState(wHandlerID,
  209. HANDLERSTATE_INITIALIZE,
  210. &wHandlerID);
  211. }
  212. // loop through adding items
  213. sc = m_HndlrQueue->FindFirstHandlerInState (HANDLERSTATE_ADDHANDLERTEMS,&wHandlerID);
  214. while (sc == S_OK)
  215. {
  216. m_HndlrQueue->AddHandlerItemsToQueue(wHandlerID);
  217. sc = m_HndlrQueue->FindNextHandlerInState(wHandlerID,HANDLERSTATE_ADDHANDLERTEMS,
  218. &wHandlerID);
  219. }
  220. }
  221. Assert(m_HndlrQueue);
  222. return TRUE;
  223. }
  224. void CAutoSyncPage::SetAutoSyncHwnd(HWND hwnd)
  225. {
  226. m_hwndAutoSync = hwnd;
  227. }
  228. void CAutoSyncPage::SetIdleHwnd(HWND hwnd)
  229. {
  230. m_hwndIdle = hwnd;
  231. }
  232. //--------------------------------------------------------------------------------
  233. //
  234. // FUNCTION: CAutoSyncPage::CommitChanges()
  235. //
  236. // PURPOSE: Write all the current AutoSync Settings to the registry
  237. //
  238. // COMMENTS: Implemented on main thread.
  239. //
  240. // HISTORY: 01-01-98 SusiA Created.
  241. //
  242. //--------------------------------------------------------------------------------
  243. HRESULT CAutoSyncPage::CommitAutoSyncChanges(void)
  244. {
  245. HRESULT hr = S_FALSE;
  246. if (m_HndlrQueue)
  247. {
  248. hr = m_HndlrQueue->CommitSyncChanges(SYNCTYPE_AUTOSYNC,m_pRas);
  249. }
  250. return hr;
  251. }
  252. //--------------------------------------------------------------------------------
  253. //
  254. // FUNCTION: CAutoSyncPage::CommitIdleChanges()
  255. //
  256. // PURPOSE: Write all the current Idle Settings to the registry
  257. //
  258. //
  259. //
  260. // HISTORY: 02-23-98 rogerg Created.
  261. //
  262. //--------------------------------------------------------------------------------
  263. HRESULT CAutoSyncPage::CommitIdleChanges(void)
  264. {
  265. HRESULT hr = S_FALSE;
  266. if (m_HndlrQueue)
  267. {
  268. hr = m_HndlrQueue->CommitSyncChanges(SYNCTYPE_IDLE,m_pRas);
  269. }
  270. return hr;
  271. }
  272. //+-------------------------------------------------------------------------------
  273. //
  274. // FUNCTION: CAutoSyncPage::~CAutoSyncPage(HWND hwnd)
  275. //
  276. // PURPOSE: destructor
  277. //
  278. // COMMENTS: destructor for AutoSync page
  279. //
  280. //--------------------------------------------------------------------------------
  281. CAutoSyncPage::~CAutoSyncPage()
  282. {
  283. if (m_pRas)
  284. {
  285. delete m_pRas;
  286. m_pRas = NULL;
  287. }
  288. if (m_HndlrQueue)
  289. {
  290. m_HndlrQueue->Release();
  291. }
  292. Assert(NULL == m_pItemListViewAutoSync);
  293. Assert(NULL == m_pItemListViewIdle);
  294. }
  295. //--------------------------------------------------------------------------------
  296. //
  297. // FUNCTION: CAutoSyncPage::ShowProperties(int iItem)
  298. //
  299. // PURPOSE: Show the app specific properties Dialog
  300. //
  301. // COMMENTS: Implemented on main thread.
  302. //
  303. // HISTORY: 01-01-98 SusiA Created.
  304. //
  305. //--------------------------------------------------------------------------------
  306. SCODE CAutoSyncPage::ShowProperties(HWND hwnd,int iItem)
  307. {
  308. SCODE sc = E_UNEXPECTED;
  309. Assert(hwnd == m_hwndAutoSync || hwnd == m_hwndIdle);
  310. // review, what happens when a cancel comes in when properties are being shown??
  311. if (m_HndlrQueue)
  312. {
  313. sc = m_HndlrQueue->ShowProperties(hwnd,iItem);
  314. }
  315. return sc;
  316. }
  317. //+-------------------------------------------------------------------------------
  318. //
  319. // FUNCTION: BOOL CAutoSyncPage::SetItemCheckState(int iItem, BOOL fChecked)
  320. //
  321. // PURPOSE: set the selected check state
  322. //
  323. // RETURN VALUE: return TRUE if we process it ok.
  324. //
  325. // HISTORY: 01-01-98 SusiA Created.
  326. //
  327. //+-------------------------------------------------------------------------------
  328. BOOL CAutoSyncPage::SetItemCheckState(HWND hwnd,SYNCTYPE syncType,int iItem, BOOL fChecked,int iCheckCount)
  329. {
  330. HWND hwndRasCombo;
  331. int iConnectionItem;
  332. Assert(hwnd == m_hwndAutoSync || hwnd == m_hwndIdle);
  333. hwndRasCombo = GetDlgItem(hwnd,IDC_AUTOUPDATECOMBO);
  334. if (NULL == hwndRasCombo || NULL == m_HndlrQueue)
  335. {
  336. Assert(hwndRasCombo);
  337. Assert(m_HndlrQueue);
  338. return FALSE;
  339. }
  340. iConnectionItem = ComboBox_GetCurSel(hwndRasCombo);
  341. //The check state is message is getting flagged by us programmatically setting it,
  342. // until after we are done initializing.
  343. if (m_fItemsOnConnection)
  344. {
  345. BOOL fAnyChecked;
  346. CListView *pItemListView = (syncType == SYNCTYPE_AUTOSYNC) ? m_pItemListViewAutoSync : m_pItemListViewIdle;
  347. fAnyChecked = iCheckCount ? TRUE : FALSE;
  348. if (ERROR_SUCCESS == m_HndlrQueue->SetSyncCheckStateFromListViewItem(
  349. syncType,iItem,fChecked, iConnectionItem))
  350. {
  351. return TRUE;
  352. }
  353. return FALSE;
  354. }
  355. return TRUE;
  356. }
  357. //+-------------------------------------------------------------------------------
  358. //
  359. // FUNCTION: BOOL CAutoSyncPage::SetConnectionCheck(WORD wParam,DWORD dwCheckState)
  360. //
  361. // PURPOSE: set the selected check state
  362. //
  363. // RETURN VALUE: return TRUE if we process it ok.
  364. //
  365. // HISTORY: 01-01-98 SusiA Created.
  366. //
  367. //+-------------------------------------------------------------------------------
  368. BOOL CAutoSyncPage::SetConnectionCheck(HWND hwnd,SYNCTYPE syncType,WORD wParam, DWORD dwCheckState)
  369. {
  370. HWND hwndRasCombo ;
  371. int iConnectionItem;
  372. Assert(hwnd == m_hwndAutoSync || hwnd == m_hwndIdle);
  373. hwndRasCombo = GetDlgItem(hwnd,IDC_AUTOUPDATECOMBO);
  374. if (NULL == hwndRasCombo || NULL == m_HndlrQueue)
  375. {
  376. Assert(hwndRasCombo);
  377. Assert(m_HndlrQueue);
  378. return FALSE;
  379. }
  380. iConnectionItem = ComboBox_GetCurSel(hwndRasCombo);
  381. if (m_fItemsOnConnection)
  382. {
  383. CListView *pItemListView = (syncType == SYNCTYPE_AUTOSYNC) ? m_pItemListViewAutoSync : m_pItemListViewIdle;
  384. //Check changing for logon or logoff
  385. //So enable the prompt me first accordingly
  386. if (wParam != IDC_AUTOPROMPT_ME_FIRST)
  387. {
  388. HWND hwndLogon = GetDlgItem(hwnd,IDC_AUTOUPDATELIST);
  389. int iLogonCheck = Button_GetCheck(GetDlgItem(hwnd,IDC_AUTOLOGON));
  390. int iLogoffCheck = Button_GetCheck(GetDlgItem(hwnd,IDC_AUTOLOGOFF));
  391. }
  392. if (ERROR_SUCCESS == m_HndlrQueue->SetConnectionCheck(wParam,dwCheckState,iConnectionItem))
  393. {
  394. return TRUE;
  395. }
  396. return FALSE;
  397. }
  398. return TRUE;
  399. }
  400. //+-------------------------------------------------------------------------------
  401. //
  402. // FUNCTION: BOOL CAutoSyncPage::ShowItemsOnThisConnection(DWORD dwConnectionNum)
  403. //
  404. // PURPOSE: initialization for the autosync page
  405. //
  406. // RETURN VALUE: return TRUE if we process it ok.
  407. //
  408. // HISTORY: 01-01-98 SusiA Created.
  409. //
  410. //+-------------------------------------------------------------------------------
  411. BOOL CAutoSyncPage::ShowItemsOnThisConnection(HWND hwnd,SYNCTYPE syncType,DWORD dwConnectionNum)
  412. {
  413. TCHAR pszConnectionName[RAS_MaxEntryName+1];
  414. HWND hwndRasCombo;
  415. CListView *pItemListView = (syncType == SYNCTYPE_AUTOSYNC) ? m_pItemListViewAutoSync : m_pItemListViewIdle;
  416. BOOL *pListViewInitialize = (syncType == SYNCTYPE_AUTOSYNC) ? &m_pItemListViewAutoSyncInitialized : &m_fListViewIdleInitialized;
  417. Assert(hwnd == m_hwndAutoSync || hwnd == m_hwndIdle);
  418. hwndRasCombo = GetDlgItem(hwnd,IDC_AUTOUPDATECOMBO);
  419. if (NULL == hwndRasCombo || NULL == m_HndlrQueue || NULL == pItemListView)
  420. {
  421. Assert(m_HndlrQueue);
  422. Assert(hwndRasCombo);
  423. Assert(pItemListView);
  424. return FALSE;
  425. }
  426. *pListViewInitialize = FALSE; // reset initialized in case user switched connections.
  427. //first clear out the list view
  428. // Review - why not just recheck items based on new connection???
  429. m_fItemsOnConnection = FALSE;
  430. pItemListView->DeleteAllItems();
  431. HIMAGELIST himage;
  432. LVITEMEX lvItemInfo;
  433. WORD wHandlerID;
  434. //Note: Use text to "uniquely" identify connection on RAS
  435. DWORD dwNumConnections = (DWORD) ComboBox_GetCount(hwndRasCombo);
  436. // make sure dwConnectionNum is valid,
  437. if (dwConnectionNum >= dwNumConnections)
  438. {
  439. return FALSE;
  440. }
  441. COMBOBOXEXITEM comboItem;
  442. comboItem.mask = CBEIF_TEXT;
  443. comboItem.cchTextMax = ARRAY_SIZE(pszConnectionName);
  444. comboItem.pszText = pszConnectionName;
  445. comboItem.iItem = dwConnectionNum;
  446. // Review, handle failures.
  447. ComboEx_GetItem(hwndRasCombo,&comboItem);
  448. // loop through proxies initializing and adding to the list
  449. SYNCMGRITEMID ItemID;
  450. CLSID clsidHandler;
  451. WORD wItemID;
  452. // add same images over and over again. Should either just use the same listView
  453. // resetting the CheckBoxes according or clear the ImageList each time.
  454. himage = pItemListView->GetImageList(LVSIL_SMALL );
  455. HRESULT hr = m_HndlrQueue->FindFirstItemOnConnection
  456. (pszConnectionName, &clsidHandler,
  457. &ItemID,&wHandlerID,&wItemID);
  458. if (NOERROR == hr)
  459. {
  460. DWORD dwCheckState;
  461. do
  462. {
  463. INT iListViewItem;
  464. CLSID clsidDataHandler;
  465. SYNCMGRITEM offlineItem;
  466. ITEMCHECKSTATE ItemCheckState;
  467. // grab the offline item info.
  468. if (NOERROR == m_HndlrQueue->GetSyncItemDataOnConnection(
  469. dwConnectionNum,
  470. wHandlerID,wItemID,
  471. &clsidDataHandler,&offlineItem,
  472. &ItemCheckState,
  473. FALSE, FALSE))
  474. {
  475. LVHANDLERITEMBLOB lvHandlerItemBlob;
  476. int iParentItemId;
  477. BOOL fHandlerParent = TRUE; // always have a parent for now.
  478. DWORD dwCheckState;
  479. // Check if item is already in the ListView and if so
  480. // go on
  481. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  482. lvHandlerItemBlob.clsidServer = clsidDataHandler;
  483. lvHandlerItemBlob.ItemID = offlineItem.ItemID;
  484. if (-1 != pItemListView->FindItemFromBlob((LPLVBLOB) &lvHandlerItemBlob))
  485. {
  486. // already in ListView, go on to the next item.
  487. continue;
  488. }
  489. if (!fHandlerParent)
  490. {
  491. iParentItemId = LVI_ROOT;
  492. }
  493. else
  494. {
  495. // need to add to list so find parent and if one doesn't exist, create it.
  496. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  497. lvHandlerItemBlob.clsidServer = clsidDataHandler;
  498. lvHandlerItemBlob.ItemID = GUID_NULL;
  499. iParentItemId = pItemListView->FindItemFromBlob((LPLVBLOB) &lvHandlerItemBlob);
  500. if (-1 == iParentItemId)
  501. {
  502. LVITEMEX itemInfoParent;
  503. SYNCMGRHANDLERINFO SyncMgrHandlerInfo;
  504. // if can't get the ParentInfo then don't add the Item
  505. if (NOERROR != m_HndlrQueue->GetHandlerInfo(clsidDataHandler,&SyncMgrHandlerInfo))
  506. {
  507. continue;
  508. }
  509. // Insert the Parent.
  510. itemInfoParent.mask = LVIF_TEXT;
  511. itemInfoParent.iItem = LVI_LAST;;
  512. itemInfoParent.iSubItem = 0;
  513. itemInfoParent.iImage = -1;
  514. itemInfoParent.pszText = SyncMgrHandlerInfo.wszHandlerName;
  515. if (himage)
  516. {
  517. HICON hIcon = SyncMgrHandlerInfo.hIcon ? SyncMgrHandlerInfo.hIcon : offlineItem.hIcon;
  518. // if have toplevel handler info icon use this else use the
  519. // items icon
  520. if (hIcon && (itemInfoParent.iImage =
  521. ImageList_AddIcon(himage,hIcon)) )
  522. {
  523. itemInfoParent.mask |= LVIF_IMAGE ;
  524. }
  525. }
  526. // save the blob
  527. itemInfoParent.maskEx = LVIFEX_BLOB;
  528. itemInfoParent.pBlob = (LPLVBLOB) &lvHandlerItemBlob;
  529. iParentItemId = pItemListView->InsertItem(&itemInfoParent);
  530. // if parent insert failed go onto the next item
  531. if (-1 == iParentItemId)
  532. {
  533. continue;
  534. }
  535. }
  536. }
  537. // now attemp to insert the item.
  538. lvItemInfo.mask = LVIF_TEXT;
  539. lvItemInfo.maskEx = LVIFEX_PARENT | LVIFEX_BLOB;
  540. lvItemInfo.iItem = LVI_LAST;
  541. lvItemInfo.iSubItem = 0;
  542. lvItemInfo.iParent = iParentItemId;
  543. lvItemInfo.pszText = offlineItem.wszItemName;
  544. lvItemInfo.iImage = -1; // set to -1 in case can't get image.
  545. // setup the blob
  546. lvHandlerItemBlob.ItemID = offlineItem.ItemID;
  547. lvItemInfo.pBlob = (LPLVBLOB) &lvHandlerItemBlob;
  548. if (himage && offlineItem.hIcon)
  549. {
  550. lvItemInfo.iImage =
  551. ImageList_AddIcon(himage,offlineItem.hIcon);
  552. }
  553. iListViewItem = pItemListView->InsertItem(&lvItemInfo);
  554. if (-1 == iListViewItem)
  555. {
  556. continue;
  557. }
  558. //Set the check state of the item
  559. lvItemInfo.mask = LVIF_STATE;
  560. lvItemInfo.maskEx = 0;
  561. lvItemInfo.iItem = iListViewItem;
  562. lvItemInfo.iSubItem = 0;
  563. dwCheckState = (syncType == SYNCTYPE_IDLE)
  564. ? ItemCheckState.dwIdle : ItemCheckState.dwAutoSync;
  565. lvItemInfo.stateMask= LVIS_STATEIMAGEMASK;
  566. lvItemInfo.state = (dwCheckState == SYNCMGRITEMSTATE_UNCHECKED) ?
  567. LVIS_STATEIMAGEMASK_UNCHECK : LVIS_STATEIMAGEMASK_CHECK;
  568. pItemListView->SetItem(&lvItemInfo);
  569. m_HndlrQueue->SetItemListViewID(clsidDataHandler,offlineItem.ItemID,iListViewItem);
  570. }
  571. } while (NOERROR == m_HndlrQueue->FindNextItemOnConnection
  572. (pszConnectionName,wHandlerID,wItemID,
  573. &clsidHandler,&ItemID,&wHandlerID,&wItemID, TRUE,
  574. &dwCheckState) );
  575. }
  576. if (pItemListView->GetItemCount())
  577. {
  578. pItemListView->SetItemState(0,LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED );
  579. }
  580. if (syncType == SYNCTYPE_AUTOSYNC)
  581. {
  582. int iLogonCheck = m_HndlrQueue->GetCheck(IDC_AUTOLOGON, dwConnectionNum);
  583. int iLogoffCheck = m_HndlrQueue->GetCheck(IDC_AUTOLOGOFF, dwConnectionNum);
  584. Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOLOGON),iLogonCheck);
  585. Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOLOGOFF),iLogoffCheck);
  586. Button_SetCheck(GetDlgItem(hwnd,IDC_AUTOPROMPT_ME_FIRST),
  587. m_HndlrQueue->GetCheck(IDC_AUTOPROMPT_ME_FIRST, dwConnectionNum));
  588. }
  589. else if (syncType == SYNCTYPE_IDLE)
  590. {
  591. int iIdleCheck = m_HndlrQueue->GetCheck(IDC_IDLECHECKBOX, dwConnectionNum);
  592. Button_SetCheck(GetDlgItem(hwnd,IDC_IDLECHECKBOX),iIdleCheck);
  593. }
  594. *pListViewInitialize = TRUE;
  595. m_fItemsOnConnection = TRUE;
  596. return TRUE;
  597. }
  598. //+-------------------------------------------------------------------------------
  599. //
  600. // FUNCTION: BOOL CAutoSyncPage::GetNumConnections(SYNCTYPE syncType))
  601. //
  602. // PURPOSE: returns the number of connections available to select for the
  603. // specified sync type
  604. //
  605. // RETURN number of connections.
  606. //
  607. // HISTORY: 03-10-98 rogerg Created.
  608. //
  609. //+-------------------------------------------------------------------------------
  610. DWORD CAutoSyncPage::GetNumConnections(HWND hwnd,SYNCTYPE syncType)
  611. {
  612. HWND hwndRasCombo;
  613. Assert(syncType == SYNCTYPE_IDLE || syncType == SYNCTYPE_AUTOSYNC);
  614. Assert(NULL != hwnd);
  615. hwndRasCombo = GetDlgItem(hwnd,IDC_AUTOUPDATECOMBO);
  616. Assert(hwndRasCombo);
  617. if (hwndRasCombo)
  618. {
  619. return ComboBox_GetCount(hwndRasCombo);
  620. }
  621. return 0;
  622. }
  623. //+-------------------------------------------------------------------------------
  624. //
  625. // FUNCTION: BOOL CAutoSyncPage::GetAdvancedIdleSettings(LPCONNECTIONSETTINGS *ppConnectionSettings)
  626. //
  627. // PURPOSE: fills in the ConnectionSettings Structure with the Advanced
  628. // Idle default settings.
  629. //
  630. // RETURN
  631. //
  632. // HISTORY: 03-10-98 rogerg Created.
  633. //
  634. //+-------------------------------------------------------------------------------
  635. HRESULT CAutoSyncPage::GetAdvancedIdleSettings(LPCONNECTIONSETTINGS pConnectionSettings)
  636. {
  637. Assert(pConnectionSettings);
  638. Assert(m_HndlrQueue);
  639. if (NULL == pConnectionSettings
  640. || NULL == m_HndlrQueue)
  641. {
  642. return S_FALSE;
  643. }
  644. return m_HndlrQueue->ReadAdvancedIdleSettings(pConnectionSettings);
  645. }
  646. //+-------------------------------------------------------------------------------
  647. //
  648. // FUNCTION: BOOL CAutoSyncPage::SetAdvancedidleSettings(LPCONNECTIONSETTINGS pConnectionSettings)
  649. //
  650. // PURPOSE: sets the advancedIdle Settings.
  651. //
  652. // RETURN
  653. //
  654. // HISTORY: 03-10-98 rogerg Created.
  655. //
  656. //+-------------------------------------------------------------------------------
  657. HRESULT CAutoSyncPage::SetAdvancedIdleSettings(LPCONNECTIONSETTINGS pConnectionSettings)
  658. {
  659. Assert(pConnectionSettings);
  660. Assert(m_HndlrQueue);
  661. if (NULL == pConnectionSettings
  662. || NULL == m_HndlrQueue)
  663. {
  664. return S_FALSE;
  665. }
  666. return m_HndlrQueue->WriteAdvancedIdleSettings(pConnectionSettings);
  667. }