diff options
-rw-r--r-- | components/channels.cpp | 22 | ||||
-rw-r--r-- | components/channels.hpp | 13 | ||||
-rw-r--r-- | discord/channel.cpp | 4 | ||||
-rw-r--r-- | discord/channel.hpp | 1 | ||||
-rw-r--r-- | settings.cpp | 8 | ||||
-rw-r--r-- | settings.hpp | 4 |
6 files changed, 39 insertions, 13 deletions
diff --git a/components/channels.cpp b/components/channels.cpp index 37e7625..547232c 100644 --- a/components/channels.cpp +++ b/components/channels.cpp @@ -66,6 +66,7 @@ ChannelList::ChannelList() column->add_attribute(renderer->property_icon(), m_columns.m_icon); column->add_attribute(renderer->property_name(), m_columns.m_name); column->add_attribute(renderer->property_expanded(), m_columns.m_expanded); + column->add_attribute(renderer->property_nsfw(), m_columns.m_nsfw); m_view.append_column(*column); m_menu_guild_copy_id.signal_activate().connect([this] { @@ -191,15 +192,13 @@ void ChannelList::UpdateChannel(Snowflake id) { channel_row[m_columns.m_type] = RenderType::TextChannel; channel_row[m_columns.m_id] = channel->ID; channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel->Name); + channel_row[m_columns.m_nsfw] = channel->NSFW(); if (is_orphan) channel_row[m_columns.m_sort] = *channel->Position + OrphanChannelSortOffset; else channel_row[m_columns.m_sort] = *channel->Position; } -void ChannelList::UpdateCreateDMChannel(Snowflake id) { -} - void ChannelList::UpdateCreateChannel(Snowflake id) { const auto channel = Abaddon::Get().GetDiscordClient().GetChannel(id); if (!channel.has_value()) return; @@ -221,6 +220,7 @@ void ChannelList::UpdateCreateChannel(Snowflake id) { channel_row[m_columns.m_type] = RenderType::TextChannel; channel_row[m_columns.m_id] = channel->ID; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel->Name); + channel_row[m_columns.m_nsfw] = channel->NSFW(); if (orphan) channel_row[m_columns.m_sort] = *channel->Position + OrphanChannelSortOffset; else @@ -293,6 +293,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) { channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); channel_row[m_columns.m_sort] = *channel.Position + OrphanChannelSortOffset; + channel_row[m_columns.m_nsfw] = channel.NSFW(); } for (const auto &[category_id, channels] : categories) { @@ -312,6 +313,7 @@ Gtk::TreeModel::iterator ChannelList::AddGuild(const GuildData &guild) { channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); channel_row[m_columns.m_sort] = *channel.Position; + channel_row[m_columns.m_nsfw] = channel.NSFW(); } } @@ -527,6 +529,7 @@ ChannelList::ModelColumns::ModelColumns() { add(m_name); add(m_icon); add(m_sort); + add(m_nsfw); add(m_expanded); } @@ -536,7 +539,8 @@ CellRendererChannels::CellRendererChannels() , m_property_type(*this, "render-type") , m_property_name(*this, "name") , m_property_pixbuf(*this, "pixbuf") - , m_property_expanded(*this, "expanded") { + , m_property_expanded(*this, "expanded") + , m_property_nsfw(*this, "nsfw") { property_mode() = Gtk::CELL_RENDERER_MODE_ACTIVATABLE; property_xpad() = 2; property_ypad() = 2; @@ -564,6 +568,10 @@ Glib::PropertyProxy<bool> CellRendererChannels::property_expanded() { return m_property_expanded.get_proxy(); } +Glib::PropertyProxy<bool> CellRendererChannels::property_nsfw() { + return m_property_nsfw.get_proxy(); +} + void CellRendererChannels::get_preferred_width_vfunc(Gtk::Widget &widget, int &minimum_width, int &natural_width) const { switch (m_property_type.get_value()) { case RenderType::Guild: @@ -794,7 +802,13 @@ void CellRendererChannels::render_vfunc_channel(const Cairo::RefPtr<Cairo::Conte Gdk::Rectangle text_cell_area(text_x, text_y, text_w, text_h); + const static auto nsfw_color = Gdk::RGBA(Abaddon::Get().GetSettings().GetNSFWChannelColor()); + if (m_property_nsfw.get_value()) + m_renderer_text.property_foreground_rgba() = nsfw_color; m_renderer_text.render(cr, widget, background_area, text_cell_area, flags); + // setting property_foreground_rgba() sets this to true which makes non-nsfw cells use the property too which is bad + // so unset it + m_renderer_text.property_foreground_set() = false; } // dm header diff --git a/components/channels.hpp b/components/channels.hpp index d3df2d5..2246b3b 100644 --- a/components/channels.hpp +++ b/components/channels.hpp @@ -12,7 +12,7 @@ constexpr static int GuildIconSize = 24; constexpr static int DMIconSize = 20; constexpr static int OrphanChannelSortOffset = -100; // forces orphan channels to the top of the list -enum class RenderType { +enum class RenderType : uint8_t { Guild, Category, TextChannel, @@ -30,6 +30,7 @@ public: Glib::PropertyProxy<Glib::ustring> property_name(); Glib::PropertyProxy<Glib::RefPtr<Gdk::Pixbuf>> property_icon(); Glib::PropertyProxy<bool> property_expanded(); + Glib::PropertyProxy<bool> property_nsfw(); protected: void get_preferred_width_vfunc(Gtk::Widget &widget, int &minimum_width, int &natural_width) const override; @@ -100,11 +101,11 @@ protected: private: Gtk::CellRendererText m_renderer_text; - Glib::Property<RenderType> m_property_type; - - Glib::Property<Glib::ustring> m_property_name; // guild - Glib::Property<Glib::RefPtr<Gdk::Pixbuf>> m_property_pixbuf; // guild + Glib::Property<RenderType> m_property_type; // all + Glib::Property<Glib::ustring> m_property_name; // all + Glib::Property<Glib::RefPtr<Gdk::Pixbuf>> m_property_pixbuf; // guild, dm Glib::Property<bool> m_property_expanded; // category + Glib::Property<bool> m_property_nsfw; // channel }; class ChannelList : public Gtk::ScrolledWindow { @@ -115,7 +116,6 @@ public: void UpdateRemoveGuild(Snowflake id); void UpdateRemoveChannel(Snowflake id); void UpdateChannel(Snowflake id); - void UpdateCreateDMChannel(Snowflake id); void UpdateCreateChannel(Snowflake id); void UpdateGuild(Snowflake id); @@ -133,6 +133,7 @@ protected: Gtk::TreeModelColumn<Glib::ustring> m_name; Gtk::TreeModelColumn<Glib::RefPtr<Gdk::Pixbuf>> m_icon; Gtk::TreeModelColumn<int64_t> m_sort; + Gtk::TreeModelColumn<bool> m_nsfw; // Gtk::CellRenderer's property_is_expanded only works how i want it to if it has children // because otherwise it doesnt count as an "expander" (property_is_expander) // so this solution will have to do which i hate but the alternative is adding invisible children diff --git a/discord/channel.cpp b/discord/channel.cpp index 68e73e9..9d90eb5 100644 --- a/discord/channel.cpp +++ b/discord/channel.cpp @@ -43,6 +43,10 @@ void ChannelData::update_from_json(const nlohmann::json &j) { JS_RD("last_pin_timestamp", LastPinTimestamp); } +bool ChannelData::NSFW() const { + return IsNSFW.has_value() && *IsNSFW; +} + std::optional<PermissionOverwrite> ChannelData::GetOverwrite(Snowflake id) const { return Abaddon::Get().GetDiscordClient().GetPermissionOverwrite(ID, id); } diff --git a/discord/channel.hpp b/discord/channel.hpp index b9bfd6d..68597e6 100644 --- a/discord/channel.hpp +++ b/discord/channel.hpp @@ -61,6 +61,7 @@ struct ChannelData { friend void from_json(const nlohmann::json &j, ChannelData &m); void update_from_json(const nlohmann::json &j); + bool NSFW() const; std::optional<PermissionOverwrite> GetOverwrite(Snowflake id) const; std::vector<UserData> GetDMRecipients() const; }; diff --git a/settings.cpp b/settings.cpp index 2974dca..dadd485 100644 --- a/settings.cpp +++ b/settings.cpp @@ -63,11 +63,15 @@ bool SettingsManager::GetShowCustomEmojis() const { } std::string SettingsManager::GetLinkColor() const { - return GetSettingString("misc", "linkcolor", "rgba(40, 200, 180, 255)"); + return GetSettingString("style", "linkcolor", "rgba(40, 200, 180, 255)"); } std::string SettingsManager::GetChannelsExpanderColor() const { - return GetSettingString("misc", "expandercolor", "rgba(255, 83, 112, 255)"); + return GetSettingString("style", "expandercolor", "rgba(255, 83, 112, 255)"); +} + +std::string SettingsManager::GetNSFWChannelColor() const { + return GetSettingString("style", "nsfwchannelcolor", "#ed6666"); } int SettingsManager::GetCacheHTTPConcurrency() const { diff --git a/settings.hpp b/settings.hpp index 7559dc0..d328805 100644 --- a/settings.hpp +++ b/settings.hpp @@ -29,9 +29,11 @@ public: // #3 it's a massive pain in the ass to try and bump the version to a functioning version // because they switch build systems to nmake/meson (took months to get merged in vcpkg) // #4 c++ build systems sucks - // perhaps i'll bump to gtk4 when it's more stable + // three options are: use gtk4 with updated vcpkg, try and port it myself, or use msys2 instead of vcpkg + // im leaning towards msys std::string GetLinkColor() const; std::string GetChannelsExpanderColor() const; + std::string GetNSFWChannelColor() const; bool IsValid() const; |