mirror of
https://github.com/uowuo/abaddon.git
synced 2026-08-15 05:19:58 +00:00
Merge branch 'master' into stages
This commit is contained in:
commit
e65174f5aa
29 files changed
+413
-197
No files matched your search
@@ -1,13 +1,15 @@
|
||||
#include "cellrendererchannels.hpp"
|
||||
|
||||
#include <gdkmm/general.h>
|
||||
|
||||
#include "misc/cairo.hpp"
|
||||
|
||||
#include "abaddon.hpp"
|
||||
|
||||
constexpr static int MentionsRightPad = 7;
|
||||
#ifndef M_PI
|
||||
constexpr static double M_PI = 3.14159265358979;
|
||||
#endif
|
||||
constexpr static double M_PI_H = M_PI / 2.0;
|
||||
constexpr static double M_PI_3_2 = M_PI * 3.0 / 2.0;
|
||||
|
||||
void AddUnreadIndicator(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, const Gdk::Rectangle &background_area) {
|
||||
static const auto color_setting = Gdk::RGBA(Abaddon::Get().GetSettings().UnreadIndicatorColor);
|
||||
@@ -120,13 +122,11 @@ 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:
|
||||
case RenderType::VoiceStage:
|
||||
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:
|
||||
@@ -146,13 +146,11 @@ 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:
|
||||
case RenderType::VoiceStage:
|
||||
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,13 +170,11 @@ 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:
|
||||
case RenderType::VoiceStage:
|
||||
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:
|
||||
@@ -198,13 +194,11 @@ 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:
|
||||
case RenderType::VoiceStage:
|
||||
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:
|
||||
@@ -224,14 +218,12 @@ 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, "\U0001F50A");
|
||||
case RenderType::VoiceStage:
|
||||
return render_vfunc_voice_channel(cr, widget, background_area, cell_area, flags, "\U0001F4E1");
|
||||
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:
|
||||
@@ -567,8 +559,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 {
|
||||
@@ -616,6 +606,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
|
||||
@@ -718,8 +723,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 {
|
||||
@@ -838,17 +841,6 @@ void CellRendererChannels::render_vfunc_dm(const Cairo::RefPtr<Cairo::Context> &
|
||||
}
|
||||
}
|
||||
|
||||
void CellRendererChannels::cairo_path_rounded_rect(const Cairo::RefPtr<Cairo::Context> &cr, double x, double y, double w, double h, double r) {
|
||||
const double degrees = M_PI / 180.0;
|
||||
|
||||
cr->begin_new_sub_path();
|
||||
cr->arc(x + w - r, y + r, r, -M_PI_H, 0);
|
||||
cr->arc(x + w - r, y + h - r, r, 0, M_PI_H);
|
||||
cr->arc(x + r, y + h - r, r, M_PI_H, M_PI);
|
||||
cr->arc(x + r, y + r, r, M_PI, M_PI_3_2);
|
||||
cr->close_path();
|
||||
}
|
||||
|
||||
void CellRendererChannels::unread_render_mentions(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, int mentions, int edge, const Gdk::Rectangle &cell_area) {
|
||||
Pango::FontDescription font;
|
||||
font.set_family("sans 14");
|
||||
@@ -869,7 +861,7 @@ void CellRendererChannels::unread_render_mentions(const Cairo::RefPtr<Cairo::Con
|
||||
|
||||
const auto x = cell_area.get_x() + edge - width - MentionsRightPad;
|
||||
const auto y = cell_area.get_y() + cell_area.get_height() / 2.0 - height / 2.0 - 1;
|
||||
cairo_path_rounded_rect(cr, x - 4, y + 2, width + 8, height, 5);
|
||||
CairoUtil::PathRoundedRect(cr, x - 4, y + 2, width + 8, height, 5);
|
||||
cr->set_source_rgb(bg.get_red(), bg.get_green(), bg.get_blue());
|
||||
cr->fill();
|
||||
cr->set_source_rgb(text.get_red(), text.get_green(), text.get_blue());
|
||||
|
||||
@@ -15,13 +15,9 @@ 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,
|
||||
VoiceStage, // identical to non-stage except for icon
|
||||
VoiceParticipant,
|
||||
#endif
|
||||
|
||||
DMHeader,
|
||||
DM,
|
||||
@@ -108,7 +104,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;
|
||||
@@ -131,7 +126,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;
|
||||
@@ -155,7 +149,6 @@ protected:
|
||||
const Gdk::Rectangle &cell_area,
|
||||
Gtk::CellRendererState flags);
|
||||
|
||||
static void cairo_path_rounded_rect(const Cairo::RefPtr<Cairo::Context> &cr, double x, double y, double w, double h, double r);
|
||||
static void unread_render_mentions(const Cairo::RefPtr<Cairo::Context> &cr, Gtk::Widget &widget, int mentions, int edge, const Gdk::Rectangle &cell_area);
|
||||
|
||||
private:
|
||||
|
||||
@@ -26,12 +26,12 @@ 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)
|
||||
, m_menu_voice_stage_join("_Join", true)
|
||||
, m_menu_voice_stage_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
|
||||
@@ -210,11 +210,24 @@ 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();
|
||||
|
||||
#ifdef WITH_VOICE
|
||||
m_menu_voice_stage_join.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_join_voice_channel.emit(id);
|
||||
@@ -223,11 +236,11 @@ ChannelListTree::ChannelListTree()
|
||||
m_menu_voice_stage_disconnect.signal_activate().connect([this]() {
|
||||
m_signal_action_disconnect_voice.emit();
|
||||
});
|
||||
#endif
|
||||
|
||||
m_menu_voice_stage.append(m_menu_voice_stage_join);
|
||||
m_menu_voice_stage.append(m_menu_voice_stage_disconnect);
|
||||
m_menu_voice_stage.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]));
|
||||
@@ -370,10 +383,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 || b_type == RenderType::VoiceStage)) return -1;
|
||||
if (b_type == RenderType::TextChannel && (a_type == RenderType::VoiceChannel || a_type == RenderType::VoiceStage)) return 1;
|
||||
#endif
|
||||
return static_cast<int>(std::clamp(a_sort - b_sort, int64_t(-1), int64_t(1)));
|
||||
}
|
||||
|
||||
@@ -505,7 +516,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);
|
||||
if (!channel->IsText()) return;
|
||||
// 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;
|
||||
|
||||
// refresh stuff that might have changed
|
||||
const bool is_orphan_TMP = !channel->ParentID.has_value();
|
||||
@@ -527,7 +540,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);
|
||||
if (channel.Type != ChannelType::GUILD_TEXT && channel.Type != ChannelType::GUILD_NEWS) return;
|
||||
if (channel.Type != ChannelType::GUILD_TEXT && channel.Type != ChannelType::GUILD_NEWS && channel.Type != ChannelType::GUILD_VOICE) return;
|
||||
|
||||
Gtk::TreeRow channel_row;
|
||||
bool orphan;
|
||||
@@ -540,7 +553,7 @@ void ChannelListTree::UpdateCreateChannel(const ChannelData &channel) {
|
||||
auto iter = GetIteratorForGuildFromID(*channel.GuildID);
|
||||
channel_row = *m_model->append(iter->children());
|
||||
}
|
||||
channel_row[m_columns.m_type] = RenderType::TextChannel;
|
||||
channel_row[m_columns.m_type] = IsTextChannel(channel.Type) ? RenderType::TextChannel : RenderType::VoiceChannel;
|
||||
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();
|
||||
@@ -636,7 +649,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::VoiceStage);
|
||||
@@ -659,7 +671,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);
|
||||
@@ -921,11 +932,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 || channel->Type == ChannelType::GUILD_STAGE_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
|
||||
@@ -952,7 +959,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()) {
|
||||
@@ -960,25 +966,21 @@ 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 if (channel.Type == ChannelType::GUILD_VOICE) {
|
||||
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());
|
||||
} else if (channel.Type == ChannelType::GUILD_STAGE_VOICE) {
|
||||
channel_row[m_columns.m_type] = RenderType::VoiceStage;
|
||||
channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel.Name);
|
||||
add_voice_participants(channel, channel_row->children());
|
||||
} 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();
|
||||
@@ -1003,18 +1005,15 @@ 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 if (channel.Type == ChannelType::GUILD_VOICE) {
|
||||
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());
|
||||
} else if (channel.Type == ChannelType::GUILD_STAGE_VOICE) {
|
||||
channel_row[m_columns.m_type] = RenderType::VoiceStage;
|
||||
channel_row[m_columns.m_name] = Glib::Markup::escape_text(*channel.Name);
|
||||
add_voice_participants(channel, channel_row->children());
|
||||
} 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();
|
||||
@@ -1052,7 +1051,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;
|
||||
@@ -1074,7 +1072,6 @@ Gtk::TreeModel::iterator ChannelListTree::CreateVoiceParticipantRow(const UserDa
|
||||
|
||||
return row;
|
||||
}
|
||||
#endif
|
||||
|
||||
void ChannelListTree::UpdateChannelCategory(const ChannelData &channel) {
|
||||
auto iter = GetIteratorForRowFromID(channel.ID);
|
||||
@@ -1182,8 +1179,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() {
|
||||
@@ -1215,13 +1215,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);
|
||||
}
|
||||
@@ -1352,7 +1350,6 @@ 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));
|
||||
@@ -1361,7 +1358,6 @@ bool ChannelListTree::OnButtonPressEvent(GdkEventButton *ev) {
|
||||
OnVoiceStageSubmenuPopup();
|
||||
m_menu_voice_stage.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]));
|
||||
@@ -1454,8 +1450,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]);
|
||||
@@ -1467,9 +1463,14 @@ 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::OnVoiceStageSubmenuPopup() {
|
||||
#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]);
|
||||
@@ -1481,8 +1482,10 @@ void ChannelListTree::OnVoiceStageSubmenuPopup() {
|
||||
m_menu_voice_stage_join.set_sensitive(true);
|
||||
m_menu_voice_stage_disconnect.set_sensitive(false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
m_menu_voice_stage_join.set_sensitive(false);
|
||||
m_menu_voice_stage_disconnect.set_sensitive(false);
|
||||
}
|
||||
|
||||
void ChannelListTree::OnDMSubmenuPopup() {
|
||||
auto iter = m_model->get_iter(m_path_for_menu);
|
||||
|
||||
@@ -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,7 +159,6 @@ 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;
|
||||
@@ -170,7 +166,8 @@ protected:
|
||||
Gtk::Menu m_menu_voice_stage;
|
||||
Gtk::MenuItem m_menu_voice_stage_join;
|
||||
Gtk::MenuItem m_menu_voice_stage_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;
|
||||
@@ -198,11 +195,8 @@ protected:
|
||||
void OnChannelSubmenuPopup();
|
||||
void OnDMSubmenuPopup();
|
||||
void OnThreadSubmenuPopup();
|
||||
|
||||
#ifdef WITH_VOICE
|
||||
void OnVoiceChannelSubmenuPopup();
|
||||
void OnVoiceStageSubmenuPopup();
|
||||
#endif
|
||||
|
||||
bool m_updating_listing = false;
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#include <gtkmm/overlay.h>
|
||||
|
||||
#include "guildlist.hpp"
|
||||
|
||||
#include "abaddon.hpp"
|
||||
#include "util.hpp"
|
||||
#include "guildlistfolderitem.hpp"
|
||||
#include "mentionoverlay.hpp"
|
||||
|
||||
class GuildListDMsButton : public Gtk::EventBox {
|
||||
public:
|
||||
@@ -93,10 +96,38 @@ void GuildList::UpdateListing() {
|
||||
}
|
||||
}
|
||||
|
||||
static Gtk::Widget *AddMentionOverlay(Gtk::Widget *widget, Snowflake guild_id) {
|
||||
auto *overlay = Gtk::make_managed<Gtk::Overlay>();
|
||||
overlay->add(*widget);
|
||||
auto *mention_overlay = Gtk::make_managed<MentionOverlay>(guild_id);
|
||||
overlay->add_overlay(*mention_overlay);
|
||||
overlay->set_overlay_pass_through(*mention_overlay, true);
|
||||
mention_overlay->signal_realize().connect([mention_overlay]() {
|
||||
mention_overlay->get_window()->set_pass_through(true);
|
||||
});
|
||||
mention_overlay->show();
|
||||
overlay->show();
|
||||
return overlay;
|
||||
}
|
||||
|
||||
static Gtk::Widget *AddMentionOverlay(Gtk::Widget *widget, const UserSettingsGuildFoldersEntry &folder) {
|
||||
auto *overlay = Gtk::make_managed<Gtk::Overlay>();
|
||||
overlay->add(*widget);
|
||||
auto *mention_overlay = Gtk::make_managed<MentionOverlay>(folder);
|
||||
overlay->add_overlay(*mention_overlay);
|
||||
overlay->set_overlay_pass_through(*mention_overlay, true);
|
||||
mention_overlay->signal_realize().connect([mention_overlay]() {
|
||||
mention_overlay->get_window()->set_pass_through(true);
|
||||
});
|
||||
mention_overlay->show();
|
||||
overlay->show();
|
||||
return overlay;
|
||||
}
|
||||
|
||||
void GuildList::AddGuild(Snowflake id) {
|
||||
if (auto item = CreateGuildWidget(id)) {
|
||||
item->show();
|
||||
add(*item);
|
||||
add(*AddMentionOverlay(item, id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,12 +163,12 @@ void GuildList::AddFolder(const UserSettingsGuildFoldersEntry &folder) {
|
||||
for (const auto guild_id : folder.GuildIDs) {
|
||||
if (auto *guild_widget = CreateGuildWidget(guild_id)) {
|
||||
guild_widget->show();
|
||||
folder_widget->AddGuildWidget(guild_widget);
|
||||
folder_widget->AddGuildWidget(AddMentionOverlay(guild_widget, guild_id));
|
||||
}
|
||||
}
|
||||
|
||||
folder_widget->show();
|
||||
add(*folder_widget);
|
||||
add(*AddMentionOverlay(folder_widget, folder));
|
||||
}
|
||||
|
||||
void GuildList::Clear() {
|
||||
|
||||
@@ -95,7 +95,7 @@ GuildListFolderItem::GuildListFolderItem(const UserSettingsGuildFoldersEntry &fo
|
||||
CheckUnreadStatus();
|
||||
}
|
||||
|
||||
void GuildListFolderItem::AddGuildWidget(GuildListGuildItem *widget) {
|
||||
void GuildListFolderItem::AddGuildWidget(Gtk::Widget *widget) {
|
||||
m_box.add(*widget);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class GuildListFolderItem : public Gtk::VBox {
|
||||
public:
|
||||
GuildListFolderItem(const UserSettingsGuildFoldersEntry &folder);
|
||||
|
||||
void AddGuildWidget(GuildListGuildItem *widget);
|
||||
void AddGuildWidget(Gtk::Widget *widget);
|
||||
|
||||
private:
|
||||
void OnMessageCreate(const Message &msg);
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#include "mentionoverlay.hpp"
|
||||
|
||||
#include "misc/cairo.hpp"
|
||||
|
||||
#include "abaddon.hpp"
|
||||
|
||||
MentionOverlay::MentionOverlay(Snowflake guild_id)
|
||||
: m_guild_ids({ guild_id }) {
|
||||
Init();
|
||||
}
|
||||
|
||||
MentionOverlay::MentionOverlay(const UserSettingsGuildFoldersEntry &folder)
|
||||
: m_guild_ids({ folder.GuildIDs.begin(), folder.GuildIDs.end() }) {
|
||||
Init();
|
||||
}
|
||||
|
||||
void MentionOverlay::Init() {
|
||||
m_font.set_family("sans 14");
|
||||
m_layout = create_pango_layout("12");
|
||||
m_layout->set_font_description(m_font);
|
||||
m_layout->set_alignment(Pango::ALIGN_RIGHT);
|
||||
|
||||
get_style_context()->add_class("classic-mention-overlay"); // fuck you
|
||||
|
||||
set_hexpand(false);
|
||||
set_vexpand(false);
|
||||
|
||||
signal_draw().connect(sigc::mem_fun(*this, &MentionOverlay::OnDraw));
|
||||
|
||||
Abaddon::Get().GetDiscordClient().signal_message_ack().connect([this](const MessageAckData &data) {
|
||||
// fetching and checking guild id is probably more expensive than just forcing a redraw anyways
|
||||
queue_draw();
|
||||
});
|
||||
|
||||
Abaddon::Get().GetDiscordClient().signal_message_create().connect([this](const Message &msg) {
|
||||
if (msg.GuildID.has_value() && m_guild_ids.find(*msg.GuildID) == m_guild_ids.end()) return;
|
||||
if (!msg.DoesMentionEveryone && msg.Mentions.empty() && msg.MentionRoles.empty()) return;
|
||||
queue_draw();
|
||||
});
|
||||
}
|
||||
|
||||
bool MentionOverlay::OnDraw(const Cairo::RefPtr<Cairo::Context> &cr) {
|
||||
int total_mentions = 0;
|
||||
for (auto guild_id : m_guild_ids) {
|
||||
int mentions;
|
||||
Abaddon::Get().GetDiscordClient().GetUnreadStateForGuild(guild_id, mentions);
|
||||
total_mentions += mentions;
|
||||
}
|
||||
if (total_mentions == 0) return true;
|
||||
m_layout->set_text(std::to_string(total_mentions));
|
||||
|
||||
const int width = get_allocated_width();
|
||||
const int height = std::min(get_allocated_height(), 48); // cope
|
||||
|
||||
int lw, lh;
|
||||
m_layout->get_pixel_size(lw, lh);
|
||||
{
|
||||
static const auto badge_setting = Gdk::RGBA(Abaddon::Get().GetSettings().MentionBadgeColor);
|
||||
static const auto text_setting = Gdk::RGBA(Abaddon::Get().GetSettings().MentionBadgeTextColor);
|
||||
|
||||
auto bg = badge_setting.get_alpha_u() > 0 ? badge_setting : get_style_context()->get_background_color(Gtk::STATE_FLAG_SELECTED);
|
||||
auto text = text_setting.get_alpha_u() > 0 ? text_setting : get_style_context()->get_color(Gtk::STATE_FLAG_SELECTED);
|
||||
|
||||
const auto x = width - lw - 5;
|
||||
const auto y = height - lh - 1;
|
||||
CairoUtil::PathRoundedRect(cr, x - 4, y + 2, lw + 8, lh, 5);
|
||||
cr->set_source_rgb(bg.get_red(), bg.get_green(), bg.get_blue());
|
||||
cr->fill();
|
||||
cr->set_source_rgb(text.get_red(), text.get_green(), text.get_blue());
|
||||
cr->move_to(x, y);
|
||||
m_layout->show_in_cairo_context(cr);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <gtkmm/drawingarea.h>
|
||||
#include <pangomm/fontdescription.h>
|
||||
|
||||
#include "discord/snowflake.hpp"
|
||||
#include "discord/usersettings.hpp"
|
||||
|
||||
class MentionOverlay : public Gtk::DrawingArea {
|
||||
public:
|
||||
MentionOverlay(Snowflake guild_id);
|
||||
MentionOverlay(const UserSettingsGuildFoldersEntry &folder);
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
bool OnDraw(const Cairo::RefPtr<Cairo::Context> &cr);
|
||||
|
||||
std::set<Snowflake> m_guild_ids;
|
||||
|
||||
Pango::FontDescription m_font;
|
||||
Glib::RefPtr<Pango::Layout> m_layout;
|
||||
};
|
||||
Reference in new issue
Block a user