diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-10-04 15:31:39 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-10-04 15:31:39 -0400 |
commit | 69c4b0c948b6c141c9d251f20a973be064ab0087 (patch) | |
tree | f5fe4b0a63bd69d4d5078103c5de2f623a5fd5f6 | |
parent | 77fc962de4fbf6c21b76c8e4a43390b879315b10 (diff) | |
download | abaddon-portaudio-69c4b0c948b6c141c9d251f20a973be064ab0087.tar.gz abaddon-portaudio-69c4b0c948b6c141c9d251f20a973be064ab0087.zip |
use sigc in imgmanager to hopefully get rid of some lifetime errors
-rw-r--r-- | components/channels.cpp | 14 | ||||
-rw-r--r-- | components/channels.hpp | 2 | ||||
-rw-r--r-- | imgmanager.cpp | 9 | ||||
-rw-r--r-- | imgmanager.hpp | 4 |
4 files changed, 15 insertions, 14 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index 6d2f60e..9b95f1d 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -70,7 +70,7 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const Channel *data) { void ChannelListRowDMChannel::OnImageLoad(Glib::RefPtr<Gdk::Pixbuf> buf) { if (m_icon != nullptr) - m_icon->property_pixbuf() = buf; + m_icon->property_pixbuf() = buf->scale_simple(24, 24, Gdk::INTERP_BILINEAR); } ChannelListRowGuild::ChannelListRowGuild(const Guild *data) { @@ -85,13 +85,7 @@ ChannelListRowGuild::ChannelListRowGuild(const Guild *data) { m_icon = Gtk::manage(new Gtk::Image(buf->scale_simple(24, 24, Gdk::INTERP_BILINEAR))); else { m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24))); - Abaddon::Get().GetImageManager().LoadFromURL(data->GetIconURL("png", "32"), [this](Glib::RefPtr<Gdk::Pixbuf> ldbuf) { - Glib::signal_idle().connect([this, ldbuf]() -> bool { - m_icon->property_pixbuf() = ldbuf->scale_simple(24, 24, Gdk::INTERP_BILINEAR); - - return false; - }); - }); + Abaddon::Get().GetImageManager().LoadFromURL(data->GetIconURL("png", "32"), sigc::mem_fun(*this, &ChannelListRowGuild::OnImageLoad)); } } else { m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24))); @@ -110,6 +104,10 @@ ChannelListRowGuild::ChannelListRowGuild(const Guild *data) { show_all_children(); } +void ChannelListRowGuild::OnImageLoad(Glib::RefPtr<Gdk::Pixbuf> buf) { + m_icon->property_pixbuf() = buf->scale_simple(24, 24, Gdk::INTERP_BILINEAR); +} + ChannelListRowCategory::ChannelListRowCategory(const Channel *data) { ID = data->ID; m_ev = Gtk::manage(new Gtk::EventBox); diff --git a/components/channels.hpp b/components/channels.hpp index b3fa753..b1c1262 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -55,6 +55,8 @@ public: int GuildIndex; protected: + void OnImageLoad(Glib::RefPtr<Gdk::Pixbuf> buf); + Gtk::EventBox *m_ev; Gtk::Box *m_box; Gtk::Label *m_lbl; diff --git a/imgmanager.cpp b/imgmanager.cpp index bbfd50f..4cd9e66 100644 --- a/imgmanager.cpp +++ b/imgmanager.cpp @@ -26,11 +26,13 @@ Glib::RefPtr<Gdk::Pixbuf> ImageManager::ReadFileToPixbuf(std::string path) { } void ImageManager::LoadFromURL(std::string url, callback_type cb) { - m_cache.GetFileFromURL(url, [this, url, cb](std::string path) { + sigc::signal<void(Glib::RefPtr<Gdk::Pixbuf>)> signal; + signal.connect(cb); + m_cache.GetFileFromURL(url, [this, url, signal](std::string path) { try { auto buf = ReadFileToPixbuf(path); m_cb_mutex.lock(); - m_cb_queue.push(std::make_pair(buf, cb)); + m_cb_queue.push([signal, buf]() { signal.emit(buf); }); m_cb_dispatcher.emit(); m_cb_mutex.unlock(); } catch (std::exception &e) { @@ -41,8 +43,7 @@ void ImageManager::LoadFromURL(std::string url, callback_type cb) { void ImageManager::RunCallbacks() { m_cb_mutex.lock(); - const auto &pair = m_cb_queue.front(); - pair.second(pair.first); + m_cb_queue.front()(); m_cb_queue.pop(); m_cb_mutex.unlock(); } diff --git a/imgmanager.hpp b/imgmanager.hpp index 800d6a2..c7e2119 100644 --- a/imgmanager.hpp +++ b/imgmanager.hpp @@ -10,7 +10,7 @@ class ImageManager { public: ImageManager(); - using callback_type = std::function<void(Glib::RefPtr<Gdk::Pixbuf>)>; + using callback_type = sigc::slot<void(Glib::RefPtr<Gdk::Pixbuf>)>; Cache &GetCache(); void LoadFromURL(std::string url, callback_type cb); @@ -24,7 +24,7 @@ private: 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; + std::queue<std::function<void()>> m_cb_queue; std::unordered_map<std::string, Glib::RefPtr<Gdk::Pixbuf>> m_pixs; Cache m_cache; |