1 #ifndef WEBRESOURCESMANAGER_H 2 #define WEBRESOURCESMANAGER_H 3 4 #include <wx/hashmap.h> 5 #include <wx/arrstr.h> 6 #include <vector> 7 8 /** \brief Class managing web resources */ 9 class WebResourcesManager 10 { 11 public: 12 13 /** \brief Class which does handle progress notifying operations */ 14 class ProgressHandler 15 { 16 public: 17 18 /** \brief Values of predefined ids */ 19 enum PredefinedIds 20 { 21 idDownloadList = -1, 22 idDownloadConfig = -2 23 }; 24 ~ProgressHandler()25 virtual ~ProgressHandler() {} 26 27 /** \brief Notifying that new downlaod has been started 28 * \return Some identifier that will be passed into other handler functions 29 */ 30 virtual int StartDownloading( const wxString& Url ) = 0; 31 32 33 /** \brief Get progress change information, note if progres < 0, progress can not be calculated */ 34 virtual void SetProgress( float progress, int id ) = 0; 35 36 /** \brief Notifying that job has been finished */ 37 virtual void JobFinished( int id ) = 0; 38 39 /** \brief Notify about some error */ 40 virtual void Error( const wxString& info, int id ) = 0; 41 }; 42 43 /** \brief Ctor */ 44 WebResourcesManager(); 45 46 /** \brief Dctor */ 47 ~WebResourcesManager(); 48 49 /** \brief Load list of detection configurations from given list of base urls */ 50 bool LoadDetectionConfigurations( const wxArrayString& baseUrls, ProgressHandler* handler = 0 ); 51 52 /** \brief Try to download library detection settings with given shortcode */ 53 bool LoadDetectionConfig( const wxString& shortcut, std::vector< char >& content, ProgressHandler* handler = 0 ); 54 55 56 private: 57 58 struct DetectConfigurationEntry 59 { 60 wxString m_Url; ///< \brief Url to resource with configuration file 61 wxString m_Sign; ///< \brief Digital sign for the resource file (may be empty) 62 DetectConfigurationEntry* m_Next; ///< \brief Next configuration in the chain 63 }; 64 65 WX_DECLARE_STRING_HASH_MAP( DetectConfigurationEntry*, EntriesT ); 66 67 EntriesT m_Entries; 68 69 void ClearEntries(); 70 71 bool DoDownload( const wxString& url, ProgressHandler* handler, std::vector< char >& arr ); 72 }; 73 74 #endif 75