From 4ac27e91403b708088451c9c07f3b4c2eecb7cf2 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Wed, 30 Sep 2020 00:12:38 -0400 Subject: add wonky image loading --- imgmanager.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'imgmanager.cpp') diff --git a/imgmanager.cpp b/imgmanager.cpp index ce26b0f..2e582c3 100644 --- a/imgmanager.cpp +++ b/imgmanager.cpp @@ -5,15 +5,15 @@ Cache &ImageManager::GetCache() { } void ImageManager::LoadFromURL(std::string url, std::function)> cb) { - if (m_pixs.find(url) != m_pixs.end()) { + /*if (m_pixs.find(url) != m_pixs.end()) { cb(m_pixs.at(url)); return; - } + }*/ m_cache.GetFileFromURL(url, [this, url, cb](std::string path) { try { auto buf = Gdk::Pixbuf::create_from_file(path); - m_pixs[url] = buf; + //m_pixs[url] = buf; cb(buf); } catch (std::exception &e) { fprintf(stderr, "err loading pixbuf from %s: %s\n", path.c_str(), e.what()); @@ -22,20 +22,23 @@ void ImageManager::LoadFromURL(std::string url, std::function ImageManager::GetFromURLIfCached(std::string url) { - if (m_pixs.find(url) != m_pixs.end()) - return m_pixs.at(url); + std::string path = m_cache.GetPathIfCached(url); + if (path != "") + return Gdk::Pixbuf::create_from_file(path); + //if (m_pixs.find(url) != m_pixs.end()) + // return m_pixs.at(url); return Glib::RefPtr(nullptr); } Glib::RefPtr ImageManager::GetPlaceholder(int size) { std::string name = "/placeholder" + std::to_string(size); - if (m_pixs.find(name) != m_pixs.end()) - return m_pixs.at(name); + //if (m_pixs.find(name) != m_pixs.end()) + // return m_pixs.at(name); try { auto buf = Gdk::Pixbuf::create_from_file("res/decamarks.png", size, size); - m_pixs[name] = buf; + // m_pixs[name] = buf; return buf; } catch (std::exception &e) { fprintf(stderr, "error loading placeholder\n"); -- cgit v1.2.3