friends: friends list is now in main content stack

This commit is contained in:
ouwou
2021-05-14 00:27:58 -04:00
parent 858fd8ce62
commit 95eb664641
5 changed files with 43 additions and 14 deletions

View File

@@ -7,18 +7,15 @@ using namespace std::string_literals;
FriendsList::FriendsList()
: Gtk::Box(Gtk::ORIENTATION_VERTICAL)
, m_filter_mode(FILTER_FRIENDS) {
get_style_context()->add_class("friends-list");
auto &discord = Abaddon::Get().GetDiscordClient();
discord.signal_relationship_add().connect(sigc::mem_fun(*this, &FriendsList::OnRelationshipAdd));
discord.signal_relationship_remove().connect(sigc::mem_fun(*this, &FriendsList::OnRelationshipRemove));
for (const auto &[id, type] : discord.GetRelationships()) {
const auto user = discord.GetUser(id);
if (!user.has_value()) continue;
auto *row = MakeRow(*user, type);
m_list.add(*row);
row->show();
}
PopulateRelationships();
signal_map().connect(sigc::mem_fun(*this, &FriendsList::PopulateRelationships));
constexpr static std::array<const char *, 4> strs = {
"Friends",
@@ -147,6 +144,20 @@ void FriendsList::OnActionRemove(Snowflake id) {
}
}
void FriendsList::PopulateRelationships() {
for (auto child : m_list.get_children())
delete child;
auto &discord = Abaddon::Get().GetDiscordClient();
for (const auto &[id, type] : discord.GetRelationships()) {
const auto user = discord.GetUser(id);
if (!user.has_value()) continue;
auto *row = MakeRow(*user, type);
m_list.add(*row);
row->show();
}
}
int FriendsList::ListSortFunc(Gtk::ListBoxRow *a_, Gtk::ListBoxRow *b_) {
auto *a = dynamic_cast<FriendsListFriendRow *>(a_);
auto *b = dynamic_cast<FriendsListFriendRow *>(b_);
@@ -238,6 +249,7 @@ FriendsListFriendRow::FriendsListFriendRow(RelationshipType type, const UserData
auto *ev = Gtk::manage(new Gtk::EventBox);
auto *box = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
auto *img = Gtk::manage(new LazyImage(32, 32, true));
auto *namebox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_HORIZONTAL));
auto *namelbl = Gtk::manage(new Gtk::Label("", Gtk::ALIGN_START));
m_status_lbl = Gtk::manage(new Gtk::Label("", Gtk::ALIGN_START));
auto *lblbox = Gtk::manage(new Gtk::Box(Gtk::ORIENTATION_VERTICAL));
@@ -291,7 +303,8 @@ FriendsListFriendRow::FriendsListFriendRow(RelationshipType type, const UserData
img->set_margin_end(5);
lblbox->add(*namelbl);
namebox->add(*namelbl);
lblbox->add(*namebox);
lblbox->add(*m_status_lbl);
box->add(*img);

View File

@@ -33,6 +33,8 @@ private:
void OnActionAccept(Snowflake id);
void OnActionRemove(Snowflake id);
void PopulateRelationships();
enum FilterMode {
FILTER_FRIENDS,
FILTER_ONLINE,

View File

@@ -341,3 +341,12 @@
.drag-hover-bottom {
background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 65%, rgba(255, 66, 66, 0.65) 100%);
}
.friends-list list {
background: @background_color;
padding-left: 10px;
}
.friends-list-row-bot {
color: #ff0000;
}

View File

@@ -1,6 +1,5 @@
#include "mainwindow.hpp"
#include "../abaddon.hpp"
#include "../components/friendslist.hpp"
MainWindow::MainWindow()
: m_main_box(Gtk::ORIENTATION_VERTICAL)
@@ -88,10 +87,7 @@ MainWindow::MainWindow()
});
m_menu_view_friends.signal_activate().connect([this] {
auto *window = new FriendsListWindow;
window->set_position(Gtk::WIN_POS_CENTER);
window->show();
Abaddon::Get().ManageHeapWindow(window);
m_content_stack.set_visible_child("friends");
});
m_content_box.set_hexpand(true);
@@ -125,9 +121,15 @@ MainWindow::MainWindow()
member_list->set_vexpand(true);
member_list->show();
m_content_stack.add(*chat);
m_friends.set_vexpand(true);
m_friends.set_hexpand(true);
m_friends.show();
m_content_stack.add(*chat, "chat");
m_content_stack.add(m_friends, "friends");
m_content_stack.set_vexpand(true);
m_content_stack.set_hexpand(true);
m_content_stack.set_visible_child("chat");
m_content_stack.show();
m_chan_content_paned.pack1(*channel_list);
@@ -222,6 +224,7 @@ void MainWindow::UpdateChatActiveChannel(Snowflake id) {
m_chat.SetActiveChannel(id);
m_members.SetActiveChannel(id);
m_channel_list.SetActiveChannel(id);
m_content_stack.set_visible_child("chat");
}
Snowflake MainWindow::GetChatActiveChannel() const {

View File

@@ -2,6 +2,7 @@
#include "../components/channels.hpp"
#include "../components/chatwindow.hpp"
#include "../components/memberlist.hpp"
#include "../components/friendslist.hpp"
#include <gtkmm.h>
class MainWindow : public Gtk::Window {
@@ -74,6 +75,7 @@ protected:
ChannelList m_channel_list;
ChatWindow m_chat;
MemberList m_members;
FriendsList m_friends;
Gtk::Stack m_content_stack;