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.

2208 lines
72 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998.
  5. //
  6. // File: Hndlrq.cpp
  7. //
  8. // Contents: Implements class for keeping track of handlers
  9. // and the UI associated with them
  10. //
  11. // Classes: CHndlrQueue
  12. //
  13. // History: 05-Nov-97 rogerg Created.
  14. // 17-Nov-97 susia Moved to onestop dll for settings.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "precomp.h"
  18. //--------------------------------------------------------------------------------
  19. //
  20. // FUNCTION: CHndlrQueue::CHndlrQueue(QUEUETYPE QueueType)
  21. //
  22. // PURPOSE: CHndlrQueue constructor
  23. //
  24. // COMMENTS: Implemented on main thread.
  25. //
  26. // History: 01-01-98 susia Created.
  27. //
  28. //--------------------------------------------------------------------------------
  29. CHndlrQueue::CHndlrQueue(QUEUETYPE QueueType)
  30. {
  31. m_cRef = 1;
  32. m_pFirstHandler = NULL;
  33. m_wHandlerCount = 0;
  34. m_QueueType = QueueType;
  35. m_ConnectionList = NULL;
  36. m_ConnectionCount = 0;
  37. m_fItemsMissing = FALSE;
  38. }
  39. STDMETHODIMP CHndlrQueue::Init()
  40. {
  41. return InitializeCriticalSectionAndSpinCount(&m_CriticalSection, 0) ? S_OK : E_FAIL;
  42. }
  43. //--------------------------------------------------------------------------------
  44. //
  45. // FUNCTION: CHndlrQueue::AddRef()
  46. //
  47. // PURPOSE: AddRef
  48. //
  49. // History: 30-Mar-98 susia Created.
  50. //
  51. //--------------------------------------------------------------------------------
  52. STDMETHODIMP_(ULONG) CHndlrQueue::AddRef()
  53. {
  54. TRACE("CHndlrQueue::AddRef()\r\n");
  55. return ++m_cRef;
  56. }
  57. //--------------------------------------------------------------------------------
  58. //
  59. // FUNCTION: CHndlrQueue::Release()
  60. //
  61. // PURPOSE: Release
  62. //
  63. // History: 30-Mar-98 susia Created.
  64. //
  65. //--------------------------------------------------------------------------------
  66. STDMETHODIMP_(ULONG) CHndlrQueue::Release()
  67. {
  68. TRACE("CHndlrQueue::Release()\r\n");
  69. if (--m_cRef)
  70. return m_cRef;
  71. FreeAllHandlers();
  72. delete this;
  73. return 0L;
  74. }
  75. //--------------------------------------------------------------------------------
  76. //
  77. // FUNCTION: CHndlrQueue::~CHndlrQueue()
  78. //
  79. // PURPOSE: CHndlrQueue destructor
  80. //
  81. // COMMENTS: Implemented on main thread.
  82. //
  83. // History: 01-01-98 susia Created.
  84. //
  85. //--------------------------------------------------------------------------------
  86. CHndlrQueue::~CHndlrQueue()
  87. {
  88. Assert(NULL == m_pFirstHandler); // all items should be freed at this point.
  89. DeleteCriticalSection(&m_CriticalSection);
  90. }
  91. //--------------------------------------------------------------------------------
  92. //
  93. // FUNCTION: CHndlrQueue::AddHandler(REFCLSID clsidHandler, WORD *wHandlerId)
  94. //
  95. // PURPOSE: Add a handler to the queue
  96. //
  97. // COMMENTS:
  98. //
  99. // History: 01-01-98 susia Created.
  100. //
  101. //--------------------------------------------------------------------------------
  102. STDMETHODIMP CHndlrQueue::AddHandler(REFCLSID clsidHandler, WORD *wHandlerId)
  103. {
  104. HRESULT hr = E_OUTOFMEMORY;
  105. LPHANDLERINFO pnewHandlerInfo;
  106. LPHANDLERINFO pCurHandlerInfo = NULL;
  107. // first see if we already have this handler in the queue.
  108. // find first handler that matches the request CLSID
  109. pCurHandlerInfo = m_pFirstHandler;
  110. while (pCurHandlerInfo )
  111. {
  112. if (clsidHandler == pCurHandlerInfo->clsidHandler)
  113. {
  114. return S_FALSE;
  115. }
  116. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  117. }
  118. //didn't find the handler in the queue, add it now.
  119. pnewHandlerInfo = (LPHANDLERINFO) ALLOC(sizeof(*pnewHandlerInfo));
  120. if (pnewHandlerInfo)
  121. {
  122. // initialize
  123. ZeroMemory(pnewHandlerInfo, sizeof(*pnewHandlerInfo));
  124. pnewHandlerInfo->HandlerState = HANDLERSTATE_CREATE;
  125. pnewHandlerInfo->wHandlerId = ++m_wHandlerCount;
  126. // add to end of list and set wHandlerId. End of list since in choice dialog want
  127. // first writer wins so don't have to continue searches when setting item state.
  128. if (NULL == m_pFirstHandler)
  129. {
  130. m_pFirstHandler = pnewHandlerInfo;
  131. }
  132. else
  133. {
  134. pCurHandlerInfo = m_pFirstHandler;
  135. while (pCurHandlerInfo->pNextHandler)
  136. {
  137. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  138. }
  139. pCurHandlerInfo->pNextHandler = pnewHandlerInfo;
  140. }
  141. *wHandlerId = pnewHandlerInfo->wHandlerId;
  142. hr = NOERROR;
  143. }
  144. return hr;
  145. }
  146. //--------------------------------------------------------------------------------
  147. //
  148. // FUNCTION: CHndlrQueue::RemoveHandler(WORD wHandlerId)
  149. //
  150. // PURPOSE: Release a handler from the queue
  151. //
  152. // COMMENTS:
  153. //
  154. // History: 09-23-98 susia Created.
  155. //
  156. //--------------------------------------------------------------------------------
  157. STDMETHODIMP CHndlrQueue::RemoveHandler(WORD wHandlerId)
  158. {
  159. HRESULT hr = NOERROR;
  160. LPHANDLERINFO pPrevHandlerInfo;
  161. LPHANDLERINFO pCurHandlerInfo;
  162. LPITEMLIST pCurItem = NULL;
  163. LPITEMLIST pNextItem = NULL;
  164. pCurHandlerInfo = pPrevHandlerInfo = m_pFirstHandler;
  165. while (pCurHandlerInfo && (pCurHandlerInfo->wHandlerId != wHandlerId))
  166. {
  167. pPrevHandlerInfo = pCurHandlerInfo;
  168. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  169. }
  170. if (pCurHandlerInfo)
  171. {
  172. //Update the first node if necessary
  173. if (pCurHandlerInfo == m_pFirstHandler)
  174. {
  175. m_pFirstHandler = m_pFirstHandler->pNextHandler;
  176. }
  177. //Fix up linked list
  178. pPrevHandlerInfo->pNextHandler = pCurHandlerInfo->pNextHandler;
  179. //Free the handler items if there are any
  180. pCurItem = pCurHandlerInfo->pFirstItem;
  181. while (pCurItem)
  182. {
  183. FREE(pCurItem->pItemCheckState);
  184. pNextItem = pCurItem->pnextItem;
  185. FREE(pCurItem);
  186. pCurItem = pNextItem;
  187. }
  188. //Release the handler
  189. if (pCurHandlerInfo->pSyncMgrHandler)
  190. {
  191. pCurHandlerInfo->pSyncMgrHandler->Release();
  192. }
  193. FREE(pCurHandlerInfo);
  194. }
  195. else
  196. {
  197. return E_UNEXPECTED;
  198. }
  199. return hr;
  200. }
  201. //--------------------------------------------------------------------------------
  202. //
  203. // FUNCTION: CHndlrQueue::FreeAllHandlers(void)
  204. //
  205. // PURPOSE: loops through all the Handlers and frees them
  206. //
  207. // COMMENTS:
  208. //
  209. // History: 01-01-98 susia Created.
  210. //
  211. //--------------------------------------------------------------------------------
  212. STDMETHODIMP CHndlrQueue::FreeAllHandlers(void)
  213. {
  214. HANDLERINFO HandlerInfoStart;
  215. LPHANDLERINFO pPrevHandlerInfo = &HandlerInfoStart;
  216. LPHANDLERINFO pCurHandlerInfo = NULL;
  217. LPITEMLIST pCurItem = NULL;
  218. LPITEMLIST pNextItem = NULL;
  219. if (m_ConnectionList)
  220. {
  221. FREE(m_ConnectionList);
  222. m_ConnectionList = NULL;
  223. }
  224. pPrevHandlerInfo->pNextHandler = m_pFirstHandler;
  225. while (pPrevHandlerInfo->pNextHandler)
  226. {
  227. pCurHandlerInfo = pPrevHandlerInfo->pNextHandler;
  228. pCurItem = pCurHandlerInfo->pFirstItem;
  229. while (pCurItem)
  230. {
  231. FREE(pCurItem->pItemCheckState);
  232. pNextItem = pCurItem->pnextItem;
  233. FREE(pCurItem);
  234. pCurItem = pNextItem;
  235. }
  236. pPrevHandlerInfo->pNextHandler = pCurHandlerInfo->pNextHandler;
  237. if (pCurHandlerInfo->pSyncMgrHandler)
  238. {
  239. pCurHandlerInfo->pSyncMgrHandler->Release();
  240. }
  241. FREE(pCurHandlerInfo);
  242. }
  243. // update the pointer to the first handler item
  244. m_pFirstHandler = HandlerInfoStart.pNextHandler;
  245. Assert(NULL == m_pFirstHandler); // should always have released everything.
  246. return NOERROR;
  247. }
  248. //+---------------------------------------------------------------------------
  249. //
  250. // Member: CHndlrQueue::GetHandlerInfo, public
  251. //
  252. // Synopsis: Gets Data associated with the HandlerID and ItemID
  253. //
  254. // Arguments: [wHandlerId] - Id Of Handler the Item belongs too
  255. //
  256. // Returns: Appropriate return codes
  257. //
  258. // Modifies:
  259. //
  260. // History: 17-Nov-97 rogerg Created.
  261. //
  262. //----------------------------------------------------------------------------
  263. STDMETHODIMP CHndlrQueue::GetHandlerInfo(REFCLSID clsidHandler,
  264. LPSYNCMGRHANDLERINFO pSyncMgrHandlerInfo)
  265. {
  266. HRESULT hr = S_FALSE;
  267. LPHANDLERINFO pCurHandlerInfo = NULL;
  268. // find first handler that matches the request CLSID
  269. pCurHandlerInfo = m_pFirstHandler;
  270. while (pCurHandlerInfo )
  271. {
  272. if (clsidHandler == pCurHandlerInfo->clsidHandler)
  273. {
  274. *pSyncMgrHandlerInfo = pCurHandlerInfo->SyncMgrHandlerInfo;
  275. hr = NOERROR;
  276. break;
  277. }
  278. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  279. }
  280. return hr;
  281. }
  282. //--------------------------------------------------------------------------------
  283. //
  284. // FUNCTION:CHndlrQueue::GetSyncItemDataOnConnection(int iConnectionIndex,
  285. // WORD wHandlerId,
  286. // WORD wItemID,
  287. // CLSID *pclsidHandler,
  288. // SYNCMGRITEM* offlineItem,
  289. // ITEMCHECKSTATE *pItemCheckState,
  290. // BOOL fSchedSync,
  291. // BOOL fClear)
  292. //
  293. // PURPOSE: Get the item data per connection
  294. //
  295. // COMMENTS: Ras implementation is based on names. Switch to GUIDs for Connection
  296. // objects
  297. //
  298. // History: 01-01-98 susia Created.
  299. //
  300. //--------------------------------------------------------------------------------
  301. STDMETHODIMP CHndlrQueue::GetSyncItemDataOnConnection(
  302. int iConnectionIndex,
  303. WORD wHandlerId, WORD wItemID,
  304. CLSID *pclsidHandler,
  305. SYNCMGRITEM* offlineItem,
  306. ITEMCHECKSTATE *pItemCheckState,
  307. BOOL fSchedSync,
  308. BOOL fClear)
  309. {
  310. BOOL fFoundMatch = FALSE;
  311. LPHANDLERINFO pCurHandlerInfo = NULL;
  312. LPITEMLIST pCurItem = NULL;
  313. pCurHandlerInfo = m_pFirstHandler;
  314. while (pCurHandlerInfo && !fFoundMatch)
  315. {
  316. // only valid if Hanlder is in the PrepareForSync state.
  317. if (wHandlerId == pCurHandlerInfo->wHandlerId) // see if CLSID matches
  318. {
  319. // see if handler info has a matching item
  320. pCurItem = pCurHandlerInfo->pFirstItem;
  321. while (pCurItem)
  322. {
  323. if (wItemID == pCurItem->wItemId)
  324. {
  325. fFoundMatch = TRUE;
  326. break;
  327. }
  328. pCurItem = pCurItem->pnextItem;
  329. }
  330. }
  331. if (!fFoundMatch)
  332. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  333. }
  334. if (fFoundMatch)
  335. {
  336. if (pclsidHandler)
  337. {
  338. *pclsidHandler = pCurHandlerInfo->clsidHandler;
  339. }
  340. if (offlineItem)
  341. {
  342. *offlineItem = pCurItem->offlineItem;
  343. }
  344. if (pItemCheckState)
  345. {
  346. if (fSchedSync)
  347. {
  348. Assert(0 == iConnectionIndex);
  349. //if only holding on connection's settings at a time
  350. if (fClear)
  351. {
  352. pCurItem->pItemCheckState[iConnectionIndex].dwSchedule = SYNCMGRITEMSTATE_UNCHECKED;
  353. }
  354. }
  355. else //AutoSync
  356. {
  357. Assert((iConnectionIndex>=0) && (iConnectionIndex < m_ConnectionCount))
  358. }
  359. *pItemCheckState = pCurItem->pItemCheckState[iConnectionIndex];
  360. }
  361. }
  362. return fFoundMatch ? NOERROR : S_FALSE;
  363. }
  364. //--------------------------------------------------------------------------------
  365. //
  366. // STDMETHODIMP CHndlrQueue::GetItemIcon(WORD wHandlerId, WORD wItemID, HICON *phIcon)
  367. //
  368. // PURPOSE: Get the item icon
  369. //
  370. // History: 03-13-98 susia Created.
  371. //
  372. //--------------------------------------------------------------------------------
  373. STDMETHODIMP CHndlrQueue::GetItemIcon(WORD wHandlerId,
  374. WORD wItemID,
  375. HICON *phIcon)
  376. {
  377. BOOL fFoundMatch = FALSE;
  378. LPHANDLERINFO pCurHandlerInfo = NULL;
  379. LPITEMLIST pCurItem = NULL;
  380. pCurHandlerInfo = m_pFirstHandler;
  381. while (pCurHandlerInfo && !fFoundMatch)
  382. {
  383. if (wHandlerId == pCurHandlerInfo->wHandlerId) // see if CLSID matches
  384. {
  385. // see if handler info has a matching item
  386. pCurItem = pCurHandlerInfo->pFirstItem;
  387. while (pCurItem)
  388. {
  389. if (wItemID == pCurItem->wItemId)
  390. {
  391. fFoundMatch = TRUE;
  392. break;
  393. }
  394. pCurItem = pCurItem->pnextItem;
  395. }
  396. }
  397. if (!fFoundMatch)
  398. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  399. }
  400. if (fFoundMatch)
  401. {
  402. if (phIcon)
  403. {
  404. *phIcon = pCurItem->offlineItem.hIcon;
  405. }
  406. }
  407. return fFoundMatch ? NOERROR : S_FALSE;
  408. }
  409. //--------------------------------------------------------------------------------
  410. //
  411. // STDMETHODIMP CHndlrQueue::GetItemName(WORD wHandlerId, WORD wItemID, WCHAR *pwszName, UINT cchName);
  412. //
  413. // PURPOSE: Get the item Name
  414. //
  415. // History: 03-13-98 susia Created.
  416. //
  417. //--------------------------------------------------------------------------------
  418. STDMETHODIMP CHndlrQueue::GetItemName(WORD wHandlerId,
  419. WORD wItemID,
  420. WCHAR *pwszName,
  421. UINT cchName)
  422. {
  423. HRESULT hr = S_OK;
  424. BOOL fFoundMatch = FALSE;
  425. LPHANDLERINFO pCurHandlerInfo = NULL;
  426. LPITEMLIST pCurItem = NULL;
  427. pCurHandlerInfo = m_pFirstHandler;
  428. while (pCurHandlerInfo && !fFoundMatch)
  429. {
  430. if (wHandlerId == pCurHandlerInfo->wHandlerId) // see if CLSID matches
  431. {
  432. // see if handler info has a matching item
  433. pCurItem = pCurHandlerInfo->pFirstItem;
  434. while (pCurItem)
  435. {
  436. if (wItemID == pCurItem->wItemId)
  437. {
  438. fFoundMatch = TRUE;
  439. break;
  440. }
  441. pCurItem = pCurItem->pnextItem;
  442. }
  443. }
  444. if (!fFoundMatch)
  445. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  446. }
  447. if (fFoundMatch)
  448. {
  449. if (pwszName)
  450. {
  451. hr = StringCchCopy(pwszName, cchName, pCurItem->offlineItem.wszItemName);
  452. }
  453. else
  454. {
  455. hr = S_OK;
  456. }
  457. }
  458. else
  459. {
  460. hr = S_FALSE;
  461. }
  462. return hr;
  463. }
  464. //--------------------------------------------------------------------------------
  465. //
  466. // FUNCTION: CHndlrQueue::FindFirstHandlerInState(HANDLERSTATE hndlrState,WORD *wHandlerID)
  467. //
  468. // PURPOSE: finds first handler it comes across in the state
  469. //
  470. // COMMENTS:
  471. //
  472. // HISTORY: 01-01-98 SusiA Created.
  473. //
  474. //--------------------------------------------------------------------------------
  475. STDMETHODIMP CHndlrQueue::FindFirstHandlerInState(HANDLERSTATE hndlrState,WORD *wHandlerID)
  476. {
  477. return FindNextHandlerInState(0,hndlrState,wHandlerID);
  478. }
  479. //--------------------------------------------------------------------------------
  480. //
  481. // FUNCTION: CHndlrQueue::FindNextHandlerInState(WORD wLastHandlerID,
  482. // HANDLERSTATE hndlrState,WORD *wHandlerID)
  483. //
  484. // PURPOSE: finds next handler after LasthandlerID in the queue that matches
  485. // the requested state.
  486. //
  487. // COMMENTS: passing in 0 for the LasthandlerID is the same as calling
  488. // FindFirstHandlerInState
  489. //
  490. // HISTORY: 01-01-98 SusiA Created.
  491. //
  492. //--------------------------------------------------------------------------------
  493. STDMETHODIMP CHndlrQueue::FindNextHandlerInState(WORD wLastHandlerID,HANDLERSTATE hndlrState,WORD *wHandlerID)
  494. {
  495. HRESULT hr = S_FALSE;
  496. LPHANDLERINFO pCurHandler;
  497. *wHandlerID = 0;
  498. pCurHandler = m_pFirstHandler;
  499. if (0 != wLastHandlerID)
  500. {
  501. // loop foward until find the last handlerID we checked or hit the end
  502. while (pCurHandler)
  503. {
  504. if (wLastHandlerID == pCurHandler->wHandlerId)
  505. {
  506. break;
  507. }
  508. pCurHandler = pCurHandler->pNextHandler;
  509. }
  510. if (NULL == pCurHandler)
  511. return S_FALSE;
  512. pCurHandler = pCurHandler->pNextHandler; // increment to next handler.
  513. }
  514. while (pCurHandler)
  515. {
  516. if (hndlrState == pCurHandler->HandlerState)
  517. {
  518. *wHandlerID = pCurHandler->wHandlerId;
  519. hr = S_OK;
  520. break;
  521. }
  522. pCurHandler = pCurHandler->pNextHandler;
  523. }
  524. return hr;
  525. }
  526. //--------------------------------------------------------------------------------
  527. //
  528. // FUNCTION: CHndlrQueue::FindFirstItemOnConnection
  529. // (TCHAR *pszConnectionName,
  530. // CLSID *pclsidHandler,
  531. // SYNCMGRITEMID* OfflineItemID,
  532. // WORD *wHandlerId,
  533. // WORD *wItemID)
  534. //
  535. // PURPOSE: find first ListView Item that can sync over the specified
  536. // connection and return its clsid and ItemID
  537. //
  538. // COMMENTS:
  539. //
  540. // HISTORY: 01-01-98 SusiA Created.
  541. //
  542. //--------------------------------------------------------------------------------
  543. STDMETHODIMP CHndlrQueue::FindFirstItemOnConnection
  544. (TCHAR *pszConnectionName,
  545. CLSID *pclsidHandler,
  546. SYNCMGRITEMID* OfflineItemID,
  547. WORD *pwHandlerId,
  548. WORD *pwItemID)
  549. {
  550. DWORD dwCheckState;
  551. return FindNextItemOnConnection
  552. (pszConnectionName,0,0,pclsidHandler,
  553. OfflineItemID, pwHandlerId, pwItemID,
  554. TRUE, &dwCheckState);
  555. }
  556. //--------------------------------------------------------------------------------
  557. //
  558. // FUNCTION: CHndlrQueue::FindNextItemOnConnection
  559. // (TCHAR *pszConnectionName,
  560. // WORD wLastHandlerId,
  561. // WORD wLastItemID,
  562. // CLSID *pclsidHandler,
  563. // SYNCMGRITEMID* OfflineItemID,
  564. // WORD *pwHandlerId,
  565. // WORD *pwItemID,
  566. // BOOL fAllHandlers,
  567. // DWORD *pdwCheckState)
  568. //
  569. //
  570. //
  571. // PURPOSE: starts on the next item after the specified Handler and ItemID
  572. // setting the last HandlerID to 0 is the same as calling
  573. // FindFirstItemOnConnection
  574. //
  575. // COMMENTS: For now, no Handler can specifiy that it can or cannot sync over a
  576. // connection, so assume it can, and ignore the connection.
  577. //
  578. // HISTORY: 01-01-98 SusiA Created.
  579. //
  580. //--------------------------------------------------------------------------------
  581. STDMETHODIMP CHndlrQueue::FindNextItemOnConnection
  582. (TCHAR *pszConnectionName,
  583. WORD wLastHandlerId,
  584. WORD wLastItemID,
  585. CLSID *pclsidHandler,
  586. SYNCMGRITEMID* OfflineItemID,
  587. WORD *pwHandlerId,
  588. WORD *pwItemID,
  589. BOOL fAllHandlers,
  590. DWORD *pdwCheckState)
  591. {
  592. BOOL fFoundMatch = FALSE;
  593. LPHANDLERINFO pCurHandlerInfo = NULL;
  594. LPITEMLIST pCurItem = NULL;
  595. pCurHandlerInfo = m_pFirstHandler;
  596. if (!pCurHandlerInfo)
  597. {
  598. return S_FALSE;
  599. }
  600. if (0 != wLastHandlerId)
  601. {
  602. // loop until find the specified handler or hit end of list.
  603. while(pCurHandlerInfo && wLastHandlerId != pCurHandlerInfo->wHandlerId)
  604. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  605. if (NULL == pCurHandlerInfo) // reached end of list without finding the Handler
  606. {
  607. Assert(0); // user must have passed an invalid start HandlerID.
  608. return S_FALSE;
  609. }
  610. }
  611. // loop until find item or end of item list
  612. pCurItem = pCurHandlerInfo->pFirstItem;
  613. if (0 != wLastItemID)
  614. {
  615. while (pCurItem && pCurItem->wItemId != wLastItemID)
  616. {
  617. pCurItem = pCurItem->pnextItem;
  618. }
  619. if (NULL == pCurItem) // reached end of item list without finding the specified item
  620. {
  621. Assert(0); // user must have passed an invalid start ItemID.
  622. return S_FALSE;
  623. }
  624. // now we found the Handler and item. loop through remaining items for this handler and
  625. // see if there is a match
  626. pCurItem = pCurItem->pnextItem;
  627. }
  628. //Found the item on this handler
  629. if (pCurItem)
  630. {
  631. fFoundMatch = TRUE;
  632. }
  633. //If we are to move beyond this handler, do so now, else we are done
  634. if (!fFoundMatch && fAllHandlers)
  635. {
  636. pCurHandlerInfo = pCurHandlerInfo->pNextHandler; // increment to next handler if no match
  637. }
  638. if ((FALSE == fFoundMatch) && fAllHandlers)
  639. {
  640. while (pCurHandlerInfo && !fFoundMatch)
  641. {
  642. // see if handler info has a matching item
  643. pCurItem = pCurHandlerInfo->pFirstItem;
  644. if (pCurItem)
  645. fFoundMatch = TRUE;
  646. if (!fFoundMatch)
  647. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  648. }
  649. }
  650. if (fFoundMatch)
  651. {
  652. *pclsidHandler = pCurHandlerInfo->clsidHandler;
  653. *OfflineItemID = pCurItem->offlineItem.ItemID;
  654. *pwHandlerId = pCurHandlerInfo->wHandlerId;
  655. *pwItemID = pCurItem->wItemId;
  656. *pdwCheckState = pCurItem->pItemCheckState[0].dwSchedule;
  657. }
  658. return fFoundMatch ? NOERROR : S_FALSE;
  659. }
  660. //--------------------------------------------------------------------------------
  661. //
  662. // FUNCTION: CHndlrQueue::GetHandlerIDFromClsid
  663. // (REFCLSID clsidHandlerIn,
  664. // WORD *pwHandlerId)
  665. //
  666. // PURPOSE: get the HnadlerID from the CLSID
  667. //
  668. // COMMENTS: if the Handler is GUID_NULL enumerate all
  669. //
  670. // HISTORY: 03-09-98 SusiA Created.
  671. //
  672. //--------------------------------------------------------------------------------
  673. STDMETHODIMP CHndlrQueue::GetHandlerIDFromClsid
  674. (REFCLSID clsidHandlerIn,
  675. WORD *pwHandlerId)
  676. {
  677. LPHANDLERINFO pCurHandlerInfo = m_pFirstHandler;
  678. Assert(pwHandlerId);
  679. if (clsidHandlerIn == GUID_NULL)
  680. {
  681. *pwHandlerId = 0;
  682. return S_OK;
  683. }
  684. while (pCurHandlerInfo && (clsidHandlerIn != pCurHandlerInfo->clsidHandler))
  685. {
  686. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  687. }
  688. if (NULL == pCurHandlerInfo) // reached end of list without finding the Handler
  689. {
  690. *pwHandlerId = 0;
  691. Assert(0); // user must have passed an invalid start HandlerID.
  692. return S_FALSE;
  693. }
  694. *pwHandlerId = pCurHandlerInfo->wHandlerId;
  695. return S_OK;
  696. }
  697. //--------------------------------------------------------------------------------
  698. //
  699. // FUNCTION: CHndlrQueue::SetItemListViewID(CLSID clsidHandler,
  700. // SYNCMGRITEMID OfflineItemID,INT iItem)
  701. //
  702. // PURPOSE: assigns all items that match the handler clsid and
  703. // ItemID this listView Value.
  704. //
  705. // COMMENTS:
  706. //
  707. // HISTORY: 01-01-98 SusiA Created.
  708. //
  709. //--------------------------------------------------------------------------------
  710. STDMETHODIMP CHndlrQueue::SetItemListViewID(CLSID clsidHandler,
  711. SYNCMGRITEMID OfflineItemID,INT iItem)
  712. {
  713. LPHANDLERINFO pCurHandlerInfo = NULL;
  714. LPITEMLIST pCurItem = NULL;
  715. pCurHandlerInfo = m_pFirstHandler;
  716. while (pCurHandlerInfo )
  717. {
  718. if (clsidHandler == pCurHandlerInfo->clsidHandler)
  719. {
  720. pCurItem = pCurHandlerInfo->pFirstItem;
  721. while (pCurItem)
  722. {
  723. if (OfflineItemID == pCurItem->offlineItem.ItemID)
  724. {
  725. // This can be called at anytime after prepareforSync if a duplicate
  726. // is added later to the choice or progress bar.
  727. // found a match
  728. pCurItem->iItem = iItem;
  729. }
  730. pCurItem = pCurItem->pnextItem;
  731. }
  732. }
  733. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  734. }
  735. return NOERROR;
  736. }
  737. //--------------------------------------------------------------------------------
  738. //
  739. // FUNCTION: DWORD CHndlrQueue::GetCheck(WORD wParam, INT iItem)
  740. //
  741. // PURPOSE: Return the check state for the logon, logoff and
  742. // prompt me first check boxes on the connection number iItem
  743. //
  744. // COMMENTS:
  745. //
  746. // HISTORY: 01-01-98 SusiA Created.
  747. //
  748. //--------------------------------------------------------------------------------
  749. DWORD CHndlrQueue::GetCheck(WORD wParam, INT iItem)
  750. {
  751. // if no connection list all items are unchecked
  752. if (!m_ConnectionList)
  753. return 0;
  754. switch (wParam)
  755. {
  756. case IDC_AUTOLOGON:
  757. return m_ConnectionList[iItem].dwLogon;
  758. break;
  759. case IDC_AUTOLOGOFF:
  760. return m_ConnectionList[iItem].dwLogoff;
  761. break;
  762. case IDC_AUTOPROMPT_ME_FIRST:
  763. return m_ConnectionList[iItem].dwPromptMeFirst;
  764. break;
  765. case IDC_AUTOREADONLY:
  766. return m_ConnectionList->dwReadOnly;
  767. break;
  768. case IDC_AUTOHIDDEN:
  769. return m_ConnectionList->dwHidden;
  770. break;
  771. case IDC_AUTOCONNECT:
  772. return m_ConnectionList->dwMakeConnection;
  773. break;
  774. case IDC_IDLECHECKBOX:
  775. return m_ConnectionList[iItem].dwIdleEnabled;
  776. default:
  777. AssertSz(0,"Unkown SetConnectionCheckBox");
  778. return 0;
  779. }
  780. }
  781. //--------------------------------------------------------------------------------
  782. //
  783. // FUNCTION: DWORD CHndlrQueue::SetConnectionCheck(WORD wParam, DWORD dwState,
  784. // INT iConnectionItem)
  785. //
  786. // PURPOSE: Set the check state for the logon, logoff and
  787. // prompt me first check boxes on the connection number iConnectionItem
  788. //
  789. // COMMENTS:
  790. //
  791. // HISTORY: 01-01-98 SusiA Created.
  792. //
  793. //--------------------------------------------------------------------------------
  794. STDMETHODIMP CHndlrQueue::SetConnectionCheck(WORD wParam, DWORD dwState, INT iConnectionItem)
  795. {
  796. // if no connection list then just return
  797. if (!m_ConnectionList)
  798. return E_OUTOFMEMORY;
  799. switch (wParam)
  800. {
  801. case IDC_AUTOLOGON:
  802. m_ConnectionList[iConnectionItem].dwLogon = dwState;
  803. break;
  804. case IDC_AUTOLOGOFF:
  805. m_ConnectionList[iConnectionItem].dwLogoff = dwState;
  806. break;
  807. case IDC_AUTOPROMPT_ME_FIRST:
  808. m_ConnectionList[iConnectionItem].dwPromptMeFirst = dwState;
  809. break;
  810. case IDC_IDLECHECKBOX:
  811. m_ConnectionList[iConnectionItem].dwIdleEnabled = dwState;
  812. break;
  813. // these two sare for schedule
  814. case IDC_AUTOHIDDEN:
  815. m_ConnectionList->dwHidden = dwState;
  816. break;
  817. case IDC_AUTOREADONLY:
  818. m_ConnectionList->dwReadOnly = dwState;
  819. break;
  820. case IDC_AUTOCONNECT:
  821. m_ConnectionList->dwMakeConnection = dwState;
  822. break;
  823. default:
  824. AssertSz(0,"Unkown SetConnectionCheckBox");
  825. return E_UNEXPECTED;
  826. }
  827. return ERROR_SUCCESS;
  828. }
  829. //--------------------------------------------------------------------------------
  830. //
  831. // FUNCTION: CHndlrQueue::SetSyncCheckStateFromListViewItem(
  832. // DWORD dwSyncType,
  833. // INT iItem,
  834. // BOOL fChecked,
  835. // INT iConnectionItem)
  836. //
  837. //
  838. // PURPOSE: finds item with this listview ID and sets it appropriately.
  839. //
  840. // COMMENTS:
  841. //
  842. // HISTORY: 01-01-98 SusiA Created.
  843. //
  844. //--------------------------------------------------------------------------------
  845. STDMETHODIMP CHndlrQueue::SetSyncCheckStateFromListViewItem(SYNCTYPE SyncType,
  846. INT iItem,
  847. BOOL fChecked,
  848. INT iConnectionItem)
  849. {
  850. LPHANDLERINFO pCurHandlerInfo = NULL;
  851. LPITEMLIST pCurItem = NULL;
  852. DWORD dwState;
  853. pCurHandlerInfo = m_pFirstHandler;
  854. dwState = fChecked ? SYNCMGRITEMSTATE_CHECKED : SYNCMGRITEMSTATE_UNCHECKED;
  855. while (pCurHandlerInfo )
  856. {
  857. pCurItem = pCurHandlerInfo->pFirstItem;
  858. while (pCurItem)
  859. {
  860. if (iItem == pCurItem->iItem)
  861. {
  862. switch(SyncType)
  863. {
  864. case SYNCTYPE_AUTOSYNC:
  865. pCurItem->pItemCheckState[iConnectionItem].dwAutoSync = dwState;
  866. break;
  867. case SYNCTYPE_IDLE:
  868. pCurItem->pItemCheckState[iConnectionItem].dwIdle = dwState;
  869. break;
  870. case SYNCTYPE_SCHEDULED:
  871. pCurItem->pItemCheckState[iConnectionItem].dwSchedule = dwState;
  872. break;
  873. default:
  874. AssertSz(0,"Unknown Setting type");
  875. break;
  876. }
  877. return NOERROR;
  878. }
  879. pCurItem = pCurItem->pnextItem;
  880. }
  881. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  882. }
  883. Assert(0); // review - better assert but warn us when try to set a listView item that isn't assigned.
  884. return S_FALSE; // item wasn't found
  885. }
  886. //--------------------------------------------------------------------------------
  887. //
  888. // FUNCTION: CHndlrQueue::ListViewItemHasProperties(INT iItem)
  889. //
  890. // PURPOSE: determines if there are properties associated with this item.
  891. //
  892. // COMMENTS:
  893. //
  894. // HISTORY: 01-01-98 SusiA Created.
  895. //
  896. //--------------------------------------------------------------------------------
  897. STDMETHODIMP CHndlrQueue::ListViewItemHasProperties(INT iItem)
  898. {
  899. LPHANDLERINFO pCurHandlerInfo = NULL;
  900. LPITEMLIST pCurItem = NULL;
  901. pCurHandlerInfo = m_pFirstHandler;
  902. while (pCurHandlerInfo )
  903. {
  904. pCurItem = pCurHandlerInfo->pFirstItem;
  905. while (pCurItem)
  906. {
  907. if (iItem == pCurItem->iItem)
  908. {
  909. Assert(HANDLERSTATE_PREPAREFORSYNC == pCurHandlerInfo->HandlerState);
  910. return pCurItem->offlineItem.dwFlags & SYNCMGRITEM_HASPROPERTIES
  911. ? NOERROR : S_FALSE;
  912. }
  913. pCurItem = pCurItem->pnextItem;
  914. }
  915. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  916. }
  917. // Assert(-1 == iItem); // if don't find item, should be because user clicked in list box where there was none
  918. return S_FALSE; // item wasn't found
  919. }
  920. //--------------------------------------------------------------------------------
  921. //
  922. // FUNCTION: CHndlrQueue::ShowProperties(HWND hwndParent,INT iItem)
  923. //
  924. // PURPOSE: find the first item in the queueu with the assigned iItem and
  925. // call there show properties method.
  926. //
  927. // COMMENTS:
  928. //
  929. // HISTORY: 01-01-98 SusiA Created.
  930. //
  931. //--------------------------------------------------------------------------------
  932. STDMETHODIMP CHndlrQueue::ShowProperties(HWND hwndParent,INT iItem)
  933. {
  934. LPHANDLERINFO pCurHandlerInfo = NULL;
  935. LPITEMLIST pCurItem = NULL;
  936. AssertSz(0,"ShowProperties Called from Setttings");
  937. pCurHandlerInfo = m_pFirstHandler;
  938. while (pCurHandlerInfo )
  939. {
  940. pCurItem = pCurHandlerInfo->pFirstItem;
  941. while (pCurItem)
  942. {
  943. if (iItem == pCurItem->iItem)
  944. {
  945. Assert(HANDLERSTATE_PREPAREFORSYNC == pCurHandlerInfo->HandlerState);
  946. // UI shouldn't call this unless item actually has a properties flag
  947. Assert(SYNCMGRITEM_HASPROPERTIES & pCurItem->offlineItem.dwFlags);
  948. // make sure properties flag isn't set.
  949. if ( (SYNCMGRITEM_HASPROPERTIES & pCurItem->offlineItem.dwFlags))
  950. {
  951. return pCurHandlerInfo->pSyncMgrHandler->
  952. ShowProperties(hwndParent,
  953. (pCurItem->offlineItem.ItemID));
  954. }
  955. return S_FALSE;
  956. }
  957. pCurItem = pCurItem->pnextItem;
  958. }
  959. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  960. }
  961. Assert(0); // review - better assert but wanr us when try to set a listView item that isn't assigned.
  962. return S_FALSE; // item wasn't found
  963. }
  964. //--------------------------------------------------------------------------------
  965. //
  966. // FUNCTION: CHndlrQueue::CreateServer(WORD wHandlerId, const CLSID *pCLSIDServer)
  967. //
  968. // PURPOSE: Create the Handler server
  969. //
  970. // COMMENTS:
  971. //
  972. // HISTORY: 01-01-98 SusiA Created.
  973. //
  974. //--------------------------------------------------------------------------------
  975. STDMETHODIMP CHndlrQueue::CreateServer(WORD wHandlerId, const CLSID *pCLSIDServer)
  976. {
  977. HRESULT hr = NO_ERROR; // review for Lookup failures
  978. LPHANDLERINFO pHandlerInfo = NULL;
  979. LPUNKNOWN pUnk;
  980. hr = LookupHandlerFromId(wHandlerId,&pHandlerInfo);
  981. if (hr == NOERROR)
  982. {
  983. if (HANDLERSTATE_CREATE != pHandlerInfo->HandlerState)
  984. {
  985. Assert(HANDLERSTATE_CREATE == pHandlerInfo->HandlerState);
  986. return E_UNEXPECTED;
  987. }
  988. pHandlerInfo->HandlerState = HANDLERSTATE_INCREATE;
  989. pHandlerInfo->clsidHandler = *pCLSIDServer;
  990. hr = CoCreateInstance(pHandlerInfo->clsidHandler,
  991. NULL, CLSCTX_INPROC_SERVER,
  992. IID_IUnknown, (void**)&pUnk);
  993. if (NOERROR == hr)
  994. {
  995. hr = pUnk->QueryInterface(IID_ISyncMgrSynchronize,
  996. (void **) &pHandlerInfo->pSyncMgrHandler);
  997. pUnk->Release();
  998. }
  999. if (NOERROR == hr)
  1000. {
  1001. pHandlerInfo->HandlerState = HANDLERSTATE_INITIALIZE;
  1002. }
  1003. else
  1004. {
  1005. pHandlerInfo->pSyncMgrHandler = NULL;
  1006. pHandlerInfo->HandlerState = HANDLERSTATE_DEAD;
  1007. }
  1008. }
  1009. return hr;
  1010. }
  1011. //--------------------------------------------------------------------------------
  1012. //
  1013. // FUNCTION: CHndlrQueue::Initialize(WORD wHandlerId,DWORD dwReserved,DWORD dwSyncFlags,
  1014. // DWORD cbCookie,const BYTE *lpCookie)
  1015. //
  1016. // PURPOSE: Initialize the handler
  1017. //
  1018. // COMMENTS:
  1019. //
  1020. // HISTORY: 01-01-98 SusiA Created.
  1021. //
  1022. //--------------------------------------------------------------------------------
  1023. STDMETHODIMP CHndlrQueue::Initialize(WORD wHandlerId,DWORD dwReserved,DWORD dwSyncFlags,
  1024. DWORD cbCookie,const BYTE *lpCookie)
  1025. {
  1026. HRESULT hr = E_UNEXPECTED; // review for Lookup failures
  1027. LPHANDLERINFO pHandlerInfo = NULL;
  1028. if (NOERROR == LookupHandlerFromId(wHandlerId,&pHandlerInfo))
  1029. {
  1030. if (HANDLERSTATE_INITIALIZE != pHandlerInfo->HandlerState)
  1031. {
  1032. Assert(HANDLERSTATE_INITIALIZE == pHandlerInfo->HandlerState);
  1033. return E_UNEXPECTED;
  1034. }
  1035. pHandlerInfo->HandlerState = HANDLERSTATE_ININITIALIZE;
  1036. Assert(pHandlerInfo->pSyncMgrHandler);
  1037. if (NULL != pHandlerInfo->pSyncMgrHandler)
  1038. {
  1039. hr = pHandlerInfo->pSyncMgrHandler->Initialize(dwReserved,dwSyncFlags,cbCookie,lpCookie);
  1040. }
  1041. if (NOERROR == hr)
  1042. {
  1043. pHandlerInfo->HandlerState = HANDLERSTATE_ADDHANDLERTEMS;
  1044. pHandlerInfo->dwSyncFlags = dwSyncFlags;
  1045. }
  1046. else
  1047. {
  1048. // on an error, go ahead and release the proxy if server doesn't want to handle
  1049. pHandlerInfo->HandlerState = HANDLERSTATE_DEAD;
  1050. }
  1051. }
  1052. return hr;
  1053. }
  1054. //--------------------------------------------------------------------------------
  1055. //
  1056. // FUNCTION: CHndlrQueue::AddHandlerItemsToQueue(WORD wHandlerId)
  1057. //
  1058. // PURPOSE: Enumerate the handler items and add them to the queue
  1059. //
  1060. // COMMENTS:
  1061. //
  1062. // HISTORY: 01-01-98 SusiA Created.
  1063. //
  1064. //--------------------------------------------------------------------------------
  1065. STDMETHODIMP CHndlrQueue::AddHandlerItemsToQueue(WORD wHandlerId)
  1066. {
  1067. HRESULT hr = E_UNEXPECTED; // review for Lookup failures
  1068. LPHANDLERINFO pHandlerInfo = NULL;
  1069. LPSYNCMGRENUMITEMS pEnumOffline = NULL;
  1070. if (NOERROR == LookupHandlerFromId(wHandlerId,&pHandlerInfo))
  1071. {
  1072. if (HANDLERSTATE_ADDHANDLERTEMS != pHandlerInfo->HandlerState)
  1073. {
  1074. Assert(HANDLERSTATE_ADDHANDLERTEMS == pHandlerInfo->HandlerState);
  1075. return E_UNEXPECTED;
  1076. }
  1077. pHandlerInfo->HandlerState = HANDLERSTATE_INADDHANDLERITEMS;
  1078. Assert(pHandlerInfo->pSyncMgrHandler);
  1079. if (pHandlerInfo->pSyncMgrHandler)
  1080. {
  1081. hr = pHandlerInfo->pSyncMgrHandler->EnumSyncMgrItems(&pEnumOffline);
  1082. if ( ((S_OK == hr) || (S_SYNCMGR_MISSINGITEMS == hr)) && pEnumOffline)
  1083. {
  1084. SYNCMGRITEMNT5B2 offItem; // temporarily use NT5B2 structure since its bigger
  1085. ULONG pceltFetched;
  1086. // add the handler info
  1087. SYNCMGRHANDLERINFO *pSyncMgrHandlerInfo = NULL;
  1088. // update missing items info
  1089. if (S_SYNCMGR_MISSINGITEMS == hr)
  1090. m_fItemsMissing = TRUE;
  1091. hr = pHandlerInfo->pSyncMgrHandler->GetHandlerInfo(&pSyncMgrHandlerInfo);
  1092. if (NOERROR == hr && pSyncMgrHandlerInfo)
  1093. {
  1094. if (IsValidSyncMgrHandlerInfo(pSyncMgrHandlerInfo))
  1095. {
  1096. SetHandlerInfo(wHandlerId,pSyncMgrHandlerInfo);
  1097. }
  1098. CoTaskMemFree(pSyncMgrHandlerInfo);
  1099. }
  1100. // Get this handlers registration flags
  1101. BOOL fReg;
  1102. fReg = RegGetHandlerRegistrationInfo(pHandlerInfo->clsidHandler,
  1103. &(pHandlerInfo->dwRegistrationFlags));
  1104. // rely on RegGetHandler to set flags to zero on error
  1105. // so assert that it does
  1106. Assert(fReg || (0 == pHandlerInfo->dwRegistrationFlags));
  1107. hr = NOERROR; // okay to add items even if Gethandler info fails
  1108. Assert(sizeof(SYNCMGRITEMNT5B2) > sizeof(SYNCMGRITEM));
  1109. // sit in loop getting data of objects to fill list box.
  1110. // should really set up list in memory for OneStop to fill in or
  1111. // main thread could pass in a callback interface.
  1112. while(NOERROR == pEnumOffline->Next(1,(SYNCMGRITEM *) &offItem,&pceltFetched))
  1113. {
  1114. // don't add the item if temporary.
  1115. if (!(offItem.dwFlags & SYNCMGRITEM_TEMPORARY))
  1116. {
  1117. AddItemToHandler(wHandlerId,(SYNCMGRITEM *) &offItem);
  1118. }
  1119. }
  1120. pEnumOffline->Release();
  1121. }
  1122. }
  1123. if (NOERROR == hr)
  1124. {
  1125. pHandlerInfo->HandlerState = HANDLERSTATE_PREPAREFORSYNC;
  1126. }
  1127. else
  1128. {
  1129. pHandlerInfo->HandlerState = HANDLERSTATE_DEAD;
  1130. }
  1131. }
  1132. return hr;
  1133. }
  1134. //+---------------------------------------------------------------------------
  1135. //
  1136. // Member: CHndlrQueue::SetHandlerInfo, public
  1137. //
  1138. // Synopsis: Adds item to the specified handler.
  1139. // Called in context of the handlers thread.
  1140. //
  1141. // Arguments: [pHandlerId] - Id of handler.
  1142. // [pSyncMgrHandlerInfo] - Points to SyncMgrHandlerInfo to be filled in.
  1143. //
  1144. // Returns: Appropriate Error code
  1145. //
  1146. // Modifies:
  1147. //
  1148. // History: 28-Jul-98 rogerg Created.
  1149. //
  1150. //----------------------------------------------------------------------------
  1151. STDMETHODIMP CHndlrQueue::SetHandlerInfo(WORD wHandlerId,LPSYNCMGRHANDLERINFO pSyncMgrHandlerInfo)
  1152. {
  1153. HRESULT hr = E_UNEXPECTED;
  1154. LPHANDLERINFO pHandlerInfo = NULL;
  1155. if (!pSyncMgrHandlerInfo)
  1156. {
  1157. return E_INVALIDARG;
  1158. Assert(pSyncMgrHandlerInfo);
  1159. }
  1160. if (NOERROR == LookupHandlerFromId(wHandlerId,&pHandlerInfo))
  1161. {
  1162. if (HANDLERSTATE_INADDHANDLERITEMS != pHandlerInfo->HandlerState)
  1163. {
  1164. Assert(HANDLERSTATE_INADDHANDLERITEMS == pHandlerInfo->HandlerState);
  1165. hr = E_UNEXPECTED;
  1166. }
  1167. else
  1168. {
  1169. // Review - After clients update turn
  1170. // this check back on
  1171. if (0 /* pSyncMgrHandlerInfo->cbSize != sizeof(SYNCMGRHANDLERINFO) */)
  1172. {
  1173. hr = E_INVALIDARG;
  1174. }
  1175. else
  1176. {
  1177. pHandlerInfo->SyncMgrHandlerInfo = *pSyncMgrHandlerInfo;
  1178. }
  1179. }
  1180. }
  1181. return hr;
  1182. }
  1183. //--------------------------------------------------------------------------------
  1184. //
  1185. // FUNCTION: CHndlrQueue::AddItemToHandler(WORD wHandlerId,SYNCMGRITEM *pOffineItem)
  1186. //
  1187. // PURPOSE: Add the handler's items
  1188. //
  1189. // COMMENTS:
  1190. //
  1191. // HISTORY: 01-01-98 SusiA Created.
  1192. //
  1193. //--------------------------------------------------------------------------------
  1194. STDMETHODIMP CHndlrQueue::AddItemToHandler(WORD wHandlerId,SYNCMGRITEM *pOffineItem)
  1195. {
  1196. HRESULT hr = E_UNEXPECTED; // review for Lookup failures
  1197. LPHANDLERINFO pHandlerInfo = NULL;
  1198. LPITEMLIST pNewItem = NULL;
  1199. if (!IsValidSyncMgrItem(pOffineItem))
  1200. {
  1201. return E_UNEXPECTED;
  1202. }
  1203. if (NOERROR == LookupHandlerFromId(wHandlerId,&pHandlerInfo))
  1204. {
  1205. if (HANDLERSTATE_INADDHANDLERITEMS != pHandlerInfo->HandlerState)
  1206. {
  1207. Assert(HANDLERSTATE_INADDHANDLERITEMS == pHandlerInfo->HandlerState);
  1208. return E_UNEXPECTED;
  1209. }
  1210. // Allocate the item.
  1211. pNewItem = (LPITEMLIST) ALLOC(sizeof(*pNewItem));
  1212. if (NULL == pNewItem)
  1213. {
  1214. return E_OUTOFMEMORY;
  1215. }
  1216. ZeroMemory(pNewItem, sizeof(*pNewItem));
  1217. pNewItem->wItemId = ++pHandlerInfo->wItemCount;
  1218. pNewItem->pHandlerInfo = pHandlerInfo;
  1219. pNewItem->iItem = -1;
  1220. pNewItem->offlineItem = *pOffineItem;
  1221. // stick the item on the end of the list
  1222. if (NULL == pHandlerInfo->pFirstItem)
  1223. {
  1224. pHandlerInfo->pFirstItem = pNewItem;
  1225. Assert(1 == pHandlerInfo->wItemCount);
  1226. }
  1227. else
  1228. {
  1229. LPITEMLIST pCurItem;
  1230. pCurItem = pHandlerInfo->pFirstItem;
  1231. while (pCurItem->pnextItem)
  1232. pCurItem = pCurItem->pnextItem;
  1233. pCurItem->pnextItem = pNewItem;
  1234. Assert ((pCurItem->wItemId + 1) == pNewItem->wItemId);
  1235. }
  1236. hr = NOERROR;
  1237. }
  1238. return hr;
  1239. }
  1240. //--------------------------------------------------------------------------------
  1241. //
  1242. // FUNCTION: CHndlrQueue::LookupHandlerFromId(WORD wHandlerId,
  1243. // LPHANDLERINFO *pHandlerInfo)
  1244. //
  1245. // PURPOSE: finds associated hander data from the handler ID
  1246. //
  1247. // COMMENTS:
  1248. //
  1249. // HISTORY: 01-01-98 SusiA Created.
  1250. //
  1251. //--------------------------------------------------------------------------------
  1252. STDMETHODIMP CHndlrQueue::LookupHandlerFromId(WORD wHandlerId,LPHANDLERINFO *pHandlerInfo)
  1253. {
  1254. HRESULT hr = E_UNEXPECTED; // review error code.
  1255. LPHANDLERINFO pCurItem;
  1256. *pHandlerInfo = NULL;
  1257. pCurItem = m_pFirstHandler;
  1258. while (pCurItem)
  1259. {
  1260. if (wHandlerId == pCurItem->wHandlerId )
  1261. {
  1262. *pHandlerInfo = pCurItem;
  1263. hr = NOERROR;
  1264. break;
  1265. }
  1266. pCurItem = pCurItem->pNextHandler;
  1267. }
  1268. return hr;
  1269. }
  1270. //--------------------------------------------------------------------------------
  1271. //
  1272. // FUNCTION: CHndlrQueue::InitAutoSyncSettings(HWND hwndRasCombo)
  1273. //
  1274. // PURPOSE: Initialize the autosync settings per the connections
  1275. // listed in this RasCombo
  1276. //
  1277. // COMMENTS: Ras based (connection name as identifier) When connection object
  1278. // based, we will use the connection GUID to identify the connection
  1279. // settings
  1280. //
  1281. // HISTORY: 01-01-98 SusiA Created.
  1282. //
  1283. //--------------------------------------------------------------------------------
  1284. STDMETHODIMP CHndlrQueue::InitSyncSettings(SYNCTYPE syncType,HWND hwndRasCombo)
  1285. {
  1286. SCODE sc = S_OK;
  1287. int i;
  1288. // This function gets possibly gets called twice
  1289. // once for AuotSync and once for Idle if already have
  1290. // a connection list then use existing
  1291. if (NULL == m_ConnectionList)
  1292. {
  1293. m_ConnectionCount = ComboBox_GetCount(hwndRasCombo);
  1294. if (m_ConnectionCount > 0)
  1295. {
  1296. smMem(m_ConnectionList = (LPCONNECTIONSETTINGS)
  1297. ALLOC(m_ConnectionCount * sizeof(CONNECTIONSETTINGS)));
  1298. }
  1299. }
  1300. // if now have a connection list set the appropriate settings
  1301. if (m_ConnectionList)
  1302. {
  1303. COMBOBOXEXITEM comboItem;
  1304. for (i=0; i<m_ConnectionCount; i++)
  1305. {
  1306. comboItem.mask = CBEIF_TEXT;
  1307. comboItem.cchTextMax = RAS_MaxEntryName + 1;
  1308. comboItem.pszText = m_ConnectionList[i].pszConnectionName;
  1309. comboItem.iItem = i;
  1310. // Review what happens on failure
  1311. SendMessage(hwndRasCombo, CBEM_GETITEM, (WPARAM) 0, (LPARAM) &comboItem);
  1312. switch (syncType)
  1313. {
  1314. case SYNCTYPE_AUTOSYNC:
  1315. RegGetAutoSyncSettings(&(m_ConnectionList[i]));
  1316. break;
  1317. case SYNCTYPE_IDLE:
  1318. RegGetIdleSyncSettings(&(m_ConnectionList[i]));
  1319. break;
  1320. default:
  1321. AssertSz(0,"Unknown SyncType");
  1322. break;
  1323. }
  1324. }
  1325. }
  1326. EH_Err:
  1327. return sc;
  1328. }
  1329. //--------------------------------------------------------------------------------
  1330. //
  1331. // FUNCTION: CHndlrQueue::InitSchedSyncSettings(LPCONNECTIONSETTINGS pConnectionSettings)
  1332. //
  1333. // PURPOSE: Initialize the scheduled Sync settings per the connections
  1334. // listed in this RasCombo
  1335. //
  1336. // COMMENTS: Ras based (connection name as identifier) When connection object
  1337. // based, we will use the connection GUID to identify the connection
  1338. // settings
  1339. //
  1340. // HISTORY: 01-01-98 SusiA Created.
  1341. //
  1342. //--------------------------------------------------------------------------------
  1343. STDMETHODIMP CHndlrQueue::InitSchedSyncSettings(LPCONNECTIONSETTINGS pConnectionSettings)
  1344. {
  1345. m_ConnectionList = pConnectionSettings;
  1346. return S_OK;
  1347. }
  1348. //--------------------------------------------------------------------------------
  1349. //
  1350. // FUNCTION: CHndlrQueue::ReadSchedSyncSettingsPerConnection(WORD wHandlerID,
  1351. // TCHAR * pszSchedName)
  1352. //
  1353. // PURPOSE: Read the scheduled Sync settings from the registry.
  1354. // If there is no entry in the registry, the default is the
  1355. // check state of the current offline item
  1356. //
  1357. // COMMENTS: Ras based (connection name as identifier) When connection object
  1358. // based, we will use the connection GUID to identify the connection
  1359. // settings
  1360. //
  1361. // HISTORY: 01-01-98 SusiA Created.
  1362. //
  1363. //--------------------------------------------------------------------------------
  1364. STDMETHODIMP CHndlrQueue::ReadSchedSyncSettingsOnConnection(WORD wHandlerID,TCHAR * pszSchedName)
  1365. {
  1366. HRESULT hr = E_UNEXPECTED; // review for Lookup failures
  1367. LPHANDLERINFO pHandlerInfo = NULL;
  1368. Assert(m_ConnectionList != NULL);
  1369. if (!m_ConnectionList)
  1370. return E_UNEXPECTED;
  1371. //Set the Check set of this item per connection
  1372. if (NOERROR == LookupHandlerFromId(wHandlerID,&pHandlerInfo))
  1373. {
  1374. LPITEMLIST pCurItem = pHandlerInfo->pFirstItem;
  1375. while (pCurItem)
  1376. {
  1377. //Scheduled sync only works on one connection
  1378. Assert(NULL == pCurItem->pItemCheckState );
  1379. pCurItem->pItemCheckState = (ITEMCHECKSTATE*) ALLOC(sizeof(*(pCurItem->pItemCheckState)));
  1380. if (!pCurItem->pItemCheckState)
  1381. {
  1382. return E_OUTOFMEMORY;
  1383. }
  1384. // by default no items in the schedule are checked.
  1385. pCurItem->pItemCheckState[0].dwSchedule = FALSE;
  1386. // possible for schedule name to be null when schedule first created.
  1387. if (pszSchedName)
  1388. {
  1389. RegGetSyncItemSettings(SYNCTYPE_SCHEDULED,
  1390. pHandlerInfo->clsidHandler,
  1391. pCurItem->offlineItem.ItemID,
  1392. m_ConnectionList->pszConnectionName,
  1393. &(pCurItem->pItemCheckState[0].dwSchedule),
  1394. pCurItem->offlineItem.dwItemState,
  1395. pszSchedName);
  1396. }
  1397. pCurItem = pCurItem->pnextItem;
  1398. }
  1399. }
  1400. return hr;
  1401. }
  1402. //--------------------------------------------------------------------------------
  1403. //
  1404. // FUNCTION: CHndlrQueue::InsertItem(LPHANDLERINFO pCurHandler,
  1405. // LPSYNC_HANDLER_ITEM_INFO pHandlerItemInfo)
  1406. //
  1407. // PURPOSE: App is programatically adding an item to the schedule
  1408. // with a default check state
  1409. //
  1410. // HISTORY: 11-25-98 SusiA Created.
  1411. //
  1412. //--------------------------------------------------------------------------------
  1413. STDMETHODIMP CHndlrQueue::InsertItem(LPHANDLERINFO pCurHandler,
  1414. LPSYNC_HANDLER_ITEM_INFO pHandlerItemInfo)
  1415. {
  1416. LPITEMLIST pCurItem = pCurHandler->pFirstItem;
  1417. while (pCurItem)
  1418. {
  1419. if (pHandlerItemInfo->itemID == pCurItem->offlineItem.ItemID)
  1420. {
  1421. pCurItem->pItemCheckState[0].dwSchedule = pHandlerItemInfo->dwCheckState;
  1422. pCurItem->offlineItem.hIcon = pHandlerItemInfo->hIcon;
  1423. return StringCchCopy(pCurItem->offlineItem.wszItemName,
  1424. ARRAYSIZE(pCurItem->offlineItem.wszItemName),
  1425. pHandlerItemInfo->wszItemName);
  1426. }
  1427. pCurItem = pCurItem->pnextItem;
  1428. }
  1429. if (!pCurItem)
  1430. {
  1431. //Item was not found on the handler, add it now
  1432. // Allocate the item.
  1433. LPITEMLIST pNewItem = (LPITEMLIST) ALLOC(sizeof(*pNewItem));
  1434. if (NULL == pNewItem)
  1435. {
  1436. return E_OUTOFMEMORY;
  1437. }
  1438. ZeroMemory(pNewItem,sizeof(*pNewItem));
  1439. pNewItem->wItemId = ++pCurHandler->wItemCount;
  1440. pNewItem->pHandlerInfo = pCurHandler;
  1441. pNewItem->iItem = -1;
  1442. SYNCMGRITEM *pOfflineItem = (LPSYNCMGRITEM) ALLOC(sizeof(*pOfflineItem));
  1443. if (NULL == pOfflineItem)
  1444. {
  1445. FREE(pNewItem);
  1446. return E_OUTOFMEMORY;
  1447. }
  1448. ZeroMemory(pOfflineItem, sizeof(*pOfflineItem));
  1449. pNewItem->offlineItem = *pOfflineItem;
  1450. pNewItem->offlineItem.hIcon = pHandlerItemInfo->hIcon;
  1451. pNewItem->offlineItem.ItemID = pHandlerItemInfo->itemID;
  1452. HRESULT hrCopy = StringCchCopy(pNewItem->offlineItem.wszItemName,
  1453. ARRAYSIZE(pNewItem->offlineItem.wszItemName),
  1454. pHandlerItemInfo->wszItemName);
  1455. if (FAILED(hrCopy))
  1456. {
  1457. FREE(pNewItem);
  1458. FREE(pOfflineItem);
  1459. return hrCopy;
  1460. }
  1461. //Scheduled sync only works on one connection
  1462. Assert(NULL == pNewItem->pItemCheckState );
  1463. pNewItem->pItemCheckState = (ITEMCHECKSTATE*) ALLOC(sizeof(*(pNewItem->pItemCheckState)));
  1464. if (!pNewItem->pItemCheckState)
  1465. {
  1466. FREE(pNewItem);
  1467. FREE(pOfflineItem);
  1468. return E_OUTOFMEMORY;
  1469. }
  1470. pNewItem->pItemCheckState[0].dwSchedule = pHandlerItemInfo->dwCheckState;
  1471. // stick the item on the end of the list
  1472. if (NULL == pCurHandler->pFirstItem)
  1473. {
  1474. pCurHandler->pFirstItem = pNewItem;
  1475. Assert(1 == pCurHandler->wItemCount);
  1476. }
  1477. else
  1478. {
  1479. pCurItem = pCurHandler->pFirstItem;
  1480. while (pCurItem->pnextItem)
  1481. pCurItem = pCurItem->pnextItem;
  1482. pCurItem->pnextItem = pNewItem;
  1483. Assert ((pCurItem->wItemId + 1) == pNewItem->wItemId);
  1484. }
  1485. }
  1486. return S_OK;
  1487. }
  1488. //--------------------------------------------------------------------------------
  1489. //
  1490. // FUNCTION: CHndlrQueue::AddHandlerItem(LPSYNC_HANDLER_ITEM_INFO pHandlerItemInfo)
  1491. //
  1492. // PURPOSE: App is programatically adding an item to the schedule
  1493. // with this default check state
  1494. //
  1495. // HISTORY: 03-05-98 SusiA Created.
  1496. //
  1497. //--------------------------------------------------------------------------------
  1498. STDMETHODIMP CHndlrQueue::AddHandlerItem(LPSYNC_HANDLER_ITEM_INFO pHandlerItemInfo)
  1499. {
  1500. LPHANDLERINFO pCurHandlerInfo = NULL;
  1501. SCODE sc = S_OK;
  1502. pCurHandlerInfo = m_pFirstHandler;
  1503. while (pCurHandlerInfo )
  1504. {
  1505. if (pHandlerItemInfo->handlerID == pCurHandlerInfo->clsidHandler)
  1506. {
  1507. return InsertItem(pCurHandlerInfo, pHandlerItemInfo);
  1508. }
  1509. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1510. }
  1511. //if the handler is not loaded, just cache the new item.
  1512. return SYNCMGR_E_HANDLER_NOT_LOADED;
  1513. }
  1514. //--------------------------------------------------------------------------------
  1515. //
  1516. // FUNCTION: CHndlrQueue::SetItemCheck(REFCLSID pclsidHandler,
  1517. // SYNCMGRITEMID *pOfflineItemID, DWORD dwCheckState)
  1518. //
  1519. // PURPOSE: App is programatically setting the check state of an item
  1520. //
  1521. // HISTORY: 03-05-98 SusiA Created.
  1522. //
  1523. //--------------------------------------------------------------------------------
  1524. STDMETHODIMP CHndlrQueue::SetItemCheck(REFCLSID pclsidHandler,
  1525. SYNCMGRITEMID *pOfflineItemID, DWORD dwCheckState)
  1526. {
  1527. LPHANDLERINFO pCurHandlerInfo = NULL;
  1528. LPITEMLIST pCurItem = NULL;
  1529. pCurHandlerInfo = m_pFirstHandler;
  1530. while (pCurHandlerInfo )
  1531. {
  1532. if (pclsidHandler == pCurHandlerInfo->clsidHandler)
  1533. {
  1534. pCurItem = pCurHandlerInfo->pFirstItem;
  1535. while (pCurItem)
  1536. {
  1537. if (*pOfflineItemID == pCurItem->offlineItem.ItemID)
  1538. {
  1539. pCurItem->pItemCheckState[0].dwSchedule = dwCheckState;
  1540. return S_OK;
  1541. }
  1542. pCurItem = pCurItem->pnextItem;
  1543. }
  1544. return SYNCMGR_E_ITEM_UNREGISTERED;
  1545. }
  1546. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1547. }
  1548. //if the handler is not loaded, just cache the new item
  1549. return SYNCMGR_E_HANDLER_NOT_LOADED;
  1550. }
  1551. //--------------------------------------------------------------------------------
  1552. //
  1553. // FUNCTION: HndlrQueue::GetItemCheck(REFCLSID pclsidHandler,
  1554. // SYNCMGRITEMID *pOfflineItemID, DWORD *pdwCheckState)
  1555. // PURPOSE: App is programatically setting the check state of an item
  1556. //
  1557. // HISTORY: 03-05-98 SusiA Created.
  1558. //
  1559. //--------------------------------------------------------------------------------
  1560. STDMETHODIMP CHndlrQueue::GetItemCheck(REFCLSID pclsidHandler,
  1561. SYNCMGRITEMID *pOfflineItemID, DWORD *pdwCheckState)
  1562. {
  1563. LPHANDLERINFO pCurHandlerInfo = NULL;
  1564. LPITEMLIST pCurItem = NULL;
  1565. pCurHandlerInfo = m_pFirstHandler;
  1566. while (pCurHandlerInfo )
  1567. {
  1568. if (pclsidHandler == pCurHandlerInfo->clsidHandler)
  1569. {
  1570. pCurItem = pCurHandlerInfo->pFirstItem;
  1571. while (pCurItem)
  1572. {
  1573. if (*pOfflineItemID == pCurItem->offlineItem.ItemID)
  1574. {
  1575. *pdwCheckState = pCurItem->pItemCheckState[0].dwSchedule;
  1576. return S_OK;
  1577. }
  1578. pCurItem = pCurItem->pnextItem;
  1579. }
  1580. return SYNCMGR_E_ITEM_UNREGISTERED;
  1581. }
  1582. pCurHandlerInfo = pCurHandlerInfo->pNextHandler;
  1583. }
  1584. //if the handler is not loaded, just cache the new item
  1585. return SYNCMGR_E_HANDLER_NOT_LOADED;
  1586. }
  1587. //--------------------------------------------------------------------------------
  1588. //
  1589. // FUNCTION: CHndlrQueue::ReadSyncSettingsPerConnection(SYNCTYPE syncType,
  1590. // WORD wHandlerID)
  1591. //
  1592. // PURPOSE: Read the autosync settings from the registry.
  1593. // If there is no entry in the registry, the default is the
  1594. // check state of the current offline item
  1595. //
  1596. // COMMENTS: Ras based (connection name as identifier) When connection object
  1597. // based, we will use the connection GUID to identify the connection
  1598. // settings
  1599. //
  1600. //--------------------------------------------------------------------------------
  1601. STDMETHODIMP CHndlrQueue::ReadSyncSettingsPerConnection(SYNCTYPE syncType,
  1602. WORD wHandlerID)
  1603. {
  1604. HRESULT hr = E_UNEXPECTED; // review for Lookup failures
  1605. LPHANDLERINFO pHandlerInfo = NULL;
  1606. int i;
  1607. if (0 == m_ConnectionCount)
  1608. return S_FALSE;
  1609. Assert(m_ConnectionList != NULL);
  1610. Assert(m_ConnectionCount != 0);
  1611. //Set the Check set of this item per connection
  1612. if (NOERROR == LookupHandlerFromId(wHandlerID,&pHandlerInfo))
  1613. {
  1614. LPITEMLIST pCurItem = pHandlerInfo->pFirstItem;
  1615. while (pCurItem)
  1616. {
  1617. // if don't alreayd have a checkStateAllocate one.
  1618. if (!pCurItem->pItemCheckState)
  1619. {
  1620. pCurItem->pItemCheckState = (ITEMCHECKSTATE*) ALLOC(m_ConnectionCount * sizeof(ITEMCHECKSTATE));
  1621. }
  1622. if (!pCurItem->pItemCheckState)
  1623. {
  1624. return E_OUTOFMEMORY;
  1625. }
  1626. for (i=0; i<m_ConnectionCount; i++)
  1627. {
  1628. DWORD dwDefaultCheck;
  1629. // if handler hasn't registered for the
  1630. // event then set its check state fo uncheck
  1631. // we do this in each case. to start off with
  1632. // assume the handler is registered
  1633. // If change this logic need to also change logic in exe hndlrq.
  1634. dwDefaultCheck = pCurItem->offlineItem.dwItemState;
  1635. switch (syncType)
  1636. {
  1637. case SYNCTYPE_AUTOSYNC:
  1638. if (0 == (pHandlerInfo->dwRegistrationFlags
  1639. & (SYNCMGRREGISTERFLAG_CONNECT | SYNCMGRREGISTERFLAG_PENDINGDISCONNECT)))
  1640. {
  1641. dwDefaultCheck = SYNCMGRITEMSTATE_UNCHECKED;
  1642. }
  1643. RegGetSyncItemSettings(SYNCTYPE_AUTOSYNC,
  1644. pHandlerInfo->clsidHandler,
  1645. pCurItem->offlineItem.ItemID,
  1646. m_ConnectionList[i].pszConnectionName,
  1647. &(pCurItem->pItemCheckState[i].dwAutoSync),
  1648. dwDefaultCheck,
  1649. NULL);
  1650. break;
  1651. case SYNCTYPE_IDLE:
  1652. if (0 == (pHandlerInfo->dwRegistrationFlags & (SYNCMGRREGISTERFLAG_IDLE) ))
  1653. {
  1654. dwDefaultCheck = SYNCMGRITEMSTATE_UNCHECKED;
  1655. }
  1656. RegGetSyncItemSettings(SYNCTYPE_IDLE,
  1657. pHandlerInfo->clsidHandler,
  1658. pCurItem->offlineItem.ItemID,
  1659. m_ConnectionList[i].pszConnectionName,
  1660. &(pCurItem->pItemCheckState[i].dwIdle),
  1661. dwDefaultCheck,
  1662. NULL);
  1663. break;
  1664. default:
  1665. AssertSz(0,"Unknown SyncType");
  1666. break;
  1667. }
  1668. }
  1669. pCurItem = pCurItem->pnextItem;
  1670. }
  1671. }
  1672. return hr;
  1673. }
  1674. //--------------------------------------------------------------------------------
  1675. //
  1676. // FUNCTION: CHndlrQueue::ReadAdvancedIdleSettings
  1677. //
  1678. // PURPOSE: Reads in the advanced Idle Settings.
  1679. //
  1680. // COMMENTS:
  1681. //
  1682. // HISTORY: 01-01-98 SusiA Created.
  1683. //
  1684. //--------------------------------------------------------------------------------
  1685. STDMETHODIMP CHndlrQueue::ReadAdvancedIdleSettings(LPCONNECTIONSETTINGS pConnectionSettings)
  1686. {
  1687. // connection settings for global idle are really overloaded.
  1688. // advanced idle settings are in each connection so just copy it from
  1689. // whatever the first connection is.
  1690. if ( (m_ConnectionCount < 1) || (NULL == m_ConnectionList))
  1691. return S_FALSE;
  1692. *pConnectionSettings = m_ConnectionList[0];
  1693. return NOERROR;
  1694. }
  1695. STDMETHODIMP CHndlrQueue::WriteAdvancedIdleSettings(LPCONNECTIONSETTINGS pConnectionSettings)
  1696. {
  1697. int iIndex;
  1698. // connection settings for global idle are really overloaded.
  1699. // advanced idle settings are in each connection so copy the members into each
  1700. // loaded connection in the list
  1701. for (iIndex = 0; iIndex < m_ConnectionCount; iIndex++)
  1702. {
  1703. m_ConnectionList[iIndex].ulIdleWaitMinutes = pConnectionSettings->ulIdleWaitMinutes;
  1704. m_ConnectionList[iIndex].ulIdleRetryMinutes = pConnectionSettings->ulIdleRetryMinutes;
  1705. m_ConnectionList[iIndex].dwRepeatSynchronization = pConnectionSettings->dwRepeatSynchronization;
  1706. m_ConnectionList[iIndex].dwRunOnBatteries = pConnectionSettings->dwRunOnBatteries;
  1707. m_ConnectionList[iIndex].ulIdleWaitMinutes = pConnectionSettings->ulIdleWaitMinutes;
  1708. }
  1709. return NOERROR;
  1710. }
  1711. //--------------------------------------------------------------------------------
  1712. //
  1713. // FUNCTION: CHndlrQueue::CommitAutoSyncChanges(Ras *pRas)
  1714. //
  1715. // PURPOSE: Write the autosync settings to the registry. This is done when
  1716. // the user selects OK or APPLY from the settings dialog.
  1717. //
  1718. // COMMENTS:
  1719. //
  1720. // HISTORY: 01-01-98 SusiA Created.
  1721. //
  1722. //--------------------------------------------------------------------------------
  1723. STDMETHODIMP CHndlrQueue::CommitSyncChanges(SYNCTYPE syncType,CRasUI *pRas)
  1724. {
  1725. LPHANDLERINFO pHandlerInfo;
  1726. int i;
  1727. if (!m_ConnectionList) // if no connection list, nothing to do
  1728. {
  1729. Assert(m_ConnectionList);
  1730. return NOERROR;
  1731. }
  1732. switch (syncType)
  1733. {
  1734. case SYNCTYPE_AUTOSYNC:
  1735. RegSetAutoSyncSettings(m_ConnectionList, m_ConnectionCount, pRas,
  1736. !m_fItemsMissing /* fCleanReg */,
  1737. TRUE /* fSetMachineState */,
  1738. TRUE /* fPerUser */);
  1739. break;
  1740. case SYNCTYPE_IDLE:
  1741. RegSetIdleSyncSettings(m_ConnectionList, m_ConnectionCount, pRas,
  1742. !m_fItemsMissing /* fCleanReg */,
  1743. TRUE /* fPerUser */);
  1744. break;
  1745. default:
  1746. AssertSz(0,"Unknown SyncType");
  1747. break;
  1748. }
  1749. for (i=0; i<m_ConnectionCount; i++)
  1750. {
  1751. pHandlerInfo = m_pFirstHandler;
  1752. while (pHandlerInfo)
  1753. {
  1754. LPITEMLIST pCurItem = pHandlerInfo->pFirstItem;
  1755. BOOL fAnyItemsChecked = FALSE;
  1756. while (pCurItem)
  1757. {
  1758. switch (syncType)
  1759. {
  1760. case SYNCTYPE_AUTOSYNC:
  1761. fAnyItemsChecked |= pCurItem->pItemCheckState[i].dwAutoSync;
  1762. RegSetSyncItemSettings(syncType,
  1763. pHandlerInfo->clsidHandler,
  1764. pCurItem->offlineItem.ItemID,
  1765. m_ConnectionList[i].pszConnectionName,
  1766. pCurItem->pItemCheckState[i].dwAutoSync,
  1767. NULL);
  1768. break;
  1769. case SYNCTYPE_IDLE:
  1770. fAnyItemsChecked |= pCurItem->pItemCheckState[i].dwIdle;
  1771. RegSetSyncItemSettings(syncType,
  1772. pHandlerInfo->clsidHandler,
  1773. pCurItem->offlineItem.ItemID,
  1774. m_ConnectionList[i].pszConnectionName,
  1775. pCurItem->pItemCheckState[i].dwIdle,
  1776. NULL);
  1777. break;
  1778. }
  1779. pCurItem = pCurItem->pnextItem;
  1780. }
  1781. // write out the NoItems checked value on the handler for this connection
  1782. RegSetSyncHandlerSettings(syncType,
  1783. m_ConnectionList[i].pszConnectionName,
  1784. pHandlerInfo->clsidHandler,
  1785. fAnyItemsChecked ? 1 : 0);
  1786. pHandlerInfo = pHandlerInfo->pNextHandler;
  1787. }
  1788. }
  1789. return ERROR_SUCCESS;
  1790. }
  1791. //--------------------------------------------------------------------------------
  1792. //
  1793. // FUNCTION: CHndlrQueue::CommitSchedSyncChanges(TCHAR * pszSchedName,
  1794. // TCHAR * pszFriendlyName,
  1795. // TCHAR * pszConnectionName,
  1796. // DWORD dwConnType,
  1797. // BOOL fCleanReg)
  1798. //
  1799. //
  1800. // PURPOSE: Write the scheduled sync settings to the registry. This is done when
  1801. // the user selects OK or FINISH from the settings dialog.
  1802. //
  1803. // COMMENTS:
  1804. //
  1805. // HISTORY: 01-01-98 SusiA Created.
  1806. //
  1807. //--------------------------------------------------------------------------------
  1808. STDMETHODIMP CHndlrQueue::CommitSchedSyncChanges(TCHAR * pszSchedName,
  1809. TCHAR * pszFriendlyName,
  1810. TCHAR * pszConnectionName,
  1811. DWORD dwConnType,
  1812. BOOL fCleanReg)
  1813. {
  1814. HRESULT hr;
  1815. LPHANDLERINFO pHandlerInfo;
  1816. pHandlerInfo = m_pFirstHandler;
  1817. if (!m_ConnectionList) // Review - What should we do here?
  1818. {
  1819. hr = E_FAIL;
  1820. }
  1821. else
  1822. {
  1823. if (fCleanReg && !m_fItemsMissing)
  1824. {
  1825. RegRemoveScheduledTask(pszSchedName); // Remove any previous settings
  1826. }
  1827. hr = StringCchCopy(m_ConnectionList->pszConnectionName,
  1828. ARRAYSIZE(m_ConnectionList->pszConnectionName),
  1829. pszConnectionName);
  1830. if (SUCCEEDED(hr))
  1831. {
  1832. m_ConnectionList->dwConnType = dwConnType;
  1833. //set the SID on this schedule
  1834. if (!RegSetSIDForSchedule(pszSchedName) ||
  1835. !RegSetSchedFriendlyName(pszSchedName,pszFriendlyName))
  1836. {
  1837. hr = E_FAIL;
  1838. }
  1839. else
  1840. {
  1841. RegSetSchedSyncSettings(m_ConnectionList, pszSchedName);
  1842. while (pHandlerInfo)
  1843. {
  1844. LPITEMLIST pCurItem = pHandlerInfo->pFirstItem;
  1845. while (pCurItem)
  1846. {
  1847. RegSetSyncItemSettings(SYNCTYPE_SCHEDULED,
  1848. pHandlerInfo->clsidHandler,
  1849. pCurItem->offlineItem.ItemID,
  1850. m_ConnectionList->pszConnectionName,
  1851. pCurItem->pItemCheckState[0].dwSchedule,
  1852. pszSchedName);
  1853. pCurItem = pCurItem->pnextItem;
  1854. }
  1855. pHandlerInfo = pHandlerInfo->pNextHandler;
  1856. }
  1857. hr = S_OK;
  1858. }
  1859. }
  1860. }
  1861. return hr;
  1862. }