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.

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