forked from OpenGamers/abaddon
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ad0d4e7d4d | ||
|
1ca6235e09 | ||
|
c04fc2e60c | ||
|
a7bf9a2404 | ||
|
2065ef4940 | ||
|
3aefab652e |
|
@ -51,8 +51,35 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const ChannelData *data) {
|
|||
ID = data->ID;
|
||||
m_ev = Gtk::manage(new Gtk::EventBox);
|
||||
m_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
||||
m_lbl = Gtk::manage(new Gtk::TextView);
|
||||
MakeReadOnly(m_lbl);
|
||||
|
||||
std::optional<UserData> top_recipient; // potentially nullopt in group dm
|
||||
const auto recipients = data->GetDMRecipients();
|
||||
if (recipients.size() > 0)
|
||||
top_recipient = recipients[0];
|
||||
|
||||
const static bool alt = Abaddon::Get().GetSettings().GetUseMobileLayout();
|
||||
if (alt) {
|
||||
auto *tmp = Gtk::manage(new Gtk::Label);
|
||||
m_lbl = tmp;
|
||||
if (data->Type == ChannelType::DM)
|
||||
tmp->set_text(top_recipient->Username);
|
||||
else if (data->Type == ChannelType::GROUP_DM)
|
||||
tmp->set_text(std::to_string(recipients.size()) + " users");
|
||||
} else {
|
||||
auto *tmp = Gtk::manage(new Gtk::TextView);
|
||||
m_lbl = tmp;
|
||||
MakeReadOnly(tmp);
|
||||
|
||||
auto buf = tmp->get_buffer();
|
||||
if (data->Type == ChannelType::DM)
|
||||
buf->set_text(top_recipient->Username);
|
||||
else if (data->Type == ChannelType::GROUP_DM)
|
||||
buf->set_text(std::to_string(recipients.size()) + " users");
|
||||
|
||||
static bool show_emojis = Abaddon::Get().GetSettings().GetShowEmojis();
|
||||
if (show_emojis)
|
||||
Abaddon::Get().GetEmojis().ReplaceEmojis(buf, ChannelEmojiSize);
|
||||
}
|
||||
|
||||
AddWidgetMenuHandler(m_ev, m_menu);
|
||||
AddWidgetMenuHandler(m_lbl, m_menu);
|
||||
|
@ -77,11 +104,6 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const ChannelData *data) {
|
|||
get_style_context()->add_class("channel-row");
|
||||
m_lbl->get_style_context()->add_class("channel-row-label");
|
||||
|
||||
std::optional<UserData> top_recipient; // potentially nullopt in group dm
|
||||
const auto recipients = data->GetDMRecipients();
|
||||
if (recipients.size() > 0)
|
||||
top_recipient = recipients[0];
|
||||
|
||||
if (data->Type == ChannelType::DM) {
|
||||
m_status = Gtk::manage(new StatusIndicator(top_recipient->ID));
|
||||
m_status->set_margin_start(5);
|
||||
|
@ -93,16 +115,6 @@ ChannelListRowDMChannel::ChannelListRowDMChannel(const ChannelData *data) {
|
|||
Abaddon::Get().GetImageManager().LoadFromURL(top_recipient->GetAvatarURL("png", "16"), sigc::track_obj(cb, *this));
|
||||
}
|
||||
|
||||
auto buf = m_lbl->get_buffer();
|
||||
if (data->Type == ChannelType::DM)
|
||||
buf->set_text(top_recipient->Username);
|
||||
else if (data->Type == ChannelType::GROUP_DM)
|
||||
buf->set_text(std::to_string(recipients.size()) + " users");
|
||||
|
||||
static bool show_emojis = Abaddon::Get().GetSettings().GetShowEmojis();
|
||||
if (show_emojis)
|
||||
Abaddon::Get().GetEmojis().ReplaceEmojis(buf, ChannelEmojiSize);
|
||||
|
||||
m_box->set_halign(Gtk::ALIGN_START);
|
||||
if (m_icon != nullptr)
|
||||
m_box->pack_start(*m_icon);
|
||||
|
@ -118,8 +130,22 @@ ChannelListRowGuild::ChannelListRowGuild(const GuildData *data) {
|
|||
ID = data->ID;
|
||||
m_ev = Gtk::manage(new Gtk::EventBox);
|
||||
m_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
||||
m_lbl = Gtk::manage(new Gtk::TextView);
|
||||
MakeReadOnly(m_lbl);
|
||||
|
||||
const static bool alt = Abaddon::Get().GetSettings().GetUseMobileLayout();
|
||||
if (alt) {
|
||||
m_lbl = Gtk::manage(new Gtk::Label(data->Name));
|
||||
} else {
|
||||
auto *tmp = Gtk::manage(new Gtk::TextView);
|
||||
m_lbl = tmp;
|
||||
MakeReadOnly(tmp);
|
||||
auto buf = tmp->get_buffer();
|
||||
Gtk::TextBuffer::iterator start, end;
|
||||
buf->get_bounds(start, end);
|
||||
buf->insert_markup(start, "<b>" + Glib::Markup::escape_text(data->Name) + "</b>");
|
||||
static bool show_emojis = Abaddon::Get().GetSettings().GetShowEmojis();
|
||||
if (show_emojis)
|
||||
Abaddon::Get().GetEmojis().ReplaceEmojis(buf, ChannelEmojiSize);
|
||||
}
|
||||
|
||||
AddWidgetMenuHandler(m_ev, m_menu);
|
||||
AddWidgetMenuHandler(m_lbl, m_menu);
|
||||
|
@ -168,13 +194,6 @@ ChannelListRowGuild::ChannelListRowGuild(const GuildData *data) {
|
|||
get_style_context()->add_class("channel-row-guild");
|
||||
m_lbl->get_style_context()->add_class("channel-row-label");
|
||||
|
||||
auto buf = m_lbl->get_buffer();
|
||||
Gtk::TextBuffer::iterator start, end;
|
||||
buf->get_bounds(start, end);
|
||||
buf->insert_markup(start, "<b>" + Glib::Markup::escape_text(data->Name) + "</b>");
|
||||
static bool show_emojis = Abaddon::Get().GetSettings().GetShowEmojis();
|
||||
if (show_emojis)
|
||||
Abaddon::Get().GetEmojis().ReplaceEmojis(buf, ChannelEmojiSize);
|
||||
m_box->set_halign(Gtk::ALIGN_START);
|
||||
m_box->pack_start(*m_icon);
|
||||
m_box->pack_start(*m_lbl);
|
||||
|
@ -199,8 +218,20 @@ ChannelListRowCategory::ChannelListRowCategory(const ChannelData *data) {
|
|||
ID = data->ID;
|
||||
m_ev = Gtk::manage(new Gtk::EventBox);
|
||||
m_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
||||
m_lbl = Gtk::manage(new Gtk::TextView);
|
||||
MakeReadOnly(m_lbl);
|
||||
|
||||
const static bool alt = Abaddon::Get().GetSettings().GetUseMobileLayout();
|
||||
if (alt) {
|
||||
m_lbl = Gtk::manage(new Gtk::Label(*data->Name));
|
||||
} else {
|
||||
auto *tmp = Gtk::manage(new Gtk::TextView);
|
||||
m_lbl = tmp;
|
||||
MakeReadOnly(tmp);
|
||||
auto buf = tmp->get_buffer();
|
||||
buf->set_text(*data->Name);
|
||||
static bool show_emojis = Abaddon::Get().GetSettings().GetShowEmojis();
|
||||
if (show_emojis)
|
||||
Abaddon::Get().GetEmojis().ReplaceEmojis(buf, ChannelEmojiSize);
|
||||
}
|
||||
m_arrow = Gtk::manage(new Gtk::Arrow(Gtk::ARROW_DOWN, Gtk::SHADOW_NONE));
|
||||
|
||||
m_menu_copyid = Gtk::manage(new Gtk::MenuItem("_Copy ID", true));
|
||||
|
@ -218,11 +249,6 @@ ChannelListRowCategory::ChannelListRowCategory(const ChannelData *data) {
|
|||
get_style_context()->add_class("channel-row-category");
|
||||
m_lbl->get_style_context()->add_class("channel-row-label");
|
||||
|
||||
auto buf = m_lbl->get_buffer();
|
||||
buf->set_text(*data->Name);
|
||||
static bool show_emojis = Abaddon::Get().GetSettings().GetShowEmojis();
|
||||
if (show_emojis)
|
||||
Abaddon::Get().GetEmojis().ReplaceEmojis(buf, ChannelEmojiSize);
|
||||
m_box->set_halign(Gtk::ALIGN_START);
|
||||
m_box->pack_start(*m_arrow);
|
||||
m_box->pack_start(*m_lbl);
|
||||
|
@ -247,8 +273,20 @@ ChannelListRowChannel::ChannelListRowChannel(const ChannelData *data) {
|
|||
ID = data->ID;
|
||||
m_ev = Gtk::manage(new Gtk::EventBox);
|
||||
m_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
||||
m_lbl = Gtk::manage(new Gtk::TextView);
|
||||
MakeReadOnly(m_lbl);
|
||||
|
||||
const static bool alt = Abaddon::Get().GetSettings().GetUseMobileLayout();
|
||||
if (alt) {
|
||||
m_lbl = Gtk::manage(new Gtk::Label("#" + *data->Name));
|
||||
} else {
|
||||
auto *tmp = Gtk::manage(new Gtk::TextView);
|
||||
m_lbl = tmp;
|
||||
MakeReadOnly(tmp);
|
||||
auto buf = tmp->get_buffer();
|
||||
buf->set_text("#" + *data->Name);
|
||||
static bool show_emojis = Abaddon::Get().GetSettings().GetShowEmojis();
|
||||
if (show_emojis)
|
||||
Abaddon::Get().GetEmojis().ReplaceEmojis(buf, ChannelEmojiSize);
|
||||
}
|
||||
|
||||
m_menu_copyid = Gtk::manage(new Gtk::MenuItem("_Copy ID", true));
|
||||
m_menu_copyid->signal_activate().connect([this]() {
|
||||
|
@ -265,15 +303,11 @@ ChannelListRowChannel::ChannelListRowChannel(const ChannelData *data) {
|
|||
get_style_context()->add_class("channel-row-channel");
|
||||
m_lbl->get_style_context()->add_class("channel-row-label");
|
||||
|
||||
auto buf = m_lbl->get_buffer();
|
||||
if (data->IsNSFW.has_value() && *data->IsNSFW) {
|
||||
get_style_context()->add_class("nsfw");
|
||||
m_lbl->get_style_context()->add_class("nsfw");
|
||||
}
|
||||
buf->set_text("#" + *data->Name);
|
||||
static bool show_emojis = Abaddon::Get().GetSettings().GetShowEmojis();
|
||||
if (show_emojis)
|
||||
Abaddon::Get().GetEmojis().ReplaceEmojis(buf, ChannelEmojiSize);
|
||||
|
||||
m_box->set_halign(Gtk::ALIGN_START);
|
||||
m_box->pack_start(*m_lbl);
|
||||
m_ev->add(*m_box);
|
||||
|
|
|
@ -42,7 +42,7 @@ protected:
|
|||
Gtk::EventBox *m_ev;
|
||||
Gtk::Box *m_box;
|
||||
StatusIndicator *m_status = nullptr;
|
||||
Gtk::TextView *m_lbl;
|
||||
Gtk::Widget *m_lbl;
|
||||
Gtk::Image *m_icon = nullptr;
|
||||
|
||||
Gtk::Menu m_menu;
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
protected:
|
||||
Gtk::EventBox *m_ev;
|
||||
Gtk::Box *m_box;
|
||||
Gtk::TextView *m_lbl;
|
||||
Gtk::Widget *m_lbl;
|
||||
Gtk::Image *m_icon;
|
||||
|
||||
Gtk::Menu m_menu;
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
protected:
|
||||
Gtk::EventBox *m_ev;
|
||||
Gtk::Box *m_box;
|
||||
Gtk::TextView *m_lbl;
|
||||
Gtk::Widget *m_lbl;
|
||||
Gtk::Arrow *m_arrow;
|
||||
|
||||
Gtk::Menu m_menu;
|
||||
|
@ -114,7 +114,7 @@ public:
|
|||
protected:
|
||||
Gtk::EventBox *m_ev;
|
||||
Gtk::Box *m_box;
|
||||
Gtk::TextView *m_lbl;
|
||||
Gtk::Widget *m_lbl;
|
||||
|
||||
Gtk::Menu m_menu;
|
||||
Gtk::MenuItem *m_menu_copyid;
|
||||
|
|
|
@ -81,3 +81,8 @@ bool SettingsManager::GetShowAnimations() const {
|
|||
bool SettingsManager::GetShowOwnerCrown() const {
|
||||
return GetSettingBool("gui", "owner_crown", true);
|
||||
}
|
||||
|
||||
bool SettingsManager::GetUseMobileLayout() const {
|
||||
// todo: see if there's some sort of preprocessor directive to default this to true on mobile platforms
|
||||
return GetSettingBool("gui", "mobile", false);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public:
|
|||
std::string GetMainCSS() const;
|
||||
bool GetShowAnimations() const;
|
||||
bool GetShowOwnerCrown() const;
|
||||
bool GetUseMobileLayout() const;
|
||||
|
||||
bool IsValid() const;
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
#include "mainwindow.hpp"
|
||||
#include "../abaddon.hpp"
|
||||
|
||||
MainWindow::MainWindow()
|
||||
: m_main_box(Gtk::ORIENTATION_VERTICAL)
|
||||
, m_content_box(Gtk::ORIENTATION_HORIZONTAL)
|
||||
, m_chan_content_paned(Gtk::ORIENTATION_HORIZONTAL)
|
||||
, m_content_members_paned(Gtk::ORIENTATION_HORIZONTAL) {
|
||||
MainWindow::MainWindow() {
|
||||
const bool use_mobile = Abaddon::Get().GetSettings().GetUseMobileLayout();
|
||||
|
||||
set_default_size(1200, 800);
|
||||
get_style_context()->add_class("app-window");
|
||||
|
||||
|
@ -79,26 +77,10 @@ MainWindow::MainWindow()
|
|||
m_signal_action_add_recipient.emit(GetChatActiveChannel());
|
||||
});
|
||||
|
||||
m_content_box.set_hexpand(true);
|
||||
m_content_box.set_vexpand(true);
|
||||
m_content_box.show();
|
||||
|
||||
m_main_box.add(m_menu_bar);
|
||||
m_main_box.add(m_content_box);
|
||||
m_main_box.show();
|
||||
|
||||
auto *channel_list = m_channel_list.GetRoot();
|
||||
auto *member_list = m_members.GetRoot();
|
||||
auto *chat = m_chat.GetRoot();
|
||||
|
||||
m_members.signal_action_show_user_menu().connect([this](const GdkEvent *event, Snowflake id, Snowflake guild_id) {
|
||||
m_signal_action_show_user_menu.emit(event, id, guild_id);
|
||||
});
|
||||
|
||||
m_chat.signal_action_open_user_menu().connect([this](const GdkEvent *event, Snowflake id, Snowflake guild_id) {
|
||||
m_signal_action_show_user_menu.emit(event, id, guild_id);
|
||||
});
|
||||
|
||||
chat->set_vexpand(true);
|
||||
chat->set_hexpand(true);
|
||||
chat->show();
|
||||
|
@ -110,29 +92,83 @@ MainWindow::MainWindow()
|
|||
member_list->set_vexpand(true);
|
||||
member_list->show();
|
||||
|
||||
m_content_stack.add(*chat);
|
||||
m_content_stack.set_vexpand(true);
|
||||
m_content_stack.set_hexpand(true);
|
||||
m_content_stack.show();
|
||||
if (use_mobile) {
|
||||
m_main_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL));
|
||||
|
||||
m_chan_content_paned.pack1(*channel_list);
|
||||
m_chan_content_paned.pack2(m_content_members_paned);
|
||||
m_chan_content_paned.child_property_shrink(*channel_list) = false;
|
||||
m_chan_content_paned.child_property_resize(*channel_list) = false;
|
||||
m_chan_content_paned.set_position(200);
|
||||
m_chan_content_paned.show();
|
||||
m_content_box.add(m_chan_content_paned);
|
||||
m_stack = Gtk::manage(new Gtk::Stack);
|
||||
m_switcher = Gtk::manage(new Gtk::StackSwitcher);
|
||||
|
||||
m_content_members_paned.pack1(m_content_stack);
|
||||
m_content_members_paned.pack2(*member_list);
|
||||
m_content_members_paned.child_property_shrink(*member_list) = false;
|
||||
m_content_members_paned.child_property_resize(*member_list) = false;
|
||||
int w, h;
|
||||
get_default_size(w, h); // :s
|
||||
m_content_members_paned.set_position(w - m_chan_content_paned.get_position() - 150);
|
||||
m_content_members_paned.show();
|
||||
m_stack->set_transition_type(Gtk::STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT);
|
||||
|
||||
add(m_main_box);
|
||||
m_stack->add(*m_channel_list.GetRoot(), "Channels");
|
||||
m_stack->add(*m_chat.GetRoot(), "Chat");
|
||||
m_stack->add(*m_members.GetRoot(), "Members");
|
||||
m_stack->child_property_icon_name(*m_channel_list.GetRoot()) = "format-justify-fill-symbolic";
|
||||
m_stack->child_property_icon_name(*m_chat.GetRoot()) = "user-invisible-symbolic";
|
||||
m_stack->child_property_icon_name(*m_members.GetRoot()) = "avatar-default-symbolic";
|
||||
|
||||
m_switcher->set_hexpand(true);
|
||||
m_switcher->set_halign(Gtk::ALIGN_FILL);
|
||||
m_switcher->set_homogeneous(true);
|
||||
|
||||
m_main_box->add(m_menu_bar);
|
||||
m_main_box->add(*m_stack);
|
||||
m_main_box->add(*m_switcher);
|
||||
m_switcher->set_stack(*m_stack);
|
||||
|
||||
m_stack->show();
|
||||
m_switcher->show_all();
|
||||
m_main_box->show();
|
||||
|
||||
add(*m_main_box);
|
||||
} else {
|
||||
m_main_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL));
|
||||
m_content_box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
|
||||
m_chan_content_paned = Gtk::manage(new Gtk::Paned(Gtk::ORIENTATION_HORIZONTAL));
|
||||
m_content_members_paned = Gtk::manage(new Gtk::Paned(Gtk::ORIENTATION_HORIZONTAL));
|
||||
m_content_stack = Gtk::manage(new Gtk::Stack);
|
||||
|
||||
m_main_box->show();
|
||||
|
||||
m_content_box->set_hexpand(true);
|
||||
m_content_box->set_vexpand(true);
|
||||
m_content_box->show();
|
||||
|
||||
m_content_stack->add(*chat);
|
||||
m_content_stack->set_vexpand(true);
|
||||
m_content_stack->set_hexpand(true);
|
||||
m_content_stack->show();
|
||||
|
||||
m_chan_content_paned->pack1(*channel_list);
|
||||
m_chan_content_paned->pack2(*m_content_members_paned);
|
||||
m_chan_content_paned->child_property_shrink(*channel_list) = false;
|
||||
m_chan_content_paned->child_property_resize(*channel_list) = false;
|
||||
m_chan_content_paned->set_position(200);
|
||||
m_chan_content_paned->show();
|
||||
m_content_box->add(*m_chan_content_paned);
|
||||
|
||||
m_content_members_paned->pack1(*m_content_stack);
|
||||
m_content_members_paned->pack2(*member_list);
|
||||
m_content_members_paned->child_property_shrink(*member_list) = false;
|
||||
m_content_members_paned->child_property_resize(*member_list) = false;
|
||||
int w, h;
|
||||
get_default_size(w, h); // :s
|
||||
m_content_members_paned->set_position(w - m_chan_content_paned->get_position() - 150);
|
||||
m_content_members_paned->show();
|
||||
|
||||
m_main_box->add(m_menu_bar);
|
||||
m_main_box->add(*m_content_box);
|
||||
|
||||
add(*m_main_box);
|
||||
}
|
||||
|
||||
m_members.signal_action_show_user_menu().connect([this](const GdkEvent *event, Snowflake id, Snowflake guild_id) {
|
||||
m_signal_action_show_user_menu.emit(event, id, guild_id);
|
||||
});
|
||||
|
||||
m_chat.signal_action_open_user_menu().connect([this](const GdkEvent *event, Snowflake id, Snowflake guild_id) {
|
||||
m_signal_action_show_user_menu.emit(event, id, guild_id);
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::UpdateComponents() {
|
||||
|
@ -207,6 +243,10 @@ void MainWindow::UpdateChatActiveChannel(Snowflake id) {
|
|||
m_chat.SetActiveChannel(id);
|
||||
m_members.SetActiveChannel(id);
|
||||
m_channel_list.SetActiveChannel(id);
|
||||
|
||||
if (m_stack != nullptr) {
|
||||
m_stack->set_visible_child("Chat");
|
||||
}
|
||||
}
|
||||
|
||||
Snowflake MainWindow::GetChatActiveChannel() const {
|
||||
|
|
|
@ -66,17 +66,21 @@ protected:
|
|||
type_signal_action_add_recipient m_signal_action_add_recipient;
|
||||
|
||||
protected:
|
||||
Gtk::Box m_main_box;
|
||||
Gtk::Box m_content_box;
|
||||
Gtk::Paned m_chan_content_paned;
|
||||
Gtk::Paned m_content_members_paned;
|
||||
Gtk::Box *m_main_box;
|
||||
// normal
|
||||
Gtk::Box *m_content_box = nullptr;
|
||||
Gtk::Paned *m_chan_content_paned = nullptr;
|
||||
Gtk::Paned *m_content_members_paned = nullptr;
|
||||
Gtk::Stack *m_content_stack = nullptr;
|
||||
|
||||
// mobile
|
||||
Gtk::StackSwitcher *m_switcher = nullptr;
|
||||
Gtk::Stack *m_stack = nullptr;
|
||||
|
||||
ChannelList m_channel_list;
|
||||
ChatWindow m_chat;
|
||||
MemberList m_members;
|
||||
|
||||
Gtk::Stack m_content_stack;
|
||||
|
||||
Gtk::MenuBar m_menu_bar;
|
||||
Gtk::MenuItem m_menu_discord;
|
||||
Gtk::Menu m_menu_discord_sub;
|
||||
|
|
Loading…
Reference in New Issue
Block a user