summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2020-12-11 00:12:43 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2020-12-11 00:12:43 -0500
commita9e41482f53353629a1ea2d12a0b069a773f4f65 (patch)
tree7601c71abac83420cee064c2b6c00aab9cabbebb /components
parentdf781e0dc6cca6f610de317c91d2bd11530a06d1 (diff)
downloadabaddon-portaudio-a9e41482f53353629a1ea2d12a0b069a773f4f65.tar.gz
abaddon-portaudio-a9e41482f53353629a1ea2d12a0b069a773f4f65.zip
fix #7 and some other "improvements"
Diffstat (limited to 'components')
-rw-r--r--components/chatmessage.cpp46
-rw-r--r--components/chatmessage.hpp2
2 files changed, 28 insertions, 20 deletions
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<Gdk::Pixbuf> &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<Gtk::TextBuffer> &buf) {
Gtk::TextBuffer::iterator a, b;
buf->get_bounds(a, b);
diff --git a/components/chatmessage.hpp b/components/chatmessage.hpp
index 92d39b9..0f76f21 100644
--- a/components/chatmessage.hpp
+++ b/components/chatmessage.hpp
@@ -27,6 +27,8 @@ protected:
Gtk::Widget *CreateStickerComponent(const Sticker &data);
void HandleImage(const AttachmentData &data, Gtk::Image *img, std::string url);
+ void OnEmbedImageLoad(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf);
+
static Glib::ustring GetText(const Glib::RefPtr<Gtk::TextBuffer> &buf);
void HandleUserMentions(Gtk::TextView *tv);