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.

285 lines
8.5 KiB

  1. #define UA_STATUS_IDLE 0
  2. #define UA_STATUS_UPDATEALL 1
  3. #define UA_STATUS_MULTIPLE 2
  4. #define UPDATEALL_PENDING 3
  5. #define MULTIPLE_PENDING 4
  6. #define U_STATUS_ABORTED 5
  7. const UM_ONREQUEST = WM_USER + 4;
  8. const UM_ONSKIP = WM_USER + 5;
  9. const UM_ONABORT = WM_USER + 6;
  10. const UM_ONSKIPSINGLE = WM_USER + 7;
  11. const UM_ONADDSINGLE = WM_USER + 8;
  12. // At CleanUp msg we call CleanUp()/Release().
  13. const UM_CLEANUP = WM_USER + 3;
  14. // At Ready msg we call AddRef().
  15. // Who is sending us WM_USER + 9?
  16. const UM_READY = WM_USER + 10;
  17. const UM_BACKGROUND = WM_USER + 11;
  18. const UM_DECREASE = WM_USER + 12;
  19. const UM_BEGINREPORT = WM_USER + 13;
  20. const UM_ENDREPORT = WM_USER + 14;
  21. // Note: This is redefined in urlmon\download
  22. const UM_NEEDREBOOT = WM_USER + 16;
  23. #define IS_UPDATING(l) (((l)==UA_STATUS_UPDATEALL) || ((l)==UA_STATUS_MULTIPLE))
  24. #define IS_PENDING(l) (((l)==UPDATEALL_PENDING) || ((l)==MULTIPLE_PENDING))
  25. #define IS_IDLE(l) ((l)==UA_STATUS_IDLE)
  26. #define DIALER_OFFLINE 0
  27. #define DIALER_ONLINE 1
  28. #define DIALER_CONNECTING 2
  29. #define IDD_START IDD_RESET
  30. typedef enum {
  31. ITEM_STAT_IDLE,
  32. ITEM_STAT_PENDING,
  33. ITEM_STAT_SKIPPED,
  34. ITEM_STAT_FAILED,
  35. ITEM_STAT_UPDATING,
  36. ITEM_STAT_SUCCEEDED,
  37. ITEM_STAT_ABORTED,
  38. ITEM_STAT_QUEUED,
  39. E_ATTEMPT_FAILED,
  40. E_CONNECTION_LOST
  41. } STATUS, CONNECT_ERROR;
  42. #define MAX_COLUMN 16
  43. #define CHECKBOX_NONE 16384
  44. #define CHECKBOX_OFF 4096
  45. #define CHECKBOX_ON 8192
  46. class CDialHelper;
  47. class CUpdateAgent;
  48. class CUpdateController;
  49. struct CookieItemMapEntry {
  50. CLSID _cookie;
  51. LPARAM _id;
  52. };
  53. class CCookieItemMap {
  54. private:
  55. CookieItemMapEntry* _map;
  56. UINT _count;
  57. UINT _capacity;
  58. LPARAM _lParamNext;
  59. public:
  60. CCookieItemMap();
  61. ~CCookieItemMap();
  62. STDMETHODIMP Init(UINT size = 0);
  63. STDMETHODIMP DelCookie(CLSID *);
  64. STDMETHODIMP FindLParam(CLSID *, LPARAM *);
  65. STDMETHODIMP FindCookie(LPARAM, CLSID *);
  66. STDMETHODIMP AddCookie(CLSID *, LPARAM *);
  67. STDMETHODIMP ResetMap();
  68. };
  69. extern DWORD WINAPI UpdateThreadProc(LPVOID);
  70. extern BOOL CALLBACK UpdateDlgProc(HWND hDlg, UINT iMsg, WPARAM, LPARAM);
  71. extern BOOL ListView_OnNotify(HWND hDlg, NM_LISTVIEW *, CUpdateController *);
  72. class CUpdateDialog
  73. {
  74. friend BOOL CALLBACK UpdateDlgProc(HWND, UINT, WPARAM, LPARAM);
  75. friend DWORD WINAPI UpdateThreadProc(LPVOID);
  76. public:
  77. CUpdateDialog();
  78. ~CUpdateDialog();
  79. // Helper APIs
  80. // Get columns set up.
  81. STDMETHODIMP Init(HWND hParent, CUpdateController *);
  82. // Show/Hide the page.
  83. STDMETHODIMP Show(BOOL);
  84. // Change the appearance of item accord to new stat and return old stat
  85. // if needed.
  86. STDMETHODIMP RefreshStatus(CLSID *, LPTSTR, STATUS, LPTSTR = NULL);
  87. // Add new item with the status.
  88. STDMETHODIMP AddItem(CLSID *, LPTSTR, STATUS);
  89. // Reset the dialog.
  90. STDMETHODIMP ResetDialog(void);
  91. // Get a list of cookies that are selected.
  92. STDMETHODIMP GetSelectedCookies(CLSID *, UINT *);
  93. // Get the count of selected cookies.
  94. STDMETHODIMP GetSelectionCount(UINT *);
  95. // Get the cookie according to the iItem;
  96. STDMETHODIMP IItem2Cookie(const int iItem, CLSID *);
  97. STDMETHODIMP CleanUp(void);
  98. BOOL SelectFirstUpdatingSubscription();
  99. DWORD SetSiteDownloadSize (CLSID *, DWORD);
  100. HWND m_hDlg;
  101. DWORD m_ThreadID;
  102. int colMap[MAX_COLUMN];
  103. CUpdateController * m_pController;
  104. static BOOL m_bDetail;
  105. int m_cDlKBytes;
  106. int m_cDlDocs;
  107. int m_cxWidget;
  108. int m_cyWidget;
  109. private:
  110. static int CALLBACK SortUpdatingToTop (LPARAM, LPARAM, LPARAM);
  111. BOOL PersistStateToRegistry (HWND hDlg);
  112. BOOL GetPersistentStateFromRegistry (struct _PROG_PERSIST_STATE& state, int iCharWidth);
  113. HWND m_hLV;
  114. HWND m_hParent;
  115. BOOL m_bInitialized;
  116. CCookieItemMap cookieMap;
  117. };
  118. //----------------------------------------------------------------------------
  119. // Update controller class
  120. //----------------------------------------------------------------------------
  121. typedef struct ReportMapEntry {
  122. NOTIFICATIONCOOKIE startCookie;
  123. STATUS status;
  124. DWORD progress;
  125. LPTSTR name;
  126. LPTSTR url;
  127. SUBSCRIPTIONTYPE subType;
  128. } * PReportMap;
  129. class CUpdateController : public INotificationSink
  130. {
  131. friend BOOL CALLBACK UpdateDlgProc(HWND, UINT, WPARAM, LPARAM);
  132. friend DWORD WINAPI UpdateThreadProc(LPVOID);
  133. friend BOOL ListView_OnNotify(HWND hDlg, NM_LISTVIEW *, CUpdateController *);
  134. friend class CDialHelper;
  135. private:
  136. ULONG m_cRef; // OLE ref count
  137. enum {CUC_ENTRY_INCRE = 32, CUC_MAX_ENTRY = 1024};
  138. PReportMap m_aReport;
  139. UINT m_cReportCount;
  140. UINT m_cReportCapacity;
  141. INotificationMgr *m_pNotMgr;
  142. CUpdateDialog *m_pDialog;
  143. CDialHelper *m_pDialer;
  144. DWORD m_ThreadID; // Update thread ID
  145. LONG m_count; // Current active updates.
  146. UINT m_cTotal;
  147. UINT m_cFinished;
  148. BOOL m_fInit;
  149. BOOL m_fSessionEnded;
  150. // private Helper APIs
  151. STDMETHODIMP AddEntry(NOTIFICATIONITEM *, STATUS);
  152. STDMETHODIMP DispatchRequest(PReportMap);
  153. STDMETHODIMP CancelRequest(PReportMap);
  154. STDMETHODIMP IncreaseCount();
  155. STDMETHODIMP DecreaseCount(CLSID *);
  156. STDMETHODIMP StartPending(void);
  157. STDMETHODIMP GetItemList(UINT *);
  158. STDMETHODIMP GetLocationOf(CLSID *, LPTSTR, UINT);
  159. BOOL IsSkippable(CLSID *);
  160. STDMETHODIMP ResyncData();
  161. STDMETHODIMP OnBeginReportFromTray(INotification *);
  162. STDMETHODIMP OnEndReportFromTray(INotification *);
  163. public:
  164. CUpdateController();
  165. ~CUpdateController();
  166. STDMETHODIMP QueryInterface(REFIID riid, void **punk);
  167. STDMETHODIMP_(ULONG) AddRef(void);
  168. STDMETHODIMP_(ULONG) Release(void);
  169. // INotificationSink members
  170. STDMETHODIMP OnNotification(
  171. LPNOTIFICATION pNotification,
  172. LPNOTIFICATIONREPORT pNotificationReport,
  173. DWORD dwReserved
  174. );
  175. // Helper APIs:
  176. STDMETHODIMP StartService(void);
  177. STDMETHODIMP StopService(STATUS);
  178. STDMETHODIMP CleanUp();
  179. STDMETHODIMP OnRequest(INotification *);
  180. STDMETHODIMP Skip(void);
  181. STDMETHODIMP SkipSingle(CLSID *);
  182. STDMETHODIMP AddSingle(CLSID *);
  183. STDMETHODIMP Restart(UINT count);
  184. STDMETHODIMP Abort(void);
  185. STDMETHODIMP Init(CUpdateDialog *);
  186. PReportMap FindReportEntry(CLSID *);
  187. SUBSCRIPTIONTYPE GetSubscriptionType(CLSID *);
  188. };
  189. class CUpdateAgent
  190. {
  191. protected:
  192. CUpdateController *m_pController;
  193. CUpdateDialog *m_pDialog;
  194. public:
  195. DWORD m_DialogThreadID;
  196. DWORD m_ThreadID;
  197. CUpdateAgent(void);
  198. ~CUpdateAgent(void);
  199. // other functions
  200. STDMETHODIMP Init(void);
  201. };
  202. class CDialHelper : public INotificationSink
  203. {
  204. friend class CUpdateController;
  205. protected:
  206. ULONG m_cRef;
  207. CUpdateController * m_pController;
  208. INotificationMgr * m_pNotMgr;
  209. INotificationReport * m_pConnAgentReport;
  210. UINT m_cConnection;
  211. DWORD m_ThreadID;
  212. public:
  213. INT m_iDialerStatus;
  214. public:
  215. CDialHelper(void);
  216. ~CDialHelper(void) {}
  217. // IUnknown members
  218. STDMETHODIMP QueryInterface(REFIID riid, void **punk);
  219. STDMETHODIMP_(ULONG) AddRef(void);
  220. STDMETHODIMP_(ULONG) Release(void);
  221. // INotificationSink members
  222. STDMETHODIMP OnNotification(
  223. LPNOTIFICATION pNotification,
  224. LPNOTIFICATIONREPORT pNotificationReport,
  225. DWORD dwReserved
  226. );
  227. STDMETHODIMP OnInetOnline(INotification *);
  228. STDMETHODIMP OnInetOffline(INotification *);
  229. STDMETHODIMP NotifyAutoDialer(NOTIFICATIONTYPE);
  230. STDMETHODIMP Init(CUpdateController *);
  231. STDMETHODIMP CleanUp();
  232. STDMETHODIMP HangUp();
  233. STDMETHODIMP DialOut();
  234. BOOL IsOffline() {
  235. return (DIALER_OFFLINE == m_iDialerStatus);
  236. }
  237. BOOL IsConnecting() {
  238. return (DIALER_CONNECTING == m_iDialerStatus);
  239. }
  240. };