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.

673 lines
22 KiB

  1. /** Copyright (c) 2000 Microsoft Corporation
  2. ******************************************************************************
  3. ** Module Name:
  4. **
  5. ** Newslib.h
  6. **
  7. ** Abstract:
  8. **
  9. ** Declaration of News Headlines classes
  10. **
  11. ** Author:
  12. **
  13. ** Martha Arellano (t-alopez) 06-Dec-2000
  14. **
  15. **
  16. ** Revision History:
  17. **
  18. **
  19. ******************************************************************************
  20. **/
  21. #if !defined(AFX_NEWSLIB_H__B87C3400_E0B9_48CD_A0A9_0223F4448759__INCLUDED_)
  22. #define AFX_NEWSLIB_H__B87C3400_E0B9_48CD_A0A9_0223F4448759__INCLUDED_
  23. ////////////////////////////////////////////////////////////////////////////////
  24. // NewsSet.xml path
  25. #define HC_HCUPDATE_NEWSSETTINGS HC_ROOT_HELPSVC_CONFIG L"\\NewsSet.xml"
  26. // newsver.xml path
  27. #define HC_HCUPDATE_NEWSVER HC_ROOT_HELPSVC_CONFIG L"\\News\\newsver.xml"
  28. // UpdateHeadlines.xml path
  29. #define HC_HCUPDATE_UPDATE HC_ROOT_HELPSVC_CONFIG L"\\News\\UpdateHeadlines.xml"
  30. // NewsHeadlines.xml path
  31. #define HC_HCUPDATE_NEWSHEADLINES HC_ROOT_HELPSVC_CONFIG L"\\News\\NewsHeadlines_"
  32. // default URL for newsver.xml
  33. #define NEWSSETTINGS_DEFAULT_URL L"http://go.microsoft.com/fwlink/?LinkID=11"
  34. //default URL for the icon for Update headlines
  35. #define HC_HCUPDATE_UPDATEBLOCK_ICONURL L"http://go.microsoft.com/fwlink/?LinkId=627"
  36. // default Frequency
  37. #define NEWSSETTINGS_DEFAULT_FREQUENCY 14
  38. // Headlines RegKey Name
  39. #define HEADLINES_REGKEY L"Headlines"
  40. // Default expiration date for news items from HCUpdate
  41. #define HCUPDATE_DEFAULT_TIMEOUT 10
  42. // Current number of OEM headlines
  43. #define NUMBER_OF_OEM_HEADLINES 2
  44. ////////////////////////////////////////////////////////////////////////////////
  45. namespace News
  46. {
  47. /////////////////////////////////////////////////////////////////////////////
  48. // NEWSVER
  49. //
  50. // The NEWSVER class loads the newsver.xml file, with the information to update the news headlines
  51. //
  52. // It defines the clases:
  53. // Newsblock
  54. // SKU
  55. // Language
  56. //
  57. // and the variables:
  58. // URL
  59. // Frequency
  60. //
  61. // list of Languages
  62. //
  63. //
  64. // Has the following functions:
  65. // Download ( URL )
  66. // Load( LCID, SKU )
  67. //
  68. // get_NumbeOfNewsblocks
  69. // get_NewsblockURL
  70. // get_URL
  71. // get_Frequency
  72. //
  73. class Newsver : public MPC::Config::TypeConstructor // hungarian: nw
  74. {
  75. public:
  76. //
  77. // The Newsblock class stores the newsfile information from the newsver.xml file:
  78. // URL
  79. //
  80. class Newsblock : public MPC::Config::TypeConstructor
  81. {
  82. DECLARE_CONFIG_MAP(Newsblock);
  83. public:
  84. MPC::wstring m_strURL;
  85. bool m_fNewsblockHasHeadlines;
  86. ////////////////////
  87. Newsblock();
  88. ////////////////////////////////////////
  89. //
  90. // MPC::Config::TypeConstructor
  91. //
  92. DEFINE_CONFIG_DEFAULTTAG();
  93. DECLARE_CONFIG_METHODS();
  94. //
  95. ////////////////////////////////////////
  96. };
  97. typedef std::vector< Newsblock > NewsblockVector;
  98. typedef NewsblockVector::iterator NewsblockIter;
  99. typedef NewsblockVector::const_iterator NewsblockIterConst;
  100. ////////////////////////////////////////
  101. //
  102. // The SKU class stores the SKU information from the newsver.xml file:
  103. // SKU Version (Professional, Personal, ...)
  104. //
  105. // vector of newsblocks
  106. //
  107. class SKU : public MPC::Config::TypeConstructor
  108. {
  109. DECLARE_CONFIG_MAP(SKU);
  110. public:
  111. MPC::wstring m_strSKU;
  112. NewsblockVector m_vecNewsblocks; //vector of newsblocks
  113. ////////////////////
  114. SKU();
  115. ////////////////////////////////////////
  116. //
  117. // MPC::Config::TypeConstructor
  118. //
  119. DEFINE_CONFIG_DEFAULTTAG();
  120. DECLARE_CONFIG_METHODS();
  121. //
  122. ////////////////////////////////////////
  123. };
  124. typedef std::list< SKU > SKUList;
  125. typedef SKUList::iterator SKUIter;
  126. typedef SKUList::const_iterator SKUIterConst;
  127. ////////////////////////////////////////
  128. //
  129. // The Language class stores the Language information from the newsver.xml file:
  130. // Language LCID
  131. //
  132. // list of SKUs
  133. //
  134. class Language : public MPC::Config::TypeConstructor
  135. {
  136. DECLARE_CONFIG_MAP(Language);
  137. public:
  138. long m_lLCID;
  139. SKUList m_lstSKUs; //list of SKUs
  140. ////////////////////
  141. Language();
  142. ////////////////////////////////////////
  143. //
  144. // MPC::Config::TypeConstructor
  145. //
  146. DEFINE_CONFIG_DEFAULTTAG();
  147. DECLARE_CONFIG_METHODS();
  148. //
  149. ////////////////////////////////////////
  150. };
  151. typedef std::list< Language > LanguageList;
  152. typedef LanguageList::iterator LanguageIter;
  153. typedef LanguageList::const_iterator LanguageIterConst;
  154. ////////////////////////////////////////
  155. private:
  156. DECLARE_CONFIG_MAP(Newsver);
  157. MPC::wstring m_strURL;
  158. int m_nFrequency;
  159. bool m_fLoaded;
  160. bool m_fDirty;
  161. LanguageList m_lstLanguages; //list of Languages
  162. SKU* m_data;
  163. public:
  164. Newsver();
  165. ////////////////////////////////////////
  166. //
  167. // MPC::Config::TypeConstructor
  168. //
  169. DEFINE_CONFIG_DEFAULTTAG();
  170. DECLARE_CONFIG_METHODS();
  171. //
  172. ////////////////////////////////////////
  173. HRESULT Download( /*[in]*/ const MPC::wstring& strNewsverURL );
  174. HRESULT Load( /*[in]*/ long lLCID, /*[in]*/ const MPC::wstring& strSKU );
  175. bool OEMNewsblock( /*[in]*/ size_t nIndex );
  176. size_t get_NumberOfNewsblocks( );
  177. const MPC::wstring* get_NewsblockURL ( /*[in]*/ size_t nIndex );
  178. const MPC::wstring* get_URL ( );
  179. int get_Frequency ( );
  180. };
  181. /////////////////////////////////////////////////////////////////////////////
  182. // Headlines
  183. //
  184. // The Headlines class manipulates the news headlines file (with 1 or more providers headlines)
  185. //
  186. //
  187. // It contains the clases:
  188. // Headline
  189. // Newsblock
  190. //
  191. // the variables:
  192. // Timestamp when was the file created from newsblocks
  193. // Date when was the file modified (and for the UI)
  194. //
  195. // list of Newsblocks
  196. //
  197. //
  198. // and the methods:
  199. // Clear()
  200. // Load( Path )
  201. // Save( Path )
  202. // get_Stream ( Path )
  203. // set_Timestamp()
  204. // get_Timestamp
  205. // get_Number_of_Newsblocks
  206. // check_Number_of_Newsblocks
  207. // Time_To_Update_Newsblock( BOOL )
  208. //
  209. // Add_Provider( Name, URL, PostDate )
  210. // Delete_Provider()
  211. //
  212. // Copy_Newsblock( index, LangSKU, ProvID, Block )
  213. // Add_First_Newsblock( index, LangSKU, BOOL )
  214. //
  215. class Headlines : public MPC::Config::TypeConstructor // hungarian nh
  216. {
  217. public:
  218. //
  219. // The Headline class stores the Headline information from the news headline:
  220. // Icon (path)
  221. // Title
  222. // Link
  223. // Description
  224. // Expires
  225. //
  226. class Headline : public MPC::Config::TypeConstructor
  227. {
  228. DECLARE_CONFIG_MAP(Headline);
  229. public:
  230. MPC::wstring m_strIcon;
  231. MPC::wstring m_strTitle;
  232. MPC::wstring m_strLink;
  233. MPC::wstring m_strDescription;
  234. DATE m_dtExpires;
  235. bool m_fUpdateHeadlines;
  236. ////////////////////
  237. Headline( );
  238. Headline( /*[in]*/ const MPC::wstring& strIcon ,
  239. /*[in]*/ const MPC::wstring& strTitle ,
  240. /*[in]*/ const MPC::wstring& strLink ,
  241. /*[in]*/ const MPC::wstring& strDescription ,
  242. /*[in]*/ DATE dtExpires ,
  243. /*[in]*/ bool fUpdateHeadlines);
  244. ////////////////////////////////////////
  245. //
  246. // MPC::Config::TypeConstructor
  247. //
  248. DEFINE_CONFIG_DEFAULTTAG();
  249. DECLARE_CONFIG_METHODS();
  250. //
  251. ////////////////////////////////////////
  252. };
  253. typedef std::vector< Headline > HeadlineVector;
  254. typedef HeadlineVector::iterator HeadlineIter;
  255. typedef HeadlineVector::const_iterator HeadlineConst;
  256. ////////////////////////////////////////
  257. //
  258. // The Newsblock class stores the Provider information from the news headline:
  259. // Provider
  260. // Link
  261. // Icon
  262. // Position
  263. // Timestamp
  264. // Frequency
  265. //
  266. // vector of Headlines
  267. //
  268. class Newsblock : public MPC::Config::TypeConstructor
  269. {
  270. DECLARE_CONFIG_MAP(Newsblock);
  271. private:
  272. void GetFileName( MPC::wstring strURL, MPC::wstring& strFileName );
  273. public:
  274. MPC::wstring m_strProvider;
  275. MPC::wstring m_strLink;
  276. MPC::wstring m_strIcon;
  277. MPC::wstring m_strPosition;
  278. DATE m_dtTimestamp;
  279. int m_nFrequency;
  280. HeadlineVector m_vecHeadlines; //vector of headlines
  281. ////////////////////
  282. Newsblock();
  283. ////////////////////////////////////////
  284. //
  285. // MPC::Config::TypeConstructor
  286. //
  287. DEFINE_CONFIG_DEFAULTTAG();
  288. DECLARE_CONFIG_METHODS();
  289. //
  290. ////////////////////////////////////////
  291. bool TimeToUpdate();
  292. HRESULT Copy( /*[in]*/ const Headlines::Newsblock& block ,
  293. /*[in]*/ const MPC::wstring& strLangSKU ,
  294. /*[in]*/ int nProvID );
  295. };
  296. typedef std::vector< Newsblock > NewsblockVector;
  297. typedef NewsblockVector::iterator NewsblockIter;
  298. typedef NewsblockVector::const_iterator NewsblockIterConst;
  299. ////////////////////////////////////////
  300. private:
  301. DECLARE_CONFIG_MAP(Headlines);
  302. DATE m_dtTimestamp;
  303. DATE m_dtDate;
  304. NewsblockVector m_vecNewsblocks; // vector of newsblocks
  305. public:
  306. Headlines();
  307. ////////////////////////////////////////
  308. //
  309. // MPC::Config::TypeConstructor
  310. //
  311. DEFINE_CONFIG_DEFAULTTAG();
  312. DECLARE_CONFIG_METHODS();
  313. //
  314. ////////////////////////////////////////
  315. HRESULT Clear( );
  316. HRESULT Load ( /*[in]*/ const MPC::wstring& strPath );
  317. HRESULT Save ( /*[in]*/ const MPC::wstring& strPath );
  318. HRESULT get_Stream( /*[in]*/ long lLCID, /*[in]*/ const MPC::wstring& strSKU, /*[in]*/ const MPC::wstring& strPath, /*[out]*/ IUnknown* *pVal );
  319. void set_Timestamp ( );
  320. DATE get_Timestamp ( ) { return m_dtTimestamp; }
  321. size_t get_NumberOfNewsblocks( ) { return m_vecNewsblocks.size(); }
  322. Headlines::Newsblock* get_Newsblock ( /*[in]*/ size_t nBlockIndex );
  323. HRESULT AddNewsblock( /*[in]*/ const Headlines::Newsblock& block, /*[in]*/ const MPC::wstring& strLangSKU );
  324. HRESULT AddHomepageHeadlines( /*[in]*/ const Headlines::Newsblock& block );
  325. };
  326. /////////////////////////////////////////////////////////////////////////////
  327. // UpdateHeadlines
  328. //
  329. // The UpdateHeadlines class loads the UpdateHeadlines.xml file
  330. // that contains update headlines to insert in the news headlines
  331. //
  332. // It defines the classes:
  333. // Headline
  334. // SKU
  335. // Language
  336. //
  337. // and the variables:
  338. //
  339. // list of Languages
  340. //
  341. // functions:
  342. // Load ( LCID, SKU )
  343. // Save ( )
  344. // Add ( LCID, SKU, Icon, Title, Link, #Days )
  345. // Get ( LCID, SKU, list of Headlines )
  346. //
  347. class UpdateHeadlines : public MPC::Config::TypeConstructor // hungarian: uh
  348. {
  349. public:
  350. //
  351. // The Headline class stores the Headline information from the news headline:
  352. // Icon
  353. // Title
  354. // Link
  355. // Expires
  356. //
  357. class Headline : public MPC::Config::TypeConstructor
  358. {
  359. DECLARE_CONFIG_MAP(Headline);
  360. public:
  361. MPC::wstring m_strIcon;
  362. MPC::wstring m_strTitle;
  363. MPC::wstring m_strLink;
  364. MPC::wstring m_strDescription;
  365. DATE m_dtTimeOut;
  366. ////////////////////
  367. Headline( );
  368. Headline( /*[in]*/ const MPC::wstring& strIcon ,
  369. /*[in]*/ const MPC::wstring& strTitle ,
  370. /*[in]*/ const MPC::wstring& strLink ,
  371. /*[in]*/ const MPC::wstring& strDescription ,
  372. /*[in]*/ int nDays );
  373. ////////////////////////////////////////
  374. //
  375. // MPC::Config::TypeConstructor
  376. //
  377. DEFINE_CONFIG_DEFAULTTAG();
  378. DECLARE_CONFIG_METHODS();
  379. //
  380. ////////////////////////////////////////
  381. };
  382. typedef std::vector< Headline > HeadlineVector;
  383. typedef HeadlineVector::iterator HeadlineIter;
  384. typedef HeadlineVector::const_iterator HeadlineConst;
  385. ////////////////////////////////////////
  386. //
  387. // The SKU class stores the SKU information:
  388. // SKU Version (Professional, Personal, ...)
  389. //
  390. // vector of Newsfiles
  391. //
  392. class SKU : public MPC::Config::TypeConstructor
  393. {
  394. DECLARE_CONFIG_MAP(SKU);
  395. public:
  396. MPC::wstring m_strSKU;
  397. HeadlineVector m_vecHeadlines; //vector of news files
  398. ////////////////////
  399. SKU( );
  400. SKU( /*[in]*/ const MPC::wstring& strSKU );
  401. ////////////////////////////////////////
  402. //
  403. // MPC::Config::TypeConstructor
  404. //
  405. DEFINE_CONFIG_DEFAULTTAG();
  406. DECLARE_CONFIG_METHODS();
  407. //
  408. ////////////////////////////////////////
  409. };
  410. typedef std::list< SKU > SKUList;
  411. typedef SKUList::iterator SKUIter;
  412. typedef SKUList::const_iterator SKUIterConst;
  413. ////////////////////////////////////////
  414. //
  415. // The Language class stores the Language information:
  416. // Language LCID
  417. //
  418. // list of SKUs
  419. //
  420. class Language : public MPC::Config::TypeConstructor
  421. {
  422. DECLARE_CONFIG_MAP(Language);
  423. public:
  424. long m_lLCID;
  425. SKUList m_lstSKUs; //list of SKUs
  426. ////////////////////
  427. Language( );
  428. Language( /*[in]*/ long lLCID );
  429. ////////////////////////////////////////
  430. //
  431. // MPC::Config::TypeConstructor
  432. //
  433. DEFINE_CONFIG_DEFAULTTAG();
  434. DECLARE_CONFIG_METHODS();
  435. //
  436. ////////////////////////////////////////
  437. };
  438. typedef std::list< Language > LanguageList;
  439. typedef LanguageList::iterator LanguageIter;
  440. typedef LanguageList::const_iterator LanguageIterConst;
  441. ////////////////////////////////////////
  442. private:
  443. DECLARE_CONFIG_MAP(UpdateHeadlines);
  444. LanguageList m_lstLanguages; //list of Languages
  445. SKU* m_data;
  446. bool m_fLoaded;
  447. bool m_fDirty;
  448. ////////////////////
  449. HRESULT Locate( /*[in]*/ long lLCID, /*[in]*/ const MPC::wstring& strSKU, /*[in]*/ bool fCreate );
  450. public:
  451. UpdateHeadlines();
  452. ////////////////////////////////////////
  453. //
  454. // MPC::Config::TypeConstructor
  455. //
  456. DEFINE_CONFIG_DEFAULTTAG();
  457. DECLARE_CONFIG_METHODS();
  458. //
  459. ////////////////////////////////////////
  460. HRESULT Load( /*[in]*/ long lLCID ,
  461. /*[in]*/ const MPC::wstring& strSKU );
  462. HRESULT Save( );
  463. HRESULT Add ( /*[in]*/ long lLCID ,
  464. /*[in]*/ const MPC::wstring& strSKU ,
  465. /*[in]*/ const MPC::wstring& strIcon ,
  466. /*[in]*/ const MPC::wstring& strTitle ,
  467. /*[in]*/ const MPC::wstring& strDescription ,
  468. /*[in]*/ const MPC::wstring& strLink ,
  469. /*[in]*/ int nTimeOutDays ,
  470. /*[in]*/ DATE dtExpiryDate);
  471. HRESULT AddHCUpdateHeadlines( /*[in]*/ long lLCID ,
  472. /*[in]*/ const MPC::wstring& strSKU ,
  473. /*[in]*/ News::Headlines& nhHeadlines);
  474. HRESULT DoesMoreThanOneHeadlineExist( /*[in]*/ long lLCID,
  475. /*[in]*/ const MPC::wstring& strSKU,
  476. /*[out]*/ bool& fMoreThanOneHeadline,
  477. /*[out]*/ bool& fExactlyOneHeadline);
  478. };
  479. ////////////////////////////////////////////////////////////////////////////////
  480. /////////////////////////////////////////////////////////////////////////////
  481. // CNewslib
  482. //
  483. // The CNewslib class stores the information in the cached newsset.xml file, that stores the user news settings:
  484. // URL, Frequency (in days) and Timestamp (the time the news headlines were last updated).
  485. //
  486. // Has the following methods:
  487. // Load()
  488. // Restore(LCID)
  489. // Save()
  490. // Time_To_Update_Newsver(BOOL)
  491. // Update_Newsver
  492. // Update_NewsHeadlines
  493. // Update_Newsblocks
  494. //
  495. // get_Headlines_Enabled (BOOL)
  496. // get_News( LCID, SKU, IStream)
  497. // get_Cached_News( LCID, SKU, IStream)
  498. // get_Download_News( LCID, SKU, IStream)
  499. // get_URL
  500. // put_URL
  501. // get_Frequency
  502. // put_Frequency
  503. //
  504. //
  505. class Main : public MPC::Config::TypeConstructor
  506. {
  507. DECLARE_CONFIG_MAP(Main);
  508. MPC::wstring m_strURL;
  509. int m_nFrequency;
  510. DATE m_dtTimestamp;
  511. bool m_fLoaded;
  512. bool m_fDirty;
  513. long m_lLCID;
  514. MPC::wstring m_strSKU;
  515. MPC::wstring m_strLangSKU;
  516. MPC::wstring m_strNewsHeadlinesPath;
  517. bool m_fOnline;
  518. bool m_fConnectionStatusChecked;
  519. ////////////////////
  520. HRESULT Init( /*[in]*/ long lLCID, /*[in]*/ BSTR bstrSKU );
  521. public:
  522. Main();
  523. ////////////////////////////////////////
  524. //
  525. // MPC::Config::TypeConstructor
  526. //
  527. DEFINE_CONFIG_DEFAULTTAG();
  528. DECLARE_CONFIG_METHODS();
  529. //
  530. ////////////////////////////////////////
  531. HRESULT Load ( );
  532. HRESULT Restore( /*[in]*/ long lLCID );
  533. HRESULT Save ( );
  534. bool IsTimeToUpdateNewsver();
  535. HRESULT Update_Newsver ( /*[in/out]*/ Newsver& nwNewsver );
  536. HRESULT Update_NewsHeadlines( /*[in/out]*/ Newsver& nwNewsver, /*[in/out]*/ Headlines& nhHeadlines );
  537. HRESULT Update_NewsBlocks ( /*[in/out]*/ Newsver& nwNewsver, /*[in/out]*/ Headlines& nhHeadlines );
  538. HRESULT get_URL ( /*[out]*/ BSTR *pVal );
  539. HRESULT put_URL ( /*[in ]*/ BSTR newVal );
  540. HRESULT get_Frequency( /*[out]*/ int *pVal );
  541. HRESULT put_Frequency( /*[in ]*/ int newVal );
  542. HRESULT get_Headlines_Enabled( /*[out]*/ VARIANT_BOOL *pVal );
  543. HRESULT get_News ( /*[in]*/ long lLCID, /*[in]*/ BSTR bstrSKU, /*[out]*/ IUnknown* *pVal );
  544. HRESULT get_News_Cached ( /*[in]*/ long lLCID, /*[in]*/ BSTR bstrSKU, /*[out]*/ IUnknown* *pVal );
  545. HRESULT get_News_Download( /*[in]*/ long lLCID, /*[in]*/ BSTR bstrSKU, /*[out]*/ IUnknown* *pVal );
  546. HRESULT AddHCUpdateNews (/*[in ]*/ const MPC::wstring& strNewsHeadlinesPath );
  547. bool CheckConnectionStatus ();
  548. };
  549. ////////////////////////////////////////////////////////////////////////////////
  550. HRESULT LoadXMLFile ( /*[in]*/ LPCWSTR szURL, /*[out]*/ CComPtr<IStream>& stream );
  551. HRESULT LoadFileFromServer ( /*[in]*/ LPCWSTR szURL, /*[out]*/ CComPtr<IStream>& stream );
  552. };
  553. #endif // !defined(AFX_NEWSLIB_H__B87C3400_E0B9_48CD_A0A9_0223F4448759__INCLUDED_)