summaryrefslogtreecommitdiff
path: root/src/components/channeltabswitcherhandy.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2022-04-09 03:33:56 -0400
committerouwou <26526779+ouwou@users.noreply.github.com>2022-04-09 03:33:56 -0400
commitd36fe4d0e9f7e537adc73827b925c429cd1f6ba8 (patch)
tree3c1679c477f20f0677dd1a7cd154b05af5e1ab27 /src/components/channeltabswitcherhandy.cpp
parent44317e2d349acb859821691801692c87433c1b83 (diff)
downloadabaddon-portaudio-d36fe4d0e9f7e537adc73827b925c429cd1f6ba8.tar.gz
abaddon-portaudio-d36fe4d0e9f7e537adc73827b925c429cd1f6ba8.zip
add server icons to channels
Diffstat (limited to 'src/components/channeltabswitcherhandy.cpp')
-rw-r--r--src/components/channeltabswitcherhandy.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/components/channeltabswitcherhandy.cpp b/src/components/channeltabswitcherhandy.cpp
index f9dc6c4..37ac927 100644
--- a/src/components/channeltabswitcherhandy.cpp
+++ b/src/components/channeltabswitcherhandy.cpp
@@ -50,11 +50,13 @@ void ChannelTabSwitcherHandy::AddChannelTab(Snowflake id) {
auto *page = hdy_tab_view_append(m_tab_view, GTK_WIDGET(dummy->gobj()));
hdy_tab_page_set_title(page, ("#" + *channel->Name).c_str());
+ hdy_tab_page_set_tooltip(page, nullptr);
m_pages[id] = page;
m_pages_rev[page] = id;
CheckUnread(id);
+ CheckPageIcon(page, *channel);
}
void ChannelTabSwitcherHandy::ReplaceActiveTab(Snowflake id) {
@@ -75,6 +77,7 @@ void ChannelTabSwitcherHandy::ReplaceActiveTab(Snowflake id) {
m_pages_rev[page] = id;
CheckUnread(id);
+ CheckPageIcon(page, *channel);
}
}
@@ -89,6 +92,33 @@ void ChannelTabSwitcherHandy::ClearPage(HdyTabPage *page) {
m_pages.erase(it->second);
}
m_pages_rev.erase(page);
+ m_page_icons.erase(page);
+}
+
+void ChannelTabSwitcherHandy::OnPageIconLoad(HdyTabPage *page, const Glib::RefPtr<Gdk::Pixbuf> &pb) {
+ auto new_pb = pb->scale_simple(16, 16, Gdk::INTERP_BILINEAR);
+ m_page_icons[page] = new_pb;
+ hdy_tab_page_set_icon(page, G_ICON(new_pb->gobj()));
+}
+
+void ChannelTabSwitcherHandy::CheckPageIcon(HdyTabPage *page, const ChannelData &data) {
+ if (data.GuildID.has_value()) {
+ if (const auto guild = Abaddon::Get().GetDiscordClient().GetGuild(*data.GuildID); guild.has_value() && guild->HasIcon()) {
+ auto *child_widget = hdy_tab_page_get_child(page);
+ if (child_widget == nullptr) return; // probably wont happen :---)
+ // i think this works???
+ auto *trackable = Glib::wrap(GTK_WIDGET(child_widget));
+
+ Abaddon::Get().GetImageManager().LoadFromURL(
+ guild->GetIconURL("png", "16"),
+ sigc::track_obj([this, page](const Glib::RefPtr<Gdk::Pixbuf> &pb) { OnPageIconLoad(page, pb); },
+ *trackable));
+ return;
+ }
+ return;
+ }
+
+ hdy_tab_page_set_icon(page, nullptr);
}
ChannelTabSwitcherHandy::type_signal_channel_switched_to ChannelTabSwitcherHandy::signal_channel_switched_to() {