2020-09-12 07:17:34 +00:00
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <functional>
|
2020-10-03 22:49:22 +00:00
|
|
|
#include <queue>
|
2020-09-12 07:17:34 +00:00
|
|
|
#include <gtkmm.h>
|
|
|
|
#include "filecache.hpp"
|
|
|
|
|
|
|
|
class ImageManager {
|
|
|
|
public:
|
2020-10-03 22:49:22 +00:00
|
|
|
ImageManager();
|
|
|
|
|
|
|
|
using callback_type = std::function<void(Glib::RefPtr<Gdk::Pixbuf>)>;
|
|
|
|
|
2020-09-12 07:17:34 +00:00
|
|
|
Cache &GetCache();
|
2020-10-03 22:49:22 +00:00
|
|
|
void LoadFromURL(std::string url, callback_type cb);
|
2020-09-12 07:17:34 +00:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> GetFromURLIfCached(std::string url);
|
2020-09-12 23:35:24 +00:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> GetPlaceholder(int size);
|
2020-09-12 07:17:34 +00:00
|
|
|
|
|
|
|
private:
|
2020-10-03 22:49:22 +00:00
|
|
|
Glib::RefPtr<Gdk::Pixbuf> ReadFileToPixbuf(std::string path);
|
|
|
|
|
|
|
|
mutable std::mutex m_load_mutex;
|
|
|
|
void RunCallbacks();
|
|
|
|
Glib::Dispatcher m_cb_dispatcher;
|
|
|
|
mutable std::mutex m_cb_mutex;
|
|
|
|
std::queue<std::pair<Glib::RefPtr<Gdk::Pixbuf>, callback_type>> m_cb_queue;
|
|
|
|
|
2020-09-12 07:17:34 +00:00
|
|
|
std::unordered_map<std::string, Glib::RefPtr<Gdk::Pixbuf>> m_pixs;
|
|
|
|
Cache m_cache;
|
|
|
|
};
|