diff --git a/cmake/Findglib.cmake b/cmake/Findglib.cmake index f60f75d..6a4af66 100644 --- a/cmake/Findglib.cmake +++ b/cmake/Findglib.cmake @@ -35,6 +35,12 @@ find_library(glib_GOBJECT_LIBRARIES ${PC_GLIB2_LIBRARY_DIRS} ) +find_library(glib_GIO_LIBRARIES + NAMES gio-2.0 + HINTS ${PC_GLIB2_LIBDIR} + ${PC_GLIB2_LIBRARY_DIRS} + ) + get_filename_component(_GLIB2_LIB_DIR "${GLIB_LIBRARIES}" PATH) find_path(GLIB_CONFIG_INCLUDE_DIR NAMES glibconfig.h @@ -54,7 +60,7 @@ if (GLIB_CONFIG_INCLUDE_DIR) set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIRS} ${GLIB_CONFIG_INCLUDE_DIR}) endif () -set(GLIB_LIBRARIES ${GLIB_LIBRARIES} ${glib_GOBJECT_LIBRARIES}) +set(GLIB_LIBRARIES ${GLIB_LIBRARIES} ${glib_GOBJECT_LIBRARIES} ${glib_GIO_LIBRARIES}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(glib 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 &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 &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() { diff --git a/src/components/channeltabswitcherhandy.hpp b/src/components/channeltabswitcherhandy.hpp index bc38091..6a2dbff 100644 --- a/src/components/channeltabswitcherhandy.hpp +++ b/src/components/channeltabswitcherhandy.hpp @@ -6,6 +6,8 @@ #include #include "discord/snowflake.hpp" +class ChannelData; + // thin wrapper over c api // HdyTabBar + invisible HdyTabView since it needs one class ChannelTabSwitcherHandy : public Gtk::Box { @@ -20,6 +22,8 @@ public: private: void CheckUnread(Snowflake id); void ClearPage(HdyTabPage *page); + void OnPageIconLoad(HdyTabPage *page, const Glib::RefPtr &pb); + void CheckPageIcon(HdyTabPage *page, const ChannelData &data); HdyTabBar *m_tab_bar; Gtk::Widget *m_tab_bar_wrapped; @@ -28,6 +32,8 @@ private: std::unordered_map m_pages; std::unordered_map m_pages_rev; + // need to hold a reference to the pixbuf data + std::unordered_map> m_page_icons; friend void selected_page_notify_cb(HdyTabView *, GParamSpec *, ChannelTabSwitcherHandy *); friend gboolean close_page_cb(HdyTabView *, HdyTabPage *, ChannelTabSwitcherHandy *);