mirror of
https://github.com/celisej567/abaddon.git
synced 2026-09-04 11:33:27 +03:00
show mutual guilds
This commit is contained in:
67
windows/profile/mutualguildspane.cpp
Normal file
67
windows/profile/mutualguildspane.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "mutualguildspane.hpp"
|
||||
#include "../../abaddon.hpp"
|
||||
|
||||
MutualGuildItem::MutualGuildItem(const MutualGuildData &guild)
|
||||
: Gtk::Box(Gtk::ORIENTATION_HORIZONTAL)
|
||||
, m_box(Gtk::ORIENTATION_VERTICAL) {
|
||||
get_style_context()->add_class("mutual-guild-item");
|
||||
m_name.get_style_context()->add_class("mutual-guild-item-name");
|
||||
m_icon.get_style_context()->add_class("mutual-guild-item-icon");
|
||||
|
||||
m_icon.set_margin_end(10);
|
||||
|
||||
const auto data = *Abaddon::Get().GetDiscordClient().GetGuild(guild.ID);
|
||||
const auto show_animations = Abaddon::Get().GetSettings().GetShowAnimations();
|
||||
auto &img = Abaddon::Get().GetImageManager();
|
||||
m_icon.property_pixbuf() = img.GetPlaceholder(24);
|
||||
if (data.HasIcon()) {
|
||||
if (data.HasAnimatedIcon() && show_animations) {
|
||||
auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {
|
||||
m_icon.property_pixbuf_animation() = pb;
|
||||
};
|
||||
img.LoadAnimationFromURL(data.GetIconURL("gif", "32"), 24, 24, sigc::track_obj(cb, *this));
|
||||
} else {
|
||||
auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
|
||||
m_icon.property_pixbuf() = pb->scale_simple(24, 24, Gdk::INTERP_BILINEAR);
|
||||
};
|
||||
img.LoadFromURL(data.GetIconURL("png", "32"), sigc::track_obj(cb, *this));
|
||||
}
|
||||
}
|
||||
|
||||
m_name.set_markup("<b>" + Glib::Markup::escape_text(data.Name) + "</b>");
|
||||
|
||||
if (guild.Nick.has_value()) {
|
||||
m_nick = Gtk::manage(new Gtk::Label(*guild.Nick));
|
||||
m_nick->get_style_context()->add_class("mutual-guild-item-nick");
|
||||
m_nick->set_margin_start(5);
|
||||
m_nick->set_halign(Gtk::ALIGN_START);
|
||||
m_nick->set_single_line_mode(true);
|
||||
m_nick->set_ellipsize(Pango::ELLIPSIZE_END);
|
||||
}
|
||||
|
||||
m_box.set_valign(Gtk::ALIGN_CENTER);
|
||||
|
||||
m_box.add(m_name);
|
||||
if (m_nick != nullptr)
|
||||
m_box.add(*m_nick);
|
||||
add(m_icon);
|
||||
add(m_box);
|
||||
show_all_children();
|
||||
}
|
||||
|
||||
UserMutualGuildsPane::UserMutualGuildsPane(Snowflake id)
|
||||
: UserID(id) {
|
||||
add(m_list);
|
||||
show_all_children();
|
||||
}
|
||||
|
||||
void UserMutualGuildsPane::SetMutualGuilds(const std::vector<MutualGuildData> &guilds) {
|
||||
for (auto child : m_list.get_children())
|
||||
delete child;
|
||||
|
||||
for (const auto &guild : guilds) {
|
||||
auto *item = Gtk::manage(new MutualGuildItem(guild));
|
||||
item->show();
|
||||
m_list.add(*item);
|
||||
}
|
||||
}
|
||||
26
windows/profile/mutualguildspane.hpp
Normal file
26
windows/profile/mutualguildspane.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include <gtkmm.h>
|
||||
#include "../../discord/objects.hpp"
|
||||
|
||||
class MutualGuildItem : public Gtk::Box {
|
||||
public:
|
||||
MutualGuildItem(const MutualGuildData &guild);
|
||||
|
||||
private:
|
||||
Gtk::Image m_icon;
|
||||
Gtk::Box m_box;
|
||||
Gtk::Label m_name;
|
||||
Gtk::Label *m_nick = nullptr;
|
||||
};
|
||||
|
||||
class UserMutualGuildsPane : public Gtk::ScrolledWindow {
|
||||
public:
|
||||
UserMutualGuildsPane(Snowflake id);
|
||||
|
||||
void SetMutualGuilds(const std::vector<MutualGuildData> &guilds);
|
||||
|
||||
Snowflake UserID;
|
||||
|
||||
private:
|
||||
Gtk::ListBox m_list;
|
||||
};
|
||||
@@ -6,7 +6,8 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
|
||||
, m_main(Gtk::ORIENTATION_VERTICAL)
|
||||
, m_upper(Gtk::ORIENTATION_HORIZONTAL)
|
||||
, m_badges(Gtk::ORIENTATION_HORIZONTAL)
|
||||
, m_pane_info(user_id) {
|
||||
, m_pane_info(user_id)
|
||||
, m_pane_guilds(user_id) {
|
||||
const auto &discord = Abaddon::Get().GetDiscordClient();
|
||||
auto user = *discord.GetUser(ID);
|
||||
|
||||
@@ -70,6 +71,7 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
|
||||
m_switcher.set_hexpand(true);
|
||||
|
||||
m_stack.add(m_pane_info, "info", "User Info");
|
||||
m_stack.add(m_pane_guilds, "guilds", "Mutual Servers");
|
||||
|
||||
m_badges.set_valign(Gtk::ALIGN_CENTER);
|
||||
m_badges_scroll.set_hexpand(true);
|
||||
@@ -99,6 +101,7 @@ void ProfileWindow::on_hide() {
|
||||
|
||||
void ProfileWindow::OnFetchProfile(const UserProfileData &data) {
|
||||
m_pane_info.SetConnections(data.ConnectedAccounts);
|
||||
m_pane_guilds.SetMutualGuilds(data.MutualGuilds);
|
||||
|
||||
for (auto child : m_badges.get_children())
|
||||
delete child;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <gtkmm.h>
|
||||
#include "../discord/snowflake.hpp"
|
||||
#include "profile/userinfopane.hpp"
|
||||
#include "profile/mutualguildspane.hpp"
|
||||
|
||||
class ProfileWindow : public Gtk::Window {
|
||||
public:
|
||||
@@ -26,4 +27,5 @@ private:
|
||||
Gtk::StackSwitcher m_switcher;
|
||||
|
||||
ProfileUserInfoPane m_pane_info;
|
||||
UserMutualGuildsPane m_pane_guilds;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user