summaryrefslogtreecommitdiff
path: root/windows/profile
diff options
context:
space:
mode:
Diffstat (limited to 'windows/profile')
-rw-r--r--windows/profile/mutualfriendspane.cpp54
-rw-r--r--windows/profile/mutualfriendspane.hpp24
2 files changed, 78 insertions, 0 deletions
diff --git a/windows/profile/mutualfriendspane.cpp b/windows/profile/mutualfriendspane.cpp
new file mode 100644
index 0000000..233df64
--- /dev/null
+++ b/windows/profile/mutualfriendspane.cpp
@@ -0,0 +1,54 @@
+#include "mutualfriendspane.hpp"
+#include "../../abaddon.hpp"
+
+MutualFriendItem::MutualFriendItem(const UserData &user)
+ : Gtk::Box(Gtk::ORIENTATION_HORIZONTAL) {
+ get_style_context()->add_class("mutual-friend-item");
+ m_name.get_style_context()->add_class("mutual-friend-item-name");
+ m_avatar.get_style_context()->add_class("mutual-friend-item-avatar");
+
+ m_avatar.set_margin_end(10);
+
+ const auto show_animations = Abaddon::Get().GetSettings().GetShowAnimations();
+ auto &img = Abaddon::Get().GetImageManager();
+ m_avatar.property_pixbuf() = img.GetPlaceholder(24);
+ if (user.HasAvatar()) {
+ if (user.HasAnimatedAvatar() && show_animations) {
+ auto cb = [this](const Glib::RefPtr<Gdk::PixbufAnimation> &pb) {
+ m_avatar.property_pixbuf_animation() = pb;
+ };
+ img.LoadAnimationFromURL(user.GetAvatarURL("gif", "32"), 24, 24, sigc::track_obj(cb, *this));
+ } else {
+ auto cb = [this](const Glib::RefPtr<Gdk::Pixbuf> &pb) {
+ m_avatar.property_pixbuf() = pb->scale_simple(24, 24, Gdk::INTERP_BILINEAR);
+ };
+ img.LoadFromURL(user.GetAvatarURL("png", "32"), sigc::track_obj(cb, *this));
+ }
+ }
+
+ m_name.set_markup("<b>" +
+ Glib::Markup::escape_text(user.Username) +
+ "</b>#" + user.Discriminator);
+
+ m_name.set_valign(Gtk::ALIGN_CENTER);
+ add(m_avatar);
+ add(m_name);
+ show_all_children();
+}
+
+MutualFriendsPane::MutualFriendsPane(Snowflake id)
+ : UserID(id) {
+ add(m_list);
+ show_all_children();
+}
+
+void MutualFriendsPane::SetMutualFriends(const std::vector<UserData> &users) {
+ for (auto child : m_list.get_children())
+ delete child;
+
+ for (const auto &user : users) {
+ auto *item = Gtk::manage(new MutualFriendItem(user));
+ item->show();
+ m_list.add(*item);
+ }
+}
diff --git a/windows/profile/mutualfriendspane.hpp b/windows/profile/mutualfriendspane.hpp
new file mode 100644
index 0000000..70774a7
--- /dev/null
+++ b/windows/profile/mutualfriendspane.hpp
@@ -0,0 +1,24 @@
+#pragma once
+#include <gtkmm.h>
+#include "../../discord/objects.hpp"
+
+class MutualFriendItem : public Gtk::Box {
+public:
+ MutualFriendItem(const UserData &user);
+
+private:
+ Gtk::Image m_avatar;
+ Gtk::Label m_name;
+};
+
+class MutualFriendsPane : public Gtk::ScrolledWindow {
+public:
+ MutualFriendsPane(Snowflake id);
+
+ void SetMutualFriends(const std::vector<UserData> &users);
+
+ Snowflake UserID;
+
+private:
+ Gtk::ListBox m_list;
+};