diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-01-17 22:50:55 -0500 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-01-17 22:50:55 -0500 |
commit | 744e42892d3da3247df4e04f0d97e93e6d50799a (patch) | |
tree | bbdc4a58785de6fd54f237edec2c71c7523a5c4f /components | |
parent | 3f6024ddf213b83cf0c815b68f8ad8de3f3afa44 (diff) | |
download | abaddon-portaudio-744e42892d3da3247df4e04f0d97e93e6d50799a.tar.gz abaddon-portaudio-744e42892d3da3247df4e04f0d97e93e6d50799a.zip |
cleanup
Diffstat (limited to 'components')
-rw-r--r-- | components/channels.cpp | 63 | ||||
-rw-r--r-- | components/channels.hpp | 13 | ||||
-rw-r--r-- | components/chatmessage.cpp | 39 | ||||
-rw-r--r-- | components/chatmessage.hpp | 4 | ||||
-rw-r--r-- | components/lazyimage.cpp | 6 | ||||
-rw-r--r-- | components/lazyimage.hpp | 1 | ||||
-rw-r--r-- | components/memberlist.cpp | 12 | ||||
-rw-r--r-- | components/memberlist.hpp | 5 |
8 files changed, 31 insertions, 112 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index 0819f8c..3734ba0 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -62,13 +62,11 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const ChannelData *data) { if (data->Type == ChannelType::DM) { if (top_recipient.HasAvatar()) { - auto buf = Abaddon::Get().GetImageManager().GetFromURLIfCached(top_recipient.GetAvatarURL("png", "16")); - if (buf) - 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(top_recipient.GetAvatarURL("png", "16"), sigc::mem_fun(*this, &ChannelListRowDMChannel::OnImageLoad)); - } + m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24))); + auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) { + m_icon->property_pixbuf() = pb->scale_simple(24, 24, Gdk::INTERP_BILINEAR); + }; + Abaddon::Get().GetImageManager().LoadFromURL(top_recipient.GetAvatarURL("png", "16"), sigc::track_obj(cb, *this)); } else { m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24))); } @@ -90,11 +88,6 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const ChannelData *data) { show_all_children(); } -void ChannelListRowDMChannel::OnImageLoad(Glib::RefPtr<Gdk::Pixbuf> buf) { - if (m_icon != nullptr) - m_icon->property_pixbuf() = buf->scale_simple(24, 24, Gdk::INTERP_BILINEAR); -} - ChannelListRowGuild::ChannelListRowGuild(const GuildData *data) { ID = data->ID; m_ev = Gtk::manage(new Gtk::EventBox); @@ -129,21 +122,17 @@ ChannelListRowGuild::ChannelListRowGuild(const GuildData *data) { auto &img = Abaddon::Get().GetImageManager(); if (data->HasIcon()) { if (data->HasAnimatedIcon() && show_animations) { - auto buf = img.GetAnimationFromURLIfCached(data->GetIconURL("gif", "32"), 24, 24); - if (buf) - m_icon = Gtk::manage(new Gtk::Image(buf)); - else { - m_icon = Gtk::manage(new Gtk::Image(img.GetPlaceholder(24))); - img.LoadAnimationFromURL(data->GetIconURL("gif", "32"), 24, 24, sigc::mem_fun(*this, &ChannelListRowGuild::OnAnimatedImageLoad)); - } + m_icon = Gtk::manage(new Gtk::Image(img.GetPlaceholder(24))); + auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) { + m_icon->property_pixbuf_animation() = pb; + }; + img.LoadAnimationFromURL(data->GetIconURL("gif", "32"), 24, 24, sigc::track_obj(cb, *this)); } else { - auto buf = img.GetFromURLIfCached(data->GetIconURL("png", "32")); - if (buf) - m_icon = Gtk::manage(new Gtk::Image(buf->scale_simple(24, 24, Gdk::INTERP_BILINEAR))); - else { - m_icon = Gtk::manage(new Gtk::Image(img.GetPlaceholder(24))); - img.LoadFromURL(data->GetIconURL("png", "32"), sigc::mem_fun(*this, &ChannelListRowGuild::OnImageLoad)); - } + m_icon = Gtk::manage(new Gtk::Image(img.GetPlaceholder(24))); + auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) { + m_icon->property_pixbuf() = pb->scale_simple(24, 24, Gdk::INTERP_BILINEAR); + }; + img.LoadFromURL(data->GetIconURL("png", "32"), sigc::track_obj(cb, *this)); } } else { m_icon = Gtk::manage(new Gtk::Image(Abaddon::Get().GetImageManager().GetPlaceholder(24))); @@ -166,14 +155,6 @@ ChannelListRowGuild::ChannelListRowGuild(const GuildData *data) { show_all_children(); } -void ChannelListRowGuild::OnImageLoad(const Glib::RefPtr<Gdk::Pixbuf> &buf) { - m_icon->property_pixbuf() = buf->scale_simple(24, 24, Gdk::INTERP_BILINEAR); -} - -void ChannelListRowGuild::OnAnimatedImageLoad(const Glib::RefPtr<Gdk::PixbufAnimation> &buf) { - m_icon->property_pixbuf_animation() = buf; -} - ChannelListRowGuild::type_signal_copy_id ChannelListRowGuild::signal_copy_id() { return m_signal_copy_id; } @@ -284,8 +265,6 @@ ChannelList::ChannelList() { m_main->add(*m_list); m_main->show_all(); - m_update_dispatcher.connect(sigc::mem_fun(*this, &ChannelList::UpdateListingInternal)); - // maybe will regret doing it this way auto &discord = Abaddon::Get().GetDiscordClient(); auto cb = [this, &discord](Snowflake message_id) { @@ -302,11 +281,6 @@ Gtk::Widget *ChannelList::GetRoot() const { return m_main; } -void ChannelList::UpdateListing() { - //std::scoped_lock<std::mutex> guard(m_update_mutex); - m_update_dispatcher.emit(); -} - void ChannelList::UpdateNewGuild(Snowflake id) { auto sort = Abaddon::Get().GetDiscordClient().GetUserSortedGuilds(); if (sort.size() == 1) { @@ -537,11 +511,6 @@ void ChannelList::UpdateGuild(Snowflake id) { m_list->insert(*new_row, index); } -void ChannelList::Clear() { - //std::scoped_lock<std::mutex> guard(m_update_mutex); - m_update_dispatcher.emit(); -} - void ChannelList::SetActiveChannel(Snowflake id) { auto it = m_id_to_row.find(id); if (it == m_id_to_row.end()) return; @@ -707,7 +676,7 @@ void ChannelList::AddPrivateChannels() { } } -void ChannelList::UpdateListingInternal() { +void ChannelList::UpdateListing() { std::unordered_set<Snowflake> guilds = Abaddon::Get().GetDiscordClient().GetGuilds(); auto children = m_list->get_children(); diff --git a/components/channels.hpp b/components/channels.hpp index 8f73a50..f537043 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -38,8 +38,6 @@ public: ChannelListRowDMChannel(const ChannelData *data); protected: - void OnImageLoad(Glib::RefPtr<Gdk::Pixbuf> buf); - Gtk::EventBox *m_ev; Gtk::Box *m_box; Gtk::TextView *m_lbl; @@ -53,9 +51,6 @@ public: int GuildIndex; protected: - void OnImageLoad(const Glib::RefPtr<Gdk::Pixbuf> &buf); - void OnAnimatedImageLoad(const Glib::RefPtr<Gdk::PixbufAnimation> &buf); - Gtk::EventBox *m_ev; Gtk::Box *m_box; Gtk::TextView *m_lbl; @@ -139,7 +134,6 @@ public: void UpdateCreateDMChannel(Snowflake id); void UpdateCreateChannel(Snowflake id); void UpdateGuild(Snowflake id); - void Clear(); void SetActiveChannel(Snowflake id); @@ -165,10 +159,6 @@ protected: Gtk::Menu m_channel_menu; Gtk::MenuItem *m_channel_menu_copyid; - Glib::Dispatcher m_update_dispatcher; - //mutable std::mutex m_update_mutex; - //std::queue<std::unordered_set<Snowflake>> m_update_queue; - // i would use one map but in really old guilds there can be a channel w/ same id as the guild so this hacky shit has to do std::unordered_map<Snowflake, ChannelListRow *> m_guild_id_to_row; std::unordered_map<Snowflake, ChannelListRow *> m_id_to_row; @@ -176,8 +166,7 @@ protected: void InsertGuildAt(Snowflake id, int pos); - void AddPrivateChannels(); // retard moment - void UpdateListingInternal(); + void AddPrivateChannels(); void CheckBumpDM(Snowflake channel_id); diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index 4692a80..0981448 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -484,14 +484,7 @@ Gtk::Widget *ChatMessageItemContainer::CreateReactionsComponent(const Message &d img->set_can_focus(false); box->add(*img); } else { // custom - const auto &pb = imgr.GetFromURLIfCached(reaction.Emoji.GetURL()); - Gtk::Image *img; - if (pb) { - img = Gtk::manage(new Gtk::Image(pb->scale_simple(16, 16, Gdk::INTERP_BILINEAR))); - } else { - img = Gtk::manage(new Gtk::Image(placeholder)); - imgr.LoadFromURL(reaction.Emoji.GetURL(), sigc::bind<0>(sigc::mem_fun(*this, &ChatMessageItemContainer::ReactionUpdateImage), img)); - } + auto img = Gtk::manage(new LazyImage(reaction.Emoji.GetURL(), 16, 16)); img->set_can_focus(false); box->add(*img); } @@ -574,10 +567,6 @@ Gtk::Widget *ChatMessageItemContainer::CreateReplyComponent(const Message &data) return box; } -void ChatMessageItemContainer::ReactionUpdateImage(Gtk::Image *img, const Glib::RefPtr<Gdk::Pixbuf> &pb) { - img->property_pixbuf() = pb->scale_simple(16, 16, Gdk::INTERP_BILINEAR); -} - Glib::ustring ChatMessageItemContainer::GetText(const Glib::RefPtr<Gtk::TextBuffer> &buf) { Gtk::TextBuffer::iterator a, b; buf->get_bounds(a, b); @@ -973,11 +962,20 @@ ChatMessageHeader::ChatMessageHeader(const Message *data) { auto &img = Abaddon::Get().GetImageManager(); m_avatar = Gtk::manage(new Gtk::Image(img.GetPlaceholder(AvatarSize))); - if (author->HasAvatar()) - img.LoadFromURL(author->GetAvatarURL(), sigc::mem_fun(*this, &ChatMessageHeader::OnAvatarLoad)); + if (author->HasAvatar()) { + auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) { + m_static_avatar = pb; + m_avatar->property_pixbuf() = pb; + }; + img.LoadFromURL(author->GetAvatarURL(), sigc::track_obj(cb, *this)); + } - if (author->HasAnimatedAvatar()) - img.LoadAnimationFromURL(author->GetAvatarURL("gif"), AvatarSize, AvatarSize, sigc::mem_fun(*this, &ChatMessageHeader::OnAnimatedAvatarLoad)); + if (author->HasAnimatedAvatar()) { + auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) { + m_anim_avatar = pb; + }; + img.LoadAnimationFromURL(author->GetAvatarURL("gif"), AvatarSize, AvatarSize, sigc::track_obj(cb, *this)); + } get_style_context()->add_class("message-container"); m_author->get_style_context()->add_class("message-container-author"); @@ -1089,15 +1087,6 @@ void ChatMessageHeader::UpdateNameColor() { m_author->set_markup(md); } -void ChatMessageHeader::OnAvatarLoad(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf) { - m_static_avatar = pixbuf; - m_avatar->property_pixbuf() = pixbuf; -} - -void ChatMessageHeader::OnAnimatedAvatarLoad(const Glib::RefPtr<Gdk::PixbufAnimation> &pixbuf) { - m_anim_avatar = pixbuf; -} - void ChatMessageHeader::AttachUserMenuHandler(Gtk::Widget &widget) { widget.signal_button_press_event().connect([this](GdkEventButton *ev) -> bool { if (ev->type == GDK_BUTTON_PRESS && ev->button == GDK_BUTTON_SECONDARY) { diff --git a/components/chatmessage.hpp b/components/chatmessage.hpp index 43bf7a2..de30ce8 100644 --- a/components/chatmessage.hpp +++ b/components/chatmessage.hpp @@ -25,7 +25,6 @@ protected: Gtk::Widget *CreateStickerComponent(const StickerData &data); Gtk::Widget *CreateReactionsComponent(const Message &data); Gtk::Widget *CreateReplyComponent(const Message &data); - void ReactionUpdateImage(Gtk::Image *img, const Glib::RefPtr<Gdk::Pixbuf> &pb); static Glib::ustring GetText(const Glib::RefPtr<Gtk::TextBuffer> &buf); @@ -107,9 +106,6 @@ public: void UpdateNameColor(); protected: - void OnAvatarLoad(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf); - void OnAnimatedAvatarLoad(const Glib::RefPtr<Gdk::PixbufAnimation> &pixbuf); - void AttachUserMenuHandler(Gtk::Widget &widget); bool on_author_button_press(GdkEventButton *ev); diff --git a/components/lazyimage.cpp b/components/lazyimage.cpp index 08b9f10..40d2268 100644 --- a/components/lazyimage.cpp +++ b/components/lazyimage.cpp @@ -4,9 +4,6 @@ LazyImage::LazyImage(int w, int h, bool use_placeholder) : m_width(w) , m_height(h) { - static int sidx = 0; - sidx++; - m_idx = sidx; if (use_placeholder) property_pixbuf() = Abaddon::Get().GetImageManager().GetPlaceholder(w)->scale_simple(w, h, Gdk::INTERP_BILINEAR); signal_draw().connect(sigc::mem_fun(*this, &LazyImage::OnDraw)); @@ -16,9 +13,6 @@ LazyImage::LazyImage(const std::string &url, int w, int h, bool use_placeholder) : m_url(url) , m_width(w) , m_height(h) { - static int sidx = 0; - sidx++; - m_idx = sidx; if (use_placeholder) property_pixbuf() = Abaddon::Get().GetImageManager().GetPlaceholder(w)->scale_simple(w, h, Gdk::INTERP_BILINEAR); signal_draw().connect(sigc::mem_fun(*this, &LazyImage::OnDraw)); diff --git a/components/lazyimage.hpp b/components/lazyimage.hpp index 54282b5..31e727b 100644 --- a/components/lazyimage.hpp +++ b/components/lazyimage.hpp @@ -13,7 +13,6 @@ private: bool OnDraw(const Cairo::RefPtr<Cairo::Context> &context); bool m_needs_request = true; - int m_idx; std::string m_url; int m_width; int m_height; diff --git a/components/memberlist.cpp b/components/memberlist.cpp index 81abb6c..0d54448 100644 --- a/components/memberlist.cpp +++ b/components/memberlist.cpp @@ -45,13 +45,7 @@ MemberListUserRow::MemberListUserRow(Snowflake guild_id, const UserData *data) { show_all(); } -void MemberListUserRow::SetAvatarFromPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf) { - m_avatar->property_pixbuf() = pixbuf; -} - MemberList::MemberList() { - m_update_member_list_dispatcher.connect(sigc::mem_fun(*this, &MemberList::UpdateMemberListInternal)); - m_main = Gtk::manage(new Gtk::ScrolledWindow); m_listbox = Gtk::manage(new Gtk::ListBox); @@ -74,7 +68,6 @@ void MemberList::Clear() { } void MemberList::SetActiveChannel(Snowflake id) { - std::scoped_lock<std::mutex> guard(m_mutex); m_chan_id = id; m_guild_id = Snowflake::Invalid; if (m_chan_id.IsValid()) { @@ -84,11 +77,6 @@ void MemberList::SetActiveChannel(Snowflake id) { } void MemberList::UpdateMemberList() { - std::scoped_lock<std::mutex> guard(m_mutex); - m_update_member_list_dispatcher.emit(); -} - -void MemberList::UpdateMemberListInternal() { m_id_to_row.clear(); auto children = m_listbox->get_children(); diff --git a/components/memberlist.hpp b/components/memberlist.hpp index f19880e..c816b26 100644 --- a/components/memberlist.hpp +++ b/components/memberlist.hpp @@ -8,7 +8,6 @@ class MemberListUserRow : public Gtk::ListBoxRow { public: MemberListUserRow(Snowflake guild_id, const UserData *data); - void SetAvatarFromPixbuf(Glib::RefPtr<Gdk::Pixbuf> pixbuf); Snowflake ID; @@ -29,12 +28,8 @@ public: void SetActiveChannel(Snowflake id); private: - void UpdateMemberListInternal(); void AttachUserMenuHandler(Gtk::ListBoxRow *row, Snowflake id); - std::mutex m_mutex; - Glib::Dispatcher m_update_member_list_dispatcher; - Gtk::ScrolledWindow *m_main; Gtk::ListBox *m_listbox; |