diff options
author | Jerzy Kozera <120114+jkozera@users.noreply.github.com> | 2023-07-04 01:15:05 +0200 |
---|---|---|
committer | Jerzy Kozera <120114+jkozera@users.noreply.github.com> | 2023-07-04 01:33:15 +0200 |
commit | 3f6be457b121b0388874f8263ec0ab0be9a0c46e (patch) | |
tree | 9f452e5673e036b0716953573f8f11b6c95e6470 | |
parent | 060e79ff2af65c46b5a53606784345b570118f2b (diff) | |
download | abaddon-portaudio-3f6be457b121b0388874f8263ec0ab0be9a0c46e.tar.gz abaddon-portaudio-3f6be457b121b0388874f8263ec0ab0be9a0c46e.zip |
Show unread indicators next to categories containing unread channels
-rw-r--r-- | src/components/channelscellrenderer.cpp | 27 | ||||
-rw-r--r-- | src/discord/discord.cpp | 10 | ||||
-rw-r--r-- | src/discord/discord.hpp | 1 |
3 files changed, 29 insertions, 9 deletions
diff --git a/src/components/channelscellrenderer.cpp b/src/components/channelscellrenderer.cpp index 6de7a00..ac98512 100644 --- a/src/components/channelscellrenderer.cpp +++ b/src/components/channelscellrenderer.cpp @@ -410,6 +410,17 @@ void CellRendererChannels::get_preferred_height_for_width_vfunc_category(Gtk::Wi m_renderer_text.get_preferred_height_for_width(widget, width, minimum_height, natural_height); } +void AddUnreadIndicator(const Cairo::RefPtr<Cairo::Context> &cr, const Gdk::Rectangle &background_area) { + static const auto color = Gdk::RGBA(Abaddon::Get().GetSettings().UnreadIndicatorColor); + cr->set_source_rgb(color.get_red(), color.get_green(), color.get_blue()); + const auto x = background_area.get_x(); + const auto y = background_area.get_y(); + const auto w = background_area.get_width(); + const auto h = background_area.get_height(); + cr->rectangle(x, y, 3, h); + cr->fill(); +} + void CellRendererChannels::render_vfunc_category(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area, Gtk::CellRendererState flags) { // todo: figure out how Gtk::Arrow is rendered because i like it better :^) constexpr static int len = 5; @@ -447,13 +458,18 @@ void CellRendererChannels::render_vfunc_category(const Cairo::RefPtr<Cairo::Cont Gdk::Rectangle text_cell_area(text_x, text_y, text_w, text_h); static const auto color = Gdk::RGBA(Abaddon::Get().GetSettings().ChannelColor); - if (Abaddon::Get().GetDiscordClient().IsChannelMuted(m_property_id.get_value())) { + auto &discord = Abaddon::Get().GetDiscordClient(); + const auto id = m_property_id.get_value(); + if (discord.IsChannelMuted(m_property_id.get_value())) { auto muted = color; muted.set_red(muted.get_red() * 0.5); muted.set_green(muted.get_green() * 0.5); muted.set_blue(muted.get_blue() * 0.5); m_renderer_text.property_foreground_rgba() = muted; } else { + if (discord.GetUnreadChannelsCountForCategory(id) > 0) { + AddUnreadIndicator(cr, background_area); + } m_renderer_text.property_foreground_rgba() = color; } m_renderer_text.render(cr, widget, background_area, text_cell_area, flags); @@ -519,14 +535,7 @@ void CellRendererChannels::render_vfunc_channel(const Cairo::RefPtr<Cairo::Conte if (unread_state < 0) return; if (!is_muted) { - static const auto color = Gdk::RGBA(Abaddon::Get().GetSettings().UnreadIndicatorColor); - cr->set_source_rgb(color.get_red(), color.get_green(), color.get_blue()); - const auto x = background_area.get_x(); - const auto y = background_area.get_y(); - const auto w = background_area.get_width(); - const auto h = background_area.get_height(); - cr->rectangle(x, y, 3, h); - cr->fill(); + AddUnreadIndicator(cr, background_area); } if (unread_state < 1) return; diff --git a/src/discord/discord.cpp b/src/discord/discord.cpp index 817aca8..1f54c7e 100644 --- a/src/discord/discord.cpp +++ b/src/discord/discord.cpp @@ -1317,6 +1317,16 @@ int DiscordClient::GetUnreadStateForChannel(Snowflake id) const noexcept { return iter->second; } +int DiscordClient::GetUnreadChannelsCountForCategory(Snowflake id) const noexcept { + int result = 0; + for (Snowflake channel_id : m_store.GetChannelIDsWithParentID(id)) { + const auto iter = m_unread.find(channel_id); + if (iter == m_unread.end()) continue; + result += 1; + } + return result; +} + bool DiscordClient::GetUnreadStateForGuild(Snowflake id, int &total_mentions) const noexcept { total_mentions = 0; bool has_any_unread = false; diff --git a/src/discord/discord.hpp b/src/discord/discord.hpp index d2435dd..29ac00c 100644 --- a/src/discord/discord.hpp +++ b/src/discord/discord.hpp @@ -214,6 +214,7 @@ public: bool IsChannelMuted(Snowflake id) const noexcept; bool IsGuildMuted(Snowflake id) const noexcept; int GetUnreadStateForChannel(Snowflake id) const noexcept; + int GetUnreadChannelsCountForCategory(Snowflake id) const noexcept; bool GetUnreadStateForGuild(Snowflake id, int &total_mentions) const noexcept; int GetUnreadDMsCount() const; |