diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-09-30 15:12:52 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2020-09-30 15:12:52 -0400 |
commit | 872b15e6af603d166f5a1df4c960fb69b2c7938b (patch) | |
tree | f2d2a9bc572592db425f79a4802828b454a07c29 /components | |
parent | 7965b788b1bae6b71cc5f7461e7d4d98d92cc851 (diff) | |
download | abaddon-portaudio-872b15e6af603d166f5a1df4c960fb69b2c7938b.tar.gz abaddon-portaudio-872b15e6af603d166f5a1df4c960fb69b2c7938b.zip |
hopefully take care of some annoying bugs
Diffstat (limited to 'components')
-rw-r--r-- | components/channels.cpp | 13 | ||||
-rw-r--r-- | components/channels.hpp | 2 | ||||
-rw-r--r-- | components/chatmessage.cpp | 26 | ||||
-rw-r--r-- | components/chatmessage.hpp | 2 | ||||
-rw-r--r-- | components/chatwindow.cpp | 5 |
5 files changed, 24 insertions, 24 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index dffd200..cb5307b 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -46,13 +46,7 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const Channel *data) { m_icon = Gtk::manage(new Gtk::Image(buf)); else { m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24))); - Abaddon::Get().GetImageManager().LoadFromURL(data->Recipients[0].GetAvatarURL("png", "16"), [this](Glib::RefPtr<Gdk::Pixbuf> ldbuf) { - Glib::signal_idle().connect([this, ldbuf]() -> bool { - m_icon->property_pixbuf() = ldbuf; - - return false; - }); - }); + Abaddon::Get().GetImageManager().LoadFromURL(data->Recipients[0].GetAvatarURL("png", "16"), sigc::mem_fun(*this, &ChannelListRowDMChannel::OnImageLoad)); } } @@ -70,6 +64,11 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const Channel *data) { show_all_children(); } +void ChannelListRowDMChannel::OnImageLoad(Glib::RefPtr<Gdk::Pixbuf> buf) { + if (m_icon != nullptr) + m_icon->property_pixbuf() = buf; +} + ChannelListRowGuild::ChannelListRowGuild(const Guild *data) { ID = data->ID; m_ev = Gtk::manage(new Gtk::EventBox); diff --git a/components/channels.hpp b/components/channels.hpp index 6c88ac9..b3fa753 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -40,6 +40,8 @@ public: ChannelListRowDMChannel(const Channel *data); protected: + void OnImageLoad(Glib::RefPtr<Gdk::Pixbuf> buf); + Gtk::EventBox *m_ev; Gtk::Box *m_box; Gtk::Label *m_lbl; diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index 363b733..a219958 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -132,6 +132,11 @@ void ChatMessageItemContainer::UpdateAttributes() { m_attrib_label->set_markup("<span color='#999999'>[edited]</span>"); } +bool ChatMessageItemContainer::EmitImageLoad(std::string url) { + m_signal_image_load.emit(url); + return false; +} + void ChatMessageItemContainer::AddClickHandler(Gtk::Widget *widget, std::string url) { // clang-format off widget->signal_button_press_event().connect([url](GdkEventButton *event) -> bool { @@ -258,27 +263,24 @@ Gtk::EventBox *ChatMessageItemContainer::CreateEmbedComponent(const Message *dat } } - bool img = embed.Image.URL.size() > 0; - bool thumb = embed.Thumbnail.URL.size() > 0; - if (img || thumb) { + bool is_img = embed.Image.URL.size() > 0; + bool is_thumb = embed.Thumbnail.URL.size() > 0; + if (is_img || is_thumb) { auto *img = Gtk::manage(new Gtk::Image); img->set_halign(Gtk::ALIGN_CENTER); int w, h; - if (img) + if (is_img) std::tie(w, h) = GetImageDimensions(embed.Image.Width, embed.Image.Height, 200, 150); else std::tie(w, h) = GetImageDimensions(embed.Thumbnail.Width, embed.Thumbnail.Height, 200, 150); img->set_size_request(w, h); main->pack_start(*img); m_embed_img = img; - if (img) + if (is_img) m_embed_imgurl = embed.Image.ProxyURL; else m_embed_imgurl = embed.Thumbnail.ProxyURL; - Glib::signal_idle().connect([this]() -> bool { - m_signal_image_load.emit(m_embed_imgurl); - return false; - }); + Glib::signal_idle().connect(sigc::bind(sigc::mem_fun(*this, &ChatMessageItemContainer::EmitImageLoad), m_embed_imgurl)); } if (embed.Footer.Text.length() > 0) { @@ -366,10 +368,8 @@ std::pair<int, int> ChatMessageItemContainer::GetImageDimensions(int width, int void ChatMessageItemContainer::HandleImage(const AttachmentData &data, Gtk::Image *img, std::string url) { m_img_loadmap[url] = std::make_pair(img, data); - Glib::signal_idle().connect([this, url]() -> bool { - m_signal_image_load.emit(url); // ask the chatwindow to call UpdateImage because dealing with lifetimes sucks - return false; - }); + // ask the chatwindow to call UpdateImage because dealing with lifetimes sucks + Glib::signal_idle().connect(sigc::bind(sigc::mem_fun(*this, &ChatMessageItemContainer::EmitImageLoad), url)); } void ChatMessageItemContainer::ShowMenu(GdkEvent *event) { diff --git a/components/chatmessage.hpp b/components/chatmessage.hpp index f105354..73307d2 100644 --- a/components/chatmessage.hpp +++ b/components/chatmessage.hpp @@ -16,6 +16,8 @@ public: void UpdateImage(); protected: + bool EmitImageLoad(std::string url); + void AddClickHandler(Gtk::Widget *widget, std::string); Gtk::TextView *CreateTextComponent(const Message *data); // Message.Content Gtk::EventBox *CreateEmbedComponent(const Message *data); // Message.Embeds[0] diff --git a/components/chatwindow.cpp b/components/chatwindow.cpp index f466852..710d2ad 100644 --- a/components/chatwindow.cpp +++ b/components/chatwindow.cpp @@ -232,9 +232,8 @@ void ChatWindow::ProcessNewMessage(Snowflake id, bool prepend) { } void ChatWindow::SetMessagesInternal() { - m_update_mutex.lock(); + std::scoped_lock<std::mutex> guard(m_update_mutex); const auto *msgs = &m_set_messages_queue.front(); - m_update_mutex.unlock(); // empty the listbox auto children = m_list->get_children(); @@ -251,9 +250,7 @@ void ChatWindow::SetMessagesInternal() { ProcessNewMessage(id, false); } - m_update_mutex.lock(); m_set_messages_queue.pop(); - m_update_mutex.unlock(); } void ChatWindow::AddNewMessageInternal() { |