summaryrefslogtreecommitdiff
path: root/windows
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-02-08 15:57:55 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2021-02-08 15:57:55 -0500
commit2ddac42575aee5370d01701ce50444713d4d44b9 (patch)
tree019036c715c0c163d36f2137d340395cb600367d /windows
parent6896db53d672bc5b94eeb66e9fda85f6a4c81c8f (diff)
downloadabaddon-portaudio-2ddac42575aee5370d01701ce50444713d4d44b9.tar.gz
abaddon-portaudio-2ddac42575aee5370d01701ce50444713d4d44b9.zip
show mutual friends
Diffstat (limited to 'windows')
-rw-r--r--windows/profile/mutualfriendspane.cpp54
-rw-r--r--windows/profile/mutualfriendspane.hpp24
-rw-r--r--windows/profilewindow.cpp13
-rw-r--r--windows/profilewindow.hpp3
4 files changed, 91 insertions, 3 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;
+};
diff --git a/windows/profilewindow.cpp b/windows/profilewindow.cpp
index 2599065..332652b 100644
--- a/windows/profilewindow.cpp
+++ b/windows/profilewindow.cpp
@@ -7,11 +7,13 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
, m_upper(Gtk::ORIENTATION_HORIZONTAL)
, m_badges(Gtk::ORIENTATION_HORIZONTAL)
, m_pane_info(user_id)
- , m_pane_guilds(user_id) {
- const auto &discord = Abaddon::Get().GetDiscordClient();
+ , m_pane_guilds(user_id)
+ , m_pane_friends(user_id) {
+ auto &discord = Abaddon::Get().GetDiscordClient();
auto user = *discord.GetUser(ID);
- Abaddon::Get().GetDiscordClient().FetchUserProfile(user_id, sigc::mem_fun(*this, &ProfileWindow::OnFetchProfile));
+ discord.FetchUserProfile(user_id, sigc::mem_fun(*this, &ProfileWindow::OnFetchProfile));
+ discord.FetchUserRelationships(user_id, sigc::mem_fun(*this, &ProfileWindow::OnFetchRelationships));
set_name("user-profile");
set_default_size(450, 375);
@@ -72,6 +74,7 @@ ProfileWindow::ProfileWindow(Snowflake user_id)
m_stack.add(m_pane_info, "info", "User Info");
m_stack.add(m_pane_guilds, "guilds", "Mutual Servers");
+ m_stack.add(m_pane_friends, "friends", "Mutual Friends");
m_badges.set_valign(Gtk::ALIGN_CENTER);
m_badges_scroll.set_hexpand(true);
@@ -126,3 +129,7 @@ void ProfileWindow::OnFetchProfile(const UserProfileData &data) {
m_badges.add(*image);
}
}
+
+void ProfileWindow::OnFetchRelationships(const std::vector<UserData> &data) {
+ m_pane_friends.SetMutualFriends(data);
+}
diff --git a/windows/profilewindow.hpp b/windows/profilewindow.hpp
index a5627d3..7b22829 100644
--- a/windows/profilewindow.hpp
+++ b/windows/profilewindow.hpp
@@ -3,6 +3,7 @@
#include "../discord/snowflake.hpp"
#include "profile/userinfopane.hpp"
#include "profile/mutualguildspane.hpp"
+#include "profile/mutualfriendspane.hpp"
class ProfileWindow : public Gtk::Window {
public:
@@ -14,6 +15,7 @@ public:
private:
void OnFetchProfile(const UserProfileData &data);
+ void OnFetchRelationships(const std::vector<UserData> &data);
Gtk::Box m_main;
Gtk::Box m_upper;
@@ -28,4 +30,5 @@ private:
ProfileUserInfoPane m_pane_info;
UserMutualGuildsPane m_pane_guilds;
+ MutualFriendsPane m_pane_friends;
};