diff options
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/channellist/cellrendererchannels.cpp | 29 | ||||
-rw-r--r-- | src/components/channellist/cellrendererchannels.hpp | 6 | ||||
-rw-r--r-- | src/components/channellist/channellisttree.cpp | 73 | ||||
-rw-r--r-- | src/components/channellist/channellisttree.hpp | 10 |
4 files changed, 45 insertions, 73 deletions
diff --git a/src/components/channellist/cellrendererchannels.cpp b/src/components/channellist/cellrendererchannels.cpp index bb2b9ba..8a6097e 100644 --- a/src/components/channellist/cellrendererchannels.cpp +++ b/src/components/channellist/cellrendererchannels.cpp @@ -122,12 +122,10 @@ void CellRendererChannels::get_preferred_width_vfunc(Gtk::Widget &widget, int &m return get_preferred_width_vfunc_channel(widget, minimum_width, natural_width); case RenderType::Thread: return get_preferred_width_vfunc_thread(widget, minimum_width, natural_width); -#ifdef WITH_VOICE case RenderType::VoiceChannel: return get_preferred_width_vfunc_voice_channel(widget, minimum_width, natural_width); case RenderType::VoiceParticipant: return get_preferred_width_vfunc_voice_participant(widget, minimum_width, natural_width); -#endif case RenderType::DMHeader: return get_preferred_width_vfunc_dmheader(widget, minimum_width, natural_width); case RenderType::DM: @@ -147,12 +145,10 @@ void CellRendererChannels::get_preferred_width_for_height_vfunc(Gtk::Widget &wid return get_preferred_width_for_height_vfunc_channel(widget, height, minimum_width, natural_width); case RenderType::Thread: return get_preferred_width_for_height_vfunc_thread(widget, height, minimum_width, natural_width); -#ifdef WITH_VOICE case RenderType::VoiceChannel: return get_preferred_width_for_height_vfunc_voice_channel(widget, height, minimum_width, natural_width); case RenderType::VoiceParticipant: return get_preferred_width_for_height_vfunc_voice_participant(widget, height, minimum_width, natural_width); -#endif case RenderType::DMHeader: return get_preferred_width_for_height_vfunc_dmheader(widget, height, minimum_width, natural_width); case RenderType::DM: @@ -172,12 +168,10 @@ void CellRendererChannels::get_preferred_height_vfunc(Gtk::Widget &widget, int & return get_preferred_height_vfunc_channel(widget, minimum_height, natural_height); case RenderType::Thread: return get_preferred_height_vfunc_thread(widget, minimum_height, natural_height); -#ifdef WITH_VOICE case RenderType::VoiceChannel: return get_preferred_height_vfunc_voice_channel(widget, minimum_height, natural_height); case RenderType::VoiceParticipant: return get_preferred_height_vfunc_voice_participant(widget, minimum_height, natural_height); -#endif case RenderType::DMHeader: return get_preferred_height_vfunc_dmheader(widget, minimum_height, natural_height); case RenderType::DM: @@ -197,12 +191,10 @@ void CellRendererChannels::get_preferred_height_for_width_vfunc(Gtk::Widget &wid return get_preferred_height_for_width_vfunc_channel(widget, width, minimum_height, natural_height); case RenderType::Thread: return get_preferred_height_for_width_vfunc_thread(widget, width, minimum_height, natural_height); -#ifdef WITH_VOICE case RenderType::VoiceChannel: return get_preferred_height_for_width_vfunc_voice_channel(widget, width, minimum_height, natural_height); case RenderType::VoiceParticipant: return get_preferred_height_for_width_vfunc_voice_participant(widget, width, minimum_height, natural_height); -#endif case RenderType::DMHeader: return get_preferred_height_for_width_vfunc_dmheader(widget, width, minimum_height, natural_height); case RenderType::DM: @@ -222,12 +214,10 @@ void CellRendererChannels::render_vfunc(const Cairo::RefPtr<Cairo::Context> &cr, return render_vfunc_channel(cr, widget, background_area, cell_area, flags); case RenderType::Thread: return render_vfunc_thread(cr, widget, background_area, cell_area, flags); -#ifdef WITH_VOICE case RenderType::VoiceChannel: return render_vfunc_voice_channel(cr, widget, background_area, cell_area, flags); case RenderType::VoiceParticipant: return render_vfunc_voice_participant(cr, widget, background_area, cell_area, flags); -#endif case RenderType::DMHeader: return render_vfunc_dmheader(cr, widget, background_area, cell_area, flags); case RenderType::DM: @@ -563,8 +553,6 @@ void CellRendererChannels::render_vfunc_thread(const Cairo::RefPtr<Cairo::Contex } } -#ifdef WITH_VOICE - // voice channel void CellRendererChannels::get_preferred_width_vfunc_voice_channel(Gtk::Widget &widget, int &minimum_width, int &natural_width) const { @@ -612,6 +600,21 @@ void CellRendererChannels::render_vfunc_voice_channel(const Cairo::RefPtr<Cairo: layout->show_in_cairo_context(cr); RenderExpander(24, cr, widget, background_area, property_expanded()); + + // unread + if (!Abaddon::Get().GetSettings().Unreads) return; + + const auto id = m_property_id.get_value(); + const auto unread_state = Abaddon::Get().GetDiscordClient().GetUnreadStateForChannel(id); + + if (unread_state < 1) return; + + auto *paned = dynamic_cast<Gtk::Paned *>(widget.get_ancestor(Gtk::Paned::get_type())); + if (paned != nullptr) { + const auto edge = std::min(paned->get_position(), cell_area.get_width()); + + unread_render_mentions(cr, widget, unread_state, edge, cell_area); + } } // voice participant @@ -714,8 +717,6 @@ void CellRendererChannels::render_vfunc_voice_participant(const Cairo::RefPtr<Ca } } -#endif - // dm header void CellRendererChannels::get_preferred_width_vfunc_dmheader(Gtk::Widget &widget, int &minimum_width, int &natural_width) const { diff --git a/src/components/channellist/cellrendererchannels.hpp b/src/components/channellist/cellrendererchannels.hpp index a313dc7..ebe4957 100644 --- a/src/components/channellist/cellrendererchannels.hpp +++ b/src/components/channellist/cellrendererchannels.hpp @@ -15,12 +15,8 @@ enum class RenderType : uint8_t { Category, TextChannel, Thread, - -// TODO: maybe enable anyways but without ability to join if no voice support -#ifdef WITH_VOICE VoiceChannel, VoiceParticipant, -#endif DMHeader, DM, @@ -107,7 +103,6 @@ protected: const Gdk::Rectangle &cell_area, Gtk::CellRendererState flags); -#ifdef WITH_VOICE // voice channel void get_preferred_width_vfunc_voice_channel(Gtk::Widget &widget, int &minimum_width, int &natural_width) const; void get_preferred_width_for_height_vfunc_voice_channel(Gtk::Widget &widget, int height, int &minimum_width, int &natural_width) const; @@ -129,7 +124,6 @@ protected: const Gdk::Rectangle &background_area, const Gdk::Rectangle &cell_area, Gtk::CellRendererState flags); -#endif // dm header void get_preferred_width_vfunc_dmheader(Gtk::Widget &widget, int &minimum_width, int &natural_width) const; diff --git a/src/components/channellist/channellisttree.cpp b/src/components/channellist/channellisttree.cpp index ebbed58..4597a1f 100644 --- a/src/components/channellist/channellisttree.cpp +++ b/src/components/channellist/channellisttree.cpp @@ -26,10 +26,10 @@ ChannelListTree::ChannelListTree() , m_menu_channel_open_tab("Open in New _Tab", true) , m_menu_dm_open_tab("Open in New _Tab", true) #endif -#ifdef WITH_VOICE , m_menu_voice_channel_join("_Join", true) , m_menu_voice_channel_disconnect("_Disconnect", true) -#endif + , m_menu_voice_channel_mark_as_read("Mark as _Read", true) + , m_menu_voice_open_chat("Open _Chat", true) , m_menu_dm_copy_id("_Copy ID", true) , m_menu_dm_close("") // changes depending on if group or not #ifdef WITH_VOICE @@ -208,11 +208,22 @@ ChannelListTree::ChannelListTree() m_menu_voice_channel_disconnect.signal_activate().connect([this]() { m_signal_action_disconnect_voice.emit(); }); +#endif + + m_menu_voice_channel_mark_as_read.signal_activate().connect([this]() { + Abaddon::Get().GetDiscordClient().MarkChannelAsRead(static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]), NOOP_CALLBACK); + }); + + m_menu_voice_open_chat.signal_activate().connect([this]() { + const auto id = static_cast<Snowflake>((*m_model->get_iter(m_path_for_menu))[m_columns.m_id]); + m_signal_action_channel_item_select.emit(id); + }); m_menu_voice_channel.append(m_menu_voice_channel_join); m_menu_voice_channel.append(m_menu_voice_channel_disconnect); + m_menu_voice_channel.append(m_menu_voice_channel_mark_as_read); + m_menu_voice_channel.append(m_menu_voice_open_chat); m_menu_voice_channel.show_all(); -#endif m_menu_dm_copy_id.signal_activate().connect([this] { Gtk::Clipboard::get()->set_text(std::to_string((*m_model->get_iter(m_path_for_menu))[m_columns.m_id])); @@ -355,10 +366,8 @@ int ChannelListTree::SortFunc(const Gtk::TreeModel::iterator &a, const Gtk::Tree const int64_t b_sort = (*b)[m_columns.m_sort]; if (a_type == RenderType::DMHeader) return -1; if (b_type == RenderType::DMHeader) return 1; -#ifdef WITH_VOICE if (a_type == RenderType::TextChannel && b_type == RenderType::VoiceChannel) return -1; if (b_type == RenderType::TextChannel && a_type == RenderType::VoiceChannel) return 1; -#endif return static_cast<int>(std::clamp(a_sort - b_sort, int64_t(-1), int64_t(1))); } @@ -490,13 +499,9 @@ void ChannelListTree::UpdateChannel(Snowflake id) { auto channel = Abaddon::Get().GetDiscordClient().GetChannel(id); if (!iter || !channel.has_value()) return; if (channel->Type == ChannelType::GUILD_CATEGORY) return UpdateChannelCategory(*channel); - // TODO: theres like 4 different fucking ways of checking if somethin g is text or voice can i fix that How stupid . - // fun fact clang-format is indenting me right now i wonder why ,,,,,,,,,,, -#ifdef WITH_VOICE + // TODO: theres like 4 different fucking ways of checking if somethin g is text or voice can i fix that How stupid . + // fun fact clang-format is indenting me right now i wonder why ,,,,,,,,,,, if (!channel->IsText() && channel->Type != ChannelType::GUILD_VOICE) return; -#else - if (!channel->IsText()) return; -#endif // refresh stuff that might have changed const bool is_orphan_TMP = !channel->ParentID.has_value(); @@ -518,11 +523,7 @@ void ChannelListTree::UpdateChannel(Snowflake id) { void ChannelListTree::UpdateCreateChannel(const ChannelData &channel) { if (channel.Type == ChannelType::GUILD_CATEGORY) return (void)UpdateCreateChannelCategory(channel); if (channel.Type == ChannelType::DM || channel.Type == ChannelType::GROUP_DM) return UpdateCreateDMChannel(channel); -#ifdef WITH_VOICE if (channel.Type != ChannelType::GUILD_TEXT && channel.Type != ChannelType::GUILD_NEWS && channel.Type != ChannelType::GUILD_VOICE) return; -#else - if (channel.Type != ChannelType::GUILD_TEXT && channel.Type != ChannelType::GUILD_NEWS) return; -#endif Gtk::TreeRow channel_row; bool orphan; @@ -535,11 +536,7 @@ void ChannelListTree::UpdateCreateChannel(const ChannelData &channel) { auto iter = GetIteratorForGuildFromID(*channel.GuildID); channel_row = *m_model->append(iter->children()); } -#ifdef WITH_VOICE channel_row[m_columns.m_type] = IsTextChannel(channel.Type) ? RenderType::TextChannel : RenderType::VoiceChannel; -#else - channel_row[m_columns.m_type] = RenderType::TextChannel; -#endif 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(); @@ -635,7 +632,6 @@ void ChannelListTree::OnThreadListSync(const ThreadListSyncData &data) { } } -#ifdef WITH_VOICE void ChannelListTree::OnVoiceUserConnect(Snowflake user_id, Snowflake channel_id) { auto parent_iter = GetIteratorForRowFromIDOfType(channel_id, RenderType::VoiceChannel); if (!parent_iter) parent_iter = GetIteratorForRowFromIDOfType(channel_id, RenderType::DM); @@ -657,7 +653,6 @@ void ChannelListTree::OnVoiceStateSet(Snowflake user_id, Snowflake channel_id, V (*iter)[m_columns.m_voice_flags] = flags; } } -#endif void ChannelListTree::DeleteThreadRow(Snowflake id) { auto iter = GetIteratorForRowFromID(id); @@ -919,11 +914,7 @@ Gtk::TreeModel::iterator ChannelListTree::AddGuild(const GuildData &guild, const for (const auto &channel_ : *guild.Channels) { const auto channel = discord.GetChannel(channel_.ID); if (!channel.has_value()) continue; -#ifdef WITH_VOICE if (channel->Type == ChannelType::GUILD_TEXT || channel->Type == ChannelType::GUILD_NEWS || channel->Type == ChannelType::GUILD_VOICE) { -#else - if (channel->Type == ChannelType::GUILD_TEXT || channel->Type == ChannelType::GUILD_NEWS) { -#endif if (channel->ParentID.has_value()) categories[*channel->ParentID].push_back(*channel); else @@ -950,7 +941,6 @@ Gtk::TreeModel::iterator ChannelListTree::AddGuild(const GuildData &guild, const } }; -#ifdef WITH_VOICE auto add_voice_participants = [this, &discord](const ChannelData &channel, const Gtk::TreeNodeChildren &root) { for (auto user_id : discord.GetUsersInVoiceChannel(channel.ID)) { if (const auto user = discord.GetUser(user_id); user.has_value()) { @@ -958,21 +948,17 @@ Gtk::TreeModel::iterator ChannelListTree::AddGuild(const GuildData &guild, const } } }; -#endif for (const auto &channel : orphan_channels) { auto channel_row = *m_model->append(guild_row.children()); if (IsTextChannel(channel.Type)) { channel_row[m_columns.m_type] = RenderType::TextChannel; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); - } -#ifdef WITH_VOICE - else { + } else { channel_row[m_columns.m_type] = RenderType::VoiceChannel; channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel.Name); add_voice_participants(channel, channel_row->children()); } -#endif channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_sort] = *channel.Position + OrphanChannelSortOffset; channel_row[m_columns.m_nsfw] = channel.NSFW(); @@ -997,14 +983,11 @@ Gtk::TreeModel::iterator ChannelListTree::AddGuild(const GuildData &guild, const if (IsTextChannel(channel.Type)) { channel_row[m_columns.m_type] = RenderType::TextChannel; channel_row[m_columns.m_name] = "#" + Glib::Markup::escape_text(*channel.Name); - } -#ifdef WITH_VOICE - else { + } else { channel_row[m_columns.m_type] = RenderType::VoiceChannel; channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel.Name); add_voice_participants(channel, channel_row->children()); } -#endif channel_row[m_columns.m_id] = channel.ID; channel_row[m_columns.m_sort] = *channel.Position; channel_row[m_columns.m_nsfw] = channel.NSFW(); @@ -1042,7 +1025,6 @@ Gtk::TreeModel::iterator ChannelListTree::CreateThreadRow(const Gtk::TreeNodeChi return thread_iter; } -#ifdef WITH_VOICE Gtk::TreeModel::iterator ChannelListTree::CreateVoiceParticipantRow(const UserData &user, const Gtk::TreeNodeChildren &parent) { auto row = *m_model->append(parent); row[m_columns.m_type] = RenderType::VoiceParticipant; @@ -1064,7 +1046,6 @@ Gtk::TreeModel::iterator ChannelListTree::CreateVoiceParticipantRow(const UserDa return row; } -#endif void ChannelListTree::UpdateChannelCategory(const ChannelData &channel) { auto iter = GetIteratorForRowFromID(channel.ID); @@ -1172,8 +1153,11 @@ bool ChannelListTree::SelectionFunc(const Glib::RefPtr<Gtk::TreeModel> &model, c } } - auto type = (*model->get_iter(path))[m_columns.m_type]; - return type == RenderType::TextChannel || type == RenderType::DM || type == RenderType::Thread; + const auto type = (*model->get_iter(path))[m_columns.m_type]; + const auto id = static_cast<Snowflake>((*model->get_iter(path))[m_columns.m_id]); + // todo maybe just keep this last check? + if (type == RenderType::TextChannel || type == RenderType::DM || type == RenderType::Thread || (id == m_active_channel)) return true; + return is_currently_selected; } void ChannelListTree::AddPrivateChannels() { @@ -1205,13 +1189,11 @@ void ChannelListTree::AddPrivateChannels() { row[m_columns.m_icon] = img.GetPlaceholder(DMIconSize); row[m_columns.m_expanded] = true; -#ifdef WITH_VOICE for (auto user_id : discord.GetUsersInVoiceChannel(dm_id)) { if (const auto user = discord.GetUser(user_id); user.has_value()) { CreateVoiceParticipantRow(*user, row->children()); } } -#endif SetDMChannelIcon(iter, *dm); } @@ -1342,12 +1324,10 @@ bool ChannelListTree::OnButtonPressEvent(GdkEventButton *ev) { OnChannelSubmenuPopup(); m_menu_channel.popup_at_pointer(reinterpret_cast<GdkEvent *>(ev)); break; -#ifdef WITH_VOICE case RenderType::VoiceChannel: OnVoiceChannelSubmenuPopup(); m_menu_voice_channel.popup_at_pointer(reinterpret_cast<GdkEvent *>(ev)); break; -#endif case RenderType::DM: { OnDMSubmenuPopup(); const auto channel = Abaddon::Get().GetDiscordClient().GetChannel(static_cast<Snowflake>(row[m_columns.m_id])); @@ -1440,8 +1420,8 @@ void ChannelListTree::OnChannelSubmenuPopup() { m_menu_channel_toggle_mute.set_label("Mute"); } -#ifdef WITH_VOICE void ChannelListTree::OnVoiceChannelSubmenuPopup() { +#ifdef WITH_VOICE const auto iter = m_model->get_iter(m_path_for_menu); if (!iter) return; const auto id = static_cast<Snowflake>((*iter)[m_columns.m_id]); @@ -1453,8 +1433,11 @@ void ChannelListTree::OnVoiceChannelSubmenuPopup() { m_menu_voice_channel_join.set_sensitive(true); m_menu_voice_channel_disconnect.set_sensitive(false); } -} +#else + m_menu_voice_channel_join.set_sensitive(false); + m_menu_voice_channel_disconnect.set_sensitive(false); #endif +} void ChannelListTree::OnDMSubmenuPopup() { auto iter = m_model->get_iter(m_path_for_menu); diff --git a/src/components/channellist/channellisttree.hpp b/src/components/channellist/channellisttree.hpp index 4eebbdb..9e2c544 100644 --- a/src/components/channellist/channellisttree.hpp +++ b/src/components/channellist/channellisttree.hpp @@ -104,10 +104,7 @@ protected: Gtk::TreeModel::iterator AddGuild(const GuildData &guild, const Gtk::TreeNodeChildren &root); Gtk::TreeModel::iterator UpdateCreateChannelCategory(const ChannelData &channel); Gtk::TreeModel::iterator CreateThreadRow(const Gtk::TreeNodeChildren &children, const ChannelData &channel); - -#ifdef WITH_VOICE Gtk::TreeModel::iterator CreateVoiceParticipantRow(const UserData &user, const Gtk::TreeNodeChildren &parent); -#endif void UpdateChannelCategory(const ChannelData &channel); @@ -162,11 +159,11 @@ protected: Gtk::MenuItem m_menu_channel_open_tab; #endif -#ifdef WITH_VOICE Gtk::Menu m_menu_voice_channel; Gtk::MenuItem m_menu_voice_channel_join; Gtk::MenuItem m_menu_voice_channel_disconnect; -#endif + Gtk::MenuItem m_menu_voice_channel_mark_as_read; + Gtk::MenuItem m_menu_voice_open_chat; Gtk::Menu m_menu_dm; Gtk::MenuItem m_menu_dm_copy_id; @@ -194,10 +191,7 @@ protected: void OnChannelSubmenuPopup(); void OnDMSubmenuPopup(); void OnThreadSubmenuPopup(); - -#ifdef WITH_VOICE void OnVoiceChannelSubmenuPopup(); -#endif bool m_updating_listing = false; |