updateui.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 9k
Category:

Windows Kernel

Development Platform:

Visual C++

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