From b2f6a0235c5de32a3fcd359e28f4d1e3bd6950df Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 4 May 2018 23:12:54 +0200 Subject: Add web page preview (image or html content), not finished --- include/Cache.hpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'include/Cache.hpp') diff --git a/include/Cache.hpp b/include/Cache.hpp index 71226cc..311658b 100644 --- a/include/Cache.hpp +++ b/include/Cache.hpp @@ -16,8 +16,9 @@ namespace TinyProcessLib namespace dchat { class Gif; + class WebPagePreview; - struct ImageByUrlResult + struct ContentByUrlResult { enum class Type { @@ -26,19 +27,29 @@ namespace dchat FAILED_DOWNLOAD }; - ImageByUrlResult() : texture(nullptr), type(Type::DOWNLOADING), isGif(false) {} - ImageByUrlResult(sf::Texture *_texture, Type _type) : texture(_texture), type(_type), isGif(false) {} - ImageByUrlResult(Gif *_gif, Type _type) : gif(_gif), type(_type), isGif(true) {} + enum class CachedType + { + NONE, + TEXTURE, + GIF, + WEB_PAGE_PREVIEW + }; + + ContentByUrlResult() : texture(nullptr), type(Type::DOWNLOADING), cachedType(CachedType::NONE) {} + ContentByUrlResult(sf::Texture *_texture, Type _type) : texture(_texture), type(_type), cachedType(CachedType::TEXTURE) {} + ContentByUrlResult(Gif *_gif, Type _type) : gif(_gif), type(_type), cachedType(CachedType::GIF) {} + ContentByUrlResult(WebPagePreview *_webPagePreview, Type _type) : webPagePreview(_webPagePreview), type(_type), cachedType(CachedType::WEB_PAGE_PREVIEW) {} // @texture is null if @type is DOWNLOADING or FAILED_DOWNLOAD union { sf::Texture *texture; Gif *gif; + WebPagePreview *webPagePreview; }; Type type; - bool isGif; + CachedType cachedType; }; class Cache @@ -56,10 +67,10 @@ namespace dchat static void loadBindsFromFile(); static void replaceBindsInFile(const std::unordered_map &binds); - // Get cached image or downloads it. + // Get cached content or download it. // Default download file limit is 12MB - // Returns ImageByUrlResult describing texture status. - const ImageByUrlResult getImageByUrl(const std::string &url, int downloadLimitBytes = 12582912); + // Returns ContentByUrlResult describing texture status. + const ContentByUrlResult getContentByUrl(const std::string &url, int downloadLimitBytes = 12582912); private: struct ImageDownloadInfo { -- cgit v1.2.3