aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-05-04 23:12:54 +0200
committerdec05eba <dec05eba@protonmail.com>2018-05-04 23:12:57 +0200
commitb2f6a0235c5de32a3fcd359e28f4d1e3bd6950df (patch)
tree0cd53dcd44cf744c88ef3d0b71c2f97172d8d0d0 /include
parent640d8df5277af4ac4b545cc6d4cf2830509e61b9 (diff)
Add web page preview (image or html content), not finished
Diffstat (limited to 'include')
-rw-r--r--include/Cache.hpp27
-rw-r--r--include/WebPagePreview.hpp15
2 files changed, 34 insertions, 8 deletions
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<std::string, std::string> &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
{
diff --git a/include/WebPagePreview.hpp b/include/WebPagePreview.hpp
new file mode 100644
index 0000000..749308c
--- /dev/null
+++ b/include/WebPagePreview.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <SFML/System/String.hpp>
+#include "Text.hpp"
+
+namespace dchat
+{
+ class WebPagePreview
+ {
+ public:
+ WebPagePreview(const sf::String &title);
+
+ Text title;
+ };
+}