diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-04-21 03:46:58 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2018-04-21 03:50:59 +0200 |
commit | 09a8ade6becca2a71f45ff0db5f4bf6d64afb212 (patch) | |
tree | 3cc733a5af1323c57f7dc4c18747ae0c7de78be6 /include/Cache.hpp | |
parent | de059e317e43fa1b94d77fd981be68b86bf6de6e (diff) |
Add support for static image emoji
Emoji are downloaded asynchronously using remote program (curl).
Need to add support for converting [inline](url) chat message emoji
and gifs.
Diffstat (limited to 'include/Cache.hpp')
-rw-r--r-- | include/Cache.hpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/include/Cache.hpp b/include/Cache.hpp new file mode 100644 index 0000000..89abe2c --- /dev/null +++ b/include/Cache.hpp @@ -0,0 +1,54 @@ +#pragma once + +#include <boost/filesystem/path.hpp> +#include <SFML/Graphics/Texture.hpp> +#include <string> +#include <thread> +#include <mutex> +#include <vector> + +namespace TinyProcessLib +{ + class Process; +} + +namespace dchat +{ + struct ImageByUrlResult + { + enum class Type + { + CACHED, + DOWNLOADING, + FAILED_DOWNLOAD + }; + + // @texture is null if @type is DOWNLOADING or FAILED_DOWNLOAD + const sf::Texture *texture; + Type type; + }; + + class Cache + { + public: + Cache(); + + // Creates directory if it doesn't exist (recursively). Throws boost exception on failure + static boost::filesystem::path getDchatDir(); + + // Get cached image or downloads it. + // Default download file limit is 12MB + // Returns ImageByUrlResult describing texture status. + const ImageByUrlResult getImageByUrl(const std::string &url, int downloadLimitBytes = 12582912); + private: + struct ImageDownloadInfo + { + TinyProcessLib::Process *process; + std::string url; + }; + + std::thread downloadWaitThread; + std::vector<ImageDownloadInfo> imageDownloadProcesses; + std::mutex imageDownloadMutex; + }; +} |