#pragma once #include #include #include #include #include #include "filecache.hpp" class ImageManager { public: ImageManager(); using callback_anim_type = sigc::slot)>; using callback_type = sigc::slot)>; Cache &GetCache(); void ClearCache(); void LoadFromURL(std::string url, callback_type cb); // animations need dimensions before loading since there is no (easy) way to scale a PixbufAnimation void LoadAnimationFromURL(std::string url, int w, int h, callback_anim_type cb); void Prefetch(std::string url); Glib::RefPtr GetFromURLIfCached(std::string url); Glib::RefPtr GetAnimationFromURLIfCached(std::string url, int w, int h); Glib::RefPtr GetPlaceholder(int size); private: Glib::RefPtr ReadFileToPixbuf(std::string path); Glib::RefPtr ReadFileToPixbufAnimation(std::string path, int w, int h); mutable std::mutex m_load_mutex; void RunCallbacks(); Glib::Dispatcher m_cb_dispatcher; mutable std::mutex m_cb_mutex; std::queue> m_cb_queue; std::unordered_map> m_pixs; Cache m_cache; };