From a9e41482f53353629a1ea2d12a0b069a773f4f65 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Fri, 11 Dec 2020 00:12:43 -0500 Subject: fix #7 and some other "improvements" --- components/chatmessage.cpp | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'components/chatmessage.cpp') diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index a2b4f69..7e0860b 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -290,26 +290,26 @@ Gtk::Widget *ChatMessageItemContainer::CreateEmbedComponent(const Message *data) } } - if (embed.Image.has_value()) { - bool is_img = embed.Image->URL.has_value(); - bool is_thumb = embed.Thumbnail.has_value(); - if (is_img || is_thumb) { - auto *img = Gtk::manage(new Gtk::Image); - img->set_halign(Gtk::ALIGN_CENTER); - int w = 0, h = 0; - if (is_img) - GetImageDimensions(*embed.Image->Width, *embed.Image->Height, w, h, 200, 150); - else - GetImageDimensions(*embed.Thumbnail->Width, *embed.Thumbnail->Height, w, h, 200, 150); - img->set_size_request(w, h); - main->pack_start(*img); - m_embed_img = img; - if (is_img) - m_embed_imgurl = *embed.Image->ProxyURL; - else - m_embed_imgurl = *embed.Thumbnail->ProxyURL; - Glib::signal_idle().connect(sigc::bind(sigc::mem_fun(*this, &ChatMessageItemContainer::EmitImageLoad), m_embed_imgurl)); - } + bool is_img = embed.Image.has_value() && embed.Image->ProxyURL.has_value(); + bool is_thumb = embed.Thumbnail.has_value() && embed.Thumbnail->ProxyURL.has_value(); + if (is_img || is_thumb) { + auto *img = Gtk::manage(new Gtk::Image); + img->set_halign(Gtk::ALIGN_CENTER); + int w = 0, h = 0; + if (is_img) + GetImageDimensions(*embed.Image->Width, *embed.Image->Height, w, h, 200, 150); + else + GetImageDimensions(*embed.Thumbnail->Width, *embed.Thumbnail->Height, w, h, 200, 150); + img->set_size_request(w, h); + main->pack_start(*img); + m_embed_img = img; + if (is_img) + m_embed_imgurl = *embed.Image->ProxyURL; + else + m_embed_imgurl = *embed.Thumbnail->ProxyURL; + + Abaddon::Get().GetImageManager().LoadFromURL(m_embed_imgurl, + sigc::mem_fun(*this, &ChatMessageItemContainer::OnEmbedImageLoad)); } if (embed.Footer.has_value()) { @@ -399,6 +399,12 @@ void ChatMessageItemContainer::HandleImage(const AttachmentData &data, Gtk::Imag Glib::signal_idle().connect(sigc::bind(sigc::mem_fun(*this, &ChatMessageItemContainer::EmitImageLoad), url)); } +void ChatMessageItemContainer::OnEmbedImageLoad(const Glib::RefPtr &pixbuf) { + int w, h; + m_embed_img->get_size_request(w, h); + m_embed_img->property_pixbuf() = pixbuf->scale_simple(w, h, Gdk::INTERP_BILINEAR); +} + Glib::ustring ChatMessageItemContainer::GetText(const Glib::RefPtr &buf) { Gtk::TextBuffer::iterator a, b; buf->get_bounds(a, b); -- cgit v1.2.3